Commit 7a04d0d6 by zhuht

Merge remote-tracking branch 'origin/master'

2 parents 5e31c73d 69a5d8ae
package vion.cron;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vion.model.Contract;
import vion.model.ContractPayment;
import vion.model.Dictionary;
import vion.service.IContractPaymentService;
import vion.service.IContractService;
import vion.service.IDictionaryService;
......@@ -28,6 +31,8 @@ public class ContractRunner {
private IContractService contractService;
@Resource
private IDictionaryService dictionaryService;
@Resource
private IContractPaymentService contractPaymentService;
@Scheduled(cron = "0 0 * * * *")
public Boolean contractSync() {
......@@ -35,28 +40,48 @@ public class ContractRunner {
Set<String> existContractNoSet = contractService.list().stream().map(Contract::getContractNo).collect(Collectors.toSet());
Map<String, Integer> contractTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "contract_type").list()
.stream().collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey));
Map<String, Integer> payTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "pay_type").list()
.stream().collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey));
List<Contract> insertContractList = new ArrayList<>();
String url = "jdbc:sqlserver://47.92.144.255:1433;databaseName=UFDATA_001_2020;encrypt=false";
String username = "vion-reader";
String password = "vion-reader";
try (Connection connection = DriverManager.getConnection(url, username, password)) {
String sql = "select concat(t3.optnty_name,t1.hetongluru_name) as name, t1.hetongluru_name as contract_no,t1.hetongluru_char12 as type,t1.hetongluru_date01 as sign_date,t1.hetongluru_start_date as maintain_sdate,t1.hetongluru_end_date as maintain_edate,t1.hetongluru_dec01 as total_amount,t2.cCusAbbName as customer_name,t4.cUser_Name as sale_name" +
" from tcu_hetongluru t1 left join Customer t2 on t1.account_id = t2.cCusCode left join tc_opportunity t3 on t1.hetongluru_char04 = t3.ufcode left join UA_User_Ex t4 on t1.owner_user_id = t4.cUser_Id";
String sql = "select t5.hetongpingshen_name as name,t1.hetongluru_name as contract_no,t1.hetongluru_char12 as type,t1.hetongluru_date01 as sign_date,t1.hetongluru_char01 as warranty_period,t1.hetongluru_start_date as maintain_sdate,t1.hetongluru_end_date as maintain_edate,t1.hetongluru_dec01 as total_amount,t5.hetongpingshen_dec02 as sign_ratio,t5.hetongpingshen_dec03 as arrive_ratio,t5.hetongpingshen_dec04 as system_check_ratio,t5.hetongpingshen_dec05 as project_check_ratio,t5.hetongpingshen_dec06 as warranty_ratio,t5.hetongpingshen_dec07 as maintain1_ratio,t5.hetongpingshen_dec09 as maintain2_ratio,t5.hetongpingshen_dec10 as maintain3_ratio,t2.cCusAbbName as customer_name,t4.cUser_Name as sale_name" +
" from tcu_hetongluru t1 left join Customer t2 on t1.account_id = t2.cCusCode left join tc_opportunity t3 on t1.hetongluru_char04 = t3.ufcode left join UA_User_Ex t4 on t1.owner_user_id = t4.cUser_Id left join tcu_hetongpingshen t5 on t1.hetongluru_name = t5.hetongpingshen_char05";
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
String contractNo = resultSet.getString("contract_no");
if (!existContractNoSet.contains(contractNo)) {
Contract contract = new Contract();
contract.setName(resultSet.getString("name"));
String contractName = resultSet.getString("name");
if (StrUtil.isNotBlank(contractName)) {
contract.setName(resultSet.getString("name"));
} else {
contract.setName(contractNo);
}
contract.setContractNo(contractNo);
contract.setType(contractTypeMap.getOrDefault(resultSet.getString("type"), 0));
contract.setSignDate(resultSet.getDate("sign_date"));
String warrantyPeriod = resultSet.getString("warranty_period");
if (StrUtil.isNotBlank(warrantyPeriod) && warrantyPeriod.contains("个月")) {
String substring = warrantyPeriod.substring(0, (warrantyPeriod.length() - 2));
contract.setWarrantyPeriod(Integer.parseInt(substring));
}
contract.setMaintainSdate(resultSet.getDate("maintain_sdate"));
contract.setMaintainEdate(resultSet.getDate("maintain_edate"));
contract.setStatus(1);
contract.setTotalAmount(resultSet.getBigDecimal("total_amount"));
contract.setSignRatio(resultSet.getBigDecimal("sign_ratio"));
contract.setArriveRatio(resultSet.getBigDecimal("arrive_ratio"));
contract.setSystemCheckRatio(resultSet.getBigDecimal("system_check_ratio"));
contract.setProjectCheckRatio(resultSet.getBigDecimal("project_check_ratio"));
contract.setWarrantyRatio(resultSet.getBigDecimal("warranty_ratio"));
contract.setMaintainRatio1(resultSet.getBigDecimal("maintain1_ratio"));
contract.setMaintainRatio2(resultSet.getBigDecimal("maintain2_ratio"));
contract.setMaintainRatio3(resultSet.getBigDecimal("maintain3_ratio"));
contract.setPaidAmount(BigDecimal.ZERO);
contract.setReceivableAmount(BigDecimal.ZERO);
contract.setOutstandingAmount(resultSet.getBigDecimal("total_amount"));
......@@ -66,6 +91,8 @@ public class ContractRunner {
contract.setCreateUser(-1L);
contract.setModifyUser(-1L);
insertContractList.add(contract);
}
}
......@@ -74,9 +101,67 @@ public class ContractRunner {
log.error("合同信息同步失败:", e);
return false;
}
contractService.saveBatch(insertContractList, 500);
// 合同付款比例
List<ContractPayment> contractPaymentList = new ArrayList<>();
for (Contract contract : insertContractList) {
// 签订
ContractPayment contractSignPayment = new ContractPayment();
contractSignPayment.setContractId(contract.getId());
contractSignPayment.setPaymentType(1);
contractSignPayment.setPaymentRatio(null != contract.getSignRatio() ? contract.getSignRatio() : BigDecimal.ZERO);
contractPaymentList.add(contractSignPayment);
// 到货
ContractPayment contractArrivePayment = new ContractPayment();
contractArrivePayment.setContractId(contract.getId());
contractArrivePayment.setPaymentType(2);
contractArrivePayment.setPaymentRatio(null != contract.getArriveRatio() ? contract.getArriveRatio() : BigDecimal.ZERO);
contractPaymentList.add(contractArrivePayment);
// 系统验收
ContractPayment contractSystemCheckPayment = new ContractPayment();
contractSystemCheckPayment.setContractId(contract.getId());
contractSystemCheckPayment.setPaymentType(3);
contractSystemCheckPayment.setPaymentRatio(null != contract.getSystemCheckRatio() ? contract.getSystemCheckRatio() : BigDecimal.ZERO);
contractPaymentList.add(contractSystemCheckPayment);
// 项目验收
ContractPayment contractProjectCheckPayment = new ContractPayment();
contractProjectCheckPayment.setContractId(contract.getId());
contractProjectCheckPayment.setPaymentType(4);
contractProjectCheckPayment.setPaymentRatio(null != contract.getProjectCheckRatio() ? contract.getProjectCheckRatio() : BigDecimal.ZERO);
contractPaymentList.add(contractProjectCheckPayment);
// 质保
ContractPayment contractWarrantyPayment = new ContractPayment();
contractWarrantyPayment.setContractId(contract.getId());
contractWarrantyPayment.setPaymentType(5);
contractWarrantyPayment.setPaymentRatio(null != contract.getWarrantyRatio() ? contract.getWarrantyRatio() : BigDecimal.ZERO);
contractPaymentList.add(contractWarrantyPayment);
// 维保
ContractPayment contractMaintainPayment = new ContractPayment();
contractMaintainPayment.setContractId(contract.getId());
contractMaintainPayment.setPaymentType(6);
BigDecimal maintainPaymentRatio = BigDecimal.ZERO;
if (null != contract.getMaintainRatio1()) {
maintainPaymentRatio = maintainPaymentRatio.add(contract.getMaintainRatio1());
}
if (null != contract.getMaintainRatio2()) {
maintainPaymentRatio = maintainPaymentRatio.add(contract.getMaintainRatio2());
}
if (null != contract.getMaintainRatio3()) {
maintainPaymentRatio = maintainPaymentRatio.add(contract.getMaintainRatio3());
}
contractMaintainPayment.setPaymentRatio(maintainPaymentRatio);
contractPaymentList.add(contractMaintainPayment);
}
contractPaymentService.saveBatch(contractPaymentList);
log.info("【结束】从crm系统同步合同信息");
return true;
}
......
......@@ -144,4 +144,52 @@ public class Contract {
*/
@TableField(value = "warranty_period")
private Integer warrantyPeriod;
/**
* 合同签订付款比例
*/
@TableField(exist = false)
private BigDecimal signRatio;
/**
* 合同到货付款比例
*/
@TableField(exist = false)
private BigDecimal arriveRatio;
/**
* 合同系统验收付款比例
*/
@TableField(exist = false)
private BigDecimal systemCheckRatio;
/**
* 合同项目验收付款比例
*/
@TableField(exist = false)
private BigDecimal projectCheckRatio;
/**
* 合同质保付款比例
*/
@TableField(exist = false)
private BigDecimal warrantyRatio;
/**
* 合同维保付款比例1
*/
@TableField(exist = false)
private BigDecimal maintainRatio1;
/**
* 合同维保付款比例2
*/
@TableField(exist = false)
private BigDecimal maintainRatio2;
/**
* 合同维保付款比例2
*/
@TableField(exist = false)
private BigDecimal maintainRatio3;
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!