写入功能完成
This commit is contained in:
@@ -9,8 +9,11 @@ import com.ruoyi.common.core.controller.BaseController;
|
|||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.enums.BusinessType;
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.fizz.business.domain.vo.FurnaceSendCoilInfoVO;
|
||||||
import com.fizz.business.domain.vo.SendJobLastSuccessVO;
|
import com.fizz.business.domain.vo.SendJobLastSuccessVO;
|
||||||
import com.fizz.business.service.ISendJobQueryService;
|
import com.fizz.business.service.ISendJobQueryService;
|
||||||
|
import com.fizz.business.utils.RedisUtil;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@@ -87,4 +90,24 @@ public class SendJobController extends BaseController {
|
|||||||
SendJobLastSuccessVO vo = sendJobQueryService.getLastSuccess(groupType);
|
SendJobLastSuccessVO vo = sendJobQueryService.getLastSuccess(groupType);
|
||||||
return AjaxResult.success(vo);
|
return AjaxResult.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取上次炉火写入的钢卷信息
|
||||||
|
* @return 上次写入的钢卷信息(coilId、planId、sendTime)
|
||||||
|
*/
|
||||||
|
@GetMapping("/furnace/lastCoilInfo")
|
||||||
|
public AjaxResult getLastFurnaceSendCoilInfo() {
|
||||||
|
try {
|
||||||
|
String jsonValue = RedisUtil.getValue("furnace:send:coil:info");
|
||||||
|
if (jsonValue == null || jsonValue.isEmpty()) {
|
||||||
|
return AjaxResult.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
FurnaceSendCoilInfoVO coilInfo = objectMapper.readValue(jsonValue, FurnaceSendCoilInfoVO.class);
|
||||||
|
return AjaxResult.success(coilInfo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return AjaxResult.error("获取上次炉火写入钢卷信息失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.fizz.business.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 炉火写入时的钢卷信息(存储到 Redis)
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FurnaceSendCoilInfoVO {
|
||||||
|
|
||||||
|
/** 钢卷号 */
|
||||||
|
private String coilId;
|
||||||
|
|
||||||
|
/** 计划ID */
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
/** 写入时间 */
|
||||||
|
private Date sendTime;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -29,4 +29,10 @@ public interface CrmPdiPlanService extends IService<CrmPdiPlan> {
|
|||||||
CrmPdiPlan getFirstUnProducedCoil();
|
CrmPdiPlan getFirstUnProducedCoil();
|
||||||
|
|
||||||
void changeStatus(ChangePlanStatusForm build);
|
void changeStatus(ChangePlanStatusForm build);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前正在线上的钢卷(优先级:ONLINE > PRODUCING > READY/NEW)
|
||||||
|
* @return 当前正在线上的钢卷,如果没有则返回null
|
||||||
|
*/
|
||||||
|
CrmPdiPlan getCurrentOnlineCoil();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,4 +169,45 @@ public class CrmPdiPlanServiceImpl extends ServiceImpl<CrmPdiPlanMapper, CrmPdiP
|
|||||||
log.info("计划状态更新成功,ID: {}, 新状态: {}", build.getId(), build.getOperation());
|
log.info("计划状态更新成功,ID: {}, 新状态: {}", build.getId(), build.getOperation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前正在线上的钢卷(优先级:ONLINE > PRODUCING > READY/NEW)
|
||||||
|
* @return 当前正在线上的钢卷,如果没有则返回null
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public CrmPdiPlan getCurrentOnlineCoil() {
|
||||||
|
|
||||||
|
|
||||||
|
// 1. 优先查找 PRODUCING 状态的钢卷
|
||||||
|
CrmPdiPlan producingPlan = this.lambdaQuery()
|
||||||
|
.eq(CrmPdiPlan::getStatus, "PRODUCING")
|
||||||
|
.orderByAsc(CrmPdiPlan::getSeqid)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (producingPlan != null) {
|
||||||
|
return producingPlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 其次查找 ONLINE 状态的钢卷
|
||||||
|
CrmPdiPlan onlinePlan = this.lambdaQuery()
|
||||||
|
.eq(CrmPdiPlan::getStatus, "ONLINE")
|
||||||
|
.orderByAsc(CrmPdiPlan::getSeqid)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
|
||||||
|
if (onlinePlan != null) {
|
||||||
|
return onlinePlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 3. 最后查找 READY 或 NEW 状态的钢卷(按顺序号排序,取第一个)
|
||||||
|
CrmPdiPlan readyOrNewPlan = this.lambdaQuery()
|
||||||
|
.in(CrmPdiPlan::getStatus, "READY", "NEW")
|
||||||
|
.orderByAsc(CrmPdiPlan::getSeqid)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
|
||||||
|
return readyOrNewPlan;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,13 @@ import com.fizz.business.domain.vo.SendJobItemVO;
|
|||||||
import com.fizz.business.mapper.BizSendJobGroupMapper;
|
import com.fizz.business.mapper.BizSendJobGroupMapper;
|
||||||
import com.fizz.business.mapper.BizSendJobItemMapper;
|
import com.fizz.business.mapper.BizSendJobItemMapper;
|
||||||
import com.fizz.business.mapper.BizSendJobMapper;
|
import com.fizz.business.mapper.BizSendJobMapper;
|
||||||
|
import com.fizz.business.domain.CrmPdiPlan;
|
||||||
|
import com.fizz.business.domain.vo.FurnaceSendCoilInfoVO;
|
||||||
|
import com.fizz.business.service.CrmPdiPlanService;
|
||||||
import com.fizz.business.service.ISendJobService;
|
import com.fizz.business.service.ISendJobService;
|
||||||
import com.fizz.business.service.manager.OpcMessageIdsManager;
|
import com.fizz.business.service.manager.OpcMessageIdsManager;
|
||||||
|
import com.fizz.business.utils.RedisUtil;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -45,6 +50,11 @@ public class SendJobServiceImpl extends ServiceImpl<BizSendJobMapper, BizSendJob
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OpcMessageIdsManager opcMessageIdsManager;
|
private OpcMessageIdsManager opcMessageIdsManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CrmPdiPlanService crmPdiPlanService;
|
||||||
|
|
||||||
|
private static final String REDIS_KEY_FURNACE_SEND_COIL_INFO = "furnace:send:coil:info";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Integer createSendJob(SendJobCreateDTO dto) {
|
public Integer createSendJob(SendJobCreateDTO dto) {
|
||||||
@@ -338,6 +348,35 @@ public class SendJobServiceImpl extends ServiceImpl<BizSendJobMapper, BizSendJob
|
|||||||
finish.setRemark(allSuccess ? "全部发送成功" : "部分发送失败");
|
finish.setRemark(allSuccess ? "全部发送成功" : "部分发送失败");
|
||||||
baseMapper.updateById(finish);
|
baseMapper.updateById(finish);
|
||||||
|
|
||||||
|
// 如果是炉火写入(FURNACE),获取当前正在线上的钢卷信息并存储到 Redis
|
||||||
|
try {
|
||||||
|
boolean isFurnaceSend = groups.stream()
|
||||||
|
.anyMatch(g -> "FURNACE".equalsIgnoreCase(g.getGroupType()));
|
||||||
|
|
||||||
|
if (isFurnaceSend && allSuccess) {
|
||||||
|
CrmPdiPlan currentCoil = crmPdiPlanService.getCurrentOnlineCoil();
|
||||||
|
if (currentCoil != null) {
|
||||||
|
FurnaceSendCoilInfoVO coilInfo = new FurnaceSendCoilInfoVO();
|
||||||
|
coilInfo.setCoilId(currentCoil.getCoilid());
|
||||||
|
coilInfo.setPlanId(currentCoil.getPlanid());
|
||||||
|
coilInfo.setSendTime(new Date());
|
||||||
|
|
||||||
|
// 存储到 Redis(使用 JSON 格式)
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
String jsonValue = objectMapper.writeValueAsString(coilInfo);
|
||||||
|
RedisUtil.setValue(REDIS_KEY_FURNACE_SEND_COIL_INFO, jsonValue);
|
||||||
|
|
||||||
|
log.info("炉火写入成功,已保存钢卷信息到 Redis: coilId={}, planId={}",
|
||||||
|
coilInfo.getCoilId(), coilInfo.getPlanId());
|
||||||
|
} else {
|
||||||
|
log.warn("炉火写入成功,但未找到当前正在线上的钢卷");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存炉火写入钢卷信息到 Redis 失败", e);
|
||||||
|
// 不影响主流程,只记录日志
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user