Merge remote-tracking branch 'yudao/develop' into develop

This commit is contained in:
puhui999 2024-02-27 21:28:23 +08:00
commit c4ff0a1038
12 changed files with 76 additions and 51 deletions

View File

@ -39,6 +39,7 @@ public interface ErrorCodeConstants {
ErrorCode RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态"); ErrorCode RECEIVABLE_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_004_004, "更新回款审核状态失败,原因:回款不是审核中状态");
ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试"); ErrorCode RECEIVABLE_NO_EXISTS = new ErrorCode(1_020_004_005, "生成回款序列号重复,请重试");
ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态"); ErrorCode RECEIVABLE_CREATE_FAIL_CONTRACT_NOT_APPROVE = new ErrorCode(1_020_004_006, "创建回款失败,原因:合同不是审核通过状态");
ErrorCode RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元");
// ========== 回款计划 1-020-005-000 ========== // ========== 回款计划 1-020-005-000 ==========
ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在"); ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");

View File

@ -164,13 +164,6 @@ public class CrmReceivableController {
}); });
} }
@GetMapping("/check-receivables-count")
@Operation(summary = "获得待审核回款数量")
@PreAuthorize("@ss.hasPermission('crm:receivable:query')")
public CommonResult<Long> getCheckReceivablesCount() {
return success(receivableService.getCheckReceivablesCount(getLoginUserId()));
}
@PutMapping("/submit") @PutMapping("/submit")
@Operation(summary = "提交回款审批") @Operation(summary = "提交回款审批")
@PreAuthorize("@ss.hasPermission('crm:receivable:update')") @PreAuthorize("@ss.hasPermission('crm:receivable:update')")
@ -179,4 +172,11 @@ public class CrmReceivableController {
return success(true); return success(true);
} }
@GetMapping("/audit-count")
@Operation(summary = "获得待审核回款数量")
@PreAuthorize("@ss.hasPermission('crm:receivable:query')")
public CommonResult<Long> getAuditReceivableCount() {
return success(receivableService.getAuditReceivableCount(getLoginUserId()));
}
} }

View File

@ -163,13 +163,6 @@ public class CrmReceivablePlanController {
}); });
} }
@GetMapping("/remind-receivable-plan-count")
@Operation(summary = "获得待回款提醒数量")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
public CommonResult<Long> getRemindReceivablesCount() {
return success(receivablePlanService.getRemindReceivablePlanCount(getLoginUserId()));
}
@GetMapping("/simple-list") @GetMapping("/simple-list")
@Operation(summary = "获得回款计划精简列表", description = "获得回款计划精简列表,主要用于前端的下拉选项") @Operation(summary = "获得回款计划精简列表", description = "获得回款计划精简列表,主要用于前端的下拉选项")
@Parameters({ @Parameters({
@ -187,4 +180,11 @@ public class CrmReceivablePlanController {
.setPrice(receivablePlan.getPrice()).setReturnType(receivablePlan.getReturnType()))); .setPrice(receivablePlan.getPrice()).setReturnType(receivablePlan.getReturnType())));
} }
@GetMapping("/remind-count")
@Operation(summary = "获得待回款提醒数量")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
public CommonResult<Long> getReceivablePlanRemindCount() {
return success(receivablePlanService.getReceivablePlanRemindCount(getLoginUserId()));
}
} }

View File

