jx pcn job collect third party db data

tags/yfai-pcn-ext-v1.0
王杰 2 years ago
parent a8751468c7
commit 3a2f762ada

@ -0,0 +1,96 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbCollectDataDispatchService {
/**
*
* @param collect
* @param fieldValue
* @param field
* @param fieldName
* @return
*/
@ApiOperation(value = "验证是否配置固定字段", notes = "验证是否配置固定字段")
default Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect, String fieldValue, String field, String fieldName) { return true; }
/**
*
* @param collect
* @param arr
* @param fieldCodeList
* @param field
* @return
*/
@ApiOperation(value = "验证必要字段数组是否配置在对象结构集合中", notes = "验证必要字段数组是否配置在对象结构集合中")
default Boolean checkFieldIsExistObjectCfg(SxThirdPartyDbCollectDataModel collect, String[] arr, List<String> fieldCodeList, String field) { return true; }
/**
*
* @param snField
* @return
*/
@ApiOperation(value = "分解条码字段", notes = "分解条码字段")
default String[] getArr(String snField) { return null; }
/**
*
*
* @param map
* @param snField
*/
@ApiOperation(value = "解析条码", notes = "解析条码")
default String assembleSn(Map<String, Object> map, String snField) { return null; }
/**
*
* @param collect
* @param map
* @param obj
*/
@ApiOperation(value = "反射写入动态数据", notes = "反射写入动态数据")
default void packDynamicsField(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, Object obj) {}
/**
*
* @param collect
* @param baseBean
*/
@ApiOperation(value = "反射写入默认数据", notes = "反射写入默认数据")
default void packDefaultField(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean) {}
/**
*
* @param obj
* @param fieldName
* @param value
*/
@ApiOperation(value = "反射写入数据", notes = "反射写入数据")
default void setObjectAttr(Object obj, String fieldName, Object value) {}
/**
*
* @param collect
* @param obj
*/
default void execMethodField(SxThirdPartyDbCollectDataModel collect, Object obj) {}
/**
*
* @param collect
* @return
*/
default Boolean saveParitySyncData(SxThirdPartyDbCollectDataModel collect) { return true; }
}

@ -0,0 +1,21 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import io.swagger.annotations.ApiOperation;
/**
* @Author: wangjie
* @CreateDate: 2021/01/19 15:06
* @Description:
**/
public interface ISxThirdPartyDbCollectDataJobService {
/**
* DB
* @param organizeCode
* @param cfgCode
* @param userInfo
*/
@ApiOperation(value = "第三方DB数据采集定时任务", notes = "第三方DB数据采集定时任务")
void doThirdPartyDbCollectData(String organizeCode, String cfgCode, String userInfo);
}

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import io.swagger.annotations.ApiOperation;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbCollectDataMethodService {
/**
* DB
* @param collect
* @param obj
* @return
*/
@ApiOperation(value = "第三方DB数据采集定时任务业务字段自定义方法", notes = "第三方DB数据采集定时任务业务字段自定义方法")
Object exec(SxThirdPartyDbCollectDataModel collect, Object obj);
}

@ -0,0 +1,26 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesThirdPartyDbCollectDataRecord;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbCollectDataRecordService {
/**
* DB
* @param organizeCode
* @param userInfo
* @param record
*/
@ApiOperation(value = "第三方DB数据采集定时任务执行记录", notes = "第三方DB数据采集定时任务执行记录")
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
void exec(String organizeCode, String userInfo, MesThirdPartyDbCollectDataRecord record);
}

@ -0,0 +1,20 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import io.swagger.annotations.ApiOperation;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbCollectDataStrategyService extends ISxThirdPartyDbCollectDataDispatchService {
/**
* DB
* @param collect
*/
@ApiOperation(value = "第三方DB数据采集定时任务策略方法", notes = "第三方DB数据采集定时任务策略方法")
void exec(SxThirdPartyDbCollectDataModel collect);
}

@ -0,0 +1,21 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import io.swagger.annotations.ApiOperation;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbParitySyncDispatchService {
/**
* DB
* @param collect
* @param builderService SQL
*/
@ApiOperation(value = "第三方DB对等同步", notes = "第三方DB对等同步")
void exec(SxThirdPartyDbCollectDataModel collect, ISxThirdPartyDbParitySyncSqlBuilderService builderService);
}

@ -0,0 +1,26 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
/**
* @Author: wangjie
* @CreateDate: 2021/01/18 11:22
* @Description:
**/
public interface ISxThirdPartyDbParitySyncSqlBuilderService {
/**
* DBSQL
* @param collect
* @param map
* @param fieldList
* @return
*/
@ApiOperation(value = "第三方DB对等同步SQL建造器", notes = "第三方DB对等同步SQL建造器")
StringBuilder builder(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, List<String> fieldList);
}

@ -0,0 +1,49 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.schedulejob;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataJobService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
/**
* @author wangjie
* @version 1.0
* @date 2021/2/2 16:44
**/
@Slf4j
@DisallowConcurrentExecution
@ApiOperation("第三方DB数据采集定时任务")
public class SxThirdPartyDbCollectDataJob implements Job {
@Autowired
private ISxThirdPartyDbCollectDataJobService thirdPartyDbCollectDataJobService;
@Override
public void execute(JobExecutionContext jobExecutionContext) {
Object param = jobExecutionContext.getJobDetail().getJobDataMap().get(MesPcnExtConstWords.PARAM);
if (StringUtils.isEmpty(param)) return;
log.info("第三方DB数据采集 --- JOB --- PARAM:{}", param.toString());
String[] paramArr = param.toString().split(MesPcnExtConstWords.COMMA);
if (paramArr.length != 2) return;
log.info("工厂{}第三方DB数据采集 --- JOB START --- PARAM:{}", paramArr[0], param.toString());
long startTime = System.currentTimeMillis();
thirdPartyDbCollectDataJobService.doThirdPartyDbCollectData(paramArr[0], paramArr[1], MesPcnExtConstWords.JOB);
long endTime = System.currentTimeMillis();
log.info("工厂{}第三方DB数据采集 --- JOB END --- 耗时: {} ms", paramArr[0], endTime - startTime);
}
}

