|
@@ -73,78 +73,63 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
Long waterBatchId = waterTagVo.getWaterBatchId();
|
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
|
|
|
+ // 获取批次详情
|
|
|
+ WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
+ Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
+
|
|
|
// 标签数量
|
|
|
int num = waterTagVo.getNum() == null || waterTagVo.getNum() < 1 ? 1 : waterTagVo.getNum();
|
|
|
|
|
|
+ // 获取最新添加标签
|
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
|
|
|
List<WaterTag> waterTagList = new ArrayList<>();
|
|
|
-
|
|
|
- if (waterTag != null) {
|
|
|
- Integer number = waterTag.getNumber();
|
|
|
- for (int i = 1; i <= num; i++) {
|
|
|
- WaterTag waterTagTemp = createWaterTag(waterTag.getMaterialId(), quantity, waterTag.getPrice(),
|
|
|
- waterTag.getContractId(), waterTag.getContractDetailsId(),
|
|
|
- waterTag.getWaterBatchId(), waterTag.getWaterBatchCode(), number + i);
|
|
|
- waterTagList.add(waterTagTemp);
|
|
|
- }
|
|
|
- } else {
|
|
|
- WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
- for (int i = 1; i <= num; i++) {
|
|
|
- WaterTag waterTagTemp = createWaterTag(waterBatch.getMaterialId(), quantity, waterBatch.getPrice(),
|
|
|
- waterBatch.getContractId(), waterBatch.getContractDetailsId(),
|
|
|
- waterBatch.getId(), waterBatch.getCode(), i);
|
|
|
- waterTagList.add(waterTagTemp);
|
|
|
- }
|
|
|
-
|
|
|
- // 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
|
- updateContractProcessed(waterBatch.getContractId());
|
|
|
+ int number = waterTag != null ? waterTag.getNumber() : 0;
|
|
|
+ for (int i = 1; i <= num; i++) {
|
|
|
+ waterTagList.add(createWaterTag(waterBatch, quantity, number + i));
|
|
|
}
|
|
|
saveBatch(waterTagList);
|
|
|
+
|
|
|
+ // 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
|
+ updateContractProcessed(waterBatch);
|
|
|
+
|
|
|
+ // 更新批次标签总个数以及标签总米数
|
|
|
+ waterBatchService.editTagCountAndQuantitySum(waterBatch, num, quantity.multiply(BigDecimal.valueOf(num)));
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public void uploadTag(MultipartFile file, Long waterBatchId) {
|
|
|
+ public synchronized void uploadTag(MultipartFile file, Long waterBatchId) {
|
|
|
|
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
|
|
|
// 解析excel文件中的数据
|
|
|
List<BigDecimal> quantityList = getQuantityListByExcel(file);
|
|
|
- Assert.gtZero(quantityList.size(), "导入标签数量为空");
|
|
|
+
|
|
|
+ // 获取批次详情
|
|
|
+ WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
+ Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
|
|
|
// 获取此批次最新标签
|
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
|
|
|
- List<WaterTag> waterTagList = new ArrayList<>();
|
|
|
- if (waterTag != null) {
|
|
|
- Integer number = waterTag.getNumber() + 1;
|
|
|
-
|
|
|
- for (BigDecimal quantity : quantityList) {
|
|
|
- WaterTag waterTagTemp = createWaterTag(waterTag.getMaterialId(), quantity, waterTag.getPrice(),
|
|
|
- waterTag.getContractId(), waterTag.getContractDetailsId(),
|
|
|
- waterTag.getWaterBatchId(), waterTag.getWaterBatchCode(), number);
|
|
|
- number++;
|
|
|
- waterTagList.add(waterTagTemp);
|
|
|
- }
|
|
|
+ int number = waterTag != null ? waterTag.getNumber() : 0;
|
|
|
|
|
|
- } else {
|
|
|
- WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
+ List<WaterTag> waterTagList = new ArrayList<>();
|
|
|
+ BigDecimal tagQuantitySum = BigDecimal.ZERO;
|
|
|
+ for (BigDecimal quantity : quantityList) {
|
|
|
+ number++;
|
|
|
+ waterTagList.add(createWaterTag(waterBatch, quantity, number));
|
|
|
+ tagQuantitySum = tagQuantitySum.add(quantity);
|
|
|
+ }
|
|
|
+ saveBatch(waterTagList);
|
|
|
|
|
|
- int number = 1;
|
|
|
+ // 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
|
+ updateContractProcessed(waterBatch);
|
|
|
|
|
|
- for (BigDecimal quantity : quantityList) {
|
|
|
- WaterTag waterTagTemp = createWaterTag(waterBatch.getMaterialId(), quantity, waterBatch.getPrice(),
|
|
|
- waterBatch.getContractId(), waterBatch.getContractDetailsId(),
|
|
|
- waterBatch.getId(), waterBatch.getCode(), number);
|
|
|
- number++;
|
|
|
- waterTagList.add(waterTagTemp);
|
|
|
- }
|
|
|
+ // 更新批次标签总个数以及标签总米数
|
|
|
+ waterBatchService.editTagCountAndQuantitySum(waterBatch, quantityList.size(), tagQuantitySum);
|
|
|
|
|
|
- // 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
|
- updateContractProcessed(waterBatch.getContractId());
|
|
|
- }
|
|
|
- saveBatch(waterTagList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -297,6 +282,8 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
IoUtil.close(workbook);
|
|
|
}
|
|
|
|
|
|
+ Assert.gtZero(quantityList.size(), "导入标签数量为空");
|
|
|
+
|
|
|
return quantityList;
|
|
|
}
|
|
|
|
|
@@ -304,26 +291,21 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
/**
|
|
|
* 创建标签
|
|
|
*
|
|
|
- * @param materialId 物料id
|
|
|
- * @param quantity 数量
|
|
|
- * @param price 单价
|
|
|
- * @param contractId 合同id
|
|
|
- * @param contractDetailsId 合同明细id
|
|
|
- * @param waterBatchId 批次id
|
|
|
- * @param waterBatchCodee 批次编码
|
|
|
- * @param number 二维码编码
|
|
|
+ * @param waterBatch 批次信息
|
|
|
+ * @param quantity 数量
|
|
|
+ * @param number 二维码编码
|
|
|
*/
|
|
|
- private WaterTag createWaterTag(Long materialId, BigDecimal quantity, BigDecimal price, Long contractId,
|
|
|
- Long contractDetailsId, Long waterBatchId, String waterBatchCodee, Integer number) {
|
|
|
+ private WaterTag createWaterTag(WaterBatch waterBatch, BigDecimal quantity, Integer number) {
|
|
|
+
|
|
|
WaterTag waterTagTemp = new WaterTag();
|
|
|
- waterTagTemp.setMaterialId(materialId);
|
|
|
+ waterTagTemp.setMaterialId(waterBatch.getMaterialId());
|
|
|
waterTagTemp.setQuantity(quantity);
|
|
|
- waterTagTemp.setPrice(price);
|
|
|
+ waterTagTemp.setPrice(waterBatch.getPrice());
|
|
|
waterTagTemp.setQrCode(UUID.fastUUID().toString());
|
|
|
- waterTagTemp.setContractId(contractId);
|
|
|
- waterTagTemp.setContractDetailsId(contractDetailsId);
|
|
|
- waterTagTemp.setWaterBatchId(waterBatchId);
|
|
|
- waterTagTemp.setWaterBatchCode(waterBatchCodee);
|
|
|
+ waterTagTemp.setContractId(waterBatch.getContractId());
|
|
|
+ waterTagTemp.setContractDetailsId(waterBatch.getContractDetailsId());
|
|
|
+ waterTagTemp.setWaterBatchId(waterBatch.getId());
|
|
|
+ waterTagTemp.setWaterBatchCode(waterBatch.getCode());
|
|
|
waterTagTemp.setNumber(number);
|
|
|
waterTagTemp.setHadPrinter(StatusConstant.NO);
|
|
|
waterTagTemp.setHadShipment(StatusConstant.NO);
|
|
@@ -347,14 +329,16 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
/**
|
|
|
* 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
|
*
|
|
|
- * @param contractId 合同id
|
|
|
+ * @param waterBatch 批次信息
|
|
|
*/
|
|
|
- private void updateContractProcessed(Long contractId) {
|
|
|
- contractService.update(Wrappers.<Contract>lambdaUpdate()
|
|
|
- .eq(StorageBaseEntity::getId, contractId)
|
|
|
- .eq(Contract::getProcessed, StatusConstant.NO)
|
|
|
- .set(Contract::getProcessed, StatusConstant.YES)
|
|
|
- );
|
|
|
+ private void updateContractProcessed(WaterBatch waterBatch) {
|
|
|
+ if (waterBatch.getTagCount() == 0) {
|
|
|
+ contractService.update(Wrappers.<Contract>lambdaUpdate()
|
|
|
+ .eq(StorageBaseEntity::getId, waterBatch.getContractId())
|
|
|
+ .eq(Contract::getProcessed, StatusConstant.NO)
|
|
|
+ .set(Contract::getProcessed, StatusConstant.YES)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|