|
@@ -18,12 +18,13 @@ import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.actualControl.heatsActuals.service.IHeatsActualsService;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
|
|
|
import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
|
|
|
-import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleUtils;
|
|
|
+import org.jeecg.modules.billet.billetHotsendChangeShift.util.ScheduleRecord;
|
|
|
import org.jeecg.modules.billet.operateLog.service.IOperateLogService;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.ShiftEnum;
|
|
|
import org.jeecg.modules.billet.storageBill.entity.ShiftGroupEnum;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
@@ -33,8 +34,10 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.YearMonth;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @Description: 钢坯交班记录
|
|
@@ -242,35 +245,51 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
|
|
|
|
|
|
|
|
|
// 每天 08:00:00 执行的定时任务
|
|
|
-// @Scheduled(cron = "0 0 8 * * ?")
|
|
|
+ @Scheduled(cron = "0 0 8 * * ?")
|
|
|
public void executeDayShiftTask() {
|
|
|
log.info("自动化定时交班——白班:08:00:00开始执行!");
|
|
|
performShiftChange("白班");
|
|
|
}
|
|
|
|
|
|
// 每天 16:00:00 执行的定时任务
|
|
|
-// @Scheduled(cron = "0 0 16 * * ?")
|
|
|
+ @Scheduled(cron = "0 0 16 * * ?")
|
|
|
public void executeMiddleShiftTask() {
|
|
|
log.info("自动定时交班——中班:16:00:00开始执行!");
|
|
|
performShiftChange("中班");
|
|
|
}
|
|
|
|
|
|
// 每天 00:00:00 执行的定时任务
|
|
|
-// @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
public void executeNeightShiftTask() {
|
|
|
- log.info("自动化定时交班——白班:08:00:00开始执行!");
|
|
|
+ log.info("自动化定时交班——白班:00:00:00开始执行!");
|
|
|
performShiftChange("夜班");
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="自动化交班测试", notes="自动化交班测试")
|
|
|
@GetMapping(value = "/autoByCcmNo")
|
|
|
- public Result<List<BilletHotsendChangeShift>> autoByCcmNo() {
|
|
|
- performShiftChange("白班");
|
|
|
- List<BilletHotsendChangeShift> list = billetHotsendChangeShiftService.list().stream()
|
|
|
- .sorted(Comparator.comparing(BilletHotsendChangeShift::getCreateTime).reversed())
|
|
|
- .limit(2)
|
|
|
- .collect(Collectors.toList());
|
|
|
- return Result.OK(list);
|
|
|
+ public Result<String> autoByCcmNo(@RequestParam(name="ccmNo", required = false) String ccmNo,
|
|
|
+ @RequestParam(name="nextId", required = false) Integer nextId,
|
|
|
+ @RequestParam(name="shift", required = false) String shift,
|
|
|
+ @RequestParam(name="shiftGroup", required = false) String shiftGroup) {
|
|
|
+ // 设置5.6号机的缓存班组班别信息
|
|
|
+ if ("5".equals(ccmNo) || "6".equals(ccmNo)){
|
|
|
+ String keyShiftGroupsix = String.format("class:shift:group:%s", "6");
|
|
|
+ String keyShiftsix = String.format("class:shift:%s", "6");
|
|
|
+ redisTemplate.opsForValue().set(keyShiftGroupsix, shiftGroup);
|
|
|
+ redisTemplate.opsForValue().set(keyShiftsix, shift);
|
|
|
+
|
|
|
+ String keyShiftGroupsix1 = String.format("class:shift:group:%s", "5");
|
|
|
+ String keyShiftsix1 = String.format("class:shift:%s", "5");
|
|
|
+ redisTemplate.opsForValue().set(keyShiftGroupsix1, shiftGroup);
|
|
|
+ redisTemplate.opsForValue().set(keyShiftsix1, shift);
|
|
|
+ return Result.OK("5.6号机缓存设置成功!");
|
|
|
+ } else if (oConvertUtils.isNotEmpty(nextId)) {
|
|
|
+ String nextshiftIdKey = String.format("class:nextshift:Id:%s", "5-6");
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, nextId);
|
|
|
+ return Result.OK("设置交班索引i为:" + nextId);
|
|
|
+ }
|
|
|
+// performShiftChange(null);
|
|
|
+ return Result.OK(null);
|
|
|
}
|
|
|
/**
|
|
|
* 自动化交班
|
|
@@ -279,12 +298,6 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
|
|
|
*/
|
|
|
private void performShiftChange(String shiftName) {
|
|
|
|
|
|
- String keyShiftGroupfive = String.format("class:shift:group:%s", "5");
|
|
|
- String keyShiftfive = String.format("class:shift:%s", "5");
|
|
|
-
|
|
|
- String fiveShiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftGroupfive));
|
|
|
- String fiveShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftfive));
|
|
|
-
|
|
|
String keyShiftGroupsix = String.format("class:shift:group:%s", "6");
|
|
|
String keyShiftsix = String.format("class:shift:%s", "6");
|
|
|
|
|
@@ -292,46 +305,129 @@ public class BilletHotsendChangeShiftController extends JeecgController<BilletHo
|
|
|
String sixShift = oConvertUtils.getString(redisTemplate.opsForValue().get(keyShiftsix));
|
|
|
|
|
|
|
|
|
- // 5.6号机的班组和班别是否相等
|
|
|
- if (!Objects.equals(sixShiftGroup, fiveShiftGroup) || !Objects.equals(sixShift, fiveShift)) {
|
|
|
- log.info("缓存中5.6号机的当班班组信息不一致,执行交班定时任务失败! {}", new Date());
|
|
|
- log.info("5号机班组值:{},6号机班组值:{}", fiveShiftGroup, sixShiftGroup);
|
|
|
- log.info("5号机班别值:{},6号机班别值:{}", fiveShift, sixShift);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
String currentShiftGroupName = ShiftGroupEnum.fromCode(sixShiftGroup).name();
|
|
|
String currentShiftName = ShiftEnum.fromCode(sixShift).name().replace("班", "");
|
|
|
|
|
|
- String[] result = ScheduleUtils.getNextShiftInfo(currentShiftGroupName, currentShiftName);
|
|
|
- if (result.length < 4 || result[2] == null || result[3] == null) {
|
|
|
- log.info("根据排班表未匹配出下一个班次信息,自动化交班失败! {}", new Date());
|
|
|
- return;
|
|
|
+ String nextshiftIdKey = String.format("class:nextshift:Id:%s", "5-6");
|
|
|
+ String nextCacheId = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
|
|
|
+
|
|
|
+
|
|
|
+ String nextShiftGroupName = "";
|
|
|
+ String nextShiftName = "";
|
|
|
+ int nextShiftGroupVal = 0;
|
|
|
+ int nextShiftVal = 0;
|
|
|
+
|
|
|
+
|
|
|
+ List<ScheduleRecord> scheduleRecordListAll = new ArrayList<>();
|
|
|
+ // 将数据添加到列表中
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(1, "丙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(2, "甲", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(3, "乙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(4, "丙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(5, "甲", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(6, "乙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(7, "丙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(8, "甲", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(9, "乙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(10, "丙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(11, "甲", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(12, "乙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(13, "丁", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(14, "丙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(15, "甲", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(16, "丁", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(17, "丙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(18, "甲", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(19, "丁", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(20, "丙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(21, "甲", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(22, "丁", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(23, "丙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(24, "甲", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(25, "乙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(26, "丁", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(27, "丙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(28, "乙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(29, "丁", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(30, "丙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(31, "乙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(32, "丁", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(33, "丙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(34, "乙", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(35, "丁", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(36, "丙", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(37, "甲", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(38, "乙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(39, "丁", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(40, "甲", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(41, "乙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(42, "丁", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(43, "甲", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(44, "乙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(45, "丁", "中"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(46, "甲", "夜"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(47, "乙", "白"));
|
|
|
+ scheduleRecordListAll.add(new ScheduleRecord(48, "丁", "中"));
|
|
|
+
|
|
|
+ if (oConvertUtils.isEmpty(nextCacheId)) {
|
|
|
+ for (ScheduleRecord scheduleRecord : scheduleRecordListAll) {
|
|
|
+ if (currentShiftGroupName.equals(scheduleRecord.getShiftGroup()) && currentShiftName.equals(scheduleRecord.getShift())) {
|
|
|
+ nextShiftGroupName = scheduleRecord.getShiftGroup();
|
|
|
+ nextShiftName = scheduleRecord.getShift();
|
|
|
+ nextShiftGroupVal = scheduleRecord.getShiftGroupValue();
|
|
|
+ nextShiftVal = scheduleRecord.getShiftValue();
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, scheduleRecord.getId() + 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ for (ScheduleRecord scheduleRecord : scheduleRecordListAll) {
|
|
|
+ if (scheduleRecord.getId() == Integer.parseInt(nextCacheId)) {
|
|
|
+
|
|
|
+ nextShiftName = scheduleRecord.getShift();
|
|
|
+ nextShiftGroupName = scheduleRecord.getShiftGroup();
|
|
|
+
|
|
|
+ nextShiftGroupVal = scheduleRecord.getShiftGroupValue();
|
|
|
+ nextShiftVal = scheduleRecord.getShiftValue();
|
|
|
+
|
|
|
+ if (Integer.parseInt(nextCacheId) == 48){
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, 1);
|
|
|
+ }else {
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, scheduleRecord.getId() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- log.info("下一个班次信息:{}——{}", result[0], result[1]);
|
|
|
- log.info("下一个班次信息:{}——{}", result[3], result[2]);
|
|
|
+ log.info(new Date() + "下一个班次名::" + nextCacheId + ","+nextShiftGroupName+ ","+ nextShiftName);
|
|
|
+ log.info("下一个班次值::" + nextShiftGroupVal+ ","+ nextShiftVal);
|
|
|
|
|
|
+ String finalNextShiftGroupVal = String.valueOf(nextShiftGroupVal);
|
|
|
+ String finalNextShiftVal = String.valueOf(nextShiftVal);
|
|
|
// 查询当天的交班记录
|
|
|
LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapperCS = new LambdaQueryWrapper<>();
|
|
|
queryWrapperCS.between(BilletHotsendChangeShift::getCreateTime, DateUtils.getStartOfDay(), DateUtils.getEndOfDay());
|
|
|
List<BilletHotsendChangeShift> billetHotsendChangeShiftList = billetHotsendChangeShiftService.list(queryWrapperCS);
|
|
|
|
|
|
- String nextShift = String.join(",", result[3], result[2]);
|
|
|
+ String nextShift = String.join(",", finalNextShiftVal, finalNextShiftGroupVal);
|
|
|
|
|
|
if (oConvertUtils.listIsNotEmpty(billetHotsendChangeShiftList)) {
|
|
|
boolean exists = billetHotsendChangeShiftList.stream()
|
|
|
.map(x -> String.join(",", x.getShift(), x.getShiftGroup()))
|
|
|
.anyMatch(s -> s.equals(nextShift));
|
|
|
if (exists) {
|
|
|
- log.info("自动化当天不能重复交班! {}", new Date());
|
|
|
+ log.info("自动交班,当天不能重复交班! {}", new Date());
|
|
|
+ // 自动交班失败,交班ID索引值回滚,保证交班顺序
|
|
|
+ String nextCacheIdRollBack = oConvertUtils.getString(redisTemplate.opsForValue().get(nextshiftIdKey));
|
|
|
+ int nextCacheIdRollBacks = Integer.parseInt(nextCacheIdRollBack);
|
|
|
+ redisTemplate.opsForValue().set(nextshiftIdKey, nextCacheIdRollBacks - 1);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BilletHotsendChangeShift billetHotsendChangeShiftVo = new BilletHotsendChangeShift();
|
|
|
- billetHotsendChangeShiftVo.setShiftGroup(result[2]);
|
|
|
- billetHotsendChangeShiftVo.setShift(result[3]);
|
|
|
+ billetHotsendChangeShiftVo.setShiftGroup(finalNextShiftGroupVal);
|
|
|
+ billetHotsendChangeShiftVo.setShift(finalNextShiftVal);
|
|
|
JSONObject jsonObject = billetHotsendChangeShiftService.autoChangeShiftHandle(billetHotsendChangeShiftVo);
|
|
|
- log.info("自动化{}交班成功! {} 结果值:{}", shiftName, new Date(), jsonObject);
|
|
|
+ log.info("自动化{}交班成功!{} 结果值:{}", shiftName, new Date(), jsonObject);
|
|
|
}
|
|
|
}
|