@ -0,0 +1,427 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataMethodService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncDispatchService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncSqlBuilderService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbDynamicsFieldModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.mes.pcn.dao.IDataSourceDao;
import cn.estsh.i3plus.mes.pcn.util.BsJdbcTemplate;
import cn.estsh.i3plus.mes.pcn.util.BsJdbcTemplateConfig;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.ReflectTool;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesDataObject;
import cn.estsh.i3plus.pojo.mes.bean.MesDatasource;
import cn.estsh.i3plus.pojo.mes.bean.MesObjectCfg;
import cn.estsh.i3plus.pojo.mes.repository.MesDataObjectRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesObjectCfgRepository;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class SxThirdPartyDbCollectDataCommonService implements ISxThirdPartyDbCollectDataStrategyService {
private IDataSourceDao dataSourceDao;
private MesDataObjectRepository dataObjectRepository;
private MesObjectCfgRepository objectCfgRepository;
private BsJdbcTemplateConfig jdbcTemplateConfig;
private BsJdbcTemplate bsJdbcTemplate;
private ISxThirdPartyDbParitySyncDispatchService paritySyncDispatchService;
public SxThirdPartyDbCollectDataCommonService() {
dataSourceDao = (IDataSourceDao) SpringContextsUtil.getBean("dataSourceDao");
dataObjectRepository = (MesDataObjectRepository) SpringContextsUtil.getBean("mesDataObjectRepository");
objectCfgRepository = (MesObjectCfgRepository) SpringContextsUtil.getBean("mesObjectCfgRepository");
jdbcTemplateConfig = (BsJdbcTemplateConfig) SpringContextsUtil.getBean("bsJdbcTemplateConfig");
paritySyncDispatchService = (ISxThirdPartyDbParitySyncDispatchService) SpringContextsUtil.getBean("sxThirdPartyDbParitySyncDispatchService");
}
@Override
public void exec(SxThirdPartyDbCollectDataModel collect) {
if (MesPcnExtConstWords.STATE_1.compareTo(collect.getState()) == 0) execBasic(collect);
else if (MesPcnExtConstWords.STATE_2.compareTo(collect.getState()) == 0) execQuery(collect);
else if (MesPcnExtConstWords.STATE_3.compareTo(collect.getState()) == 0) execFeedBack(collect);
else return;
}
private void execBasic(SxThirdPartyDbCollectDataModel collect) {
if (!checkIsSelfAddition(collect)) return;
MesDatasource dataSourceDb = getDataSource(collect);
if (!checkDatasource(collect, dataSourceDb)) return;
MesDataObject dataObjectDb = getDataObjectByDsCode(collect, dataSourceDb.getDsCode());
if (!checkDataObject(collect, dataObjectDb)) return;
List<MesObjectCfg> objectCfgDbList = getObjectCfgListByObjectCode(collect);
if (!checkObjectCfgList(collect, objectCfgDbList, dataObjectDb)) return;
List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList = getDynamicsFieldList(collect);
if (!checkDynamicsField(collect, objectCfgDbList, dynamicsFieldList)) return;
collect.dataSource(dataSourceDb).dataObject(dataObjectDb).objectCfgList(objectCfgDbList).dynamicsFieldList(dynamicsFieldList).state(MesPcnExtConstWords.STATE_2);
if (collect.getNoExtraValidate()) exec(collect);
}
private void execQuery(SxThirdPartyDbCollectDataModel collect) {
bsJdbcTemplate = jdbcTemplateConfig.getJdbcTemplate(collect.getDataSource());
if (!checkBsJdbcTemplateConnect(collect, collect.getDataSource(), bsJdbcTemplate)) return;
String sql = doAppendSql(collect);
doCollectData(collect, sql, bsJdbcTemplate).state(MesPcnExtConstWords.STATE_3);
}
private void execFeedBack(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList())) return;
MesDataObject dataObjectDb = collect.getDataObject();
if (collect.getIsSelfAdditionBoo()) execFeedBack2DataObject(collect, dataObjectDb);
else execFeedBack2ThirdPartyDb(collect, dataObjectDb);
collect.complete();
}
private Boolean checkIsSelfAddition(SxThirdPartyDbCollectDataModel collect) {
collect.setIsSelfAdditionBoo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr().equals(collect.getIsSelfAddition()) ? true : false);
if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr().equals(collect.getIsSelfAddition()) ||
CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValueStr().equals(collect.getIsSelfAddition())) return true;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- %s:[%s]配置错误 ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), MesPcnExtConstWords.IS_SELF_ADDITION, collect.getIsSelfAddition())));
return false;
}
private MesDatasource getDataSource(SxThirdPartyDbCollectDataModel collect) {
MesDatasource dataSourceDb = dataSourceDao.getDataSourceByObjectCode(collect.getObjectCode(), collect.getOrganizeCode());
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- MesDatasource:{} ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), null == dataSourceDb ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(dataSourceDb));
return dataSourceDb;
}
private Boolean checkDatasource(SxThirdPartyDbCollectDataModel collect, MesDatasource dataSourceDb) {
if (null != dataSourceDb && !StringUtils.isEmpty(dataSourceDb.getDsType()) &&
(CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_MARIA_DB.name().equals(dataSourceDb.getDsType()) ||
CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_SQL_SERVER.name().equals(dataSourceDb.getDsType()) ||
CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_ORACLE.name().equals(dataSourceDb.getDsType()) ||
CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_POSTGRE_SQL.name().equals(dataSourceDb.getDsType()))) return true;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- 未配置有效的地址清单[MesDatasource] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode())));
return false;
}
private MesDataObject getDataObjectByDsCode(SxThirdPartyDbCollectDataModel collect, String dsCode) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(collect.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(dsCode, MesPcnExtConstWords.DS_CODE, packBean);
DdlPreparedPack.getStringEqualPack(collect.getObjectCode(), MesPcnExtConstWords.OBJECT_CODE, packBean);
MesDataObject dataObjectDb = dataObjectRepository.getByProperty(packBean);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- MesDataObject:{} ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), null == dataObjectDb ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(dataObjectDb));
return dataObjectDb;
}
private Boolean checkDataObject(SxThirdPartyDbCollectDataModel collect, MesDataObject dataObjectDb) {
if (!collect.getIsSelfAdditionBoo()) {
if (!checkDataObjectValue(collect, dataObjectDb.getFieldPk(), MesPcnExtConstWords.FIELD_PK)) return false;
if (!checkDataObjectValue(collect, dataObjectDb.getFeedField(), MesPcnExtConstWords.FEED_FIELD)) return false;
if (!checkDataObjectValue(collect, dataObjectDb.getFeedValue(), MesPcnExtConstWords.FEED_VALUE)) return false;
if (!checkDataObjectValue(collect, dataObjectDb.getReadFlagValue(), MesPcnExtConstWords.READ_FLAG_VALUE)) return false;
} else {
if (!checkDataObjectValue(collect, dataObjectDb.getSelfAddition(), MesPcnExtConstWords.SELF_ADDITION)) return false;
}
return true;
}
private Boolean checkDataObjectValue(SxThirdPartyDbCollectDataModel collect, String value, String field) {
if (!StringUtils.isEmpty(value)) return true;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- MesDataObject:[%s] IS NULL ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), field)));
return false;
}
private List<MesObjectCfg> getObjectCfgListByObjectCode(SxThirdPartyDbCollectDataModel collect) {
DdlPackBean pBean = DdlPackBean.getDdlPackBean(collect.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(collect.getObjectCode(), MesPcnExtConstWords.OBJECT_CODE, pBean);
List<MesObjectCfg> objectCfgDbList = objectCfgRepository.findByHqlWhere(pBean);
objectCfgDbList = CollectionUtils.isEmpty(objectCfgDbList) ? null :
objectCfgDbList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getFieldCode()))).collect(Collectors.toList());
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- MesObjectCfg:size[%s] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), CollectionUtils.isEmpty(objectCfgDbList) ? MesPcnExtConstWords.ZERO : objectCfgDbList.size())));
return objectCfgDbList;
}
private Boolean checkObjectCfgList(SxThirdPartyDbCollectDataModel collect, List<MesObjectCfg> objectCfgDbList, MesDataObject dataObjectDb) {
if (CollectionUtils.isEmpty(objectCfgDbList)) return false;
if (collect.getIsSelfAdditionBoo() && !checkDataObjectNecessaryFieldIsInObjectCfgList(collect, objectCfgDbList, dataObjectDb.getSelfAddition(), MesPcnExtConstWords.SELF_ADDITION)) return false;
if (!collect.getIsSelfAdditionBoo() && !checkDataObjectNecessaryFieldIsInObjectCfgList(collect, objectCfgDbList, dataObjectDb.getFieldPk(), MesPcnExtConstWords.FIELD_PK)) return false;
collect.noError();
return true;
}
private List<SxThirdPartyDbDynamicsFieldModel> getDynamicsFieldList(SxThirdPartyDbCollectDataModel collect) {
try {
return !StringUtils.isEmpty(collect.getDynamicsReflectField()) ? JSONObject.parseArray(collect.getDynamicsReflectField(), SxThirdPartyDbDynamicsFieldModel.class) : null;
} catch (Exception e) {
throw new ImppBusiException(String.format("动态反射字段[%s]转换异常:%s", collect.getDynamicsReflectField(), e.getMessage()));
}
}
private Boolean checkDynamicsField(SxThirdPartyDbCollectDataModel collect, List<MesObjectCfg> objectCfgDbList, List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList) {
List<String> sourceFieldList = CollectionUtils.isEmpty(dynamicsFieldList) ? null :
dynamicsFieldList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getSourceField()) &&
!StringUtils.isEmpty(o.getTargetField()))).map(SxThirdPartyDbDynamicsFieldModel::getSourceField).collect(Collectors.toList());
if (CollectionUtils.isEmpty(sourceFieldList)) return true;
List<String> fieldCodeList = objectCfgDbList.stream().filter(o -> (null != o &&
o.getIsSave() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue())).map(MesObjectCfg::getFieldCode).collect(Collectors.toList());
return checkFieldIsExistObjectCfg(collect, sourceFieldList.toArray(new String[sourceFieldList.size()]), fieldCodeList, MesPcnExtConstWords.DYNAMICS_REFLECT_FIELD);
}
private Boolean checkDataObjectNecessaryFieldIsInObjectCfgList(SxThirdPartyDbCollectDataModel collect, List<MesObjectCfg> objectCfgDbList, String fieldCode, String field) {
Optional<MesObjectCfg> objectCfgOp = objectCfgDbList.stream().filter(o -> (null != o && o.getFieldCode().equals(fieldCode))).findFirst();
if (null != objectCfgOp && objectCfgOp.isPresent()) return true;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- MesObjectCfg未配置MesDataObject对应字段%s:[%s] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), field, fieldCode)));
return false;
}
private Boolean checkBsJdbcTemplateConnect(SxThirdPartyDbCollectDataModel collect, MesDatasource dataSourceDb, BsJdbcTemplate bsJdbcTemplate) {
if (null == bsJdbcTemplate) {
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- BsJdbcTemplate 获取失败 ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode())));
return false;
}
Boolean isConnected = jdbcTemplateConfig.checkDbConn(dataSourceDb);
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- BsJdbcTemplate:isConnected[%s] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), isConnected)));
if (isConnected) collect.noError();
return isConnected;
}
private String doAppendSql(SxThirdPartyDbCollectDataModel collect) {
MesDataObject dataObjectDb = collect.getDataObject();
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(MesPcnExtConstWords.SELECT);
for (MesObjectCfg mesObjectCfg : collect.getObjectCfgList()) {
sqlBuilder.append(mesObjectCfg.getFieldCode()).append(MesPcnExtConstWords.COMMA);
}
sqlBuilder = new StringBuilder(sqlBuilder.substring(0, sqlBuilder.toString().length() - 1));
sqlBuilder.append(MesPcnExtConstWords.ONE_SPACE).append(MesPcnExtConstWords.FROM).append(MesPcnExtConstWords.ONE_SPACE)
.append(collect.getOtherTableName()).append(MesPcnExtConstWords.WHERE);
if (collect.getIsSelfAdditionBoo()) {
sqlBuilder.append(dataObjectDb.getSelfAddition())
.append(MesPcnExtConstWords.GREATER_THAN)
.append(StringUtils.isEmpty(dataObjectDb.getSelfAdditionValue()) ? 0 : dataObjectDb.getSelfAdditionValue());
} else {
sqlBuilder.append(dataObjectDb.getFeedField()).append(MesPcnExtConstWords.EQ).append(dataObjectDb.getReadFlagValue());
}
sqlBuilder = appendArr(sqlBuilder, getArr(collect.getSerialNumberArrField()));
sqlBuilder = appendArr(sqlBuilder, getArr(collect.getProductSnArrField()));
sqlBuilder.append(MesPcnExtConstWords.ORDER_BY).append(collect.getOrderField());
return modifySqlByDbType(collect, sqlBuilder.toString(), collect.getDataSource().getDsType());
}
private StringBuilder appendArr(StringBuilder sqlBuilder, String[] arr) {
if (null != arr) {
for (String snField : arr) {
if (StringUtils.isEmpty(snField)) continue;
sqlBuilder.append(MesPcnExtConstWords.AND_SPACE).append(snField).append(MesPcnExtConstWords.IS_NOT_NULL).append(MesPcnExtConstWords.AND_SPACE).append(snField).append(MesPcnExtConstWords.NOT_EQ_EMPTY);
}
}
return sqlBuilder;
}
private String modifySqlByDbType(SxThirdPartyDbCollectDataModel collect, String sql, String dataSourceType) {
if (CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_MARIA_DB.name().equals(dataSourceType)) {
sql = new StringJoiner(MesPcnExtConstWords.ONE_SPACE).add(sql).add(MesPcnExtConstWords.LIMIT).add(collect.getLimitRows()).toString();
} else if (CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_SQL_SERVER.name().equals(dataSourceType)) {
sql = sql.replaceFirst(MesPcnExtConstWords.SELECT, new StringJoiner(MesPcnExtConstWords.ONE_SPACE).add(MesPcnExtConstWords.SELECT_TOP).add(collect.getLimitRows()).toString());
} else if (CommonEnumUtil.DATA_SOURCE_TYPE.SOURCE_ORACLE.name().equals(dataSourceType)) {
sql = sql.replaceFirst(MesPcnExtConstWords.SELECT, MesPcnExtConstWords.SELECT_ROWNUM).
replaceFirst(MesPcnExtConstWords.WHERE, new StringBuilder().append(MesPcnExtConstWords.WHERE_ROWNUM_GREATER_THAN).append(collect.getLimitRows()).append(MesPcnExtConstWords.AND_SPACE).toString());
} else {
sql = new StringJoiner(MesPcnExtConstWords.ONE_SPACE).add(sql).add(MesPcnExtConstWords.LIMIT).add(collect.getLimitRows()).toString();
}
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- QUERY SQL:[{}] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), sql);
return sql;
}
private SxThirdPartyDbCollectDataModel doCollectData(SxThirdPartyDbCollectDataModel collect, String sql, BsJdbcTemplate bsJdbcTemplate) {
List<Map<String, Object>> mapList = bsJdbcTemplate.getJdbcTemplate().queryForList(sql, new HashMap<>());
collect.mapList(mapList).execSize(CollectionUtils.isEmpty(mapList) ? MesPcnExtConstWords.ZERO : mapList.size());
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- COLLECT_DATA:size[{}] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), collect.getExecSize());
return collect;
}
private void execFeedBack2DataObject(SxThirdPartyDbCollectDataModel collect, MesDataObject dataObjectDb) {
OptionalLong op = collect.getMapList().stream().mapToLong(o -> Long.parseLong(String.valueOf(o.get(dataObjectDb.getSelfAddition())))).max();
if (null != op && op.isPresent()) {
dataObjectDb.setSelfAdditionValue(op.getAsLong());
ConvertBean.serviceModelUpdate(dataObjectDb, collect.getUserInfo());
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- FEED BACK MesDataObject:{} ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), JSONObject.toJSONString(dataObjectDb));
dataObjectRepository.save(dataObjectDb);
}
}
private void execFeedBack2ThirdPartyDb(SxThirdPartyDbCollectDataModel collect, MesDataObject dataObjectDb) {
StringBuilder sb = new StringBuilder(MesPcnExtConstWords.UPDATE)
.append(collect.getOtherTableName())
.append(MesPcnExtConstWords.SET)
.append(dataObjectDb.getFeedField())
.append(MesPcnExtConstWords.ONE_SPACE).append(MesPcnExtConstWords.EQ).append(MesPcnExtConstWords.ONE_SPACE)
.append(dataObjectDb.getFeedValue())
.append(MesPcnExtConstWords.WHERE)
.append(dataObjectDb.getFieldPk()).append(MesPcnExtConstWords.IN_LEFT);
StringJoiner stringJoiner = new StringJoiner(MesPcnExtConstWords.COMMA);
for (Map<String, Object> map : collect.getMapList()) {
stringJoiner.add(map.get(dataObjectDb.getFieldPk()).toString());
}
sb.append(stringJoiner).append(MesPcnExtConstWords.IN_RIGHT);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC COMMON --- FEED BACK SQL:[{}] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), sb.toString());
bsJdbcTemplate.getJdbcTemplate().update(sb.toString(), new HashMap<>());
}
@Override
public Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect, String fieldValue, String field, String fieldName) {
if (!StringUtils.isEmpty(fieldValue)) return true;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- cfgValue:%s 未设置:%s字段[%s] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), collect.getCfgValue(), fieldName, field)));
return false;
}
@Override
public Boolean checkFieldIsExistObjectCfg(SxThirdPartyDbCollectDataModel collect, String[] arr, List<String> fieldCodeList, String field) {
if (null == arr) return true;
for (String snField : arr) {
if (StringUtils.isEmpty(snField) || fieldCodeList.contains(snField)) continue;
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- MesObjectCfg未配置%s对应字段[%s] ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), field, snField)));
return false;
}
return true;
}
@Override
public String[] getArr(String snField) {
if (StringUtils.isEmpty(snField)) return null;
return snField.split(MesPcnExtConstWords.COMMA);
}
@Override
public String assembleSn(Map<String, Object> map, String snField) {
if (StringUtils.isEmpty(snField)) return null;
String[] snArr = snField.split(MesPcnExtConstWords.COMMA);
String serialNumber = MesPcnExtConstWords.EMPTY;
StringBuilder snBuilder = new StringBuilder(serialNumber);
for (String s : snArr) {
snBuilder.append(map.get(s) == null ? MesPcnExtConstWords.EMPTY : String.valueOf(map.get(s)).trim());
}
serialNumber = snBuilder.toString();
return serialNumber.toUpperCase();
}
@Override
public void packDynamicsField(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, Object obj) {
List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList = collect.getDynamicsFieldList();
if (CollectionUtils.isEmpty(dynamicsFieldList)) return;
for (SxThirdPartyDbDynamicsFieldModel dynamicsField : dynamicsFieldList) {
if (null == dynamicsField) continue;
Object value = map.get(dynamicsField.getSourceField());
if (StringUtils.isEmpty(value)) continue;
String valueStr = String.valueOf(value).replaceAll(MesPcnExtConstWords.ONE_SPACE, MesPcnExtConstWords.EMPTY).trim();
setObjectAttr(obj, dynamicsField.getTargetField(), valueStr);
}
}
@Override
public void packDefaultField(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean) {
if (StringUtils.isEmpty(collect.getDefaultValueField())) return;
try {
Map<String, Object> defaultFieldValueMap = JSONObject.parseObject(collect.getDefaultValueField(), Map.class);
if (CollectionUtils.isEmpty(defaultFieldValueMap)) return;
ReflectTool.setObjectAttr(baseBean, defaultFieldValueMap);
} catch (Exception e) {
throw new ImppBusiException(String.format("默认字段[%s]处理异常:%s", collect.getDefaultValueField(), e.getMessage()));
}
}
@Override
public void setObjectAttr(Object obj, String fieldName, Object value) {
try {
ReflectTool.setObjectAttr(obj, fieldName, value);
} catch (Exception e) {
throw new ImppBusiException(String.format("目标字段[%s]反射写值[%s]异常:%s", fieldName, value, e.getMessage()));
}
}
@Override
public void execMethodField(SxThirdPartyDbCollectDataModel collect, Object obj) {
if (StringUtils.isEmpty(collect.getMethodField())) return;
try {
Map<String, String> methodFieldMap = JSONObject.parseObject(collect.getMethodField(), Map.class);
if (CollectionUtils.isEmpty(methodFieldMap)) return;
Map<String, ISxThirdPartyDbCollectDataMethodService> methodImplMap = null;
for (String field : methodFieldMap.keySet()) {
if (StringUtils.isEmpty(field)) continue;
ISxThirdPartyDbCollectDataMethodService methodService = (ISxThirdPartyDbCollectDataMethodService) SpringContextsUtil.getBean(methodFieldMap.get(field));
if (null == methodFieldMap) throw new ImppBusiException(String.format("业务自定义方法[%s]不存在", methodFieldMap.get(field)));
if (CollectionUtils.isEmpty(methodImplMap)) methodImplMap = new LinkedHashMap<>();
methodImplMap.put(field, methodService);
}
if (CollectionUtils.isEmpty(methodImplMap)) return;
for (String field : methodImplMap.keySet()) {
if (StringUtils.isEmpty(field)) continue;
Object value = methodImplMap.get(field).exec(collect, obj);
if (StringUtils.isEmpty(value)) continue;
setObjectAttr(obj, field, value);
}
} catch (Exception e) {
throw new ImppBusiException(String.format("业务自定义方法字段%s:[%s]处理异常:%s", MesPcnExtConstWords.METHOD_FIELD, collect.getMethodField(), e.getMessage()));
}
}
@Override
public Boolean saveParitySyncData(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList()) || StringUtils.isEmpty(collect.getParitySyncTableName())) return false;
try {
ISxThirdPartyDbParitySyncSqlBuilderService builderService =
(ISxThirdPartyDbParitySyncSqlBuilderService) SpringContextsUtil.getBean(MesPcnExtEnumUtil.SX_PARITY_SYNC_SQL_BUILDER_STRATEGY.valueOfClazz(collect.getParitySyncDatabase()));
paritySyncDispatchService.exec(collect, builderService);
} catch (Exception e) {
log.info(collect.error(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s EXEC --- EXEC COMMON --- 对等同步执行异常:%s ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), e.getMessage())));
return false;
}
return true;
}
}

