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