文件备份---何朝阳

jingwei
chaoyang.he 2023-05-17 10:29:15 +08:00
parent f2b938e668
commit 0e2e6325f3
16 changed files with 826 additions and 0 deletions

View File

@ -0,0 +1,43 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.controller;
import aiyh.utils.Util;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherOtherSystemInfoService;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl.GMGatherOtherSystemInfoServiceImpl;
import weaver.interfaces.schedule.BaseCronJob;
/**
* <h1>GMGM</h1>
* @author hcy
* @date 2023/5/9 13:56
*/
public class GMGatherOtherSystemInfoController extends BaseCronJob {
//日志处理
private final Logger logger = Util.getLogger();
private final GMGatherOtherSystemInfoService gmgatherOtherSystemInfoService = (GMGatherOtherSystemInfoService) new GMGatherOtherSystemInfoServiceImpl();
//同步标准0 同步全量数据 1 同步前一天的数据
public String syncStandard;
//GM集团获取GM集团下级单位的url
public String URL;
//GM集团数据库表名
public String formTableNameGM;
public void execute() {
try {
boolean insertDataBool = gmgatherOtherSystemInfoService.insertDataIntoGM(syncStandard,URL,formTableNameGM);
if (insertDataBool){
logger.info("GM集团获取GM集团下级单位合同台账信息执行成功");
}else {
logger.error("GM集团获取GM集团下级单位合同台账信息执行失败");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,15 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.controller;
import weaver.interfaces.schedule.BaseCronJob;
/**
* <h1>GM</h1>
* @author hcy
* @date 2023/5/9 18:20
*/
public class GMGatherSMInfoController extends BaseCronJob {
public void execute() {
}
}

View File

@ -0,0 +1,39 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.controller;
import aiyh.utils.Util;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherSameSystemInfoService;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl.GMGatherSameSystemInfoServiceImpl;
import weaver.interfaces.schedule.BaseCronJob;
/**
* <h1>GMGM使GM</h1>
* @author hcy
* @date 2023/5/9 17:16
*/
public class GMGatherSameSystemInfoController extends BaseCronJob {
//业务主要逻辑
private final GMGatherSameSystemInfoService gmgatherSameSystemInfoService = (GMGatherSameSystemInfoService) new GMGatherSameSystemInfoServiceImpl();
//日志处理
private final Logger logger = Util.getLogger();
//配置表主表名称
public String configurationMainTableName;
//配置表明细表1名称
public String configurationDetailTableName1;
//配置表明细表2名称
public String configurationDetailTableName2;
//唯一标识
public String uniqueIdentification;
public void execute() {
gmgatherSameSystemInfoService.dealMainLogic(configurationMainTableName,configurationDetailTableName1,configurationDetailTableName2,uniqueIdentification);
}
}

View File

@ -0,0 +1,14 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
@SqlMapper
public interface GMGatherOtherSystemInfoMapper {
@Select("insert into $t{formTableNameGM} $t{keys} value $t{values}")
boolean insertData(@ParamMapper("formTableNameGM") String formTableNameGM,
@ParamMapper("keys") String keys,
@ParamMapper("values") String values);
}

View File

@ -0,0 +1,7 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper;
import aiyh.utils.annotation.recordset.SqlMapper;
@SqlMapper
public class GMGatherSMInfoMapper {
}

View File

@ -0,0 +1,37 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import java.util.List;
import java.util.Map;
@SqlMapper
public interface GMGatherSameSystemInfoMapper {
@Select("select * from #{configurationMainTableName} where wybs = #{uniqueIdentification}")
List<Map<String, Object>> getConfigInformation(@ParamMapper("configurationMainTableName") String configurationMainTableName,
@ParamMapper("uniqueIdentification") String uniqueIdentification);
@Select("select * from #{configurationDetailTableName1} where mainid = #{mainid}")
List<Map<String, Object>> getConfigDetal1Information(@ParamMapper("configurationDetailTableName1")String configurationDetailTableName1,
@ParamMapper("mainid")String mainid);
@Select("select * from #{configurationDetailTableName2} where mainid = #{mainid}")
List<Map<String, Object>> getConfigDetal2Information(@ParamMapper("configurationDetailTableName2")String configurationDetailTableName2,
@ParamMapper("mainid")String mainid);
@Select("select * from #{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)")
List<Map<String, Object>> getSMCountLowGroupdata(@ParamMapper("ejdwtzb_name")String ejdwtzb_name,
@ParamMapper("yesterday")String yesterday);
@Select("select * from #{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)")
List<Map<String, Object>> getSMCountLowGroupDataUpdate(@ParamMapper("ejdwtzb_name")String ejdwtzb_name,
@ParamMapper("yesterday")String yesterday);
@Select("select * from #{jttzbd} where htbm = #{htbm}")
List<Map<String, Object>> selectHtbmData(@ParamMapper("jttzbd")String jttzbd,
@ParamMapper("htbm")String htbm);
}

View File

@ -0,0 +1,6 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service;
public interface GMGatherOtherSystemInfoService {
boolean insertDataIntoGM(String syncStandard, String url,String formTableNameGM);
}

View File

@ -0,0 +1,4 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service;
public interface GMGatherSMInfoService {
}

View File

@ -0,0 +1,5 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service;
public interface GMGatherSameSystemInfoService {
void dealMainLogic(String configurationMainTableName, String configurationDetailTableName1, String configurationDetailTableName2, String uniqueIdentification);
}

View File

@ -0,0 +1,101 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl;
import aiyh.utils.Util;
import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.wbi.util.StringUtil;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper.GMGatherOtherSystemInfoMapper;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherOtherSystemInfoService;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemInfoService {
//日志处理
private final Logger logger = Util.getLogger();
//sql
private final GMGatherOtherSystemInfoMapper gmGatherOtherSystemInfoMapper = Util.getMapper(GMGatherOtherSystemInfoMapper.class);
public boolean insertDataIntoGM(String syncStandard, String URL,String formTableNameGM) {
try {
if (StringUtil.isNotBlank(syncStandard) && "0".equals(syncStandard)){
//连接GM下级单位暴露的接口获取台账所有的数据
this.getEntityInsertDB(syncStandard,URL,formTableNameGM);
}else if (StringUtil.isNotBlank(syncStandard) && "1".equals(syncStandard)){
//连接GM下级单位暴露的接口获取前一天的数据
this.getEntityInsertDB(syncStandard,URL,formTableNameGM);
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public boolean getEntityInsertDB(String syncStandard, String URL,String formTableNameGM) {
try {
ResponeVo responeVo = getEntityMap(syncStandard, URL);
int code = responeVo.getCode();
if (code != 200) {
logger.info("对方接口状态码为:" + code + " 程序执行错误");
return false;
}
Map<String, Object> entityMap = responeVo.getResponseMap();
// Map<String, Object> entityMap = responeVo.getEntityMap();
// logger.info("接口返回的参数如下===" + entityMap);
List<Map<String,Object>> datas = (List<Map<String,Object>>) entityMap.get("data");
if (datas.isEmpty()) return false;//数据为空返回:数据为空
int num = 0;
// Map<String, Object> totalDataMap = new HashMap<>();
for (Map<String,Object> totalDataMap : datas) {
// totalDataMap = (Map<String, Object>) data;//主要数据
String keys = "(";
String values = "(";
for (Map.Entry<String, Object> entry : totalDataMap.entrySet()) {
String k = entry.getKey();
String v = Util.null2String(entry.getValue());
keys += k + ",";
values += v + ",";
}
keys = keys.substring(0, keys.length() - 1) + ")";
values = values.substring(0, values.length() - 1) + ")";
//todo:数据插入之前需要先进行数据校验
//todo:改一下这个sql
boolean insertDataDataBool = gmGatherOtherSystemInfoMapper.insertData(formTableNameGM, keys, values);
if (!insertDataDataBool) {
num++;
logger.info("数据同步失败第" + num + "次");
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 访ResponeVo
* @param syncStandard 0 1
* @param URL 访
* @return
*/
public ResponeVo getEntityMap(String syncStandard, String URL){
try {
HttpUtils httpUtils = new HttpUtils();
Map<String, Object> paramsMap = new HashMap<>();
paramsMap.put("syncStandard", syncStandard);
return httpUtils.apiPost(URL, paramsMap);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,7 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherSMInfoService;
public class GMGatherSMInfoServiceImpl implements GMGatherSMInfoService {
}

View File

@ -0,0 +1,162 @@
package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl;
import aiyh.utils.Util;
import com.google.common.base.Joiner;
import com.weaver.formmodel.util.DateHelper;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper.GMGatherSameSystemInfoMapper;
import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherSameSystemInfoService;
import weaver.conn.RecordSet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfoService {
/**
*
*/
private final Logger logger = Util.getLogger();
//sql
private final GMGatherSameSystemInfoMapper gmGatherSameSystemInfoMapper = Util.getMapper(GMGatherSameSystemInfoMapper.class);
/**
*
* @param configurationMainTableName
* @param configurationDetailTableName1 1
* @param configurationDetailTableName2 2
* @param uniqueIdentification
*/
public void dealMainLogic(String configurationMainTableName, String configurationDetailTableName1, String configurationDetailTableName2, String uniqueIdentification) {
//第一步获取配置表中数据
if (configurationMainTableName.equals("") && configurationDetailTableName1.equals("") && uniqueIdentification.equals("")) return;
//主表数据
List<Map<String,Object>> configMainTableData = gmGatherSameSystemInfoMapper.getConfigInformation(configurationMainTableName,uniqueIdentification);
logger.info("配置表主表数据---configMainTableData---"+configMainTableData);
if (configMainTableData.isEmpty()) return;
String jttzbd = Util.null2String(configMainTableData.get(0).get("jttzbd"));//集团台账表单
String mainid = Util.null2String(configMainTableData.get(0).get("mainid"));
logger.info("配置表主表数据---mainid---"+mainid);
if (mainid.equals("")) return;
//配置表明细表1数据用来统计商密下级单位台账名称
List<Map<String,Object>> configDetal1TableData = gmGatherSameSystemInfoMapper.getConfigDetal1Information(configurationDetailTableName1,mainid);
logger.info("配置表明细表数据---configDetal1TableData---"+configDetal1TableData);
//明细表2数据
List<Map<String,Object>> configDetal2TableData = gmGatherSameSystemInfoMapper.getConfigDetal2Information(configurationDetailTableName2,mainid);
logger.info("配置表明细表数据---configDetal2TableData---"+configDetal2TableData);
List<String> keys = new ArrayList<>();//用于insert和update的key
for (Map<String, Object> configdetal2 : configDetal2TableData) {
keys.add(Util.null2String(configdetal2.get("tbzd")));
}
//第二步:其次我们需要根据数据创建时间,和数据修改时间来判断二级单位中的这条数据是第一次进来的,还是二次进来修改的,如果只有创建时间没有修改时间那么就对这条数据进行增加,如果既有创建时间又有修改时间,那么就需要将这条数据进行修改
if (configDetal1TableData.isEmpty()) return;
for (Map<String, Object> config1 : configDetal1TableData) {
String ejdwtzb_name = Util.null2String(config1.get("ejdwtzb")); //二级单位台账表数据库名称
String bz = Util.null2String(config1.get("bz")); //备注
logger.info("二级单位台账表数据库名称===="+ejdwtzb_name+" 二级单位台账表数名称==="+bz);
//获取当天日期的前一天,如果和创建时间吻合,并且满足修改时间为空那么,这条数据就是纯插入的数据
List<Map<String,Object>> smCountLowGroupDataInsert = gmGatherSameSystemInfoMapper.getSMCountLowGroupdata(ejdwtzb_name, DateHelper.getYesterday());
logger.info("smCountLowGroupDataInsert===="+smCountLowGroupDataInsert);
//获取当天日期的前一天,如果和修改时间吻合,那么这条数据就是更新操作的数据
List<Map<String,Object>> smCountLowGroupDataupdate = gmGatherSameSystemInfoMapper.getSMCountLowGroupDataUpdate(ejdwtzb_name,DateHelper.getYesterday());
logger.info("smCountLowGroupDataupdate===="+smCountLowGroupDataupdate);
//数据插入商密集团总台账
if (smCountLowGroupDataInsert.size()>0){
this.insertData(smCountLowGroupDataInsert,jttzbd,keys);
}
//数据更新商密集团总台账
if (smCountLowGroupDataupdate.size()>0){
this.updateData(smCountLowGroupDataupdate,jttzbd,keys);
}
}
}
/**
* <h2></h2>
* @param smCountLowGroupDataInsert
* @param jttzbd
* @param keys insertkey
* @author hcy
* 2023/5/6 17:41
*/
private void insertData(List<Map<String, Object>> smCountLowGroupDataInsert, String jttzbd,List<String> keys) {
RecordSet recordSet = new RecordSet();
for (Map<String, Object> insertDatas : smCountLowGroupDataInsert) {
String htbm = Util.null2String(insertDatas.get("htbm"));
List<Map<String,Object>> selectHtbmData = gmGatherSameSystemInfoMapper.selectHtbmData(jttzbd,htbm);
if (selectHtbmData.size()==0){
String insertKey = Joiner.on(",").join((Iterable<?>) keys);//key
ArrayList<String> valueList = new ArrayList<>();
for (String key : keys) {
String v = Util.null2String(insertDatas.get(key));
valueList.add(v);
}
String insertValue = Joiner.on(",").join((Iterable<?>) valueList);//value
String insertSql = "insert into "+jttzbd + "(" +insertKey + ")"+ "value " +"("+insertValue+")";//拼接插入的sql语句
boolean insertBool = recordSet.executeQuery(insertSql);
if (insertBool){
logger.info("数据插入成功");
}else{
logger.info("数据插入失败");
}
}
}
}
/**
* <h2></h2>
* @param smCountLowGroupDataupdate
* @param jttzbd
* @param keys key
* @author hcy
* 2023/5/6 17:40
*/
private void updateData(List<Map<String, Object>> smCountLowGroupDataupdate, String jttzbd, List<String> keys) {
try {
RecordSet recordSet = new RecordSet();
for (Map<String, Object> updateDates : smCountLowGroupDataupdate) {
String htbm = Util.null2String(updateDates.get("htbm"));
List<Map<String, Object>> updateDatas = gmGatherSameSystemInfoMapper.selectHtbmData(jttzbd, htbm);
if (updateDatas.size()>0){
//拼接sql
List<String> updateValueList = new ArrayList<>();
for (String key : keys) {
String value = Util.null2String(updateDates.get(key));
updateValueList.add(value);
}
StringBuilder builder = new StringBuilder();
Joiner.on(", ").appendTo(builder, keys);
builder.append(" = ");
Joiner.on(", ").appendTo(builder, updateValueList);
String updateSql = "update "+jttzbd + "set " + builder + " where htbm = ?";
boolean updateBool = recordSet.executeQuery(updateSql, htbm);
if (updateBool){
logger.info("======数据更新成功======");
}else {
logger.info("======数据更新失败======");
}
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("----GMGatherSameSystemInfoServiceImpl----smCountLowGroupDataupdate----异常如下===="+e);
}
}
}

View File

@ -0,0 +1,73 @@
package weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.controller;
import aiyh.utils.Util;
import lombok.SneakyThrows;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.service.SMCountLowGroupDataService;
import weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.service.impl.SMCountLowGroupDataServiceImpl;
import weaver.interfaces.schedule.BaseCronJob;
/**
* <h1>使使</h1>
* @Author hcy
* @Date 2023/4/26 18:14
*/
public class SMCountLowGroupDataController extends BaseCronJob {
//业务主要逻辑
private final SMCountLowGroupDataService smCountLowGroupData = (SMCountLowGroupDataService) new SMCountLowGroupDataServiceImpl();
//日志处理
private final Logger logger = Util.getLogger();
//配置表主表名称
public String configurationMainTableName;
//配置表明细表1名称
public String configurationDetailTableName1;
//配置表明细表2名称
public String configurationDetailTableName2;
//唯一标识
public String uniqueIdentification;
@SneakyThrows
public void execute() {
smCountLowGroupData.dealMainLogic(configurationMainTableName,configurationDetailTableName1,configurationDetailTableName2,uniqueIdentification);//处理业务主要逻辑
}
public String getConfigurationDetailTableName1() {
return configurationDetailTableName1;
}
public void setConfigurationDetailTableName1(String configurationDetailTableName1) {
this.configurationDetailTableName1 = configurationDetailTableName1;
}
public String getConfigurationDetailTableName2() {
return configurationDetailTableName2;
}
public void setConfigurationDetailTableName2(String configurationDetailTableName2) {
this.configurationDetailTableName2 = configurationDetailTableName2;
}
public String getConfigurationMainTableName() {
return configurationMainTableName;
}
public void setConfigurationMainTableName(String configurationMainTableName) {
this.configurationMainTableName = configurationMainTableName;
}
public String getUniqueIdentification() {
return uniqueIdentification;
}
public void setUniqueIdentification(String uniqueIdentification) {
this.uniqueIdentification = uniqueIdentification;
}
}

View File

@ -0,0 +1,56 @@
package weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.mapper;
import aiyh.utils.annotation.recordset.ParamMapper;
import aiyh.utils.annotation.recordset.Select;
import aiyh.utils.annotation.recordset.SqlMapper;
import java.util.List;
import java.util.Map;
@SqlMapper
public interface SMCountLowGroupDataMapper {
@Select("select * from $t{configurationMainTableName} where wybs = #{uniqueIdentification}")
List<Map<String, Object>> getConfigInformation(@ParamMapper("configurationMainTableName") String configurationMainTableName,
@ParamMapper("uniqueIdentification") String uniqueIdentification);
@Select("select * from $t{configurationDetailTableName1} where mainid = #{mainid}")
List<Map<String, Object>> getConfigDetal1Information(@ParamMapper("configurationDetailTableName1")String configurationDetailTableName1,
@ParamMapper("mainid")String mainid);
@Select("select * from $t{configurationDetailTableName2} where mainid = #{mainid}")
List<Map<String, Object>> getConfigDetal2Information(@ParamMapper("configurationDetailTableName2")String configurationDetailTableName2,
@ParamMapper("mainid")String mainid);
@Select("select * from $t{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)")
List<Map<String, Object>> getSMCountLowGroupdata(@ParamMapper("ejdwtzb_name")String ejdwtzb_name,
@ParamMapper("yesterday")String yesterday);
@Select("select * from $t{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)")
List<Map<String, Object>> getSMCountLowGroupDataUpdate(@ParamMapper("ejdwtzb_name")String ejdwtzb_name,
@ParamMapper("yesterday")String yesterday);
@Select("select * from $t{jttzbd} where htbm = #{htbm}")
List<Map<String, Object>> selectHtbmData(@ParamMapper("jttzbd")String jttzbd,
@ParamMapper("htbm")String htbm);
@Select("select * from $t{ejdwtzb_name}")
List<Map<String, Object>> getSMCountLowGroupTotalData(@ParamMapper("ejdwtzb_name") String ejdwtzb_name);
@Select("select id from $t{jttzbd} where htbm = #{htbm}")
String selectIdByHtbm(@ParamMapper("jttzbd")String jttzbd,
@ParamMapper("htbm")String htbm);
@Select("delete from $t{s} where mainid = #{id}")
boolean deleteDetalDataByMainId(@ParamMapper("s")String s,
@ParamMapper("id")String id);
@Select("select id from $t{ejdwtzb_name} where id = #{htbm1}")
String selectDetailTableSouceId(@ParamMapper("ejdwtzb_name")String ejdwtzb_name,
@ParamMapper("htbm1")String htbm1);
@Select("select * from $t{s} where mainid = #{ejdw_id}")
List<Map<String, Object>> selectDetailTableSouceData(String s, String ejdw_id);
}

View File

@ -0,0 +1,9 @@
package weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.service;
import java.io.IOException;
public interface SMCountLowGroupDataService {
void dealMainLogic(String configurationMainTableName, String configurationDetailTableName1, String configurationDetailTableName2, String uniqueIdentification) throws IOException;
}

View File

@ -0,0 +1,248 @@
package weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.service.impl;
import aiyh.utils.Util;
import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl;
import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.impl.PrepWhereImpl;
import com.weaver.formmodel.util.DateHelper;
import org.apache.log4j.Logger;
import weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.mapper.SMCountLowGroupDataMapper;
import weaver.chaoyang.he.hcy_hangtiankeji.smcountlowgruop.service.SMCountLowGroupDataService;
import weaver.conn.RecordSet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// 3、开发补充详细开发方案
// 1我们现在要做的事情就是要将商密下级单位台账表中的数据同步到商密集团台账表uf_hthpjtz中
// 2首先我们需要根据合同台账同步表uf_httztb来获取数据库二级单位表名称和想要同步不来的字段名称这里要求做成配置的是因为后续便于字段增删
// 3其次我们需要根据数据创建时间和数据修改时间来判断二级单位中的这条数据是第一次进来的还是二次进来修改的如果只有创建时间没有修改时间那么就对这条数据进行增加如果既有创建时间又有修改时间那么就需要将这条数据进行修改
// 4在向商密集团总台账插入数据的时候同时为了保证数据的准确性我们首先需要根据合同编码来查询合同总台账中查询本条数据是否已经存在如果存在执行更新操作如果不存在执行插入操作。
public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataService {
//处理sql
private final SMCountLowGroupDataMapper smCountLowGroupDataMapper = Util.getMapper(SMCountLowGroupDataMapper.class);
//构建inser、update 的sql语句
private final BuilderSqlImpl builderSqlImpl = new BuilderSqlImpl();
//日志
private final Logger logger = Util.getLogger();
/**
* <h2></h2>
* @author hcy 2023/5/6 14:59
*/
public void dealMainLogic(String configurationMainTableName, String configurationDetailTableName1, String configurationDetailTableName2, String uniqueIdentification) throws IOException {
//第一步获取配置表中数据
if (configurationMainTableName.equals("") && configurationDetailTableName1.equals("") && uniqueIdentification.equals("")) return;
//主表数据
List<Map<String,Object>> configMainTableData = smCountLowGroupDataMapper.getConfigInformation(configurationMainTableName,uniqueIdentification);
logger.info("配置表主表数据---configMainTableData---"+configMainTableData);
if (configMainTableData.isEmpty()) return;
String jttzbd = Util.null2String(configMainTableData.get(0).get("jttzbd"));//集团台账表单
String mainid = Util.null2String(configMainTableData.get(0).get("id"));
logger.info("配置表主表数据---mainid---"+mainid);
if (mainid.equals("") && "".equals(jttzbd)) return;
//配置表明细表1数据用来统计商密下级单位台账名称
List<Map<String,Object>> configDetal1TableData = smCountLowGroupDataMapper.getConfigDetal1Information(configurationDetailTableName1,mainid);
logger.info("配置表明细表数据---configDetal1TableData---"+configDetal1TableData);
//明细表2数据
List<Map<String,Object>> configDetal2TableData = smCountLowGroupDataMapper.getConfigDetal2Information(configurationDetailTableName2,mainid);
logger.info("配置表明细表数据---configDetal2TableData---"+configDetal2TableData);
List<String> mainTablekeys = new ArrayList<>();//用于存放主表中insert和update的key
List<String> detalTablekeys = new ArrayList<>();//用于存放主表中insert和update的key
for (Map<String, Object> configdetal2 : configDetal2TableData) {
String sfzb = Util.null2String(configdetal2.get("sfzb"));
if ("0".equals(sfzb)){
mainTablekeys.add(Util.null2String(configdetal2.get("tbzd")));
}else if ("1".equals(sfzb)){
detalTablekeys.add(Util.null2String(configdetal2.get("tbzd")));
}
}
//第二步:其次我们需要根据数据创建时间,和数据修改时间来判断二级单位中的这条数据是第一次进来的,还是二次进来修改的,如果只有创建时间没有修改时间那么就对这条数据进行增加,如果既有创建时间又有修改时间,那么就需要将这条数据进行修改
if (configDetal1TableData.isEmpty()) return;
for (Map<String, Object> config1 : configDetal1TableData) {
String ejdwtzb_name = Util.null2String(config1.get("ejdwtzb")); //二级单位台账表数据库名称
String bz = Util.null2String(config1.get("bz")); //备注
String tbzt = Util.null2String(config1.get("tbzt"));
logger.info("二级单位台账表数据库名称===="+ejdwtzb_name+" 二级单位台账表数名称==="+bz+" 同步状态==="+tbzt);
if ("0".equals(tbzt)){
//查询全量数据
List<Map<String,Object>> smCountLowGroupTotalData = smCountLowGroupDataMapper.getSMCountLowGroupTotalData(ejdwtzb_name);//第一次同步数据
if (smCountLowGroupTotalData.size()>0){
this.insertData(smCountLowGroupTotalData,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys,tbzt);//全增量主表数据执行插入 并且包含明细表的删除,和再次添加
}
}else if ("1".equals(tbzt)){ //非第一次同步数据
//获取当天日期的前一天,如果和创建时间吻合,并且满足修改时间为空那么,这条数据就是纯插入的数据
List<Map<String,Object>> smCountLowGroupDataInsert = smCountLowGroupDataMapper.getSMCountLowGroupdata(ejdwtzb_name,DateHelper.getYesterday());
logger.info("smCountLowGroupDataInsert===="+smCountLowGroupDataInsert);
//获取当天日期的前一天,如果和修改时间吻合,那么这条数据就是更新操作的数据
List<Map<String,Object>> smCountLowGroupDataupdate = smCountLowGroupDataMapper.getSMCountLowGroupDataUpdate(ejdwtzb_name,DateHelper.getYesterday());
logger.info("smCountLowGroupDataupdate===="+smCountLowGroupDataupdate);
//数据插入商密集团总台账
if (smCountLowGroupDataInsert.size()>0){
this.insertData(smCountLowGroupDataInsert,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys, tbzt);
}
//数据更新商密集团总台账
if (smCountLowGroupDataupdate.size()>0){
this.updateData(smCountLowGroupDataupdate,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys);
}
}
}
}
/**
* <h2></h2>
* @param smCountLowGroupDataInsert
* @param jttzbd
* @param ejdwtzb_name
* @param keys insertkey
* @param detalTablekeys list
* @param tbzt
* @author hcy
* 2023/5/6 17:41
*/
private void insertData(List<Map<String, Object>> smCountLowGroupDataInsert, String jttzbd, String ejdwtzb_name, List<String> keys, List<String> detalTablekeys, String tbzt) {
RecordSet recordSet = new RecordSet();
int successNum = 0;
int failNum = 0;
for (Map<String, Object> insertDatas : smCountLowGroupDataInsert) {
String htbm = Util.null2String(insertDatas.get("htbm"));
List<Map<String,Object>> selectHtbmData = smCountLowGroupDataMapper.selectHtbmData(jttzbd,htbm);
if (selectHtbmData.size()==0){
// String insertKey = Joiner.on(",").join((Iterable<?>) keys);//key
Map<String, Object> keyValueMap = new HashMap<>();
for (String key : keys) {
String v = Util.null2String(insertDatas.get(key));
keyValueMap.put(key, v);
}
//执行主表数据的插入语句
PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd, keyValueMap);
if(recordSet.executeUpdate(prepSqlResult.getSqlStr(),prepSqlResult)){
successNum++;
String htbm1 = Util.null2String(keyValueMap.get("htbm"));
//执行明细表的数据删除和数据插入
deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys);
}else{
failNum++;
logger.error("台账数据插入失败失败SQL:["+ prepSqlResult +"----失败次数:"+failNum+"]");
}
logger.info("台账数据插入成功 "+successNum+"次");
}
}
}
/**
* <h2></h2>
* @param smCountLowGroupDataupdate
* @param jttzbd
* @param ejdwtzb_name
* @param keys key
* @param detalTablekeys list
* @author hcy
* 2023/5/6 17:40
*/
private void updateData(List<Map<String, Object>> smCountLowGroupDataupdate, String jttzbd, String ejdwtzb_name, List<String> keys, List<String> detalTablekeys) {
RecordSet recordSet = new RecordSet();
int failNum = 0;
int successNum = 0;
for (Map<String, Object> updateDates : smCountLowGroupDataupdate) {
String htbm = Util.null2String(updateDates.get("htbm"));
List<Map<String, Object>> selecthtbmData = smCountLowGroupDataMapper.selectHtbmData(jttzbd, htbm);
if (selecthtbmData.size()>0){
Map<String, Object> keyValueMap = getKeyValueMap(updateDates, keys);
PrepWhereImpl prepWhere = new PrepWhereImpl();
prepWhere.whereAnd("htbm = ?");
prepWhere.addArgs(htbm);
PrepSqlResultImpl prepSqlResult = builderSqlImpl.updateSql(jttzbd, keyValueMap, prepWhere);
if (recordSet.executeQuery(prepSqlResult.getSqlStr(), prepSqlResult)){
String htbm1 = Util.null2String(keyValueMap.get("htbm"));
//执行明细表的数据删除和数据插入
deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys);
successNum++;
}else {
failNum++;
logger.error("台账数据更新失败SQL["+ prepSqlResult +"------失败次数:"+failNum+"]");
}
logger.info("台账数据更新成功 "+successNum + "次");
}
}
}
/**
* insertupdatekey,valuemap
* @param datas
* @param keys keys
* @return key,valuemap
*/
public Map<String, Object> getKeyValueMap(Map<String, Object> datas ,List<String> keys){
Map<String, Object> keyValueMap = new HashMap<>();
for (String key : keys) {
String v = Util.null2String(datas.get(key));
keyValueMap.put(key, v);
}
return keyValueMap;
}
/**
*
* @param htbm1
* @param jttzbd
* @param ejdwtzb_name
* @param detalTablekeys list
*/
public void deleteAndInsertDetailTable(String htbm1,String jttzbd,String ejdwtzb_name,List<String> detalTablekeys){
RecordSet insertDatailRS = new RecordSet();
//执行明细表的插入语句
String id = smCountLowGroupDataMapper.selectIdByHtbm(jttzbd,htbm1);
int successNum = 0;
int failNum = 0;
if (!"".equals(id)){
boolean deleteBool = smCountLowGroupDataMapper.deleteDetalDataByMainId(jttzbd+"_dt1",id);//明细表插入数据之前,先执行删除语句
if (deleteBool){
//执行明细表插入逻辑
String ejdw_id = smCountLowGroupDataMapper.selectDetailTableSouceId(ejdwtzb_name,htbm1);
List<Map<String,Object>> souceDetailDatas = smCountLowGroupDataMapper.selectDetailTableSouceData(ejdwtzb_name+"_dt1",ejdw_id);
for (Map<String, Object> souceDetailData : souceDetailDatas) {
Map<String, Object> dealwithData = new HashMap<>();//根据配置表处理完需要字段后的数据Map
for (String key : detalTablekeys) {
dealwithData.put(key,souceDetailData.get(key));
}
//将mainid拼进去
dealwithData.put("mainid",id);
//开始插入明细表数据 insert into
PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd, dealwithData);
if (insertDatailRS.executeUpdate(prepSqlResult.getSqlStr(),prepSqlResult.getArgs())){
successNum++;
}else {
failNum++;
logger.error("明细表数据插入失败SQL:["+prepSqlResult+"------失败次数:"+failNum+"]");
}
logger.info("明细表数据插入成功数量:"+successNum);
}
}
}
}
}