许鹏程
2023-06-30 3bbfaa3d7d416afbd154576453c8ee9e7e2f8899
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.product.data.center.controller;
 
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.data.center.config.CmnConst;
import com.product.data.center.config.ErrorCode;
import com.product.data.center.service.JournalManagerService;
import com.product.data.center.service.MesExternalService;
import com.product.data.center.service.ide.IMesExternalService;
import com.product.module.sys.version.ApiVersion;
import com.product.util.BaseUtil;
import com.product.util.support.AbstractBaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
/**
 * Controller 中所有的接口已配置不需要token认证
 *
 * @Author cheng
 * @Date 2022/12/16 13:20
 * @Desc MES外部接口
 */
@RestController
@RequestMapping("/api/open-mes/")
public class MesExternalController extends AbstractBaseController {
 
    @Resource
    private MesExternalService mesExternalService;
 
    @Resource
    private JournalManagerService journalManagerService;
 
 
    @PostMapping("get-collect-log/{version}")
    @ApiVersion(1)
    public String getCollectLog() {
        try {
            return BaseUtil.success(mesExternalService.getCollectLog());
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
        }
    }
 
    /**
     * 获取历史数据
     *
     * @param request
     * @return
     */
    @PostMapping("get-history-data/{version}")
    @ApiVersion(1)
    public String getHistory(HttpServletRequest request) {
        SpringMVCContextHolder.getSystemLogger().info("get-history-data");
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            mesExternalService.getHistoryData(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            return error(ErrorCode.REQUEST_HISTORY_FAIL, e);
        }
    }
 
    @PostMapping("rehandle-error/{version}")
    @ApiVersion(1)
    public String rehandleError(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            journalManagerService.secondOperation(fse.getUUID());
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
        }
    }
 
    /**
     * 创建或更新制令单
     * 不要token、签名认证
     *
     * @param request
     * @return
     */
    @PostMapping("update-mo-base/{version}")
    @ApiVersion(1)
    public String updateMoBase(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            //制令单号
            String moNumber = fse.getString("MO_NUMBER");
            //操作类型 1 创建 2 更新
            String type = fse.getString("TYPE");
            if (StringUtils.isEmpty(moNumber)) {
                throw new BaseException(ErrorCode.MO_NUMBER_CON_NOT_EMPTY);
            }
            if (!"1".equals(type) && !"2".equals(type)) {
                throw new BaseException(ErrorCode.MO_NUMBER_OPERATION_TYPE_ERROR);
            }
            this.mesExternalService.updateMoBase(moNumber.split(","), Integer.parseInt(type));
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
        }
    }
 
    /**
     * 初始化制令单
     * 不要token、签名认证
     *
     * @param request
     * @return
     */
    @PostMapping("init-mo-base/{version}")
    @ApiVersion(1)
    public String initMoBase(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request);
            //制令单号
            String moNumber = fse.getString("MO_NUMBER");
            if (StringUtils.isEmpty(moNumber)) {
                throw new BaseException(ErrorCode.MO_NUMBER_CON_NOT_EMPTY);
            }
            this.mesExternalService.initMoBase(moNumber.split(","));
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return error(e);
        } catch (Exception e) {
            e.printStackTrace();
            return error(ErrorCode.OPEN_API_REQUEST_FAIL, e);
        }
    }
 
    /**
     * 采集配置保存,子服务调用
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("/save-collect-config/{version}")
    @ApiVersion(1)
    public String saveCollectConfig(HttpServletRequest request) {
        try {
            IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.saveCollectConfig(request);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
 
    /**
     * 提取配置保存,主服务调用
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("/save-extract-config/{version}")
    @ApiVersion(1)
    public String saveExtractConfig(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_EXTRACT_TABLE);
            IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.saveExtractConfig(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
 
    /**
     * 归档保存,主服务调用
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("/save-archive-config/{version}")
    @ApiVersion(1)
    public String saveArchiveConfig(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_ARCHIVING_TABLE);
            IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.saveArchiveConfig(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
 
    /**
     * 采集日志保存 子服务调用该接口
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("save-collect-log/{version}")
    @ApiVersion(1)
    public String saveCollectLog(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DATA_CENTER_LOG);
            IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.saveCollectLog(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
 
    /**
     * 提取日志保存主服务调用该接口
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("save-extract-log/{version}")
    @ApiVersion(1)
    public String saveExtractLog(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DATA_CENTER_LOG);
            IMesExternalService mesExternalService = (IMesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.saveExtractLog(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
 
    /**
     * 定时任务日志保存,子服务调用
     * 不要token认证
     *
     * @param request
     * @return
     */
    @PostMapping("/save-timed-log/{version}")
    @ApiVersion(1)
    public String saveTimedLog(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.DATA_ARCHIVING_TABLE);
            MesExternalService mesExternalService = (MesExternalService) this.getProxyInstance(this.mesExternalService);
            mesExternalService.remoteSaveArchiveConfig(fse);
            return OK();
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e);
        } catch (Exception e) {
            return this.error(new BaseException(e));
        }
    }
}