MesShipScanService.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.jeesite.modules.mes.service;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import com.jeesite.common.entity.Page;
  7. import com.jeesite.common.lang.StringUtils;
  8. import com.jeesite.common.service.CrudService;
  9. import com.jeesite.modules.mes.dao.MesShipScanDao;
  10. import com.jeesite.modules.mes.entity.MesShipScan;
  11. /**
  12. * 出货扫码校验记录Service
  13. * @author mes
  14. * @version 2026-06-10
  15. */
  16. @Service
  17. @Transactional(readOnly = true)
  18. public class MesShipScanService extends CrudService<MesShipScanDao, MesShipScan> {
  19. /** 校验长度(标签前 N 位 == 标识卡) 默认 15 */
  20. @Value("${mes.ship.scan.match.length:15}")
  21. private int matchLength;
  22. @Override
  23. public Page<MesShipScan> findPage(MesShipScan entity) {
  24. return super.findPage(entity);
  25. }
  26. @Override
  27. public List<MesShipScan> findList(MesShipScan entity) {
  28. return super.findList(entity);
  29. }
  30. @Override
  31. @Transactional(readOnly = false)
  32. public void save(MesShipScan entity) {
  33. super.save(entity);
  34. }
  35. @Override
  36. @Transactional(readOnly = false)
  37. public void delete(MesShipScan entity) {
  38. super.delete(entity);
  39. }
  40. /**
  41. * 安卓上传:扫码校验 + 落库
  42. * 规则:标签码前 N 位 == 标识卡完整内容
  43. * 一致或不一致都落库(方案C)
  44. *
  45. * @return 已保存的记录(含 matchState、failReason)
  46. */
  47. @Transactional(readOnly = false)
  48. public MesShipScan upload(String cardCode, String labelCode) {
  49. MesShipScan log = new MesShipScan();
  50. log.setCardCode(StringUtils.trimToEmpty(cardCode));
  51. log.setLabelCode(StringUtils.trimToEmpty(labelCode));
  52. // 取标签前 N 位
  53. String labelSeg = log.getLabelCode().length() >= matchLength
  54. ? log.getLabelCode().substring(0, matchLength)
  55. : log.getLabelCode();
  56. boolean match = StringUtils.isNotBlank(log.getCardCode())
  57. && StringUtils.equals(log.getCardCode(), labelSeg);
  58. if (match) {
  59. log.setMatchState(MesShipScan.MATCH_OK);
  60. log.setFailReason(null);
  61. } else {
  62. log.setMatchState(MesShipScan.MATCH_FAIL);
  63. log.setFailReason("二维码不一致:标识卡=" + log.getCardCode()
  64. + " 标签前" + matchLength + "位=" + labelSeg);
  65. }
  66. super.save(log);
  67. return log;
  68. }
  69. }