@ -68,16 +68,22 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> {
return selectJoinList(CrmReceivableDO.class, query); return selectJoinList(CrmReceivableDO.class, query);
} }
default Long selectCheckReceivablesCount(Long userId) { default Long selectCountByAudit(Long userId) {
MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmReceivableDO> query = new MPJLambdaWrapperX<>();
// 我负责的 + 非公海 // 我负责的 + 非公海
CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(), CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE.getType(),
CrmReceivableDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE); CrmReceivableDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE);
// 提交 or 审核不通过 // 审核
query.in(CrmContractDO::getAuditStatus, CrmAuditStatusEnum.DRAFT.getStatus(), CrmAuditStatusEnum.REJECT.getStatus()); query.eq(CrmContractDO::getAuditStatus, CrmAuditStatusEnum.PROCESS.getStatus());
return selectCount(query); return selectCount(query);
} }
default List<CrmReceivableDO> selectListByContractIdAndStatus(Long contractId, Collection<Integer> auditStatuses) {
return selectList(new LambdaQueryWrapperX<CrmReceivableDO>()
.eq(CrmReceivableDO::getContractId, contractId)
.in(CrmReceivableDO::getAuditStatus, auditStatuses));
}
default Map<Long, BigDecimal> selectReceivablePriceMapByContractId(Collection<Long> contractIds) { default Map<Long, BigDecimal> selectReceivablePriceMapByContractId(Collection<Long> contractIds) {
if (CollUtil.isEmpty(contractIds)) { if (CollUtil.isEmpty(contractIds)) {
return Collections.emptyMap(); return Collections.emptyMap();
@ -85,7 +91,8 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> {
// SQL sum 查询 // SQL sum 查询
List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>() List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>()
.select("contract_id, SUM(price) AS total_price") .select("contract_id, SUM(price) AS total_price")
.eq("audit_status", CrmAuditStatusEnum.APPROVE.getStatus()) .in("audit_status", CrmAuditStatusEnum.DRAFT.getStatus(), // 草稿 + 审批中 + 审批通过
CrmAuditStatusEnum.PROCESS, CrmAuditStatusEnum.APPROVE.getStatus())
.groupBy("contract_id") .groupBy("contract_id")
.in("contract_id", contractIds)); .in("contract_id", contractIds));
// 获得金额 // 获得金额

View File

@ -60,19 +60,16 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO
} }
// Backlog: 回款提醒类型 // Backlog: 回款提醒类型
// TODO: @dhb52 需要配置 提前提醒天数
int REMIND_DAYS = 20;
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now()); LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(LocalDateTime.now());
if (CrmReceivablePlanPageReqVO.REMIND_TYPE_NEEDED.equals(pageReqVO.getRemindType())) { // 待回款 if (CrmReceivablePlanPageReqVO.REMIND_TYPE_NEEDED.equals(pageReqVO.getRemindType())) { // 待回款
query.isNull(CrmReceivablePlanDO::getReceivableId) query.isNull(CrmReceivablePlanDO::getReceivableId) // 未回款
.between(CrmReceivablePlanDO::getReturnTime, beginOfToday, endOfToday.plusDays(REMIND_DAYS)); .lt(CrmReceivablePlanDO::getReturnTime, beginOfToday) // 已逾期
.lt(CrmReceivablePlanDO::getRemindTime, beginOfToday); // 今天开始提醒
} else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_EXPIRED.equals(pageReqVO.getRemindType())) { // 已逾期 } else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_EXPIRED.equals(pageReqVO.getRemindType())) { // 已逾期
query.isNull(CrmReceivablePlanDO::getReceivableId) query.isNull(CrmReceivablePlanDO::getReceivableId) // 未回款
.lt(CrmReceivablePlanDO::getReturnTime, endOfToday); .ge(CrmReceivablePlanDO::getReturnTime, beginOfToday); // 已逾期
} else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_RECEIVED.equals(pageReqVO.getRemindType())) { // 已回款 } else if (CrmReceivablePlanPageReqVO.REMIND_TYPE_RECEIVED.equals(pageReqVO.getRemindType())) { // 已回款
query.isNotNull(CrmReceivablePlanDO::getReceivableId) query.isNotNull(CrmReceivablePlanDO::getReceivableId);
.between(CrmReceivablePlanDO::getReturnTime, beginOfToday, endOfToday.plusDays(REMIND_DAYS));
} }
return selectJoinPage(pageReqVO, CrmReceivablePlanDO.class, query); return selectJoinPage(pageReqVO, CrmReceivablePlanDO.class, query);
} }
@ -86,20 +83,16 @@ public interface CrmReceivablePlanMapper extends BaseMapperX<CrmReceivablePlanDO
return selectJoinList(CrmReceivablePlanDO.class, query); return selectJoinList(CrmReceivablePlanDO.class, query);
} }
default Long selectRemindReceivablePlanCount(Long userId) { default Long selectReceivablePlanCountByRemind(Long userId) {
MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmReceivablePlanDO> query = new MPJLambdaWrapperX<>();
// 我负责的 + 非公海 // 我负责的 + 非公海
CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(), CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_RECEIVABLE_PLAN.getType(),
CrmReceivablePlanDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE); CrmReceivablePlanDO::getId, userId, CrmSceneTypeEnum.OWNER.getType(), Boolean.FALSE);
// TODO: @dhb52 需要配置 提前提醒天数 // 未回款 + 已逾期 + 今天开始提醒
int REMIND_DAYS = 20;
LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now()); LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now());
LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(LocalDateTime.now()); query.isNull(CrmReceivablePlanDO::getReceivableId) // 未回款
query.isNull(CrmReceivablePlanDO::getReceivableId) .lt(CrmReceivablePlanDO::getReturnTime, beginOfToday) // 已逾期
.between(CrmReceivablePlanDO::getReturnTime, beginOfToday, endOfToday.plusDays(REMIND_DAYS)); .lt(CrmReceivablePlanDO::getRemindTime, beginOfToday); // 今天开始提醒
// TODO return_time 小于现在
// TODO 未回款
// TODO remind_time 大于现在
return selectCount(query); return selectCount(query);
} }

