优化合同列表查询

This commit is contained in:
mx 2024-10-09 09:06:51 +08:00
parent 81ff6c9510
commit 43ba3088dc
17 changed files with 263 additions and 19 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*/target/*
*/*/target/*
*.log
.flattened-*

View File

@ -6,6 +6,8 @@ import com.pusong.common.translation.annotation.TranslationType;
import com.pusong.common.translation.constant.TransConstant;
import com.pusong.common.translation.core.TranslationInterface;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 字典翻译实现
@ -16,10 +18,12 @@ import lombok.AllArgsConstructor;
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
public class DictTypeTranslationImpl implements TranslationInterface<String> {
private final static Logger logger = LoggerFactory.getLogger(DictTypeTranslationImpl.class);
private final DictService dictService;
@Override
public String translation(Object key, String other) {
logger.info("key = {}, other = {}", key, other);
if (key instanceof String dictValue && StringUtils.isNotBlank(other)) {
String ret = dictService.getDictLabel(other, dictValue);
return StringUtils.isBlank(ret)? dictValue:ret;

View File

@ -78,4 +78,7 @@ public class PsApproverRecord extends TenantEntity {
private Long delFlag;
public String getBusinessIdAndBusinessType(){
return this.businessId + "_" + this.businessType;
}
}

View File

@ -232,5 +232,7 @@ public class PsApproverRecordVo implements Serializable {
* 退款详细信息
*/
private PsContractPayVo psContractPayVo;
public String getBusinessIdAndBusinessType(){
return this.businessId + "_" + this.businessType;
}
}

View File

@ -248,4 +248,13 @@ public class PsCompanyInfoVo implements Serializable {
*/
private String remark;
/**
* 合同公司中间表主键
*/
private Long pccId;
/**
* 合同编号
*/
private String contractCode;
}

View File