@ -0,0 +1,113 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataJobService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataRecordService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesThirdPartyDbCollectDataRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.mes.pcn.api.iservice.base.IConfigService;
import cn.estsh.i3plus.pojo.mes.bean.MesConfig;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
/**
* @Author: wangjie
* @CreateDate: 2019/8/23 1:16 PM
* @Description: DB
**/
@Slf4j
@Service
public class SxThirdPartyDbCollectDataJobService implements ISxThirdPartyDbCollectDataJobService {
@Autowired
private IConfigService configService;
@Autowired
private ISxThirdPartyDbCollectDataRecordService thirdPartyDbCollectDataRecordService;
@Value("${spring.jpa.database}")
private Database database;
@Override
public void doThirdPartyDbCollectData(String organizeCode, String cfgCode, String userInfo) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC ---", organizeCode, cfgCode);
List<MesConfig> cfgList = getCfgList(organizeCode, cfgCode, userInfo);
if (CollectionUtils.isEmpty(cfgList)) return;
for (MesConfig cfg : cfgList) {
if (null == cfg) continue;
SxThirdPartyDbCollectDataModel collect = getCfgModel(organizeCode, cfg, userInfo);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} START --- collect:{} ---", organizeCode, cfgCode, cfg.getCfgKey(), null == collect ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(collect));
if (null == collect) continue;
try {
((ISxThirdPartyDbCollectDataStrategyService) SpringContextsUtil.getBean(collect.getStrategyClass())).exec(collect);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} END --- execResult[{}] execSize[{}] ---", organizeCode, cfgCode, cfg.getCfgKey(), collect.getExecResult(), collect.getExecSize());
} catch (Exception e) {
saveCurExecResult(organizeCode, cfg, userInfo, String.format("Exception:%s", e.getMessage()));
}
}
}
private SxThirdPartyDbCollectDataModel getCfgModel(String organizeCode, MesConfig cfg, String userInfo) {
SxThirdPartyDbCollectDataModel collect = JSONObject.parseObject(cfg.getCfgValue(), SxThirdPartyDbCollectDataModel.class);
if (null == collect) {
saveCurExecResult(organizeCode, cfg, userInfo, String.format("cfgValue:%s 无效配置", cfg.getCfgValue()));
return null;
}
String error = collect.checkValid();
if (!StringUtils.isEmpty(error)) {
saveCurExecResult(organizeCode, cfg, userInfo, String.format("cfgValue:%s 未设置:%s", cfg.getCfgValue(), error));
return null;
}
return collect.organizeCode(organizeCode).userInfo(userInfo).cfgCode(cfg.getCfgCode()).objectCode(cfg.getCfgKey()).cfgValue(cfg.getCfgValue()).paritySyncDatabase(database.name()).defaultValue();
}
private List<MesConfig> getCfgList(String organizeCode, String cfgCode, String userInfo) {
List<MesConfig> cfgList = configService.findMesConfigByCfgCode(cfgCode, organizeCode);
cfgList = CollectionUtils.isEmpty(cfgList) ? null :
cfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getCfgValue()) && !StringUtils.isEmpty(o.getCfgKey())))
.distinct().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MesConfig::getCfgKey))), ArrayList::new)
);
if (CollectionUtils.isEmpty(cfgList)) {
MesThirdPartyDbCollectDataRecord record = new MesThirdPartyDbCollectDataRecord(cfgCode);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- 未配置有效的参数配置 ---", organizeCode, cfgCode);
thirdPartyDbCollectDataRecordService.exec(organizeCode, userInfo, record);
}
return cfgList;
}
private void saveCurExecResult(String organizeCode, MesConfig cfg, String userInfo, String message) {
MesThirdPartyDbCollectDataRecord record = new MesThirdPartyDbCollectDataRecord(cfg.getCfgCode(), cfg.getCfgKey(), cfg.getCfgValue());
log.info(record.message(String.format("工厂%s第三方DB数据采集 --- CFG_CODE: %s EXEC --- CFG_KEY: %s --- %s ---", organizeCode, cfg.getCfgCode(), cfg.getCfgKey(), message)));
thirdPartyDbCollectDataRecordService.exec(organizeCode, userInfo, record);
}
}

