Commit ce646292 authored by shiyu's avatar shiyu

标签制作

parent f18d238e
......@@ -16,6 +16,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
......@@ -154,6 +156,24 @@ public class QiniuStorage implements Storage {
}
public String storeItemQrcodeBase64Str(String baseStr, String keyName) throws Exception {
if (uploadManager == null) {
if (auth == null) {
auth = Auth.create(accessKey, secretKey);
}
uploadManager = new UploadManager(new Configuration());
}
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] imageByte = base64Decoder.decodeBuffer(baseStr);
InputStream inputStream = new ByteArrayInputStream(imageByte);
BufferedImage image = ImageIO.read(inputStream);
keyName = keyName + "_" + image.getWidth() + "x" + image.getHeight() + BASE64_IMG_SUFFIX;
store(imageByte, keyName);
String url =generateUrl(keyName);
return url;
}
@Override
public Stream<Path> loadAll() {
return null;
......
package com.wwdz.ch.db.dao;
import com.wwdz.ch.db.domain.ItemTagQrCode;
public interface ItemTagQrCodeDao {
/**
* 插入商品标签二维码
* @param itemTagQrCode
* @return
*/
long insert(ItemTagQrCode itemTagQrCode);
boolean update(ItemTagQrCode itemTagQrCode);
ItemTagQrCode findByCode(String code);
}
package com.wwdz.ch.db.domain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import com.xxdxxs.entity.Entity;
import lombok.Data;
/**
* @author shiyu
* @date 2024/11/26
*/
@Data
public class ItemTagQrCode implements Entity {
private Long id;
/**
* 二维码编码
*/
private String code;
/**
* 二维码
*/
private String qrCode;
/**
* 类目id
*/
private Integer categoryId;
/**
* 类目名称
*/
private String categoryName;
/**
* 创建时间
*/
private Date createTime;
/**
* 绑定的商品id
*/
private Long itemId;
private static final long serialVersionUID = 1L;
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", code=").append(code);
sb.append(", qrCode=").append(qrCode);
sb.append(", categoryId=").append(categoryId);
sb.append(", categoryName=").append(categoryName);
sb.append(", createTime=").append(createTime);
sb.append(", itemId=").append(itemId);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
ItemTagQrCode other = (ItemTagQrCode) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getCode() == null ? other.getCode() == null : this.getCode().equals(other.getCode()))
&& (this.getQrCode() == null ? other.getQrCode() == null : this.getQrCode().equals(other.getQrCode()))
&& (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()))
&& (this.getCategoryName() == null ? other.getCategoryName() == null : this.getCategoryName().equals(other.getCategoryName()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getItemId() == null ? other.getItemId() == null : this.getItemId().equals(other.getItemId()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
result = prime * result + ((getQrCode() == null) ? 0 : getQrCode().hashCode());
result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
result = prime * result + ((getCategoryName() == null) ? 0 : getCategoryName().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getItemId() == null) ? 0 : getItemId().hashCode());
return result;
}
/**
* This enum was generated by MyBatis Generator.
* This enum corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public enum Column {
id("id", "id", "BIGINT", false),
code("code", "code", "VARCHAR", false),
qrCode("qr_code", "qrCode", "VARCHAR", false),
categoryId("category_id", "categoryId", "INTEGER", false),
categoryName("category_name", "categoryName", "VARCHAR", false),
createTime("create_time", "createTime", "TIMESTAMP", false),
itemId("item_id", "itemId", "BIGINT", false);
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String BEGINNING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private static final String ENDING_DELIMITER = "`";
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String column;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final boolean isColumnNameDelimited;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String javaProperty;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
private final String jdbcType;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String value() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getValue() {
return this.column;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJavaProperty() {
return this.javaProperty;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getJdbcType() {
return this.jdbcType;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
this.column = column;
this.javaProperty = javaProperty;
this.jdbcType = jdbcType;
this.isColumnNameDelimited = isColumnNameDelimited;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String desc() {
return this.getEscapedColumnName() + " DESC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String asc() {
return this.getEscapedColumnName() + " ASC";
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public static Column[] excludes(Column ... excludes) {
ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
if (excludes != null && excludes.length > 0) {
columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
}
return columns.toArray(new Column[]{});
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
public String getEscapedColumnName() {
if (this.isColumnNameDelimited) {
return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
} else {
return this.column;
}
}
}
}
\ No newline at end of file
package com.wwdz.ch.db.dto.request;
import com.xxdxxs.entity.Entity;
import lombok.Data;
import java.util.Date;
@Data
public class ItemTagQrCodeRequestDto implements Entity {
private Long id;
/**
* 二维码编码
*/
private String code;
/**
* 二维码
*/
private String qrCode;
/**
* 类目id
*/
private Integer categoryId;
/**
* 类目名称
*/
private String categoryName;
/**
* 创建时间
*/
private Date createTime;
/**
* 绑定的商品id
*/
private Long itemId;
}
package com.wwdz.ch.db.impl;
import com.wwdz.ch.db.dao.ItemTagQrCodeDao;
import com.wwdz.ch.db.domain.ItemTagQrCode;
import com.wwdz.ch.db.domain.ItemTagQrCodeExample;
import com.wwdz.ch.db.mapper.ItemTagQrCodeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class ItemTagQrCodeDaoImpl implements ItemTagQrCodeDao {
@Autowired
ItemTagQrCodeMapper itemTagQrCodeMapper;
@Override
public long insert(ItemTagQrCode itemTagQrCode) {
itemTagQrCodeMapper.insert(itemTagQrCode);
return itemTagQrCode.getId();
}
@Override
public boolean update(ItemTagQrCode itemTagQrCode) {
ItemTagQrCodeExample example = new ItemTagQrCodeExample();
ItemTagQrCodeExample.Criteria criteria = example.createCriteria();
criteria.andCodeEqualTo(itemTagQrCode.getCode());
return itemTagQrCodeMapper.updateByExampleSelective(itemTagQrCode, example) > 0;
}
@Override
public ItemTagQrCode findByCode(String code) {
ItemTagQrCodeExample example = new ItemTagQrCodeExample();
ItemTagQrCodeExample.Criteria criteria = example.createCriteria();
criteria.andCodeEqualTo(code);
return itemTagQrCodeMapper.selectOneByExample(example);
}
}
package com.wwdz.ch.db.mapper;
import com.wwdz.ch.db.domain.ItemTagQrCode;
import com.wwdz.ch.db.domain.ItemTagQrCodeExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface ItemTagQrCodeMapper {
long countByExample(ItemTagQrCodeExample example);
int deleteByExample(ItemTagQrCodeExample example);
int deleteByPrimaryKey(Long id);
int insert(ItemTagQrCode record);
int insertSelective(ItemTagQrCode record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ItemTagQrCode selectOneByExample(ItemTagQrCodeExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ItemTagQrCode selectOneByExampleSelective(@Param("example") ItemTagQrCodeExample example, @Param("selective") ItemTagQrCode.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
List<ItemTagQrCode> selectByExampleSelective(@Param("example") ItemTagQrCodeExample example, @Param("selective") ItemTagQrCode.Column ... selective);
List<ItemTagQrCode> selectByExample(ItemTagQrCodeExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table item_tag_qr_code
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
ItemTagQrCode selectByPrimaryKeySelective(@Param("id") Long id, @Param("selective") ItemTagQrCode.Column ... selective);
ItemTagQrCode selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") ItemTagQrCode record, @Param("example") ItemTagQrCodeExample example);
int updateByExample(@Param("record") ItemTagQrCode record, @Param("example") ItemTagQrCodeExample example);
int updateByPrimaryKeySelective(ItemTagQrCode record);
int updateByPrimaryKey(ItemTagQrCode record);
}
\ No newline at end of file
......@@ -72,7 +72,7 @@
<javaClientGenerator type="XMLMAPPER" targetPackage="com.wwdz.ch.db.mapper"
targetProject="ch-dao/src/main/java"/>
<table tableName="sign_in_share_image" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<table tableName="item_tag_qr_code" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
......
......@@ -5,16 +5,20 @@ import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.SupplierItemEnum;
import com.wwdz.ch.core.storage.QiniuStorage;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.AESCrypt;
import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.QRCodeUtil;
import com.wwdz.ch.core.util.UUID;
import com.wwdz.ch.db.dao.CategoryDao;
import com.wwdz.ch.db.dao.ItemTagOperateRecordDao;
import com.wwdz.ch.db.dao.ItemTagQrCodeDao;
import com.wwdz.ch.db.dao.distribution.SupplierItemDao;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.domain.ItemTagOperateRecord;
import com.wwdz.ch.db.domain.ItemTagQrCode;
import com.wwdz.ch.db.domain.distribution.SupplierItem;
import com.wwdz.ch.db.dto.request.ItemTagOperateRecordRequestDto;
import com.wwdz.ch.wx.entity.request.ItemTagOperateRequestDto;
......@@ -52,41 +56,6 @@ public class ItemTagOperateServiceImpl implements ItemTagOperateService {
@Autowired
WxAppletApi wxAppletApi;
@Override
public Result createQrCode(ItemTagOperateRequestDto dto) {
try {
int createNum = dto.getCreateNum();
IntStream.rangeClosed(0, createNum).parallel().forEach( i ->{
SupplierItem supplierItem = new SupplierItem();
supplierItem.setDistributionPrice(0L);
supplierItem.setSupplyPrice(0L);
supplierItem.setRebate(new BigDecimal("0"));
supplierItem.setSort(1);
supplierItem.setBuyLimitNum(-1);
supplierItem.setIsAbleSale(false);
supplierItem.setIsOnSale(false);
supplierItem.setStock(1);
supplierItem.setIsOnSale(false);
Date now = new Date();
supplierItem.setCreateTime(now);
supplierItem.setUpdateTime(now);
supplierItem.setIsDeleted(true);
supplierItem.setDistributionPrice(0L);
supplierItem.setType(DistributionEnum.DistributionTypeEnum.BLACK.getCode());
supplierItem.setStatus(SupplierItemEnum.StatusEnum.COMMON.getCode());
supplierItem.setCreatorId(CommConsts.PRINT_ITEM_TAG_CREATOR_ID);
long itemId = supplierItemDao.insert(supplierItem);
//获取页面短链
String url = wxAppletApi.getUrlLink("/pages/detail/index","itemId=" + itemId);
String qrCode = QRCodeUtil.createCodeToBase64(url);
});
} catch (Exception e) {
logger.error("打印标签失败", e);
}
return Result.failed("打印标签失败");
}
@Override
public Result printItemTag(ItemTagOperateRequestDto dto) {
try {
......
package com.wwdz.ch.wx.impl;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.entity.SupplierItemVo;
import com.wwdz.ch.core.storage.QiniuStorage;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.QRCodeUtil;
import com.wwdz.ch.core.util.UUID;
import com.wwdz.ch.db.dao.ItemTagQrCodeDao;
import com.wwdz.ch.db.dao.distribution.SupplierItemDao;
import com.wwdz.ch.db.domain.ItemTagQrCode;
import com.wwdz.ch.db.domain.distribution.SupplierItem;
import com.wwdz.ch.db.dto.request.ItemTagQrCodeRequestDto;
import com.wwdz.ch.wx.entity.request.ItemTagOperateRequestDto;
import com.wwdz.ch.wx.service.ItemTagQrCodeService;
import com.xxdxxs.utils.EntityMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class ItemTagQrCodeServiceImpl implements ItemTagQrCodeService {
private static final Logger logger = LoggerFactory.getLogger(ItemTagQrCodeServiceImpl.class);
@Autowired
WxAppletApi wxAppletApi;
@Autowired
ItemTagQrCodeDao itemTagQrCodeDao;
@Autowired
QiniuStorage qiniuStorage;
@Autowired
SupplierItemDao supplierItemDao;
@Override
public Result createQrCode(ItemTagOperateRequestDto dto) {
try {
Date now = new Date();
String code = UUID.fastUUID().toString(true);
ItemTagQrCode itemTagQrCode = new ItemTagQrCode();
itemTagQrCode.setCode(code);
itemTagQrCode.setCategoryId(1774);
itemTagQrCode.setCategoryName("开元通宝");
itemTagQrCode.setCreateTime(now);
//获取页面短链
String url = wxAppletApi.getUrlLink("/pages/detail/index","code=" + code);
String qrCode = QRCodeUtil.createCodeToBase64(url);
String keyName = CommConsts.UPLOAD_PRE_DIRECTORY + code;
String qrCodeUrl = qiniuStorage.storeItemQrcodeBase64Str(qrCode.trim(), keyName);
logger.info("上传的商品标签二维码url :{}", qrCodeUrl);
itemTagQrCode.setQrCode(qrCodeUrl);
itemTagQrCodeDao.insert(itemTagQrCode);
return Result.success(qrCodeUrl);
} catch (Exception e) {
logger.error("创建标签二维码失败", e);
}
return Result.failed("创建标签二维码失败");
}
@Override
public Result findByCode(ItemTagQrCodeRequestDto dto) {
try {
ItemTagQrCode itemTagQrCode = itemTagQrCodeDao.findByCode(dto.getCode());
if (itemTagQrCode != null && itemTagQrCode.getItemId() != null) {
SupplierItem supplierItem = supplierItemDao.findById(itemTagQrCode.getItemId());
SupplierItemVo supplierItemVo = new SupplierItemVo();
EntityMapper.copyAttribute(supplierItem, supplierItemVo);
return Result.success(supplierItemVo);
}
return Result.success(itemTagQrCode);
} catch (Exception e) {
logger.error("根据二维码code查询信息失败", e);
}
return Result.failed();
}
}
......@@ -6,14 +6,6 @@ import com.wwdz.ch.wx.entity.request.ItemTagOperateRequestDto;
public interface ItemTagOperateService {
/**
* 创建无图商品,生成页面二维码
* @return
*/
Result createQrCode(ItemTagOperateRequestDto dto);
/**
* 打印标签
* @param dto
......
package com.wwdz.ch.wx.service;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.ItemTagQrCodeRequestDto;
import com.wwdz.ch.wx.entity.request.ItemTagOperateRequestDto;
public interface ItemTagQrCodeService {
/**
* 批量生成页面二维码
* @return
*/
Result createQrCode(ItemTagOperateRequestDto dto);
/**
* 根据二维码code查询信息
* @param dto
* @return
*/
Result findByCode(ItemTagQrCodeRequestDto dto);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment