提交 | 用户 | 时间
|
71e81e
|
1 |
package cn.stylefeng.guns.plcserver.server.COP010.impl; |
懒 |
2 |
|
|
3 |
|
|
4 |
import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam; |
|
5 |
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult; |
|
6 |
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService; |
|
7 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam; |
|
8 |
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService; |
|
9 |
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.params.ProductionOrdeInfoParam; |
|
10 |
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult; |
|
11 |
import cn.stylefeng.guns.modular.om.productionOrdeInfo.service.ProductionOrdeInfoService; |
|
12 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam; |
|
13 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult; |
|
14 |
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService; |
|
15 |
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.params.SerialNumbersConfParam; |
|
16 |
import cn.stylefeng.guns.modular.sc.serialNumbersConf.model.result.SerialNumbersConfResult; |
|
17 |
import cn.stylefeng.guns.modular.sc.serialNumbersConf.service.SerialNumbersConfService; |
|
18 |
import cn.stylefeng.guns.plcserver.opc.GlobalVariable; |
|
19 |
import cn.stylefeng.guns.plcserver.opc.OPCComm; |
|
20 |
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit; |
|
21 |
import cn.stylefeng.guns.plcserver.opc.unit.qrCode; |
|
22 |
import cn.stylefeng.guns.plcserver.server.COP010.COP010ServerInterface; |
|
23 |
import cn.stylefeng.guns.plcserver.tool.DateTool; |
|
24 |
import cn.stylefeng.guns.plcserver.tool.LogUtil; |
|
25 |
import org.apache.commons.lang3.StringUtils; |
|
26 |
import org.apache.log4j.Logger; |
|
27 |
import org.openscada.opc.lib.da.Group; |
|
28 |
|
|
29 |
import java.util.Date; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Random; |
|
32 |
|
|
33 |
|
|
34 |
public class COP010ServerInterfaceImpl implements COP010ServerInterface { |
|
35 |
|
|
36 |
private static Logger logger; |
|
37 |
LogUtil logUtil = new LogUtil(); |
|
38 |
static { |
|
39 |
logger = Logger.getLogger(COP010ServerInterfaceImpl.class); |
|
40 |
} |
|
41 |
|
|
42 |
private OPCComm opc = OPCComm.getInstance(); |
|
43 |
private static Date IN_TIME = null; |
|
44 |
private static String S_ORDER_CODE = "";//工单编号 |
|
45 |
private static String S_PRODUCT_CODE = "";//产品编号 |
|
46 |
private static String S_PRODUCT_TYPE= "";//产品类型 |
|
47 |
private static String S_PRODUCT_CODE_OLD = "";//产品编号 |
|
48 |
private static String S_SFC_CODE = "";//总成编码 |
|
49 |
private static String S_RIGHT_CODE = "";//右壳体编码 |
|
50 |
private static String PRODUCTION_LINE = "COP";//产线号 |
|
51 |
private static String LOCATION_CODE = "COP010";//工位号 |
|
52 |
private static String GROUP_NAME = "COP010_P";//工位号 |
|
53 |
private static List list = null; |
|
54 |
private static Group group = null; |
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
@Override |
|
60 |
public void monitor() { |
|
61 |
String ecpStr = "";//异常记录标记 |
|
62 |
try{ |
|
63 |
|
|
64 |
if(GlobalVariable.COP010_F_HEART_BEAT) { |
|
65 |
|
|
66 |
//PC读工单 |
|
67 |
String isPLCStart = OPCUnit.read(opc.getCOP010_J_PLC_START());//PLC开始 |
|
68 |
if(isPLCStart.equals("true")){ |
|
69 |
String isFinish = OPCUnit.read(opc.getCOP010_J_PC_WRITE_ORDER());//PC下发工单完成 |
|
70 |
if(isFinish.equals("false")){ |
|
71 |
String isRepair = OPCUnit.read(opc.getCOP010_P_REPAIR());//是否返修 |
|
72 |
if(isRepair.equals("true")){ |
|
73 |
handleRepair(); |
|
74 |
}else{ |
|
75 |
handleOrder(); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
//PC完成 |
|
82 |
String isPLCFinish = OPCUnit.read(opc.getCOP010_J_PLC_FINISH());//PLC完成 |
|
83 |
if(isPLCFinish.equals("true")){ |
|
84 |
String isFinish = OPCUnit.read(opc.getCOP010_J_PC_FINISH());//PC操作完成 |
|
85 |
if(isFinish.equals("false")){ |
|
86 |
handleFinsh(); |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
}else{ |
|
92 |
logger.info("COP010工位与PLC断开,请检查PLC或网络是否异常!"); |
|
93 |
} |
|
94 |
|
|
95 |
}catch (Exception e) { |
|
96 |
ecpStr ="出现异常:" + logUtil.getTrace(e); |
|
97 |
}finally { |
|
98 |
if(!"".equals(ecpStr)){ |
|
99 |
logger.info(ecpStr+"\r\n"); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
public void handleRepair() { |
|
105 |
RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam(); |
|
106 |
repairManageInfoParam.setLocationCode(LOCATION_CODE); |
|
107 |
repairManageInfoParam.setManageType("2"); |
|
108 |
repairManageInfoParam.setUpPlc("0"); |
|
109 |
RepairManageInfoService repairManageInfoService = opc.repairManageInfoService; |
|
110 |
List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam); |
|
111 |
if(list.size()>0) { |
|
112 |
RepairManageInfoResult result = list.get(0); |
|
113 |
|
|
114 |
//自动生成唯一码 |
|
115 |
Random random = new Random(System.currentTimeMillis()); |
|
116 |
S_SFC_CODE = "COP" + random.nextLong(); |
|
117 |
|
|
118 |
|
|
119 |
S_ORDER_CODE = result.getWorkOrderNo(); |
|
120 |
S_PRODUCT_CODE = result.getProductCode(); |
|
121 |
S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); |
|
122 |
String repairLocation = result.getPoorLocationCode();// |
|
123 |
|
|
124 |
//根据工位编码查询工位表中配置的返修工位号 |
|
125 |
LocationInfoParam param = new LocationInfoParam(); |
|
126 |
param.setLocationCode(repairLocation); |
|
127 |
LocationInfoService locationInfoService = opc.locationInfoService; |
|
128 |
List<LocationInfoResult> results = locationInfoService.findListBySpec(param); |
|
129 |
if(results.size()>0) { |
|
130 |
LocationInfoResult r = results.get(0); |
|
131 |
String repairLocationNo = r.getSpareField2(); |
|
132 |
if(null != repairLocationNo && "" != repairLocationNo){ |
|
133 |
OPCUnit.write(opc.getCOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号 |
|
134 |
OPCUnit.write(opc.getCOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号 |
|
135 |
OPCUnit.write(opc.getCOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码 |
|
136 |
OPCUnit.write(opc.getCOP010_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号 |
|
137 |
OPCUnit.write(opc.getCOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成 |
|
138 |
|
|
139 |
//更新为已经返修上线 |
|
140 |
Long id = result.getId(); |
|
141 |
repairManageInfoParam.setId(id); |
|
142 |
repairManageInfoParam.setUpPlc("1"); |
|
143 |
repairManageInfoService.update(repairManageInfoParam); |
|
144 |
|
|
145 |
}else{ |
|
146 |
logger.info("COP010工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!"); |
|
147 |
} |
|
148 |
}else{ |
|
149 |
logger.info("COP010工位,handleRepair 无法查询到"+repairLocation+"工位!"); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
//PC下发工单 |
|
155 |
public void handleOrder() { |
|
156 |
|
|
157 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
158 |
ProductionOrdeInfoParam param = new ProductionOrdeInfoParam(); |
|
159 |
param.setProductionLine("");//产线 |
|
160 |
param.setOrderStatus("3");//工单状态 |
|
161 |
|
|
162 |
ProductionOrdeInfoService productionOrdeInfoService = opc.productionOrdeInfoService; |
|
163 |
List<ProductionOrdeInfoResult> list = productionOrdeInfoService.findListBySpec(param); |
|
164 |
|
|
165 |
if(list.size()>0) { |
|
166 |
ProductionOrdeInfoResult result = list.get(0); |
|
167 |
|
|
168 |
S_ORDER_CODE = result.getWorkOrderNo(); |
|
169 |
S_PRODUCT_CODE = result.getMaterialCode(); |
|
170 |
S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE); |
|
171 |
|
|
172 |
//自动生成唯一码 |
|
173 |
Random random = new Random(System.currentTimeMillis()); |
|
174 |
S_SFC_CODE = "COP"+ random.nextLong(); |
|
175 |
|
|
176 |
|
|
177 |
OPCUnit.write(opc.getCOP010_S_ORDER_CODE(),S_ORDER_CODE); //工单编号 |
|
178 |
OPCUnit.write(opc.getCOP010_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品类型 |
|
179 |
OPCUnit.write(opc.getCOP010_S_SFC_CODE(), S_SFC_CODE); //总成编码 |
|
180 |
// OPCUnit.write(opc.getCOP010_S_RIGHT_CODE(), S_RIGHT_CODE); //右壳体编码 |
|
181 |
OPCUnit.write(opc.getCOP010_S_NUMBER(), result.getPlanQty().toString()); //计划数量 |
|
182 |
|
|
183 |
OPCUnit.write(opc.getCOP010_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成 |
|
184 |
logger.info("COP010工位,handleOrder PC处理完成!2"); |
|
185 |
}else{ |
|
186 |
logger.info("COP010工位没有可执行的工单,请联系工单管理员下发该产线的工单!"); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
//PC完成 |
|
192 |
public void handleFinsh() { |
|
193 |
if("".equals(S_ORDER_CODE)){ |
|
194 |
IN_TIME = DateTool.getLocalTimeForDate(); |
|
195 |
S_ORDER_CODE = OPCUnit.read(opc.getCOP010_S_ORDER_CODE());//工单编号 |
|
196 |
S_PRODUCT_TYPE = OPCUnit.read(opc.getCOP010_S_PRODUCT_CODE());//产品编号 |
|
197 |
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE); |
|
198 |
S_SFC_CODE = OPCUnit.read(opc.getCOP010_S_SFC_CODE());//总成编码 |
|
199 |
} |
|
200 |
//处理过站信息 |
|
201 |
String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getCOP010_S_PRODUCT_STATE_CODE()); |
|
202 |
PassingStationCollectionParam param = new PassingStationCollectionParam(); |
|
203 |
param.setWorkOrderNo(S_ORDER_CODE); |
|
204 |
param.setProductCode(S_PRODUCT_CODE); |
|
205 |
param.setSfcCode(S_SFC_CODE); |
|
206 |
param.setProductionLine(PRODUCTION_LINE); |
|
207 |
param.setLocationCode(LOCATION_CODE); |
|
208 |
param.setInboundTime(IN_TIME); |
|
209 |
param.setOutboundTime(DateTool.getLocalTimeForDate()); |
|
210 |
param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格 |
|
211 |
PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService; |
|
212 |
passingStationCollectionService.add(param); |
|
213 |
|
|
214 |
//写完成 |
|
215 |
OPCUnit.write(opc.getCOP010_J_PC_FINISH(), "true"); //PC完成 |
|
216 |
|
|
217 |
logger.info("COP010工位,handleFinsh PC处理完成!"); |
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 |
} |