写入功能完成
This commit is contained in:
@@ -4,17 +4,25 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.fizz.business.domain.BizSendJob;
|
import com.fizz.business.domain.BizSendJob;
|
||||||
import com.fizz.business.domain.BizSendJobGroup;
|
import com.fizz.business.domain.BizSendJobGroup;
|
||||||
import com.fizz.business.domain.BizSendJobItem;
|
import com.fizz.business.domain.BizSendJobItem;
|
||||||
|
import com.fizz.business.domain.CrmPdiPlan;
|
||||||
|
import com.fizz.business.domain.vo.BizSendTemplateItemVO;
|
||||||
|
import com.fizz.business.domain.vo.BizSendTemplateVO;
|
||||||
import com.fizz.business.domain.vo.SendJobLastSuccessVO;
|
import com.fizz.business.domain.vo.SendJobLastSuccessVO;
|
||||||
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.mapper.CrmPdiPlanMapper;
|
||||||
|
import com.fizz.business.service.IBizSendTemplateService;
|
||||||
import com.fizz.business.service.ISendJobQueryService;
|
import com.fizz.business.service.ISendJobQueryService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SendJobQueryServiceImpl implements ISendJobQueryService {
|
public class SendJobQueryServiceImpl implements ISendJobQueryService {
|
||||||
@@ -28,50 +36,142 @@ public class SendJobQueryServiceImpl implements ISendJobQueryService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private BizSendJobItemMapper itemMapper;
|
private BizSendJobItemMapper itemMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IBizSendTemplateService templateService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CrmPdiPlanMapper planMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SendJobLastSuccessVO getLastSuccess(String groupType) {
|
public SendJobLastSuccessVO getLastSuccess(String groupType) {
|
||||||
// 1) 先找最近一次 COMPLETED 的 job(倒序)
|
// 1) 先找最近一次 COMPLETED 的 job(倒序)
|
||||||
BizSendJob lastJob = jobMapper.selectOne(
|
BizSendJob lastJob = jobMapper.selectOne(
|
||||||
new LambdaQueryWrapper<BizSendJob>()
|
new LambdaQueryWrapper<BizSendJob>()
|
||||||
.eq(BizSendJob::getStatus, "COMPLETED")
|
.eq(BizSendJob::getStatus, "COMPLETED")
|
||||||
|
.eq(BizSendJob::getGroupType, groupType)
|
||||||
.orderByDesc(BizSendJob::getFinishTime)
|
.orderByDesc(BizSendJob::getFinishTime)
|
||||||
.last("LIMIT 1")
|
.last("LIMIT 1")
|
||||||
);
|
);
|
||||||
if (lastJob == null) {
|
|
||||||
return null;
|
// 如果找到了,直接返回上次成功的值
|
||||||
|
if (lastJob != null) {
|
||||||
|
List<BizSendJobGroup> groups = groupMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<BizSendJobGroup>()
|
||||||
|
.eq(BizSendJobGroup::getJobId, lastJob.getJobId())
|
||||||
|
);
|
||||||
|
if (groups != null && !groups.isEmpty()) {
|
||||||
|
List<Integer> groupIds = groups.stream().map(BizSendJobGroup::getGroupId).collect(Collectors.toList());
|
||||||
|
List<BizSendJobItem> items = itemMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<BizSendJobItem>()
|
||||||
|
.in(BizSendJobItem::getGroupId, groupIds)
|
||||||
|
.eq(BizSendJobItem::getResultStatus, "SUCCESS")
|
||||||
|
.orderByAsc(BizSendJobItem::getItemId)
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, String> values = new HashMap<>();
|
||||||
|
for (BizSendJobItem it : items) {
|
||||||
|
if (it.getParamCode() == null) continue;
|
||||||
|
values.put(it.getParamCode(), it.getValueRaw());
|
||||||
|
}
|
||||||
|
|
||||||
|
SendJobLastSuccessVO vo = new SendJobLastSuccessVO();
|
||||||
|
vo.setJobId(lastJob.getJobId());
|
||||||
|
vo.setLastSendTime(lastJob.getFinishTime());
|
||||||
|
vo.setValues(values);
|
||||||
|
// 添加一个标志,告诉前端这是真实发送过的值
|
||||||
|
vo.setIsFromHistory(true);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) 找该 job 下对应 groupType 的 groups
|
// 2) 如果没找到,根据 groupType 返回模板或计划值
|
||||||
List<BizSendJobGroup> groups = groupMapper.selectList(
|
if ("FURNACE".equalsIgnoreCase(groupType)) {
|
||||||
new LambdaQueryWrapper<BizSendJobGroup>()
|
return getFurnaceTemplateValues();
|
||||||
.eq(BizSendJobGroup::getJobId, lastJob.getJobId())
|
} else if ("DRIVE".equalsIgnoreCase(groupType)) {
|
||||||
.eq(groupType != null && !groupType.trim().isEmpty(), BizSendJobGroup::getGroupType, groupType)
|
return getDrivePlanValues();
|
||||||
);
|
|
||||||
if (groups == null || groups.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> groupIds = groups.stream().map(BizSendJobGroup::getGroupId).collect(java.util.stream.Collectors.toList());
|
return null; // 其他情况返回 null
|
||||||
|
}
|
||||||
|
|
||||||
// 3) 取这些 group 的 item,按 paramCode 聚合最后一次值(同 paramCode 取最后一条 itemId 最大)
|
/**
|
||||||
List<BizSendJobItem> items = itemMapper.selectList(
|
* 获取炉火工艺模板的默认值
|
||||||
new LambdaQueryWrapper<BizSendJobItem>()
|
*/
|
||||||
.in(BizSendJobItem::getGroupId, groupIds)
|
private SendJobLastSuccessVO getFurnaceTemplateValues() {
|
||||||
.eq(BizSendJobItem::getResultStatus, "SUCCESS")
|
// "FURNACE_DEFAULT" 是前端写死的模板编码
|
||||||
.orderByAsc(BizSendJobItem::getItemId)
|
BizSendTemplateVO template = templateService.getTemplateWithItems("FURNACE_DEFAULT");
|
||||||
);
|
if (template == null || template.getItems() == null || template.getItems().isEmpty()) {
|
||||||
|
return createEmptyResponse("Furnace template 'FURNACE_DEFAULT' not found or is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, String> values = new HashMap<>();
|
Map<String, String> values = new HashMap<>();
|
||||||
for (BizSendJobItem it : items) {
|
for (BizSendTemplateItemVO item : template.getItems()) {
|
||||||
if (it.getParamCode() == null) continue;
|
if (item.getEnabled() && item.getParamCode() != null) {
|
||||||
values.put(it.getParamCode(), it.getValueRaw());
|
values.put(item.getParamCode(), item.getDefaultValueRaw());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SendJobLastSuccessVO vo = new SendJobLastSuccessVO();
|
SendJobLastSuccessVO vo = new SendJobLastSuccessVO();
|
||||||
vo.setJobId(lastJob.getJobId());
|
|
||||||
vo.setLastSendTime(lastJob.getFinishTime());
|
|
||||||
vo.setValues(values);
|
vo.setValues(values);
|
||||||
|
// 标志为非历史值
|
||||||
|
vo.setIsFromHistory(false);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前计划的传动参数
|
||||||
|
*/
|
||||||
|
private SendJobLastSuccessVO getDrivePlanValues() {
|
||||||
|
// 优先找 PRODUCING 或 ONLINE 状态的计划,按更新时间倒序取最新的一个
|
||||||
|
CrmPdiPlan currentPlan = planMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<CrmPdiPlan>()
|
||||||
|
.in(CrmPdiPlan::getStatus, "PRODUCING", "ONLINE")
|
||||||
|
.orderByDesc(CrmPdiPlan::getUpdateTime)
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
|
||||||
|
// 如果没有正在生产的,就找第一个 READY 的计划
|
||||||
|
if (currentPlan == null) {
|
||||||
|
currentPlan = planMapper.selectOne(
|
||||||
|
new LambdaQueryWrapper<CrmPdiPlan>()
|
||||||
|
.eq(CrmPdiPlan::getStatus, "READY")
|
||||||
|
.orderByAsc(CrmPdiPlan::getSeqid)
|
||||||
|
.last("LIMIT 1")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPlan == null) {
|
||||||
|
return createEmptyResponse("No active or ready plan found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 CrmPdiPlan 对象的字段反射为 Map
|
||||||
|
Map<String, String> values = new HashMap<>();
|
||||||
|
Field[] fields = CrmPdiPlan.class.getDeclaredFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
try {
|
||||||
|
field.setAccessible(true);
|
||||||
|
Object value = field.get(currentPlan);
|
||||||
|
if (value != null) {
|
||||||
|
values.put(field.getName(), String.valueOf(value));
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
// 忽略无法访问的字段
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SendJobLastSuccessVO vo = new SendJobLastSuccessVO();
|
||||||
|
vo.setValues(values);
|
||||||
|
vo.setIsFromHistory(false); // 标志为非历史值
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个空的带消息的返回对象
|
||||||
|
*/
|
||||||
|
private SendJobLastSuccessVO createEmptyResponse(String message) {
|
||||||
|
SendJobLastSuccessVO vo = new SendJobLastSuccessVO();
|
||||||
|
vo.setValues(Collections.singletonMap("_message", message));
|
||||||
|
vo.setIsFromHistory(false);
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user