View File

@ -1,4 +1,4 @@
/** /**
* TODO 芋艿临时占位后续可删除 * 定时任务
*/ */
package cn.iocoder.yudao.module.crm.job; package cn.iocoder.yudao.module.crm.job;

View File

@ -222,7 +222,7 @@ public class CrmContractServiceImpl implements CrmContractService {
success = CRM_CONTRACT_DELETE_SUCCESS) success = CRM_CONTRACT_DELETE_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) @CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
public void deleteContract(Long id) { public void deleteContract(Long id) {
// TODO @合同待定如果被 CrmReceivableDO 所使用则不允许删除 // TODO @puhui999如果被 CrmReceivableDO 所使用则不允许删除
// 校验存在 // 校验存在
CrmContractDO contract = validateContractExists(id); CrmContractDO contract = validateContractExists(id);
// 删除 // 删除

View File

@ -170,7 +170,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
throw exception(CRM_PERMISSION_DELETE_FAIL); throw exception(CRM_PERMISSION_DELETE_FAIL);
} }
// 校验操作人是否为负责人 // 校验操作人是否为负责人
CrmPermissionDO permission = permissionMapper.selectByBizIdAndUserId(permissions.getFirst().getBizId(), userId); CrmPermissionDO permission = permissionMapper.selectByBizIdAndUserId(permissions.get(0).getBizId(), userId);
if (permission == null) { if (permission == null) {
throw exception(CRM_PERMISSION_DELETE_DENIED); throw exception(CRM_PERMISSION_DELETE_DENIED);
} }

View File

@ -90,6 +90,6 @@ public interface CrmReceivablePlanService {
* @param userId 用户编号 * @param userId 用户编号
* @return 提醒数量 * @return 提醒数量
*/ */
Long getRemindReceivablePlanCount(Long userId); Long getReceivablePlanRemindCount(Long userId);
} }

View File

@ -184,8 +184,8 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService {
} }
@Override @Override
public Long getRemindReceivablePlanCount(Long userId) { public Long getReceivablePlanRemindCount(Long userId) {
return receivablePlanMapper.selectRemindReceivablePlanCount(userId); return receivablePlanMapper.selectReceivablePlanCountByRemind(userId);
} }
} }

View File

