中控批量入库:SN与编码判重

This commit is contained in:
attiya 2025-10-15 16:52:59 +08:00
parent 7801e20d4b
commit 7a84f80e84
2 changed files with 22 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.ex.EbikeException; import com.cdzy.common.ex.EbikeException;
import com.cdzy.operations.model.vo.EbikeEcuInfoBatchVo; import com.cdzy.operations.model.vo.EbikeEcuInfoBatchVo;
import com.cdzy.operations.model.vo.EbikeEcuInfoVo; import com.cdzy.operations.model.vo.EbikeEcuInfoVo;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cdzy.operations.model.entity.EbikeEcuInfo; import com.cdzy.operations.model.entity.EbikeEcuInfo;
import com.cdzy.operations.mapper.EbikeEcuInfoMapper; import com.cdzy.operations.mapper.EbikeEcuInfoMapper;
@ -14,6 +15,8 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.cdzy.operations.model.entity.table.EbikeEcuInfoTableDef.EBIKE_ECU_INFO;
/** /**
* 中控基本信息 服务层实现 * 中控基本信息 服务层实现
* *
@ -35,6 +38,13 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
.ecuBrand(ebikeEcuInfo.getEcuBrand()) .ecuBrand(ebikeEcuInfo.getEcuBrand())
.createdBy(StpUtil.getLoginIdAsLong()) .createdBy(StpUtil.getLoginIdAsLong())
.build(); .build();
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ECU_INFO.ECU_SN.eq(ebikeEcuInfo.getEcuSn()))
.or(EBIKE_ECU_INFO.ECU_CODE.eq(ebikeEcuInfo.getEcuCode()));
EbikeEcuInfo ecuInfo = ebikeEcuInfoMapper.selectOneByQuery(queryWrapper);
if (ecuInfo != null) {
throw new EbikeException("中控信息存在重复");
}
ebikeEcuInfoMapper.insert(ebikeEcuInfoEntity); ebikeEcuInfoMapper.insert(ebikeEcuInfoEntity);
} }
@ -47,6 +57,9 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
if (ecuCodes.size() != ecuSns.size()) { if (ecuCodes.size() != ecuSns.size()) {
throw new EbikeException("中控编号与中控SN码数量不对应"); throw new EbikeException("中控编号与中控SN码数量不对应");
} }
if (ecuCodes.isEmpty()) {
throw new EbikeException("中控编号与中控SN码不能为空");
}
List<EbikeEcuInfo> list = new ArrayList<>(); List<EbikeEcuInfo> list = new ArrayList<>();
for (int i = 0; i < ecuCodes.size(); i++) { for (int i = 0; i < ecuCodes.size(); i++) {
EbikeEcuInfo ebikeEcuInfoEntity = EbikeEcuInfo.builder() EbikeEcuInfo ebikeEcuInfoEntity = EbikeEcuInfo.builder()
@ -58,6 +71,13 @@ public class EbikeEcuInfoServiceImpl extends ServiceImpl<EbikeEcuInfoMapper, Ebi
.build(); .build();
list.add(ebikeEcuInfoEntity); list.add(ebikeEcuInfoEntity);
} }
QueryWrapper queryWrapper = QueryWrapper.create()
.where(EBIKE_ECU_INFO.ECU_SN.in(ecuSns))
.or(EBIKE_ECU_INFO.ECU_CODE.in(ecuCodes));
long count = ebikeEcuInfoMapper.selectCountByQuery(queryWrapper);
if (count > 0) {
throw new EbikeException("中控信息存在重复");
}
saveBatch(list); saveBatch(list);
} }
} }

View File

@ -64,7 +64,7 @@ public class EbikeInventoryServiceImpl extends ServiceImpl<EbikeInventoryMapper,
recordMapper.insert(inventoryRecord); recordMapper.insert(inventoryRecord);
//该类型值存入字典 //该类型值存入字典
if (ebikeInventory.getInventoryType() == 1){ if (ebikeInventory.getInventoryType() == 1){
//TODO二维码生产 //电池二维码生产
EbikeBatteryInfoVo ebikeBatteryInfoVo =EbikeBatteryInfoVo.builder() EbikeBatteryInfoVo ebikeBatteryInfoVo =EbikeBatteryInfoVo.builder()
.operatorId(ebikeInventory.getOperatorId()) .operatorId(ebikeInventory.getOperatorId())
.batteryNum(ebikeInventory.getInventoryNum()) .batteryNum(ebikeInventory.getInventoryNum())