春风项目四线(合箱线、总装线)
yyt
2024-06-03 5030f3d30ccc1bd16db371c6970a48103aff9191
提交 | 用户 | 时间
e4c3b0 1 package com.jcdm.main.da.opcuaconfig.controller;
Y 2
054abe 3 import java.util.List;
5030f3 4 import java.util.stream.Collectors;
054abe 5 import javax.servlet.http.HttpServletResponse;
Y 6
5030f3 7 import cn.hutool.core.collection.CollUtil;
054abe 8 import com.jcdm.main.da.opcuaconfig.domain.DaOpcuaConfig;
0b1422 9 import com.jcdm.main.da.opcuaconfig.domain.NodeEntity;
054abe 10 import com.jcdm.main.da.opcuaconfig.service.IDaOpcuaConfigService;
04b8ef 11 import com.jcdm.main.da.paramCollection.domain.DaParamCollection;
Y 12 import com.jcdm.main.da.paramCollection.mapper.DaParamCollectionMapper;
13 import com.jcdm.main.da.paramCollection.service.IDaParamCollectionService;
5030f3 14 import com.jcdm.main.da.tileMatchMiddleware.domain.DaTileMatchMiddleware;
Y 15 import com.jcdm.main.da.tileMatchMiddleware.service.IDaTileMatchMiddlewareService;
16 import com.jcdm.main.da.tileMatchRules.domain.DaTileMatchRules;
17 import com.jcdm.main.da.tileMatchRules.service.IDaTileMatchRulesService;
d4f437 18 import com.jcdm.main.plcserver.sub.OPCUaSubscription;
Y 19 import com.kangaroohy.milo.model.ReadWriteEntity;
054abe 20 import org.springframework.security.access.prepost.PreAuthorize;
Y 21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.web.bind.annotation.GetMapping;
23 import org.springframework.web.bind.annotation.PostMapping;
24 import org.springframework.web.bind.annotation.PutMapping;
25 import org.springframework.web.bind.annotation.DeleteMapping;
26 import org.springframework.web.bind.annotation.PathVariable;
27 import org.springframework.web.bind.annotation.RequestBody;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RestController;
e4c3b0 30 import com.jcdm.common.annotation.Log;
Y 31 import com.jcdm.common.core.controller.BaseController;
32 import com.jcdm.common.core.domain.AjaxResult;
33 import com.jcdm.common.enums.BusinessType;
34 import com.jcdm.common.utils.poi.ExcelUtil;
054abe 35 import com.jcdm.common.core.page.TableDataInfo;
e4c3b0 36
04b8ef 37 import static com.jcdm.main.plcserver.sub.OPCUaSubscription.miloService;
Y 38
e4c3b0 39 /**
054abe 40  * 交互信号配置Controller
e4c3b0 41  * 
Y 42  * @author yyt
28cd73 43  * @date 2024-01-23
e4c3b0 44  */
Y 45 @RestController
46 @RequestMapping("/da/opcuaconfig")
47 public class DaOpcuaConfigController extends BaseController
48 {
49     @Autowired
50     private IDaOpcuaConfigService daOpcuaConfigService;
5030f3 51     @Autowired
04b8ef 52     private IDaParamCollectionService daParamCollectionService;
5030f3 53     @Autowired
Y 54     private IDaTileMatchRulesService daTileMatchRulesService;
55     @Autowired
56     private IDaTileMatchMiddlewareService daTileMatchMiddlewareService;
e4c3b0 57
Y 58     /**
054abe 59      * 查询交互信号配置列表
e4c3b0 60      */
Y 61     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:list')")
62     @GetMapping("/list")
63     public TableDataInfo list(DaOpcuaConfig daOpcuaConfig)
64     {
65         startPage();
66         List<DaOpcuaConfig> list = daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig);
67         return getDataTable(list);
68     }
69
70     /**
054abe 71      * 导出交互信号配置列表
e4c3b0 72      */
Y 73     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:export')")
054abe 74     @Log(title = "交互信号配置", businessType = BusinessType.EXPORT)
e4c3b0 75     @PostMapping("/export")
Y 76     public void export(HttpServletResponse response, DaOpcuaConfig daOpcuaConfig)
77     {
78         List<DaOpcuaConfig> list = daOpcuaConfigService.selectDaOpcuaConfigList(daOpcuaConfig);
79         ExcelUtil<DaOpcuaConfig> util = new ExcelUtil<DaOpcuaConfig>(DaOpcuaConfig.class);
054abe 80         util.exportExcel(response, list, "交互信号配置数据");
e4c3b0 81     }
Y 82
83     /**
054abe 84      * 获取交互信号配置详细信息
e4c3b0 85      */
Y 86     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:query')")
87     @GetMapping(value = "/{id}")
88     public AjaxResult getInfo(@PathVariable("id") Long id)
89     {
90         return success(daOpcuaConfigService.selectDaOpcuaConfigById(id));
91     }
92
93     /**
054abe 94      * 新增交互信号配置
e4c3b0 95      */
Y 96     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:add')")
054abe 97     @Log(title = "交互信号配置", businessType = BusinessType.INSERT)
e4c3b0 98     @PostMapping
Y 99     public AjaxResult add(@RequestBody DaOpcuaConfig daOpcuaConfig)
100     {
101         return toAjax(daOpcuaConfigService.insertDaOpcuaConfig(daOpcuaConfig));
102     }
103
104     /**
054abe 105      * 修改交互信号配置
e4c3b0 106      */
Y 107     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:edit')")
054abe 108     @Log(title = "交互信号配置", businessType = BusinessType.UPDATE)
e4c3b0 109     @PutMapping
Y 110     public AjaxResult edit(@RequestBody DaOpcuaConfig daOpcuaConfig)
111     {
112         return toAjax(daOpcuaConfigService.updateDaOpcuaConfig(daOpcuaConfig));
113     }
114
115     /**
054abe 116      * 删除交互信号配置
e4c3b0 117      */
Y 118     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:remove')")
054abe 119     @Log(title = "交互信号配置", businessType = BusinessType.DELETE)
e4c3b0 120     @DeleteMapping("/{ids}")
Y 121     public AjaxResult remove(@PathVariable Long[] ids)
122     {
123         return toAjax(daOpcuaConfigService.deleteDaOpcuaConfigByIds(ids));
124     }
0b1422 125
Y 126     /**
127      * 获取交互信号配置详细信息
128      */
129     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:query')")
130     @GetMapping(value = "/SNCode/{SNCode}/{locationCode}")
131     public AjaxResult setSNCode(@PathVariable("SNCode") String SNCode,@PathVariable("locationCode") String locationCode) {
d4f437 132         ReadWriteEntity entity = new ReadWriteEntity("CFL4HX."+locationCode+".SNCode", SNCode);
Y 133         Boolean out= true;
0b1422 134         try {
04b8ef 135             miloService.writeToOpcUa(entity);//写SN
Y 136         } catch (Exception e) {
137             throw new RuntimeException(e);
138         }
139         return toAjax(out);
140     }
141
142     /**
143      * 配瓦扫码
144      */
145     @PreAuthorize("@ss.hasPermi('da:opcuaconfig:query')")
5030f3 146     @GetMapping(value = "/barcode1")
Y 147     public DaParamCollection setBarcode1(String barcode,String locationCode) {
148         Boolean out = true;
149         DaParamCollection xParamCollection = null;
04b8ef 150         try {
5030f3 151             Object SNCodeObject = miloService.readFromOpcUa("CFL4HX." + locationCode + ".Code1").getValue();
Y 152             if (null == SNCodeObject) {
153                 SNCodeObject = miloService.readFromOpcUa("CFL4HX." + locationCode + ".Code").getValue();
04b8ef 154             }
5030f3 155             if (null != SNCodeObject) {
04b8ef 156                 String SNCode = SNCodeObject.toString();
Y 157                 //插入数据
158                 DaParamCollection saveData = new DaParamCollection();
159                 saveData.setSfcCode(SNCode);
160                 saveData.setParamValue(barcode);
161                 saveData.setLocationCode(locationCode);
1c7036 162                 saveData.setParamCode("CZM");
5030f3 163                 saveData.setParamName("曲轴");
04b8ef 164                 daParamCollectionService.insertDaParamCollection(saveData);
5030f3 165
Y 166                 DaTileMatchRules TileMatchRules = new DaTileMatchRules();
167                 TileMatchRules.setProductSeries("380Y");
168                 TileMatchRules.setScanObject1("连杆");
169                 TileMatchRules.setScanObject2("曲轴");
170                 daTileMatchRulesService.selectDaTileMatchRulesList(TileMatchRules);
171
172                 for (int i = 1; i <= 3; i++) {
173                     DaTileMatchMiddleware TileMatchMiddleware = new DaTileMatchMiddleware();
174                     TileMatchMiddleware.setSfcCode(SNCode);
175                     TileMatchMiddleware.setCrankshaftNo(barcode);
176                     TileMatchMiddleware.setCylinder((long) i);
177                     TileMatchMiddleware.setState(1L);
178                     daTileMatchMiddlewareService.insertDaTileMatchMiddleware(TileMatchMiddleware);
179                 }
180
181                 DaParamCollection ParamCollection = new DaParamCollection();
182                 ParamCollection.setSfcCode(SNCode);
183                 ParamCollection.setParamName("箱体");
184                 List<DaParamCollection> DaParamCollectionlist = daParamCollectionService.selectDaParamCollectionList(ParamCollection);
185                 List<DaParamCollection> XTParamCollection = DaParamCollectionlist.stream().filter(x -> "箱体".equals(x.getParamName())).collect(Collectors.toList());
186                 if (CollUtil.isNotEmpty(XTParamCollection)) {
187                     xParamCollection = XTParamCollection.get(0);
188                 }
04b8ef 189             }
0b1422 190         } catch (Exception e) {
Y 191             throw new RuntimeException(e);
192         }
5030f3 193         return xParamCollection;
0b1422 194     }
e4c3b0 195 }