@ -273,6 +273,9 @@ public class PsContractInfoVo implements Serializable {
* @return
*/
public boolean isTuoguanService(){
if (this.getPsCompanySerivceVo() == null){
return false;
}
for (PsCompanyInfoVo psCompanyInfoVo : this.getPsCompanySerivceVo()) {
for (PsContractBusinessVo psContractBusinessVo : psCompanyInfoVo.getBusinessVoList()) {
if (psContractBusinessVo.getBusinessType().equals("2")){//2托管服务没找到枚举暂时写死2

View File

@ -12,7 +12,8 @@ public enum CustomerStatusEnum {
INIT("1","初始化"),
PUBLIC("2","进入公海"),
CLAIMAPPROVER("20","认领审批中"),
STOP("3","终止合作");
STOP("3","终止合作"),
HAVE_CONTRACT("6","已成交");;
private String code;
private String text;

View File

@ -10,6 +10,8 @@ import com.pusong.business.domain.vo.PsContractInfoVo;
import com.pusong.common.mybatis.core.mapper.BaseMapperPlus;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 审批记录Mapper接口
*
@ -22,4 +24,7 @@ public interface PsApproverRecordMapper extends BaseMapperPlus<PsApproverRecord,
Page<PsApproverRecordVo> selectPageFreeApproverList(@Param("page") Page<PsApproverRecord> page, @Param(Constants.WRAPPER) Wrapper<PsApproverRecord> queryWrapper);
Page<PsApproverRecordVo> selectPagePublicList(@Param("page") Page<PsApproverRecord> page, @Param(Constants.WRAPPER) Wrapper<PsApproverRecord> queryWrapper);
List<PsApproverRecordVo> getLastFail(@Param(Constants.WRAPPER) Wrapper<PsApproverRecord> queryWrapper);
}

View File

@ -7,6 +7,7 @@ import com.pusong.common.mybatis.core.page.PageQuery;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* 审批记录Service接口
@ -55,6 +56,8 @@ public interface IPsApproverRecordService {
* @return
*/
String getLastFail(String businessId,String contractCode,List<String> businessTypes);
Map<String, String> getLastFail(List<String> businessIds, List<String> businessTypes);
//
// /**
// * 新增审批记录

View File

@ -89,5 +89,6 @@ public interface IPsCompanyInfoService {
*/
List<PsCompanyInfoVo> getServiceCompany(String controctCode);
List<PsCompanyInfoVo> getServiceCompany(List<String> controctCodes);
void terminationService(Long serviceCompanyId);
}

View File

@ -29,6 +29,7 @@ public interface IPsContractPayService {
* @return 合同回款记录分页列表
*/
List<PsContractPayVo> queryListByContractCode(String contractCode, String business, PayStatusEnum enu);
List<PsContractPayVo> queryListByContractCode(List<String> contractCode, String business, PayStatusEnum enu);
/**

View File

@ -1,6 +1,8 @@
package com.pusong.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.pusong.business.domain.PsContractInfo;
import com.pusong.business.enums.ApproverStatusEnum;
import com.pusong.business.enums.ApproverTypeEnum;
import com.pusong.business.enums.TaskStatusEnum;
@ -24,6 +26,7 @@ import com.pusong.business.service.IPsApproverRecordService;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* 审批记录Service业务层处理
@ -134,6 +137,29 @@ public class PsApproverRecordServiceImpl implements IPsApproverRecordService {
return record!=null&&StringUtils.equals(ApproverStatusEnum.FAIL.getCode(),record.getApproverStatus())
?record.getApproverDesc():null;
}
public Map<String, String> getLastFail(List<String> businessIds, List<String> businessTypes){
if (businessIds.isEmpty()){
return new HashMap<>();
}
QueryWrapper<PsApproverRecord> qw = Wrappers.query();
qw.in("r.business_id", businessIds)
.in("r.business_type", businessTypes);
List<PsApproverRecordVo> record = baseMapper.getLastFail(qw);
Map<String, String> map = new HashMap<>();
for (PsApproverRecordVo v : record) {
if (StringUtils.equals(ApproverStatusEnum.FAIL.getCode(), v.getApproverStatus())){
map.put(v.getBusinessIdAndBusinessType(), v.getApproverDesc());
}
}
// Map<String, String> map
// = record.stream()
// .filter(v -> StringUtils.equals(ApproverStatusEnum.FAIL.getCode(), v.getApproverStatus()))
// .collect(Collectors.toMap(PsApproverRecordVo::getBusinessIdAndBusinessType, v -> v.getApproverDesc()));
return map;
}
// /**
// * 新增审批记录
// *

View File

@ -261,7 +261,28 @@ public class PsCompanyInfoServiceImpl implements IPsCompanyInfoService {
*/
public List<PsCompanyInfoVo> getServiceCompany(String controctCode){
QueryWrapper<PsCompanyInfoVo> wq = Wrappers.<PsCompanyInfoVo>query().eq("pcc.del_flag", "0").eq("bus.del_flag","0")
.eq("det.del_flag","0").eq("pcc.contract_code", controctCode);
.eq("det.del_flag","0")
.eq("pcc.contract_code", controctCode);
List<PsCompanyInfoVo> list = baseMapper.selectServiceCompanyList(wq);
for (PsCompanyInfoVo psCompanyInfoVo : list) {
psCompanyInfoVo.setStartServiceDate(psCompanyInfoVo.getBusinessVoList().get(0).getStartDate());
psCompanyInfoVo.setEndServiceDate(psCompanyInfoVo.getBusinessVoList().get(0).getEndDate());
psCompanyInfoVo.setIsOld(psCompanyInfoVo.getBusinessVoList().get(0).getIsOld());
psCompanyInfoVo.setIsProxy(psCompanyInfoVo.getBusinessVoList().get(0).getIsProxy());
}
return list;
}
/**
* 根据合同编码查询服务公司信息
* @param controctCode
* @return
*/
public List<PsCompanyInfoVo> getServiceCompany(List<String> controctCodes){
QueryWrapper<PsCompanyInfoVo> wq = Wrappers.<PsCompanyInfoVo>query()
.eq("pcc.del_flag", "0")
.eq("bus.del_flag","0")
.eq("det.del_flag","0")
.in("pcc.contract_code", controctCodes);
List<PsCompanyInfoVo> list = baseMapper.selectServiceCompanyList(wq);
for (PsCompanyInfoVo psCompanyInfoVo : list) {
psCompanyInfoVo.setStartServiceDate(psCompanyInfoVo.getBusinessVoList().get(0).getStartDate());

View File

@ -281,7 +281,8 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
return TableDataInfo.build(result);
}
//装填信息
result.getRecords().forEach(this::fillContractInfo);
fillContractInfo(result.getRecords());
// result.getRecords().forEach(this::fillContractInfo);
return TableDataInfo.build(result);
}
@ -291,7 +292,8 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
return TableDataInfo.build(result);
}
//装填信息
result.getRecords().forEach(this::fillContractInfo);
fillContractInfo(result.getRecords());
// result.getRecords().forEach(this::fillContractInfo);
return TableDataInfo.build(result);
}
@ -409,8 +411,10 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
//服务公司删则删任务重新校验合同状态可能已完成
List<Long> taskIds = psTaskMainList.stream().map(stTask1 -> stTask1.getId()).collect(Collectors.toList());
if (!taskIds.isEmpty()){
taskAppointMapper.deleteByIds(taskIds);
}
}
List<PsTaskMain> psTaskMainList = new ArrayList<>();
for (PsCompanyInfoBo companyInfoBo : addCompany) {
@ -420,7 +424,7 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
if (companyInfoBo.getId() == null){
companyInfoService.saveBo(companyInfoBo);
}else{
PsCompanyInfo update = MapstructUtils.convert(updateBo, PsCompanyInfo.class);
PsCompanyInfo update = MapstructUtils.convert(companyInfoBo, PsCompanyInfo.class);
companyInfoMapper.updateById(update);
for (PsContractBusinessBo psContractBusinessBo : companyInfoBo.getBusinessList()) {
psContractBusinessBo.setCompanyId(companyInfoBo.getId());
@ -884,6 +888,72 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
return qw;
}
private List<PsContractInfoVo> fillContractInfo(List<PsContractInfoVo> vos){
fillMoney(vos);
List<String> businessIds = new ArrayList<>();
for (PsContractInfoVo vo : vos) {
//电子签章审批
if(StringUtils.equals(CommonStatusEnum.FAIL.getCode(), vo.getSignStatus())){
// signFail.add(vo.getContractCode());
businessIds.add(vo.getContractCode());
}
//回传合同审批
if(StringUtils.equals(CommonStatusEnum.FAIL.getCode(), vo.getRollBackStatus())){
businessIds.add(vo.getContractCode());
}
//合同作废审批
if(StringUtils.equals(CommonStatusEnum.FAIL.getCode(), vo.getIsCancel())){
businessIds.add(vo.getContractCode());
}
}
Map<String, String> lastFailMap = approverRecordService.getLastFail(businessIds
, List.of(ApproverTypeEnum.SIGN.getCode(), ApproverTypeEnum.ROLBACK.getCode(), ApproverTypeEnum.CANCELLA.getCode()));
for (PsContractInfoVo vo : vos) {
vo.setSignFailDesc(lastFailMap.get(vo.getContractCode() + "_" + ApproverTypeEnum.SIGN.getCode()));
vo.setRollBackFailDesc(lastFailMap.get(vo.getContractCode() + "_" + ApproverTypeEnum.ROLBACK.getCode()));
vo.setContractStatusDesc(lastFailMap.get(vo.getContractCode() + "_" + ApproverTypeEnum.CANCELLA.getCode()));
}
//装填服务公司信息
List<String> contractCodeList = vos.stream().map(PsContractInfoVo::getContractCode).toList();
List<PsCompanyInfoVo> list = companyInfoService.getServiceCompany(contractCodeList);
Map<String, List<PsCompanyInfoVo>> psCompanyInfoVoMap = new HashMap<>();
for (PsCompanyInfoVo psCompanyInfoVo : list) {
List<PsCompanyInfoVo> companyInfoVos = psCompanyInfoVoMap.computeIfAbsent(psCompanyInfoVo.getContractCode(), v -> new ArrayList<>());
companyInfoVos.add(psCompanyInfoVo);
}
for (PsContractInfoVo vo : vos) {
vo.setPsCompanySerivceVo(psCompanyInfoVoMap.get(vo.getContractCode()));
}
for (PsContractInfoVo vo : vos) {
if (vo.getFirstApplyDate() != null) {
Date date = new Date();
Date startDate = vo.getFirstApplyDate();
long num = DateUtils.differentMonth(startDate, date);
if (num <= 0) {
vo.setConTime("0");
} else if (num < 12) {
vo.setConTime(num + "个月");
} else {
vo.setConTime(((int) (num / 12)) + "" + num % 12 + "个月");
}
// int year = (date.getYear() - startDate.getYear());
// int month = (date.getMonth() - startDate.getMonth());
//// int day = (date.getDate() - startDate.getDate());
// vo.setConTime((year>0?year+"":"")+(month>0?month+"":"")/*+(day>0?day+"天":"") */);
}
if(vo.getEndServiceDate() != null){
int num = DateUtils.differentDaysByMillisecond(new Date(), vo.getEndServiceDate());
vo.setEndNum(Math.max(num, 0));
}
}
return vos;
}
private PsContractInfoVo fillContractInfo(PsContractInfoVo vo){
//装填服务类型和服务项目信息
@ -935,6 +1005,66 @@ public class PsContractInfoServiceImpl implements IPsContractInfoService {
return vo;
}
public void fillMoney(List<PsContractInfoVo> vos){
List<String> contractCodeList = vos.stream().map(PsContractInfoVo::getContractCode).toList();
//装填回款记录
List<PsContractPayVo> payListAll = contractPayService.queryListByContractCode(contractCodeList,null,PayStatusEnum.SUCCESS);
Map<String, List<PsContractPayVo>> psContractPayVoMap = new HashMap<>();
for (PsContractPayVo psContractPayVo : payListAll) {
List<PsContractPayVo> psContractPayVos = psContractPayVoMap.computeIfAbsent(psContractPayVo.getContractCode(), v -> new ArrayList<>());
psContractPayVos.add(psContractPayVo);
}
for (PsContractInfoVo vo : vos) {
List<PsContractPayVo> payList = psContractPayVoMap.get(vo.getContractCode());
if (payList == null){
payList = new ArrayList<>();
}
vo.setContractPayVoList(payList);
//退款金额
vo.setReturnMoney(payList.stream().filter(item->StringUtils.equals(item.getBusinessType(), PayBuinessStatusEnum.RETURN.getCode()))
.map(PsContractPayVo::getMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
//收款金额
List<PsContractPayVo> returnList = payList.stream().filter(item -> StringUtils.equals(item.getBusinessType(), PayBuinessStatusEnum.PAY.getCode())).toList();
BigDecimal netPay = returnList.stream().map(PsContractPayVo::getMoney).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal pay = netPay.subtract(vo.getReturnMoney());
//已付金额(收款-退款)
vo.setPayMoney(pay.compareTo(BigDecimal.ZERO) >= 0 ? pay : BigDecimal.ZERO);
//未付金额(合同金额-已付金额)
vo.setResidualMoney((vo.getContractAmount() == null ? BigDecimal.ZERO:vo.getContractAmount()).subtract(vo.getPayMoney()));
//回款日期 = 第一次回款若有全部退款过则需要从全部退款开始算到最后一次回款的时间
BigDecimal big = BigDecimal.ZERO;
Date startDate = null;
Date endDate = null;
for (PsContractPayVo pcp : payList){
big = StringUtils.equals(pcp.getBusinessType(),"1")?big.add(pcp.getMoney()):big.subtract(pcp.getMoney());
if(big.compareTo(BigDecimal.ZERO)>0){
if( startDate == null){
startDate = pcp.getPayDate();
}else{
endDate = pcp.getPayDate();
}
}else{
startDate = null;
endDate = null;
}
}
//付款周期
if(startDate == null){
vo.setPeriod(0);
}else if(endDate == null){
vo.setPeriod(1);
}else{
//包含最后一天
vo.setPeriod(DateUtils.calWorkDate(startDate,endDate));
}
}
}
public void fillMoney(PsContractInfoVo vo){
//装填回款记录
List<PsContractPayVo> payList = contractPayService.queryListByContractCode(vo.getContractCode(),null,PayStatusEnum.SUCCESS);

View File

@ -66,6 +66,17 @@ public class PsContractPayServiceImpl implements IPsContractPayService {
return list == null?new ArrayList<>():list;
}
public List<PsContractPayVo> queryListByContractCode(List<String> contractCode, String business, PayStatusEnum enu){
if(contractCode.isEmpty()){return new ArrayList<>();}
String code = enu == null ? null :enu.getCode();
List<PsContractPayVo> list = baseMapper.selectVoList(Wrappers.<PsContractPay>lambdaQuery().
in(PsContractPay::getContractCode, contractCode).eq(PsContractPay::getDelFlag,0)
.eq(StringUtils.isNotBlank(business),PsContractPay::getBusinessType,business)
.eq(code != null ,PsContractPay::getPayStatus, code)
.notIn(PsContractPay::getPayStatus, PayStatusEnum.getStatus())//去掉无用的状态
.orderByAsc(PsContractPay::getPayDate));
return list == null?new ArrayList<>():list;
}
/**
* 查询合同所有支付记录列表
*

View File

@ -92,4 +92,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join ps_custom_info cus on app.business_id = cus.id
${ew.getCustomSqlSegment}
</select>
<select id="getLastFail" resultType="com.pusong.business.domain.vo.PsApproverRecordVo">
SELECT r.business_id, r.business_type, r.approver_status, r.approver_desc
FROM ps_approver_record r
join(
SELECT business_id, business_type, MAX(apply_date) AS max_apply_date
FROM ps_approver_record
GROUP BY business_id, business_type
) AS max_records ON r.business_type = max_records.business_type AND r.apply_date = max_records.max_apply_date AND r.business_id = max_records.business_id
${ew.getCustomSqlSegment}
</select>
</mapper>

View File

@ -10,15 +10,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<collection columnPrefix="det_" column="det" property="detailVoList" ofType="com.pusong.business.domain.vo.PsContractBusinessDetailVo" >
</collection>
</collection>
<collection columnPrefix="fu_" property="followUsers" ofType="com.pusong.system.domain.vo.SysUserVo" >
</collection>
</resultMap>
<resultMap id="serviceCompanyServiceResult2" type="com.pusong.business.domain.vo.PsCompanyInfoVo">
<id column="pcc_id" property="pccId"></id>
<collection columnPrefix="bus_" property="businessVoList" ofType="com.pusong.business.domain.vo.PsContractBusinessVo" >
<id column="id" property="id"></id>
<collection columnPrefix="det_" column="det" property="detailVoList" ofType="com.pusong.business.domain.vo.PsContractBusinessDetailVo" >
</collection>
</collection>
<collection columnPrefix="fu_" property="followUsers" ofType="com.pusong.system.domain.vo.SysUserVo" >
</collection>
</resultMap>
<select id="selectVoCustomManager" resultType="com.pusong.business.domain.vo.PsCompanyInfoVo">
select
com.*
@ -71,8 +78,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${ew.getCustomSqlSegment}
</select>
<select id="selectServiceCompanyList" resultMap="serviceCompanyServiceResult">
select com.*,
<select id="selectServiceCompanyList" resultMap="serviceCompanyServiceResult2">
select
--pcc.contract_code contract_code, 必须在 com.*, 上边否则company里的 contract_code值会被com表的字段覆盖
pcc.contract_code,
pcc.id pcc_id,
com.*,
bus.business_amount bus_business_amount,
bus.business_desc bus_business_desc,
bus.business_type bus_business_type,
@ -91,8 +102,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
det.amount bus_det_amount,
det.amount_desc bus_det_amount_desc,
det.extent_info bus_det_extent_info
from ps_contract_company pcc
left join ps_company_info com on pcc.company_id = com.id
from ps_company_info com
inner join ps_contract_company pcc on pcc.company_id = com.id
left join ps_contract_business bus on bus.company_id = com.id and bus.contract_code = pcc.contract_code
left join ps_contract_business_detail det on det.business_id = bus.id
${ew.getCustomSqlSegment}