@ -0,0 +1,24 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataMethodService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SxThirdPartyDbCollectDataMethodGetDateService implements ISxThirdPartyDbCollectDataMethodService {
@Override
public Object exec(SxThirdPartyDbCollectDataModel collect, Object obj) {
try {
BaseBean baseBean = (BaseBean) obj;
return null != baseBean ? baseBean.getModifyDatetime() : TimeTool.getNowTime(true);
} catch (Exception e) {
throw new ImppBusiException(String.format("[%s]执行异常:%s", this.getClass().getSimpleName(), e.getMessage()));
}
}
}

@ -0,0 +1,149 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.ConvertBeanExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.ConvertUtil;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
public class SxThirdPartyDbCollectDataProxyDynamicsService implements ISxThirdPartyDbCollectDataStrategyService {
private ISxThirdPartyDbCollectDataStrategyService proxyObject;
public SxThirdPartyDbCollectDataProxyDynamicsService(ISxThirdPartyDbCollectDataStrategyService proxyObject) {
this.proxyObject = proxyObject;
}
@Override
public void exec(SxThirdPartyDbCollectDataModel collect) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY DYNAMICS --- START ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
if (!checkFieldIsNull(collect)) return;
BaseBean baseBean = instanceDynamicsTable(collect);
BaseRepository baseRepository = instanceDynamicsRepository(collect, baseBean);
proxyObject.exec(collect);
saveDynamicsData(collect, baseBean, baseRepository);
saveParitySyncData(collect);
proxyObject.exec(collect);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY DYNAMICS --- END ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
}
private Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect) {
if (!checkFieldIsNull(collect, collect.getDynamicsTableName(), MesPcnExtConstWords.DYNAMICS_TABLE_NAME, "动态表名")) return false;
if (!checkFieldIsNull(collect, collect.getDynamicsReflectField(), MesPcnExtConstWords.DYNAMICS_REFLECT_FIELD, "动态")) return false;
return true;
}
private BaseBean instanceDynamicsTable(SxThirdPartyDbCollectDataModel collect) {
try {
Class clazz = Class.forName(collect.getDynamicsTableName());
return (BaseBean) clazz.newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new ImppBusiException(String.format("动态表名[%s]反射异常:%s", collect.getDynamicsTableName(), e.getMessage()));
}
}
private BaseRepository instanceDynamicsRepository(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean) {
try {
return (BaseRepository) SpringContextsUtil.getBean(ConvertUtil.toLowerCaseFirstOne(baseBean.getClass().getSimpleName()) + MesPcnExtConstWords.Repository);
} catch (Exception e) {
throw new ImppBusiException(String.format("动态表名[%s]注入Repository类异常:%s", collect.getDynamicsTableName(), e.getMessage()));
}
}
private List<BaseBean> saveDynamicsData(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean, BaseRepository baseRepository) {
if (CollectionUtils.isEmpty(collect.getMapList())) return null;
packBasicDynamicsData(collect, baseBean);
packDefaultField(collect, baseBean);
List<BaseBean> resultList = new ArrayList<>();
for (Map<String, Object> map : collect.getMapList()) {
BaseBean result = instanceDynamicsTable(collect);
BeanUtils.copyProperties(baseBean, result);
packResult(collect, map, result);
execMethodField(collect, result);
resultList.add(result);
baseRepository.insert(result);
}
return resultList;
}
private void packBasicDynamicsData(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean) {
baseBean.setOrganizeCode(collect.getOrganizeCode());
ConvertBean.serviceModelInitialize(baseBean, collect.getUserInfo());
setObjectAttr(baseBean, MesPcnExtConstWords.SYSTEM_SYNC_STATUS, MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
new ConvertBeanExt(baseBean).convertBean(baseBean);
}
private void packResult(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, BaseBean result) {
if (!StringUtils.isEmpty(collect.getSerialNumberArrField()))
setObjectAttr(result, MesPcnExtConstWords.SERIAL_NUMBER, assembleSn(map, collect.getSerialNumberArrField()));
if (!StringUtils.isEmpty(collect.getProductSnArrField()))
setObjectAttr(result, MesPcnExtConstWords.PRODUCT_SN, assembleSn(map, collect.getProductSnArrField()));
result.setId(null);
packDynamicsField(collect, map, result);
}
@Override
public Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect, String fieldValue, String field, String fieldName) {
return proxyObject.checkFieldIsNull(collect, fieldValue, field, fieldName);
}
@Override
public void packDefaultField(SxThirdPartyDbCollectDataModel collect, BaseBean baseBean) {
if (StringUtils.isEmpty(collect.getDefaultValueField())) return;
proxyObject.packDefaultField(collect, baseBean);
}
@Override
public void packDynamicsField(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, Object obj) {
proxyObject.packDynamicsField(collect, map, obj);
}
@Override
public void setObjectAttr(Object obj, String fieldName, Object value) {
proxyObject.setObjectAttr(obj, fieldName, value);
}
@Override
public void execMethodField(SxThirdPartyDbCollectDataModel collect, Object obj) {
if (StringUtils.isEmpty(collect.getMethodField())) return;
proxyObject.execMethodField(collect, obj);
}
@Override
public String assembleSn(Map<String, Object> map, String snField) {
return proxyObject.assembleSn(map, snField);
}
@Override
public Boolean saveParitySyncData(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList())) return false;
return proxyObject.saveParitySyncData(collect);
}
}

