|
@@ -1,9 +1,11 @@
|
|
|
package org.jeecg.modules.billet.billetHotsendChangeShift.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
@@ -14,10 +16,13 @@ import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 钢坯交班记录
|
|
@@ -25,6 +30,7 @@ import java.util.List;
|
|
|
* @Date: 2024-11-19
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotsendChangeShiftMapper, BilletHotsendChangeShift> implements IBilletHotsendChangeShiftService {
|
|
|
|
|
@@ -39,43 +45,62 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public JSONObject billetHotsendChangeShiftHandle(BilletHotsendChangeShift billetHotsendChangeShiftVo) {
|
|
|
-
|
|
|
JSONObject result = new JSONObject();
|
|
|
+
|
|
|
+ if (billetHotsendChangeShiftVo == null || oConvertUtils.isEmpty(billetHotsendChangeShiftVo.getCcmNo())) {
|
|
|
+ result.put("fail", "参数无效,交班操作失败!");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
|
|
|
+ String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
|
|
|
+ // 保存旧的缓存值,用于异常回滚
|
|
|
+ String oldShiftGroup = Optional.ofNullable(redisTemplate.opsForValue().get(keyShiftGroup))
|
|
|
+ .map(Object::toString)
|
|
|
+ .orElse(null);
|
|
|
+ String oldShift = Optional.ofNullable(redisTemplate.opsForValue().get(keyShift))
|
|
|
+ .map(Object::toString)
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
try {
|
|
|
- //先更新班组班别缓存
|
|
|
- String keyShiftGroup = String.format("class:shift:group:%s", billetHotsendChangeShiftVo.getCcmNo());
|
|
|
- String keyShift = String.format("class:shift:%s", billetHotsendChangeShiftVo.getCcmNo());
|
|
|
+ // 先更新班组班别缓存
|
|
|
redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
|
|
|
redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
|
|
|
+
|
|
|
// 获取当前班组班别
|
|
|
BilletHotsendChangeShift billetHotsendChangeShift = baseMapper.selectOne(new LambdaQueryWrapper<BilletHotsendChangeShift>()
|
|
|
.eq(BilletHotsendChangeShift::getCcmNo, billetHotsendChangeShiftVo.getCcmNo())
|
|
|
.orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1"));
|
|
|
- if (oConvertUtils.isEmpty(billetHotsendChangeShift)){
|
|
|
+ if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
|
|
|
result.put("fail", "当班信息查询为空,交班操作失败!");
|
|
|
return result;
|
|
|
}
|
|
|
// 更新当前班次的交班时间,相当于上一个班交班的结束时间
|
|
|
billetHotsendChangeShift.setChangeShiftTime(new Date());
|
|
|
+ billetHotsendChangeShift.setUpdateTime(new Date());
|
|
|
baseMapper.updateById(billetHotsendChangeShift);
|
|
|
// 获取当前最新炉号
|
|
|
- if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getHeatNo())){
|
|
|
+ if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getHeatNo())) {
|
|
|
// 根据当前炉号、铸机号、班组、班别查询总生产的钢坯数
|
|
|
LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>()
|
|
|
.eq(BilletBasicInfo::getCcmNo, Integer.valueOf(billetHotsendChangeShiftVo.getCcmNo()))
|
|
|
.eq(BilletBasicInfo::getHeatNo, billetHotsendChangeShift.getHeatNo())
|
|
|
.eq(BilletBasicInfo::getShift, billetHotsendChangeShift.getShift())
|
|
|
.eq(BilletBasicInfo::getShiftGroup, billetHotsendChangeShift.getShiftGroup())
|
|
|
- .orderByDesc(BilletBasicInfo::getCreateTime);
|
|
|
+ .isNull(BilletBasicInfo::getBelongTable)
|
|
|
+ .isNull(BilletBasicInfo::getBhtcId)
|
|
|
+ .orderByAsc(BilletBasicInfo::getCreateTime);
|
|
|
List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
|
|
|
- if (oConvertUtils.listIsNotEmpty(billetBasicInfoList)){
|
|
|
- List<BilletBasicInfo> updateBilletBasicInfo = extractRemainderData(billetBasicInfoList);
|
|
|
- updateBilletBasicInfo.forEach(x ->{
|
|
|
+ List<BilletBasicInfo> updateBilletBasicInfo = extractRemainderData(billetBasicInfoList);
|
|
|
+ if (oConvertUtils.listIsNotEmpty(updateBilletBasicInfo)){
|
|
|
+ updateBilletBasicInfo.forEach(x -> {
|
|
|
x.setShift(billetHotsendChangeShiftVo.getShift());
|
|
|
x.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
|
|
|
x.setUpdateTime(new Date());
|
|
|
});
|
|
|
+ log.info("交班判定该钢坯到新的班组:{}", JSON.toJSON(updateBilletBasicInfo));
|
|
|
billetBasicInfoService.saveOrUpdateBatch(updateBilletBasicInfo);
|
|
|
}
|
|
|
}
|
|
@@ -86,20 +111,25 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
|
|
|
billetHotsendChangeShift1.setCcmNo(billetHotsendChangeShiftVo.getCcmNo());
|
|
|
billetHotsendChangeShift1.setShift(billetHotsendChangeShiftVo.getShift());
|
|
|
billetHotsendChangeShift1.setShiftGroup(billetHotsendChangeShiftVo.getShiftGroup());
|
|
|
- billetHotsendChangeShift1.setHotfeignAmount(0);// 当前热装支数
|
|
|
- billetHotsendChangeShift1.setProductAmount(0);//当前生产支数
|
|
|
- billetHotsendChangeShift1.setHotsendAmount(0);// 当前热送支数
|
|
|
- billetHotsendChangeShift1.setStackAmount(0);//当前起垛支数
|
|
|
- billetHotsendChangeShift1.setOutCarNum(0);//车次
|
|
|
- billetHotsendChangeShift1.setShiftSum(0);//当班总数
|
|
|
+ billetHotsendChangeShift1.setHotfeignAmount(0); // 当前热装支数
|
|
|
+ billetHotsendChangeShift1.setProductAmount(0); // 当前生产支数
|
|
|
+ billetHotsendChangeShift1.setHotsendAmount(0); // 当前热送支数
|
|
|
+ billetHotsendChangeShift1.setStackAmount(0); // 当前起垛支数
|
|
|
+ billetHotsendChangeShift1.setOutCarNum(0); // 车次
|
|
|
+ billetHotsendChangeShift1.setShiftSum(0); // 当班总数
|
|
|
billetHotsendChangeShift1.setShiftProduct(0d); // 当班总重
|
|
|
- billetHotsendChangeShift1.setWasteAmount(0);// 当前废品支数
|
|
|
+ billetHotsendChangeShift1.setWasteAmount(0); // 当前废品支数
|
|
|
billetHotsendChangeShift1.setCreateTime(new Date());
|
|
|
baseMapper.insert(billetHotsendChangeShift1);
|
|
|
- operateLogService.add(billetHotsendChangeShift1,null, BilletHotsendChangeShift.class);
|
|
|
+ operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
|
|
|
result.put("success", "交班操作成功!");
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("交班操作出现异常", e);
|
|
|
+ // 回滚缓存
|
|
|
+ if (oldShiftGroup != null && oldShift != null) {
|
|
|
+ redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
|
|
|
+ redisTemplate.opsForValue().set(keyShift, oldShift);
|
|
|
+ }
|
|
|
result.put("fail", "交班操作失败,出现异常!");
|
|
|
}
|
|
|
return result;
|
|
@@ -111,16 +141,12 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
|
|
|
* @return
|
|
|
*/
|
|
|
private List<BilletBasicInfo> extractRemainderData(List<BilletBasicInfo> billetBasicInfoList) {
|
|
|
- List<BilletBasicInfo> remainderList = new ArrayList<>();
|
|
|
- if (oConvertUtils.listIsNotEmpty(billetBasicInfoList)) {
|
|
|
- int size = billetBasicInfoList.size();
|
|
|
- int remainder = size % 4;
|
|
|
- if (remainder > 0) {
|
|
|
- for (int i = size - remainder; i < size; i++) {
|
|
|
- remainderList.add(billetBasicInfoList.get(i));
|
|
|
- }
|
|
|
- }
|
|
|
+ if (oConvertUtils.listIsNotEmpty(billetBasicInfoList) && billetBasicInfoList.size() % 4 > 0) {
|
|
|
+ return billetBasicInfoList.stream()
|
|
|
+ .skip(billetBasicInfoList.size() - billetBasicInfoList.size() % 4)
|
|
|
+ .collect(Collectors.toList());
|
|
|
}
|
|
|
- return remainderList;
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
+
|
|
|
}
|