Merge branch 'yuecheng-project' of http://192.168.2.237:3000/root/kangarooDataCenterV3 into yuecheng-project
This commit is contained in:
commit
5a49f04d96
|
@ -0,0 +1,19 @@
|
|||
package com.hzya.frame.sysnew.comparison.masterData.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.basedao.service.IBaseService;
|
||||
import com.hzya.frame.sysnew.comparison.entity.ComparisonEntity;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
|
||||
public interface IMasterDataService extends IBaseService<ComparisonEntity, String> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @content 查询经过配置的主数据信息进行同步主数据档案接口
|
||||
* @author laborer
|
||||
* @date 2024/6/24 0024 9:34
|
||||
*
|
||||
*/
|
||||
|
||||
JsonResultEntity queryArchives(JSONObject jsonObject);
|
||||
}
|
|
@ -0,0 +1,194 @@
|
|||
package com.hzya.frame.sysnew.comparison.masterData.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.basedao.service.impl.BaseService;
|
||||
import com.hzya.frame.dateutil.DateUtil;
|
||||
import com.hzya.frame.mdm.mdmModuleSource.dao.impl.MdmModuleSourceDaoImpl;
|
||||
import com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity;
|
||||
import com.hzya.frame.sysnew.comparison.entity.ComparisonEntity;
|
||||
import com.hzya.frame.sysnew.comparison.masterData.dao.impl.MasterDataDaoImpl;
|
||||
import com.hzya.frame.sysnew.comparison.masterData.service.IMasterDataProjectService;
|
||||
import com.hzya.frame.sysnew.comparison.masterData.service.IMasterDataService;
|
||||
import com.hzya.frame.sysnew.comparison.service.impl.ComparisonServiceImpl;
|
||||
import com.hzya.frame.web.entity.BaseResult;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Service("MasterDataServiceImpl")
|
||||
public class MasterDataServiceImpl extends BaseService<ComparisonEntity, String> implements IMasterDataService {
|
||||
|
||||
@Autowired
|
||||
private MasterDataDaoImpl masterDataDaoImpl;
|
||||
@Autowired
|
||||
private ComparisonServiceImpl comparisonServiceimpl;
|
||||
@Autowired
|
||||
private MdmModuleSourceDaoImpl mdmModuleSourceDaoImpl;
|
||||
|
||||
private String ts = "";
|
||||
|
||||
/**
|
||||
*
|
||||
* @content 查询经过配置的主数据信息进行同步主数据档案接口
|
||||
* @author laborer
|
||||
* @date 2024/6/24 0024 9:56
|
||||
*
|
||||
*/
|
||||
|
||||
@Override
|
||||
public JsonResultEntity queryArchives(JSONObject json){
|
||||
JSONObject jsonObject = json.getJSONObject("jsonStr");
|
||||
//查询主数据来源表,根据来源类型为插件得进行分类,获取来源名称和编码
|
||||
List<MdmModuleSourceEntity> list = mdmModuleSourceDaoImpl.MdmModuleSourceentityGroupByType();
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
logger.info("数据来源表中没有类型为插件得数据,无法获取来源名称和来源编码");
|
||||
return BaseResult.getFailureMessageEntity("数据来源表无插件类型");
|
||||
}
|
||||
for (MdmModuleSourceEntity mdmModuleSourceEntity : list) {
|
||||
try {
|
||||
//通过不同的应用类型用于拼接sql
|
||||
String appTyp = mdmModuleSourceEntity.getAppType();
|
||||
String dbCode = mdmModuleSourceEntity.getDbCode();
|
||||
String mdmCode = mdmModuleSourceEntity.getMdmCode();
|
||||
List<HashMap<String, Object>>hashMaps = new ArrayList<>();
|
||||
List<HashMap<String, Object>> hashMapsDetails = new ArrayList<>();
|
||||
switch (appTyp) {//1、致远OA 2、用友U8C 3、用友BIP
|
||||
case "1":
|
||||
//通过主数据编码判断,不同的接口走不通的查询逻辑
|
||||
switch (mdmCode){
|
||||
case "10003"://致远用户信息
|
||||
bindingUser(jsonObject, mdmModuleSourceEntity, dbCode);
|
||||
break;
|
||||
case "10004"://致远客商信息
|
||||
hashMaps = binDingCust(jsonObject, mdmModuleSourceEntity, dbCode);
|
||||
//查询明细数据
|
||||
for (HashMap<String, Object> hashMap : hashMaps) {
|
||||
//查询明细信息
|
||||
Long formmainId = (Long) hashMap.get("id");
|
||||
StringBuffer stringBufferDetails = new StringBuffer();
|
||||
stringBufferDetails.append("SELECT field0023 AS pk_bankdoc,field0024 AS accnum,field0025 AS combinenum FROM formson_0229 WHERE formmain_id = '"+formmainId+"' " );
|
||||
hashMapsDetails = masterDataDaoImpl.queryArchivesByDataSource(stringBufferDetails.toString(),mdmModuleSourceEntity);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
logger.info("未匹配到主数据的编码,请检查");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//调用主数据接口进行数据推送或更新
|
||||
if (null != hashMaps && hashMaps.size() > 0) {
|
||||
ParametricAssembly(mdmModuleSourceEntity,hashMaps,mdmCode,hashMapsDetails);
|
||||
} else {
|
||||
logger.info("U8C主数据档案没有需要同步中台的数据");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("主数据同步错误:{}",e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return BaseResult.getSuccessMessageEntity("项目档案同步成功");
|
||||
}
|
||||
//绑定客户档案
|
||||
private List<HashMap<String, Object>> binDingCust(JSONObject jsonObject, MdmModuleSourceEntity mdmModuleSourceEntity, String dbCode) {
|
||||
List<HashMap<String, Object>> hashMap;
|
||||
StringBuffer sbCust = new StringBuffer();
|
||||
if(null != jsonObject && StrUtil.isNotEmpty(jsonObject.getString("code"))){
|
||||
String code = jsonObject.getString("code");
|
||||
sbCust.append(" and a.code = '"+code+"'");
|
||||
}else{
|
||||
ts = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
sbCust.append(" and a.update_time >= '"+ts+"'");
|
||||
}
|
||||
StringBuffer stringBufferCust = new StringBuffer();
|
||||
stringBufferCust.append("SELECT id as id,field0013 AS code,field0014 AS name,field0016 AS pk_custclass,field0015 AS shortname,field0012 AS pk_org FROM formmain_0226 WHERE 1=1 "+ sbCust.toString());
|
||||
mdmModuleSourceEntity.setDataSourceCode(dbCode);
|
||||
return masterDataDaoImpl.queryArchivesByDataSource(stringBufferCust.toString(),mdmModuleSourceEntity);
|
||||
}
|
||||
|
||||
//绑定OA用户参数
|
||||
private JSONArray bindingUser(JSONObject jsonObject, MdmModuleSourceEntity mdmModuleSourceEntity, String dbCode) {
|
||||
StringBuffer sbUser = new StringBuffer();
|
||||
if(null != jsonObject && StrUtil.isNotEmpty(jsonObject.getString("code"))){
|
||||
String code = jsonObject.getString("code");
|
||||
sbUser.append(" and a.code = '"+code+"'");
|
||||
}else{
|
||||
ts = DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
sbUser.append(" and a.update_time >= '"+ts+"'");
|
||||
}
|
||||
StringBuffer stringBufferUser = new StringBuffer();
|
||||
stringBufferUser.append("SELECT id as id,field0013 AS code,field0014 AS name,field0016 AS pk_custclass,field0015 AS shortname,field0012 AS pk_org FROM formmain_0226 WHERE 1=1 "+ sbUser.toString());
|
||||
mdmModuleSourceEntity.setDataSourceCode(dbCode);
|
||||
List<HashMap<String, Object>> hashMaps = masterDataDaoImpl.queryArchivesByDataSource(stringBufferUser.toString(),mdmModuleSourceEntity);
|
||||
for (HashMap<String, Object> hashMap : hashMaps) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//查询档案参数组装
|
||||
public JsonResultEntity ParametricAssembly(MdmModuleSourceEntity mdmModuleSourceEntity,List<HashMap<String, Object>> hashMaps,String mdmCode,List<HashMap<String, Object>> hashMapsDetails){
|
||||
for (HashMap<String, Object> hashMap : hashMaps) {
|
||||
JSONObject jsonObjectUser = new JSONObject();
|
||||
JSONObject jsonStr = new JSONObject();
|
||||
jsonObjectUser.put("id", hashMap.get("id"));
|
||||
jsonObjectUser.put("mdmCode", mdmCode);
|
||||
jsonStr.put("jsonStr", jsonObjectUser);
|
||||
//先查询编码和名称查询是否存在
|
||||
JsonResultEntity jsonResultEntity = comparisonServiceimpl.queryEntityPage(jsonStr);
|
||||
Object attribute = jsonResultEntity.getAttribute();
|
||||
logger.info("得到的attribute值为:{}", attribute);
|
||||
JSONObject jsonObjectAttribute = (JSONObject) JSON.toJSON(attribute);
|
||||
JSONArray jsonArrayList = jsonObjectAttribute.getJSONArray("list");
|
||||
//如果jsonArrayList为null,说明没有值,在表中不存在
|
||||
if (jsonArrayList == null || jsonArrayList.size() == 0) {
|
||||
//将查询出来得数据调用通用接口新增,保存到表中
|
||||
JSONObject main = new JSONObject();
|
||||
for(String key:hashMap.keySet()) {
|
||||
main.put(key, hashMap.get(key));
|
||||
}
|
||||
jsonObjectUser.put("main", main);
|
||||
jsonObjectUser.put("appName","数智中台");
|
||||
jsonObjectUser.put("appCode","800004");
|
||||
jsonObjectUser.put("optionName", "数智中台");
|
||||
jsonStr.put("jsonStr", jsonObjectUser);
|
||||
try {
|
||||
comparisonServiceimpl.saveEntity(jsonStr);
|
||||
} catch (Exception e) {
|
||||
logger.info("U8C主数据档案新增用户档案失败,失败原因:{}",e.getMessage());
|
||||
}
|
||||
} else {
|
||||
for (Object o : jsonArrayList) {
|
||||
JSONObject jsonObjectUpdate = JSON.parseObject(String.valueOf(o));
|
||||
String id = jsonObjectUpdate.getString("id");
|
||||
JSONObject main = new JSONObject();
|
||||
for(String key:hashMap.keySet()) {
|
||||
main.put(key, hashMap.get(key));
|
||||
main.put("id",id);
|
||||
}
|
||||
jsonObjectUser.put("main", main);
|
||||
jsonObjectUser.put("appName","数智中台");
|
||||
jsonObjectUser.put("appCode","800004");
|
||||
jsonObjectUser.put("optionName", "数智中台");
|
||||
jsonStr.put("jsonStr", jsonObjectUser);
|
||||
try {
|
||||
comparisonServiceimpl.updateEntity(jsonStr);
|
||||
} catch (Exception e) {
|
||||
logger.info("U8C主数据档案更新用户档案失败,失败原因:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue