提交 | 用户 | 时间
0ca254 1 package com.jcdm.main.om.productionOrde.controller;
A 2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
35c489 6 import java.util.concurrent.CompletableFuture;
0ca254 7 import javax.servlet.http.HttpServletResponse;
A 8
6a53e6 9 import cn.hutool.core.collection.CollUtil;
35c489 10 import cn.hutool.core.util.ObjectUtil;
0ca254 11 import cn.hutool.json.JSONObject;
A 12 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
13 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
14 import com.jcdm.common.core.domain.entity.SysUser;
15 import com.jcdm.common.core.domain.model.LoginUser;
16 import com.jcdm.common.utils.ServletUtils;
17 import com.jcdm.common.utils.StringUtils;
22c9e0 18 import com.jcdm.framework.websocket.WebSocketUsers;
35c489 19 import com.jcdm.main.constant.Constants;
0ca254 20 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
A 21 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfoExcelImport;
22 import com.jcdm.main.om.productionOrde.mapper.OmProductionOrdeInfoMapper;
23 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
24 import com.jcdm.main.restful.factoryMes.service.RestfulService;
22c9e0 25 import com.kangaroohy.milo.model.ReadWriteEntity;
A 26 import com.kangaroohy.milo.service.MiloService;
0ca254 27 import lombok.extern.slf4j.Slf4j;
A 28 import org.aspectj.weaver.loadtime.Aj;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.security.access.prepost.PreAuthorize;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.web.bind.annotation.GetMapping;
34 import org.springframework.web.bind.annotation.PostMapping;
35 import org.springframework.web.bind.annotation.PutMapping;
36 import org.springframework.web.bind.annotation.DeleteMapping;
37 import org.springframework.web.bind.annotation.PathVariable;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RestController;
41 import com.jcdm.common.annotation.Log;
42 import com.jcdm.common.core.controller.BaseController;
43 import com.jcdm.common.core.domain.AjaxResult;
44 import com.jcdm.common.enums.BusinessType;
45 import com.jcdm.common.utils.poi.ExcelUtil;
46 import com.jcdm.common.core.page.TableDataInfo;
47 import org.springframework.web.multipart.MultipartFile;
48
49 /**
50  * 生产工单Controller
51  * 
52  * @author ruimin
53  * @date 2023-12-11
54  */
55 @Slf4j
56 @RestController
57 @RequestMapping("/om/productionOrde")
58 public class OmProductionOrdeInfoController extends BaseController
59 {
60     private static final Logger logger = LoggerFactory.getLogger("sys-user");
61
62     @Autowired
63     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
22c9e0 64
A 65     @Autowired
66     private MiloService miloService;
0ca254 67
A 68     /**
69      * 查询生产工单列表
70      */
71     @PreAuthorize("@ss.hasPermi('om:productionOrde:list')")
72     @GetMapping("/list")
73     public TableDataInfo list(OmProductionOrdeInfo omProductionOrdeInfo)
74     {
75         startPage();
76 //        List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getWorkOrderNo, "W_202403120001"));
77         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
78         return getDataTable(list);
79     }
80
81     @GetMapping("/checkCarCode")
82     public AjaxResult checkCarCode(OmProductionOrdeInfo omProductionOrdeInfo)
83     {
84         Integer i = 0;
85         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum()));
86         if(StringUtils.isNotBlank(list.get(0).getTrolleyYard())){
87             i = 1;
88         }
89         return AjaxResult.success(i);
90     }
91
92     @GetMapping("/checkYzSfcCode")
93     public AjaxResult checkYzSfcCode(OmProductionOrdeInfo omProductionOrdeInfo)
94     {
95         Integer i = 0;
96         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum()));
97         if(StringUtils.isNotBlank(list.get(0).getSpareField2())){
98             i = 1;
99         }
100         return AjaxResult.success(i);
101     }
102
103     @GetMapping("/bindYzSfcFlag")
104     public AjaxResult bindYzSfcFlag(OmProductionOrdeInfo omProductionOrdeInfo)
105     {
106         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum, omProductionOrdeInfo.getProductNum()));
107         list.get(0).setSpareField2("1");
108         omProductionOrdeInfoService.saveOrUpdate(list.get(0));
109         return AjaxResult.success(null);
110     }
111
112     /**
113      * 导出生产工单列表
114      */
115     @PreAuthorize("@ss.hasPermi('om:productionOrde:export')")
116     @Log(title = "生产工单", businessType = BusinessType.EXPORT)
117     @PostMapping("/export")
118     public void export(HttpServletResponse response, OmProductionOrdeInfo omProductionOrdeInfo)
119     {
120         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
121         ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class);
122         util.exportExcel(response, list, "生产工单数据");
123     }
124
22c9e0 125     @GetMapping("/mozuReceivingWorkOrders")
1ebf2a 126     public AjaxResult mozuReceivingWorkOrders(OmProductionOrdeInfo paramOrder) throws Exception {
22c9e0 127         String paramProductNum = "";
09ceef 128         Object productTypeObjcet = miloService.readFromOpcUa("MOZU1." + paramOrder.getLineCode() + ".ProductType").getValue();//产品类型
1ebf2a 129         if (ObjectUtil.isNull(productTypeObjcet)) {
f1f266 130             return AjaxResult.error("接单失败,PLC未传输生产类型,请联系管理员!");
1ebf2a 131         }
6a53e6 132
1ebf2a 133         String productType = productTypeObjcet.toString();//产品类型
C 134         String materialCode = Constants.materialMap.get(productType);
135
ab6314 136
6a53e6 137         //先查询表中是否有剩余工单
C 138         List<OmProductionOrdeInfo> orderList = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>()
139                 .eq(OmProductionOrdeInfo::getOrderStatus, Constants.ONE)
140                 .eq(OmProductionOrdeInfo::getStationCode,paramOrder.getLineCode())//工位
141                 .eq(OmProductionOrdeInfo::getProductCode,materialCode));//产品类型
142         if (CollUtil.isNotEmpty(orderList)){
143             Long id = orderList.get(0).getId();
144             String productNum = orderList.get(0).getProductNum();//模组码
145             String orderNum = orderList.get(0).getWorkOrderNo();
146
147             paramProductNum = productNum;
148             //下发产品模组码
149             miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".WorkOrderNumber").value(orderNum).build());
150             miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".ModuleCode").value(productNum).build());
151
152         }else{
153             OmProductionOrdeInfo lastOrder = omProductionOrdeInfoService.getLastOrder();
154             String orderJsonString = RestfulService.getProductionWorkOrderRequest(lastOrder.getProductNum(), "M1OP100",materialCode);
155             JSONObject jsonObject = new JSONObject(orderJsonString);
156             // 从JSONObject中获取data对象
157             JSONObject dataObject = jsonObject.getJSONObject("data");
158             String code = jsonObject.getStr("code");
159             // 判断接单是否成功
160             if(code.equals("success")){
161                 logger.info("请求工厂MES工单:入参pack{}出参pack:{}",paramProductNum,dataObject.getStr("productNum"));
162                 List<OmProductionOrdeInfo> check = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().eq(OmProductionOrdeInfo::getProductNum,dataObject.getStr("productNum")));
163                 if(check.isEmpty()){
164                     try {
165                         log.info("请求工厂MES工单:入参pack{}出参pack:{}", paramProductNum, dataObject.getStr("productNum"));
166                         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
167                         omProductionOrdeInfo.setWorkOrderNo(dataObject.getStr("productionOrderNum"));
168                         omProductionOrdeInfo.setProductNum(dataObject.getStr("productNum"));
169                         omProductionOrdeInfo.setStationCode(paramOrder.getLineCode());//工位
170                         omProductionOrdeInfo.setProductCode(dataObject.getStr("materialCode"));
171                         omProductionOrdeInfo.setPlanQty(Long.valueOf(dataObject.getStr("plannedQuantity")));
172                         omProductionOrdeInfo.setOnlineCompletionMark("0");
173                         omProductionOrdeInfo.setSfResult("0");
174                         omProductionOrdeInfo.setProductModel(dataObject.getStr("model"));
175                         omProductionOrdeInfo.setCreateTime(new Date());
176                         omProductionOrdeInfo.setCreateUser("工厂MES");
177                         omProductionOrdeInfoService.save(omProductionOrdeInfo);
178
179                         paramProductNum = dataObject.getStr("productNum");
180                         //写PLC
181                         miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".WorkOrderNumber").value(dataObject.getStr("productionOrderNum")).build());
182                         miloService.writeToOpcUa(ReadWriteEntity.builder().identifier("MOZU1." + paramOrder.getLineCode() + ".ModuleCode").value(dataObject.getStr("productNum")).build());
183                     } catch (Exception e) {
184                         throw new RuntimeException(e);
185                     }
186                 }else{
187                     return AjaxResult.error("工单重复,请重新接收");
22c9e0 188                 }
6a53e6 189             }else {
C 190                 return AjaxResult.error("接单失败,请联系管理员");
22c9e0 191             }
A 192         }
6a53e6 193
C 194         return AjaxResult.success(paramProductNum);
22c9e0 195     }
A 196
0ca254 197     @GetMapping(value = "/jieBang/{id}")
A 198     public AjaxResult jieBang(@PathVariable("id") Long id)
199     {
200         OmProductionOrdeInfo byId = omProductionOrdeInfoService.getById(id);
201         byId.setTrolleyYard("");
202         return success(omProductionOrdeInfoService.saveOrUpdate(byId));
203     }
204
205     /**
206      * 获取生产工单详细信息
207      */
208     @PreAuthorize("@ss.hasPermi('om:productionOrde:query')")
209     @GetMapping(value = "/{id}")
210     public AjaxResult getInfo(@PathVariable("id") Long id)
211     {
212         return success(omProductionOrdeInfoService.selectOmProductionOrdeInfoById(id));
213     }
214
215     /**
216      * 新增生产工单
217      */
218     @PreAuthorize("@ss.hasPermi('om:productionOrde:add')")
219     @Log(title = "生产工单", businessType = BusinessType.INSERT)
220     @PostMapping
221     public AjaxResult add(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
222     {
223         return toAjax(omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo));
224     }
225
226     /**
227      * 修改生产工单
228      */
229     @PreAuthorize("@ss.hasPermi('om:productionOrde:edit')")
230     @Log(title = "生产工单", businessType = BusinessType.UPDATE)
231     @PutMapping
232     public AjaxResult edit(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
233     {
234         return toAjax(omProductionOrdeInfoService.updateOmProductionOrdeInfo(omProductionOrdeInfo));
235     }
236
237     /**
238      * 删除生产工单
239      */
240     @PreAuthorize("@ss.hasPermi('om:productionOrde:remove')")
241     @Log(title = "生产工单", businessType = BusinessType.DELETE)
242     @DeleteMapping("/{ids}")
243     public AjaxResult remove(@PathVariable Long[] ids)
244     {
245         return toAjax(omProductionOrdeInfoService.deleteOmProductionOrdeInfoByIds(ids));
246     }
247
248     /**
249      * table列上移下移
250      */
251     @Log(title = "生产工单", businessType = BusinessType.DELETE)
252     @GetMapping("/upDownMove")
253     public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo)
254     {
255         return omProductionOrdeInfoService.upDownMove(omProductionOrdeInfo);
256     }
257
258     @PostMapping("/importData")
259     public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
260     {
261         ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class);
262         List<OmProductionOrdeInfo> ordeInfo = util.importExcel(file.getInputStream());
263         for (OmProductionOrdeInfo omProductionOrdeInfo : ordeInfo) {
264             omProductionOrdeInfo.setCreateTime(new Date());
265             omProductionOrdeInfo.setCreateBy("工厂MES");
266         }
267         omProductionOrdeInfoService.overrideSaveBatch(ordeInfo);
268         return AjaxResult.success();
269     }
270
271     @PostMapping("/importTemplate")
272     public void importTemplate(HttpServletResponse response)
273     {
274         ExcelUtil<OmProductionOrdeInfoExcelImport> util = new ExcelUtil<OmProductionOrdeInfoExcelImport>(OmProductionOrdeInfoExcelImport.class);
275         util.importTemplateExcel(response, "订单数据");
276     }
277
278     @PostMapping("/trolleyYardBinDing")
279     public AjaxResult trolleyYardBinDing(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
280     {
281         return omProductionOrdeInfoService.trolleyYardBinDing(omProductionOrdeInfo);
282     }
283
284     @PostMapping("/getCarCodeSize")
285     public AjaxResult getCarCodeSize(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
286     {
287         return omProductionOrdeInfoService.getCarCodeSize(omProductionOrdeInfo);
288     }
289
290     @PostMapping("/findBytrolleyYardGetOne")
291     public AjaxResult findBytrolleyYardGetOne(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
292     {
293         return omProductionOrdeInfoService.findBytrolleyYardGetOne(omProductionOrdeInfo);
294     }
295
296     @GetMapping("/workReportingByStation/{id}/{stationCode}")
297     public AjaxResult workReportingByStation(@PathVariable("id") Long id, @PathVariable("stationCode") String stationCode)
298     {
299         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
300         omProductionOrdeInfo.setId(id);
301         omProductionOrdeInfo.setStationCode(stationCode);
302         return omProductionOrdeInfoService.workReportingByStation(omProductionOrdeInfo);
303     }
304 }