| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package com.jeesite.modules.mes.service;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.lang.StringUtils;
- import com.jeesite.common.service.CrudService;
- import com.jeesite.modules.mes.dao.MesShipScanDao;
- import com.jeesite.modules.mes.entity.MesShipScan;
- /**
- * 出货扫码校验记录Service
- * @author mes
- * @version 2026-06-10
- */
- @Service
- @Transactional(readOnly = true)
- public class MesShipScanService extends CrudService<MesShipScanDao, MesShipScan> {
- /** 校验长度(标签前 N 位 == 标识卡) 默认 15 */
- @Value("${mes.ship.scan.match.length:15}")
- private int matchLength;
- @Override
- public Page<MesShipScan> findPage(MesShipScan entity) {
- return super.findPage(entity);
- }
- @Override
- public List<MesShipScan> findList(MesShipScan entity) {
- return super.findList(entity);
- }
- @Override
- @Transactional(readOnly = false)
- public void save(MesShipScan entity) {
- super.save(entity);
- }
- @Override
- @Transactional(readOnly = false)
- public void delete(MesShipScan entity) {
- super.delete(entity);
- }
- /**
- * 安卓上传:扫码校验 + 落库
- * 规则:标签码前 N 位 == 标识卡完整内容
- * 一致或不一致都落库(方案C)
- *
- * @return 已保存的记录(含 matchState、failReason)
- */
- @Transactional(readOnly = false)
- public MesShipScan upload(String cardCode, String labelCode) {
- MesShipScan log = new MesShipScan();
- log.setCardCode(StringUtils.trimToEmpty(cardCode));
- log.setLabelCode(StringUtils.trimToEmpty(labelCode));
- // 取标签前 N 位
- String labelSeg = log.getLabelCode().length() >= matchLength
- ? log.getLabelCode().substring(0, matchLength)
- : log.getLabelCode();
- boolean match = StringUtils.isNotBlank(log.getCardCode())
- && StringUtils.equals(log.getCardCode(), labelSeg);
- if (match) {
- log.setMatchState(MesShipScan.MATCH_OK);
- log.setFailReason(null);
- } else {
- log.setMatchState(MesShipScan.MATCH_FAIL);
- log.setFailReason("二维码不一致:标识卡=" + log.getCardCode()
- + " 标签前" + matchLength + "位=" + labelSeg);
- }
- super.save(log);
- return log;
- }
- }
|