@ -0,0 +1,50 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@Slf4j
public class SxThirdPartyDbCollectDataProxyParitySyncService implements ISxThirdPartyDbCollectDataStrategyService {
private ISxThirdPartyDbCollectDataStrategyService proxyObject;
public SxThirdPartyDbCollectDataProxyParitySyncService(ISxThirdPartyDbCollectDataStrategyService proxyObject) {
this.proxyObject = proxyObject;
}
@Override
public void exec(SxThirdPartyDbCollectDataModel collect) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY PARITY SYNC --- START ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
if (!checkFieldIsNull(collect)) return;
proxyObject.exec(collect);
if (!saveParitySyncData(collect)) return;
proxyObject.exec(collect);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY PARITY SYNC --- END ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
}
private Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect) {
if (!checkFieldIsNull(collect, collect.getParitySyncTableName(), MesPcnExtConstWords.PARITY_SYNC_TABLE_NAME, "对等同步表名")) return false;
return true;
}
@Override
public Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect, String fieldValue, String field, String fieldName) {
return proxyObject.checkFieldIsNull(collect, fieldValue, field, fieldName);
}
@Override
public Boolean saveParitySyncData(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList())) return false;
return proxyObject.saveParitySyncData(collect);
}
}

@ -0,0 +1,169 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.mes.pcn.api.iservice.base.IBaseDataService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesDatasource;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipment;
import cn.estsh.i3plus.pojo.mes.bean.MesObjectCfg;
import cn.estsh.i3plus.pojo.mes.bean.MesProductData;
import cn.estsh.i3plus.pojo.mes.model.ProductDataModel;
import cn.estsh.i3plus.pojo.mes.repository.MesProductDataRepository;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Slf4j
public class SxThirdPartyDbCollectDataProxyProdDataService implements ISxThirdPartyDbCollectDataStrategyService {
private ISxThirdPartyDbCollectDataStrategyService proxyObject;
private IBaseDataService baseDataService;
private MesProductDataRepository productDataRepository;
public SxThirdPartyDbCollectDataProxyProdDataService(ISxThirdPartyDbCollectDataStrategyService proxyObject) {
this.proxyObject = proxyObject;
baseDataService = (IBaseDataService) SpringContextsUtil.getBean("baseDataService");
productDataRepository = (MesProductDataRepository) SpringContextsUtil.getBean("mesProductDataRepository");
}
@Override
public void exec(SxThirdPartyDbCollectDataModel collect) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY PROD DATA --- START ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
if (!checkFieldIsNull(collect)) return;
proxyObject.exec(collect.noExtraValidate(false));
if (!checkObjectCfgList(collect)) return;
proxyObject.exec(collect);
saveProductData(collect);
saveParitySyncData(collect);
proxyObject.exec(collect);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC PROXY PROD DATA --- END ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
}
private Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect) {
if (!checkFieldIsNull(collect, collect.getSerialNumberArrField(), MesPcnExtConstWords.SERIAL_NUMBER_ARR_FIELD, "过程条码")) return false;
if (!checkFieldIsNull(collect, collect.getProductSnArrField(), MesPcnExtConstWords.PRODUCT_SN_ARR_FIELD, "产品条码")) return false;
return true;
}
private Boolean checkObjectCfgList(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getObjectCfgList())) return false;
List<String> fieldCodeList = collect.getObjectCfgList().stream().filter(o -> (null != o &&
o.getIsSave() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue())).map(MesObjectCfg::getFieldCode).collect(Collectors.toList());
if (!checkFieldIsExistObjectCfg(collect, getArr(collect.getSerialNumberArrField()), fieldCodeList, MesPcnExtConstWords.SERIAL_NUMBER_ARR_FIELD)) return false;
if (!checkFieldIsExistObjectCfg(collect, getArr(collect.getProductSnArrField()), fieldCodeList, MesPcnExtConstWords.PRODUCT_SN_ARR_FIELD)) return false;
return true;
}
private List<MesProductData> saveProductData(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList())) return null;
MesProductData productData = getBasicProductData(collect);
return saveProductDataList(collect, productData);
}
private MesProductData getBasicProductData(SxThirdPartyDbCollectDataModel collect) {
MesProductData productData = new MesProductData();
productData.setObjectCode(collect.getObjectCode());
productData.setObjectName(collect.getDataObject().getObjectName());
productData.setOrganizeCode(collect.getOrganizeCode());
getEquipment(productData, collect.getDataSource());
ConvertBean.serviceModelInitialize(productData, collect.getUserInfo());
return productData;
}
private void getEquipment(MesProductData productData, MesDatasource dataSource) {
if (StringUtils.isEmpty(dataSource.getEquipmentCode())) return;
productData.setEquCode(dataSource.getEquipmentCode());
MesEquipment equipment = baseDataService.getEqpByCode(dataSource.getEquipmentCode(), productData.getOrganizeCode());
if (null == equipment) return;
productData.setEquName(equipment.getEquipmentName());
}
private List<MesProductData> saveProductDataList(SxThirdPartyDbCollectDataModel collect, MesProductData productData) {
List<MesProductData> resultList = new ArrayList<>();
for (Map<String, Object> map : collect.getMapList()) {
MesProductData result = new MesProductData();
BeanUtils.copyProperties(productData, result);
packResult(collect, map, result);
resultList.add(result);
productDataRepository.insert(result);
}
return resultList;
}
private void packResult(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, MesProductData result) {
result.setSerialNumber(assembleSn(map, collect.getSerialNumberArrField()));
result.setProductSn(assembleSn(map, collect.getProductSnArrField()));
result.setId(null);
List<ProductDataModel> productDataModels = new ArrayList<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
Optional<MesObjectCfg> optional = collect.getObjectCfgList().stream().filter(o ->
(null != o && o.getFieldCode().equals(entry.getKey()) && o.getIsSave() != null && o.getIsSave() == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue())).findFirst();
if (null != optional && optional.isPresent()) {
ProductDataModel productDataModel = new ProductDataModel(
String.valueOf(entry.getKey()).replaceAll(MesPcnExtConstWords.ONE_SPACE, MesPcnExtConstWords.EMPTY).trim(),
optional.get().getFieldName().replaceAll(MesPcnExtConstWords.ONE_SPACE, MesPcnExtConstWords.EMPTY).trim(),
String.valueOf(entry.getValue()).replaceAll(MesPcnExtConstWords.ONE_SPACE, MesPcnExtConstWords.EMPTY).trim());
productDataModels.add(productDataModel);
}
}
result.setLineData(JSON.toJSONString(productDataModels));
result.setSystemSyncStatus(MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
packDynamicsField(collect, map, result);
}
@Override
public Boolean checkFieldIsNull(SxThirdPartyDbCollectDataModel collect, String fieldValue, String field, String fieldName) {
return proxyObject.checkFieldIsNull(collect, fieldValue, field, fieldName);
}
@Override
public Boolean checkFieldIsExistObjectCfg(SxThirdPartyDbCollectDataModel collect, String[] arr, List<String> fieldCodeList, String field) {
return proxyObject.checkFieldIsExistObjectCfg(collect, arr, fieldCodeList, field);
}
@Override
public String[] getArr(String snField) { return proxyObject.getArr(snField); }
@Override
public void packDynamicsField(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, Object obj) {
proxyObject.packDynamicsField(collect, map, obj);
}
@Override
public String assembleSn(Map<String, Object> map, String snField) {
return proxyObject.assembleSn(map, snField);
}
@Override
public Boolean saveParitySyncData(SxThirdPartyDbCollectDataModel collect) {
if (CollectionUtils.isEmpty(collect.getMapList())) return false;
return proxyObject.saveParitySyncData(collect);
}
}

@ -0,0 +1,66 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataRecordService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesThirdPartyDbCollectDataRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
@Slf4j
public class SxThirdPartyDbCollectDataProxyWatchService implements ISxThirdPartyDbCollectDataStrategyService {
private ISxThirdPartyDbCollectDataStrategyService proxyObject;
private ISxThirdPartyDbCollectDataRecordService thirdPartyDbCollectDataRecordService;
public SxThirdPartyDbCollectDataProxyWatchService(ISxThirdPartyDbCollectDataStrategyService proxyObject) {
this.proxyObject = proxyObject;
thirdPartyDbCollectDataRecordService = (ISxThirdPartyDbCollectDataRecordService) SpringContextsUtil.getBean("gzThirdPartyDbCollectDataRecordService");
}
@Override
public void exec(SxThirdPartyDbCollectDataModel collect) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC WATCH --- START ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode());
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
proxyObject.exec(collect);
} catch (ImppBusiException e) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC WATCH --- ImppBusiException:%s ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), e.getMessage());
} catch (Exception e) {
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC WATCH --- Exception:%s ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), JSONObject.toJSONString(e));
}
saveCurExecResult(collect);
stopWatch.stop();
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC --- EXEC WATCH --- END --- 耗时:{} ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), stopWatch.getTotalTimeMillis());
}
private void saveCurExecResult(SxThirdPartyDbCollectDataModel collect) {
if (collect.getExecResult() || !StringUtils.isEmpty(collect.getError()))
thirdPartyDbCollectDataRecordService.exec(collect.getOrganizeCode(), collect.getUserInfo(), packRecord(collect));
}
private MesThirdPartyDbCollectDataRecord packRecord(SxThirdPartyDbCollectDataModel collect) {
return new MesThirdPartyDbCollectDataRecord(collect.getCfgCode(), collect.getObjectCode(), collect.getCfgValue(),
collect.getExecResult() ? CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() : CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), collect.getExecSize(), collect.getError());
}
}

