|
|
|
|
package com.weaver.seconddev.tjzs.cronjob.job.baseDataSync;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.weaver.common.escheduler.handler.annotation.ESchedulerHandler;
|
|
|
|
|
import com.weaver.ebuilder.common.exception.BusinessException;
|
|
|
|
|
import com.weaver.ebuilder.form.client.entity.data.*;
|
|
|
|
|
import com.weaver.ebuilder.form.client.service.data.RemoteSimpleDataService;
|
|
|
|
|
import com.weaver.framework.rpc.annotation.RpcReference;
|
|
|
|
|
import com.weaver.framework.rpc.context.impl.TenantRpcContext;
|
|
|
|
|
import com.weaver.mc.util.StringUtils;
|
|
|
|
|
import com.weaver.seconddev.tjzs.cronjob.job.util.DataUtil;
|
|
|
|
|
import com.weaver.seconddev.tjzs.tb.config.EbDbDataSourceConfig;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
import org.apache.commons.configuration.ConfigurationException;
|
|
|
|
|
import org.apache.commons.configuration.PropertiesConfiguration;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* use:基础信息同步 区域
|
|
|
|
|
* author:liuhao
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@Component
|
|
|
|
|
public class SyncBaseInfoAreaJob {
|
|
|
|
|
@Autowired
|
|
|
|
|
private static JdbcTemplate jdbcTemplate = new JdbcTemplate(EbDbDataSourceConfig.dbDataSource());
|
|
|
|
|
//测试
|
|
|
|
|
static {
|
|
|
|
|
//根据表单配置获取同步方式。全量,天,月,年
|
|
|
|
|
String sql = "select timeperiodname as name,timeperiod as num from ec_base.uf_setdaymaindata";
|
|
|
|
|
Map<String, Object> map = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
String count = String.valueOf(map.get("num"));
|
|
|
|
|
code = Integer.parseInt(count);
|
|
|
|
|
}
|
|
|
|
|
private String quyuformid;
|
|
|
|
|
private String sysadminid;
|
|
|
|
|
private String tenantkey;
|
|
|
|
|
private String quyucode;
|
|
|
|
|
private String quyuareaorder;
|
|
|
|
|
private String quyuname;
|
|
|
|
|
private String quyuregionbelong;
|
|
|
|
|
private String quyusimplename;
|
|
|
|
|
private String quyuareaowner;
|
|
|
|
|
|
|
|
|
|
public SyncBaseInfoAreaJob() {
|
|
|
|
|
PropertiesConfiguration p = null;
|
|
|
|
|
try {
|
|
|
|
|
p = new PropertiesConfiguration();
|
|
|
|
|
p.setEncoding("utf-8");
|
|
|
|
|
p.setFileName("tjzssecond.properties");
|
|
|
|
|
p.load();
|
|
|
|
|
this.tenantkey = p.getString("tenantkey");
|
|
|
|
|
this.quyucode = p.getString("quyu.code");
|
|
|
|
|
this.quyuareaorder = p.getString("quyu.areaorder");
|
|
|
|
|
this.quyuname = p.getString("quyu.name");
|
|
|
|
|
this.quyuregionbelong = p.getString("quyu.regionbelong");
|
|
|
|
|
this.quyusimplename = p.getString("quyu.simplename");
|
|
|
|
|
this.quyuareaowner = p.getString("quyu.areaowner");
|
|
|
|
|
this.quyuformid=p.getString("quyu.formid");
|
|
|
|
|
this.sysadminid=p.getString("sysadminid");
|
|
|
|
|
}catch (ConfigurationException e) {
|
|
|
|
|
throw new BusinessException("获取tjzssecond.properties配置文件失败,", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int code;
|
|
|
|
|
|
|
|
|
|
@RpcReference(group = "ebuilderform")
|
|
|
|
|
private RemoteSimpleDataService remoteSimpleDataService;
|
|
|
|
|
|
|
|
|
|
@ESchedulerHandler(value = "syncBaseInfoAreaJob",cron = "0 0 0/4 * * ?")
|
|
|
|
|
public void syncProjectPostJob() {
|
|
|
|
|
log.error("更新区域信息启动...");
|
|
|
|
|
Map<String, Object> datajson = new HashMap<>();
|
|
|
|
|
//通过接口获取区域信息,全量获取,动态分页
|
|
|
|
|
DataUtil dataUtil = new DataUtil();
|
|
|
|
|
//获取总页数,总条数
|
|
|
|
|
String tmpData = dataUtil.syncData(1, code, "区域信息");
|
|
|
|
|
log.error("获取区域信息返回报文:{}",tmpData);
|
|
|
|
|
if (!StringUtils.isBlank(tmpData)) {
|
|
|
|
|
JSONObject obj = JSONObject.parseObject(tmpData);
|
|
|
|
|
boolean suc = (boolean) obj.get("Success");
|
|
|
|
|
if (suc) {
|
|
|
|
|
int pageNum;
|
|
|
|
|
JSONObject pageObj = obj.getJSONObject("Page");
|
|
|
|
|
int totalNumber = pageObj.getIntValue("TotalNumber");
|
|
|
|
|
int pageSize = pageObj.getIntValue("PageSize");
|
|
|
|
|
if (totalNumber % pageSize == 0) {
|
|
|
|
|
pageNum = totalNumber / pageSize;
|
|
|
|
|
} else {
|
|
|
|
|
pageNum = totalNumber / pageSize + 1;
|
|
|
|
|
}
|
|
|
|
|
//开始分页
|
|
|
|
|
for (int i = 1; i <= pageNum; i++) {
|
|
|
|
|
tmpData = dataUtil.syncData(i, code, "区域信息");
|
|
|
|
|
JSONObject resdata = JSONObject.parseObject(tmpData);
|
|
|
|
|
JSONArray data = resdata.getJSONArray("Data");
|
|
|
|
|
if (data != null && data.size() > 0) {
|
|
|
|
|
List<EBDataReqDto> mainDatas = new ArrayList<>();
|
|
|
|
|
for (int a = 0; a < data.size(); a++) {
|
|
|
|
|
JSONObject dataobj = data.getJSONObject(a);
|
|
|
|
|
String MemberCode = dataobj.getString("MemberCode");
|
|
|
|
|
String MemberName = dataobj.getString("MemberName");
|
|
|
|
|
Map<String, String> smallarray = getValueByNameArea(dataobj.getJSONArray("MemberAttributes"));
|
|
|
|
|
String AeraCom_SimpleName =smallarray.containsKey("AeraCom_SimpleName")? smallarray.get("AeraCom_SimpleName") : "";
|
|
|
|
|
String AeraCom_OwnerGroup = smallarray.containsKey("AeraCom_OwnerGroup")? smallarray.get("AeraCom_OwnerGroup"): "";
|
|
|
|
|
// String AeraCom_OwnerGroup="ceshi";
|
|
|
|
|
String AeraCom_Order = smallarray.containsKey("AeraCom_Order")? smallarray.get("AeraCom_Order"): "";
|
|
|
|
|
String AeraCom_RegionBelong = smallarray.containsKey("AeraCom_RegionBelong")? smallarray.get("AeraCom_RegionBelong"): "";
|
|
|
|
|
//根据AeraCom_Order反查人员id,如果存在,执行,不存在,本条记录不做处理
|
|
|
|
|
String sql = "select count(id) as nums from eteams.employee where job_num = '"+AeraCom_OwnerGroup+"'";
|
|
|
|
|
log.error("howec111:{}",sql);
|
|
|
|
|
Map<String, Object> rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
String userid = "";
|
|
|
|
|
long nums = (long) rs.get("nums");
|
|
|
|
|
if(nums==1l) {
|
|
|
|
|
sql = "select id from eteams.employee where job_num = '"+AeraCom_OwnerGroup+"'";
|
|
|
|
|
log.error("howec222:{}",sql);
|
|
|
|
|
rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
userid = String.valueOf(rs.get("id"));
|
|
|
|
|
}
|
|
|
|
|
//根据MemberCode判断是否更新
|
|
|
|
|
String id = "yongyuanbucunzaiid";//如果是新增,则传一个数据库永远不存在的id
|
|
|
|
|
sql = "select count(id) as nums from uf_region_tripartite where code = '" + MemberCode + "'";
|
|
|
|
|
rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
nums = (long) rs.get("nums");
|
|
|
|
|
if (nums > 0l) {
|
|
|
|
|
sql = "select id from uf_region_tripartite where code = '" + MemberCode + "'";
|
|
|
|
|
log.error("howec333:{}",sql);
|
|
|
|
|
rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
id = String.valueOf(rs.get("id"));
|
|
|
|
|
}
|
|
|
|
|
//数据拼接
|
|
|
|
|
EBDataReqDto ebDataReqDto = new EBDataReqDto();
|
|
|
|
|
List<EBDataReqDetailDto> singledata = Lists.newArrayList();
|
|
|
|
|
singledata.add(new EBDataReqDetailDto("id", id));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyucode, MemberCode));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyuareaorder, AeraCom_Order));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyuname, MemberName));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyuregionbelong, AeraCom_RegionBelong));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyusimplename, AeraCom_SimpleName));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(quyuareaowner, userid));//人员code转换为系统人员id
|
|
|
|
|
ebDataReqDto.setMainDatas(singledata);
|
|
|
|
|
mainDatas.add(ebDataReqDto);
|
|
|
|
|
log.error("howec:::::::::id:{},quyucode:{},quyuareaorder:{},quyuname:{},quyuregionbelong:{},quyusimplename:{},quyuareaowner:{}",id,MemberCode,AeraCom_Order,MemberName,AeraCom_RegionBelong,AeraCom_SimpleName,userid);
|
|
|
|
|
}
|
|
|
|
|
//保存
|
|
|
|
|
if(CollectionUtil.isNotEmpty(mainDatas)) {
|
|
|
|
|
saveEb(mainDatas,quyuformid);
|
|
|
|
|
}else {
|
|
|
|
|
log.error("howec无符合数据");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* eb表单保存
|
|
|
|
|
* 括号内由EB组装转换生成, 括号外更新由表单引擎执行
|
|
|
|
|
*/
|
|
|
|
|
private void saveEb(List<EBDataReqDto> datas,String formid) {
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
String jsonString = gson.toJson(datas);
|
|
|
|
|
log.error("howec:::tenantkey:{}",tenantkey);
|
|
|
|
|
log.error("howec:::sysadminid:{}",sysadminid);
|
|
|
|
|
log.error("howec:::jsons:{}",jsonString);
|
|
|
|
|
//二开免登陆的方式,设置租户
|
|
|
|
|
TenantRpcContext.setTargetTenantKey(tenantkey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EBDataChangeReqDto ebDataChangeReqDto = new EBDataChangeReqDto();
|
|
|
|
|
// 构建基础参数; objId 表单id, operator 操作人, tenantKey 租户
|
|
|
|
|
ebDataChangeReqDto.setHeader(new EBDataReqHeader(formid, sysadminid, tenantkey));
|
|
|
|
|
EBDataReqOperation ebDataReqOperation = new EBDataReqOperation();
|
|
|
|
|
ebDataReqOperation.setUpdateType(EBDataUpdateType.ids);
|
|
|
|
|
EBDataReqOperationInfo ebDataReqOperationInfo = new EBDataReqOperationInfo();
|
|
|
|
|
ebDataReqOperationInfo.setNeedAdd(true);
|
|
|
|
|
ebDataReqOperation.setMainData(ebDataReqOperationInfo);
|
|
|
|
|
ebDataChangeReqDto.setOperation(ebDataReqOperation);
|
|
|
|
|
ebDataChangeReqDto.setDatas(datas);
|
|
|
|
|
EBDataChangeResult ebDataChangeResult = remoteSimpleDataService.updateFormData(ebDataChangeReqDto);
|
|
|
|
|
log.error("批量更新/新增eb-uf_region_tripartite返回值:"+ebDataChangeResult.getMessage());
|
|
|
|
|
log.error("批量更新/新增eb-uf_region_tripartite返回值:"+ebDataChangeResult.getStatus());
|
|
|
|
|
log.error("批量更新/新增eb-uf_region_tripartite返回值:"+ebDataChangeResult.getDataIds().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String,String> getValueByNameArea(JSONArray jsonArray) {
|
|
|
|
|
if(jsonArray == null || jsonArray.size() == 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Map<String,String> map = new HashMap<>();
|
|
|
|
|
for(int i = 0 ;i < jsonArray.size(); i++) {
|
|
|
|
|
JSONObject obj1 = jsonArray.getJSONObject(i);
|
|
|
|
|
String name1 = obj1.getString("Name");
|
|
|
|
|
if("String".equals(obj1.getString("ValueType"))) {
|
|
|
|
|
map.put(name1,obj1.getString("Value"));
|
|
|
|
|
}
|
|
|
|
|
if("Domain".equals(obj1.getString("ValueType"))) {
|
|
|
|
|
JSONObject v2 = obj1.getJSONObject("Value");
|
|
|
|
|
String code = v2.getString("Code");
|
|
|
|
|
map.put(name1,code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
}
|