admin
2024-07-18 0aaabac24ac4ebc2fe3e54c56e95f250ea238d5b
提交 | 用户 | 时间
e57a89 1 package com.jcdm.main.bs.formulaChild.controller;
2
3 import java.util.List;
6a462f 4 import java.util.stream.Collectors;
e57a89 5 import javax.servlet.http.HttpServletResponse;
0caf87 6
6a462f 7 import cn.hutool.core.collection.CollUtil;
273d64 8 import cn.hutool.core.util.ObjectUtil;
0caf87 9 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
0aaaba 10 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
A 11 import com.jcdm.main.bs.formulaChildInfoTemp.domain.BsFormulaChildInfoTemp;
12 import com.jcdm.main.bs.formulaChildInfoTemp.service.IBsFormulaChildInfoTempService;
6a462f 13 import com.jcdm.main.constant.Constants;
273d64 14 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
A 15 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
a320dc 16 import com.kangaroohy.milo.model.ReadWriteEntity;
A 17 import com.kangaroohy.milo.service.MiloService;
e57a89 18 import org.springframework.security.access.prepost.PreAuthorize;
19 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.web.bind.annotation.GetMapping;
21 import org.springframework.web.bind.annotation.PostMapping;
22 import org.springframework.web.bind.annotation.PutMapping;
23 import org.springframework.web.bind.annotation.DeleteMapping;
24 import org.springframework.web.bind.annotation.PathVariable;
25 import org.springframework.web.bind.annotation.RequestBody;
26 import org.springframework.web.bind.annotation.RequestMapping;
27 import org.springframework.web.bind.annotation.RestController;
28 import com.jcdm.common.annotation.Log;
29 import com.jcdm.common.core.controller.BaseController;
30 import com.jcdm.common.core.domain.AjaxResult;
31 import com.jcdm.common.enums.BusinessType;
32 import com.jcdm.main.bs.formulaChild.domain.BsFormulaChildInfo;
33 import com.jcdm.main.bs.formulaChild.service.IBsFormulaChildInfoService;
34 import com.jcdm.common.utils.poi.ExcelUtil;
35 import com.jcdm.common.core.page.TableDataInfo;
36
37 /**
38  * 配方配置子信息Controller
39  * 
40  * @author ruimin
41  * @date 2023-12-26
42  */
43 @RestController
44 @RequestMapping("/bs/formulaChild")
45 public class BsFormulaChildInfoController extends BaseController
46 {
47     @Autowired
48     private IBsFormulaChildInfoService bsFormulaChildInfoService;
49
a320dc 50     @Autowired
273d64 51     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
A 52
53     @Autowired
a320dc 54     private MiloService miloService;
273d64 55
0aaaba 56     @Autowired
A 57     private IBsFormulaChildInfoTempService bsFormulaChildInfoTempService;
58
273d64 59     /**
A 60      * 扫码确认
61      */
62     @GetMapping("/inPlaceInspection")
63     public AjaxResult inPlaceInspection(BsFormulaChildInfo bsFormulaChildInfo)
64     {
65         Integer recordDataDone = 0;
66         try {
67             Object orderNumberObject = miloService.readFromOpcUa("PACK."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone").getValue();
68             if(ObjectUtil.isNotEmpty(orderNumberObject)){
69                 if(Integer.valueOf(orderNumberObject.toString()) == 11){
70                     recordDataDone = 1;
71                 }
72             }
73
74         } catch (Exception e) {
75             throw new RuntimeException(e);
76         }
77         return AjaxResult.success(recordDataDone);
78     }
79
80     /**
81      * 扫码确认
82      */
83     @GetMapping("/unfinishedProcess")
84     public AjaxResult unfinishedProcess(BsFormulaChildInfo bsFormulaChildInfo)
85     {
86         try {
87             String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".RecordDataDone";
88             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(bsFormulaChildInfo.getRecordDataDone()).build());
89         } catch (Exception e) {
90             throw new RuntimeException(e);
91         }
92         return AjaxResult.success();
93     }
94
95     @GetMapping("/manualNgOffline")
96     public AjaxResult manualNgOffline(BsFormulaChildInfo bsFormulaChildInfo)
97     {
0aaaba 98         Integer stepNumber = 31;
273d64 99         try {
0aaaba 100             logger.info("手动下线,写入ArtificialNgSignal为:{}",stepNumber);
A 101             String str = "PACK."+bsFormulaChildInfo.getLocationCode()+".ArtificialNgSignal";
273d64 102             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());
A 103         } catch (Exception e) {
104             throw new RuntimeException(e);
105         }
106         OmProductionOrdeInfo one = omProductionOrdeInfoService.getOne(new LambdaQueryWrapper<OmProductionOrdeInfo>()
107                 .eq(OmProductionOrdeInfo::getProductNum, bsFormulaChildInfo.getSfcBarcode())
108         );
109         one.setArtificialNgFlag("1");
110         omProductionOrdeInfoService.saveOrUpdate(one);
111         return AjaxResult.success(stepNumber);
112     }
a320dc 113
A 114     /**
115      * 扫码确认
116      */
117     @GetMapping("/fistSetpNumber")
bdb404 118     public AjaxResult fistSetpNumber(BsFormulaChildInfo bsFormulaChildInfo)
a320dc 119     {
bdb404 120 //        try {
A 121 //            String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".MStepNumber";
122 //            miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(1).build());
123 //        } catch (Exception e) {
124 //            throw new RuntimeException(e);
125 //        }
126         Integer stepNumber = 1;
a320dc 127         try {
bdb404 128             List<BsFormulaChildInfo> op260 = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>().eq(BsFormulaChildInfo::getProcessesCode, bsFormulaChildInfo.getProcessesCode()));
A 129             List<BsFormulaChildInfo> filteredList = op260.stream()
130                     .filter(obj -> obj.getResults() != null && !obj.getResults().isEmpty())
131                     .collect(Collectors.toList());
132             if(filteredList.size() > 0){
133                 stepNumber = Integer.valueOf(filteredList.get(filteredList.size()-1).getStepSort())+1;
134             }
135
a320dc 136             String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".MStepNumber";
bdb404 137             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());
a320dc 138         } catch (Exception e) {
A 139             throw new RuntimeException(e);
140         }
bdb404 141         return AjaxResult.success(stepNumber);
a320dc 142     }
A 143
e57a89 144     /**
145      * 查询配方配置子信息列表
146      */
0aaaba 147 //    @GetMapping("/noPageListFormulaChild")
A 148 //    public TableDataInfo noPageListFormulaChild(BsFormulaChildInfo bsFormulaChildInfo)
149 //    {
150 //
151 //        List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
152 //                .eq(BsFormulaChildInfo::getProductCode,bsFormulaChildInfo.getProductCode())
153 //                .eq(BsFormulaChildInfo::getProcessesCode,bsFormulaChildInfo.getProcessesCode())
154 //        );
155 //        if (CollUtil.isNotEmpty(list)){
156 //            List<BsFormulaChildInfo> collect1 = list.stream().filter(x -> Constants.OK.equals(x.getResults())).collect(Collectors.toList());
157 //            List<BsFormulaChildInfo> collect2 = list.stream().filter(x -> !Constants.OK.equals(x.getResults())).collect(Collectors.toList());
158 //            list = collect1;
159 //            list.addAll(collect2);
160 //        }
161 //
162 //        if("1".equals(bsFormulaChildInfo.getArtificialNgFlag())){
163 //            List<BsFormulaChildInfoTemp> tempList = bsFormulaChildInfoTempService.list(new LambdaQueryWrapper<BsFormulaChildInfoTemp>()
164 //                    .eq(BsFormulaChildInfoTemp::getProcessesCode, bsFormulaChildInfo.getProcessesCode())
165 //                    .eq(BsFormulaChildInfoTemp::getProductCode, bsFormulaChildInfo.getProductCode())
166 //                    .eq(BsFormulaChildInfoTemp::getSfcCode, bsFormulaChildInfo.getSfcBarcode()));
167 //
168 //            for (int i = 0; i < list.size(); i++) {
169 //                BsFormulaChildInfo formulaChildInfo = list.get(i);
170 //                if(i < tempList.size()){
171 //                    BsFormulaChildInfoTemp childInfoTemp = tempList.get(i);
172 //                    if(ObjectUtil.isNotEmpty(childInfoTemp)){
173 //                        formulaChildInfo.setResults(childInfoTemp.getResults());
174 //                        formulaChildInfo.setCollectData(childInfoTemp.getCollectData());
175 //                        bsFormulaChildInfoService.saveOrUpdate(formulaChildInfo);
176 //                    }
177 //                }
178 //                if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
179 //                    if(formulaChildInfo.getCollectData().contains("[")){
180 //                        String data = formulaChildInfo.getCollectData();
181 //                        data = data.replace("[", "").replace("]", "").replace(" ", "");
182 //                        String[] tightenDataParts = data.split(",");
183 //                        formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
184 //                    }
185 //                }
186 //            }
187 //
188 //            //给plc写ng工步
189 //            BsFormulaChildInfoTemp lastTemp = tempList.get(tempList.size()-1);
190 //            try {
191 //                Integer stepSort = Integer.valueOf(lastTemp.getStepSort()+1);
192 //                logger.info("ng工件给plc写工步为:{}---工位{}---pack码{}",stepSort,lastTemp.getProcessesCode(),lastTemp.getSfcCode());
193 //                String str = "PACK."+bsFormulaChildInfo.getProcessesCode()+".MStepNumber";
194 //                miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepSort+1).build());
195 //            } catch (Exception e) {
196 //                throw new RuntimeException(e);
197 //            }
198 //
199 //            //清除工单标记
200 //            LambdaUpdateWrapper<OmProductionOrdeInfo> updateWrapper = new LambdaUpdateWrapper<>();
201 //            updateWrapper.set(OmProductionOrdeInfo::getArtificialNgFlag, "");
202 //            updateWrapper.eq(OmProductionOrdeInfo::getProductNum, lastTemp.getSfcCode());
203 //            boolean update = omProductionOrdeInfoService.update(new OmProductionOrdeInfo(), updateWrapper);
204 //        }else {
205 //            for (BsFormulaChildInfo formulaChildInfo : list) {
206 //                if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
207 //                    if(formulaChildInfo.getCollectData().contains("[")){
208 //                        String data = formulaChildInfo.getCollectData();
209 //                        data = data.replace("[", "").replace("]", "").replace(" ", "");
210 //                        String[] tightenDataParts = data.split(",");
211 //                        formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
212 //                    }
213 //                }
214 //            }
215 //        }
216 //        return getDataTable(list);
217 //    }
218
0caf87 219     @GetMapping("/noPageListFormulaChild")
220     public TableDataInfo noPageListFormulaChild(BsFormulaChildInfo bsFormulaChildInfo)
221     {
a320dc 222
0caf87 223         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
0aaaba 224                         .eq(BsFormulaChildInfo::getProductCode,bsFormulaChildInfo.getProductCode())
A 225                         .eq(BsFormulaChildInfo::getProcessesCode,bsFormulaChildInfo.getProcessesCode())
768498 226         );
6a462f 227         if (CollUtil.isNotEmpty(list)){
W 228             List<BsFormulaChildInfo> collect1 = list.stream().filter(x -> Constants.OK.equals(x.getResults())).collect(Collectors.toList());
229             List<BsFormulaChildInfo> collect2 = list.stream().filter(x -> !Constants.OK.equals(x.getResults())).collect(Collectors.toList());
230             list = collect1;
231             list.addAll(collect2);
232         }
0caf87 233         for (BsFormulaChildInfo formulaChildInfo : list) {
234             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
235                 if(formulaChildInfo.getCollectData().contains("[")){
236                     String data = formulaChildInfo.getCollectData();
237                     data = data.replace("[", "").replace("]", "").replace(" ", "");
238                     String[] tightenDataParts = data.split(",");
239                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
240                 }
241             }
242         }
243         return getDataTable(list);
244     }
245
246     /**
247      * 查询配方配置子信息列表
248      */
e57a89 249     @PreAuthorize("@ss.hasPermi('bs:formulaChild:list')")
250     @GetMapping("/list")
251     public TableDataInfo list(BsFormulaChildInfo bsFormulaChildInfo)
252     {
253         startPage();
254         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
255         for (BsFormulaChildInfo formulaChildInfo : list) {
256             formulaChildInfo.setSort(formulaChildInfo.getStepSort());
257             formulaChildInfo.setAddress(formulaChildInfo.getTechRequirement());
258             formulaChildInfo.setImg(formulaChildInfo.getOperationSteps());
b77303 259             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
260                 if(formulaChildInfo.getCollectData().contains("[")){
261                     String data = formulaChildInfo.getCollectData();
262                     data = data.replace("[", "").replace("]", "").replace(" ", "");
263                     String[] tightenDataParts = data.split(",");
264                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
265                 }
266             }
e57a89 267         }
268         return getDataTable(list);
269     }
270
b77303 271 //    /**
272 //     * 检查是否可以放行
273 //     */
274 //    @GetMapping("/releaseCheck")
275 //    public AjaxResult releaseCheck(BsFormulaChildInfo bsFormulaChildInfo)
276 //    {
277 //        List<BsFormulaChildInfo> i = bsFormulaChildInfoService.releaseCheck(bsFormulaChildInfo);
278 //        return AjaxResult.success(i.size());
279 //    }
e57a89 280
281     /**
282      * 扫码确认
283      */
284     @GetMapping("/updateResults")
285     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo)
286     {
287         return bsFormulaChildInfoService.updateResults(bsFormulaChildInfo);
288     }
289
290     /**
2c7661 291      * 扫码确认
A 292      */
06713a 293     @GetMapping("/jrmUpdateResults")
A 294     public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
295     {
296         return bsFormulaChildInfoService.jrmUpdateResults(bsFormulaChildInfo);
297     }
298
299     /**
300      * 扫码确认
301      */
2c7661 302     @GetMapping("/yzUpdateResults")
A 303     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
304     {
305         return bsFormulaChildInfoService.yzUpdateResults(bsFormulaChildInfo);
306     }
307
308     /**
e57a89 309      * 放行请空状态
310      */
311     @GetMapping("/workpieceRelease")
312     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
313     {
314         return bsFormulaChildInfoService.workpieceRelease(bsFormulaChildInfo);
315     }
316
317     /**
8cfe20 318      * 放行请空状态
A 319      */
bdb404 320     @GetMapping("/checkMaterialCode")
A 321     public AjaxResult checkMaterialCode(BsFormulaChildInfo bsFormulaChildInfo)
322     {
323         return bsFormulaChildInfoService.checkMaterialCode(bsFormulaChildInfo);
324     }
325
326     /**
327      * 放行请空状态
328      */
8cfe20 329     @GetMapping("/clearWorkpieceRelease")
A 330     public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
331     {
332         return bsFormulaChildInfoService.clearWorkpieceRelease(bsFormulaChildInfo);
333     }
334
335     /**
336      * 放行请空状态
337      */
338     @GetMapping("/jrmWorkpieceRelease")
339     public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
340     {
341         return bsFormulaChildInfoService.jrmWorkpieceRelease(bsFormulaChildInfo);
342     }
343
344     /**
b77303 345      * 拧紧后更新对应数据
346      */
347     @GetMapping("/updateTighteningFormula")
348     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
349     {
350         return bsFormulaChildInfoService.updateTighteningFormula(bsFormulaChildInfo);
351     }
352
353     /**
2c7661 354      * 拧紧后更新对应数据
A 355      */
356     @GetMapping("/yzUpdateTighteningFormula")
357     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
358     {
359         return bsFormulaChildInfoService.yzUpdateTighteningFormula(bsFormulaChildInfo);
360     }
361
362     /**
e57a89 363      * 导出配方配置子信息列表
364      */
365     @PreAuthorize("@ss.hasPermi('bs:formulaChild:export')")
366     @Log(title = "配方配置子信息", businessType = BusinessType.EXPORT)
367     @PostMapping("/export")
368     public void export(HttpServletResponse response, BsFormulaChildInfo bsFormulaChildInfo)
369     {
370         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
371         ExcelUtil<BsFormulaChildInfo> util = new ExcelUtil<BsFormulaChildInfo>(BsFormulaChildInfo.class);
372         util.exportExcel(response, list, "配方配置子信息数据");
373     }
374
375     /**
376      * 获取配方配置子信息详细信息
377      */
378     @PreAuthorize("@ss.hasPermi('bs:formulaChild:query')")
379     @GetMapping(value = "/{id}")
380     public AjaxResult getInfo(@PathVariable("id") Long id)
381     {
382         return success(bsFormulaChildInfoService.selectBsFormulaChildInfoById(id));
383     }
384
385     /**
386      * 新增配方配置子信息
387      */
388     @PreAuthorize("@ss.hasPermi('bs:formulaChild:add')")
389     @Log(title = "配方配置子信息", businessType = BusinessType.INSERT)
390     @PostMapping
391     public AjaxResult add(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
392     {
393         return toAjax(bsFormulaChildInfoService.insertBsFormulaChildInfo(bsFormulaChildInfo));
394     }
395
396     /**
397      * 修改配方配置子信息
398      */
399     @PreAuthorize("@ss.hasPermi('bs:formulaChild:edit')")
400     @Log(title = "配方配置子信息", businessType = BusinessType.UPDATE)
401     @PutMapping
402     public AjaxResult edit(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
403     {
404         return toAjax(bsFormulaChildInfoService.updateBsFormulaChildInfo(bsFormulaChildInfo));
405     }
406
407     /**
408      * 删除配方配置子信息
409      */
410     @PreAuthorize("@ss.hasPermi('bs:formulaChild:remove')")
411     @Log(title = "配方配置子信息", businessType = BusinessType.DELETE)
412     @DeleteMapping("/{ids}")
413     public AjaxResult remove(@PathVariable Long[] ids)
414     {
415         return toAjax(bsFormulaChildInfoService.deleteBsFormulaChildInfoByIds(ids));
416     }
417 }