package org.jeecg.modules.mdc.webservice.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySchedule;
|
import org.jeecg.modules.mdc.entity.MdcEquipmentDaySummary;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentDayScheduleService;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentDaySummaryService;
|
import org.jeecg.modules.mdc.vo.EquipmentDaySchedule;
|
import org.jeecg.modules.mdc.vo.EquipmentDaySummary;
|
import org.jeecg.modules.mdc.vo.WsResult;
|
import org.jeecg.modules.mdc.webservice.EquipmentWebService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import javax.jws.WebService;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* @author Lius
|
* @date 2024/6/11 11:07
|
*/
|
@Service
|
@WebService(name = "EquipmentWebService",
|
targetNamespace = "http://mdc.webservice.equipment.com",
|
endpointInterface = "org.jeecg.modules.mdc.webservice.EquipmentWebService"
|
)
|
@Slf4j
|
public class EquipmentWebServiceImpl implements EquipmentWebService {
|
|
@Resource
|
private IMdcEquipmentDaySummaryService mdcEquipmentDaySummaryService;
|
|
@Resource
|
private IMdcEquipmentDayScheduleService mdcEquipmentDayScheduleService;
|
|
@Override
|
public String equipmentDaySchedule(String msg) {
|
log.info("接收MES上报日计划原始数据 === {}", msg);
|
|
// 1. 数据解析与校验
|
List<EquipmentDaySchedule> equipmentDayScheduleList;
|
try {
|
equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class);
|
if (CollectionUtils.isEmpty(equipmentDayScheduleList)) {
|
return buildErrorResult("数据为空或解析失败");
|
}
|
} catch (Exception e) {
|
log.error("JSON解析异常", e);
|
return buildErrorResult("数据格式错误");
|
}
|
|
// 2. 数据转换
|
List<MdcEquipmentDaySchedule> mdcList = equipmentDayScheduleList.stream()
|
.map(source -> {
|
MdcEquipmentDaySchedule target = new MdcEquipmentDaySchedule();
|
BeanUtils.copyProperties(source, target);
|
return target;
|
})
|
.collect(Collectors.toList());
|
|
// 3. 按mesId批量保存或更新
|
try {
|
boolean result = mdcEquipmentDayScheduleService.saveOrUpdateBatchByMesId(mdcList);
|
if (!result) {
|
log.error("部分数据保存失败");
|
return buildErrorResult("部分数据保存失败");
|
}
|
|
log.info("成功处理{}条日计划数据", mdcList.size());
|
return buildSuccessResult();
|
} catch (Exception e) {
|
log.error("日计划数据保存异常", e);
|
return buildErrorResult("系统处理异常");
|
}
|
}
|
|
// 构建成功响应
|
private String buildSuccessResult() {
|
return JSONObject.toJSONString(new WsResult("1", "成功"));
|
}
|
|
// 构建错误响应
|
private String buildErrorResult(String message) {
|
return JSONObject.toJSONString(new WsResult("0", message));
|
}
|
|
@Override
|
public String equipmentDaySummary(String msg) {
|
log.info("接收MES上报日汇总原始数据 === {}", msg);
|
|
// 1. 数据解析与校验
|
List<EquipmentDaySummary> equipmentDaySummaryList;
|
|
try {
|
equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class);
|
if (CollectionUtils.isEmpty(equipmentDaySummaryList)) {
|
return buildErrorResult("数据为空或解析失败");
|
}
|
} catch (Exception e) {
|
log.error("JSON解析异常", e);
|
return buildErrorResult("数据格式错误");
|
}
|
|
// 2. 数据转换
|
List<MdcEquipmentDaySummary> mdcList = equipmentDaySummaryList.stream()
|
.map(source -> {
|
MdcEquipmentDaySummary target = new MdcEquipmentDaySummary();
|
BeanUtils.copyProperties(source, target);
|
return target;
|
})
|
.collect(Collectors.toList());
|
|
|
// 3. 按mesId批量保存或更新
|
try {
|
boolean result = mdcEquipmentDaySummaryService.saveOrUpdateBatchByMesId(mdcList);
|
if (!result) {
|
log.error("部分数据保存失败");
|
return buildErrorResult("部分数据保存失败");
|
}
|
|
log.info("成功处理{}条日计划数据", mdcList.size());
|
return buildSuccessResult();
|
} catch (Exception e) {
|
log.error("日计划数据保存异常", e);
|
return buildErrorResult("系统处理异常");
|
}
|
|
}
|
}
|