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