Lius
昨天 f73f8cb6753f8d8ab2c689b4640cd2688e6f6f62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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("系统处理异常");
        }
 
    }
}