Browse Source

Merge branch 'master' of ssh://dev@10.10.100.21/source/uas_schedular.git

tanmh 5 years ago
parent
commit
71bd9d33de

+ 23 - 330
src/main/java/com/uas/erp/schedular/finance/task/B2BInformation.java

@@ -5,60 +5,32 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
-import java.util.Set;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.uas.erp.schedular.entity.Master;
 import com.uas.erp.schedular.task.support.Method;
 import com.uas.erp.schedular.util.ContextHolder;
-import com.usoft.fin.external.open.api.entity.CapitalSideLoan;
-import com.usoft.fin.external.open.api.entity.FinanceOfferListOrBuilder;
-import com.usoft.fin.external.open.api.entity.OfferQuotaInfoRest;
+import com.usoft.fin.external.open.api.entity.*;
 import com.usoft.fin.external.open.api.protobuf.*;
 import com.usoft.sdk.fin.client.CapitalSideSdk;
-import com.usoft.sdk.fin.client.TradingHallSdk;
 
-import org.apache.commons.lang3.StringUtils;
-import org.apache.tomcat.util.descriptor.web.ContextHandler;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 import com.uas.erp.schedular.task.support.Role;
 import com.uas.erp.schedular.task.support.TaskMapping;
-import com.uas.erp.schedular.util.CollectionUtil;
-import com.uas.erp.schedular.util.ContextHolder;
-import com.usoft.fin.external.open.api.entity.AcceptOfferDetail;
-import com.usoft.fin.external.open.api.entity.CompanyBasicInfosByErmRest;
-import com.usoft.fin.external.open.api.entity.CompanyEnterpriseCrawlerListFinRest;
-import com.usoft.fin.external.open.api.entity.CompanyIndustryAndCommerceInfoRest;
-import com.usoft.fin.external.open.api.entity.CompanyLawInfoFinRest;
-import com.usoft.fin.external.open.api.entity.FinanceOfferDetails;
-import com.usoft.fin.external.open.api.entity.OfferDetailAndFinanceAccept;
-import com.usoft.fin.external.open.api.entity.OpenCapitalSideLoanOther;
-import com.usoft.fin.external.open.api.entity.OpenCapitalSideRepaymentPlanOther;
-import com.usoft.fin.external.open.api.entity.RestBaseInfo;
-import com.usoft.fin.external.open.api.protobuf.GetCapitalSideLoanReq;
-import com.usoft.fin.external.open.api.protobuf.GetCapitalSideLoanResp;
-import com.usoft.fin.external.open.api.protobuf.GetFinanceOfferDetailsReq;
-import com.usoft.fin.external.open.api.protobuf.GetFinanceOfferDetailsResp;
-import com.usoft.fin.external.open.api.protobuf.GetFinanceOfferListReq;
-import com.usoft.fin.external.open.api.protobuf.GetFinanceOfferListResp;
 import com.usoft.fin.external.open.api.protobuf.GetOfferQuotaInfoListReq;
 import com.usoft.fin.external.open.api.protobuf.GetOfferQuotaInfoListResp;
 import com.usoft.sdk.fin.utils.ProtoBufUtil;
 
