Commit d6ba22fa authored by licc's avatar licc

二维码实现

parent 830fe74e
......@@ -122,11 +122,6 @@
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
......@@ -175,6 +170,8 @@
<artifactId>druid</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
</dependencyManagement>
......
......@@ -26,8 +26,7 @@ import java.util.*;
@Component("springUtils")
@Lazy(false)
public final class StringUtil implements ApplicationContextAware,
DisposableBean {
DisposableBean {
/**
......@@ -565,15 +564,15 @@ public final class StringUtil implements ApplicationContextAware,
* @param s 入参
* @return 结果
*/
public static List<Integer> strToArray(String s) {
public static List<Long> strToLongArray(String s) {
if (StringUtils.isEmpty(s)) {
return new ArrayList<>();
}
List<Integer> result = new ArrayList<>();
List<Long> result = new ArrayList<>();
String[] str = s.split(",");
for (String string : str) {
result.add(Integer.valueOf(string));
result.add(Long.valueOf(string));
}
return result;
}
......@@ -591,7 +590,8 @@ public final class StringUtil implements ApplicationContextAware,
/**
* 不可实例化
*/
private StringUtil() { }
private StringUtil() {
}
// public void setApplicationContext(ApplicationContext applicationContext) {
// SpringUtils.applicationContext = applicationContext;
......@@ -613,8 +613,7 @@ public final class StringUtil implements ApplicationContextAware,
/**
* 获取实例
*
* @param name
* Bean名称
* @param name Bean名称
* @return 实例
*/
@SuppressWarnings("deprecation")
......@@ -626,10 +625,8 @@ public final class StringUtil implements ApplicationContextAware,
/**
* 获取实例
*
* @param name
* Bean名称
* @param type
* Bean类型
* @param name Bean名称
* @param type Bean类型
* @return 实例
*/
@SuppressWarnings("deprecation")
......@@ -641,25 +638,26 @@ public final class StringUtil implements ApplicationContextAware,
/**
* 根据传入的字符串和切割方式返回一个Long的集合
*
* @param s
* @param cut
* @return
*/
public static Set<Long> string2LongSet(String s, String cut) {
if(StringUtils.isBlank(s) ){
if (StringUtils.isBlank(s)) {
return null;
}
if(StringUtils.isBlank(cut)){
if (StringUtils.isBlank(cut)) {
cut = Constants.Connnector.COMMA_;
}
String s_temp = s.trim();
String[] arr = s_temp.split(cut);
Set<Long> list = new HashSet<Long>();
if(arr==null || arr.length<=0){
if (arr == null || arr.length <= 0) {
return null;
}
for(String l : arr){
if(!StringUtils.isBlank(l)){
for (String l : arr) {
if (!StringUtils.isBlank(l)) {
try {
list.add(Long.parseLong(l));
} catch (NumberFormatException e) {
......@@ -670,8 +668,10 @@ public final class StringUtil implements ApplicationContextAware,
}
return list;
}
/**
* 根据传入的字符串和切割方式返回一个object的集合
*
* @param s
* @param cut
* @return
......@@ -679,33 +679,35 @@ public final class StringUtil implements ApplicationContextAware,
* @date:
*/
public static List<String> string2StringList(String s, String cut) {
if(StringUtils.isBlank(s)){
if (StringUtils.isBlank(s)) {
return null;
}
if(StringUtils.isBlank(cut)){
if (StringUtils.isBlank(cut)) {
cut = Constants.Connnector.COMMA_;
}
String s_temp = s.trim();
String[] arr = s_temp.split(cut);
List<String> list = new ArrayList<String>();
if(arr==null || arr.length<=0){
if (arr == null || arr.length <= 0) {
return null;
}
for(String l : arr){
if(!StringUtils.isBlank(l)){
for (String l : arr) {
if (!StringUtils.isBlank(l)) {
list.add(l);
}
}
return list;
}
/**
* 根据出入的参数创建一个key
*
* @return 如果参数为空,那么返回null
*/
public static String formatKeys(String ... args){
if (args != null && args.length > 0){
public static String formatKeys(String... args) {
if (args != null && args.length > 0) {
StringBuilder key = new StringBuilder();
for (String s: args){
for (String s : args) {
key.append(s).append(Constants.Connnector.UNDERLINE);
}
return key.toString();
......@@ -715,12 +717,13 @@ public final class StringUtil implements ApplicationContextAware,
/**
* 根据出入的参数创建一个Redis key,自动拼接前缀
*
* @return 如果参数为空,那么返回null
*/
public static String formatKeyWithPrefix(String ... args){
if (args != null && args.length > 0){
StringBuffer key=new StringBuffer("");
for (String s: args){
public static String formatKeyWithPrefix(String... args) {
if (args != null && args.length > 0) {
StringBuffer key = new StringBuffer("");
for (String s : args) {
key.append(s).append(Constants.Connnector.COLON);
}
return key.toString();
......@@ -731,35 +734,38 @@ public final class StringUtil implements ApplicationContextAware,
/**
* Description: 创建一个简单的map对象
*
* @param key
* @param value
* @return
* @Author
* @since
*/
public static Map<String,Object> createSimpleMap(String key, Object value){
Map<String,Object> conditions = null;
if(key !=null && !key.equals("")){
conditions = new HashMap<String,Object>();
public static Map<String, Object> createSimpleMap(String key, Object value) {
Map<String, Object> conditions = null;
if (key != null && !key.equals("")) {
conditions = new HashMap<String, Object>();
conditions.put(key, value);
}
return conditions;
}
/***
* 判断字符串是否为空
* @param temp
* @return
*/
public static boolean isBlank(String temp){
public static boolean isBlank(String temp) {
return StringUtils.isBlank(temp);
}
/**
* 返回一个没有中划线的32位字符串
*
* @return
*/
public static String createToken(){
return UUID.randomUUID().toString().replace("-","");
public static String createToken() {
return UUID.randomUUID().toString().replace("-", "");
}
......
......@@ -46,11 +46,19 @@ public interface AntiFakeMapper extends BaseMapper<AntiFake> {
/**
* 通过产品编号 获取二维码信息
*
* @param productNo
* @return
* @param productNo 产品编号
* @return 二维码信息
*/
AntiFake getByProductNo(@Param("productNo") String productNo);
/**
* 通过防伪码 获取二维码信息
*
* @param shaValue 防伪码
* @return 二维码信息
*/
AntiFake getByShaValue(@Param("shaValue") String shaValue);
/**
* 根据条件获取二维码数量
*
......@@ -67,4 +75,14 @@ public interface AntiFakeMapper extends BaseMapper<AntiFake> {
*/
List<AntiFake> getList(Map<String, Object> map);
/**
* 根据主键id,获取生产码
*
* @param list 主键ids
* @return ProductNos
*/
List<AntiFake> getProductNos(List<Long> list);
int updateUseStatus(List<Long> list);
}
......@@ -5,11 +5,21 @@
<id column="id" property="id"/>
<result column="product_no" property="productNo"/>
<result column="batch_number" property="batchNumber"/>
<result column="batch_no" property="batchNo"/>
<result column="sha_value" property="shaValue"/>
<result column="produce_time" property="produceTime"/>
<result column="scan_time" property="scanTime"/>
<result column="status" property="status"/>
<result column="url" property="url"/>
<result column="use_status" property="useStatus"/>
<result column="scan_number" property="scanNumber"/>
<result column="brand" property="brand"/>
<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>
......@@ -24,25 +34,41 @@
</sql>
<sql id="cols_exclude_id">
product_no,batch_number,batch_no,produce_time,scan_time,status,url,create_time,update_time
product_no,batch_number,sha_value,produce_time,scan_time,status,use_status,scan_number,brand,product_country,
valid_time, company_name,company_address,company_url,tracking_number,logistics_url,record_number,
create_time,update_time
</sql>
<sql id="vals">
#{productNo},#{batchNumber},#{batchNo},#{produceTime},#{scanTime},#{status},#{url},now(),now()
#{productNo},#{batchNumber},#{shaValue},#{produceTime},#{scanTime},#{status},#{useStatus},#{scanNumber},#{brand},
#{productCountry}, #{validTime},#{companyName},#{companyAddress},#{companyUrl},#{trackingNumber},#{logisticsUrl},
#{recordNumber},now(),now()
</sql>
<sql id="createsVal">
#{i.productNo},#{i.batchNumber},#{i.batchNo},#{i.produceTime},#{i.scanTime},#{i.status},#{i.url},now(),now()
#{i.productNo},#{i.batchNumber},#{i.shaValue},#{i.produceTime},#{i.scanTime},#{i.status},#{i.useStatus},
#{i.scanNumber},#{i.brand},#{i.productCountry}, #{i.validTime},#{i.companyName},#{i.companyAddress},
#{i.companyUrl},#{i.trackingNumber},#{i.logisticsUrl}, #{i.recordNumber},now(),now()
</sql>
<sql id="updateCondition">
<if test="productNo != null">product_no = #{productNo},</if>
<if test="batchNumber != null">batch_number = #{batchNumber},</if>
<if test="batchNo != null">batch_no = #{batchNo},</if>
<if test="shaValue != null">sha_value = #{shaValue},</if>
<if test="produceTime != null">produce_time = #{produceTime},</if>
<if test="scanTime != null">scan_time = #{scanTime},</if>
<if test="status != null">status = #{status},</if>
<if test="url != null">url = #{url},</if>
<if test="useStatus != null">use_status = #{useStatus},</if>
<if test="scaNumber != null">sca_number = #{scaNumber},</if>
<if test="brand != null">brand = #{brand},</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>
......@@ -50,11 +76,21 @@
<if test="id != null">id = #{id}</if>
<if test="productNo != null">and product_no = #{productNo}</if>
<if test="batchNumber != null">and batch_number = #{batchNumber}</if>
<if test="batchNo != null">and anti_fake_no = #{batchNo}</if>
<if test="shaValue != null">and sha_value = #{shaValue}</if>
<if test="produceTime != null">and produce_time = #{produceTime}</if>
<if test="scanTime != null">and scan_time = #{scanTime}</if>
<if test="status != null">and status = #{status}</if>
<if test="url != null">and url = #{url}</if>
<if test="useStatus != null">and use_status = #{useStatus}</if>
<if test="scaNumber != null">and sca_number = #{scaNumber}</if>
<if test="brand != null">and brand = #{brand}</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>
......@@ -79,6 +115,20 @@
</where>
</update>
<update id="updateUseStatus">
UPDATE
<include refid="table"/>
<set>
use_status=1
</set>
<where>
id IN
<foreach collection="list" index="index" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</update>
<select id="getByBestBigNumber" resultType="java.lang.String">
select MAX(batch_number)
from
......@@ -112,7 +162,7 @@
from
<include refid="table"/>
<where>
status=0
use_status=0
</where>
</select>
......@@ -122,11 +172,34 @@
from
<include refid="table"/>
<where>
status=0
use_status=0
order by create_time desc
limit #{startNum},#{endNum}
</where>
</select>
<select id="getProductNos" resultType="cn.wisenergy.model.app.AntiFake">
select product_no
from
<include refid="table"/>
<where>
use_status=0
and id IN
<foreach collection="list" index="index" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>
<select id="getByShaValue" resultType="cn.wisenergy.model.app.AntiFake">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
sha_value=#{shaValue}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -27,9 +27,13 @@
<version>1.18.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${moduleVersion.wisenergy-model}</finalName>
</build>
......
package cn.wisenergy.model.app;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
......@@ -14,7 +18,11 @@ import java.util.Date;
*/
@Data
@ApiModel("AntiFake")
public class AntiFake {
@NoArgsConstructor
@AllArgsConstructor
@ExcelIgnoreUnannotated
public class AntiFake implements Serializable {
private static final long serialVersionUID = 916503632222291721L;
/**
* 主键id
*/
......@@ -35,15 +43,15 @@ public class AntiFake {
private String batchNumber;
/**
* 编号
* 防伪码
*/
@ApiModelProperty(value = "编号", name = "batchNo")
private String batchNo;
@ApiModelProperty(value = "防伪码", name = "shaValue")
private String shaValue;
/**
* 生日期 yyyy-MM-dd
* 生日期 yyyy-MM-dd
*/
@ApiModelProperty(value = "生日期 yyyy-MM-dd", name = "produceTime")
@ApiModelProperty(value = "生日期 yyyy-MM-dd", name = "produceTime")
private String produceTime;
/**
......@@ -58,11 +66,68 @@ public class AntiFake {
@ApiModelProperty(value = "状态 : 0:未扫描 1:已扫描", name = "status")
private Integer status;
@ApiModelProperty(value = "使用状态 : 0:未使用 1:已使用", name = "useStatus")
private Integer useStatus;
/**
* 扫描次数
*/
@ApiModelProperty(value = "扫描次数", name = "scanNumber")
private Integer scanNumber;
/**
* 品牌
*/
@ApiModelProperty(value = "品牌", name = "brand")
private String brand;
/**
* 原产国
*/
@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;
/**
* 二维码图片url
* 海关进境货物备案编号
*/
@ApiModelProperty(value = "二维码图片url", name = "url")
private String url;
@ApiModelProperty(value = "海关进境货物备案编号", name = "recordNumber")
private String recordNumber;
private Date createTime;
......
package cn.wisenergy.model.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author 86187
*/
@Data
@ApiModel("CreateCodeVo")
public class CreateCodeVo {
/**
* 生成二维码数量
*/
@ApiModelProperty(value = "生成二维码数量", name = "生成二维码数量")
private Integer number;
/**
* 产品编号
*/
@ApiModelProperty(value = "产品编号", name = "productNo")
private String productNo;
/**
* 防伪码
*/
@ApiModelProperty(value = "防伪码", name = "shaValue")
private String shaValue;
/**
* 生产日期 yyyy-MM-dd
*/
@ApiModelProperty(value = "生产日期 yyyy-MM-dd", name = "produceTime",required = true)
private String produceTime;
/**
* 原产国
*/
@ApiModelProperty(value = "原产国", name = "productCountry")
private String productCountry;
/**
* 有效时间
*/
@ApiModelProperty(value = "有效时间", name = "validTime")
private Date validTime;
/**
* 货运单号
*/
@ApiModelProperty(value = "货运单号", name = "trackingNumber")
private String trackingNumber;
/**
* 物流轨迹查询平台
*/
@ApiModelProperty(value = "物流轨迹查询平台", name = "logisticsUrl")
private String logisticsUrl;
/**
* 海关进境货物备案编号
*/
@ApiModelProperty(value = "海关进境货物备案编号", name = "recordNumber")
private String recordNumber;
}
package cn.wisenergy.model.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author 86187
*/
@Data
@Builder
@ApiModel(value = "AntiFake")
@NoArgsConstructor
@AllArgsConstructor
@ExcelIgnoreUnannotated
public class ReportCodeVo implements Serializable {
private static final long serialVersionUID = 3057827920613773950L;
@ApiModelProperty(value = "防伪码",name = "shaValue")
@ExcelProperty(value = "防伪码")
private String shaValue;
}
package cn.wisenergy.service.Manager;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.AntiFakeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author 86187
*/
@Component
public class AntiFakeManger {
@Autowired
private AntiFakeMapper antiFakeMapper;
@Transactional(rollbackFor = Exception.class)
public Boolean updateAntiFake(List<Long> array) {
//修改二维码使用状态
int updateUseStatus = antiFakeMapper.updateUseStatus(array);
return updateUseStatus == array.size();
}
}
......@@ -3,9 +3,13 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AntiFake;
import cn.wisenergy.model.dto.AntiFakeQuery;
import cn.wisenergy.model.dto.CreateCodeVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author 86187
......@@ -18,20 +22,11 @@ public interface AntiFakeService {
/**
* 创建防伪二维码
*
* @param number 二维码数量
* @param codeVo 二维码信息
* @return true or false
* @throws Exception 异常
*/
R<Boolean> createCode(Integer number) throws Exception;
R<Boolean> createCode(CreateCodeVo codeVo);
/**
* 解析二维码
*
* @param file 二维码
* @return 结果
* @throws Exception 异常
*/
R<String> decode(MultipartFile file) throws Exception;
/**
* 测试二维码图片上传到服务器
......@@ -56,4 +51,14 @@ public interface AntiFakeService {
* @return 列表
*/
R<PageInfo<AntiFake>> getList(AntiFakeQuery query);
/**
* 导出生成二维码的字符串
*
* @param str "1,2,3,4,5,6,7,8,9,"
* @param response 响应
* @return
*/
R<Boolean> report(String str, HttpServletResponse response);
}
package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.constant.CommonAttributes;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.mapper.*;
import cn.wisenergy.model.app.*;
import cn.wisenergy.model.dto.AccountInfoQuery;
import cn.wisenergy.model.dto.MemberPercentQuery;
import cn.wisenergy.model.enums.*;
import cn.wisenergy.model.vo.TeamPerformanceSortVo;
import cn.wisenergy.service.Manager.PublicManager;
import cn.wisenergy.service.app.AccountService;
import cn.wisenergy.service.Manager.AccountManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
......
......@@ -3,25 +3,32 @@ package cn.wisenergy.service.app.impl;
import cn.wisenergy.common.constant.CommonAttributes;
import cn.wisenergy.common.utils.DateUtil;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.common.utils.StringUtil;
import cn.wisenergy.mapper.AntiFakeMapper;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.AntiFake;
import cn.wisenergy.model.dto.AccountInfoQuery;
import cn.wisenergy.model.dto.AntiFakeQuery;
import cn.wisenergy.model.dto.CreateCodeVo;
import cn.wisenergy.model.vo.ReportCodeVo;
import cn.wisenergy.service.Manager.AntiFakeManger;
import cn.wisenergy.service.app.AntiFakeService;
import cn.wisenergy.service.util.CodeUtils;
import cn.wisenergy.service.util.FileUtils;
import cn.wisenergy.service.util.QRCodeUtils;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author 86187
......@@ -31,15 +38,28 @@ import java.util.*;
public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> implements AntiFakeService {
private static final String DEST_PATH = "/opt/upload/video";
private static final String REQUEST_URL = "http://localhost:81/shop-mall/admin/scanCode?shaValue=";
@Autowired
private AntiFakeMapper antiFakeMapper;
@Autowired
private AntiFakeManger antiFakeManger;
@Override
public R<Boolean> createCode(Integer number) throws Exception {
log.info("AntiFakeServiceImpl[]createCode[]input.param.number:" + number);
if (null == number) {
public R<Boolean> createCode(CreateCodeVo codeVo) {
log.info("AntiFakeServiceImpl[]createCode[]input.param.codeVo:" + codeVo);
if (null == codeVo || StringUtils.isBlank(codeVo.getProduceTime())) {
return R.error("入参不能为空!");
}
int number;
if (null == codeVo.getNumber()) {
number = 1000;
} else {
number = codeVo.getNumber();
}
//获取最大批次号
String batch = antiFakeMapper.getByBestBigNumber();
String batchNumber = "";
......@@ -57,18 +77,28 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
for (int i = 0; i < number; i++) {
int batchNo = initBatchNo + i + 1;
AntiFake antiFake = new AntiFake();
antiFake.setBatchNo(String.valueOf(batchNo));
antiFake.setBatchNumber(batchNumber);
antiFake.setProduceTime(realTime);
//生成产品编码
String productNo = CodeUtils.createProductNo(batchNumber, antiFake.getBatchNo());
String productNo = CodeUtils.createProductNo(batchNumber, String.valueOf(batchNo), codeVo.getProduceTime());
antiFake.setProductNo(productNo);
antiFake.setStatus(0);
antiFake.setUseStatus(0);
//生成二维码
String url = QRCodeUtils.encode(productNo, DEST_PATH);
antiFake.setUrl(url);
String sha = DigestUtils.sha1Hex(productNo).substring(0, 16);
antiFake.setShaValue(sha);
antiFake.setScanNumber(0);
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());
list.add(antiFake);
}
......@@ -80,19 +110,6 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
return R.ok(0, true);
}
@Override
public R<String> decode(MultipartFile multipartFile) throws Exception {
log.info("AntiFakeServiceImpl[]decode[]input.param.multipartFile:" + multipartFile);
if (null == multipartFile) {
return R.error("入参为空");
}
File file = FileUtils.multipartFileToFile(multipartFile);
String result = QRCodeUtils.decode(file);
return R.ok(result);
}
@Override
public R<String> uploadImage() throws Exception {
log.info("上传二维码防伪图测试");
......@@ -102,30 +119,37 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
}
@Override
public R<String> scanCode(String produceNo) {
log.info("AntiFakeServiceImpl[]scanCode[]input.param.produceNo:" + produceNo);
if (StringUtils.isBlank(produceNo)) {
public R<String> scanCode(String shaValue) {
log.info("AntiFakeServiceImpl[]scanCode[]input.param.shaValue:" + shaValue);
if (StringUtils.isBlank(shaValue)) {
return R.error("入参不能为空!");
}
//获取二维码信息
AntiFake antiFake = antiFakeMapper.getByProductNo(produceNo);
AntiFake antiFake = antiFakeMapper.getByShaValue(shaValue);
if (null == antiFake) {
return R.error("无效二维码");
}
if (antiFake.getStatus() == 1) {
return R.ok("该产品防伪码已于" + antiFake.getScanTime() + "被扫描,批次号为:"
+ antiFake.getBatchNumber() + ",编号为:" + antiFake.getBatchNo() + "");
antiFake.setScanNumber(antiFake.getScanNumber() + 1);
int count = antiFakeMapper.edit(antiFake);
if (count == 0) {
return R.error("扫描失败!");
}
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为非正品," +
"第一次扫描时间为:" + antiFake.getScanTime() + ",共扫描过" + antiFake.getScanNumber() + "池码");
}
antiFake.setStatus(1);
antiFake.setScanTime(new Date());
antiFake.setScanNumber(antiFake.getScanNumber() + 1);
int count = antiFakeMapper.edit(antiFake);
if (count == 0) {
return R.error("扫描失败!");
}
return R.ok("该防伪二维码第一次被扫描!");
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为正品," +
"第一次扫描时间为:" + antiFake.getScanTime() + ",共扫描过" + antiFake.getScanNumber() + "池码");
}
@Override
......@@ -151,6 +175,58 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
return R.ok(info);
}
@Override
public R<Boolean> report(String str, HttpServletResponse response) {
log.info("AntiFakeServiceImpl[]report[]input.param.str:" + str);
if (StringUtils.isBlank(str)) {
return R.error("入参不能为空!");
}
//把字符转化为数字
List<Long> array = StringUtil.strToLongArray(str);
if (CollectionUtils.isEmpty(array)) {
return R.ok(false);
}
//获取防伪二维码生产码
List<AntiFake> result = antiFakeMapper.getProductNos(array);
for (AntiFake anti : result) {
String url = REQUEST_URL + anti.getShaValue();
anti.setShaValue(url);
}
//生成Excel
try {
// 设置内容格式 以及 编码方式
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 使用java8新特性的stream流去处理数据,把空的数据过滤掉
List<ReportCodeVo> resultBo = result.stream().filter(Objects::nonNull)
.map(t -> {
return ReportCodeVo.builder()
.shaValue(t.getShaValue())
.build();
}).collect(Collectors.toList());
//创建文件名称
long lon = System.currentTimeMillis();
response.setHeader("Content-disposition", "attachment;filename=" + lon + ".xlsx");
// sheet名称
EasyExcel.write(response.getOutputStream(), ReportCodeVo.class).sheet(Long.toString(lon)).doWrite(resultBo);
//修改二维码使用状态
boolean bool = antiFakeManger.updateAntiFake(array);
if (!bool) {
return R.error("更新二维码使用状态失败!");
}
return R.ok(0, true);
} catch (Exception e) {
return R.ok(1, false);
}
}
/**
* 分页处理方法
*
......@@ -172,4 +248,10 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
schemeVo.setPageNo(pageNum);
schemeVo.setPageSize(pageSize);
}
public static void main(String[] args) {
String str = "nishidamori2021042210000001100000091vfpsyib7";
String result = DigestUtils.sha1Hex(str);
System.out.println(result);
}
}
......@@ -14,9 +14,8 @@ public class CodeUtils {
private static final String VALUE = "nishidamori";
public static String createProductNo(String batchNumber, String batchNo) {
public static String createProductNo(String batchNumber, String batchNo, String produceTime) {
//产品编号 =固定值+生产时间+生产批次+编号+随机数+校验规则
String produceTime = DateUtil.getTime(new Date(), "yyyyMMdd");
String random = getRandom();
String ruleNumber = getVerifyNumber(batchNumber, batchNo, produceTime, random);
return VALUE + produceTime + batchNumber + batchNo + random + ruleNumber;
......
......@@ -3,6 +3,7 @@ package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AntiFake;
import cn.wisenergy.model.dto.AntiFakeQuery;
import cn.wisenergy.model.dto.CreateCodeVo;
import cn.wisenergy.service.app.AntiFakeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
......@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author 86187
......@@ -27,29 +29,23 @@ public class AntiFakeController {
@Autowired
private AntiFakeService antiFakeService;
@ApiOperation(value = "解析二维码", notes = "解析二维码", httpMethod = "POST")
@PostMapping(value = "/admin/decode", headers = "content-type=multipart/form-data")
public R<String> getByUserId(@RequestParam("file") MultipartFile file,
HttpServletRequest request) throws Exception {
return antiFakeService.decode(file);
}
@ApiOperation(value = "解析二维码", notes = "解析二维码", httpMethod = "POST")
@PostMapping(value = "/admin/create/code", headers = "content-type=multipart/form-data")
public R<Boolean> create(Integer number) throws Exception {
return antiFakeService.createCode(number);
@ApiOperation(value = "创建二维码", notes = "创建二维码", httpMethod = "POST")
@ApiImplicitParam(name = "codeVo", value = "二维码信息", dataType = "CreateCodeVo")
@PostMapping(value = "/admin/create/code")
public R<Boolean> create(@RequestBody CreateCodeVo codeVo) {
return antiFakeService.createCode(codeVo);
}
@ApiOperation(value = "扫描防伪二维码", notes = "扫描防伪二维码", httpMethod = "POST")
@ApiImplicitParam(name = "productNo", value = "产品编号", dataType = "String")
@ApiImplicitParam(name = "shaValue", value = "防伪码", dataType = "String")
@PostMapping("/admin/scanCode")
public R<String> scanCode(String productNo) {
log.info("shop-mall[]AntiFakeController[]scanCode[]input.param.productNo:" + productNo);
if (StringUtils.isBlank(productNo)) {
public R<String> scanCode(String shaValue) {
log.info("shop-mall[]AntiFakeController[]scanCode[]input.param.shaValue:" + shaValue);
if (StringUtils.isBlank(shaValue)) {
return R.error("入参为空!");
}
return antiFakeService.scanCode(productNo);
return antiFakeService.scanCode(shaValue);
}
......@@ -65,4 +61,16 @@ public class AntiFakeController {
return antiFakeService.getList(query);
}
@ApiOperation(value = "导出二维码", notes = "获取防伪二维码分页列表", httpMethod = "GET")
@ApiImplicitParam(name = "ids", value = " 二维码主键id :\"1,2,3,4,5,6,7,8,9,\"", dataType = "String")
@GetMapping("admin/report")
public R<Boolean> report(String ids, HttpServletResponse response) {
log.info("shop-mall[]AntiFakeController[]report[]input.param.ids:" + ids);
if (StringUtils.isBlank(ids)) {
return R.error("入参为空!");
}
return antiFakeService.report(ids, response);
}
}
......@@ -13,6 +13,7 @@ import javax.servlet.http.HttpServletRequest;
/**
* AOP日志
* @author 86187
*/
@Aspect
@Component
......
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