cl
2024-08-13 db6ebb25325838edb5e8bb9c55388341935628b8
提交 | 用户 | 时间
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";
4cba4a 114             if(bsFormulaChildInfo.getProcessesCode().equals("OP230")){
C 115                 //所有进站将进站时间写给PLC
116                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
117                 String currentDate = dateFormat.format(new Date());
118                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".StartTime").value(currentDate).build());
119                 Integer recordDataDone = 11;
120                 miloService.writeToOpcUa(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".SNCode").value(bsFormulaChildInfo.getSfcBarcode()).build());
121                 miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(thoroughfare + "." + bsFormulaChildInfo.getProcessesCode() + ".RecordDataDone").value(recordDataDone).build());
122             }
b78728 123             miloService.writeToOpcShort(ReadWriteEntity.builder().identifier(str).value(stepNumber).build());
A 124         } catch (Exception e) {
125             throw new RuntimeException(e);
126         }
127         return AjaxResult.success(stepNumber);
128     }
129
130     /**
131      * 查询配方配置子信息列表
132      */
133     @GetMapping("/noPageListFormulaChild")
134     public TableDataInfo noPageListFormulaChild(BsFormulaChildInfo bsFormulaChildInfo)
135     {
136
137         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.list(new LambdaQueryWrapper<BsFormulaChildInfo>()
138                 .eq(BsFormulaChildInfo::getProductCode,bsFormulaChildInfo.getProductCode())
139                 .eq(BsFormulaChildInfo::getProcessesCode,bsFormulaChildInfo.getProcessesCode())
eec569 140 //                .orderByAsc(BsFormulaChildInfo::getStepSort)
b78728 141         );
A 142         if (CollUtil.isNotEmpty(list)){
143             List<BsFormulaChildInfo> collect1 = list.stream().filter(x -> Constants.OK.equals(x.getResults())).collect(Collectors.toList());
144             List<BsFormulaChildInfo> collect2 = list.stream().filter(x -> !Constants.OK.equals(x.getResults())).collect(Collectors.toList());
145             list = collect1;
146             list.addAll(collect2);
147         }
148         for (BsFormulaChildInfo formulaChildInfo : list) {
149 //            formulaChildInfo.setSort(formulaChildInfo.getStepSort());
150 //            formulaChildInfo.setAddress(formulaChildInfo.getTechRequirement());
151 //            formulaChildInfo.setImg(formulaChildInfo.getOperationSteps());
152             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
153                 if(formulaChildInfo.getCollectData().contains("[")){
154                     String data = formulaChildInfo.getCollectData();
155                     data = data.replace("[", "").replace("]", "").replace(" ", "");
156                     String[] tightenDataParts = data.split(",");
157                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
158                 }
159             }
160         }
161         return getDataTable(list);
162     }
163
164     /**
165      * 查询配方配置子信息列表
166      */
167     @PreAuthorize("@ss.hasPermi('bs:formulaChild:list')")
168     @GetMapping("/list")
169     public TableDataInfo list(BsFormulaChildInfo bsFormulaChildInfo)
170     {
171         startPage();
172         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
173         for (BsFormulaChildInfo formulaChildInfo : list) {
174             formulaChildInfo.setSort(formulaChildInfo.getStepSort());
175             formulaChildInfo.setAddress(formulaChildInfo.getTechRequirement());
176             formulaChildInfo.setImg(formulaChildInfo.getOperationSteps());
177             if(formulaChildInfo.getCollectData()!=null&& !"".equals(formulaChildInfo.getCollectData())){
178                 if(formulaChildInfo.getCollectData().contains("[")){
179                     String data = formulaChildInfo.getCollectData();
180                     data = data.replace("[", "").replace("]", "").replace(" ", "");
181                     String[] tightenDataParts = data.split(",");
182                     formulaChildInfo.setCollectData("扭矩"+tightenDataParts[0]+"角度"+tightenDataParts[1]+"扭矩结果"+tightenDataParts[2]+"角度结果"+tightenDataParts[3]);
183                 }
184             }
185         }
186         return getDataTable(list);
187     }
188
189 //    /**
190 //     * 检查是否可以放行
191 //     */
192 //    @GetMapping("/releaseCheck")
193 //    public AjaxResult releaseCheck(BsFormulaChildInfo bsFormulaChildInfo)
194 //    {
195 //        List<BsFormulaChildInfo> i = bsFormulaChildInfoService.releaseCheck(bsFormulaChildInfo);
196 //        return AjaxResult.success(i.size());
197 //    }
198
199     /**
200      * 扫码确认
201      */
202     @GetMapping("/updateResults")
203     public AjaxResult updateResults(BsFormulaChildInfo bsFormulaChildInfo)
204     {
205         return bsFormulaChildInfoService.updateResults(bsFormulaChildInfo);
206     }
207
208     /**
209      * 扫码确认
210      */
211     @GetMapping("/jrmUpdateResults")
212     public AjaxResult jrmUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
213     {
214         return bsFormulaChildInfoService.jrmUpdateResults(bsFormulaChildInfo);
215     }
216
217     /**
218      * 扫码确认
219      */
220     @GetMapping("/yzUpdateResults")
221     public AjaxResult yzUpdateResults(BsFormulaChildInfo bsFormulaChildInfo)
222     {
223         return bsFormulaChildInfoService.yzUpdateResults(bsFormulaChildInfo);
224     }
225
226     /**
227      * 放行请空状态
228      */
229     @GetMapping("/workpieceRelease")
230     public AjaxResult workpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
231     {
232         return bsFormulaChildInfoService.workpieceRelease(bsFormulaChildInfo);
233     }
234
235     /**
236      * 放行请空状态
237      */
238     @GetMapping("/checkMaterialCode")
239     public AjaxResult checkMaterialCode(BsFormulaChildInfo bsFormulaChildInfo)
240     {
241         return bsFormulaChildInfoService.checkMaterialCode(bsFormulaChildInfo);
242     }
243
244     /**
245      * 放行请空状态
246      */
247     @GetMapping("/clearWorkpieceRelease")
248     public AjaxResult clearWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
249     {
250         return bsFormulaChildInfoService.clearWorkpieceRelease(bsFormulaChildInfo);
251     }
252
253     /**
254      * 放行请空状态
255      */
256     @GetMapping("/jrmWorkpieceRelease")
257     public AjaxResult jrmWorkpieceRelease(BsFormulaChildInfo bsFormulaChildInfo)
258     {
259         return bsFormulaChildInfoService.jrmWorkpieceRelease(bsFormulaChildInfo);
260     }
261
262     /**
263      * 拧紧后更新对应数据
264      */
265     @GetMapping("/updateTighteningFormula")
266     public AjaxResult updateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
267     {
268         return bsFormulaChildInfoService.updateTighteningFormula(bsFormulaChildInfo);
269     }
270
271     /**
272      * 拧紧后更新对应数据
273      */
274     @GetMapping("/yzUpdateTighteningFormula")
275     public AjaxResult yzUpdateTighteningFormula(BsFormulaChildInfo bsFormulaChildInfo)
276     {
277         return bsFormulaChildInfoService.yzUpdateTighteningFormula(bsFormulaChildInfo);
278     }
279
280     /**
281      * 导出配方配置子信息列表
282      */
283     @PreAuthorize("@ss.hasPermi('bs:formulaChild:export')")
284     @Log(title = "配方配置子信息", businessType = BusinessType.EXPORT)
285     @PostMapping("/export")
286     public void export(HttpServletResponse response, BsFormulaChildInfo bsFormulaChildInfo)
287     {
288         List<BsFormulaChildInfo> list = bsFormulaChildInfoService.selectBsFormulaChildInfoList(bsFormulaChildInfo);
289         ExcelUtil<BsFormulaChildInfo> util = new ExcelUtil<BsFormulaChildInfo>(BsFormulaChildInfo.class);
290         util.exportExcel(response, list, "配方配置子信息数据");
291     }
292
293     /**
294      * 获取配方配置子信息详细信息
295      */
296     @PreAuthorize("@ss.hasPermi('bs:formulaChild:query')")
297     @GetMapping(value = "/{id}")
298     public AjaxResult getInfo(@PathVariable("id") Long id)
299     {
300         return success(bsFormulaChildInfoService.selectBsFormulaChildInfoById(id));
301     }
302
303     /**
304      * 新增配方配置子信息
305      */
306     @PreAuthorize("@ss.hasPermi('bs:formulaChild:add')")
307     @Log(title = "配方配置子信息", businessType = BusinessType.INSERT)
308     @PostMapping
309     public AjaxResult add(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
310     {
311         return toAjax(bsFormulaChildInfoService.insertBsFormulaChildInfo(bsFormulaChildInfo));
312     }
313
314     /**
315      * 修改配方配置子信息
316      */
317     @PreAuthorize("@ss.hasPermi('bs:formulaChild:edit')")
318     @Log(title = "配方配置子信息", businessType = BusinessType.UPDATE)
319     @PutMapping
320     public AjaxResult edit(@RequestBody BsFormulaChildInfo bsFormulaChildInfo)
321     {
322         return toAjax(bsFormulaChildInfoService.updateBsFormulaChildInfo(bsFormulaChildInfo));
323     }
324
325     /**
326      * 删除配方配置子信息
327      */
328     @PreAuthorize("@ss.hasPermi('bs:formulaChild:remove')")
329     @Log(title = "配方配置子信息", businessType = BusinessType.DELETE)
330     @DeleteMapping("/{ids}")
331     public AjaxResult remove(@PathVariable Long[] ids)
332     {
333         return toAjax(bsFormulaChildInfoService.deleteBsFormulaChildInfoByIds(ids));
334     }
335 }