| | |
| | | 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 javax.annotation.Resource; |
| | | import javax.jws.WebService; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public String equipmentDaySchedule(String msg) { |
| | | log.info("接收MES上报日计划原始数据 === {}", msg); |
| | | List<EquipmentDaySchedule> equipmentDayScheduleList = JSONObject.parseArray(msg, EquipmentDaySchedule.class); |
| | | if (equipmentDayScheduleList == null || equipmentDayScheduleList.isEmpty()) { |
| | | WsResult wsResult = new WsResult("0", "json解析失败"); |
| | | return JSONObject.toJSONString(wsResult); |
| | | } |
| | | List<MdcEquipmentDaySchedule> mdcEquipmentDayScheduleList = new ArrayList<>(); |
| | | for (EquipmentDaySchedule equipmentDaySchedule : equipmentDayScheduleList) { |
| | | MdcEquipmentDaySchedule mdcEquipmentDaySchedule = new MdcEquipmentDaySchedule(); |
| | | BeanUtils.copyProperties(equipmentDaySchedule, mdcEquipmentDaySchedule); |
| | | mdcEquipmentDayScheduleList.add(mdcEquipmentDaySchedule); |
| | | } |
| | | mdcEquipmentDayScheduleService.saveBatch(mdcEquipmentDayScheduleList); |
| | | |
| | | log.info("接收MES上报日计划数据成功!"); |
| | | WsResult wsResult = new WsResult("1", "成功"); |
| | | return JSONObject.toJSONString(wsResult); |
| | | // 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); |
| | | List<EquipmentDaySummary> equipmentDaySummaryList = JSONObject.parseArray(msg, EquipmentDaySummary.class); |
| | | if (equipmentDaySummaryList == null || equipmentDaySummaryList.isEmpty()) { |
| | | WsResult wsResult = new WsResult("0", "json解析失败"); |
| | | return JSONObject.toJSONString(wsResult); |
| | | |
| | | // 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("数据格式错误"); |
| | | } |
| | | List<MdcEquipmentDaySummary> mdcEquipmentDaySummaryList = new ArrayList<>(); |
| | | for (EquipmentDaySummary equipmentDaySummary : equipmentDaySummaryList) { |
| | | MdcEquipmentDaySummary mdcEquipmentDaySummary = new MdcEquipmentDaySummary(); |
| | | BeanUtils.copyProperties(equipmentDaySummary, mdcEquipmentDaySummary); |
| | | mdcEquipmentDaySummaryList.add(mdcEquipmentDaySummary); |
| | | |
| | | // 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("系统处理异常"); |
| | | } |
| | | mdcEquipmentDaySummaryService.saveBatch(mdcEquipmentDaySummaryList); |
| | | log.info("接收MES上报日汇总数据成功!"); |
| | | WsResult wsResult = new WsResult("1", "成功"); |
| | | return JSONObject.toJSONString(wsResult); |
| | | |
| | | } |
| | | } |