Commit 162bb820 by HlQ

[add]

1.收款记录和发票记录创建时间排序
2.计算合同金额添加数据权限控制
1 parent f1f3590c
...@@ -25,7 +25,7 @@ public class ContractPaymentController { ...@@ -25,7 +25,7 @@ public class ContractPaymentController {
@GetMapping("/contractPayment/{id}") @GetMapping("/contractPayment/{id}")
@SaCheckPermission(value = "contractPayment:query", orRole = "admin") @SaCheckPermission(value = "contractPayment:query", orRole = "admin")
public List<ContractPaymentVO> getPaymentById(@PathVariable Long id) { public List<ContractPaymentVO> getPaymentById(@PathVariable Long id) {
return converter.convert(contractPaymentService.lambdaQuery().eq(ContractPayment::getContractId, id).list(), ContractPaymentVO.class); return converter.convert(contractPaymentService.lambdaQuery().eq(ContractPayment::getContractId, id).orderByAsc(ContractPayment::getPaymentType).list(), ContractPaymentVO.class);
} }
@PostMapping("/contractPayment") @PostMapping("/contractPayment")
......
...@@ -4,6 +4,8 @@ import cn.hutool.core.date.DatePattern; ...@@ -4,6 +4,8 @@ import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter; import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -11,19 +13,22 @@ import lombok.extern.slf4j.Slf4j; ...@@ -11,19 +13,22 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import vion.Global;
import vion.dto.FileInfoDTO; import vion.dto.FileInfoDTO;
import vion.model.FileInfo; import vion.model.*;
import vion.service.IFileService; import vion.service.*;
import vion.utils.ResultUtil; import vion.utils.ResultUtil;
import vion.vo.ResultVO; import vion.vo.ResultVO;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping(Global.BASE_URL) @RequestMapping("/api")
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
public class FileController { public class FileController {
...@@ -31,8 +36,13 @@ public class FileController { ...@@ -31,8 +36,13 @@ public class FileController {
private final IFileService fileService; private final IFileService fileService;
private final Converter converter; private final Converter converter;
private final IDeliveryRecordService deliveryRecordService;
private final ITbDeliverGoodsService deliverGoodsService;
private final ITbAppendixService appendixService;
private final IContractService contractService;
@Value("${fileUrl:}") @Value("${fileUrl:}")
private String fileurl; private String fileUrl;
@GetMapping("/files") @GetMapping("/files")
public Page<FileInfo> getFiles(FileInfoDTO data) { public Page<FileInfo> getFiles(FileInfoDTO data) {
...@@ -51,7 +61,6 @@ public class FileController { ...@@ -51,7 +61,6 @@ public class FileController {
} }
} }
/* /*
* todo * todo
* 手机端工单预处理提交 * 手机端工单预处理提交
...@@ -64,7 +73,7 @@ public class FileController { ...@@ -64,7 +73,7 @@ public class FileController {
//上传url地址 //上传url地址
String filename = infile.getOriginalFilename() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN); String filename = infile.getOriginalFilename() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
// String path = fileurl + FileUtil.FILE_SEPARATOR + storeId + FileUtil.FILE_SEPARATOR + sourceId + FileUtil.FILE_SEPARATOR + filename; // String path = fileurl + FileUtil.FILE_SEPARATOR + storeId + FileUtil.FILE_SEPARATOR + sourceId + FileUtil.FILE_SEPARATOR + filename;
String path = fileurl + FileUtil.FILE_SEPARATOR + filename; String path = fileUrl + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path); File file = FileUtil.touch(path);
infile.transferTo(file); infile.transferTo(file);
String sha256 = SecureUtil.sha256(file).toUpperCase(); String sha256 = SecureUtil.sha256(file).toUpperCase();
...@@ -101,7 +110,7 @@ public class FileController { ...@@ -101,7 +110,7 @@ public class FileController {
String fileName = orgName.substring(0, orgName.lastIndexOf(".")); String fileName = orgName.substring(0, orgName.lastIndexOf("."));
String fileExt = orgName.substring(orgName.lastIndexOf(".")); String fileExt = orgName.substring(orgName.lastIndexOf("."));
String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt; String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt;
String path = fileurl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename; String path = fileUrl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path); File file = FileUtil.touch(path);
infile.transferTo(file); infile.transferTo(file);
...@@ -119,4 +128,64 @@ public class FileController { ...@@ -119,4 +128,64 @@ public class FileController {
} }
return "文件保存成功"; return "文件保存成功";
} }
@GetMapping("/tmpfile")
public String sync() {
// bDeliverGoodsId => tbAppendix
Map<String, List<TbAppendix>> id2UrlMap = appendixService.list(Wrappers.<TbAppendix>lambdaQuery().eq(TbAppendix::getBusinessTable, "tb_deliver_goods"))
.stream().collect(Collectors.groupingBy(TbAppendix::getBusinessUnid));
// bDeliverGoodsId => tbDeliverGoods
Map<Long, TbDeliverGoods> id2DeliverGoodsMap = deliverGoodsService.list().stream().collect(Collectors.toMap(TbDeliverGoods::getDeliverUnid, Function.identity()));
// contractNo => contract
Map<String, Long> no2ContractIdMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Contract::getId));
// contractNo => List<DeliveryRecord>
Map<String, List<DeliveryRecord>> no2IdMap = deliveryRecordService.list().stream().collect(Collectors.groupingBy(DeliveryRecord::getContractNo));
id2UrlMap.forEach((id, appendixList) -> appendixList.forEach(appendix -> {
TbDeliverGoods deliverGoods = id2DeliverGoodsMap.get(Long.valueOf(id));
String contractNo = deliverGoods.getContractUnid();
Long contractId = no2ContractIdMap.get(contractNo);
if (contractId == null) {
log.error("合同不存在:{}", contractNo);
return;
}
List<DeliveryRecord> deliveryIdList = no2IdMap.get(contractNo);
if (deliveryIdList.size() == 1) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryIdList.get(0).getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryIdList.get(0).getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
} else {
for (DeliveryRecord deliveryRecord : deliveryIdList) {
if (deliveryRecord.getSignDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getGoodsAcceptancDate()) && deliveryRecord.getShipDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getDeliverGoodsDate())) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryRecord.getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryRecord.getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
}
}
}
}));
return "success";
}
} }
\ No newline at end of file \ No newline at end of file
package vion.cron; package vion.cron;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import vion.model.Contract; import vion.model.Contract;
...@@ -16,7 +19,11 @@ import vion.service.IStoreService; ...@@ -16,7 +19,11 @@ import vion.service.IStoreService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -31,90 +38,111 @@ public class ContractRunner { ...@@ -31,90 +38,111 @@ public class ContractRunner {
private final IDictionaryService dictionaryService; private final IDictionaryService dictionaryService;
private final IContractPaymentService contractPaymentService; private final IContractPaymentService contractPaymentService;
private final IStoreService storeService; private final IStoreService storeService;
private final RedisTemplate redisTemplate;
@Scheduled(cron = "0 0 * * * *") @Scheduled(cron = "0 0 * * * *")
public Boolean contractSync() { public Boolean contractSync() {
log.info("【开始】从crm系统同步合同信息"); log.info("【开始】从crm系统同步合同信息");
Set<String> existContractNoSet = contractService.list().stream().map(Contract::getContractNo).collect(Collectors.toSet()); Map<String, Contract> no2ContactMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Function.identity()));
Map<String, Integer> contractTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "contract_type").list() Map<String, Integer> contractTypeMap = dictionaryService.lambdaQuery().eq(Dictionary::getType, "contract_type").list()
.stream().collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey)); .stream().collect(Collectors.toMap(Dictionary::getValue, Dictionary::getKey));
List<Contract> insertContractList = new ArrayList<>(); List<Contract> insOrUpdContractList = new ArrayList<>();
String modifyTime = Opt.ofNullable((String) redisTemplate.opsForValue().get("contract:sync:time"))
.orElse("1970-01-01 00:00:00");
String url = "jdbc:sqlserver://47.92.144.255:1433;databaseName=UFDATA_001_2020;encrypt=false"; String url = "jdbc:sqlserver://47.92.144.255:1433;databaseName=UFDATA_001_2020;encrypt=false";
String username = "vion-reader"; String username = "vion-reader";
String password = "vion-reader"; String password = "vion-reader";
try (Connection connection = DriverManager.getConnection(url, username, password)) { try (Connection connection = DriverManager.getConnection(url, username, password)) {
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,t1.create_time as entry_time,t5.hetongpingshen_date01 as sign_date1,t5.hetongpingshen_date04 as arrive_date,t5.hetongpingshen_date05 as system_check_date,t5.hetongpingshen_date06 as project_check_date,t5.hetongpingshen_date07 as warranty_date,t5.hetongpingshen_date08 as maintain_date1, t6.hetongpingshen_date09 as maintain_date2,t6.hetongpingshen_date10 as maintain_date3" + String sql = StrUtil.format(
" 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 left join tcu_hetongpingshen_attr t6 on t5.hetongpingshen_id = t6.hetongpingshen_id"; "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,t1.create_time as entry_time,t5.hetongpingshen_date01 as sign_date1,t5.hetongpingshen_date04 as arrive_date,t5.hetongpingshen_date05 as system_check_date,t5.hetongpingshen_date06 as project_check_date,t5.hetongpingshen_date07 as warranty_date,t5.hetongpingshen_date08 as maintain_date1, t6.hetongpingshen_date09 as maintain_date2,t6.hetongpingshen_date10 as maintain_date3,t1.modify_time as original_mod_time" +
" 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 left join tcu_hetongpingshen_attr t6 on t5.hetongpingshen_id = t6.hetongpingshen_id where t1.modify_time > '{}' order by t1.modify_time desc", modifyTime);
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery(sql); ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) { while (resultSet.next()) {
String contractNo = resultSet.getString("contract_no"); String contractNo = resultSet.getString("contract_no");
if (!existContractNoSet.contains(contractNo)) { Contract contract = new Contract();
Contract contract = new Contract(); Opt.ofBlankAble(resultSet.getString("name"))
Opt.ofBlankAble(resultSet.getString("name")) .ifPresentOrElse(contract::setName, () -> contract.setName(contractNo));
.ifPresentOrElse(contract::setName, () -> contract.setName(contractNo));
contract.setContractNo(contractNo);
contract.setContractNo(contractNo); contract.setType(contractTypeMap.getOrDefault(resultSet.getString("type"), 0));
contract.setType(contractTypeMap.getOrDefault(resultSet.getString("type"), 0)); contract.setSignDate(resultSet.getDate("sign_date"));
contract.setSignDate(resultSet.getDate("sign_date")); String warrantyPeriod = resultSet.getString("warranty_period");
String warrantyPeriod = resultSet.getString("warranty_period"); if (StrUtil.isNotBlank(warrantyPeriod) && warrantyPeriod.contains("个月")) {
if (StrUtil.isNotBlank(warrantyPeriod) && warrantyPeriod.contains("个月")) { String substring = warrantyPeriod.substring(0, (warrantyPeriod.length() - 2));
String substring = warrantyPeriod.substring(0, (warrantyPeriod.length() - 2)); contract.setWarrantyPeriod(Integer.parseInt(substring));
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.setSignDate1(resultSet.getDate("sign_date1"));
contract.setArriveRatio(resultSet.getBigDecimal("arrive_ratio"));
contract.setArriveDate(resultSet.getDate("arrive_date"));
contract.setSystemCheckRatio(resultSet.getBigDecimal("system_check_ratio"));
contract.setSystemCheckDate(resultSet.getDate("system_check_date"));
contract.setProjectCheckRatio(resultSet.getBigDecimal("project_check_ratio"));
contract.setProjectCheckDate(resultSet.getDate("project_check_date"));
contract.setWarrantyRatio(resultSet.getBigDecimal("warranty_ratio"));
contract.setWarrantyDate(resultSet.getDate("warranty_date"));
contract.setMaintainRatio1(resultSet.getBigDecimal("maintain1_ratio"));
contract.setMaintainDate1(resultSet.getDate("maintain_date1"));
contract.setMaintainRatio2(resultSet.getBigDecimal("maintain2_ratio"));
contract.setMaintainDate2(resultSet.getDate("maintain_date2"));
contract.setMaintainRatio3(resultSet.getBigDecimal("maintain3_ratio"));
contract.setMaintainDate3(resultSet.getDate("maintain_date3"));
contract.setPaidAmount(BigDecimal.ZERO);
contract.setReceivableAmount(BigDecimal.ZERO);
contract.setOutstandingAmount(resultSet.getBigDecimal("total_amount"));
contract.setSubject("北京文安智能技术股份有限公司");
contract.setCustomerName(resultSet.getString("customer_name"));
contract.setSaleName(resultSet.getString("sale_name"));
contract.setCreateUser(-1L);
contract.setModifyUser(-1L);
contract.setEntryTime(resultSet.getTimestamp("entry_time"));
insertContractList.add(contract);
} }
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.setSignDate1(resultSet.getDate("sign_date1"));
contract.setArriveRatio(resultSet.getBigDecimal("arrive_ratio"));
contract.setArriveDate(resultSet.getDate("arrive_date"));
contract.setSystemCheckRatio(resultSet.getBigDecimal("system_check_ratio"));
contract.setSystemCheckDate(resultSet.getDate("system_check_date"));
contract.setProjectCheckRatio(resultSet.getBigDecimal("project_check_ratio"));
contract.setProjectCheckDate(resultSet.getDate("project_check_date"));
contract.setWarrantyRatio(resultSet.getBigDecimal("warranty_ratio"));
contract.setWarrantyDate(resultSet.getDate("warranty_date"));
contract.setMaintainRatio1(resultSet.getBigDecimal("maintain1_ratio"));
contract.setMaintainDate1(resultSet.getDate("maintain_date1"));
contract.setMaintainRatio2(resultSet.getBigDecimal("maintain2_ratio"));
contract.setMaintainDate2(resultSet.getDate("maintain_date2"));
contract.setMaintainRatio3(resultSet.getBigDecimal("maintain3_ratio"));
contract.setMaintainDate3(resultSet.getDate("maintain_date3"));
contract.setPaidAmount(BigDecimal.ZERO);
contract.setReceivableAmount(BigDecimal.ZERO);
contract.setOutstandingAmount(resultSet.getBigDecimal("total_amount"));
contract.setSubject("北京文安智能技术股份有限公司");
contract.setCustomerName(resultSet.getString("customer_name"));
contract.setSaleName(resultSet.getString("sale_name"));
contract.setCreateUser(-1L);
contract.setModifyUser(-1L);
contract.setEntryTime(resultSet.getTimestamp("entry_time"));
contract.setOriginalModTime(resultSet.getTimestamp("original_mod_time"));
insOrUpdContractList.add(contract);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("合同信息同步失败:", e); log.error("合同信息同步失败:", e);
return false; return false;
} }
contractService.saveBatch(insertContractList, 500);
if (CollUtil.isEmpty(insOrUpdContractList)) {
log.info("没有需要插入或更新的合同");
return true;
}
insOrUpdContractList.forEach(v -> {
if (no2ContactMap.containsKey(v.getContractNo())) {
v.setId(no2ContactMap.get(v.getContractNo()).getId());
}
});
contractService.saveOrUpdateBatch(insOrUpdContractList, 500);
List<ContractPayment> paymentList = contractPaymentService.list();
Map<Long, Map<Integer, Long>> contractId2PaymentMap = paymentList.stream().collect(Collectors.groupingBy(ContractPayment::getContractId, Collectors.toMap(ContractPayment::getPaymentType, ContractPayment::getId)));
// 合同付款比例 // 合同付款比例
List<ContractPayment> contractPaymentList = new ArrayList<>(); List<ContractPayment> contractPaymentList = new ArrayList<>();
for (Contract contract : insertContractList) { for (Contract contract : insOrUpdContractList) {
// 签订 // 签订
ContractPayment contractSignPayment = new ContractPayment(); ContractPayment contractSignPayment = new ContractPayment();
contractSignPayment.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(1));
contractSignPayment.setContractId(contract.getId()); contractSignPayment.setContractId(contract.getId());
contractSignPayment.setPaymentType(1); contractSignPayment.setPaymentType(1);
contractSignPayment.setPaymentRatio(Opt.ofNullable(contract.getSignRatio()).orElse(BigDecimal.ZERO)); contractSignPayment.setPaymentRatio(Opt.ofNullable(contract.getSignRatio()).orElse(BigDecimal.ZERO));
contractSignPayment.setPaymentDate(contract.getSignDate1()); contractSignPayment.setPaymentDate(contract.getSignDate1());
contractSignPayment.setNodeDate(contract.getSignDate());
contractPaymentList.add(contractSignPayment); contractPaymentList.add(contractSignPayment);
// 到货 // 到货
ContractPayment contractArrivePayment = new ContractPayment(); ContractPayment contractArrivePayment = new ContractPayment();
contractArrivePayment.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(2));
contractArrivePayment.setContractId(contract.getId()); contractArrivePayment.setContractId(contract.getId());
contractArrivePayment.setPaymentType(2); contractArrivePayment.setPaymentType(2);
contractArrivePayment.setPaymentRatio(Opt.ofNullable(contract.getArriveRatio()).orElse(BigDecimal.ZERO)); contractArrivePayment.setPaymentRatio(Opt.ofNullable(contract.getArriveRatio()).orElse(BigDecimal.ZERO));
...@@ -123,6 +151,7 @@ public class ContractRunner { ...@@ -123,6 +151,7 @@ public class ContractRunner {
// 系统验收 // 系统验收
ContractPayment contractSystemCheckPayment = new ContractPayment(); ContractPayment contractSystemCheckPayment = new ContractPayment();
contractSystemCheckPayment.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(3));
contractSystemCheckPayment.setContractId(contract.getId()); contractSystemCheckPayment.setContractId(contract.getId());
contractSystemCheckPayment.setPaymentType(3); contractSystemCheckPayment.setPaymentType(3);
contractSystemCheckPayment.setPaymentRatio(Opt.ofNullable(contract.getSystemCheckRatio()).orElse(BigDecimal.ZERO)); contractSystemCheckPayment.setPaymentRatio(Opt.ofNullable(contract.getSystemCheckRatio()).orElse(BigDecimal.ZERO));
...@@ -131,6 +160,7 @@ public class ContractRunner { ...@@ -131,6 +160,7 @@ public class ContractRunner {
// 项目验收 // 项目验收
ContractPayment contractProjectCheckPayment = new ContractPayment(); ContractPayment contractProjectCheckPayment = new ContractPayment();
contractProjectCheckPayment.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(4));
contractProjectCheckPayment.setContractId(contract.getId()); contractProjectCheckPayment.setContractId(contract.getId());
contractProjectCheckPayment.setPaymentType(4); contractProjectCheckPayment.setPaymentType(4);
contractProjectCheckPayment.setPaymentRatio(Opt.ofNullable(contract.getProjectCheckRatio()).orElse(BigDecimal.ZERO)); contractProjectCheckPayment.setPaymentRatio(Opt.ofNullable(contract.getProjectCheckRatio()).orElse(BigDecimal.ZERO));
...@@ -139,6 +169,7 @@ public class ContractRunner { ...@@ -139,6 +169,7 @@ public class ContractRunner {
// 质保 // 质保
ContractPayment contractWarrantyPayment = new ContractPayment(); ContractPayment contractWarrantyPayment = new ContractPayment();
contractWarrantyPayment.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(5));
contractWarrantyPayment.setContractId(contract.getId()); contractWarrantyPayment.setContractId(contract.getId());
contractWarrantyPayment.setPaymentType(5); contractWarrantyPayment.setPaymentType(5);
contractWarrantyPayment.setPaymentRatio(Opt.ofNullable(contract.getWarrantyRatio()).orElse(BigDecimal.ZERO)); contractWarrantyPayment.setPaymentRatio(Opt.ofNullable(contract.getWarrantyRatio()).orElse(BigDecimal.ZERO));
...@@ -147,6 +178,7 @@ public class ContractRunner { ...@@ -147,6 +178,7 @@ public class ContractRunner {
// 第一笔维保款 // 第一笔维保款
ContractPayment contractMaintainPayment1 = new ContractPayment(); ContractPayment contractMaintainPayment1 = new ContractPayment();
contractMaintainPayment1.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(6));
contractMaintainPayment1.setContractId(contract.getId()); contractMaintainPayment1.setContractId(contract.getId());
contractMaintainPayment1.setPaymentType(6); contractMaintainPayment1.setPaymentType(6);
contractMaintainPayment1.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio1()).orElse(BigDecimal.ZERO)); contractMaintainPayment1.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio1()).orElse(BigDecimal.ZERO));
...@@ -155,6 +187,7 @@ public class ContractRunner { ...@@ -155,6 +187,7 @@ public class ContractRunner {
// 第二笔维保款 // 第二笔维保款
ContractPayment contractMaintainPayment2 = new ContractPayment(); ContractPayment contractMaintainPayment2 = new ContractPayment();
contractMaintainPayment2.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(7));
contractMaintainPayment2.setContractId(contract.getId()); contractMaintainPayment2.setContractId(contract.getId());
contractMaintainPayment2.setPaymentType(7); contractMaintainPayment2.setPaymentType(7);
contractMaintainPayment2.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio2()).orElse(BigDecimal.ZERO)); contractMaintainPayment2.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio2()).orElse(BigDecimal.ZERO));
...@@ -163,6 +196,7 @@ public class ContractRunner { ...@@ -163,6 +196,7 @@ public class ContractRunner {
// 第三笔维保款 // 第三笔维保款
ContractPayment contractMaintainPayment3 = new ContractPayment(); ContractPayment contractMaintainPayment3 = new ContractPayment();
contractMaintainPayment3.setId(contractId2PaymentMap.getOrDefault(contract.getId(), new HashMap<>()).get(8));
contractMaintainPayment3.setContractId(contract.getId()); contractMaintainPayment3.setContractId(contract.getId());
contractMaintainPayment3.setPaymentType(8); contractMaintainPayment3.setPaymentType(8);
contractMaintainPayment3.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio3()).orElse(BigDecimal.ZERO)); contractMaintainPayment3.setPaymentRatio(Opt.ofNullable(contract.getMaintainRatio3()).orElse(BigDecimal.ZERO));
...@@ -170,11 +204,10 @@ public class ContractRunner { ...@@ -170,11 +204,10 @@ public class ContractRunner {
contractPaymentList.add(contractMaintainPayment3); contractPaymentList.add(contractMaintainPayment3);
} }
contractPaymentService.saveBatch(contractPaymentList); contractPaymentService.saveOrUpdateBatch(contractPaymentList);
insertContractList.forEach(c -> { insOrUpdContractList.forEach(c -> {
String contractNo = c.getContractNo(); String contractNo = c.getContractNo();
// 多份合同取最新录入的合同 Contract exist = contractService.lambdaQuery().eq(Contract::getContractNo, contractNo).one();
Contract exist = contractService.lambdaQuery().eq(Contract::getContractNo, contractNo).orderByDesc(Contract::getEntryTime).last("limit 1").list().get(0);
Contract updDto = new Contract(); Contract updDto = new Contract();
updDto.setId(exist.getId()); updDto.setId(exist.getId());
updDto.setPaidAmount(exist.getPaidAmount()); updDto.setPaidAmount(exist.getPaidAmount());
...@@ -183,6 +216,7 @@ public class ContractRunner { ...@@ -183,6 +216,7 @@ public class ContractRunner {
}); });
log.info("【结束】从crm系统同步合同信息"); log.info("【结束】从crm系统同步合同信息");
redisTemplate.opsForValue().set("contract:sync:time", DateUtil.formatDateTime(insOrUpdContractList.get(0).getOriginalModTime()));
return true; return true;
} }
......
package vion.dto; package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
@Getter @Getter
@Setter @Setter
...@@ -25,4 +27,10 @@ public class ContractPaymentDTO { ...@@ -25,4 +27,10 @@ public class ContractPaymentDTO {
*/ */
private BigDecimal paymentRatio; private BigDecimal paymentRatio;
/**
* 节点日期,指合同到这一阶段时的时间
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date nodeDate;
} }
\ No newline at end of file \ No newline at end of file
...@@ -167,7 +167,10 @@ public class Contract { ...@@ -167,7 +167,10 @@ public class Contract {
* 财务状态 * 财务状态
*/ */
@TableField(value = "financial_status") @TableField(value = "financial_status")
private Date financialStatus; private Integer financialStatus;
@TableField(exist = false)
private Date originalModTime;
/** /**
* 合同签订付款比例 * 合同签订付款比例
......
...@@ -157,7 +157,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -157,7 +157,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String updateById(Long id, String contractNo, ContractDTO dto) { public String updateById(Long id, String contractNo, ContractDTO dto) {
// todo 合同状态变更时,添加 nodeDate,未上线待联调
Contract existContract = new Contract(); Contract existContract = new Contract();
if (ObjUtil.isNotNull(id)) { if (ObjUtil.isNotNull(id)) {
existContract = this.getById(id); existContract = this.getById(id);
...@@ -242,7 +241,19 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -242,7 +241,19 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
@Override @Override
public JSONObject calAmount(ContractDTO dto) { public JSONObject calAmount(ContractDTO dto) {
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
String saleName = Opt.ofEmptyAble(userVO.getRoleVOList())
.map(l -> l.stream().map(RoleVO::getCode).collect(Collectors.toList()))
.map(roleCodeList -> {
if (!roleCodeList.contains("admin") && !roleCodeList.contains("shangwu") && !roleCodeList.contains("caiwu")) {
return userVO.getUsername();
} else {
return "";
}
}).orElse("未知");
List<Contract> contracts = this.list(Wrappers.lambdaQuery(converter.convert(dto, Contract.class)) List<Contract> contracts = this.list(Wrappers.lambdaQuery(converter.convert(dto, Contract.class))
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd()) .between(ArrayUtil.isAllNotNull(dto.getSignDateStart(), dto.getSignDateEnd()), Contract::getSignDate, dto.getSignDateStart(), dto.getSignDateEnd())
); );
...@@ -301,9 +312,9 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -301,9 +312,9 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
return; return;
} }
BigDecimal paidAmount = c.getPaidAmount(); BigDecimal paidAmount = c.getPaidAmount();
Map<Integer, Date> type2DateMap = contractPaymentList.stream().collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getPaymentDate()), HashMap::putAll); Map<Integer, Date> type2DateMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(HashMap::new, (m, v) -> m.put(v.getPaymentType(), v.getNodeDate()), HashMap::putAll);
Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount))); Map<Integer, BigDecimal> type2AmountMap = contractPaymentList.stream().filter(cp -> cp.getPaymentType() < c.getStatus()).collect(Collectors.toMap(ContractPayment::getPaymentType, v -> NumberUtil.mul(v.getPaymentRatio(), totalAmount)));
TreeMap<Integer, BigDecimal> sortMap = MapUtil.sort(type2AmountMap, Comparator.comparingInt(Integer::intValue)); TreeMap<Integer, BigDecimal> sortMap = MapUtil.sort(type2AmountMap, Comparator.comparingInt(Integer::intValue));
for (Map.Entry<Integer, BigDecimal> entry : sortMap.entrySet()) { for (Map.Entry<Integer, BigDecimal> entry : sortMap.entrySet()) {
...@@ -321,11 +332,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont ...@@ -321,11 +332,10 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
financialAgeVO.setContractName(c.getName()); financialAgeVO.setContractName(c.getName());
financialAgeVO.setStatus(type); financialAgeVO.setStatus(type);
financialAgeVO.setAmount(NumberUtil.equals(paidAmount, BigDecimal.ZERO) ? curAmount : BigDecimal.valueOf(Math.abs(paidAmount.doubleValue()))); financialAgeVO.setAmount(NumberUtil.equals(paidAmount, BigDecimal.ZERO) ? curAmount : BigDecimal.valueOf(Math.abs(paidAmount.doubleValue())));
Date payableDate = type2DateMap.get(type);
Opt.ofNullable(type2DateMap.get(type)).ifPresent( Opt.ofNullable(type2DateMap.get(type)).ifPresent(
date -> { date -> {
financialAgeVO.setPayableDate(date); financialAgeVO.setPayableDate(date);
long age = DateUtil.between(new Date(), payableDate, DateUnit.DAY, false); long age = DateUtil.between(new Date(), date, DateUnit.DAY, false);
financialAgeVO.setAge(((int) age)); financialAgeVO.setAge(((int) age));
} }
); );
......
...@@ -53,7 +53,8 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic ...@@ -53,7 +53,8 @@ public class InvoiceServiceImpl extends MPJBaseServiceImpl<InvoiceMapper, Invoic
MPJLambdaWrapper<Invoice> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Invoice.class)) MPJLambdaWrapper<Invoice> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Invoice.class))
.selectAll(Invoice.class) .selectAll(Invoice.class)
.leftJoin(Contract.class, Contract::getContractNo, Invoice::getContractNo) .leftJoin(Contract.class, Contract::getContractNo, Invoice::getContractNo)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName); .eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.orderByDesc(Invoice::getCreateTime);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), InvoiceVO.class, wrapper); return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), InvoiceVO.class, wrapper);
} }
......
...@@ -55,7 +55,8 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen ...@@ -55,7 +55,8 @@ public class PaymentServiceImpl extends MPJBaseServiceImpl<PaymentMapper, Paymen
MPJLambdaWrapper<Payment> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Payment.class)) MPJLambdaWrapper<Payment> wrapper = new MPJLambdaWrapper<>(converter.convert(dto, Payment.class))
.selectAll(Payment.class) .selectAll(Payment.class)
.leftJoin(Contract.class, Contract::getContractNo, Payment::getContractNo) .leftJoin(Contract.class, Contract::getContractNo, Payment::getContractNo)
.eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName); .eq(StrUtil.isNotBlank(saleName), Contract::getSaleName, saleName)
.orderByDesc(Payment::getCreateTime);
return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), PaymentVO.class, wrapper); return this.selectJoinListPage(Page.of(dto.getPageNum(), dto.getPageSize()), PaymentVO.class, wrapper);
} }
......
...@@ -31,6 +31,18 @@ public class ContractPaymentVO { ...@@ -31,6 +31,18 @@ public class ContractPaymentVO {
private BigDecimal paymentRatio; private BigDecimal paymentRatio;
/** /**
* 收款日期
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date paymentDate;
/**
* 节点日期,指合同到这一阶段时的时间
*/
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date nodeDate;
/**
* 创建者 * 创建者
*/ */
private Integer createUser; private Integer createUser;
......
...@@ -127,6 +127,11 @@ public class ContractVO { ...@@ -127,6 +127,11 @@ public class ContractVO {
private Date finalDate; private Date finalDate;
/** /**
* 财务状态
*/
private Integer financialStatus;
/**
* 开票金额 * 开票金额
*/ */
private BigDecimal invoiceAmount; private BigDecimal invoiceAmount;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!