|
@@ -4,20 +4,22 @@ 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.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletBasicInfo;
|
|
|
-import org.jeecg.modules.actualControl.billetActual.billetActual.service.IBilletBasicInfoService;
|
|
|
import org.jeecg.modules.actualControl.billetActual.billetActual.utils.MqttClientUtil;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.mapper.BilletHotsendChangeShiftMapper;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleUtils;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.util.ShiftInfo;
|
|
|
import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
|
|
|
import org.jeecg.modules.billet.shiftConfiguration.entity.ShiftConfiguration;
|
|
|
import org.jeecg.modules.billet.shiftConfiguration.service.IShiftConfigurationService;
|
|
|
+import org.jeecg.modules.billet.storageBill.entity.ShiftEnum;
|
|
|
+import org.jeecg.modules.billet.storageBill.entity.ShiftGroupEnum;
|
|
|
import org.jeecg.modules.connConfig.mapper.ConfigMqttMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -25,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -37,8 +40,9 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotsendChangeShiftMapper, BilletHotsendChangeShift> implements IBilletHotsendChangeShiftService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private IBilletBasicInfoService billetBasicInfoService;
|
|
|
+ private static final long EXPIRE_TIME = 10; // 10 分钟
|
|
|
+
|
|
|
+ private static final TimeUnit EXPIRE_TIME_UNIT = TimeUnit.MINUTES;
|
|
|
|
|
|
@Autowired
|
|
|
public RedisTemplate redisTemplate;
|
|
@@ -58,106 +62,164 @@ public class BilletHotsendChangeShiftServiceImpl extends ServiceImpl<BilletHotse
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
if (billetHotsendChangeShiftVo == null || oConvertUtils.isEmpty(billetHotsendChangeShiftVo.getCcmNo())) {
|
|
|
- result.put("fail", "参数无效,交班操作失败!");
|
|
|
+ result.put("fail", "参数无效,交班失败!");
|
|
|
return result;
|
|
|
}
|
|
|
- List<String> ccmNoList = Arrays.asList("5", "6");
|
|
|
- for (String ccmNo : ccmNoList){
|
|
|
- String keyShiftGroup = String.format("class:shift:group:%s", ccmNo);
|
|
|
- String keyShift = String.format("class:shift:%s", ccmNo);
|
|
|
- // 保存旧的缓存值,用于异常回滚
|
|
|
- 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);
|
|
|
+ String ccmNo = billetHotsendChangeShiftVo.getCcmNo();
|
|
|
+ String autoChangeShiftLimitKey = String.format("autoChangeShift:execution:%s", ccmNo);
|
|
|
|
|
|
- try {
|
|
|
- // 先更新班组班别缓存
|
|
|
- redisTemplate.opsForValue().set(keyShiftGroup, billetHotsendChangeShiftVo.getShiftGroup());
|
|
|
- redisTemplate.opsForValue().set(keyShift, billetHotsendChangeShiftVo.getShift());
|
|
|
+ // 检查键是否存在
|
|
|
+ Boolean isExecutedRecently = redisTemplate.hasKey(autoChangeShiftLimitKey);
|
|
|
+ if (isExecutedRecently == null || isExecutedRecently) {
|
|
|
+ log.info("{}{}", "10分钟内已有交班记录,交班失败!", ccmNo);
|
|
|
+ result.put("fail", "请勿重复交班!");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- // 获取当前班组班别
|
|
|
- BilletHotsendChangeShift billetHotsendChangeShift = baseMapper.selectOne(new LambdaQueryWrapper<BilletHotsendChangeShift>()
|
|
|
- .eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
- .orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1"));
|
|
|
- if (oConvertUtils.isEmpty(billetHotsendChangeShift)) {
|
|
|
- result.put("fail", "当班信息查询为空,交班操作失败!");
|
|
|
- redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
|
|
|
- redisTemplate.opsForValue().set(keyShift, oldShift);
|
|
|
- return result;
|
|
|
- }
|
|
|
- // 更新当前班次的交班时间,相当于上一个班交班的结束时间
|
|
|
- billetHotsendChangeShift.setChangeShiftTime(new Date());
|
|
|
- billetHotsendChangeShift.setUpdateTime(new Date());
|
|
|
- baseMapper.updateById(billetHotsendChangeShift);
|
|
|
- // 获取当前最新炉号
|
|
|
- if (oConvertUtils.isNotEmpty(billetHotsendChangeShift.getHeatNo())) {
|
|
|
- // 根据当前炉号、铸机号、班组、班别查询总生产的钢坯数
|
|
|
- LambdaQueryWrapper<BilletBasicInfo> queryWrapper = new LambdaQueryWrapper<BilletBasicInfo>()
|
|
|
- .eq(BilletBasicInfo::getCcmNo, Integer.valueOf(ccmNo))
|
|
|
- .eq(BilletBasicInfo::getHeatNo, billetHotsendChangeShift.getHeatNo())
|
|
|
- .eq(BilletBasicInfo::getShift, billetHotsendChangeShift.getShift())
|
|
|
- .eq(BilletBasicInfo::getShiftGroup, billetHotsendChangeShift.getShiftGroup())
|
|
|
- .isNull(BilletBasicInfo::getBelongTable)
|
|
|
- .isNull(BilletBasicInfo::getBhtcId)
|
|
|
- .orderByAsc(BilletBasicInfo::getCreateTime);
|
|
|
- List<BilletBasicInfo> billetBasicInfoList = billetBasicInfoService.list(queryWrapper);
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+ String nextshiftIdKey = String.format("class:nextshift:Id:%s", ccmNo);
|
|
|
+ String keyShiftGroup = String.format("class:shift:group:%s", ccmNo);
|
|
|
+ String keyShift = String.format("class:shift:%s", ccmNo);
|
|
|
|
|
|
- // 生成新的交班记录 初始化并保存入库
|
|
|
- BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift();
|
|
|
- billetHotsendChangeShift1.setId(String.valueOf(IdWorker.getId()));
|
|
|
- billetHotsendChangeShift1.setCcmNo(ccmNo);
|
|
|
- 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.setShiftProduct(0d); // 当班总重
|
|
|
- billetHotsendChangeShift1.setWasteAmount(0); // 当前废品支数
|
|
|
- billetHotsendChangeShift1.setCreateTime(new Date());
|
|
|
+ // 保存旧的缓存值,用于异常回滚
|
|
|
+ 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);
|
|
|
|
|
|
- // 3.19 新增班次实绩
|
|
|
- billetHotsendChangeShift1.setShiftHotsendAmount(0);
|
|
|
- billetHotsendChangeShift1.setShiftHotsendWeight(0d);
|
|
|
+ String currentShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroup));
|
|
|
+ String currentShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShift));
|
|
|
|
|
|
- billetHotsendChangeShift1.setShiftHotfeignAmount(0);
|
|
|
- billetHotsendChangeShift1.setShiftHotfeignWeight(0d);
|
|
|
+ String currentShiftGroupName = ShiftGroupEnum.fromCode(currentShiftGroup).name();
|
|
|
+ String currentShiftName = ShiftEnum.fromCode(currentShift).name().replace("班", "");
|
|
|
|
|
|
- billetHotsendChangeShift1.setShiftStackAmount(0);
|
|
|
- billetHotsendChangeShift1.setShiftStackWeight(0d);
|
|
|
+ String currentShiftIdKey = String.format("class:nextshift:Id:%s", ccmNo);
|
|
|
+ String currentCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(currentShiftIdKey));
|
|
|
|
|
|
- billetHotsendChangeShift1.setAllCarNum(0);
|
|
|
- billetHotsendChangeShift1.setCounts(0);
|
|
|
- billetHotsendChangeShift1.setBlankOutputs(0d);
|
|
|
+ log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 交班当前班次信息值:" + currentShift+ ","+ currentShiftGroup);
|
|
|
+ log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 交班当前班次信息名:" + currentCacheId + "," + currentShiftName+ ","+ currentShiftGroupName);
|
|
|
|
|
|
- baseMapper.insert(billetHotsendChangeShift1);
|
|
|
- operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
|
|
|
- result.put("success", "交班操作成功!");
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("交班操作出现异常", e);
|
|
|
- // 回滚缓存
|
|
|
- if (oldShiftGroup != null && oldShift != null) {
|
|
|
- redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
|
|
|
- redisTemplate.opsForValue().set(keyShift, oldShift);
|
|
|
- }
|
|
|
- result.put("fail", "交班操作失败,出现异常!");
|
|
|
+ String[] data = {
|
|
|
+ "1 丙", "2 甲", "3 乙", "4 丙", "5 甲", "6 乙", "7 丙", "8 甲", "9 乙", "10 丙",
|
|
|
+ "11 甲", "12 乙", "13 丁", "14 丙", "15 甲", "16 丁", "17 丙", "18 甲", "19 丁", "20 丙",
|
|
|
+ "21 甲", "22 丁", "23 丙", "24 甲", "25 乙", "26 丁", "27 丙", "28 乙", "29 丁", "30 丙",
|
|
|
+ "31 乙", "32 丁", "33 丙", "34 乙", "35 丁", "36 丙", "37 甲", "38 乙", "39 丁", "40 甲",
|
|
|
+ "41 乙", "42 丁", "43 甲", "44 乙", "45 丁", "46 甲", "47 乙", "48 丁"
|
|
|
+ };
|
|
|
+
|
|
|
+ ShiftInfo nextShiftGroupInfo = ScheduleUtils.findNextShift(data, Integer.valueOf(currentCacheId), currentShiftGroupName);
|
|
|
+ if (nextShiftGroupInfo == null){
|
|
|
+ log.info("{}{}", ccmNo + ">>>>>>获取下个班组信息为空,交班失败!", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 班别名(白中夜)
|
|
|
+ String nextShiftName = "";
|
|
|
+ // 验证23:00 到01:00 之间
|
|
|
+ if (ScheduleUtils.isBetweenTime(new Date(), "07:30", "10:30")) {
|
|
|
+ nextShiftName = "白";
|
|
|
+ } else if (ScheduleUtils.isBetweenTime(new Date(), "15:30", "16:30")) {
|
|
|
+ nextShiftName = "中";
|
|
|
+ } else if (ScheduleUtils.isBetweenTime(new Date(), "23:30", "00:30")) {
|
|
|
+ nextShiftName = "夜";
|
|
|
+ }else {
|
|
|
+ log.info("{}{}", ccmNo + "未在交班范围内,交班失败!,", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
|
|
|
+ result.put("fail","未在交班时间范围内,交班失败!");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 班组名(甲乙丙丁)
|
|
|
+ String nextShiftGroupName = nextShiftGroupInfo.getShift();
|
|
|
+ // 班组值
|
|
|
+ String finalNextShiftGroupVal = ShiftGroupEnum.getCodeByName(nextShiftGroupName);
|
|
|
+ // 班别值
|
|
|
+ String finalNextShiftVal = ShiftEnum.getCodeByName(nextShiftName + "班");
|
|
|
+
|
|
|
+ int nextUniqueShiftId = nextShiftGroupInfo.getId();
|
|
|
+
|
|
|
+ log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 手动交班下一个班次缓存值:" + finalNextShiftVal + ","+ finalNextShiftGroupVal);
|
|
|
+ log.info(DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()) + " 手动交班下一个班次信息名:" + nextUniqueShiftId + "," + nextShiftGroupName + ","+ nextShiftName);
|
|
|
+
|
|
|
+ // 设置键并设置过期时间
|
|
|
+ redisTemplate.opsForValue().set(autoChangeShiftLimitKey,"executed", EXPIRE_TIME, EXPIRE_TIME_UNIT);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 先更新班组班别缓存
|
|
|
+ redisTemplate.opsForValue().set(keyShiftGroup, finalNextShiftGroupVal);
|
|
|
+ redisTemplate.opsForValue().set(keyShift, finalNextShiftVal);
|
|
|
+ redisTemplate.opsForValue().set(currentShiftIdKey, nextUniqueShiftId);
|
|
|
+
|
|
|
+ // 获取当前班组班别
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift = baseMapper.selectOne(new LambdaQueryWrapper<BilletHotsendChangeShift>()
|
|
|
+ .eq(BilletHotsendChangeShift::getCcmNo, ccmNo)
|
|
|
+ .orderByDesc(BilletHotsendChangeShift::getCreateTime).last("limit 1"));
|
|
|
+ // 更新当前班次的交班时间,相当于上一个班交班的结束时间
|
|
|
+ billetHotsendChangeShift.setChangeShiftTime(new Date());
|
|
|
+ billetHotsendChangeShift.setUpdateTime(new Date());
|
|
|
+ baseMapper.updateById(billetHotsendChangeShift);
|
|
|
+
|
|
|
+ // 生成新的交班记录 初始化并保存入库, 初始化新的交班记录
|
|
|
+ BilletHotsendChangeShift billetHotsendChangeShift1 = new BilletHotsendChangeShift()
|
|
|
+ .setId(String.valueOf(IdWorker.getId()))
|
|
|
+ .setCcmNo(ccmNo)
|
|
|
+ .setShift(finalNextShiftVal)
|
|
|
+ .setShiftGroup(finalNextShiftGroupVal)
|
|
|
+ .setHotfeignAmount(0)
|
|
|
+ .setProductAmount(0)
|
|
|
+ .setHotsendAmount(0)
|
|
|
+ .setStackAmount(0)
|
|
|
+ .setOutCarNum(0)
|
|
|
+ .setShiftSum(0)
|
|
|
+ .setShiftProduct(0d)
|
|
|
+ .setWasteAmount(0)
|
|
|
+ .setWasteBlankOutput(0d)
|
|
|
+ .setShiftHotsendAmount(0)
|
|
|
+ .setShiftHotsendWeight(0d)
|
|
|
+ .setShiftHotfeignAmount(0)
|
|
|
+ .setShiftHotfeignWeight(0d)
|
|
|
+ .setShiftStackAmount(0)
|
|
|
+ .setShiftStackWeight(0d)
|
|
|
+ .setAllCarNum(0)
|
|
|
+ .setCounts(0)
|
|
|
+ .setBlankOutputs(0d)
|
|
|
+ .setCreateTime(new Date());
|
|
|
+ baseMapper.insert(billetHotsendChangeShift1);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 5号机根据 铸机号、当班班组、当班班别 查询储运配置信息,倒序取最新的一条,把查询到的牌号、定尺、目的地、新/旧站台
|
|
|
+ * 带到下一个班组中,生成一个新的储运配置信息,并保存到数据库中
|
|
|
+ */
|
|
|
+ LambdaQueryWrapper<ShiftConfiguration> queryWrapper = new LambdaQueryWrapper<ShiftConfiguration>();
|
|
|
+ queryWrapper.eq(ShiftConfiguration::getCcmNo, ccmNo)
|
|
|
+ .eq(ShiftConfiguration::getShiftGroup, currentShiftGroup)
|
|
|
+ .eq(ShiftConfiguration::getShift, currentShift)
|
|
|
+ .orderByDesc(ShiftConfiguration::getCreateTime)
|
|
|
+ .last("limit 1");
|
|
|
+ ShiftConfiguration shiftConfiguration = shiftConfigurationService.getOne(queryWrapper);
|
|
|
+ if (shiftConfiguration != null){
|
|
|
+ // 生出储运配置信息
|
|
|
+ ShiftConfiguration newShiftConfiguration = new ShiftConfiguration();
|
|
|
+ newShiftConfiguration.setId(String.valueOf(IdWorker.getId()));
|
|
|
+ newShiftConfiguration.setCcmNo(ccmNo);
|
|
|
+ newShiftConfiguration.setShiftGroup(finalNextShiftGroupVal);
|
|
|
+ newShiftConfiguration.setShift(finalNextShiftVal);
|
|
|
+ newShiftConfiguration.setSteelGrade(shiftConfiguration.getSteelGrade());
|
|
|
+ newShiftConfiguration.setSpec(shiftConfiguration.getSpec());
|
|
|
+ newShiftConfiguration.setDestination(shiftConfiguration.getDestination());
|
|
|
+ newShiftConfiguration.setNewOldPlatform(shiftConfiguration.getNewOldPlatform());
|
|
|
+ newShiftConfiguration.setCreateTime(new Date());
|
|
|
+ newShiftConfiguration.setDate(DateUtils.getDateWithOnlyYearMonthDay(new Date()));
|
|
|
+ shiftConfigurationService.save(newShiftConfiguration);
|
|
|
+ log.info("{}{}", ccmNo + "交班生成储运配置:", JSON.toJSON(newShiftConfiguration));
|
|
|
}
|
|
|
+ operateLogService.add(billetHotsendChangeShift1, null, BilletHotsendChangeShift.class);
|
|
|
+ result.put("success", "手动交班成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("交班出现异常", e);
|
|
|
+ redisTemplate.opsForValue().set(keyShiftGroup, oldShiftGroup);
|
|
|
+ redisTemplate.opsForValue().set(keyShift, oldShift);
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, currentCacheId);
|
|
|
+ result.put("fail", "交班异常!");
|
|
|
}
|
|
|
return result;
|
|
|
}
|