|
|
|
@ -0,0 +1,244 @@
|
|
|
|
|
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 SyncBaseInfoCityJob {
|
|
|
|
|
@Autowired
|
|
|
|
|
private static JdbcTemplate jdbcTemplate = new JdbcTemplate(EbDbDataSourceConfig.dbDataSource());
|
|
|
|
|
|
|
|
|
|
private static String transactionId = "D3640368-7615-426B-91DE-DF6367683DDD";
|
|
|
|
|
|
|
|
|
|
//测试
|
|
|
|
|
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 provinceformid;
|
|
|
|
|
private String cityformid;
|
|
|
|
|
private String sysadminid;
|
|
|
|
|
private String tenantkey;
|
|
|
|
|
private String prov_name;
|
|
|
|
|
private String prov_code;
|
|
|
|
|
private String city_mc;
|
|
|
|
|
private String city_sss;
|
|
|
|
|
private String city_bm;
|
|
|
|
|
public SyncBaseInfoCityJob() {
|
|
|
|
|
PropertiesConfiguration p = null;
|
|
|
|
|
try {
|
|
|
|
|
p = new PropertiesConfiguration();
|
|
|
|
|
p.setEncoding("utf-8");
|
|
|
|
|
p.setFileName("tjzssecond.properties");
|
|
|
|
|
p.load();
|
|
|
|
|
this.tenantkey = p.getString("tenantkey");
|
|
|
|
|
this.provinceformid = p.getString("province.formid");
|
|
|
|
|
this.cityformid = p.getString("city.formid");
|
|
|
|
|
this.prov_name = p.getString("province.prov_name");
|
|
|
|
|
this.prov_code = p.getString("province.prov_code");
|
|
|
|
|
this.city_mc = p.getString("city.mc");
|
|
|
|
|
this.city_sss = p.getString("city.sss");
|
|
|
|
|
this.city_bm = p.getString("city.bm");
|
|
|
|
|
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 = "syncBaseInfoCityProvinceJob",cron = "0 0 0/4 * * ?")
|
|
|
|
|
public void syncCountryInfoJob() {
|
|
|
|
|
log.error("更新省份,城市信息启动...");
|
|
|
|
|
Map<String, Object> datajson = new HashMap<>();
|
|
|
|
|
//通过接口获取区域信息,全量获取,动态分页
|
|
|
|
|
DataUtil dataUtil = new DataUtil();
|
|
|
|
|
//获取总页数,总条数
|
|
|
|
|
String tmpData = dataUtil.syncDataPro(1, code, "县级以上行政区划","参考数据",transactionId);
|
|
|
|
|
|
|
|
|
|
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.syncDataPro(i, code, "县级以上行政区划","参考数据",transactionId);
|
|
|
|
|
JSONObject resdata = JSONObject.parseObject(tmpData);
|
|
|
|
|
JSONArray data = resdata.getJSONArray("Data");
|
|
|
|
|
if (data != null && data.size() > 0) {
|
|
|
|
|
List<EBDataReqDto> mainDatasProvince = new ArrayList<>();//省级集合
|
|
|
|
|
List<EBDataReqDto> mainDatasCity = 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");
|
|
|
|
|
JSONArray attributeArray = dataobj.getJSONArray("MemberAttributes");
|
|
|
|
|
if(getParentName(attributeArray,"省级")!=null) {
|
|
|
|
|
//根据MemberCode判断是否更新
|
|
|
|
|
String id = "yongyuanbucunzaiid";//如果是新增,则传一个数据库永远不存在的id
|
|
|
|
|
String sql = "select count(id) as nums from uf_province where prov_code = '" + MemberCode + "'";
|
|
|
|
|
Map<String, Object> rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
long nums = (long) rs.get("nums");
|
|
|
|
|
if (nums > 0l) {
|
|
|
|
|
sql = "select id from uf_province where prov_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(prov_code, MemberCode));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(prov_name, MemberName));
|
|
|
|
|
ebDataReqDto.setMainDatas(singledata);
|
|
|
|
|
mainDatasProvince.add(ebDataReqDto);
|
|
|
|
|
log.error("howec1:::::::::id:{},cntyname:{},cntycode:{}",id,MemberCode,MemberName);
|
|
|
|
|
}
|
|
|
|
|
Map<String ,String> rsmap = getParentName(attributeArray,"地级");
|
|
|
|
|
if(rsmap!=null) {
|
|
|
|
|
String parentName = rsmap.get("parent");
|
|
|
|
|
//根据MemberCode判断是否更新
|
|
|
|
|
String id = "yongyuanbucunzaiid";//如果是新增,则传一个数据库永远不存在的id
|
|
|
|
|
String sql = "select count(id) as nums from uf_city where bm = '" + MemberCode + "'";
|
|
|
|
|
Map<String, Object> rs = jdbcTemplate.queryForMap(sql);
|
|
|
|
|
long nums = (long) rs.get("nums");
|
|
|
|
|
if (nums > 0l) {
|
|
|
|
|
sql = "select id from uf_city where bm = '" + 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(city_mc, MemberName));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(city_sss, parentName));
|
|
|
|
|
singledata.add(new EBDataReqDetailDto(city_bm, MemberCode));
|
|
|
|
|
ebDataReqDto.setMainDatas(singledata);
|
|
|
|
|
mainDatasCity.add(ebDataReqDto);
|
|
|
|
|
log.error("howec1:::::::::id:{},cntyname:{},cntycode:{}",id,MemberCode,MemberName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//省级保存
|
|
|
|
|
if(CollectionUtil.isNotEmpty(mainDatasProvince)) {
|
|
|
|
|
saveEb(mainDatasProvince,provinceformid);
|
|
|
|
|
}else {
|
|
|
|
|
log.error("howec省级无符合数据");
|
|
|
|
|
}
|
|
|
|
|
//市级保存
|
|
|
|
|
if(CollectionUtil.isNotEmpty(mainDatasCity)) {
|
|
|
|
|
saveEb(mainDatasCity,cityformid);
|
|
|
|
|
}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("批量更新/新增省、市返回值:"+ebDataChangeResult.getMessage());
|
|
|
|
|
log.error("批量更新/新增省、市返回值:"+ebDataChangeResult.getStatus());
|
|
|
|
|
log.error("批量更新/新增省、市返回值:"+ebDataChangeResult.getDataIds().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String,String> getParentName(JSONArray jsonArray,String level) {
|
|
|
|
|
if(jsonArray == null || jsonArray.size() == 0) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Boolean flag = false;
|
|
|
|
|
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("Level".equals(name1)) {
|
|
|
|
|
JSONObject levelObjvalue = obj1.getJSONObject("Value");
|
|
|
|
|
String namej = levelObjvalue.getString("Name");
|
|
|
|
|
if(level.equals(namej)) {
|
|
|
|
|
flag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if("Parent".equals(name1)) {
|
|
|
|
|
map.put("parent",obj1.getString("Value"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(flag) {
|
|
|
|
|
return map;
|
|
|
|
|
}else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|