春风项目四线(合箱线、总装线)
wujian
2024-07-26 778d3d8b387ca0a8d1b51ef68f783fb0b407ef20
提交 | 用户 | 时间
5030f3 1 package com.jcdm.main.da.tileMatchMiddleware.controller;
Y 2
778d3d 3 import java.util.Comparator;
5030f3 4 import java.util.List;
778d3d 5 import java.util.stream.Collectors;
59e228 6 import javax.annotation.Resource;
5030f3 7 import javax.servlet.http.HttpServletResponse;
Y 8
59e228 9 import cn.hutool.core.collection.CollUtil;
a4c4c1 10 import cn.hutool.core.util.StrUtil;
W 11 import com.jcdm.common.core.domain.R;
5030f3 12 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
59e228 13 import com.jcdm.main.da.passingStationCollection.domain.ProductNewPassStation;
W 14 import com.jcdm.main.da.passingStationCollection.service.ProductNewPassStationService;
5030f3 15 import com.jcdm.main.da.tileMatchRules.domain.DaTileMatchRules;
Y 16 import org.springframework.security.access.prepost.PreAuthorize;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.web.bind.annotation.GetMapping;
19 import org.springframework.web.bind.annotation.PostMapping;
20 import org.springframework.web.bind.annotation.PutMapping;
21 import org.springframework.web.bind.annotation.DeleteMapping;
22 import org.springframework.web.bind.annotation.PathVariable;
23 import org.springframework.web.bind.annotation.RequestBody;
24 import org.springframework.web.bind.annotation.RequestMapping;
25 import org.springframework.web.bind.annotation.RestController;
26 import com.jcdm.common.annotation.Log;
27 import com.jcdm.common.core.controller.BaseController;
28 import com.jcdm.common.core.domain.AjaxResult;
29 import com.jcdm.common.enums.BusinessType;
30 import com.jcdm.main.da.tileMatchMiddleware.domain.DaTileMatchMiddleware;
31 import com.jcdm.main.da.tileMatchMiddleware.service.IDaTileMatchMiddlewareService;
32 import com.jcdm.common.utils.poi.ExcelUtil;
33 import com.jcdm.common.core.page.TableDataInfo;
34
35 import static com.jcdm.main.plcserver.sub.OPCUaSubscription.miloService;
36
37 /**
38  * 活塞连杆配瓦中间Controller
39  * 
40  * @author yyt
41  * @date 2024-05-28
42  */
43 @RestController
44 @RequestMapping("/da/tileMatchMiddleware")
45 public class DaTileMatchMiddlewareController extends BaseController
46 {
47     @Autowired
48     private IDaTileMatchMiddlewareService daTileMatchMiddlewareService;
59e228 49
W 50     @Resource
51     private ProductNewPassStationService productNewPassStationService;
5030f3 52
Y 53     /**
54      * 查询活塞连杆配瓦中间列表
55      */
56     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:list')")
57     @GetMapping("/list")
58     public TableDataInfo list(DaTileMatchMiddleware daTileMatchMiddleware)
59     {
60         startPage();
61         List<DaTileMatchMiddleware> list = daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(daTileMatchMiddleware);
62         return getDataTable(list);
63     }
64
65     /**
66      * 导出活塞连杆配瓦中间列表
67      */
68     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:export')")
69     @Log(title = "活塞连杆配瓦中间", businessType = BusinessType.EXPORT)
70     @PostMapping("/export")
71     public void export(HttpServletResponse response, DaTileMatchMiddleware daTileMatchMiddleware)
72     {
73         List<DaTileMatchMiddleware> list = daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(daTileMatchMiddleware);
74         ExcelUtil<DaTileMatchMiddleware> util = new ExcelUtil<DaTileMatchMiddleware>(DaTileMatchMiddleware.class);
75         util.exportExcel(response, list, "活塞连杆配瓦中间数据");
76     }
77
78     /**
79      * 获取活塞连杆配瓦中间详细信息
80      */
81     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:query')")
82     @GetMapping(value = "/{id}")
83     public AjaxResult getInfo(@PathVariable("id") Long id)
84     {
85         return success(daTileMatchMiddlewareService.selectDaTileMatchMiddlewareById(id));
86     }
87
88     /**
89      * 新增活塞连杆配瓦中间
90      */
91     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:add')")
92     @Log(title = "活塞连杆配瓦中间", businessType = BusinessType.INSERT)
93     @PostMapping
94     public AjaxResult add(@RequestBody DaTileMatchMiddleware daTileMatchMiddleware)
95     {
96         return toAjax(daTileMatchMiddlewareService.insertDaTileMatchMiddleware(daTileMatchMiddleware));
97     }
98
99     /**
100      * 修改活塞连杆配瓦中间
101      */
102     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:edit')")
103     @Log(title = "活塞连杆配瓦中间", businessType = BusinessType.UPDATE)
104     @PutMapping
105     public AjaxResult edit(@RequestBody DaTileMatchMiddleware daTileMatchMiddleware)
106     {
107         return toAjax(daTileMatchMiddlewareService.updateDaTileMatchMiddleware(daTileMatchMiddleware));
108     }
109
110     /**
111      * 删除活塞连杆配瓦中间
112      */
113     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:remove')")
114     @Log(title = "活塞连杆配瓦中间", businessType = BusinessType.DELETE)
115     @DeleteMapping("/{ids}")
116     public AjaxResult remove(@PathVariable Long[] ids)
117     {
118         return toAjax(daTileMatchMiddlewareService.deleteDaTileMatchMiddlewareByIds(ids));
119     }
120
121     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:query')")
122     @GetMapping(value = "/barcodeup")
123     public DaTileMatchMiddleware setBarcodeup(String barcode,String locationCode) {
124         DaTileMatchMiddleware rMiddleware=null;
125         try {
126             //Object SNCodeObject = miloService.readFromOpcUa("CFL4HX."+locationCode+".Code1").getValue();
127             Object SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP050.Code1").getValue();
128             if (null == SNCodeObject){
129                 //SNCodeObject = miloService.readFromOpcUa("CFL4HX."+locationCode+ ".Code").getValue();
130                 SNCodeObject = miloService.readFromOpcUa("CFL4HX.OP050.Code").getValue();
131             }
132             if (null != SNCodeObject){
133                 String SNCode = SNCodeObject.toString();
134
135                 DaTileMatchMiddleware TileMatchMiddleware=new DaTileMatchMiddleware();
136                 TileMatchMiddleware.setSfcCode(SNCode);
137                 TileMatchMiddleware.setPalletNo(barcode);
59e228 138                 TileMatchMiddleware.setState(2);
5030f3 139                 List<DaTileMatchMiddleware> TileMatchMiddlewareList=daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(TileMatchMiddleware);
Y 140                 if(TileMatchMiddlewareList.size()>0){
141                     for(int i=0;i<TileMatchMiddlewareList.size();i++){
142                         DaTileMatchMiddleware Middleware=TileMatchMiddlewareList.get(i);
59e228 143                         Middleware.setState(3);
5030f3 144                         daTileMatchMiddlewareService.updateDaTileMatchMiddleware(Middleware);
Y 145                     }
146                     rMiddleware=TileMatchMiddlewareList.get(0);
147                 }
148             }
149
150         } catch (Exception e) {
151             throw new RuntimeException(e);
152         }
153         return rMiddleware;
154     }
155
156     @PreAuthorize("@ss.hasPermi('da:tileMatchMiddleware:query')")
157     @GetMapping(value = "/barcode")
59e228 158     public DaTileMatchMiddleware setBarcode(String barcode,String locationCode) throws Exception {
5030f3 159         DaTileMatchMiddleware rMiddleware=new DaTileMatchMiddleware();;
59e228 160         rMiddleware.setState(1);
5030f3 161         List<DaTileMatchMiddleware> TileMatchMiddlewareList=daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(rMiddleware);
59e228 162         String SNCode="";
778d3d 163         if(CollUtil.isNotEmpty(TileMatchMiddlewareList)){
W 164             TileMatchMiddlewareList = TileMatchMiddlewareList.stream().sorted(Comparator.comparing(DaTileMatchMiddleware::getCreateTime)).collect(Collectors.toList());
5030f3 165             rMiddleware=TileMatchMiddlewareList.get(0);
Y 166             rMiddleware.setPalletNo(locationCode);
167             rMiddleware.setConnectingrodNo(barcode);
59e228 168             rMiddleware.setState(2);
W 169             SNCode=rMiddleware.getSfcCode();
5030f3 170             daTileMatchMiddlewareService.updateDaTileMatchMiddleware(rMiddleware);
d2daac 171             DaTileMatchMiddleware patch = new DaTileMatchMiddleware();
W 172             patch.setSfcCode(SNCode);
173             patch.setState(1);
174             List<DaTileMatchMiddleware> checkList = daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(patch);
175             if (CollUtil.isNotEmpty(checkList)){
176                 if (checkList.size() == 2){
177                     rMiddleware.setCheckFlag("1");
178                 }
179             }
59e228 180             //获取产品型号
W 181             ProductNewPassStation productNewPassStation = new ProductNewPassStation();
182             productNewPassStation.setSfcCode(SNCode);
183             List<ProductNewPassStation> productPassStationList = productNewPassStationService.getProductPassStationList(productNewPassStation);
184             if (CollUtil.isNotEmpty(productPassStationList)){
185                 ProductNewPassStation station = productPassStationList.get(0);
186                 String productType = station.getProductType();
187                 rMiddleware.setProductType(productType);
188             }
5030f3 189         }
59e228 190 //        ReadWriteEntity entity = new ReadWriteEntity("CFL3ZZ.CR010.Code", SNCode);
W 191 //        InitCallback.miloService.writeToOpcUa(entity);//写SN
192 //        ReadWriteEntity entity2 = new ReadWriteEntity("CFL3ZZ.CR010.CodeRequestFeed", 1);
193 //        InitCallback.miloService.writeToOpcByte(entity2);//写完成
5030f3 194         return rMiddleware;
Y 195     }
a4c4c1 196
W 197
198     @GetMapping("/getSfcCodeByConnectCode")
199     public R getSfcCodeByConnectCode(String connectCode){
200         DaTileMatchMiddleware tileMatchMiddleware = new DaTileMatchMiddleware();
201         if (StrUtil.isBlank(connectCode)){
202             return R.fail("连杆码不能为空");
203         }
204         DaTileMatchMiddleware daTileMatchMiddleware = new DaTileMatchMiddleware();
205         daTileMatchMiddleware.setConnectingrodNo(connectCode);
206         List<DaTileMatchMiddleware> daTileMatchMiddlewares = daTileMatchMiddlewareService.selectDaTileMatchMiddlewareList(daTileMatchMiddleware);
207         if (CollUtil.isNotEmpty(daTileMatchMiddlewares)){
208             tileMatchMiddleware = daTileMatchMiddlewares.get(0);
209         }
210         return R.ok(tileMatchMiddleware);
211     }
5030f3 212 }