懒羊羊
2023-11-25 9bd5461a1387becd4da03158061a1ed17ddf6a6c
提交 | 用户 | 时间
71e81e 1 package cn.stylefeng.guns.plcserver.server.OP010.impl;
2
3
4 import cn.stylefeng.guns.GunsApplication;
5 import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
6 import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
7 import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
8 import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
9 import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
10 import cn.stylefeng.guns.modular.om.productionOrdeInfo.entity.ProductionOrdeInfo;
11 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam;
12 import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
13 import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService;
14 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
15 import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
16 import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
17 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam;
18 import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult;
19 import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService;
20 import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
21 import cn.stylefeng.guns.plcserver.opc.OPCComm;
22 import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
23 import cn.stylefeng.guns.plcserver.opc.unit.SFCCodeTool;
24 import cn.stylefeng.guns.plcserver.server.OP010.OP010ServerInterface;
25 import cn.stylefeng.guns.plcserver.tool.DateTool;
26 import cn.stylefeng.guns.plcserver.tool.LogUtil;
27 import cn.stylefeng.roses.core.util.ToolUtil;
28 import lombok.Synchronized;
29 import org.apache.commons.lang3.StringUtils;
30 import org.apache.log4j.Logger;
31 import org.springframework.boot.SpringApplication;
32
e37994 33 import java.util.Calendar;
71e81e 34 import java.util.Date;
35 import java.util.List;
36
37
38
39 public class OP010ServerInterfaceImpl implements OP010ServerInterface {
40
41     private static Logger logger;
42     LogUtil logUtil = new LogUtil();
43     static {
44         logger = Logger.getLogger(OP010ServerInterfaceImpl.class);
45     }
46
47     private OPCComm opc = OPCComm.getInstance();
48
49     private static String S_ORDER_CODE = "";//工单编号
50     private static String S_PRODUCT_CODE = "";//产品编号
51     private static String S_PRODUCT_TYPE= "";//产品类型
52     private static String S_SFC_CODE = "test222";//总成编码
53     private static String S_RIGHT_CODE  = "test333";//右壳体编码
54     private static String PRODUCTION_LINE  = "OP";//产线号
55     private static String LOCATION_CODE  = "OP010";//工位号
56     private static Date IN_TIME = null;//进站时间
57
58     private static Integer ACTUAL_ONLINE_QTY  = 0 ;//上线数量
59
60
61
62
63     @Override
64     public synchronized void monitor() {
65         String ecpStr = "";//异常记录标记
66         try{
67
68             if(GlobalVariable.OP010_F_HEART_BEAT) {
69
70                 //PC读工单
71                 String isPLCStart = OPCUnit.read(opc.getOP010_J_PLC_START());//PLC开始
72                 if(isPLCStart.equals("true")){
73                     String isFinish = OPCUnit.read(opc.getOP010_J_PC_WRITE_ORDER());//PC下发工单完成
74                     if(isFinish.equals("false")){
75
76                         String isRepair = OPCUnit.read(opc.getOP010_P_REPAIR());//是否返修
77                         if(isRepair.equals("true")){
78                             handleRepair();
79                         }else{
80                             handleOrder();
81                         }
82
83                     }
84                 }
85
86
87                 //PC完成
88                 String isPLCFinish = OPCUnit.read(opc.getOP010_J_PLC_FINISH());//PLC完成
89                 if(isPLCFinish.equals("true")){
90                     String isFinish = OPCUnit.read(opc.getOP010_J_PC_FINISH());//PC操作完成
91                     if(isFinish.equals("false")){
92                         handleFinsh();
93                     }
94                 }
95
96             }else{
97                 logger.info("OP010工位与PLC断开,请检查PLC或网络是否异常!");
98             }
99
100         }catch (Exception e) {
101             ecpStr ="出现异常:" + logUtil.getTrace(e);
102         }finally {
103             if(!"".equals(ecpStr)){
104                 logger.info(ecpStr+"\r\n");
105             }
106         }
107     }
108
109     public void handleRepair() {
110         RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
111         repairManageInfoParam.setLocationCode(LOCATION_CODE);
112         repairManageInfoParam.setManageType("2");
113         repairManageInfoParam.setUpPlc("0");
114         RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
115         List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
116         if(list.size()>0) {
117             RepairManageInfoResult result = list.get(0);
118
119             S_SFC_CODE = result.getSfc();
120             S_ORDER_CODE = result.getWorkOrderNo();
121             S_PRODUCT_CODE = result.getProductCode();
122             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
123             String  repairLocation = result.getPoorLocationCode();//
124
125             //根据工位编码查询工位表中配置的返修工位号
126             LocationInfoParam param = new LocationInfoParam();
127             param.setLocationCode(repairLocation);
128             LocationInfoService locationInfoService = opc.locationInfoService;
129             List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
130             if(results.size()>0) {
131                 LocationInfoResult r = results.get(0);
132                 String repairLocationNo = r.getSpareField2();
133                 if(null != repairLocationNo && "" != repairLocationNo){
134                     OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
135                     OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
136                     OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
137                     OPCUnit.write(opc.getOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
138                     OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
139
140                     //更新为已经返修上线
141                     Long id = result.getId();
142                     repairManageInfoParam.setId(id);
143                     repairManageInfoParam.setUpPlc("1");
144                     repairManageInfoService.update(repairManageInfoParam);
145
146                 }else{
147                     logger.info("OP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
148                 }
149             }else{
150                 logger.info("OP010工位,handleRepair 无法查询到"+repairLocation+"工位!");
151             }
152
153
154
155         }
156     }
157     //PC下发工单
158     public void handleOrder() {
159         logger.info("OP010工位,handleOrder PC处理开始!");
160         IN_TIME = DateTool.getLocalTimeForDate();
161         ProductionOrdeInfoParam param = new ProductionOrdeInfoParam();
162         param.setProductionLine("");//产线
163         param.setOrderStatus("3");//工单状态
164
165         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
166         List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param);
167
168         if(list.size()>0) {
169             ProductionOrdeInfoResult result = list.get(0);
170
171             String customerCode = result.getCustom();//客户编码
172             String productCode = result.getMaterialCode();//产品编码
173             String softwareVersionCode = result.getSoftwareVersionCode();//产品型号
174             String productCompanyCode = result.getProductCompanyCode();//班次
175
176             //序列号
177             String serialNumbers = "0000";
178             SerialNumbersConfParam serialNumbersConfParam = new SerialNumbersConfParam();
e37994 179             Calendar calendar = Calendar.getInstance();
L 180             String Years = String.valueOf(calendar.get(Calendar.YEAR)); //年份
181             String Months = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.MONTH) + 1),2, "0"); //月份
182             String Dates = StringUtils.leftPad(String.valueOf(calendar.get(Calendar.DATE)),2, "0"); //日期
183             serialNumbersConfParam.setYears(Years+Months+Dates);//获取当前是哪一天
71e81e 184             serialNumbersConfParam.setState("1");
185             SerialNumbersConfService serialNumbersConfService = opc.serialNumbersConfService;
186             List<SerialNumbersConfResult> serialNumberslist = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
187             if(serialNumberslist.size()>0){
188                 SerialNumbersConfResult serialNumbersConfResult = serialNumberslist.get(0);
189                 serialNumbers = serialNumbersConfResult.getSerialNumber();
190                 serialNumbersConfParam.setId(serialNumbersConfResult.getId());
191             }else{
192                 serialNumbersConfParam.setSerialNumber(serialNumbers);
193                 serialNumbersConfParam.setLengths("4");
194                 serialNumbersConfService.add(serialNumbersConfParam);
195                 List<SerialNumbersConfResult> serialNumberslist2 = serialNumbersConfService.findListBySpec(serialNumbersConfParam);
196                 if(serialNumberslist2.size()>0){
197                     SerialNumbersConfResult serialNumbersConfResult = serialNumberslist2.get(0);
198                     //serialNumbers = serialNumbersConfResult.getSerialNumber();
199                     serialNumbersConfParam.setId(serialNumbersConfResult.getId());
200                 }
201                 //logger.info("序列号没有配置,请找管理员进行配置!");
202             }
203
204             //更新序列号+1
205             int i = Integer.valueOf(serialNumbers)+1;
206             serialNumbers = StringUtils.leftPad(String.valueOf(i),4, "0");
207             serialNumbersConfParam.setSerialNumber(serialNumbers);
208             serialNumbersConfService.update(serialNumbersConfParam);
209
210             //生成总成编码
211             String sfcCode = SFCCodeTool.createCodingRulesSFC(softwareVersionCode,productCompanyCode,serialNumbers);//总成号
212             S_SFC_CODE = sfcCode;
213
214             S_ORDER_CODE = result.getWorkOrderNo();
215             S_PRODUCT_CODE = result.getMaterialCode();
216             S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
217             ACTUAL_ONLINE_QTY = result.getActualOnlineQty();
218
219             OPCUnit.write(opc.getOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
220             OPCUnit.write(opc.getOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
221             OPCUnit.write(opc.getOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码
222            //OPCUnit.write(opc.getOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码
223             OPCUnit.write(opc.getOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量
224             OPCUnit.write(opc.getOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
225             logger.info("OP010工位,handleOrder PC处理完成!^--------------------------------------------");
226         }else{
227             logger.info("OP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!");
228         }
229     }
230
231
232     //PC完成
233     public void handleFinsh() {
234         logger.info("OP010工位,handleFinsh PC处理开始!");
235         if("".equals(S_ORDER_CODE)){
236             IN_TIME = DateTool.getLocalTimeForDate();
237             S_ORDER_CODE = OPCUnit.read(opc.getOP010_S_ORDER_CODE());//工单编号
238             S_PRODUCT_TYPE = OPCUnit.read(opc.getOP010_S_PRODUCT_CODE());//产品编号
239             S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
240             S_SFC_CODE = OPCUnit.read(opc.getOP010_S_SFC_CODE());//总成编码
241         }
242         //处理过站信息
243         String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getOP010_S_PRODUCT_STATE_CODE());
244         PassingStationCollectionParam param = new PassingStationCollectionParam();
245         param.setWorkOrderNo(S_ORDER_CODE);
246         param.setProductCode(S_PRODUCT_CODE);
247         param.setSfcCode(S_SFC_CODE);
248         param.setProductionLine(PRODUCTION_LINE);
249         param.setLocationCode(LOCATION_CODE);
250         param.setInboundTime(IN_TIME);
251         param.setOutboundTime(DateTool.getLocalTimeForDate());
252         param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
253         PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
254         passingStationCollectionService.add(param);
255         //上线数量加1    根据工单号,更新 ACTUAL_ONLINE_QTY +1
256        /* ProductionOrdeInfoParam orderParam = new ProductionOrdeInfoParam();
257         orderParam.setWorkOrderNo(S_ORDER_CODE);
258         orderParam.setActualOnlineQty(ACTUAL_ONLINE_QTY+1);
259         ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService;
260         productionOrdeInfoService.updateOrderOnlineQry(orderParam);*/
261         //写完成
262         OPCUnit.write(opc.getOP010_J_PC_FINISH(), "true"); //PC完成
263         logger.info("OP010工位,handleFinsh PC处理完成!-------------------------------");
264     }
265
266
267 }