-
-
-
-
 @Component
 @TaskMapping(title = "U智融对接服务", role = Role.SELLER)
 public class B2BInformation  extends AbstractTask{
+	@Autowired
+	private CustInfomationTask custInfomationTask;
 	private CapitalSideSdk capitalSideSdk = new CapitalSideSdk("https://finrest.uuzcc.cn", "10050877", "b78d577449b64f56a8a6cf1feeb3fbf5");
-	private TradingHallSdk tradingHallSdk = new TradingHallSdk("https://finrest.uuzcc.cn", "10050877", "b78d577449b64f56a8a6cf1feeb3fbf5");
 
 	/**
      * 额度申请
@@ -67,17 +39,21 @@ public class B2BInformation  extends AbstractTask{
 	@TaskMapping(title = "额度申请下载", fixedDelay = 30000, method = Method.DOWNLOAD)
     public void getOfferQuotaInfoList() throws Exception {
 		List<String> sqls = new ArrayList<>();
-		Calendar beforeTime = Calendar.getInstance();
-		beforeTime.add(Calendar.MINUTE, -7);// 7分钟之前的时间
-		Date beforeD = beforeTime.getTime();
+		long curt = System.currentTimeMillis();
+		int cCount = jdbcTemplate.count("FROM CONFIGS WHERE CALLER = 'sys' AND CODE ='lastLoadQuotaTime'");
+		if(cCount == 0){
+			jdbcTemplate.execute("Insert into CONFIGS (CODE,TITLE,DATA_TYPE,DATA,CALLER,MULTI,ID,EDITABLE) values " +
+					"('lastLoadQuotaTime','上次同步额度申请时间','VARCHAR2','"+curt+"','sys',0,CONFIGS_SEQ.NEXTVAL,1)");
+		}
+		Object lastTime = jdbcTemplate.getObject("SELECT MAX(DATA) FROM CONFIGS WHERE CALLER = 'sys' AND CODE ='lastLoadQuotaTime'");
 		Master currMaster = ContextHolder.getMaster();
     	GetOfferQuotaInfoListReq.Builder req = GetOfferQuotaInfoListReq.newBuilder();
-    	req.setCsEnuu(10050877);
-    	//req.setCsEnuu(Integer.valueOf(currMaster.getMa_uu().toString()));
-    	//req.setCsEnuu(10050877);
-		//req.setPageNumber(1);
-		//req.setPageSize(50);
-		//req.setUpdateTime(beforeD.getTime());//获取最近7分钟更新的单据列表
+    	req.setCsEnuu(10050877); //req.setCsEnuu(Integer.valueOf(currMaster.getMa_uu().toString()));
+		if(lastTime != null){//未配置则取全部数据
+			long lt = Long.valueOf(String.valueOf(lastTime));
+			System.out.println("lt:"+lt);
+			req.setUpdateTime(lt);//获取上次更新时间结束后被更新的单据列表
+		}
 		GetOfferQuotaInfoListResp resp = capitalSideSdk.getOfferQuotaInfoList(req);
 		java.util.List<OfferQuotaInfoRest> restlist = resp.getOfferQuoteInfoList();
 		//System.out.println("restlist-size:"+restlist.size());
@@ -114,6 +90,7 @@ public class B2BInformation  extends AbstractTask{
 						"	" + rest.getQuotaAmount()*10000 + "," + rest.getCredDays() + "," + rest.getFinanceRate() + "," + rest.getOfferRate() + ",'" + rest.getRepayment() + "'," +
 						"	TO_DATE('" + rest.getApplyTime() + "','YYYY-MM-DD hh24:mi:ss'),'" + rest.getApplyUsername() + "'," + rest.getApplyUu() + ",TO_DATE('" + rest.getCheckerTime() + "','YYYY-MM-DD hh24:mi:ss')," +
 						"	'" + (rest.getStatus() == 1402 ? "AUDITED" : "ENTERING") + "','" + (rest.getStatus() == 1402 ? "已审核" : "在录入") + "','" + rest.getCheckerContent() + "')");
+				enMap.put("CQ_CODE",rest.getCode());
 				enMap.put("CQ_CUSTUU", rest.getFsEnuu());
 				enMap.put("CQ_FACTORUU", rest.getCsEnuu());
 				enMap.put("CQ_RECORDERUU", rest.getApplyUu());
@@ -123,302 +100,18 @@ public class B2BInformation  extends AbstractTask{
 			}
 		}
         //System.out.println(sqls);
+		if(cCount > 0){
+			//记录本次抓取时间
+			sqls.add("UPDATE CONFIGS SET DATA = '"+curt+"' WHERE CALLER = 'sys' AND CODE ='lastLoadQuotaTime'");
+		}
 		jdbcTemplate.batchExecute(sqls);
 		//下载或更新客户信息
 		if(enUUList.size()>0){
-			getCustInfomation(enUUList);
+			custInfomationTask.getCustInfomation(enUUList);
 		}
     }
 
 	/**
-	 * 客户信息下载
-	 * @param enUUList
-	 * @throws Exception
-	 */
-	public void getCustInfomation(List<Map<String, Object>> enUUList) throws Exception {
-		List<String> sqls = new ArrayList<>();
-		for(Map<String, Object> enMap : enUUList){
-			int facUU = enMap.get("CQ_FACTORUU") ==null ? 10050877 :Integer.valueOf(enMap.get("CQ_FACTORUU").toString());//资金方UU
-			int custUU = Integer.valueOf(enMap.get("CQ_CUSTUU").toString());//融资方UU--客户
-			int userUU = enMap.get("CQ_RECORDERUU") ==null ? 0 :Integer.valueOf(enMap.get("CQ_RECORDERUU").toString());//操作人UU
-//			System.out.println("facUU:"+facUU);
-//			System.out.println("custUU:"+custUU);
-			GetEnterpriseExtensionInfoReq.Builder entExtReq = GetEnterpriseExtensionInfoReq.newBuilder();
-			entExtReq.setEnuu(custUU);  //正式
-			//entExtReq.setEnuu(10050877);    //测试
-			//客户基本信息 CompanyBasicInfosByErmRest
-			GetEnterpriseExtensionInfoResp entExtInfoResp = tradingHallSdk.getEnterpriseExtensionInfo(entExtReq);
-			CompanyBasicInfosByErmRest compBaseInfoByErmRest = entExtInfoResp.getCompanyBasicInfo();
-			if(compBaseInfoByErmRest.getEnName()==null||compBaseInfoByErmRest.getEnName().equals("")){
-				break;
-			}
-			//System.out.println("客户基本信息: "+ProtoBufUtil.toJSON(compBaseInfoByErmRest));
-//			System.out.println("获取客户UU:"+compBaseInfoByErmRest.getEnuu());
-			//扩展信息 CompanyIndustryAndCommerceInfoRest
-			CompanyEnterpriseCrawlerListFinRest entCrawLFRest = entExtInfoResp.getCompanyEnterpriseCrawlerList();
-			CompanyIndustryAndCommerceInfoRest compIndusAndCommInforRest = entCrawLFRest.getCompanyIndustryAndCommerceInfo();
-			//System.out.println("扩展信息:"+ProtoBufUtil.toJSON(entCrawLFRest));
-			//企业简介 员工人数 CompanyIndustryAndCommerceInfoRest.CompanyLawInfoFinRest enIntro insuredNumberOfPeople
-			CompanyLawInfoFinRest compLawInfoRest = entCrawLFRest.getCompanyLawInfo();
-			//企业 融资方信息 RestBaseInfo
-			GetBaseInfoReq.Builder req = GetBaseInfoReq.newBuilder();
-			//资金方UU  为空或为0默认保理
-			req.setCsEnuu(facUU);
-			//融资方UU
-			req.setEnuu(custUU);
-			//操作人UU 为空就为0
-			req.setUu(userUU);
-			GetBaseInfoResp restBaseInfoResp = tradingHallSdk.getBaseInfo(req);
-			RestBaseInfo restBaseInfo = restBaseInfoResp.getBaseInfo();
-//			System.out.println("融资方信息:"+ProtoBufUtil.toJSON(restBaseInfoResp));
-//			System.out.println("融资方信息-客户名称:"+restBaseInfo.getEnName());
-			int cuId = jdbcTemplate.getInt("SELECT NVL(MAX(CU_ID),0) FROM CUSTOMERINFOR WHERE CU_STATUSCODE <> 'DISABLE' AND CU_ENUU = ? ", custUU);
-			int detno = 1;
-			//主表
-			String cu_term = ((compBaseInfoByErmRest.getEnOpDate()==null || compBaseInfoByErmRest.getEnOpDate().equals(""))? "null" : (compBaseInfoByErmRest.getEnOpDate().contains("无固定期限")?"9999":compBaseInfoByErmRest.getEnOpDate()));
-			String cu_licensedate = (compBaseInfoByErmRest.getEnRegDate()==null||compBaseInfoByErmRest.getEnRegDate().equals("")?"null":"to_date('"+compBaseInfoByErmRest.getEnRegDate()+"','YYYY-MM-DD HH24:MI:SS')");
-			String cu_regcapital = (compBaseInfoByErmRest.getEnRegCapital() ==null || compBaseInfoByErmRest.getEnRegCapital().equals("") ? "null":compBaseInfoByErmRest.getEnRegCapital().replace("万元人民币",""));
-			String cu_paidincapital =(compIndusAndCommInforRest.getContributedCapital() ==null ||compIndusAndCommInforRest.getContributedCapital().equals("") ? "null" : compIndusAndCommInforRest.getContributedCapital().replace("万元人民币",""));
-			String cu_employeesnum = (compIndusAndCommInforRest.getInsuredNumberOfPeople() == null || compIndusAndCommInforRest.getInsuredNumberOfPeople().equals("") ? "null":compIndusAndCommInforRest.getInsuredNumberOfPeople());
-			//从表
-			if (cuId > 0) {//资料更新
-				//System.out.println("cuId:"+cuId);
-				sqls.add("UPDATE CUSTOMERQUOTA SET CQ_CUSTCODE = (SELECT CU_CODE FROM CUSTOMERINFOR WHERE CU_ID = "+cuId+") where CQ_CUSTCODE is null and CQ_CUSTUU = "+custUU);
-				sqls.add("UPDATE CUSTOMERINFOR SET " +
-						" CU_STATUS='在录入',CU_STATUSCODE='ENTERING'," +
-						" CU_UPDATEDATE=SYSDATE,CU_NAME='"+compBaseInfoByErmRest.getEnName()+"',CU_LEGALPERSON='"+compBaseInfoByErmRest.getEnLegalRepName()+"'," +
-						" CU_TERM = "+cu_term+",CU_TYPE ='"+compBaseInfoByErmRest.getEnType()+"',CU_PLAFORMLEVEL='"+restBaseInfo.getGrade()+"'," +
-						" CU_LICENSEDATE = "+cu_licensedate+",CU_PAPERSCODE='"+compBaseInfoByErmRest.getEnCodeCrawled()+"'," +
-						" CU_TAXCREDIT ='"+compIndusAndCommInforRest.getUnifiedSocialCreditCode()+"',CU_REGISTSTATUS='"+compBaseInfoByErmRest.getEnRegStatus()+"',CU_BUSINSSCOPE='"+compBaseInfoByErmRest.getEnOpRange()+"',CU_BUSINESSMAIN='"+restBaseInfo.getEnBusinessMain()+"'," +
-						" CU_CONTACT='"+restBaseInfo.getFsContactsMan()+"',CU_CONTACTNUM='"+restBaseInfo.getFsContactsPhone()+"',CU_REGCAPITAL="+cu_regcapital+",CU_PAIDINCAPITAL="+cu_paidincapital+"," +
-						" CU_REGADD='"+compBaseInfoByErmRest.getEnRegLocation()+"',CU_OFFICEADD='"+restBaseInfo.getEnAddress()+"',CU_INTRODUCTION='"+compLawInfoRest.getEnIntro()+"',CU_ZJUU='"+10050877+"'," +
-						" CU_EMPLOYEESNUM=" +cu_employeesnum+
-						" WHERE CU_ENUU = "+custUU+" AND CU_STATUSCODE <> 'DISABLE'");
-				System.out.println(sqls);
-				//从表1 高管信息 CUSTOMEREXCUTIVE
-				JSONArray enKeyPerList = JSONArray.parseArray(compBaseInfoByErmRest.getEnKeyPersonnel());
-				//System.out.println("更新高管信息:"+compBaseInfoByErmRest.getEnKeyPersonnel());
-				if(enKeyPerList!=null && enKeyPerList.size()>0){
-					for(int ei = 0;ei < enKeyPerList.size();ei++){
-						JSONObject ek = enKeyPerList.getJSONObject(ei);
-						Set<Map.Entry<String, Object>>ekKeySet = ek.entrySet();
-						if(ekKeySet!= null && ekKeySet.size()>0){
-							for(Map.Entry<String, Object> ekMap : ekKeySet){
-								sqls.add(" INSERT INTO CUSTOMEREXCUTIVE(CE_ID,CE_CUID,CE_DETNO,CE_NAME,CE_POSITION) " +
-										" SELECT CUSTOMEREXCUTIVE_seq.nextval,"+cuId+",9999,'"+ekMap.getKey()+"','"+ekMap.getValue()+"'" +
-										" FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM CUSTOMEREXCUTIVE " +
-										" WHERE CE_CUID = "+cuId+" AND CE_NAME ='"+ekMap.getKey()+"' AND CE_POSITION ='"+ekMap.getValue()+"')");
-							}
-						}
-					}
-					sqls.add("UPDATE CUSTOMEREXCUTIVE SET CE_DETNO = (select RN from (SELECT ROWNUM RN,CE_ID FROM " +
-							"	(SELECT CE_ID FROM CUSTOMEREXCUTIVE WHERE CE_CUID = "+cuId+" ORDER BY CE_DETNO ASC,CE_ID ASC)) TT where TT.CE_ID = CUSTOMEREXCUTIVE.CE_ID) " +
-							"WHERE CE_CUID = "+cuId);
-				}
-				//从表2 股东信息 CUSTOMERSHAREHOLDER
-				//System.out.println("更新股东信息:"+compBaseInfoByErmRest.getEnShareholders());
-				JSONArray enShareholdersList = JSONArray.parseArray(compBaseInfoByErmRest.getEnShareholders());
-				if(enShareholdersList!=null && enShareholdersList.size()>0) {
-					for (int i = 0; i < enShareholdersList.size(); i++) {
-						JSONObject enShareholders = enShareholdersList.getJSONObject(i);
-						Object cs_payableamount = ((enShareholders.get("认缴出资额(万元)")  == null || enShareholders.get("认缴出资额(万元)").equals("-")) ? "null" : enShareholders.get("认缴出资额(万元)") );
-						Object cs_investratio =	(enShareholders.getString("持股比例") == null ? 0 :enShareholders.getString("持股比例").replace("%",""));
-						Object cs_investdate = (enShareholders.getDate("认缴出资日期") == null ? "null" :"to_date('"+ new SimpleDateFormat("yyyy-MM-dd").format(enShareholders.getDate("认缴出资日期"))+"','yyyy-mm-dd')");
-						sqls.add(" MERGE INTO CUSTOMERSHAREHOLDER INHOLDER " +
-								" USING (SELECT NVL(MAX(CS_ID),0) CS_ID FROM CUSTOMERSHAREHOLDER WHERE CS_CUID = "+cuId+" AND CS_NAME = '"+enShareholders.get("股东")+"') ONHOLDER " +
-								" ON (INHOLDER.CS_ID = ONHOLDER.CS_ID) " +
-								" WHEN MATCHED THEN " +
-								" UPDATE SET CS_DETNO = 9999, INHOLDER.CS_PAYABLEAMOUNT="+cs_payableamount+",INHOLDER.CS_INVESTRATIO="+cs_investratio+",INHOLDER.CS_INVESTDATE="+cs_investdate+" " +
-								" WHEN NOT MATCHED THEN " +
-								" INSERT (INHOLDER.CS_ID,INHOLDER.CS_CUID,INHOLDER.CS_DETNO,INHOLDER.CS_NAME,INHOLDER.CS_PAYABLEAMOUNT,INHOLDER.CS_INVESTRATIO,INHOLDER.CS_INVESTDATE) " +
-								" VALUES(CUSTOMERSHAREHOLDER_SEQ.NEXTVAL,"+cuId+",9999,'"+enShareholders.get("股东")+"',"+cs_payableamount+","+cs_investratio+","+cs_investdate+")");
-//					System.out.println(" MERGE INTO CUSTOMERSHAREHOLDER INHOLDER " +
-//							" USING (SELECT NVL(MAX(CS_ID),0) CS_ID FROM CUSTOMERSHAREHOLDER WHERE CS_CUID = "+cuId+" AND CS_NAME = '"+enShareholders.get("股东")+"') ONHOLDER " +
-//							" ON (INHOLDER.CS_ID = ONHOLDER.CS_ID) " +
-//							" WHEN MATCHED THEN " +
-//							" UPDATE SET CS_DETNO = 9999, INHOLDER.CS_PAYABLEAMOUNT="+cs_payableamount+",INHOLDER.CS_INVESTRATIO="+cs_investratio+",INHOLDER.CS_INVESTDATE="+cs_investdate+" " +
-//							" WHEN NOT MATCHED THEN " +
-//							" INSERT (INHOLDER.CS_ID,INHOLDER.CS_CUID,INHOLDER.CS_DETNO,INHOLDER.CS_NAME,INHOLDER.CS_PAYABLEAMOUNT,INHOLDER.CS_INVESTRATIO,INHOLDER.CS_INVESTDATE) " +
-//							" VALUES(CUSTOMERSHAREHOLDER_SEQ.NEXTVAL,"+cuId+",9999,'"+enShareholders.get("股东")+"',"+cs_payableamount+","+cs_investratio+","+cs_investdate+");");
-					}
-					sqls.add("UPDATE CUSTOMERSHAREHOLDER SET CS_DETNO = (select RN from (SELECT ROWNUM RN,CS_ID FROM " +
-							"	(SELECT CS_ID FROM CUSTOMERSHAREHOLDER WHERE CS_CUID = "+cuId+" ORDER BY CS_DETNO ASC,CS_ID ASC)) TT where TT.CS_ID = CUSTOMERSHAREHOLDER.CS_ID) " +
-							"WHERE CS_CUID = "+cuId);
-				}
-				//从表4 变更说明 FSCHANGESINSTRUCTION
-				//System.out.println("更新变更说明:"+compBaseInfoByErmRest.getEnChangingRecords());
-				JSONObject enChangingRecords = JSONObject.parseObject(compBaseInfoByErmRest.getEnChangingRecords());
-				if(enChangingRecords!=null&&enChangingRecords.size()>0&&enChangingRecords.getString("变更内容列表") != null){
-					JSONArray enChangingRecordList = JSONArray.parseArray(enChangingRecords.getString("变更内容列表"));
-					if(enChangingRecordList!=null && enChangingRecordList.size()>0) {
-						sqls.add("DELETE FSCHANGESINSTRUCTION WHERE CS_CUID = "+cuId);
-						for (int i = 0; i < enChangingRecordList.size(); i++) {
-							JSONObject enChangingRecord = enChangingRecordList.getJSONObject(i);
-							Set<Map.Entry<String, Object>> changKey = enChangingRecord.entrySet();
-							for(Map.Entry<String, Object> ckMap : changKey){
-								String cd_type = ckMap.getKey();
-								if(ckMap.getValue()!=null){
-									JSONArray recordByDateList = JSONArray.parseArray(ckMap.getValue().toString());
-									if(recordByDateList != null && recordByDateList.size() > 0) {
-										for (int j = 0; j < recordByDateList.size(); j++) {
-											JSONObject recordByDate = recordByDateList.getJSONObject(j);
-											Set<Map.Entry<String, Object>> recordByDateKey = recordByDate.entrySet();
-											for(Map.Entry<String, Object> cbdMap : recordByDateKey){
-												if(cbdMap.getKey()!=null){
-													String cs_date = "to_date('"+ cbdMap.getKey()+"','yyyy-mm-dd')";
-													JSONObject cbdRecord = JSONObject.parseObject(cbdMap.getValue().toString());
-													//BEFORE
-													StringBuffer beforeStr = new StringBuffer();
-													JSONArray beforeList = JSONArray.parseArray(cbdRecord.getString("before"));
-													Object[] bRecordArr = beforeList.toArray();
-													for(int bi = 0 ; bi < bRecordArr.length; bi++){
-														if(bRecordArr[bi] != null){
-															beforeStr.append(bRecordArr[bi]);
-														}
-													}
-													//AFTER
-													StringBuffer afterStr = new StringBuffer();
-													JSONArray afterList = JSONArray.parseArray(cbdRecord.getString("after"));
-													Object[] aRecordArr = afterList.toArray();
-													for(int ai = 0 ; ai < aRecordArr.length; ai++){
-														if(aRecordArr[ai] != null){
-															afterStr.append(aRecordArr[ai]);
-														}
-													}
-													if(afterStr.length()>0){
-														sqls.add("INSERT INTO FSCHANGESINSTRUCTION(CS_ID,CS_CUID,CD_DETNO,cd_type,cs_date,cs_before,cs_after) " +
-																"SELECT FSCHANGESINSTRUCTION_SEQ.NEXTVAL,"+cuId+","+(detno++)+",'"+cd_type+"',"+cs_date+",'"+beforeStr.toString()+"','"+afterStr.toString()+"'" +
-																"FROM DUAL WHERE NOT EXISTS(SELECT 1 FROM FSCHANGESINSTRUCTION " +
-																"WHERE CS_CUID = "+cuId+" AND cd_type = '"+cd_type+"' AND cs_date = "+cs_date+" AND cs_before = '"+beforeStr.toString()+"' AND cs_after = '"+afterStr.toString()+"')");
-													}
-												}
-											}
-										}
-									}
-								}
-							}
-						}
-					}
-				}
-			} else {//新增在录入
-				//客户资料主表 CUSTOMERINFOR
-				cuId = jdbcTemplate.generate("CUSTOMERINFOR_SEQ");
-				String cuCode = (compBaseInfoByErmRest.getCode() ==null || compBaseInfoByErmRest.getCode().equals("") )? jdbcTemplate.generateCode("Customer!Infor", 2):compBaseInfoByErmRest.getCode();
-				detno = 1;
-				//System.out.println("enuu:"+compBaseInfoByErmRest.getEnuu()+",cuCode:"+cuCode);
-				sqls.add("INSERT INTO CUSTOMERINFOR(CU_ID,CU_CODE,CU_ENUU,CU_STATUS,CU_STATUSCODE,CU_UPDATEDATE,CU_NAME,CU_LEGALPERSON," +
-						"CU_TERM,CU_TYPE,CU_PLAFORMLEVEL,CU_LICENSEDATE,CU_PAPERSCODE," +
-						"CU_TAXCREDIT,CU_REGISTSTATUS,CU_BUSINSSCOPE,CU_BUSINESSMAIN," +
-						"CU_CONTACT,CU_CONTACTNUM,CU_REGCAPITAL,CU_PAIDINCAPITAL," +
-						"CU_REGADD,CU_OFFICEADD,CU_INTRODUCTION,CU_EMPLOYEESNUM,cu_zjuu" +
-						") VALUES ("+cuId+",'"+cuCode+"',"+compBaseInfoByErmRest.getEnuu()+",'在录入','ENTERING',SYSDATE,'"+compBaseInfoByErmRest.getEnName()+"','"+compBaseInfoByErmRest.getEnLegalRepName()+"',"
-						+cu_term+","+"'"+compBaseInfoByErmRest.getEnType()+"','"+restBaseInfo.getGrade()+"'," +cu_licensedate+",'"+compBaseInfoByErmRest.getEnCodeCrawled()+"',"+
-						"'"+compIndusAndCommInforRest.getUnifiedSocialCreditCode()+"','"+compBaseInfoByErmRest.getEnRegStatus()+"','"+compBaseInfoByErmRest.getEnOpRange()+"','"+restBaseInfo.getEnBusinessMain()+"',"+
-						"'"+restBaseInfo.getFsContactsMan()+"','"+restBaseInfo.getFsContactsPhone()+"',"+cu_regcapital+","+cu_paidincapital+",'"
-						+compBaseInfoByErmRest.getEnRegLocation()+"','"+restBaseInfo.getEnAddress()+"','"+compLawInfoRest.getEnIntro()+"',"+cu_employeesnum+",'10050877')");
-				sqls.add("UPDATE CUSTOMERQUOTA SET cq_custcode ='"+cuCode+"' where cq_custcode is null and CQ_CUSTUU = "+custUU);
-				//从表2 高管信息 CUSTOMEREXCUTIVE
-//				高管信息-高管姓名	CUSTOMEREXCUTIVE.ce_name	enKeyPersonnel
-//				高管信息-担任职务	CUSTOMEREXCUTIVE.ce_position	enKeyPersonnel
-//enKeyPersonnel 数据格式:[{'陈亚荣': '总经理'}, {'陈正明': '执行董事'}, {'陈劲松': '监事'}]
-				JSONArray enKeyPerList = JSONArray.parseArray(compBaseInfoByErmRest.getEnKeyPersonnel());
-				//System.out.println("高管信息:"+compBaseInfoByErmRest.getEnKeyPersonnel());
-				if(enKeyPerList!=null && enKeyPerList.size()>0){
-					for(int ei = 0;ei < enKeyPerList.size();ei++){
-						JSONObject ek = enKeyPerList.getJSONObject(ei);
-						Set<Map.Entry<String, Object>>ekKeySet = ek.entrySet();
-						if(ekKeySet!= null && ekKeySet.size()>0){
-							for(Map.Entry<String, Object> ekMap : ekKeySet){
-								sqls.add("INSERT INTO CUSTOMEREXCUTIVE(CE_ID,CE_CUID,CE_DETNO,CE_NAME,CE_POSITION) VALUES " +
-										"(CUSTOMEREXCUTIVE_seq.nextval,"+cuId+","+(detno++)+",'"+ekMap.getKey()+"','"+ekMap.getValue()+"')");
-							}
-						}
-					}
-				}
-				//从表2 股东信息 CUSTOMERSHAREHOLDER
-//				股东情况-股东名称	CUSTOMERSHAREHOLDER.cs_name	enShareholders
-//				股东情况-应出资金额(万元)	CUSTOMERSHAREHOLDER.cs_payableamount	enShareholders
-//				股东情况-出资比例(%)	CUSTOMERSHAREHOLDER.cs_investratio	enShareholders
-//				股东情况-投资日期	CUSTOMERSHAREHOLDER.cs_investdate	enShareholders
-//enShareholders 数据格式:[{'股东': '深圳市瑞联软件技术合伙企业(有限合伙)', '持股比例': '80.00%', '认缴出资额(万元)': '4000', '认缴出资日期': ''}, {'股东': '钟勇斌', '持股比例': '20.00%', '认缴出资额(万元)': '1000', '认缴出资日期': ''}]
-				//System.out.println("股东信息:"+compBaseInfoByErmRest.getEnShareholders());
-				detno = 1;
-				JSONArray enShareholdersList = JSONArray.parseArray(compBaseInfoByErmRest.getEnShareholders());
-				if(enShareholdersList!=null && enShareholdersList.size()>0) {
-					for (int i = 0; i < enShareholdersList.size(); i++) {
-						JSONObject enShareholders = enShareholdersList.getJSONObject(i);
-						Object cs_payableamount = ((enShareholders.get("认缴出资额(万元)")  == null || enShareholders.get("认缴出资额(万元)").equals("-")) ? "null" : enShareholders.get("认缴出资额(万元)") );
-						Object cs_investratio =	(enShareholders.getString("持股比例") == null ? 0 :enShareholders.getString("持股比例").replace("%",""));
-						Object cs_investdate = (enShareholders.getDate("认缴出资日期") == null ? "null" :"to_date('"+ new SimpleDateFormat("yyyy-MM-dd").format(enShareholders.getDate("认缴出资日期"))+"','yyyy-mm-dd')");
-						sqls.add("INSERT INTO CUSTOMERSHAREHOLDER(CS_ID,CS_CUID,CS_DETNO,CS_NAME,CS_PAYABLEAMOUNT,CS_INVESTRATIO,CS_INVESTDATE) VALUES " +
-								"(CUSTOMERSHAREHOLDER_SEQ.NEXTVAL,"+cuId+","+(detno++)+",'"+enShareholders.get("股东")+"',"+cs_payableamount+","+cs_investratio+","+cs_investdate+")");
-					}
-				}
-				//从表4 变更说明 FSCHANGESINSTRUCTION
-//				变更说明-变更科目	FsChangesInstruction.cd_type	enChangingRecords
-//				变更说明-变更时间	FsChangesInstruction.cs_date	enChangingRecords
-//				变更说明-变更前内容	FsChangesInstruction.cs_before	enChangingRecords
-//				变更说明-变更后内容	FsChangesInstruction.cs_after	enChangingRecords
-//数据格式 {'变更次数':1,'变更内容列表':[{'名称变更(字号名称、集团名称等)':[{'2019-06-12':{'before':['深圳','优软商城','科技有限公司'],'after':['深圳','市英唐优软云','科技有限公司']},'2019-06-13':{'before':['深圳','优软商城','科技有限公司'],'after':['深圳','市英唐优软云','科技有限公司']}}]},{...},...]
-				//System.out.println("变更说明:"+compBaseInfoByErmRest.getEnChangingRecords());
-				detno = 1;
-				JSONObject enChangingRecords = JSONObject.parseObject(compBaseInfoByErmRest.getEnChangingRecords());
-				if(enChangingRecords!=null&&enChangingRecords.size()>0&&enChangingRecords.getString("变更内容列表") != null){
-					JSONArray enChangingRecordList = JSONArray.parseArray(enChangingRecords.getString("变更内容列表"));
-					if(enChangingRecordList!=null && enChangingRecordList.size()>0) {
-						for (int i = 0; i < enChangingRecordList.size(); i++) {
-							JSONObject enChangingRecord = enChangingRecordList.getJSONObject(i);
-							Set<Map.Entry<String, Object>> changKey = enChangingRecord.entrySet();
-							for(Map.Entry<String, Object> ckMap : changKey){
-								String cd_type = ckMap.getKey();
-								if(ckMap.getValue()!=null){
-									JSONArray recordByDateList = JSONArray.parseArray(ckMap.getValue().toString());
-									if(recordByDateList != null && recordByDateList.size() > 0) {
-										for (int j = 0; j < recordByDateList.size(); j++) {
-											JSONObject recordByDate = recordByDateList.getJSONObject(j);
-											Set<Map.Entry<String, Object>> recordByDateKey = recordByDate.entrySet();
-											for(Map.Entry<String, Object> cbdMap : recordByDateKey){
-												if(cbdMap.getKey()!=null){
-													String cs_date = "to_date('"+ cbdMap.getKey()+"','yyyy-mm-dd')";
-													JSONObject cbdRecord = JSONObject.parseObject(cbdMap.getValue().toString());
-													//BEFORE
-													StringBuffer beforeStr = new StringBuffer();
-													JSONArray beforeList = JSONArray.parseArray(cbdRecord.getString("before"));
-													Object[] bRecordArr = beforeList.toArray();
-													for(int bi = 0 ; bi < bRecordArr.length; bi++){
-														if(bRecordArr[bi] != null){
-															beforeStr.append(bRecordArr[bi]);
-														}
-													}
-													//AFTER
-													StringBuffer afterStr = new StringBuffer();
-													JSONArray afterList = JSONArray.parseArray(cbdRecord.getString("after"));
-													Object[] aRecordArr = afterList.toArray();
-													for(int ai = 0 ; ai < aRecordArr.length; ai++){
-														if(aRecordArr[ai] != null){
-															afterStr.append(aRecordArr[ai]);
-														}
-													}
-													if(afterStr.length()>0){
-														sqls.add("INSERT INTO FSCHANGESINSTRUCTION(CS_ID,CS_CUID,cd_detno,cd_type,cs_date,cs_before,cs_after) VALUES " +
-																"(FSCHANGESINSTRUCTION_SEQ.NEXTVAL,"+cuId+","+(detno++)+",'"+cd_type+"',"+cs_date+",'"+beforeStr.toString()+"','"+afterStr.toString()+"')");
-													}
-												}
-											}
-										}
-									}
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-		//System.out.println("COMMONSQLS:"+sqls);
-		jdbcTemplate.batchExecute(sqls);
-	}
-
-	  /**
 		* 上传放款信息
 		* @throws Exception
 		*/

+ 730 - 0
src/main/java/com/uas/erp/schedular/finance/task/CustInfomationTask.java

@@ -0,0 +1,730 @@
+package com.uas.erp.schedular.finance.task;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.erp.schedular.task.support.Role;
+import com.uas.erp.schedular.task.support.TaskMapping;
+import com.usoft.fin.external.open.api.entity.*;
+import com.usoft.fin.external.open.api.protobuf.GetBaseInfoReq;
+import com.usoft.fin.external.open.api.protobuf.GetBaseInfoResp;
+import com.usoft.fin.external.open.api.protobuf.GetEnterpriseExtensionInfoReq;
+import com.usoft.fin.external.open.api.protobuf.GetEnterpriseExtensionInfoResp;
+import com.usoft.sdk.fin.client.TradingHallSdk;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Component
+@TaskMapping(title = "U智融对接服务", role = Role.SELLER)
+public class CustInfomationTask extends AbstractTask{
+    private TradingHallSdk tradingHallSdk = new TradingHallSdk("https://finrest.uuzcc.cn", "10050877", "b78d577449b64f56a8a6cf1feeb3fbf5");
+    /**
+     * 客户信息下载
+     * @param enUUList
+     * @throws Exception
+     */
+    public void getCustInfomation(List<Map<String, Object>> enUUList) throws Exception {
+        List<String> sqls = new ArrayList<>();
+        for(Map<String, Object> enMap : enUUList){
+            int custUU = Integer.valueOf(enMap.get("CQ_CUSTUU").toString());//融资方UU--客户
+            //客户基本信息 CompanyBasicInfosByErmRest
+            GetEnterpriseExtensionInfoReq.Builder entExtReq = GetEnterpriseExtensionInfoReq.newBuilder();
+            entExtReq.setEnuu(custUU);  //正式   测试 entExtReq.setEnuu(10050877);
+            GetEnterpriseExtensionInfoResp entExtInfoResp = tradingHallSdk.getEnterpriseExtensionInfo(entExtReq);
+            CompanyBasicInfosByErmRest compBaseInfoByErmRest = entExtInfoResp.getCompanyBasicInfo();
+            if(compBaseInfoByErmRest.getEnName()==null||compBaseInfoByErmRest.getEnName().equals("")){
+                break;
+            }
+            int cuId = jdbcTemplate.getInt("SELECT NVL(MAX(CU_ID),0) FROM CUSTOMERINFOR WHERE CU_STATUSCODE <> 'DISABLE' AND CU_ENUU = ? ", custUU);
+            //System.out.println("cuId:"+cuId);
+            String type = "UPDATE";
+            String cuCode = compBaseInfoByErmRest.getCode();
+            if(cuId == 0){
+                type = "INSERT";
+                cuId = jdbcTemplate.generate("CUSTOMERINFOR_SEQ");
+                cuCode = (compBaseInfoByErmRest.getCode() ==null || compBaseInfoByErmRest.getCode().equals("") )? jdbcTemplate.generateCode("Customer!Infor", 2):compBaseInfoByErmRest.getCode();
+            }
+            //主表 客户资料
+            sqls.addAll(getMainSqls(type,cuId,cuCode,enMap,entExtInfoResp));
+            //从表1 高管信息 CUSTOMEREXCUTIVE
+            sqls.addAll(getOneSqls(type,cuId,compBaseInfoByErmRest.getEnKeyPersonnel()));
+            //从表2 股东信息 CUSTOMERSHAREHOLDER
+            sqls.addAll(getTwoSqls(type,cuId,compBaseInfoByErmRest.getEnShareholders()));
+            //TODO 从表3 主要关联企业 CUSTOMERUDSTREAM 暂未提供
+            //sqls.addAll(getThreeSqls(type,cuId));
+            //从表4 变更说明 FSCHANGESINSTRUCTION
+            sqls.addAll(getFourSqls(type,cuId,compBaseInfoByErmRest.getEnChangingRecords()));
+            //从表5 客户财务报表 CUSTOMERFINANCIAL
+            sqls.addAll(getFiveSqls(type,cuId,entExtInfoResp.getErpDataInfo()));
+            //从表6 经营信息 MANAGEMENTINFO ErpPurchaseInfo ErpSaleInfo
+            sqls.addAll(getSixSqls(type,cuId,entExtInfoResp.getErpDataInfo()));
+            //从表7 上下游信息 UPDOWNINFO
+            sqls.addAll(getSevenSqls(type,cuId,entExtInfoResp.getErpDataInfo()));
+        }
+        //System.out.println("COMMONSQLS:"+sqls);
+        jdbcTemplate.batchExecute(sqls);
+    }
+    //主表 CUSTOMERINFOR SQL
+    private List<String> getMainSqls(String type,int cuId,String cuCode,Map<String, Object> enMap,GetEnterpriseExtensionInfoResp entExtInfoResp) throws Exception{
+        ArrayList<String> sqls = new ArrayList<>();
+        int facUU = enMap.get("CQ_FACTORUU") ==null ? 10050877 :Integer.valueOf(enMap.get("CQ_FACTORUU").toString());//资金方UU
+        int custUU = Integer.valueOf(enMap.get("CQ_CUSTUU").toString());//融资方UU--客户
+        int userUU = enMap.get("CQ_RECORDERUU") ==null ? 0 :Integer.valueOf(enMap.get("CQ_RECORDERUU").toString());//操作人UU
+        //System.out.println("facUU:"+facUU+","+custUU:"+custUU);
+        //企业 融资方信息 RestBaseInfo
+        GetBaseInfoReq.Builder req = GetBaseInfoReq.newBuilder();
+        req.setCsEnuu(facUU);//资金方UU  为空或为0默认保理
+        req.setEnuu(custUU);//融资方UU
+        req.setUu(userUU);//操作人UU 为空就为0
+        GetBaseInfoResp restBaseInfoResp = tradingHallSdk.getBaseInfo(req);
+        RestBaseInfo restBaseInfo = restBaseInfoResp.getBaseInfo();
+//			System.out.println("融资方信息:"+ProtoBufUtil.toJSON(restBaseInfoResp));
+//			System.out.println("融资方信息-客户名称:"+restBaseInfo.getEnName());
+        //客户基本信息 CompanyBasicInfosByErmRest
+        CompanyBasicInfosByErmRest compBaseInfoByErmRest = entExtInfoResp.getCompanyBasicInfo();
+        //扩展信息 CompanyIndustryAndCommerceInfoRest
+        CompanyEnterpriseCrawlerListFinRest entCrawLFRest = entExtInfoResp.getCompanyEnterpriseCrawlerList();
+        CompanyIndustryAndCommerceInfoRest compIndusAndCommInforRest = entCrawLFRest.getCompanyIndustryAndCommerceInfo();
+        //企业简介 员工人数 CompanyIndustryAndCommerceInfoRest.CompanyLawInfoFinRest enIntro insuredNumberOfPeople
+        CompanyLawInfoFinRest compLawInfoRest = entCrawLFRest.getCompanyLawInfo();
+        String cu_term = ((compBaseInfoByErmRest.getEnOpDate()==null || compBaseInfoByErmRest.getEnOpDate().equals(""))? "null" : (compBaseInfoByErmRest.getEnOpDate().contains("无固定期限")?"9999":compBaseInfoByErmRest.getEnOpDate()));
+        String cu_licensedate = (compBaseInfoByErmRest.getEnRegDate()==null||compBaseInfoByErmRest.getEnRegDate().equals("")?"null":"to_date('"+compBaseInfoByErmRest.getEnRegDate()+"','YYYY-MM-DD HH24:MI:SS')");
+        String cu_regcapital = (compBaseInfoByErmRest.getEnRegCapital() ==null || compBaseInfoByErmRest.getEnRegCapital().equals("") ? "null":compBaseInfoByErmRest.getEnRegCapital().replace("万元人民币",""));
+        String cu_paidincapital =(compIndusAndCommInforRest.getContributedCapital() ==null ||compIndusAndCommInforRest.getContributedCapital().equals("") ? "null" : compIndusAndCommInforRest.getContributedCapital().replace("万元人民币",""));
+        String cu_employeesnum = (compIndusAndCommInforRest.getInsuredNumberOfPeople() == null || compIndusAndCommInforRest.getInsuredNumberOfPeople().equals("") ? "null":compIndusAndCommInforRest.getInsuredNumberOfPeople());
+        if(type.equals("INSERT")){
+            sqls.add("INSERT INTO CUSTOMERINFOR(CU_ID,CU_CODE,CU_ENUU,CU_STATUS,CU_STATUSCODE,CU_UPDATEDATE,CU_NAME,CU_LEGALPERSON," +
+                    "CU_TERM,CU_ENTERPTYPE,CU_PLAFORMLEVEL,CU_LICENSEDATE,CU_PAPERSCODE," +
+                    "CU_TAXCREDIT,CU_REGISTSTATUS,CU_BUSINSSCOPE,CU_BUSINESSMAIN," +
+                    "CU_CONTACT,CU_CONTACTNUM,CU_REGCAPITAL,CU_PAIDINCAPITAL," +
+                    "CU_REGADD,CU_OFFICEADD,CU_INTRODUCTION,CU_EMPLOYEESNUM,cu_zjuu" +
+                    ") VALUES ("+cuId+",'"+cuCode+"',"+compBaseInfoByErmRest.getEnuu()+",'在录入','ENTERING',SYSDATE,'"+compBaseInfoByErmRest.getEnName()+"','"+compBaseInfoByErmRest.getEnLegalRepName()+"',"
+                    +cu_term+","+"'"+compBaseInfoByErmRest.getEnType()+"','"+restBaseInfo.getGrade()+"'," +cu_licensedate+",'"+compBaseInfoByErmRest.getEnCodeCrawled()+"',"+
+                    "'"+entCrawLFRest.getConTheTaxCredit()+"','"+compBaseInfoByErmRest.getEnRegStatus()+"','"+compBaseInfoByErmRest.getEnOpRange()+"','"+restBaseInfo.getEnBusinessMain()+"',"+
+                    "'"+restBaseInfo.getFsContactsMan()+"','"+restBaseInfo.getFsContactsPhone()+"',"+cu_regcapital+","+cu_paidincapital+",'"
+                    +compBaseInfoByErmRest.getEnRegLocation()+"','"+restBaseInfo.getEnAddress()+"','"+compLawInfoRest.getEnIntro()+"',"+cu_employeesnum+",'10050877')");
+            sqls.add("UPDATE CUSTOMERQUOTA SET cq_custcode ='"+cuCode+"' where cq_custcode is null and CQ_CUSTUU = "+custUU);
+        }else {
+            sqls.add("UPDATE CUSTOMERQUOTA SET CQ_CUSTCODE = (SELECT CU_CODE FROM CUSTOMERINFOR WHERE CU_ID = "+cuId+") where CQ_CUSTCODE is null and CQ_CUSTUU = "+custUU);
+            sqls.add("UPDATE CUSTOMERINFOR SET " +
+                    " CU_STATUS='在录入',CU_STATUSCODE='ENTERING'," +
+                    " CU_UPDATEDATE=SYSDATE,CU_NAME='"+compBaseInfoByErmRest.getEnName()+"',CU_LEGALPERSON='"+compBaseInfoByErmRest.getEnLegalRepName()+"'," +
+                    " CU_TERM = "+cu_term+",CU_ENTERPTYPE ='"+compBaseInfoByErmRest.getEnType()+"',CU_PLAFORMLEVEL='"+restBaseInfo.getGrade()+"'," +
+                    " CU_LICENSEDATE = "+cu_licensedate+",CU_PAPERSCODE='"+compBaseInfoByErmRest.getEnCodeCrawled()+"'," +
+                    " CU_TAXCREDIT ='"+entCrawLFRest.getConTheTaxCredit()+"',CU_REGISTSTATUS='"+compBaseInfoByErmRest.getEnRegStatus()+"',CU_BUSINSSCOPE='"+compBaseInfoByErmRest.getEnOpRange()+"',CU_BUSINESSMAIN='"+restBaseInfo.getEnBusinessMain()+"'," +
+                    " CU_CONTACT='"+restBaseInfo.getFsContactsMan()+"',CU_CONTACTNUM='"+restBaseInfo.getFsContactsPhone()+"',CU_REGCAPITAL="+cu_regcapital+",CU_PAIDINCAPITAL="+cu_paidincapital+"," +
+                    " CU_REGADD='"+compBaseInfoByErmRest.getEnRegLocation()+"',CU_OFFICEADD='"+restBaseInfo.getEnAddress()+"',CU_INTRODUCTION='"+compLawInfoRest.getEnIntro()+"',CU_ZJUU='"+10050877+"'," +
+                    " CU_EMPLOYEESNUM=" +cu_employeesnum+
+                    " WHERE CU_ENUU = "+custUU+" AND CU_STATUSCODE <> 'DISABLE'");
+        }
+        return sqls;
+    }
+    /**
+     * 从表1 SQL CUSTOMEREXCUTIVE
+     * @param type  处理类型 INSERT UPDATE
+     * @param cuId	客户主表id
+     * @param enKeyPersonnel 数据格式:[{'陈亚荣': '总经理'}, {'陈正明': '执行董事'}, {'陈劲松': '监事'}]
+     *                       高管信息-高管姓名	CUSTOMEREXCUTIVE.ce_name == enKeyPersonnel
+     *                       高管信息-担任职务 	CUSTOMEREXCUTIVE.ce_position === enKeyPersonnel
+     */
+    private List<String> getOneSqls(String type,int cuId,String enKeyPersonnel){
+        List<String> sqls = new ArrayList<>();
+        //System.out.println("更新高管信息:"+enKeyPersonnel);
+        JSONArray enKeyPerList = JSONArray.parseArray(enKeyPersonnel);
+        if(enKeyPerList!=null && enKeyPerList.size()>0){
+            for(int ei = 0;ei < enKeyPerList.size();ei++){
+                JSONObject ek = enKeyPerList.getJSONObject(ei);
+                Set<Map.Entry<String, Object>> ekKeySet = ek.entrySet();
+                if(ekKeySet!= null && ekKeySet.size()>0){
+                    for(Map.Entry<String, Object> ekMap : ekKeySet){
+                        sqls.add("MERGE INTO CUSTOMEREXCUTIVE INCUSTOMEREXCUTIVE " +
+                                " USING (SELECT NVL(MAX(CE_ID),0) CE_ID FROM CUSTOMEREXCUTIVE WHERE CE_CUID = "+cuId+" AND CE_NAME = '"+ekMap.getKey()+"' AND CE_POSITION ='"+ekMap.getValue()+"') " +
+                                " ONINCUSTOMEREXCUTIVE " +
+                                " ON (INCUSTOMEREXCUTIVE.CE_ID = ONINCUSTOMEREXCUTIVE.CE_ID) " +
+                                " WHEN NOT MATCHED THEN " +
+                                " INSERT (INCUSTOMEREXCUTIVE.CE_ID,INCUSTOMEREXCUTIVE.CE_CUID,INCUSTOMEREXCUTIVE.CE_DETNO,INCUSTOMEREXCUTIVE.CE_NAME,INCUSTOMEREXCUTIVE.CE_POSITION) " +
+                                " VALUES(CUSTOMEREXCUTIVE_seq.nextval,"+cuId+",9999,'"+ekMap.getKey()+"','"+ekMap.getValue()+"')");
+                    }
+                }
+            }
+            sqls.add("UPDATE CUSTOMEREXCUTIVE SET CE_DETNO = (select RN from (SELECT ROWNUM RN,CE_ID FROM " +
+                    "	(SELECT CE_ID FROM CUSTOMEREXCUTIVE WHERE CE_CUID = " + cuId + " ORDER BY CE_DETNO ASC,CE_ID ASC)) TT where TT.CE_ID = CUSTOMEREXCUTIVE.CE_ID) " +
+                    "WHERE CE_CUID = " + cuId);
+        }
+        return sqls;
+    }
+    /**
+     * 从表2 股东信息 CUSTOMERSHAREHOLDER
+     * @param type
+     * @param cuId
+     * @param enShareholders_Str compBaseInfoByErmRest.getEnShareholders()
+     *                           enShareholders 数据格式:[{'股东': '深圳市瑞联软件技术合伙企业(有限合伙)', '持股比例': '80.00%', '认缴出资额(万元)': '4000', '认缴出资日期': ''}, {'股东': '钟勇斌', '持股比例': '20.00%', '认缴出资额(万元)': '1000', '认缴出资日期': ''}]
+     *                           股东情况-股东名称	CUSTOMERSHAREHOLDER.cs_name	== enShareholders
+     *                           股东情况-应出资金额(万元)	CUSTOMERSHAREHOLDER.cs_payableamount == enShareholders
+     *                           股东情况-出资比例(%)	CUSTOMERSHAREHOLDER.cs_investratio	== enShareholders
+     *                           股东情况-投资日期	CUSTOMERSHAREHOLDER.cs_investdate == enShareholders
+     */
+    private List<String> getTwoSqls(String type,int cuId,String enShareholders_Str){
+        List<String> sqls = new ArrayList<>();
+        //System.out.println("更新股东信息:"+compBaseInfoByErmRest.getEnShareholders());
+        JSONArray enShareholdersList = JSONArray.parseArray(enShareholders_Str);
+        if(enShareholdersList!=null && enShareholdersList.size()>0) {
+            for (int i = 0; i < enShareholdersList.size(); i++) {
+                JSONObject enShareholders = enShareholdersList.getJSONObject(i);
+                Object cs_payableamount = ((enShareholders.get("认缴出资额(万元)")  == null || enShareholders.get("认缴出资额(万元)").equals("-")) ? "null" : enShareholders.get("认缴出资额(万元)") );
+                Object cs_investratio =	(enShareholders.getString("持股比例") == null ? 0 :enShareholders.getString("持股比例").replace("%",""));
+                Object cs_investdate = (enShareholders.getDate("认缴出资日期") == null ? "null" :"to_date('"+ new SimpleDateFormat("yyyy-MM-dd").format(enShareholders.getDate("认缴出资日期"))+"','yyyy-mm-dd')");
+                sqls.add("MERGE INTO CUSTOMERSHAREHOLDER INHOLDER " +
+                        " USING (SELECT NVL(MAX(CS_ID),0) CS_ID FROM CUSTOMERSHAREHOLDER WHERE CS_CUID = "+cuId+" AND CS_NAME = '"+enShareholders.get("股东")+"') ONHOLDER " +
+                        " ON (INHOLDER.CS_ID = ONHOLDER.CS_ID) " +
+                        " WHEN MATCHED THEN " +
+                        " UPDATE SET CS_DETNO = 9999, INHOLDER.CS_PAYABLEAMOUNT="+cs_payableamount+",INHOLDER.CS_INVESTRATIO="+cs_investratio+",INHOLDER.CS_INVESTDATE="+cs_investdate+" " +
+                        " WHEN NOT MATCHED THEN " +
+                        " INSERT (INHOLDER.CS_ID,INHOLDER.CS_CUID,INHOLDER.CS_DETNO,INHOLDER.CS_NAME,INHOLDER.CS_PAYABLEAMOUNT,INHOLDER.CS_INVESTRATIO,INHOLDER.CS_INVESTDATE) " +
+                        " VALUES(CUSTOMERSHAREHOLDER_SEQ.NEXTVAL,"+cuId+",9999,'"+enShareholders.get("股东")+"',"+cs_payableamount+","+cs_investratio+","+cs_investdate+")");
+            }
+            sqls.add("UPDATE CUSTOMERSHAREHOLDER SET CS_DETNO = (select RN from (SELECT ROWNUM RN,CS_ID FROM " +
+                    "	(SELECT CS_ID FROM CUSTOMERSHAREHOLDER WHERE CS_CUID = "+cuId+" ORDER BY CS_DETNO ASC,CS_ID ASC)) TT where TT.CS_ID = CUSTOMERSHAREHOLDER.CS_ID) " +
+                    "WHERE CS_CUID = "+cuId);
+        }
+        return sqls;
+    }
+    /**
+     * 从表3 主要关联企业 CUSTOMERUDSTREAM 暂未提供
+     * @param type
+     * @param cuId
+     * @return
+     */
+    private List<String> getThreeSqls(String type,int cuId){
+        List<String> sqls = new ArrayList<>();
+        return sqls;
+    }
+    /**
+     * 从表4 变更说明 FSCHANGESINSTRUCTION
+     * @param type
+     * @param cuId
+     * @param enChangingRecords_Str compBaseInfoByErmRest.getEnChangingRecords()
+     *                              EnChangingRecords 数据格式 {'变更次数':1,'变更内容列表':[{'名称变更(字号名称、集团名称等)':[{'2019-06-12':{'before':['深圳','优软商城','科技有限公司'],'after':['深圳','市英唐优软云','科技有限公司']},'2019-06-13':{'before':['深圳','优软商城','科技有限公司'],'after':['深圳','市英唐优软云','科技有限公司']}}]},{...},...]
+     *                              变更说明-变更科目	FsChangesInstruction.cd_type	enChangingRecords
+     *                              变更说明-变更时间	FsChangesInstruction.cs_date	enChangingRecords
+     *                              变更说明-变更前内容	FsChangesInstruction.cs_before	enChangingRecords
+     *                              变更说明-变更后内容	FsChangesInstruction.cs_after	enChangingRecords
+     */
+    private List<String> getFourSqls(String type,int cuId,String enChangingRecords_Str){
+        List<String> sqls = new ArrayList<>();
+        //System.out.println("更新变更说明:"+enChangingRecords_Str);
+        JSONObject enChangingRecords = JSONObject.parseObject(enChangingRecords_Str);
+        if(enChangingRecords!=null&&enChangingRecords.size()>0&&enChangingRecords.getString("变更内容列表") != null){
+            JSONArray enChangingRecordList = JSONArray.parseArray(enChangingRecords.getString("变更内容列表"));
+            if(enChangingRecordList!=null && enChangingRecordList.size()>0) {
+                int detno = 1;
+                if(type.equals("UPDATE")){
+                    sqls.add("DELETE FSCHANGESINSTRUCTION WHERE CS_CUID = "+cuId);
+                }
+                for (int i = 0; i < enChangingRecordList.size(); i++) {
+                    JSONObject enChangingRecord = enChangingRecordList.getJSONObject(i);
+                    Set<Map.Entry<String, Object>> changKey = enChangingRecord.entrySet();
+                    for(Map.Entry<String, Object> ckMap : changKey){
+                        String cd_type = ckMap.getKey();
+                        if(ckMap.getValue()!=null){
+                            JSONArray recordByDateList = JSONArray.parseArray(ckMap.getValue().toString());
+                            if(recordByDateList != null && recordByDateList.size() > 0) {
+                                for (int j = 0; j < recordByDateList.size(); j++) {
+                                    JSONObject recordByDate = recordByDateList.getJSONObject(j);
+                                    Set<Map.Entry<String, Object>> recordByDateKey = recordByDate.entrySet();
+                                    for(Map.Entry<String, Object> cbdMap : recordByDateKey){
+                                        if(cbdMap.getKey()!=null){
+                                            String cs_date = "to_date('"+ cbdMap.getKey()+"','yyyy-mm-dd')";
+                                            JSONObject cbdRecord = JSONObject.parseObject(cbdMap.getValue().toString());
+                                            //BEFORE
+                                            StringBuffer beforeStr = new StringBuffer();
+                                            JSONArray beforeList = JSONArray.parseArray(cbdRecord.getString("before"));
+                                            Object[] bRecordArr = beforeList.toArray();
+                                            for(int bi = 0 ; bi < bRecordArr.length; bi++){
+                                                if(bRecordArr[bi] != null){
+                                                    beforeStr.append(bRecordArr[bi]);
+                                                }
+                                            }
+                                            //AFTER
+                                            StringBuffer afterStr = new StringBuffer();
+                                            JSONArray afterList = JSONArray.parseArray(cbdRecord.getString("after"));
+                                            Object[] aRecordArr = afterList.toArray();
+                                            for(int ai = 0 ; ai < aRecordArr.length; ai++){
+                                                if(aRecordArr[ai] != null){
+                                                    afterStr.append(aRecordArr[ai]);
+                                                }
+                                            }
+                                            if(afterStr.length()>0){
+                                                sqls.add("INSERT INTO FSCHANGESINSTRUCTION(CS_ID,CS_CUID,cd_detno,cd_type,cs_date,cs_before,cs_after) VALUES " +
+                                                        "(FSCHANGESINSTRUCTION_SEQ.NEXTVAL,"+cuId+","+(detno++)+",'"+cd_type+"',"+cs_date+",'"+beforeStr.toString()+"','"+afterStr.toString()+"')");
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return sqls;
+    }
+
+    /**
+     * 从表5 客户财务报表 CUSTOMERFINANCIAL
+     * @param type
+     * @param cuId
+     * @param erpDataInfoRest
+     * @return
+     */
+    private List<String> getFiveSqls(String type,int cuId,ErpDataInfoRest erpDataInfoRest) throws Exception{
+        List<String> sqls = new ArrayList<>();
+        int detno = 1;
+        if(type.equals("UPDATE")){
+            sqls.add("DELETE CUSTOMERFINANCIAL WHERE CF_CUID = "+cuId);
+        }
+        List<Map<String,Object>> inMsgList = new ArrayList<>();
+        Calendar date = Calendar.getInstance();
+        int year = Integer.valueOf(String.valueOf(date.get(Calendar.YEAR)));
+        //利润表(元) ErpProfitInfo CF_REPORTTYPE = 利润表(元)
+        inMsgList.addAll(getErpProfitInfoLists(year,"利润表(元)",erpDataInfoRest.getErpProfitList()));
+        //资产负债表(元) ErpBalanceSheetInfo CF_REPORTTYPE = 资产负债表(元)
+        inMsgList.addAll(getErpBalanceSheetInfoLists(year,"资产负债表(元)",erpDataInfoRest.getErpBalanceSheetList()));
+        //现金流量表(元) ErpCashFlowInfo CF_REPORTTYPE = 现金流量表(元)
+        inMsgList.addAll(getErpCashFlowLists(year,"现金流量表(元)",erpDataInfoRest.getErpCashFlowList()));
+        //盈利能力指标 资产质量指标 债务风险指标 经营增长指标
+        inMsgList.addAll(getCalculationOfEachIndexLists(erpDataInfoRest));
+        for(Map<String,Object> map : inMsgList){
+            Double[] DATAS = (Double[])map.get("DATAS");
+            sqls.add("INSERT INTO CUSTOMERFINANCIAL (CF_ID, CF_CUID, CF_DETNO,CF_REPORTTYPE,CF_PROJECTTYPE," +
+                    "CF_LASTMONTH, CF_YEAR1, CF_YEAR2, CF_YEAR3, CF_YEAR4)" +
+                    "VALUES (CUSTOMERFINANCIAL_SEQ.NEXTVAL,"+cuId+","+(detno++)+",'"+map.get("CF_REPORTTYPE")+"','"+map.get("CF_PROJECTTYPE")+"'," +
+                    ""+(DATAS[0] == null ? "NULL" : DATAS[0])+","+(DATAS[1] == null ? "NULL" : DATAS[1])+","+(DATAS[2] == null ? "NULL" : DATAS[2])+"," +
+                    ""+(DATAS[3] == null ? "NULL" : DATAS[3])+","+(DATAS[4] == null ? "NULL" : DATAS[4])+")");
+        }
+        return sqls;
+    }
+    //从表4 客户财务报表 利润表(元)
+    private List<Map<String,Object>> getErpProfitInfoLists(int year,String reporttype,List<ErpProfitInfo> erpProfitInfoList){
+        List<Map<String,Object>> inMsgList = new ArrayList<>();
+        Map<String,Object> inMsgMap = new HashMap<>();
+        //System.out.println("从表4 客户财务报表 利润表(元): "+ProtoBufUtil.toJSON(erpProfitInfoList));
+        if(erpProfitInfoList.size() == 0){
+            return inMsgList;
+        }
+        Double[] businessIncomeList = new Double[5];
+        Double[] operatingCostList = new Double[5];
+        Double[] operatingProfitList = new Double[5];
+        Double[] netProfitList = new Double[5];
+        for(ErpProfitInfo erpProfitInfo : erpProfitInfoList){
+            int gap = year - erpProfitInfo.getYear();
+            //营业收入 businessIncome
+            businessIncomeList[gap] = erpProfitInfo.getBusinessIncome();
+            //营业成本 operatingCost
+            operatingCostList[gap] = erpProfitInfo.getOperatingCost();
+            //营业利润 operatingProfit
+            operatingProfitList[gap] = erpProfitInfo.getOperatingProfit();
+            //净利润 netProfit
+            netProfitList[gap] = erpProfitInfo.getNetProfit();
+        }
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","营业收入");
+        inMsgMap.put("DATAS",businessIncomeList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","营业成本");
+        inMsgMap.put("DATAS",operatingCostList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","营业利润");
+        inMsgMap.put("DATAS",operatingProfitList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","净利润");
+        inMsgMap.put("DATAS",netProfitList);
+        inMsgList.add(inMsgMap);
+        return inMsgList;
+    }
+    //从表4 客户财务报表 资产负债表(元)
+    private List<Map<String,Object>> getErpBalanceSheetInfoLists(int year,String reporttype,List<ErpBalanceSheetInfo> erpBalanceSheetInfoList) {
+        List<Map<String,Object>> inMsgList = new ArrayList<>();
+       // System.out.println("从表4 客户财务报表 资产负债表(元): "+ ProtoBufUtil.toJSON(erpBalanceSheetInfoList));
+        if(erpBalanceSheetInfoList.size() == 0){
+            return inMsgList;
+        }
+        Double[] accountsReceivableList = new Double[5];  //应收账款 accountsReceivable
+        Double[] currentAssetsCountList = new Double[5]; //流动资产合计 currentAssetsCount
+        Double[] assetsCountList = new Double[5]; //资产合计 assetsCount
+        Double[] currentLiabilitiesCountList = new Double[5];//流动负债合计 currentLiabilitiesCount
+        Double[] liabilitiesCountList = new Double[5];//负债合计 liabilitiesCount
+        Double[] ownersEquityList = new Double[5];//所有者权益合计 ownersEquity
+        for(ErpBalanceSheetInfo erpBalanceSheetInfo : erpBalanceSheetInfoList){
+            int gap = year - erpBalanceSheetInfo.getYear();
+            accountsReceivableList[gap] = erpBalanceSheetInfo.getAccountsReceivable();
+            currentAssetsCountList[gap] = erpBalanceSheetInfo.getCurrentAssetsCount();
+            assetsCountList[gap] = erpBalanceSheetInfo.getAssetsCount();
+            currentLiabilitiesCountList[gap] = erpBalanceSheetInfo.getCurrentLiabilitiesCount();
+            liabilitiesCountList[gap] = erpBalanceSheetInfo.getLiabilitiesCount();
+            ownersEquityList[gap] = erpBalanceSheetInfo.getOwnersEquity();
+        }
+        Map<String,Object> inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","应收账款");
+        inMsgMap.put("DATAS",accountsReceivableList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","流动资产合计");
+        inMsgMap.put("DATAS",currentAssetsCountList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","资产合计");
+        inMsgMap.put("DATAS",assetsCountList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","流动负债合计");
+        inMsgMap.put("DATAS",currentLiabilitiesCountList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","负债合计");
+        inMsgMap.put("DATAS",liabilitiesCountList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","负债合计");
+        inMsgMap.put("DATAS",ownersEquityList);
+        inMsgList.add(inMsgMap);
+        return inMsgList;
+    }
+    //从表4 客户财务报表 现金流量表(元)
+    private List<Map<String,Object>> getErpCashFlowLists(int year,String reporttype,List<ErpCashFlowInfo> erpCashFlowInfoList) {
+        List<Map<String,Object>> inMsgList = new ArrayList<Map<String,Object>>();
+        if(erpCashFlowInfoList.size() == 0){
+            return inMsgList;
+        }
+        //System.out.println("从表4 客户财务报表 现金流量表(元): "+ProtoBufUtil.toJSON(erpCashFlowInfoList));
+        Double[] operatingCashFlowList = new Double[5];//经营活动产生的现金流量净额 operatingCashFlow
+        Double[] investmentCashFlowList = new Double[5];//投资活动产生的现金流量净额 investmentCashFlow
+        Double[] financingCashFlowList = new Double[5];//筹资活动产生的现金流量净额 financingCashFlow
+        Double[] netCashFlowList = new Double[5];//现金及现金等价物净增加额 netCashFlow
+        for(ErpCashFlowInfo erpCashFlowInfo : erpCashFlowInfoList){
+            int gap = year - erpCashFlowInfo.getYear();
+            operatingCashFlowList[gap] = erpCashFlowInfo.getOperatingCashFlow();
+            investmentCashFlowList[gap] = erpCashFlowInfo.getInvestmentCashFlow();
+            financingCashFlowList[gap] = erpCashFlowInfo.getFinancingCashFlow();
+            netCashFlowList[gap] = erpCashFlowInfo.getNetCashFlow();
+        }
+        Map<String,Object> inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","经营活动产生的现金流量净额");
+        inMsgMap.put("DATAS",operatingCashFlowList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","投资活动产生的现金流量净额");
+        inMsgMap.put("DATAS",investmentCashFlowList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","筹资活动产生的现金流量净额");
+        inMsgMap.put("DATAS",financingCashFlowList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        inMsgMap.put("CF_REPORTTYPE",reporttype);
+        inMsgMap.put("CF_PROJECTTYPE","现金及现金等价物净增加额");
+        inMsgMap.put("DATAS",netCashFlowList);
+        inMsgList.add(inMsgMap);
+        return inMsgList;
+    }
+    //从表4 盈利能力指标 资产质量指标 债务风险指标 经营增长指标 数据格式:[{"turnoverRateOfNetAssets":30.49,"returnOnTotalAssets":6.87,"salesProfitMargin":4.02,"turnoverRateOfTotalAssets":1.11,"turnoverRateOfAccountsReceivable":4.15,"inventoryTurnoverSpeed":6.81,"assetLiabilityRatio":86.76,"cashFlowLiabilityRatio":-9.34,"quickRatio":68.46,"salesGrowthRate":34.89,"operatingProfitGrowthRate":-68.12,"growthRateOfTotalAssets":50.48}]
+    private List<Map<String,Object>> getCalculationOfEachIndexLists(ErpDataInfoRest erpDataInfoRest){
+        List<Map<String,Object>> inMsgList = new ArrayList<Map<String,Object>>();
+        //最近月份
+        ErpCalculationOfEachIndex curYear = erpDataInfoRest.getErpCalculationOfEachIndexYearList().get(0);
+        //System.out.println("盈利能力指标..-最近月份: "+ProtoBufUtil.toJSON(curYear));
+        //前一年
+        ErpCalculationOfEachIndex lastYear = erpDataInfoRest.getErpCalculationOfEachIndexLastYearList().get(0);
+        //System.out.println("盈利能力指标..-前一年: "+ProtoBufUtil.toJSON(lastYear));
+        //前两年
+        ErpCalculationOfEachIndex twoYearsBefore = erpDataInfoRest.getErpCalculationOfEachIndexBeforeYearList().get(0);
+        //System.out.println("盈利能力指标..-前两年: "+ProtoBufUtil.toJSON(twoYearsBefore));
+        //前三年
+        ErpCalculationOfEachIndex thereYearsBefore = erpDataInfoRest.getErpCalculationOfEachIndexBeforeLastYearList().get(0);
+        //System.out.println("盈利能力指标..-前三年: "+ProtoBufUtil.toJSON(thereYearsBefore));
+        //盈利能力指标
+        Map<String,Object> inMsgMap = new HashMap<>();
+        Double[] dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","盈利能力指标");
+        inMsgMap.put("CF_PROJECTTYPE","净资产周转率(%)");//turnoverRateOfNetAssets
+        dataList[0] = curYear.getTurnoverRateOfNetAssets();
+        dataList[1] = lastYear.getTurnoverRateOfNetAssets();
+        dataList[2] = twoYearsBefore.getTurnoverRateOfNetAssets();
+        dataList[3] = thereYearsBefore.getTurnoverRateOfNetAssets();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","盈利能力指标");
+        inMsgMap.put("CF_PROJECTTYPE","总资产报酬率(%)");//returnOnTotalAssets
+        dataList[0] = curYear.getReturnOnTotalAssets();
+        dataList[1] = lastYear.getReturnOnTotalAssets();
+        dataList[2] = twoYearsBefore.getReturnOnTotalAssets();
+        dataList[3] = thereYearsBefore.getReturnOnTotalAssets();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","盈利能力指标");
+        inMsgMap.put("CF_PROJECTTYPE","销售(营业)利润率(%)");//salesProfitMargin
+        dataList[0] = curYear.getSalesProfitMargin();
+        dataList[1] = lastYear.getSalesProfitMargin();
+        dataList[2] = twoYearsBefore.getSalesProfitMargin();
+        dataList[3] = thereYearsBefore.getSalesProfitMargin();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        //资产质量指标
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","资产质量指标");
+        inMsgMap.put("CF_PROJECTTYPE","总资产周转率(次)");//turnoverRateOfTotalAssets
+        dataList[0] = curYear.getTurnoverRateOfTotalAssets();
+        dataList[1] = lastYear.getTurnoverRateOfTotalAssets();
+        dataList[2] = twoYearsBefore.getTurnoverRateOfTotalAssets();
+        dataList[3] = thereYearsBefore.getTurnoverRateOfTotalAssets();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","资产质量指标");
+        inMsgMap.put("CF_PROJECTTYPE","应收账款周转率(次)");//turnoverRateOfAccountsReceivable
+        dataList[0] = curYear.getTurnoverRateOfAccountsReceivable();
+        dataList[1] = lastYear.getTurnoverRateOfAccountsReceivable();
+        dataList[2] = twoYearsBefore.getTurnoverRateOfAccountsReceivable();
+        dataList[3] = thereYearsBefore.getTurnoverRateOfAccountsReceivable();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","资产质量指标");
+        inMsgMap.put("CF_PROJECTTYPE","存货周转速度(次)");//inventoryTurnoverSpeed
+        dataList[0] = curYear.getInventoryTurnoverSpeed();
+        dataList[1] = lastYear.getInventoryTurnoverSpeed();
+        dataList[2] = twoYearsBefore.getInventoryTurnoverSpeed();
+        dataList[3] = thereYearsBefore.getInventoryTurnoverSpeed();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        //债务风险指标
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","债务风险指标");
+        inMsgMap.put("CF_PROJECTTYPE","资产负债率(%)");//assetLiabilityRatio
+        dataList[0] = curYear.getAssetLiabilityRatio();
+        dataList[1] = lastYear.getAssetLiabilityRatio();
+        dataList[2] = twoYearsBefore.getAssetLiabilityRatio();
+        dataList[3] = thereYearsBefore.getAssetLiabilityRatio();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","债务风险指标");
+        inMsgMap.put("CF_PROJECTTYPE","现金流动负债比率(%)");//cashFlowLiabilityRatio
+        dataList[0] = curYear.getCashFlowLiabilityRatio();
+        dataList[1] = lastYear.getCashFlowLiabilityRatio();
+        dataList[2] = twoYearsBefore.getCashFlowLiabilityRatio();
+        dataList[3] = thereYearsBefore.getCashFlowLiabilityRatio();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","债务风险指标");
+        inMsgMap.put("CF_PROJECTTYPE","速动比率(%)");//quickRatio
+        dataList[0] = curYear.getQuickRatio();
+        dataList[1] = lastYear.getQuickRatio();
+        dataList[2] = twoYearsBefore.getQuickRatio();
+        dataList[3] = thereYearsBefore.getQuickRatio();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        //经营增长指标
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","经营增长指标");
+        inMsgMap.put("CF_PROJECTTYPE","销售增长率(%)");//salesGrowthRate
+        dataList[0] = curYear.getSalesGrowthRate();
+        dataList[1] = lastYear.getSalesGrowthRate();
+        dataList[2] = twoYearsBefore.getSalesGrowthRate();
+        dataList[3] = thereYearsBefore.getSalesGrowthRate();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","经营增长指标");
+        inMsgMap.put("CF_PROJECTTYPE","销售(营业)利润增长率(%)");//operatingProfitGrowthRate
+        dataList[0] = curYear.getOperatingProfitGrowthRate();
+        dataList[1] = lastYear.getOperatingProfitGrowthRate();
+        dataList[2] = twoYearsBefore.getOperatingProfitGrowthRate();
+        dataList[3] = thereYearsBefore.getOperatingProfitGrowthRate();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        inMsgMap = new HashMap<>();
+        dataList = new Double[5];
+        inMsgMap.put("CF_REPORTTYPE","经营增长指标");
+        inMsgMap.put("CF_PROJECTTYPE","总资产增长率(%)");//growthRateOfTotalAssets
+        dataList[0] = curYear.getGrowthRateOfTotalAssets();
+        dataList[1] = lastYear.getGrowthRateOfTotalAssets();
+        dataList[2] = twoYearsBefore.getGrowthRateOfTotalAssets();
+        dataList[3] = thereYearsBefore.getGrowthRateOfTotalAssets();
+        inMsgMap.put("DATAS",dataList);
+        inMsgList.add(inMsgMap);
+        return inMsgList;
+    }
+
+    /**
+     * 从表6 经营信息 MANAGEMENTINFO
+     * @param type
+     * @param cuId
+     * @param erpDataInfoRest ErpPurchaseInfo ErpSaleInfo
+     *                        数据格式
+     */
+    private List<String> getSixSqls(String type,int cuId,ErpDataInfoRest erpDataInfoRest) throws Exception{
+        List<String> sqls = new ArrayList<>();
+        if(type.equals("UPDATE")){
+            sqls.add("DELETE MANAGEMENTINFO WHERE MT_CUID = "+cuId);
+        }
+        Calendar date = Calendar.getInstance();
+        int year = Integer.valueOf(String.valueOf(date.get(Calendar.YEAR)));
+        List<ErpPurchaseInfo>  erpPurchaseList = erpDataInfoRest.getErpPurchaseList();
+        List<ErpSaleInfo> erpSaleList = erpDataInfoRest.getErpSaleList() ;
+//        System.out.println("经营信息 采购情况: "+ProtoBufUtil.toJSON(erpPurchaseList));
+//        System.out.println("经营信息 销售情况: "+ProtoBufUtil.toJSON(erpSaleList));
+        Map<String,Object> maMsg = new HashMap<>();
+        for(ErpPurchaseInfo erpPurchaseInfo: erpPurchaseList){
+            int gap = year - erpPurchaseInfo.getYear();
+            switch (gap){
+                case 0:
+                    maMsg.put("MT_CTOTALPUR",erpPurchaseInfo.getPurchaseTotal());
+                    maMsg.put("MT_SUPPLIER",erpPurchaseInfo.getSuppliersNumber());
+                    break;
+                case 1:
+                    maMsg.put("MT_LASTTOTALPUR",erpPurchaseInfo.getPurchaseTotal());
+                    maMsg.put("MT_LASTSUPPLIER",erpPurchaseInfo.getSuppliersNumber());
+                    break;
+                default:
+                    break;
+            }
+        }
+        for(ErpSaleInfo erpSaleInfo: erpSaleList){
+            int gap = year - erpSaleInfo.getYear();
+            switch (gap){
+                case 0:
+                    maMsg.put("MT_GROSSSALES",erpSaleInfo.getSalesTotal());
+                    maMsg.put("MT_CUSTOMERNUM",erpSaleInfo.getCustomersCount());
+                    break;
+                case 1:
+                    maMsg.put("MT_LGROSSSALES",erpSaleInfo.getSalesTotal());
+                    maMsg.put("MT_LCUSTOMERNUM",erpSaleInfo.getCustomersCount());
+                    break;
+                default:
+                    break;
+            }
+        }
+        sqls.add("INSERT INTO MANAGEMENTINFO (MT_ID, MT_CUID, MT_DETNO, MT_CTOTALPUR, MT_LASTTOTALPUR, MT_SUPPLIER, " +
+                "MT_LASTSUPPLIER, MT_GROSSSALES, MT_LGROSSSALES, MT_CUSTOMERNUM, MT_LCUSTOMERNUM)" +
+                "VALUES (MANAGEMENTINFO_SEQ.NEXTVAL,"+cuId+",1,'"+maMsg.get("MT_CTOTALPUR")+"','"+maMsg.get("MT_LASTTOTALPUR")+"','"+maMsg.get("MT_SUPPLIER")+"'," +
+                "'"+maMsg.get("MT_LASTSUPPLIER")+"','"+maMsg.get("MT_GROSSSALES")+"','"+maMsg.get("MT_LGROSSSALES")+"','"+maMsg.get("MT_CUSTOMERNUM")+"','"+maMsg.get("MT_LCUSTOMERNUM")+"')");
+        return sqls;
+    }
+    /**
+     * 从表7 上下游信息 UPDOWNINFO
+     * @param type
+     * @param cuId
+     * @param erpDataInfoRest
+     * @return
+     */
+    private List<String> getSevenSqls(String type,int cuId,ErpDataInfoRest erpDataInfoRest){
+        List<String> sqls = new ArrayList<>();
+        if(type.equals("UPDATE")){
+            sqls.add("DELETE UPDOWNINFO WHERE UI_CUID = "+cuId);
+        }
+        Calendar date = Calendar.getInstance();
+        int year = Integer.valueOf(String.valueOf(date.get(Calendar.YEAR)));
+        List<ErpPurchaseInfo>  erpPurchaseList = erpDataInfoRest.getErpPurchaseList();
+        List<ErpSaleInfo> erpSaleList = erpDataInfoRest.getErpSaleList() ;
+        //System.out.println("经营信息 采购情况: "+ProtoBufUtil.toJSON(erpPurchaseList));
+        //System.out.println("经营信息 销售情况: "+ProtoBufUtil.toJSON(erpSaleList));
+        List<ErpTopFiveSuppliersInfo> purLastYear = new ArrayList<ErpTopFiveSuppliersInfo>();
+        List<ErpTopFiveSuppliersInfo> purTwoYearsBefore = new ArrayList<ErpTopFiveSuppliersInfo>();
+        for(ErpPurchaseInfo erpPurchaseInfo: erpPurchaseList){
+            int gap = year - erpPurchaseInfo.getYear();
+            switch (gap){
+                case 1:
+                    purLastYear = erpPurchaseInfo.getTopFiveSuppliersList();
+                    break;
+                case 2:
+                    purTwoYearsBefore = erpPurchaseInfo.getTopFiveSuppliersList();
+                    break;
+                default:
+                    break;
+            }
+        }
+        List<ErpTopFiveCustomersInfo> saleLastYear = new ArrayList<ErpTopFiveCustomersInfo>();
+        List<ErpTopFiveCustomersInfo> saleTwoYearsBefore = new ArrayList<ErpTopFiveCustomersInfo>();
+        for(ErpSaleInfo erpSaleInfo: erpSaleList){
+            int gap = year - erpSaleInfo.getYear();
+            switch (gap){
+                case 1:
+                    saleLastYear = erpSaleInfo.getTopFiveCustomersList();
+                    break;
+                case 2:
+                    saleTwoYearsBefore = erpSaleInfo.getTopFiveCustomersList();
+                    break;
+                default:
+                    break;
+            }
+        }
+//        System.out.println("purLastYear: "+ProtoBufUtil.toJSON(purLastYear));
+//        System.out.println("purTwoYearsBefore: "+ProtoBufUtil.toJSON(purTwoYearsBefore));
+//        System.out.println("saleLastYear: "+ProtoBufUtil.toJSON(saleLastYear));
+//        System.out.println("saleTwoYearsBefore: "+ProtoBufUtil.toJSON(saleTwoYearsBefore));
+        List<Map<String,Object>> upMsgList = new ArrayList<Map<String,Object>>();
+        for(int i = 0;i < purLastYear.size();i++){
+            Map<String,Object> upMsg = new HashMap<>();
+            upMsg.put("UI_YSUPPLIER",purLastYear.get(i).getNane());
+            upMsg.put("UI_TOTALPUR",purLastYear.get(i).getAmount());
+            upMsg.put("UI_RATIO",purLastYear.get(i).getPurchaseTotalProportion());
+            upMsg.put("UI_AGELIMIT",purLastYear.get(i).getCooperationYear());
+
+            upMsg.put("UI_TSUPPLIER",purTwoYearsBefore.get(i).getNane());
+            upMsg.put("UI_TTOTALPUR",purTwoYearsBefore.get(i).getAmount());
+            upMsg.put("UI_TRATIO",purTwoYearsBefore.get(i).getPurchaseTotalProportion());
+            upMsg.put("UI_TAGELIMIT",purTwoYearsBefore.get(i).getCooperationYear());
+
+            upMsg.put("UI_CUSTOMER",saleLastYear.get(i).getNane());
+            upMsg.put("UI_GROSSSALES",saleLastYear.get(i).getSalesAmount());
+            upMsg.put("UI_YRATIO",saleLastYear.get(i).getSalesTotalProportion());
+            upMsg.put("UI_YAGELIMIT",saleLastYear.get(i).getCooperationYear());
+
+            upMsg.put("UI_TCUSTOMER",saleTwoYearsBefore.get(i).getNane());
+            upMsg.put("UI_TGROSSSALES",saleTwoYearsBefore.get(i).getSalesAmount());
+            upMsg.put("UI_LRATIO",saleTwoYearsBefore.get(i).getSalesTotalProportion());
+            upMsg.put("UI_LAGELIMIT",saleTwoYearsBefore.get(i).getCooperationYear());
+            upMsgList.add(upMsg);
+        }
+        int detno = 5;
+        for(Map<String,Object> maMsg : upMsgList){
+            sqls.add("INSERT INTO UPDOWNINFO (UI_ID, UI_CUID, UI_DETNO, UI_YSUPPLIER, UI_TOTALPUR, UI_RATIO, UI_AGELIMIT, " +
+                    "UI_TSUPPLIER, UI_TTOTALPUR, UI_TRATIO, UI_TAGELIMIT, UI_CUSTOMER, UI_GROSSSALES, " +
+                    "UI_YRATIO, UI_YAGELIMIT, UI_TCUSTOMER, UI_TGROSSSALES, UI_LRATIO, UI_LAGELIMIT) VALUES " +
+                    "(UPDOWNINFO_SEQ.NEXTVAL,"+cuId+",("+(detno--)+"),'"+maMsg.get("UI_YSUPPLIER")+"', '"+maMsg.get("UI_TOTALPUR")+"', '"+maMsg.get("UI_RATIO")+"', '"+maMsg.get("UI_AGELIMIT")+"', " +
+                    "'"+maMsg.get("UI_TSUPPLIER")+"', '"+maMsg.get("UI_TTOTALPUR")+"', '"+maMsg.get("UI_TRATIO")+"', '"+maMsg.get("UI_TAGELIMIT")+"', '"+maMsg.get("UI_CUSTOMER")+"', " +
+                    "'"+maMsg.get("UI_GROSSSALES")+"', '"+maMsg.get("UI_YRATIO")+"', '"+maMsg.get("UI_YAGELIMIT")+"', '"+maMsg.get("UI_TCUSTOMER")+"', '"+maMsg.get("UI_TGROSSSALES")+"', '"+maMsg.get("UI_LRATIO")+"', '"+maMsg.get("UI_LAGELIMIT")+"' )");
+        }
+        return sqls;
+    }
+}