@ -110,9 +110,9 @@ public interface CrmReceivableService {
* 获得待审核回款数量 * 获得待审核回款数量
* *
* @param userId 用户编号 * @param userId 用户编号
* @return 提醒数量 * @return 待审批数量
*/ */
Long getCheckReceivablesCount(Long userId); Long getAuditReceivableCount(Long userId);
/** /**
* 获得合同已回款金额 Map * 获得合同已回款金额 Map

View File

@ -6,6 +6,7 @@ import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi; import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
@ -36,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -85,18 +87,21 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
@LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}", @LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}",
success = CRM_RECEIVABLE_CREATE_SUCCESS) success = CRM_RECEIVABLE_CREATE_SUCCESS)
public Long createReceivable(CrmReceivableSaveReqVO createReqVO) { public Long createReceivable(CrmReceivableSaveReqVO createReqVO) {
// 1.1 校验关联数据存在 // 1.1 校验可回款金额超过上限
validateReceivablePriceExceedsLimit(createReqVO);
// 1.2 校验关联数据存在
validateRelationDataExists(createReqVO); validateRelationDataExists(createReqVO);
// 1.2 生成回款编号 // 1.3 生成回款编号
String no = noRedisDAO.generate(CrmNoRedisDAO.RECEIVABLE_PREFIX); String no = noRedisDAO.generate(CrmNoRedisDAO.RECEIVABLE_PREFIX);
if (receivableMapper.selectByNo(no) != null) { if (receivableMapper.selectByNo(no) != null) {
throw exception(RECEIVABLE_NO_EXISTS); throw exception(RECEIVABLE_NO_EXISTS);
} }
// 2. 插入回款 // 2.1 插入回款
CrmReceivableDO receivable = BeanUtils.toBean(createReqVO, CrmReceivableDO.class) CrmReceivableDO receivable = BeanUtils.toBean(createReqVO, CrmReceivableDO.class)
.setNo(no).setAuditStatus(CrmAuditStatusEnum.DRAFT.getStatus()); .setNo(no).setAuditStatus(CrmAuditStatusEnum.DRAFT.getStatus());
receivableMapper.insert(receivable); receivableMapper.insert(receivable);
// 2.2
// 3. 创建数据权限 // 3. 创建数据权限
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_RECEIVABLE.getType()) permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_RECEIVABLE.getType())
@ -113,6 +118,22 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
return receivable.getId(); return receivable.getId();
} }
private void validateReceivablePriceExceedsLimit(CrmReceivableSaveReqVO reqVO) {
// 1. 计算剩余可退款金额不包括 reqVO 自身
CrmContractDO contract = contractService.validateContract(reqVO.getContractId());
List<CrmReceivableDO> receivables = receivableMapper.selectListByContractIdAndStatus(reqVO.getContractId(),
Arrays.asList(CrmAuditStatusEnum.APPROVE.getStatus(), CrmAuditStatusEnum.PROCESS.getStatus()));
if (reqVO.getId() != null) {
receivables.removeIf(receivable -> ObjectUtil.equal(receivable.getId(), reqVO.getId()));
}
BigDecimal notReceivablePrice = contract.getTotalPrice().subtract(
CollectionUtils.getSumValue(receivables, CrmReceivableDO::getPrice, BigDecimal::add, BigDecimal.ZERO));
// 2. 校验金额是否超过
if (reqVO.getPrice().compareTo(notReceivablePrice) > 0) {
throw exception(RECEIVABLE_CREATE_FAIL_PRICE_EXCEEDS_LIMIT, notReceivablePrice);
}
}
private void validateRelationDataExists(CrmReceivableSaveReqVO reqVO) { private void validateRelationDataExists(CrmReceivableSaveReqVO reqVO) {
if (reqVO.getOwnerUserId() != null) { if (reqVO.getOwnerUserId() != null) {
adminUserApi.validateUser(reqVO.getOwnerUserId()); // 校验负责人存在 adminUserApi.validateUser(reqVO.getOwnerUserId()); // 校验负责人存在
@ -144,9 +165,11 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) { public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) {
Assert.notNull(updateReqVO.getId(), "回款编号不能为空"); Assert.notNull(updateReqVO.getId(), "回款编号不能为空");
updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段 updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段
// 1.1 校验存在 // 1.1 校验可回款金额超过上限
validateReceivablePriceExceedsLimit(updateReqVO);
// 1.2 校验存在
CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId()); CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId());
// 1.2 只有草稿审批中可以编辑 // 1.3 只有草稿审批中可以编辑
if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(), if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(),
CrmAuditStatusEnum.PROCESS.getStatus())) { CrmAuditStatusEnum.PROCESS.getStatus())) {
throw exception(RECEIVABLE_UPDATE_FAIL_EDITING_PROHIBITED); throw exception(RECEIVABLE_UPDATE_FAIL_EDITING_PROHIBITED);
@ -189,6 +212,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) { if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) {
throw exception(RECEIVABLE_DELETE_FAIL); throw exception(RECEIVABLE_DELETE_FAIL);
} }
// TODO @puhui999审批通过时不允许删除
// 2. 删除 // 2. 删除
receivableMapper.deleteById(id); receivableMapper.deleteById(id);
@ -256,8 +280,8 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
} }
@Override @Override
public Long getCheckReceivablesCount(Long userId) { public Long getAuditReceivableCount(Long userId) {
return receivableMapper.selectCheckReceivablesCount(userId); return receivableMapper.selectCountByAudit(userId);
} }
@Override @Override