春风项目四线(合箱线、总装线)
yyt
2024-05-20 d4f4376ab5aef071cb841de0f9a9b7f6cb16c651
提交 | 用户 | 时间
d9cf6b 1 package com.jcdm.main.bs.orderScheduling.controller;
J 2
c74dcb 3 import cn.hutool.core.collection.CollUtil;
W 4 import com.alibaba.excel.EasyExcel;
5 import com.alibaba.excel.ExcelWriter;
6 import com.alibaba.excel.write.metadata.WriteSheet;
7 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
c6aaad 8 import com.jcdm.common.annotation.Log;
W 9 import com.jcdm.common.core.controller.BaseController;
10 import com.jcdm.common.core.domain.AjaxResult;
c6e069 11 import com.jcdm.common.core.domain.R;
c74dcb 12 import com.jcdm.common.core.domain.entity.SysDictData;
c6aaad 13 import com.jcdm.common.core.page.TableDataInfo;
W 14 import com.jcdm.common.enums.BusinessType;
d4f437 15 import com.jcdm.common.utils.SecurityUtils;
766c03 16 import com.jcdm.common.utils.StringUtils;
c6aaad 17 import com.jcdm.common.utils.poi.ExcelUtil;
d4f437 18 import com.jcdm.main.bs.orderScheduling.common.Constants;
c6aaad 19 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
W 20 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
c74dcb 21 import com.jcdm.main.bs.orderScheduling.vo.FollowReportVO;
c6e069 22 import com.jcdm.main.bs.orderScheduling.vo.LineChartVO;
d4f437 23 import com.jcdm.main.bs.orderScheduling.vo.SumDataVO;
c74dcb 24 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
d4f437 25 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
Y 26 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
c74dcb 27 import com.jcdm.main.da.passingStationCollection.domain.DaPassingStationCollection;
d4f437 28 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
Y 29 import com.jcdm.main.om.productionOrde.service.impl.OmProductionOrdeInfoServiceImpl;
c6aaad 30 import com.jcdm.main.plcserver.conf.OPCElement;
d4f437 31 import com.jcdm.main.plcserver.sub.OPCUaSubscription;
c74dcb 32 import com.jcdm.system.service.ISysDictDataService;
c6aaad 33 import com.kangaroohy.milo.model.ReadWriteEntity;
W 34 import com.kangaroohy.milo.service.MiloService;
d9cf6b 35 import org.springframework.beans.factory.annotation.Autowired;
5a05af 36 import org.springframework.beans.factory.annotation.Value;
c6aaad 37 import org.springframework.security.access.prepost.PreAuthorize;
d4f437 38 import org.springframework.transaction.annotation.Transactional;
c6aaad 39 import org.springframework.web.bind.annotation.*;
W 40
41 import javax.annotation.Resource;
42 import javax.servlet.http.HttpServletResponse;
43 import java.io.IOException;
d4f437 44 import java.time.LocalDateTime;
c6aaad 45 import java.util.ArrayList;
W 46 import java.util.List;
47 import java.util.stream.Collectors;
d9cf6b 48
J 49 /**
50  * 订单排产Controller
51  * 
52  * @author jiang
2aea64 53  * @date 2024-01-13
d9cf6b 54  */
J 55 @RestController
56 @RequestMapping("/bs/orderScheduling")
57 public class BsOrderSchedulingController extends BaseController
58 {
59     @Autowired
60     private IBsOrderSchedulingService bsOrderSchedulingService;
61
c74dcb 62
W 63     @Resource
64     private ISysDictDataService iSysDictDataService;
65
d4f437 66     @Resource
Y 67     private OmProductionOrdeInfoServiceImpl productionOrdeInfoService;
68     @Resource
69     private DaParamCollectionMapper daParamCollectionService;
c6aaad 70
W 71     @Autowired
72     MiloService miloService;
73
5a05af 74     @Value("${websocketUrl}")
W 75     private String websocketUrl;
76
c6aaad 77     @GetMapping("/forceUpload")
W 78     public void forceUpload() throws Exception {
79         ReadWriteEntity entity = new ReadWriteEntity(OPCElement.OP121_ZZ_CODE_CHECK, 1);
80         miloService.writeToOpcByte(entity);
81     }
5a05af 82
W 83     @GetMapping("/websocketUrl")
84     public String websocketName() {
85         return websocketUrl;
86     }
87
88
d9cf6b 89     /**
J 90      * 查询订单排产列表
91      */
92     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
93     @GetMapping("/list")
94     public TableDataInfo list(BsOrderScheduling bsOrderScheduling)
95     {
29d394 96         startPage();
d9cf6b 97         List<BsOrderScheduling> list = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
J 98         return getDataTable(list);
99     }
100
c6e069 101     /**
8aafc5 102      * 查询追溯列表
c74dcb 103      */
W 104     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
105     @GetMapping("/getFollowReportList")
106     public R getFollowReportList(BsOrderScheduling bsOrderScheduling)
107     {
108         FollowReportVO followReportList = bsOrderSchedulingService.getFollowReportList(bsOrderScheduling);
109         return R.ok(followReportList);
110     }
111
112     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:export')")
113     @Log(title = "追溯报表导出", businessType = BusinessType.EXPORT)
114     @PostMapping("/exportFollow")
115     public void exportFollow(HttpServletResponse response, BsOrderScheduling bsOrderScheduling)
116     {
117         FollowReportVO followReportList = bsOrderSchedulingService.getFollowReportList(bsOrderScheduling);
118         List<SysDictData> allDict = iSysDictDataService.selectDictDataList(null);
119         if (CollUtil.isNotEmpty(followReportList.getMainList())){
120             List<SysDictData> dict1 = allDict.stream().filter(x -> "material_type".equals(x.getDictType())).collect(Collectors.toList());
121             List<SysDictData> dict2 = allDict.stream().filter(x -> "order_scheduling_produce_status".equals(x.getDictType())).collect(Collectors.toList());
122             for (BsOrderScheduling orderScheduling : followReportList.getMainList()) {
123                 if (CollUtil.isNotEmpty(dict1)){
124                     List<SysDictData> collect = dict1.stream().filter(x -> x.getDictValue().equals(orderScheduling.getProductType())).collect(Collectors.toList());
125                     if (CollUtil.isNotEmpty(collect)){
126                         SysDictData sysDictData1 = collect.get(0);
127                         orderScheduling.setProductTypeString(sysDictData1.getDictLabel());
128                     }
129                 }
130                 if (CollUtil.isNotEmpty(dict2)){
131                     List<SysDictData> collect = dict2.stream().filter(x -> x.getDictValue().equals(orderScheduling.getProductionStatus())).collect(Collectors.toList());
132                     if (CollUtil.isNotEmpty(collect)){
133                         SysDictData sysDictData1 = collect.get(0);
134                         orderScheduling.setProductionStatusString(sysDictData1.getDictLabel());
135                     }
136                 }
137             }
138         }
139         String fileName = "追溯报表";
140         try {
141             ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
142             WriteSheet mainSheet = EasyExcel.writerSheet(0, "订单排产")
143                     .head(BsOrderScheduling.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
144                     .build();
145             WriteSheet sheet1 = EasyExcel.writerSheet(1, "拧紧数据")
146                     .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
147                     .build();
148             WriteSheet sheet2 = EasyExcel.writerSheet(2, "相机检测")
149                     .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
150                     .build();
151             WriteSheet sheet3 = EasyExcel.writerSheet(3, "外漏检测")
152                     .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
153                     .build();
154             WriteSheet sheet4 = EasyExcel.writerSheet(4, "机油加注")
155                     .head(DaParamCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
156                     .build();
157             WriteSheet sheet5 = EasyExcel.writerSheet(5, "工位结果")
158                     .head(DaPassingStationCollection.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
159                     .build();
160             excelWriter.write(followReportList.getMainList(),mainSheet);
161             excelWriter.write(followReportList.getList1(),sheet1);
162             excelWriter.write(followReportList.getList2(),sheet2);
163             excelWriter.write(followReportList.getList3(),sheet3);
164             excelWriter.write(followReportList.getList4(),sheet4);
165             excelWriter.write(followReportList.getList5(),sheet5);
166             response.setContentType("application/vnd.ms-excel;charset=utf-8");
167             response.setCharacterEncoding("UTF-8");
168             response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
169             excelWriter.finish();
170         } catch (IOException e) {
171             throw new RuntimeException(e);
172         }
173     }
174
175     /**
c6e069 176      * 查询下线数量
W 177      */
178     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
179     @GetMapping("/getOffLineNum")
180     public TableDataInfo getOffLineNum(BsOrderScheduling bsOrderScheduling)
181     {
182
183         List<LineChartVO> vo = bsOrderSchedulingService.getOffLineNum();
184         return getDataTable(vo);
185     }
186
6eaf05 187     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:list')")
W 188     @GetMapping("/list2")
189     public TableDataInfo list2(BsOrderScheduling bsOrderScheduling)
190     {
b849f1 191 //        startPage();
766c03 192         List<BsOrderScheduling> list = new ArrayList<>();
C 193         if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
194             list = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
195         }
d9cf6b 196         return getDataTable(list);
J 197     }
198
d4f437 199     @GetMapping("/list3")
Y 200     public TableDataInfo list3(BsOrderScheduling bsOrderScheduling)
201     {
202         startPage();
203         List<BsOrderScheduling> list = new ArrayList<>();
204         if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
205             list = bsOrderSchedulingService.selectBsOrderSchedulingPage(bsOrderScheduling);
206         }
207         List<BsOrderScheduling> collect = list.stream().filter(x -> Constants.UN_QUALIFIED.equals(x.getQualityStatus())).collect(Collectors.toList());
208         if (CollUtil.isNotEmpty(collect)){
209             String.valueOf(collect.size());
210         }
211         return getDataTable(list);
212     }
213
d9cf6b 214     /**
J 215      * 导出订单排产列表
216      */
217     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:export')")
218     @Log(title = "订单排产", businessType = BusinessType.EXPORT)
219     @PostMapping("/export")
220     public void export(HttpServletResponse response, BsOrderScheduling bsOrderScheduling)
221     {
222         List<BsOrderScheduling> list = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
223         ExcelUtil<BsOrderScheduling> util = new ExcelUtil<BsOrderScheduling>(BsOrderScheduling.class);
224         util.exportExcel(response, list, "订单排产数据");
225     }
226
227     /**
228      * 获取订单排产详细信息
229      */
230     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:query')")
2aea64 231     @GetMapping(value = "/{id}")
J 232     public AjaxResult getInfo(@PathVariable("id") Long id)
d9cf6b 233     {
2aea64 234         return success(bsOrderSchedulingService.selectBsOrderSchedulingById(id));
d9cf6b 235     }
J 236
237     /**
238      * 新增订单排产
239      */
240     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:add')")
241     @Log(title = "订单排产", businessType = BusinessType.INSERT)
242     @PostMapping
243     public AjaxResult add(@RequestBody BsOrderScheduling bsOrderScheduling)
244     {
245         return toAjax(bsOrderSchedulingService.insertBsOrderScheduling(bsOrderScheduling));
246     }
247
248     /**
249      * 修改订单排产
250      */
251     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:edit')")
252     @Log(title = "订单排产", businessType = BusinessType.UPDATE)
253     @PutMapping
254     public AjaxResult edit(@RequestBody BsOrderScheduling bsOrderScheduling)
255     {
256         return toAjax(bsOrderSchedulingService.updateBsOrderScheduling(bsOrderScheduling));
257     }
258
259     /**
260      * 删除订单排产
261      */
262     @PreAuthorize("@ss.hasPermi('bs:orderScheduling:remove')")
263     @Log(title = "订单排产", businessType = BusinessType.DELETE)
2aea64 264     @DeleteMapping("/{ids}")
J 265     public AjaxResult remove(@PathVariable Long[] ids)
d9cf6b 266     {
2aea64 267         return toAjax(bsOrderSchedulingService.deleteBsOrderSchedulingByIds(ids));
d9cf6b 268     }
d4f437 269     @GetMapping("/getSumData")
Y 270     public R getSumData(BsOrderScheduling bsOrderScheduling){
271         List<BsOrderScheduling> list = new ArrayList<>();
272         int onlineNum = 0;
273         int finishNum = 0;
274         if (StringUtils.isNotEmpty(bsOrderScheduling.getOrderNo())){
275
276             list = bsOrderSchedulingService.selectBsOrderSchedulingPage(bsOrderScheduling);
277             List<BsOrderScheduling> onlineNumList = list.stream().filter(x -> Constants.ORDER_STATUS_ING.equals(x.getProductionStatus())).collect(Collectors.toList());
278             if (CollUtil.isNotEmpty(onlineNumList)){
279                 onlineNum = onlineNumList.size();
280             }
281             List<BsOrderScheduling> finishNumList = list.stream().filter(x -> Constants.FINISH_PRODUCTION.equals(x.getProductionStatus())).collect(Collectors.toList());
282             if (CollUtil.isNotEmpty(finishNumList)){
283                 finishNum = finishNumList.size();
284             }
285         }
286         List<BsOrderScheduling> collect = list.stream().filter(x -> Constants.UN_QUALIFIED.equals(x.getQualityStatus())).collect(Collectors.toList());
287         String unqualified = "0";
288         if (CollUtil.isNotEmpty(collect)){
289             unqualified = String.valueOf(collect.size());
290         }
291         SumDataVO vo = new SumDataVO();
292         vo.setFinishNum(finishNum);
293         vo.setOnlineNum(onlineNum);
294         vo.setUnqualified(unqualified);
295         return R.ok(vo);
296     }
297
298     /**
299      * 校验发动机号是否和机型匹配、是否重复扫描、是否超出计划数量
300      * @param engineNo 箱体码
301      * @param model 机型
302      * @return boolean
303      */
304     @Transactional(rollbackFor = Exception.class)
305     @GetMapping("/engineNoIsInModel")
306     public R engineNoIsInModel(String engineNo,String model,String orderNo) throws Exception {
307
308         if (StringUtils.isEmpty(engineNo)){
309             return R.ok(500,"箱体码为空或已存在,请重试");
310         }
311
312         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
313         bsOrderScheduling.setOrderNo(orderNo);
314         //bsOrderScheduling.setProductionStatus("1");
315         List<BsOrderScheduling> allList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling);
316         List<BsOrderScheduling> dlist = allList.stream().filter(x->x.getProductionStatus().equals(Constants.WAIT_PRODUCTION)).collect(Collectors.toList());
317         List<BsOrderScheduling> collect = allList.stream().filter(x -> x.getProductionStatus().equals(Constants.ORDER_STATUS_ING)
318                         ||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
319
320         BsOrderScheduling OrderScheduling=dlist.get(0);
321
322         DaParamCollection daParamCollection = new DaParamCollection();
323         daParamCollection.setParamValue(engineNo);
324         daParamCollection.setSfcCode("OP010");
325         List<DaParamCollection> list = daParamCollectionService.selectDaParamCollectionList(daParamCollection);
326         if (CollUtil.isNotEmpty(list)){
327             return R.ok(500,"已存在此箱体码,请勿重复扫描");
328         }
329
330         OmProductionOrdeInfo info = new OmProductionOrdeInfo();
331         info.setWorkOrderNo(orderNo);
332         List<OmProductionOrdeInfo> omProductionOrdeInfos = productionOrdeInfoService.selectOmProductionOrdeInfoList(info);
333         if (CollUtil.isNotEmpty(omProductionOrdeInfos)){
334             OmProductionOrdeInfo omProductionOrdeInfo = omProductionOrdeInfos.get(0);
335             Long planQty = omProductionOrdeInfo.getPlanQty();
336             if (planQty<collect.size()){
337                 return R.ok(500,"超出计划数量,请检查后重试");
338             }
339         }
340         //插入数据
341         DaParamCollection saveData = new DaParamCollection();
342         saveData.setSfcCode(OrderScheduling.getEngineNo());
343         saveData.setParamValue(engineNo);
344         saveData.setLocationCode("OP010");
345         saveData.setParamCode("XTM");
346         saveData.setParamName("箱体码");
347         daParamCollectionService.insertDaParamCollection(saveData);
348
349         //更新上线数量
350         int onlineNum = 0;
351         List<BsOrderScheduling> onlineNumList = bsOrderSchedulingService.selectBsOrderSchedulingList(bsOrderScheduling)
352                 .stream().filter(x -> Constants.ORDER_STATUS_ING.equals(x.getProductionStatus())||x.getProductionStatus().equals(Constants.FINISH_PRODUCTION)).collect(Collectors.toList());
353         if (CollUtil.isNotEmpty(onlineNumList)){
354             onlineNum = onlineNumList.size();
355         }
356         OmProductionOrdeInfo omProductionOrdeInfo = new OmProductionOrdeInfo();
357         omProductionOrdeInfo.setWorkOrderNo(orderNo);
358         List<OmProductionOrdeInfo> omList = productionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
359         if (CollUtil.isNotEmpty(omList)){
360             OmProductionOrdeInfo omInfo = omList.get(0);
361             String s = String.valueOf(onlineNum);
362             long l = Long.parseLong(s);
363             omInfo.setActualOnlineQty(l);
364             productionOrdeInfoService.updateOmProductionOrdeInfo(omInfo);
365         }
366
367         //OPC操作
368         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX.HOP010.Code", OrderScheduling.getEngineNo());
369         OPCUaSubscription.miloService.writeToOpcUa(entity);//写SN
370         ReadWriteEntity entity2 = new ReadWriteEntity("CFL4HX.HOP010.SNDoor", 1);
371         OPCUaSubscription.miloService.writeToOpcByte(entity2);//写完成
372
373         OrderScheduling.setProductionStatus("2");
374         bsOrderSchedulingService.updateBsOrderScheduling(OrderScheduling);
375         return R.ok();
376     }
377
378
d9cf6b 379 }