admin
2024-09-14 616068b49ed7ca709877a30d8abc56ecb6454218
提交 | 用户 | 时间
b78728 1 package com.jcdm.main.bs.formulaChild.controller;
A 2
4cba4a 3 import java.text.SimpleDateFormat;
C 4 import java.util.Date;
b78728 5 import java.util.List;
A 6 import java.util.stream.Collectors;
7 import javax.servlet.http.HttpServletResponse;
8
9 import cn.hutool.core.collection.CollUtil;
10 import cn.hutool.core.util.ObjectUtil;
11 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
12 import com.jcdm.main.constant.Constants;
616068 13 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
A 14 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
b78728 15 import com.kangaroohy.milo.model.ReadWriteEntity;
A 16 import com.kangaroohy.milo.service.MiloService;
17 import org.springframework.security.access.prepost.PreAuthorize;
18 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.web.bind.annotation.GetMapping;
20 import org.springframework.web.bind.annotation.PostMapping;
21 import org.springframework.web.bind.annotation.PutMapping;
22 import org.springframework.web.bind.annotation.DeleteMapping;
23 import org.springframework.web.bind.annotation.PathVariable;
24 import org.springframework.web.bind.annotation.RequestBody;
25 import org.springframework.web.bind.annotation.RequestMapping;
26 import org.springframework.web.bind.annotation.RestController;
27 import com.jcdm.common.annotation.Log;
28 import com.jcdm.common.core.controller.BaseController;
29 import com.jcdm.common.core.domain.AjaxResult;
30 import com.jcdm.common.enums.BusinessType;
31 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
32 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
33 import com.jcdm.common.utils.poi.ExcelUtil;
34 import com.jcdm.common.core.page.TableDataInfo;
35
36 /**
37  * 配方配置子信息Controller
38  * 
39  * @author ruimin
40  * @date 2023-12-26
41  */
42 @RestController
43 @RequestMapping("/bs/formulaChild")
44 public class BsFormulaChildInfoController extends BaseController
45 {
46     @Autowired
47     private IBsFormulaChildInfoService bsFormulaChildInfoService;
616068 48
A 49     @Autowired
50     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
b78728 51
A 52     @Autowired
53     private MiloService miloService;
54
55     /**
56      * 未做完工序回复plc信号
57      */
58     @GetMapping("/unfinishedProcess")
59     public AjaxResult unfinishedProcess(BsFormulaChildInfo bsFormulaChildInfo)
60     {
989363 61         String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getProcessesCode());//获取通道
b78728 62         try {
989363 63 //            String str = "MOZU1."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone";
A 64 //            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(bsFormulaChildInfo.getRecordDataDone()).build());
65             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare+"."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone").value(bsFormulaChildInfo.getRecordDataDone()).build());
b78728 66         } catch (Exception e) {
A 67             throw new RuntimeException(e);
68         }
69         return AjaxResult.success();
70     }
71
72     /**
73      * 扫码确认
74      */
75     @GetMapping("/initializedData")
76     public AjaxResult initializedData(BsFormulaChildInfo bsFormulaChildInfo)
77     {
78         String productNum = "";
79         try {
8c09d8 80             String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getLocationCode());
C 81             String str = thoroughfare+"."+bsFormulaChildInfo.getLocationCode()+".SNCode";
b78728 82             Object productNumObject = miloService.readFromOpcUa(str).getValue();
A 83             if(ObjectUtil.isNotNull(productNumObject)){
84                 productNum = productNumObject.toString();
85             }
86         } catch (Exception e) {
87             throw new RuntimeException(e);
88         }
89         return AjaxResult.success(productNum);
90     }
91
92     /**
93      * 扫码确认
94      */
95     @GetMapping("/fistSetpNumber")
96     public AjaxResult fistSetpNumber(BsFormulaChildInfo bsFormulaChildInfo)
97     {
98 //        try {
99 //            String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".MStepNumber";
100 //            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(1).build());
101 //        } catch (Exception e) {
102 //            throw new RuntimeException(e);
103 //        }
104         Integer stepNumber = 1;
105         try {
4280d7 106 //            List<BsFormulaChildInfo> op260 = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
A 107 //                    .eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
108 //                    .eq(BsFormulaChildInfo::getOperationType, "1")
109 //            );
110 //            List<BsFormulaChildInfo> filteredList = op260.stream()
111 //                    .filter(obj -> obj.getResults() != null && !obj.getResults().isEmpty())
112 //                    .collect(Collectors.toList());
113 //            if(filteredList.size() > 0){
114 //                stepNumber = Integer.valueOf(filteredList.get(filteredList.size()-1).getStepSort())+1;
115 //            }
b78728 116
039f89 117             String thoroughfare = Constants.thoroughfareMap.get(bsFormulaChildInfo.getProcessesCode());//获取通道
fd4ea6 118             String str = thoroughfare+"."+bsFormulaChildInfo.getProcessesCode()+".MESScrew";
b82de6 119             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());//拧紧步骤
252f60 120             if("OP230".equals(bsFormulaChildInfo.getProcessesCode())){
616068 121                 List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.list(new LambdaQueryWrapper<OmProductionOrdeInfo>().like(OmProductionOrdeInfo::getProductNum, bsFormulaChildInfo.getSfcBarcode()));
A 122                 String sfcCode = list.get(0).getProductNum();
4cba4a 123                 //所有进站将进站时间写给PLC
C 124                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
125                 String currentDate = dateFormat.format(new Date());
126                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".StartTime").value(currentDate).build());
616068 127                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".SNCode").value(sfcCode).build());
f2a963 128                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".RecordDataDone").value(11).build());
252f60 129             }else if("OP220".equals(bsFormulaChildInfo.getProcessesCode())){
f2a963 130                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".RecordDataDone").value(11).build());
4cba4a 131             }
b82de6 132
b78728 133         } catch (Exception e) {
A 134             throw new RuntimeException(e);
135         }
136         return AjaxResult.success(stepNumber);
137     }
138
139     /**
140      * 查询配方配置子信息列表
141      */
142     @GetMapping("/noPageListFormulaChild")
143     public TableDataInfo noPageListFormulaChild(BsFormulaChildInfo bsFormulaChildInfo)
144     {
145
146         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
147                 .eq(BsFormulaChildInfo::getProductCode,bsFormulaChildInfo.getProductCode())
148                 .eq(BsFormulaChildInfo::getProcessesCode,bsFormulaChildInfo.getProcessesCode())
eec569 149 //                .orderByAsc(BsFormulaChildInfo::getStepSort)
b78728 150         );
A 151         if (CollUtil.isNotEmpty(list)){
152             List<BsFormulaChildInfo> collect1 = list.stream().filter(x -> Constants.OK.equals(x.getResults())).collect(Collectors.toList());
153             List<BsFormulaChildInfo> collect2 = list.stream().filter(x -> !Constants.OK.equals(x.getResults())).collect(Collectors.toList());
154             list = collect1;
155             list.addAll(collect2);
156         }
157         for (BsFormulaChildInfo formulaChildInfo : list) {
158 //            formulaChildInfo.setSort(formulaChildInfo.getStepSort());
159 //            formulaChildInfo.setAddress(formulaChildInfo.getTechRequirement());
160 //            formulaChildInfo.setImg(formulaChildInfo.getOperationSteps());
161             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
162                 if(formulaChildInfo.getCollectData().contains("[")){
163                     String data = formulaChildInfo.getCollectData();
164                     data = data.replace("[", "").replace("]", "").replace(" ", "");
165                     String[] tightenDataParts = data.split(",");
166                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
167                 }
168             }
169         }
170         return getDataTable(list);
171     }
172
173     /**
174      * 查询配方配置子信息列表
175      */
176     @PreAuthorize("@ss.hasPermi('bs:formulaChild:list')")
177     @GetMapping("/list")
178     public TableDataInfo list(BsFormulaChildInfo bsFormulaChildInfo)
179     {
180         startPage();
181         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
182         for (BsFormulaChildInfo formulaChildInfo : list) {
183             formulaChildInfo.setSort(formulaChildInfo.getStepSort());
184             formulaChildInfo.setAddress(formulaChildInfo.getTechRequirement());
185             formulaChildInfo.setImg(formulaChildInfo.getOperationSteps());
186             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
187                 if(formulaChildInfo.getCollectData().contains("[")){
188                     String data = formulaChildInfo.getCollectData();
189                     data = data.replace("[", "").replace("]", "").replace(" ", "");
190                     String[] tightenDataParts = data.split(",");
191                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
192                 }
193             }
194         }
195         return getDataTable(list);
196     }
197
198 //    /**
199 //     * 检查是否可以放行
200 //     */
201 //    @GetMapping("/releaseCheck")
202 //    public AjaxResult releaseCheck(BsFormulaChildInfo bsFormulaChildInfo)
203 //    {
204 //        List<BsFormulaChildInfo> i = bsFormulaChildInfoService.releaseCheck(bsFormulaChildInfo);
205 //        return AjaxResult.success(i.size());
206 //    }
207
208     /**
209      * 扫码确认
210      */
211     @GetMapping("/updateResults")
212     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo)
213     {
214         return bsFormulaChildInfoService.updateResults(bsFormulaChildInfo);
215     }
216
217     /**
218      * 扫码确认
219      */
220     @GetMapping("/jrmUpdateResults")
221     public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
222     {
223         return bsFormulaChildInfoService.jrmUpdateResults(bsFormulaChildInfo);
224     }
225
226     /**
227      * 扫码确认
228      */
229     @GetMapping("/yzUpdateResults")
230     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
231     {
232         return bsFormulaChildInfoService.yzUpdateResults(bsFormulaChildInfo);
233     }
234
235     /**
236      * 放行请空状态
237      */
238     @GetMapping("/workpieceRelease")
239     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
240     {
241         return bsFormulaChildInfoService.workpieceRelease(bsFormulaChildInfo);
242     }
243
244     /**
245      * 放行请空状态
246      */
247     @GetMapping("/checkMaterialCode")
248     public AjaxResult checkMaterialCode(BsFormulaChildInfo bsFormulaChildInfo)
249     {
250         return bsFormulaChildInfoService.checkMaterialCode(bsFormulaChildInfo);
251     }
252
253     /**
254      * 放行请空状态
255      */
256     @GetMapping("/clearWorkpieceRelease")
257     public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
258     {
259         return bsFormulaChildInfoService.clearWorkpieceRelease(bsFormulaChildInfo);
260     }
261
262     /**
263      * 放行请空状态
264      */
265     @GetMapping("/jrmWorkpieceRelease")
266     public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
267     {
268         return bsFormulaChildInfoService.jrmWorkpieceRelease(bsFormulaChildInfo);
269     }
270
271     /**
272      * 拧紧后更新对应数据
273      */
274     @GetMapping("/updateTighteningFormula")
275     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
276     {
277         return bsFormulaChildInfoService.updateTighteningFormula(bsFormulaChildInfo);
278     }
279
280     /**
281      * 拧紧后更新对应数据
282      */
283     @GetMapping("/yzUpdateTighteningFormula")
284     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
285     {
286         return bsFormulaChildInfoService.yzUpdateTighteningFormula(bsFormulaChildInfo);
287     }
288
289     /**
290      * 导出配方配置子信息列表
291      */
292     @PreAuthorize("@ss.hasPermi('bs:formulaChild:export')")
293     @Log(title = "配方配置子信息", businessType = BusinessType.EXPORT)
294     @PostMapping("/export")
295     public void export(HttpServletResponse response, BsFormulaChildInfo bsFormulaChildInfo)
296     {
297         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
298         ExcelUtil<BsFormulaChildInfo> util = new ExcelUtil<BsFormulaChildInfo>(BsFormulaChildInfo.class);
299         util.exportExcel(response, list, "配方配置子信息数据");
300     }
301
302     /**
303      * 获取配方配置子信息详细信息
304      */
305     @PreAuthorize("@ss.hasPermi('bs:formulaChild:query')")
306     @GetMapping(value = "/{id}")
307     public AjaxResult getInfo(@PathVariable("id") Long id)
308     {
309         return success(bsFormulaChildInfoService.selectBsFormulaChildInfoById(id));
310     }
311
312     /**
313      * 新增配方配置子信息
314      */
315     @PreAuthorize("@ss.hasPermi('bs:formulaChild:add')")
316     @Log(title = "配方配置子信息", businessType = BusinessType.INSERT)
317     @PostMapping
318     public AjaxResult add(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
319     {
320         return toAjax(bsFormulaChildInfoService.insertBsFormulaChildInfo(bsFormulaChildInfo));
321     }
322
323     /**
324      * 修改配方配置子信息
325      */
326     @PreAuthorize("@ss.hasPermi('bs:formulaChild:edit')")
327     @Log(title = "配方配置子信息", businessType = BusinessType.UPDATE)
328     @PutMapping
329     public AjaxResult edit(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
330     {
331         return toAjax(bsFormulaChildInfoService.updateBsFormulaChildInfo(bsFormulaChildInfo));
332     }
333
334     /**
335      * 删除配方配置子信息
336      */
337     @PreAuthorize("@ss.hasPermi('bs:formulaChild:remove')")
338     @Log(title = "配方配置子信息", businessType = BusinessType.DELETE)
339     @DeleteMapping("/{ids}")
340     public AjaxResult remove(@PathVariable Long[] ids)
341     {
342         return toAjax(bsFormulaChildInfoService.deleteBsFormulaChildInfoByIds(ids));
343     }
344 }