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