Commit 294f62fc authored by licc's avatar licc

二维码接口优化

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