Commit c5bd5c0e authored by licc's avatar licc

二维码实现优化 2

parent 3272c8d8
package cn.wisenergy.mapper;
import cn.wisenergy.model.app.ProductInfo;
import org.apache.ibatis.annotations.Param;
/**
* @author 86187
*/
public interface ProductMapper {
/**
* 添加产品认证信息
*
* @param productInfo 产品认证信息
* @return 1
*/
int add(ProductInfo productInfo);
/**
* 编辑产品认证信息
*
* @param productInfo 产品认证信息
* @return 1
*/
int edit(ProductInfo productInfo);
/**
* 根据批次号获取产品认证信息
* @param batchNumber 批次号
* @return 产品认证信息
*/
ProductInfo getByBatchNumber(@Param("batchNumber") String batchNumber);
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<resultMap id="antiMap" type="cn.wisenergy.model.app.AntiFake"> <resultMap id="antiMap" type="cn.wisenergy.model.app.AntiFake">
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="product_no" property="productNo"/> <result column="product_no" property="productNo"/>
<result column="security_code" property="securityCode"/>
<result column="batch_number" property="batchNumber"/> <result column="batch_number" property="batchNumber"/>
<result column="sha_value" property="shaValue"/> <result column="sha_value" property="shaValue"/>
<result column="produce_time" property="produceTime"/> <result column="produce_time" property="produceTime"/>
...@@ -11,17 +12,6 @@ ...@@ -11,17 +12,6 @@
<result column="status" property="status"/> <result column="status" property="status"/>
<result column="use_status" property="useStatus"/> <result column="use_status" property="useStatus"/>
<result column="scan_number" property="scanNumber"/> <result column="scan_number" property="scanNumber"/>
<result column="brand" property="brand"/>
<result column="specification" property="specification"/>
<result column="brand_name" property="brandName"/>
<result column="product_country" property="productCountry"/>
<result column="valid_time" property="validTime"/>
<result column="company_name" property="companyName"/>
<result column="company_address" property="companyAddress"/>
<result column="company_url" property="companyUrl"/>
<result column="tracking_number" property="trackingNumber"/>
<result column="logistics_url" property="logisticsUrl"/>
<result column="record_number" property="recordNumber"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/> <result column="update_time" property="updateTime"/>
</resultMap> </resultMap>
...@@ -36,25 +26,21 @@ ...@@ -36,25 +26,21 @@
</sql> </sql>
<sql id="cols_exclude_id"> <sql id="cols_exclude_id">
product_no,batch_number,sha_value,produce_time,scan_time,status,use_status,scan_number,brand,specification, product_no,security_code,batch_number,sha_value,produce_time,scan_time,status,use_status,scan_number,create_time,update_time
brand_name,product_country, valid_time, company_name,company_address,company_url,tracking_number,
logistics_url,record_number, create_time,update_time
</sql> </sql>
<sql id="vals"> <sql id="vals">
#{productNo},#{batchNumber},#{shaValue},#{produceTime},#{scanTime},#{status},#{useStatus},#{scanNumber},#{brand}, #{productNo},#{securityCode},#{batchNumber},#{shaValue},#{produceTime},#{scanTime},#{status},#{useStatus},#{scanNumber},now(),now()
#{specification},#{brandName},#{productCountry}, #{validTime},#{companyName},#{companyAddress},#{companyUrl},#{trackingNumber},#{logisticsUrl},
#{recordNumber},now(),now()
</sql> </sql>
<sql id="createsVal"> <sql id="createsVal">
#{i.productNo},#{i.batchNumber},#{i.shaValue},#{i.produceTime},#{i.scanTime},#{i.status},#{i.useStatus}, #{i.productNo},#{i.securityCode},#{i.batchNumber},#{i.shaValue},#{i.produceTime},#{i.scanTime},#{i.status},#{i.useStatus},
#{i.scanNumber},#{i.brand},#{i.specification},#{i.brandName},#{i.productCountry}, #{i.validTime},#{i.companyName}, #{i.scanNumber},now(),now()
#{i.companyAddress}, #{i.companyUrl},#{i.trackingNumber},#{i.logisticsUrl}, #{i.recordNumber},now(),now()
</sql> </sql>
<sql id="updateCondition"> <sql id="updateCondition">
<if test="productNo != null">product_no = #{productNo},</if> <if test="productNo != null">product_no = #{productNo},</if>
<if test="securityCode != null">security_code = #{securityCode},</if>
<if test="batchNumber != null">batch_number = #{batchNumber},</if> <if test="batchNumber != null">batch_number = #{batchNumber},</if>
<if test="shaValue != null">sha_value = #{shaValue},</if> <if test="shaValue != null">sha_value = #{shaValue},</if>
<if test="produceTime != null">produce_time = #{produceTime},</if> <if test="produceTime != null">produce_time = #{produceTime},</if>
...@@ -62,23 +48,13 @@ ...@@ -62,23 +48,13 @@
<if test="status != null">status = #{status},</if> <if test="status != null">status = #{status},</if>
<if test="useStatus != null">use_status = #{useStatus},</if> <if test="useStatus != null">use_status = #{useStatus},</if>
<if test="scanNumber != null">scan_number = #{scanNumber},</if> <if test="scanNumber != null">scan_number = #{scanNumber},</if>
<if test="brand != null">brand = #{brand},</if>
<if test="specification != null">specification = #{specification},</if>
<if test="brandName != null">brand_name = #{brandName},</if>
<if test="productCountry != null">product_country = #{productCountry},</if>
<if test="validTime != null">valid_time = #{validTime},</if>
<if test="companyName != null">company_name = #{companyName},</if>
<if test="companyAddress != null">company_address = #{companyAddress},</if>
<if test="companyUrl != null">company_url = #{companyUrl},</if>
<if test="trackingNumber != null">tracking_number = #{trackingNumber},</if>
<if test="logisticsUrl != null">logistics_url = #{logisticsUrl},</if>
<if test="recordNumber != null">record_number = #{recordNumber},</if>
update_time =now() update_time =now()
</sql> </sql>
<sql id="criteria"> <sql id="criteria">
<if test="id != null">id = #{id}</if> <if test="id != null">id = #{id}</if>
<if test="productNo != null">and product_no = #{productNo}</if> <if test="productNo != null">and product_no = #{productNo}</if>
<if test="securityCode != null">and security_code = #{securityCode}</if>
<if test="batchNumber != null">and batch_number = #{batchNumber}</if> <if test="batchNumber != null">and batch_number = #{batchNumber}</if>
<if test="shaValue != null">and sha_value = #{shaValue}</if> <if test="shaValue != null">and sha_value = #{shaValue}</if>
<if test="produceTime != null">and produce_time = #{produceTime}</if> <if test="produceTime != null">and produce_time = #{produceTime}</if>
...@@ -86,17 +62,6 @@ ...@@ -86,17 +62,6 @@
<if test="status != null">and status = #{status}</if> <if test="status != null">and status = #{status}</if>
<if test="useStatus != null">and use_status = #{useStatus}</if> <if test="useStatus != null">and use_status = #{useStatus}</if>
<if test="scaNumber != null">and sca_number = #{scaNumber}</if> <if test="scaNumber != null">and sca_number = #{scaNumber}</if>
<if test="brand != null">and brand = #{brand}</if>
<if test="specification != null">and specification = #{specification}</if>
<if test="brandName != null">and brand_name = #{brandName}</if>
<if test="productCountry != null">and product_country = #{productCountry}</if>
<if test="validTime != null">and valid_time = #{validTime}</if>
<if test="companyName != null">and company_name = #{companyName}</if>
<if test="companyAddress != null">and company_address = #{companyAddress}</if>
<if test="companyUrl != null">and company_url = #{companyUrl}</if>
<if test="trackingNumber != null">and tracking_number = #{trackingNumber}</if>
<if test="logisticsUrl != null">and logistics_url = #{logisticsUrl}</if>
<if test="recordNumber != null">and record_number = #{recordNumber}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if> <if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if> <if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql> </sql>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wisenergy.mapper.ProductMapper">
<resultMap id="productMap" type="cn.wisenergy.model.app.ProductInfo">
<id column="id" property="id"/>
<result column="batch_number" property="batchNumber"/>
<result column="brand" property="brand"/>
<result column="specification" property="specification"/>
<result column="brand_name" property="brandName"/>
<result column="product_country" property="productCountry"/>
<result column="valid_time" property="validTime"/>
<result column="company_name" property="companyName"/>
<result column="company_address" property="companyAddress"/>
<result column="company_url" property="companyUrl"/>
<result column="tracking_number" property="trackingNumber"/>
<result column="logistics_url" property="logisticsUrl"/>
<result column="record_number" property="recordNumber"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
</resultMap>
<sql id="table">
product_info
</sql>
<sql id="cols_all">
id,
<include refid="cols_exclude_id"/>
</sql>
<sql id="cols_exclude_id">
batch_number,brand,specification,brand_name,product_country, valid_time, company_name,company_address,
company_url,tracking_number, logistics_url,record_number, create_time,update_time
</sql>
<sql id="vals">
#{batchNumber},#{brand}, #{specification},#{brandName},#{productCountry}, #{validTime},#{companyName},
#{companyAddress},#{companyUrl},#{trackingNumber},#{logisticsUrl}, #{recordNumber},now(),now()
</sql>
<sql id="createsVal">
#{i.batchNumber},#{i.brand},#{i.specification},#{i.brandName},#{i.productCountry},
#{i.validTime},#{i.companyName},
#{i.companyAddress}, #{i.companyUrl},#{i.trackingNumber},#{i.logisticsUrl}, #{i.recordNumber},now(),now()
</sql>
<sql id="updateCondition">
<if test="batchNumber != null">batch_number = #{batchNumber},</if>
<if test="brand != null">brand = #{brand},</if>
<if test="specification != null">specification = #{specification},</if>
<if test="brandName != null">brand_name = #{brandName},</if>
<if test="productCountry != null">product_country = #{productCountry},</if>
<if test="validTime != null">valid_time = #{validTime},</if>
<if test="companyName != null">company_name = #{companyName},</if>
<if test="companyAddress != null">company_address = #{companyAddress},</if>
<if test="companyUrl != null">company_url = #{companyUrl},</if>
<if test="trackingNumber != null">tracking_number = #{trackingNumber},</if>
<if test="logisticsUrl != null">logistics_url = #{logisticsUrl},</if>
<if test="recordNumber != null">record_number = #{recordNumber},</if>
update_time =now()
</sql>
<sql id="criteria">
<if test="id != null">id = #{id}</if>
<if test="batchNumber != null">and batch_number = #{batchNumber}</if>
<if test="brand != null">and brand = #{brand}</if>
<if test="specification != null">and specification = #{specification}</if>
<if test="brandName != null">and brand_name = #{brandName}</if>
<if test="productCountry != null">and product_country = #{productCountry}</if>
<if test="validTime != null">and valid_time = #{validTime}</if>
<if test="companyName != null">and company_name = #{companyName}</if>
<if test="companyAddress != null">and company_address = #{companyAddress}</if>
<if test="companyUrl != null">and company_url = #{companyUrl}</if>
<if test="trackingNumber != null">and tracking_number = #{trackingNumber}</if>
<if test="logisticsUrl != null">and logistics_url = #{logisticsUrl}</if>
<if test="recordNumber != null">and record_number = #{recordNumber}</if>
<if test="createTime != null">and create_time &gt;= #{createTime}</if>
<if test="updateTime != null">and #{updateTime} &gt;= update_time</if>
</sql>
<insert id="add" parameterType="cn.wisenergy.model.app.ProductInfo" keyProperty="id" useGeneratedKeys="true">
insert into
<include refid="table"/>
(<include refid="cols_exclude_id"/>)
value(
<include refid="vals"/>
)
</insert>
<update id="edit" parameterType="cn.wisenergy.model.app.ProductInfo">
UPDATE
<include refid="table"/>
<set>
<include refid="updateCondition"/>
</set>
<where>
id = #{id}
</where>
</update>
<select id="getByBatchNumber" resultMap="productMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
batch_number=#{batchNumber}
</where>
</select>
</mapper>
\ No newline at end of file
...@@ -35,7 +35,11 @@ public class AntiFake implements Serializable { ...@@ -35,7 +35,11 @@ public class AntiFake implements Serializable {
@ApiModelProperty(value = "产品编号", name = "productNo") @ApiModelProperty(value = "产品编号", name = "productNo")
private String productNo; private String productNo;
/**
* 安全码
*/
@ApiModelProperty(value = "安全码", name = "securityCode")
private String securityCode;
/** /**
* 批次号 * 批次号
*/ */
...@@ -75,72 +79,6 @@ public class AntiFake implements Serializable { ...@@ -75,72 +79,6 @@ public class AntiFake implements Serializable {
@ApiModelProperty(value = "扫描次数", name = "scanNumber") @ApiModelProperty(value = "扫描次数", name = "scanNumber")
private Integer scanNumber; private Integer scanNumber;
/**
* 品牌
*/
@ApiModelProperty(value = "品牌", name = "brand")
private String brand;
/**
* 规格
*/
@ApiModelProperty(value = "规格", name = "specification")
private String specification;
/**
* 品牌名
*/
@ApiModelProperty(value = "品牌名", name = "brandName")
private String brandName;
/**
* 原产国
*/
@ApiModelProperty(value = "原产国", name = "productCountry")
private String productCountry;
/**
* 有效时间
*/
@ApiModelProperty(value = "有效时间", name = "validTime")
private Date validTime;
/**
* 企业名称
*/
@ApiModelProperty(value = "企业名称", name = "companyName")
private String companyName;
/**
* 企业地址
*/
@ApiModelProperty(value = "企业地址", name = "companyAddress")
private String companyAddress;
/**
* 企业网址
*/
@ApiModelProperty(value = "企业网址", name = "companyUrl")
private String companyUrl;
/**
* 货运单号
*/
@ApiModelProperty(value = "货运单号", name = "trackingNumber")
private String trackingNumber;
/**
* 物流轨迹查询平台
*/
@ApiModelProperty(value = "物流轨迹查询平台", name = "logisticsUrl")
private String logisticsUrl;
/**
* 海关进境货物备案编号
*/
@ApiModelProperty(value = "海关进境货物备案编号", name = "recordNumber")
private String recordNumber;
private Date createTime; private Date createTime;
private Date updateTime; private Date updateTime;
......
package cn.wisenergy.model.app;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @ Description: 产品认证信息实体类
* @ Author : 86187
* @ Date : 2021/4/27 10:03
* @author 86187
*/
@Data
@ApiModel("ProductInfo")
public class ProductInfo {
/**
* 主键id
*/
@ApiModelProperty(value = "主键id", name = "id")
private Integer id;
/**
* 批次号
*/
@ApiModelProperty(value = "批次号", name = "batchNumber")
private String batchNumber;
/**
* 品牌
*/
@ApiModelProperty(value = "品牌", name = "brand")
private String brand;
/**
* 规格
*/
@ApiModelProperty(value = "规格", name = "specification")
private String specification;
/**
* 品牌名
*/
@ApiModelProperty(value = "品牌名", name = "brandName")
private String brandName;
/**
* 原产国
*/
@ApiModelProperty(value = "原产国", name = "productCountry")
private String productCountry;
/**
* 有效时间
*/
@ApiModelProperty(value = "有效时间", name = "validTime")
private Date validTime;
/**
* 企业名称
*/
@ApiModelProperty(value = "企业名称", name = "companyName")
private String companyName;
/**
* 企业地址
*/
@ApiModelProperty(value = "企业地址", name = "companyAddress")
private String companyAddress;
/**
* 企业网址
*/
@ApiModelProperty(value = "企业网址", name = "companyUrl")
private String companyUrl;
/**
* 货运单号
*/
@ApiModelProperty(value = "货运单号", name = "trackingNumber")
private String trackingNumber;
/**
* 物流轨迹查询平台
*/
@ApiModelProperty(value = "物流轨迹查询平台", name = "logisticsUrl")
private String logisticsUrl;
/**
* 海关进境货物备案编号
*/
@ApiModelProperty(value = "海关进境货物备案编号", name = "recordNumber")
private String recordNumber;
private Date createTime;
private Date updateTime;
}
package cn.wisenergy.service.Manager; package cn.wisenergy.service.Manager;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AntiFakeMapper; import cn.wisenergy.mapper.AntiFakeMapper;
import cn.wisenergy.mapper.ProductMapper;
import cn.wisenergy.model.app.AntiFake;
import cn.wisenergy.model.app.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
...@@ -16,10 +19,36 @@ public class AntiFakeManger { ...@@ -16,10 +19,36 @@ public class AntiFakeManger {
@Autowired @Autowired
private AntiFakeMapper antiFakeMapper; private AntiFakeMapper antiFakeMapper;
@Autowired
private ProductMapper productMapper;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean updateAntiFake(List<Long> array) { public Boolean updateAntiFake(List<Long> array) {
//修改二维码使用状态 //修改二维码使用状态
int updateUseStatus = antiFakeMapper.updateUseStatus(array); int updateUseStatus = antiFakeMapper.updateUseStatus(array);
return updateUseStatus == array.size(); return updateUseStatus == array.size();
} }
/**
* 保存二维码信息和产品认证信息
*
* @param list 二维码信息
* @param productInfo 产品认证信息
* @return true of false
*/
@Transactional(rollbackFor = Exception.class)
public Boolean addAntiFakeAndProductInfo(List<AntiFake> list, ProductInfo productInfo) {
if (!CollectionUtils.isEmpty(list)) {
int count = antiFakeMapper.creates(list);
if (count != list.size()) {
return false;
}
}
if (null != productInfo) {
int count = productMapper.add(productInfo);
return count != 0;
}
return true;
}
} }
...@@ -41,9 +41,10 @@ public interface AntiFakeService { ...@@ -41,9 +41,10 @@ public interface AntiFakeService {
* 扫描防伪二维码 * 扫描防伪二维码
* *
* @param produceNo 产品编号 * @param produceNo 产品编号
* @param securityCode 安全码
* @return 扫描结果 * @return 扫描结果
*/ */
R<String> scanCode(String produceNo); R<String> scanCode(String produceNo,String securityCode);
/** /**
* 获取防伪二维码列表 * 获取防伪二维码列表
......
//package cn.wisenergy.service.app;
//
///**
// * Created by m1991 on 2021/3/12 16:57
// */
//public interface RedisService {
// /**
// * 点赞。状态为1
// * @param likedUserId
// * @param likedPostId
// */
// void saveLiked2Redis(String likedUserId, String likedPostId);
//
// /**
// * 取消点赞。将状态改变为0
// * @param likedUserId
// * @param likedPostId
// */
// void unlikeFromRedis(String likedUserId, String likedPostId);
//
// /**
// * 从Redis中删除一条点赞数据
// * @param likedUserId
// * @param likedPostId
// */
// void deleteLikedFromRedis(String likedUserId, String likedPostId);
//
// /**
// * 该用户的点赞数加1
// * @param likedUserId
// */
// void incrementLikedCount(String likedUserId);
//
// /**
// * 该用户的点赞数减1
// * @param likedUserId
// */
// void decrementLikedCount(String likedUserId);
//
// /**
// * 获取Redis中存储的所有点赞数据
// * @return
// */
// List<UserLike> getLikedDataFromRedis();
//
// /**
// * 获取Redis中存储的所有点赞数量
// * @return
// */
// List<LikedCountDTO> getLikedCountFromRedis();
//
//}
...@@ -6,13 +6,13 @@ import cn.wisenergy.common.utils.R; ...@@ -6,13 +6,13 @@ import cn.wisenergy.common.utils.R;
import cn.wisenergy.common.utils.StringUtil; import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.mapper.AntiFakeMapper; import cn.wisenergy.mapper.AntiFakeMapper;
import cn.wisenergy.model.app.AntiFake; import cn.wisenergy.model.app.AntiFake;
import cn.wisenergy.model.app.ProductInfo;
import cn.wisenergy.model.dto.AntiFakeQuery; import cn.wisenergy.model.dto.AntiFakeQuery;
import cn.wisenergy.model.dto.CreateCodeVo; import cn.wisenergy.model.dto.CreateCodeVo;
import cn.wisenergy.model.vo.ReportCodeVo; import cn.wisenergy.model.vo.ReportCodeVo;
import cn.wisenergy.service.Manager.AntiFakeManger; import cn.wisenergy.service.Manager.AntiFakeManger;
import cn.wisenergy.service.app.AntiFakeService; import cn.wisenergy.service.app.AntiFakeService;
import cn.wisenergy.service.util.CodeUtils; import cn.wisenergy.service.util.CodeUtils;
import cn.wisenergy.service.util.FileUtils;
import cn.wisenergy.service.util.QRCodeUtils; import cn.wisenergy.service.util.QRCodeUtils;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -23,13 +23,10 @@ import org.apache.commons.lang3.StringUtils; ...@@ -23,13 +23,10 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author 86187 * @author 86187
...@@ -87,28 +84,37 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -87,28 +84,37 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
antiFake.setStatus(0); antiFake.setStatus(0);
antiFake.setUseStatus(0); antiFake.setUseStatus(0);
//生成防伪码
String sha = DigestUtils.sha1Hex(productNo).substring(0, 16); String sha = DigestUtils.sha1Hex(productNo).substring(0, 16);
antiFake.setShaValue(sha); antiFake.setShaValue(sha);
//生成六位随机数作为安全码
int code = (int) ((Math.random() * 9 + 1) * 100000);
antiFake.setSecurityCode(String.valueOf(code));
antiFake.setScanNumber(0); antiFake.setScanNumber(0);
antiFake.setProduceTime(codeVo.getProduceTime()); antiFake.setProduceTime(codeVo.getProduceTime());
antiFake.setCompanyAddress("東京都千代田区東神田2丁目6番7号608");
antiFake.setCompanyName("日本西田森製薬株式会社");
antiFake.setCompanyUrl("www.nishidamori.co.jp");
antiFake.setLogisticsUrl("中国国际货运航空 https://www.airchinacargo.com/en/search_order.php");
antiFake.setBrand("西田森");
antiFake.setProductCountry(codeVo.getProductCountry());
antiFake.setRecordNumber(codeVo.getRecordNumber());
antiFake.setTrackingNumber(codeVo.getTrackingNumber());
antiFake.setValidTime(codeVo.getValidTime());
antiFake.setSpecification(codeVo.getSpecification());
antiFake.setBrandName(codeVo.getBrandName());
list.add(antiFake); list.add(antiFake);
} }
//批量添加二维码 //初始化产品认证信息
int count = antiFakeMapper.creates(list); ProductInfo productInfo = new ProductInfo();
if (count != list.size()) { productInfo.setBatchNumber(batchNumber);
return R.error("生成防伪二维码失败!"); productInfo.setCompanyAddress("東京都千代田区東神田2丁目6番7号608");
productInfo.setCompanyName("日本西田森製薬株式会社");
productInfo.setCompanyUrl("www.nishidamori.co.jp");
productInfo.setLogisticsUrl("中国国际货运航空 https://www.airchinacargo.com/en/search_order.php");
productInfo.setBrand("西田森");
productInfo.setProductCountry(codeVo.getProductCountry());
productInfo.setRecordNumber(codeVo.getRecordNumber());
productInfo.setTrackingNumber(codeVo.getTrackingNumber());
productInfo.setValidTime(codeVo.getValidTime());
productInfo.setSpecification(codeVo.getSpecification());
productInfo.setBrandName(codeVo.getBrandName());
//批量添加二维码 和产品认证信息
boolean bool = antiFakeManger.addAntiFakeAndProductInfo(list, productInfo);
if (!bool) {
return R.ok(1, false);
} }
return R.ok(0, true); return R.ok(0, true);
} }
...@@ -122,9 +128,9 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -122,9 +128,9 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
} }
@Override @Override
public R<String> scanCode(String shaValue) { public R<String> scanCode(String shaValue, String securityCode) {
log.info("AntiFakeServiceImpl[]scanCode[]input.param.shaValue:" + shaValue); log.info("AntiFakeServiceImpl[]scanCode[]input.param.shaValue:" + shaValue);
if (StringUtils.isBlank(shaValue)) { if (StringUtils.isBlank(shaValue) || StringUtils.isBlank(securityCode)) {
return R.error("入参不能为空!"); return R.error("入参不能为空!");
} }
...@@ -134,6 +140,10 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -134,6 +140,10 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
return R.error("无效二维码"); return R.error("无效二维码");
} }
if (!securityCode.equals(antiFake.getSecurityCode())) {
return R.error("安全码不匹配!");
}
if (antiFake.getStatus() == 1) { if (antiFake.getStatus() == 1) {
antiFake.setScanNumber(antiFake.getScanNumber() + 1); antiFake.setScanNumber(antiFake.getScanNumber() + 1);
int count = antiFakeMapper.edit(antiFake); int count = antiFakeMapper.edit(antiFake);
...@@ -142,7 +152,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -142,7 +152,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
} }
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为非正品," + return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为非正品," +
"第一次扫描时间为:" + DateUtil.convertDateToStr(antiFake.getScanTime(), "yyyy-MM-dd HH:mm:ss") "第一次扫描时间为:" + DateUtil.convertDateToStr(antiFake.getScanTime(), "yyyy-MM-dd HH:mm:ss")
+ ",共扫描过" + antiFake.getScanNumber() + "码"); + ",共扫描过" + antiFake.getScanNumber() + "码");
} }
antiFake.setStatus(1); antiFake.setStatus(1);
...@@ -154,7 +164,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -154,7 +164,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
} }
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为正品," + return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为正品," +
"第一次扫描时间为:" + DateUtil.convertDateToStr(antiFake.getScanTime(), "yyyy-MM-dd HH:mm:ss") "第一次扫描时间为:" + DateUtil.convertDateToStr(antiFake.getScanTime(), "yyyy-MM-dd HH:mm:ss")
+ ",共扫描过" + antiFake.getScanNumber() + "码"); + ",共扫描过" + antiFake.getScanNumber() + "码");
} }
@Override @Override
...@@ -195,6 +205,10 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -195,6 +205,10 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
//获取防伪二维码生产码 //获取防伪二维码生产码
List<AntiFake> result = antiFakeMapper.getProductNos(array); List<AntiFake> result = antiFakeMapper.getProductNos(array);
if (CollectionUtils.isEmpty(result)) {
return R.ok(0, true);
}
for (AntiFake anti : result) { for (AntiFake anti : result) {
String url = REQUEST_URL + anti.getShaValue(); String url = REQUEST_URL + anti.getShaValue();
anti.setShaValue(url); anti.setShaValue(url);
...@@ -207,12 +221,12 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i ...@@ -207,12 +221,12 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
// 使用java8新特性的stream流去处理数据,把空的数据过滤掉 // 使用java8新特性的stream流去处理数据,把空的数据过滤掉
List<ReportCodeVo> resultBo = result.stream().filter(Objects::nonNull) List<ReportCodeVo> resultBo = new ArrayList<>();
.map(t -> { for (AntiFake antiFake : result) {
return ReportCodeVo.builder() ReportCodeVo reportCodeVo = new ReportCodeVo();
.shaValue(t.getShaValue()) reportCodeVo.setShaValue(antiFake.getShaValue());
.build(); resultBo.add(reportCodeVo);
}).collect(Collectors.toList()); }
//创建文件名称 //创建文件名称
long lon = System.currentTimeMillis(); long lon = System.currentTimeMillis();
......
...@@ -8,6 +8,7 @@ import cn.wisenergy.service.app.AntiFakeService; ...@@ -8,6 +8,7 @@ import cn.wisenergy.service.app.AntiFakeService;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -36,15 +37,19 @@ public class AntiFakeController { ...@@ -36,15 +37,19 @@ public class AntiFakeController {
} }
@ApiOperation(value = "扫描防伪二维码", notes = "扫描防伪二维码", httpMethod = "POST") @ApiOperation(value = "扫描防伪二维码", notes = "扫描防伪二维码", httpMethod = "POST")
@ApiImplicitParams({
@ApiImplicitParam(name = "shaValue", value = "防伪码", dataType = "String",required = true),
@ApiImplicitParam(name = "securityCode", value = "安全码", dataType = "String",required = true)
})
@ApiImplicitParam(name = "shaValue", value = "防伪码", dataType = "String") @ApiImplicitParam(name = "shaValue", value = "防伪码", dataType = "String")
@PostMapping("/admin/scanCode") @PostMapping("/admin/scanCode")
public R<String> scanCode(String shaValue) { public R<String> scanCode(String shaValue,String securityCode) {
log.info("shop-mall[]AntiFakeController[]scanCode[]input.param.shaValue:" + shaValue); log.info("shop-mall[]AntiFakeController[]scanCode[]input.param.shaValue:" + shaValue,securityCode);
if (StringUtils.isBlank(shaValue)) { if (StringUtils.isBlank(shaValue)) {
return R.error("入参为空!"); return R.error("入参为空!");
} }
return antiFakeService.scanCode(shaValue); return antiFakeService.scanCode(shaValue,securityCode);
} }
......
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