package cn.stylefeng.guns.plcserver.server.EOP060.impl;
|
|
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.params.CollectionParamConfParam;
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.model.result.CollectionParamConfResult;
|
import cn.stylefeng.guns.modular.bs.collectionParamConf.service.CollectionParamConfService;
|
import cn.stylefeng.guns.modular.bs.locationInfo.model.params.LocationInfoParam;
|
import cn.stylefeng.guns.modular.bs.locationInfo.model.result.LocationInfoResult;
|
import cn.stylefeng.guns.modular.bs.locationInfo.service.LocationInfoService;
|
import cn.stylefeng.guns.modular.cm.paramCollection.model.params.ParamCollectionParam;
|
import cn.stylefeng.guns.modular.cm.paramCollection.service.ParamCollectionService;
|
import cn.stylefeng.guns.modular.cm.passingStationCollection.model.params.PassingStationCollectionParam;
|
import cn.stylefeng.guns.modular.cm.passingStationCollection.service.PassingStationCollectionService;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.model.params.MaterialTraceabilityParam;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.model.result.MaterialTraceabilityResult;
|
import cn.stylefeng.guns.modular.dq.materialTraceability.service.MaterialTraceabilityService;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.params.RepairManageInfoParam;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.model.result.RepairManageInfoResult;
|
import cn.stylefeng.guns.modular.sc.repairManageInfo.service.RepairManageInfoService;
|
import cn.stylefeng.guns.plcserver.opc.GlobalVariable;
|
import cn.stylefeng.guns.plcserver.opc.OPCComm;
|
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
|
|
import cn.stylefeng.guns.plcserver.server.EOP060.EOP060ServerInterface;
|
import cn.stylefeng.guns.plcserver.tool.DateTool;
|
import cn.stylefeng.guns.plcserver.tool.LogUtil;
|
import org.apache.log4j.Logger;
|
import org.openscada.opc.lib.da.Group;
|
import org.openscada.opc.lib.da.Item;
|
|
import java.util.Date;
|
import java.util.List;
|
|
|
public class EOP060ServerInterfaceImpl implements EOP060ServerInterface {
|
|
private static Logger logger;
|
LogUtil logUtil = new LogUtil();
|
static {
|
logger = Logger.getLogger(EOP060ServerInterfaceImpl.class);
|
}
|
|
private OPCComm opc = OPCComm.getInstance();
|
private static Date IN_TIME = null;
|
private static String S_ORDER_CODE = "";//工单编号
|
private static String S_PRODUCT_CODE = "";//产品编号
|
private static String S_PRODUCT_TYPE= "";//产品类型
|
private static String S_PRODUCT_CODE_OLD = "";//产品编号
|
private static String S_SFC_CODE = "";//总成编码
|
private static String S_RIGHT_CODE = "";//右壳体编码
|
private static String PRODUCTION_LINE = "EOP";//产线号
|
private static String LOCATION_CODE = "EOP060";//工位号
|
private static String GROUP_NAME = "EOP060_P";//组名
|
private static List list = null;
|
private static Group group = null;
|
@Override
|
public synchronized void monitor() {
|
String ecpStr = "";//异常记录标记
|
try{
|
if(GlobalVariable.EOP060_F_HEART_BEAT) {
|
//PC读工单
|
String isPLCStart = OPCUnit.read(opc.getEOP060_J_PLC_START());//PLC开始
|
if(isPLCStart.equals("true")){
|
String isFinish = OPCUnit.read(opc.getEOP060_J_PC_WRITE_ORDER());//PC下发工单完成
|
|
if(isFinish.equals("false")){
|
String isRepair = OPCUnit.read(opc.getEOP060_P_REPAIR());//是否返修
|
if(isRepair.equals("true")){
|
handleRepair();
|
}else{
|
handleOrder();
|
}
|
}
|
}
|
|
|
//PC完成
|
String isPLCFinish = OPCUnit.read(opc.getEOP060_J_PLC_FINISH());//PLC完成
|
if(isPLCFinish.equals("true")){
|
String isFinish = OPCUnit.read(opc.getEOP060_J_PC_FINISH());//PC操作完成
|
if(isFinish.equals("false")){
|
handleInfo();
|
handleFinsh();
|
}
|
}
|
|
}else{
|
logger.info("EOP060工位与PLC断开,请检查PLC或网络是否异常!");
|
}
|
|
}catch (Exception e) {
|
ecpStr ="出现异常:" + logUtil.getTrace(e);
|
}finally {
|
if(!"".equals(ecpStr)){
|
logger.info(ecpStr+"\r\n");
|
}
|
}
|
}
|
|
public void handleRepair() {
|
RepairManageInfoParam repairManageInfoParam = new RepairManageInfoParam();
|
repairManageInfoParam.setLocationCode(LOCATION_CODE);
|
repairManageInfoParam.setManageType("2");
|
repairManageInfoParam.setUpPlc("0");
|
RepairManageInfoService repairManageInfoService = opc.repairManageInfoService;
|
List<RepairManageInfoResult> list = repairManageInfoService.findListBySpec(repairManageInfoParam);
|
if(list.size()>0) {
|
RepairManageInfoResult result = list.get(0);
|
|
S_SFC_CODE = result.getSfc();
|
|
//查询sfc编码
|
MaterialTraceabilityParam materialTraceabilityParam = new MaterialTraceabilityParam();
|
materialTraceabilityParam.setMaterialCode(result.getSfc());
|
MaterialTraceabilityService materialTraceabilityService = opc.materialTraceabilityService;
|
List<MaterialTraceabilityResult> materialTraceabilityResults = materialTraceabilityService.findListBySpec(materialTraceabilityParam);
|
if(materialTraceabilityResults.size()>0){
|
MaterialTraceabilityResult materialTraceabilityResult = materialTraceabilityResults.get(0);
|
S_SFC_CODE = materialTraceabilityResult.getProductNo();
|
}
|
|
S_ORDER_CODE = result.getWorkOrderNo();
|
S_PRODUCT_CODE = result.getProductCode();
|
S_PRODUCT_TYPE = GlobalVariable.PRODUCT_TYPE_MAP.get(S_PRODUCT_CODE);
|
String repairLocation = result.getPoorLocationCode();//
|
|
//根据工位编码查询工位表中配置的返修工位号
|
LocationInfoParam param = new LocationInfoParam();
|
param.setLocationCode(repairLocation);
|
LocationInfoService locationInfoService = opc.locationInfoService;
|
List<LocationInfoResult> results = locationInfoService.findListBySpec(param);
|
if(results.size()>0) {
|
LocationInfoResult r = results.get(0);
|
String repairLocationNo = r.getSpareField2();
|
if(null != repairLocationNo && "" != repairLocationNo){
|
OPCUnit.write(opc.getEOP060_S_ORDER_CODE(),S_ORDER_CODE); //工单编号
|
OPCUnit.write(opc.getEOP060_S_PRODUCT_CODE(), S_PRODUCT_TYPE); //产品编号
|
OPCUnit.write(opc.getEOP060_S_SFC_CODE(), S_SFC_CODE); //总成编码
|
OPCUnit.write(opc.getEOP060_P_REPAIR_LOCATION(), repairLocationNo); //返修工位号
|
OPCUnit.write(opc.getEOP060_J_PC_WRITE_ORDER(), "true"); //PC下发工单完成
|
|
//更新为已经返修上线
|
Long id = result.getId();
|
repairManageInfoParam.setId(id);
|
repairManageInfoParam.setUpPlc("1");
|
repairManageInfoService.update(repairManageInfoParam);
|
|
}else{
|
logger.info("EOP060工位,handleRepair 请查询"+repairLocation+"工位是否配置返修工位号!");
|
}
|
}else{
|
logger.info("EOP060工位,handleRepair 无法查询到"+repairLocation+"工位!");
|
}
|
}
|
}
|
|
//PC读工单
|
public void handleOrder() {
|
IN_TIME = DateTool.getLocalTimeForDate();
|
S_ORDER_CODE = OPCUnit.read(opc.getEOP060_S_ORDER_CODE());//工单编号
|
S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP060_S_PRODUCT_CODE());//产品编号
|
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
|
S_SFC_CODE = OPCUnit.read(opc.getEOP060_S_SFC_CODE());//总成编码
|
OPCUnit.write(opc.getEOP060_J_PC_WRITE_ORDER(), "true"); //PC读工单完成
|
logger.info("EOP060工位,handleOrder PC处理完成!");
|
}
|
|
//PC读参数信息
|
public void handleInfo() throws Exception {
|
logger.info("EOP060工位,handleInfo START!");
|
|
if(null == list /*|| !S_PRODUCT_CODE_OLD.equals(S_PRODUCT_CODE)*/){
|
if(group != null){
|
opc.getServer().removeGroup(group,true);
|
}
|
group = opc.getServer().addGroup(GROUP_NAME);
|
|
CollectionParamConfParam collectionParamConfParam = new CollectionParamConfParam();
|
//collectionParamConfParam.setProductCode(S_PRODUCT_CODE);
|
collectionParamConfParam.setLocationCode(LOCATION_CODE);
|
CollectionParamConfService collectionParamConfService = opc.collectionParamConfService;
|
list = collectionParamConfService.findListBySpec(collectionParamConfParam);
|
|
|
for(int i=0;i<list.size();i++){
|
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
|
Item item = group.addItem(result.getGatherAddress());
|
result.setItem(item);
|
list.set(i,result);
|
}
|
//S_PRODUCT_CODE_OLD = S_PRODUCT_CODE;
|
}
|
|
if(null != list && list.size()>0) {
|
ParamCollectionService paramCollectionService = opc.paramCollectionService;
|
for (int i = 0; i < list.size(); i++) {
|
CollectionParamConfResult result = (CollectionParamConfResult) list.get(i);
|
Item item = result.getItem();
|
String value = OPCUnit.read(item);//读参数值
|
ParamCollectionParam paramCollectionParam = new ParamCollectionParam();
|
paramCollectionParam.setParamCode(result.getParamCode());
|
paramCollectionParam.setParamName(result.getParamName());
|
paramCollectionParam.setWorkOrderNo(S_ORDER_CODE);
|
paramCollectionParam.setSfcCode(S_SFC_CODE);
|
paramCollectionParam.setProductCode(S_PRODUCT_CODE);
|
paramCollectionParam.setProductionLine(result.getProductionLine());
|
paramCollectionParam.setLocationCode(result.getLocationCode());
|
paramCollectionParam.setParamValue(value);
|
paramCollectionParam.setParamLower(result.getParamLower());
|
paramCollectionParam.setParamUpper(result.getParamUpper());
|
paramCollectionParam.setParamStandard(result.getParamCentral());
|
paramCollectionParam.setCollectionTime(DateTool.getLocalTimeForDate());
|
paramCollectionParam.setUnit(result.getUnit());
|
paramCollectionService.add(paramCollectionParam);
|
}
|
}
|
|
logger.info("EOP060工位,handleInfo END!");
|
}
|
|
//PC完成
|
public void handleFinsh() {
|
if("".equals(S_ORDER_CODE)){
|
IN_TIME = DateTool.getLocalTimeForDate();
|
S_ORDER_CODE = OPCUnit.read(opc.getEOP060_S_ORDER_CODE());//工单编号
|
S_PRODUCT_TYPE = OPCUnit.read(opc.getEOP060_S_PRODUCT_CODE());//产品编号
|
S_PRODUCT_CODE = GlobalVariable.PRODUCT_CODE_MAP.get(S_PRODUCT_TYPE);
|
S_SFC_CODE = OPCUnit.read(opc.getEOP060_S_SFC_CODE());//总成编码
|
}
|
//处理过站信息
|
String S_PRODUCT_STATE_CODE = OPCUnit.read(opc.getEOP060_S_PRODUCT_STATE_CODE());
|
PassingStationCollectionParam param = new PassingStationCollectionParam();
|
param.setWorkOrderNo(S_ORDER_CODE);
|
param.setProductCode(S_PRODUCT_CODE);
|
param.setSfcCode(S_SFC_CODE);
|
param.setProductionLine(PRODUCTION_LINE);
|
param.setLocationCode(LOCATION_CODE);
|
param.setInboundTime(IN_TIME);
|
param.setOutboundTime(DateTool.getLocalTimeForDate());
|
param.setOutRsSign(S_PRODUCT_STATE_CODE);//出站是否合格
|
PassingStationCollectionService passingStationCollectionService = opc.passingStationCollectionService;
|
passingStationCollectionService.add(param);
|
|
OPCUnit.write(opc.getEOP060_J_PC_FINISH(), "true"); //PC完成
|
|
logger.info("EOP060工位,handleFinsh PC处理完成!");
|
}
|
|
}
|