@ -0,0 +1,46 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataRecordService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesThirdPartyDbCollectDataRecord;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesThirdPartyDbCollectDataRecordRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Slf4j
@Service
public class SxThirdPartyDbCollectDataRecordService implements ISxThirdPartyDbCollectDataRecordService {
@Autowired
private MesThirdPartyDbCollectDataRecordRepository thirdPartyDbCollectDataRecordRepository;
@Override
public void exec(String organizeCode, String userInfo, MesThirdPartyDbCollectDataRecord record) {
if (repeatCheck(organizeCode, record)) return;
record.setOrganizeCode(organizeCode);
record.setSystemSyncStatus(MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelInitialize(record, userInfo);
thirdPartyDbCollectDataRecordRepository.insert(record);
}
private Boolean repeatCheck(String organizeCode, MesThirdPartyDbCollectDataRecord record) {
if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == record.getResult()) return false;
if (StringUtils.isEmpty(record.getMessage())) return true;
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(record.getCfgCode(), MesPcnExtConstWords.CFG_CODE, packBean);
DdlPreparedPack.getStringEqualPack(record.getObjectCode(), MesPcnExtConstWords.OBJECT_CODE, packBean);
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{MesPcnExtConstWords.CREATE_DATE_TIME}, packBean);
MesThirdPartyDbCollectDataRecord recordDb = thirdPartyDbCollectDataRecordRepository.getByProperty(packBean);
if (null == recordDb || (StringUtils.isEmpty(recordDb.getMessage()) || !recordDb.getMessage().equals(record.getMessage()))) return false;
return true;
}
}

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
public class SxThirdPartyDbCollectDataStrategyDynamicsService implements ISxThirdPartyDbCollectDataStrategyService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
public void exec(SxThirdPartyDbCollectDataModel collect) {
new SxThirdPartyDbCollectDataProxyWatchService(new SxThirdPartyDbCollectDataProxyDynamicsService(new SxThirdPartyDbCollectDataCommonService())).exec(collect);
}
}

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
public class SxThirdPartyDbCollectDataStrategyParitySyncService implements ISxThirdPartyDbCollectDataStrategyService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
public void exec(SxThirdPartyDbCollectDataModel collect) {
new SxThirdPartyDbCollectDataProxyWatchService(new SxThirdPartyDbCollectDataProxyParitySyncService(new SxThirdPartyDbCollectDataCommonService())).exec(collect);
}
}

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbCollectDataStrategyService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
public class SxThirdPartyDbCollectDataStrategyProdDataService implements ISxThirdPartyDbCollectDataStrategyService {
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {ImppBusiException.class, Exception.class})
public void exec(SxThirdPartyDbCollectDataModel collect) {
new SxThirdPartyDbCollectDataProxyWatchService(new SxThirdPartyDbCollectDataProxyProdDataService(new SxThirdPartyDbCollectDataCommonService())).exec(collect);
}
}

@ -0,0 +1,49 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncDispatchService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncSqlBuilderService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesObjectCfg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class SxThirdPartyDbParitySyncDispatchService implements ISxThirdPartyDbParitySyncDispatchService {
@Autowired
private EntityManager entityManager;
@Override
public void exec(SxThirdPartyDbCollectDataModel collect, ISxThirdPartyDbParitySyncSqlBuilderService builderService) {
if (CollectionUtils.isEmpty(collect.getMapList()) || StringUtils.isEmpty(collect.getParitySyncTableName())) return;
List<MesObjectCfg> objectCfgList = collect.getObjectCfgList().stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getIsSave()) && CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == o.getIsSave())).collect(Collectors.toList());
List<String> fieldList = CollectionUtils.isEmpty(objectCfgList) ? null :
objectCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getFieldCode()))).map(MesObjectCfg::getFieldCode).collect(Collectors.toList());
for (Map<String, Object> map : collect.getMapList()) {
if (null == map) continue;
StringBuilder builder = builderService.builder(collect, map, fieldList);
log.info("工厂{}第三方DB数据采集 --- CFG_CODE: {} EXEC --- CFG_KEY: {} EXEC ---EXEC PARITY SYNC --- SQL:{} ---", collect.getOrganizeCode(), collect.getCfgCode(), collect.getObjectCode(), builder.toString());
Query insert = entityManager.createNativeQuery(builder.toString());
insert.executeUpdate();
}
}
}

@ -0,0 +1,46 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncSqlBuilderService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class SxThirdPartyDbParitySyncSqlBuilderMysqlService implements ISxThirdPartyDbParitySyncSqlBuilderService {
@Override
public StringBuilder builder(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, List<String> fieldList) {
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder fieldBuilder = new StringBuilder();
StringBuilder valueBuilder = new StringBuilder();
sqlBuilder.append(" INSERT INTO ").append(collect.getParitySyncTableName()).append("(");
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (null == entry || !fieldList.contains(entry.getKey())) continue;
if (!StringUtils.isEmpty(fieldBuilder.toString())) fieldBuilder.append(", ");
if (!StringUtils.isEmpty(valueBuilder.toString())) valueBuilder.append(", ");
fieldBuilder.append(entry.getKey());
if (StringUtils.isEmpty(entry.getValue())) {
valueBuilder.append("NULL");
} else {
if (entry.getValue() instanceof String) {
valueBuilder.append("\'").append(entry.getValue()).append("\'");
} else {
valueBuilder.append(entry.getValue());
}
}
}
sqlBuilder.append(fieldBuilder).append(")").append(" VALUES (").append(valueBuilder).append(") ");
return sqlBuilder;
}
}

@ -0,0 +1,46 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi.collect;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxThirdPartyDbParitySyncSqlBuilderService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxThirdPartyDbCollectDataModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class SxThirdPartyDbParitySyncSqlBuilderSqlServerService implements ISxThirdPartyDbParitySyncSqlBuilderService {
@Override
public StringBuilder builder(SxThirdPartyDbCollectDataModel collect, Map<String, Object> map, List<String> fieldList) {
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder fieldBuilder = new StringBuilder();
StringBuilder valueBuilder = new StringBuilder();
sqlBuilder.append(" INSERT INTO [").append(collect.getParitySyncTableName()).append("](");
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (null == entry || !fieldList.contains(entry.getKey())) continue;
if (!StringUtils.isEmpty(fieldBuilder.toString())) fieldBuilder.append(", ");
if (!StringUtils.isEmpty(valueBuilder.toString())) valueBuilder.append(", ");
fieldBuilder.append("[").append(entry.getKey()).append("]");
if (StringUtils.isEmpty(entry.getValue())) {
valueBuilder.append("NULL");
} else {
if (entry.getValue() instanceof String) {
valueBuilder.append("\'").append(entry.getValue()).append("\'");
} else {
valueBuilder.append(entry.getValue());
}
}
}
sqlBuilder.append(fieldBuilder).append(")").append(" VALUES (").append(valueBuilder).append(") ");
return sqlBuilder;
}
}

