Commit 294f62fc authored by licc's avatar licc

二维码接口优化

parent 208f9517
......@@ -83,6 +83,20 @@ public interface AntiFakeMapper extends BaseMapper<AntiFake> {
*/
List<AntiFake> getProductNos(List<Long> list);
int updateUseStatus(List<Long> list);
/**
* 根据主键id,获取二维码集合
*
* @param batchNumber 批次号
* @return ProductNos
*/
List<AntiFake> getBatchNumber(@Param("batchNumber") String batchNumber);
/**
* 修改二维码使用状态
*
* @param batchNumber 批次号
* @return size
*/
int updateUseStatus(@Param("batchNumber") String batchNumber);
}
......@@ -93,10 +93,8 @@
use_status=1
</set>
<where>
id IN
<foreach collection="list" index="index" item="id" separator="," open="(" close=")">
#{id}
</foreach>
use_status=1
and batch_number=#{batchNumber}
</where>
</update>
......@@ -133,7 +131,9 @@
from
<include refid="table"/>
<where>
use_status=0
<if test="useStatus != null">
use_status=#{useStatus}
</if>
</where>
</select>
......@@ -143,7 +143,9 @@
from
<include refid="table"/>
<where>
use_status=0
<if test="useStatus != null">
use_status=#{useStatus}
</if>
order by create_time desc
limit #{startNum},#{endNum}
</where>
......@@ -173,5 +175,16 @@
</where>
</select>
<select id="getBatchNumber" resultMap="antiMap">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
use_status=0
and batch_number=#{batchNumber}
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -22,6 +22,8 @@ public class AntiFakeQuery {
@ApiModelProperty(value = "页条数", name = "pageSize")
private Integer pageSize;
@ApiModelProperty(value = "使用状态 : 0:未使用 1:已使用", name = "useStatus")
private Integer useStatus;
private Integer startNum;
......
......@@ -23,10 +23,10 @@ public class AntiFakeManger {
private ProductMapper productMapper;
@Transactional(rollbackFor = Exception.class)
public Boolean updateAntiFake(List<Long> array) {
public Boolean updateAntiFake(String batchNumber) {
//修改二维码使用状态
int updateUseStatus = antiFakeMapper.updateUseStatus(array);
return updateUseStatus == array.size();
int updateUseStatus = antiFakeMapper.updateUseStatus(batchNumber);
return updateUseStatus > 0;
}
/**
......
......@@ -28,15 +28,6 @@ public interface AntiFakeService {
*/
R<Boolean> createCode(CreateCodeVo codeVo) throws ParseException;
/**
* 测试二维码图片上传到服务器
*
* @return 1
* @throws Exception 异常
*/
R<String> uploadImage() throws Exception;
/**
* 扫描防伪二维码
*
......@@ -58,11 +49,11 @@ public interface AntiFakeService {
/**
* 导出生成二维码的字符串
*
* @param str "1,2,3,4,5,6,7,8,9,"
* @param batchNumber 批次号
* @param response 响应
* @return
* @return true or false
*/
R<Boolean> report(String str, HttpServletResponse response);
R<Boolean> report(String batchNumber, HttpServletResponse response);
void exportReceivable(String str, HttpServletResponse response);
}
......@@ -120,14 +120,6 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
return R.ok(0, true);
}
@Override
public R<String> uploadImage() throws Exception {
log.info("上传二维码防伪图测试");
//生成二维码
String url = QRCodeUtils.encode("2021-04022", DEST_PATH);
return R.ok(url);
}
@Override
public R<String> scanCode(String shaValue, String securityCode) {
log.info("AntiFakeServiceImpl[]scanCode[]input.param.shaValue:" + shaValue);
......@@ -138,11 +130,11 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
//获取二维码信息
AntiFake antiFake = antiFakeMapper.getByShaValue(shaValue);
if (null == antiFake) {
return R.error("无效二维码");
return R.ok("防伪码号" + shaValue + "的产品为非正品!");
}
if (!securityCode.equals(antiFake.getSecurityCode())) {
return R.error("安全码不匹配!");
return R.ok("溯源码不匹配,请重新输入!");
}
if (antiFake.getStatus() == 1) {
......@@ -151,7 +143,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
if (count == 0) {
return R.error("扫描失败!");
}
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为正品," +
return R.ok("防伪码号" + antiFake.getShaValue() + "的产品为正品," +
"第一次扫描时间为:" + DateUtil.convertDateToStr(antiFake.getScanTime(), "yyyy-MM-dd HH:mm:ss")
+ ",共扫描过" + antiFake.getScanNumber() + "次码");
}
......@@ -178,6 +170,9 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
pageHandle(query);
Map<String, Object> map = new HashMap<>(8);
if (null != query.getUseStatus()) {
map.put("useStatus", query.getUseStatus());
}
int total = antiFakeMapper.count(map);
map.put("startNum", query.getStartNum());
......@@ -192,20 +187,14 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
}
@Override
public R<Boolean> report(String str, HttpServletResponse response) {
log.info("AntiFakeServiceImpl[]report[]input.param.str:" + str);
if (StringUtils.isBlank(str)) {
public R<Boolean> report(String batchNumber, HttpServletResponse response) {
log.info("AntiFakeServiceImpl[]report[]input.param.batchNumber:" + batchNumber);
if (StringUtils.isBlank(batchNumber)) {
return R.error("入参不能为空!");
}
//把字符转化为数字
List<Long> array = StringUtil.strToLongArray(str);
if (CollectionUtils.isEmpty(array)) {
return R.ok(false);
}
//获取防伪码
List<AntiFake> result = antiFakeMapper.getProductNos(array);
List<AntiFake> result = antiFakeMapper.getBatchNumber(batchNumber);
if (CollectionUtils.isEmpty(result)) {
return R.ok(0, true);
}
......@@ -231,8 +220,9 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
// sheet名称
EasyExcel.write(response.getOutputStream(), AntiFake.class).sheet(Long.toString(lon)).doWrite(resultBo);
//修改二维码使用状态
boolean bool = antiFakeManger.updateAntiFake(array);
boolean bool = antiFakeManger.updateAntiFake(batchNumber);
if (!bool) {
return R.error("更新二维码使用状态失败!");
}
......@@ -244,7 +234,7 @@ public class AntiFakeServiceImpl extends ServiceImpl<AntiFakeMapper, AntiFake> i
@Override
public void exportReceivable(String str, HttpServletResponse response) {
if (StringUtils.isBlank(str)){
if (StringUtils.isBlank(str)) {
return;
}
......
......@@ -66,27 +66,16 @@ public class AntiFakeController {
}
@ApiOperation(value = "导出二维码", notes = "获取防伪二维码分页列表", httpMethod = "GET")
@ApiImplicitParam(name = "ids", value = " 二维码主键id :\"1,2,3,4,5,6,7,8,9,\"", dataType = "String")
@ApiImplicitParam(name = "batchNumber", value = "批次号", 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)) {
public R<Boolean> report(String batchNumber, HttpServletResponse response) {
log.info("shop-mall[]AntiFakeController[]report[]input.param.batchNumber:" + batchNumber);
if (StringUtils.isBlank(batchNumber)) {
return R.error("入参为空!");
}
return antiFakeService.report(ids, response);
return antiFakeService.report(batchNumber, response);
}
// @ApiOperation(value = "导出二维码", notes = "获取防伪二维码分页列表", httpMethod = "GET")
// @ApiImplicitParam(name = "ids", value = " 二维码主键id :\"1,2,3,4,5,6,7,8,9,\"", dataType = "String")
// @GetMapping("admin/antiFakeService")
// public void antiFakeService(String ids, HttpServletResponse response) {
// log.info("shop-mall[]AntiFakeController[]antiFakeService[]input.param.ids:" + ids);
// if (StringUtils.isBlank(ids)) {
// return ;
// }
//
// antiFakeService.exportReceivable(ids, response);
// }
}
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