|
@@ -47,6 +47,9 @@ import java.util.stream.Collectors;
|
|
@Service
|
|
@Service
|
|
public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> implements WaterTagService {
|
|
public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> implements WaterTagService {
|
|
|
|
|
|
|
|
+ // 保证批次统计标签个数和数量正常
|
|
|
|
+ private static final Object BATCH_COUNT_LOCK_OBJECT = new Object();
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private WaterBatchService waterBatchService;
|
|
private WaterBatchService waterBatchService;
|
|
|
|
|
|
@@ -66,50 +69,53 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
- public synchronized void add(WaterTagVo waterTagVo) {
|
|
|
|
|
|
+ public void add(WaterTagVo waterTagVo) {
|
|
BigDecimal quantity = waterTagVo.getQuantity();
|
|
BigDecimal quantity = waterTagVo.getQuantity();
|
|
Assert.notEmpty(quantity, "物料长度不能为空");
|
|
Assert.notEmpty(quantity, "物料长度不能为空");
|
|
|
|
|
|
Long waterBatchId = waterTagVo.getWaterBatchId();
|
|
Long waterBatchId = waterTagVo.getWaterBatchId();
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
|
|
|
- // 获取批次详情
|
|
|
|
- WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
|
- Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
|
-
|
|
|
|
// 标签数量
|
|
// 标签数量
|
|
int num = waterTagVo.getNum() == null || waterTagVo.getNum() < 1 ? 1 : waterTagVo.getNum();
|
|
int num = waterTagVo.getNum() == null || waterTagVo.getNum() < 1 ? 1 : waterTagVo.getNum();
|
|
|
|
|
|
// 获取最新添加标签
|
|
// 获取最新添加标签
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
|
+ int number = waterTag != null ? waterTag.getNumber() : 0;
|
|
|
|
|
|
List<WaterTag> waterTagList = new ArrayList<>();
|
|
List<WaterTag> waterTagList = new ArrayList<>();
|
|
- int number = waterTag != null ? waterTag.getNumber() : 0;
|
|
|
|
|
|
+
|
|
|
|
+ WaterBatch waterBatch;
|
|
|
|
+ synchronized (BATCH_COUNT_LOCK_OBJECT) {
|
|
|
|
+ // 获取批次详情
|
|
|
|
+ waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
|
+ Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
|
+ // 更新批次标签总个数以及标签总米数
|
|
|
|
+ waterBatchService.editTagCountAndQuantitySum(waterBatch, num, quantity.multiply(BigDecimal.valueOf(num)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加标签信息
|
|
for (int i = 1; i <= num; i++) {
|
|
for (int i = 1; i <= num; i++) {
|
|
waterTagList.add(createWaterTag(waterBatch, quantity, number + i));
|
|
waterTagList.add(createWaterTag(waterBatch, quantity, number + i));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 保存标签信息
|
|
saveBatch(waterTagList);
|
|
saveBatch(waterTagList);
|
|
|
|
|
|
// 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
// 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
updateContractProcessed(waterBatch);
|
|
updateContractProcessed(waterBatch);
|
|
|
|
|
|
- // 更新批次标签总个数以及标签总米数
|
|
|
|
- waterBatchService.editTagCountAndQuantitySum(waterBatch, num, quantity.multiply(BigDecimal.valueOf(num)));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
- public synchronized void uploadTag(MultipartFile file, Long waterBatchId) {
|
|
|
|
|
|
+ public void uploadTag(MultipartFile file, Long waterBatchId) {
|
|
|
|
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
|
|
|
// 解析excel文件中的数据
|
|
// 解析excel文件中的数据
|
|
List<BigDecimal> quantityList = getQuantityListByExcel(file);
|
|
List<BigDecimal> quantityList = getQuantityListByExcel(file);
|
|
|
|
|
|
- // 获取批次详情
|
|
|
|
- WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
|
- Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
|
-
|
|
|
|
// 获取此批次最新标签
|
|
// 获取此批次最新标签
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
|
|
|
@@ -117,19 +123,30 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
|
|
|
|
List<WaterTag> waterTagList = new ArrayList<>();
|
|
List<WaterTag> waterTagList = new ArrayList<>();
|
|
BigDecimal tagQuantitySum = BigDecimal.ZERO;
|
|
BigDecimal tagQuantitySum = BigDecimal.ZERO;
|
|
- for (BigDecimal quantity : quantityList) {
|
|
|
|
- number++;
|
|
|
|
- waterTagList.add(createWaterTag(waterBatch, quantity, number));
|
|
|
|
- tagQuantitySum = tagQuantitySum.add(quantity);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ WaterBatch waterBatch;
|
|
|
|
+ synchronized (BATCH_COUNT_LOCK_OBJECT) {
|
|
|
|
+ // 获取批次详情
|
|
|
|
+ waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
|
+ Assert.notEmpty(waterBatch, "没有找到批次信息");
|
|
|
|
+
|
|
|
|
+ for (BigDecimal quantity : quantityList) {
|
|
|
|
+ number++;
|
|
|
|
+ waterTagList.add(createWaterTag(waterBatch, quantity, number));
|
|
|
|
+ tagQuantitySum = tagQuantitySum.add(quantity);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新批次标签总个数以及标签总米数
|
|
|
|
+ waterBatchService.editTagCountAndQuantitySum(waterBatch, quantityList.size(), tagQuantitySum);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 保存标签信息
|
|
saveBatch(waterTagList);
|
|
saveBatch(waterTagList);
|
|
|
|
|
|
// 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
// 修改合同处理状态为已处理,后续操作不再允许删除合同
|
|
updateContractProcessed(waterBatch);
|
|
updateContractProcessed(waterBatch);
|
|
|
|
|
|
- // 更新批次标签总个数以及标签总米数
|
|
|
|
- waterBatchService.editTagCountAndQuantitySum(waterBatch, quantityList.size(), tagQuantitySum);
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -169,6 +186,7 @@ public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> i
|
|
.set(StorageBaseEntity::getUpdateUser, userId)
|
|
.set(StorageBaseEntity::getUpdateUser, userId)
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ // 新标签设置为已使用
|
|
update(Wrappers.<WaterTag>lambdaUpdate()
|
|
update(Wrappers.<WaterTag>lambdaUpdate()
|
|
.eq(StorageBaseEntity::getId, id)
|
|
.eq(StorageBaseEntity::getId, id)
|
|
.set(WaterTag::getRfidCode, rfidCode)
|
|
.set(WaterTag::getRfidCode, rfidCode)
|