@ -16,17 +16,17 @@ import java.util.stream.Collectors;
*
*/
@Slf4j
public class SxCellTaktDispatchSingleton {
public class SxThirdPartyPlcCollectCellTaktDispatchSingleton {
protected volatile static Boolean isInit = false;
private static class SxCellTaktDispatchHolder { private final static SxCellTaktDispatchSingleton INSTANCE = new SxCellTaktDispatchSingleton(); }
private static class SxCellTaktDispatchHolder { private final static SxThirdPartyPlcCollectCellTaktDispatchSingleton INSTANCE = new SxThirdPartyPlcCollectCellTaktDispatchSingleton(); }
public static SxCellTaktDispatchSingleton getInstance() { return SxCellTaktDispatchHolder.INSTANCE; }
public static SxThirdPartyPlcCollectCellTaktDispatchSingleton getInstance() { return SxCellTaktDispatchHolder.INSTANCE; }
private SxCellTaktDispatchSingleton() { isInit = true; }
private SxThirdPartyPlcCollectCellTaktDispatchSingleton() { isInit = true; }
private volatile static Map<String, SxCellTaktMonitorHandler> cellTaktMonitorMap = new ConcurrentHashMap<>();
private volatile static Map<String, SxThirdPartyPlcCollectCellTaktMonitorHandler> cellTaktMonitorMap = new ConcurrentHashMap<>();
public static Boolean getIsInit() { return isInit; }
@ -37,7 +37,7 @@ public class SxCellTaktDispatchSingleton {
private static void execMonitorRemove(String org, List<String> removeKeyList) {
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR CLOSED KEY: {} --- START ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, CollectionUtils.isEmpty(removeKeyList) ? MesPcnExtConstWords.EMPTY : JSONObject.toJSONString(removeKeyList));
if (!CollectionUtils.isEmpty(removeKeyList)) removeKeyList.stream().forEach(SxCellTaktDispatchSingleton::execMonitorRemove);
if (!CollectionUtils.isEmpty(removeKeyList)) removeKeyList.stream().forEach(SxThirdPartyPlcCollectCellTaktDispatchSingleton::execMonitorRemove);
}
private static void execMonitorCompareToCfg(String org, Map<String, String> cfgMap) {
@ -53,7 +53,7 @@ public class SxCellTaktDispatchSingleton {
}
private static void execMonitorRemove(String key) {
SxCellTaktMonitorHandler handler = cellTaktMonitorMap.get(key);
SxThirdPartyPlcCollectCellTaktMonitorHandler handler = cellTaktMonitorMap.get(key);
handler.cancel();
cellTaktMonitorMap.remove(key);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR CLOSED KEY: {} ---", key.split(MesPcnExtConstWords.COLON)[1], MesPcnExtConstWords.COLLECT_CELL_TAKT, key);
@ -64,7 +64,7 @@ public class SxCellTaktDispatchSingleton {
if (StringUtils.isEmpty(key)) continue;
String[] plcCodeArr = cfgMap.get(key).split(MesPcnExtConstWords.COMMA);
if (null == plcCodeArr || plcCodeArr.length != 2) continue;
SxCellTaktMonitorHandler handler = cellTaktMonitorMap.computeIfAbsent(key, o -> new SxCellTaktMonitorHandler(org, key));
SxThirdPartyPlcCollectCellTaktMonitorHandler handler = cellTaktMonitorMap.computeIfAbsent(key, o -> new SxThirdPartyPlcCollectCellTaktMonitorHandler(org, key));
handler.isRetry(plcCodeArr);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC SINGLETON --- MONITOR {} KEY: {} ---", org, MesPcnExtConstWords.COLLECT_CELL_TAKT, handler.version() ? "ADD" : "RETRY", key);
}

@ -17,7 +17,7 @@ import java.util.concurrent.ExecutorService;
/**
*
*/
public class SxCellTaktMonitorHandler {
public class SxThirdPartyPlcCollectCellTaktMonitorHandler {
protected volatile Boolean isOpen = true;
@ -41,7 +41,7 @@ public class SxCellTaktMonitorHandler {
private StepResult stepResult;
public SxCellTaktMonitorHandler(String org, String key) {
public SxThirdPartyPlcCollectCellTaktMonitorHandler(String org, String key) {
this.org = org;
this.key = key;
initStepResult();
@ -63,7 +63,7 @@ public class SxCellTaktMonitorHandler {
stepResult = StepResult.getSuccessComplete().data(dataMap);
}
public SxCellTaktMonitorHandler isRetry(String[] plcCodeArr) {
public SxThirdPartyPlcCollectCellTaktMonitorHandler isRetry(String[] plcCodeArr) {
version ++;
if (isRetry) return this;
if (StringUtils.isEmpty(plcCode2Flag) || !plcCode2Flag.equals(plcCodeArr[0])) plcCode2Flag = null;

@ -37,9 +37,9 @@ public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCo
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY EXEC --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString());
if (!SxCellTaktDispatchSingleton.getIsInit()) SxCellTaktDispatchSingleton.getInstance();
if (!SxThirdPartyPlcCollectCellTaktDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectCellTaktDispatchSingleton.getInstance();
SxCellTaktDispatchSingleton.execMonitor(organizeCode, cfgMap);
SxThirdPartyPlcCollectCellTaktDispatchSingleton.execMonitor(organizeCode, cfgMap);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY END --- CFGMAP:{}", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT, cfgMap.toString());
@ -47,7 +47,7 @@ public class SxThirdPartyPlcCollectCellTaktService implements ISxThirdPartyPlcCo
private Boolean checkOrgIsStopMonitor(String organizeCode, String status) {
if (!StringUtils.isEmpty(status) && status.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr())) return false;
if (SxCellTaktDispatchSingleton.getIsInit()) SxCellTaktDispatchSingleton.execMonitor(organizeCode, null);
if (SxThirdPartyPlcCollectCellTaktDispatchSingleton.getIsInit()) SxThirdPartyPlcCollectCellTaktDispatchSingleton.execMonitor(organizeCode, null);
log.info("工厂{}第三方PLC数据采集 --- {} STRATEGY END --- MONITOR CLOSED COMPLETED ---", organizeCode, MesPcnExtConstWords.COLLECT_CELL_TAKT);
return true;
}

@ -0,0 +1,96 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.bean;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import java.io.Serializable;
/**
* @Author: wangjie
* @CreateDate: 2019/7/30 9:30 AM
* @Description:
**/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "MES_THIRD_PARTY_Db_COLLECT_DATA_RECORD", indexes = {
@Index(columnList = "SYSTEM_SYNC_STATUS"),
@Index(columnList = "CFG_CODE"),
@Index(columnList = "OBJECT_CODE")
})
@Api("第三方DB数据采集定时任务执行记录")
public class MesThirdPartyDbCollectDataRecord extends BaseBean implements Serializable {
private static final long serialVersionUID = -5811666058929378534L;
@Column(name = "SYSTEM_SYNC_STATUS")
@ColumnDefault("2")
@ApiParam(value = "系统同步标志")
public Integer systemSyncStatus = 2;
@Column(name = "CFG_CODE")
@ApiParam("配置代码")
private String cfgCode;
@Column(name = "OBJECT_CODE")
@ApiParam("对象代码")
private String objectCode;
@Lob
@Column(name = "CFG_VALUE")
@ApiParam("配置值")
private String cfgValue;
@Column(name = "RESULT")
@ApiParam("结果")
private Integer result;
@Column(name = "QTY")
@ApiParam("执行数量")
private Integer qty;
@Lob
@Column(name = "MESSAGE")
@ApiParam("信息")
private String message;
public MesThirdPartyDbCollectDataRecord() {}
public MesThirdPartyDbCollectDataRecord(String cfgCode, String objectCode, String cfgValue, Integer result, Integer qty, String message) {
this.cfgCode = cfgCode;
this.objectCode = objectCode;
this.cfgValue = cfgValue;
this.result = result;
this.qty = qty;
this.message = message;
}
public MesThirdPartyDbCollectDataRecord(String cfgCode, String objectCode, String cfgValue) {
this.cfgCode = cfgCode;
this.objectCode = objectCode;
this.cfgValue = cfgValue;
}
public MesThirdPartyDbCollectDataRecord(String cfgCode) {
this.cfgCode = cfgCode;
}
public String message(String message) {
this.result = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
this.qty = MesPcnExtConstWords.ZERO;
this.message = message;
return message;
}
}

@ -0,0 +1,267 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.model;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesDataObject;
import cn.estsh.i3plus.pojo.mes.bean.MesDatasource;
import cn.estsh.i3plus.pojo.mes.bean.MesObjectCfg;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
public class SxThirdPartyDbCollectDataModel implements Serializable {
private static final long serialVersionUID = -2147511121082046955L;
@ApiParam("过程条码拼接字段")
private String serialNumberArrField;
@ApiParam("产品条码拼接字段")
private String productSnArrField;
@ApiParam("动态反射字段 基于List<SxThirdPartyDbDynamicsFieldModel>的JSON数据")
private String dynamicsReflectField;
@ApiParam("动态表名 继承BaseBean的全路径Bean对象类名,同时需创建基于Bean对象的Repository类")
private String dynamicsTableName;
@ApiParam("固定字段写值 基于Map<String, Object>的JSON数据")
private String defaultValueField;
@ApiParam("业务自定义方法字段 基于Map<String, ISxThirdPartyDbCollectDataMethodService>的JSON数据")
private String methodField;
@ApiParam("第三方表名")
private String otherTableName;
@ApiParam("对等同步表名")
private String paritySyncTableName;
@ApiParam("对等同步数据库类型")
private String paritySyncDatabase;
@ApiParam("是否使用自增列")
private String isSelfAddition;
@ApiParam("排序字段")
private String orderField;
@ApiParam("查询数量")
private String limitRows;
@ApiParam("默认策略")
private Integer defaultStrategy;
@ApiParam("实现策略")
private String strategyClass;
@ApiParam("组织代码")
private String organizeCode;
@ApiParam("操作人")
private String userInfo;
@ApiParam("JOB配置代码")
private String cfgCode;
@ApiParam("对象代码")
private String objectCode;
@ApiParam("对象代码配置值")
private String cfgValue;
@ApiParam("是否使用自增列")
private Boolean isSelfAdditionBoo;
@ApiParam("执行步骤")
private Integer state;
@ApiParam("无额外验证")
private Boolean noExtraValidate;
@ApiParam("采集结果")
private Boolean execResult;
@ApiParam("错误信息")
private String error;
@ApiParam("执行数据量")
private Integer execSize;
@ApiParam("动态字段集合")
private List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList;
@ApiParam("地址清单")
private MesDatasource dataSource;
@ApiParam("数据对象")
private MesDataObject dataObject;
@ApiParam("对象结构")
private List<MesObjectCfg> objectCfgList;
@ApiParam("采集数据")
private List<Map<String, Object>> mapList;
@ApiParam("预留数据存储")
private Map<String, Object> dataMap;
public String checkValid() {
if (!StringUtils.isEmpty(this.defaultStrategy) && !StringUtils.isEmpty(MesPcnExtEnumUtil.SX_THIRD_PARTY_DB_COLLECT_DATA_STRATEGY.valueOfClazz(this.defaultStrategy)))
this.strategyClass = MesPcnExtEnumUtil.SX_THIRD_PARTY_DB_COLLECT_DATA_STRATEGY.valueOfClazz(this.defaultStrategy);
if (StringUtils.isEmpty(this.strategyClass)) return String.format("默认策略[%s]或自定义策略[%s]", MesPcnExtConstWords.DEFAULT_STRATEGY, MesPcnExtConstWords.STRATEGY_CLASS);
if (StringUtils.isEmpty(this.otherTableName)) return String.format("第三方表名[%s]", MesPcnExtConstWords.OTHER_TABLE_NAME);
if (StringUtils.isEmpty(this.isSelfAddition)) return String.format("是否使用自增列[%s]", MesPcnExtConstWords.IS_SELF_ADDITION);
if (StringUtils.isEmpty(this.orderField)) return String.format("排序字段[%s]", MesPcnExtConstWords.ORDER_FIELD);
return null;
}
public SxThirdPartyDbCollectDataModel organizeCode(String organizeCode) {
this.organizeCode = organizeCode;
return this;
}
public SxThirdPartyDbCollectDataModel userInfo(String userInfo) {
this.userInfo = userInfo;
return this;
}
public SxThirdPartyDbCollectDataModel cfgCode(String cfgCode) {
this.cfgCode = cfgCode;
return this;
}
public SxThirdPartyDbCollectDataModel objectCode(String objectCode) {
this.objectCode = objectCode;
return this;
}
public SxThirdPartyDbCollectDataModel cfgValue(String cfgValue) {
this.cfgValue = cfgValue;
return this;
}
public SxThirdPartyDbCollectDataModel paritySyncDatabase(String paritySyncDatabase) {
this.paritySyncDatabase = paritySyncDatabase;
return this;
}
public SxThirdPartyDbCollectDataModel noExtraValidate(Boolean noExtraValidate) {
this.noExtraValidate = noExtraValidate;
return this;
}
public SxThirdPartyDbCollectDataModel defaultValue() {
if (StringUtils.isEmpty(this.limitRows)) this.limitRows = MesPcnExtConstWords.LIMIT_ROWS_DEFAULT_100;
this.execSize = MesPcnExtConstWords.ZERO;
this.state = MesPcnExtConstWords.STATE_1;
this.noExtraValidate = true;
this.execResult = false;
return this;
}
public SxThirdPartyDbCollectDataModel dynamicsFieldList(List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList) {
this.dynamicsFieldList = dynamicsFieldList;
return this;
}
public SxThirdPartyDbCollectDataModel dataMap(String key, Object obj) {
if (CollectionUtils.isEmpty(this.dataMap)) this.dataMap = new HashMap<>();
this.dataMap.put(key, obj);
return this;
}
public SxThirdPartyDbCollectDataModel dataSource(MesDatasource dataSource) {
this.dataSource = dataSource;
return this;
}
public SxThirdPartyDbCollectDataModel dataObject(MesDataObject dataObject) {
this.dataObject = dataObject;
return this;
}
public SxThirdPartyDbCollectDataModel objectCfgList(List<MesObjectCfg> objectCfgList) {
this.objectCfgList = objectCfgList;
return this;
}
public SxThirdPartyDbCollectDataModel mapList(List<Map<String, Object>> mapList) {
this.mapList = mapList;
return this;
}
public String error(String error) {
this.error = error;
return error;
}
public void noError() {
this.error = null;
}
public SxThirdPartyDbCollectDataModel execSize(Integer execSize) {
this.execSize = execSize;
return this;
}
public SxThirdPartyDbCollectDataModel state(Integer state) {
this.state = state;
return this;
}
public SxThirdPartyDbCollectDataModel complete() {
this.state = MesPcnExtConstWords.ZERO;
this.execResult = true;
return this;
}
public static void main(String[] args) {
SxThirdPartyDbCollectDataModel model = new SxThirdPartyDbCollectDataModel();
model.setSerialNumberArrField("serial_number1");
model.setProductSnArrField("serial_number1");
List<SxThirdPartyDbDynamicsFieldModel> dynamicsFieldList = new ArrayList<>();
SxThirdPartyDbDynamicsFieldModel dynamicsField = new SxThirdPartyDbDynamicsFieldModel();
dynamicsField.setFieldName("物料编码");
dynamicsField.setSourceField("part_no1");
dynamicsField.setTargetField("part_no");
SxThirdPartyDbDynamicsFieldModel dynamicsField1 = new SxThirdPartyDbDynamicsFieldModel();
dynamicsField1.setFieldName("物料名称");
dynamicsField1.setSourceField("part_name_rdd1");
dynamicsField1.setTargetField("part_name_rdd");
dynamicsFieldList.add(dynamicsField);
dynamicsFieldList.add(dynamicsField1);
model.setDynamicsReflectField(JSONObject.toJSONString(dynamicsFieldList));
model.setDynamicsTableName("MesProduceSnThirdParty");
// model.setParitySyncTableName("mes_data_collect_test");
model.setOtherTableName("mes_data_collect_test0");
model.setIsSelfAddition("1");
model.setOrderField("id");
model.setDefaultStrategy(20);
Map<String, Object> defaultMap = new HashMap<>();
defaultMap.put("qcStatus", 10);
defaultMap.put("snStatus", 20);
model.setDefaultValueField(JSONObject.toJSONString(defaultMap));
Map<String, String> methodMap = new HashMap<>();
methodMap.put("date", "sxThirdPartyDbCollectDataMethodGetDateService");
model.setMethodField(JSONObject.toJSONString(methodMap));
System.out.println(JSONObject.toJSONString(model));
}
}

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.model;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import java.io.Serializable;
@Data
public class SxThirdPartyDbDynamicsFieldModel implements Serializable {
private static final long serialVersionUID = 870383113529370949L;
@ApiParam("源字段")
private String sourceField;
@ApiParam("目标字段")
private String targetField;
@ApiParam("字段名称")
private String fieldName;
}

@ -0,0 +1,15 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.repository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesThirdPartyDbCollectDataRecord;
import cn.estsh.i3plus.pojo.base.jpa.dao.BaseRepository;
import org.springframework.stereotype.Repository;
/**
* @author wangjie
* @version 1.0
* @date 2021/1/13 9:17
**/
@Repository
public interface MesThirdPartyDbCollectDataRecordRepository extends BaseRepository<MesThirdPartyDbCollectDataRecord, Long> {
}

@ -1035,4 +1035,47 @@ public class MesPcnExtConstWords {
//下线箱包二检工位参数配置
public static final String KEY_PART_RECHECK = "KEY_PART_RECHECK";
public static final String DEFAULT_STRATEGY = "defaultStrategy";
public static final String SERIAL_NUMBER_ARR_FIELD = "serialNumberArrField";
public static final String PRODUCT_SN_ARR_FIELD = "productSnArrField";
public static final String DYNAMICS_REFLECT_FIELD = "dynamicsReflectField";
public static final String METHOD_FIELD = "methodField";
public static final String DYNAMICS_TABLE_NAME = "dynamicsTableName";
public static final String PARITY_SYNC_TABLE_NAME = "paritySyncTableName";
public static final String OTHER_TABLE_NAME = "otherTableName";
public static final String IS_SELF_ADDITION = "isSelfAddition";
public static final String ORDER_FIELD = "orderField";
public static final String LIMIT_ROWS_DEFAULT_100 = "100";
public static final String Repository = "Repository";
public static final String FIELD_PK = "fieldPk";
public static final String FEED_FIELD = "feedField";
public static final String FEED_VALUE = "feedValue";
public static final String READ_FLAG_VALUE = "readFlagValue";
public static final String SELF_ADDITION = "selfAddition";
public static final String SELECT = " SELECT ";
public static final String SELECT_TOP = " SELECT TOP";
public static final String SELECT_ROWNUM = " SELECT rownum, ";
public static final String FROM = "FROM";
public static final String WHERE = " WHERE ";
public static final String WHERE_ROWNUM_GREATER_THAN = " WHERE rownum> ";
public static final String AND_SPACE = " AND ";
public static final String IS_NOT_NULL = " is not null";
public static final String NOT_EQ_EMPTY = " !='' ";
public static final String ORDER_BY = " ORDER BY ";
public static final String LIMIT = "LIMIT";
public static final String UPDATE = " UPDATE ";
public static final String SET = " SET ";
public static final String IN_LEFT = " in ( ";
public static final String IN_RIGHT = " ) ";
//1
public static final Integer STATE_1 = 1;
//2
public static final Integer STATE_2 = 2;
//3
public static final Integer STATE_3 = 3;
}

@ -4146,4 +4146,81 @@ public class MesPcnExtEnumUtil {
return tmp;
}
}
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum SX_THIRD_PARTY_DB_COLLECT_DATA_STRATEGY {
PRODUCT_DATA(10, "生产检测数据", "sxThirdPartyDbCollectDataStrategyProdDataService"),
DYNAMICS_REFLECT(20, "动态反射数据", "sxThirdPartyDbCollectDataStrategyDynamicsService"),
PARITY_SYNC(30, "对等同步数据", "sxThirdPartyDbCollectDataStrategyParitySyncService");
private int value;
private String description;
private String clazz;
SX_THIRD_PARTY_DB_COLLECT_DATA_STRATEGY(int value, String description, String clazz) {
this.value = value;
this.description = description;
this.clazz = clazz;
}
public int getValue() {
return this.value;
}
public String getDescription() {
return this.description;
}
public String getClazz() {
return this.clazz;
}
public static String valueOfClazz(int val) {
String tmp = null;
for (int i = 0; i < values().length; ++i) {
if (values()[i].value == val) {
tmp = values()[i].clazz;
}
}
return tmp;
}
}
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum SX_PARITY_SYNC_SQL_BUILDER_STRATEGY {
MYSQL("MYSQL", "sxThirdPartyDbParitySyncSqlBuilderMysqlService"),
SQL_SERVER("SQL_SERVER", "sxThirdPartyDbParitySyncSqlBuilderSqlServerService");
private String value;
private String clazz;
SX_PARITY_SYNC_SQL_BUILDER_STRATEGY(String value, String clazz) {
this.value = value;
this.clazz = clazz;
}
public String getValue() {
return this.value;
}
public String getClazz() {
return this.clazz;
}
public static String valueOfClazz(String val) {
String tmp = null;
for (int i = 0; i < values().length; ++i) {
if (values()[i].value.equals(val)) {
tmp = values()[i].clazz;
}
}
return tmp;
}
}
}

Loading…
Cancel
Save