mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
CRM: 完善回款操作日志
This commit is contained in:
parent
c3337f21ce
commit
720b54c353
@ -15,6 +15,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CONTRACT_SUBMIT_FAIL_NOT_DRAFT = new ErrorCode(1_020_000_002, "合同提交审核失败,原因:合同没处在未提交状态");
|
||||
ErrorCode CONTRACT_UPDATE_AUDIT_STATUS_FAIL_NOT_PROCESS = new ErrorCode(1_020_000_003, "更新合同审核状态失败,原因:合同不是审核中状态");
|
||||
ErrorCode CONTRACT_NO_EXISTS = new ErrorCode(1_020_000_004, "生成合同序列号重复,请重试");
|
||||
ErrorCode CONTRACT_DELETE_FAIL = new ErrorCode(1_020_000_005, "删除合同失败,原因:有被回款所使用");
|
||||
|
||||
// ========== 线索管理 1-020-001-000 ==========
|
||||
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
|
||||
@ -40,6 +41,7 @@ public interface ErrorCodeConstants {
|
||||
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_PRICE_EXCEEDS_LIMIT = new ErrorCode(1_020_004_007, "创建回款失败,原因:回款金额超出合同金额,目前剩余可退:{} 元");
|
||||
ErrorCode RECEIVABLE_DELETE_FAIL_IS_APPROVE = new ErrorCode(1_020_004_008, "删除回款失败,原因:回款审批已通过");
|
||||
|
||||
// ========== 回款计划 1-020-005-000 ==========
|
||||
ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_020_005_000, "回款计划不存在");
|
||||
|
@ -142,11 +142,11 @@ public interface LogRecordConstants {
|
||||
|
||||
String CRM_RECEIVABLE_TYPE = "CRM 回款";
|
||||
String CRM_RECEIVABLE_CREATE_SUB_TYPE = "创建回款";
|
||||
String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款";
|
||||
String CRM_RECEIVABLE_CREATE_SUCCESS = "创建了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
|
||||
String CRM_RECEIVABLE_UPDATE_SUB_TYPE = "更新回款";
|
||||
String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款: {_DIFF{#updateReqVO}}";
|
||||
String CRM_RECEIVABLE_UPDATE_SUCCESS = "更新了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款: {_DIFF{#updateReqVO}}";
|
||||
String CRM_RECEIVABLE_DELETE_SUB_TYPE = "删除回款";
|
||||
String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的第【{{#receivable.period}}】期回款";
|
||||
String CRM_RECEIVABLE_DELETE_SUCCESS = "删除了合同【{getContractById{#receivable.contractId}}】的{{#period != null ? '【第'+ #period +'期】' : '编号为【'+ #receivable.no +'】的'}}回款";
|
||||
String CRM_RECEIVABLE_SUBMIT_SUB_TYPE = "提交回款审批";
|
||||
String CRM_RECEIVABLE_SUBMIT_SUCCESS = "提交编号为【{{#receivableNo}}】的回款审批成功";
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.plan;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable.CrmReceivableRespVO;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@ -8,53 +9,69 @@ import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
// TODO @puhui999:缺导出
|
||||
@Schema(description = "管理后台 - CRM 回款计划 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CrmReceivablePlanRespVO {
|
||||
|
||||
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "期数", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("期数")
|
||||
private Integer period;
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("客户编号")
|
||||
private Long customerId;
|
||||
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
|
||||
@ExcelProperty("客户名字")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("合同编号")
|
||||
private Long contractId;
|
||||
@Schema(description = "合同编号", example = "Q110")
|
||||
@ExcelProperty("合同编号")
|
||||
private String contractNo;
|
||||
|
||||
@Schema(description = "负责人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("负责人编号")
|
||||
private Long ownerUserId;
|
||||
@Schema(description = "负责人", example = "test")
|
||||
@ExcelProperty("负责人")
|
||||
private String ownerUserName;
|
||||
|
||||
@Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
|
||||
@ExcelProperty("计划回款日期")
|
||||
private LocalDateTime returnTime;
|
||||
|
||||
@Schema(description = "计划回款方式", example = "1")
|
||||
@ExcelProperty("计划回款方式")
|
||||
private Integer returnType;
|
||||
|
||||
@Schema(description = "计划回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
|
||||
@ExcelProperty("计划回款金额")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "回款编号", example = "19852")
|
||||
@ExcelProperty("回款编号")
|
||||
private Long receivableId;
|
||||
@Schema(description = "回款信息")
|
||||
@ExcelProperty("回款信息")
|
||||
private CrmReceivableRespVO receivable;
|
||||
|
||||
@Schema(description = "提前几天提醒", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("提前几天提醒")
|
||||
private Integer remindDays;
|
||||
|
||||
@Schema(description = "提醒日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
|
||||
@ExcelProperty("提醒日期")
|
||||
private LocalDateTime remindTime;
|
||||
|
||||
@Schema(description = "备注", example = "备注")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.receivable;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.contract.CrmContractRespVO;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@ -8,37 +9,47 @@ import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
// TODO 芋艿:导出的 VO,可以考虑使用 @Excel 注解,实现导出功能
|
||||
@Schema(description = "管理后台 - CRM 回款 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CrmReceivableRespVO {
|
||||
|
||||
@Schema(description = "编号", example = "25787")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "回款编号", example = "31177")
|
||||
@ExcelProperty("回款编号")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "回款计划编号", example = "1024")
|
||||
@ExcelProperty("回款计划编号")
|
||||
private Long planId;
|
||||
|
||||
@Schema(description = "回款方式", example = "2")
|
||||
@ExcelProperty("回款方式")
|
||||
private Integer returnType;
|
||||
|
||||
@Schema(description = "回款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "9000")
|
||||
@ExcelProperty("回款金额")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "计划回款日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-02-02")
|
||||
@ExcelProperty("计划回款日期")
|
||||
private LocalDateTime returnTime;
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("客户编号")
|
||||
private Long customerId;
|
||||
@Schema(description = "客户名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
|
||||
@ExcelProperty("客户名字")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("合同编号")
|
||||
private Long contractId;
|
||||
@Schema(description = "合同信息")
|
||||
@ExcelProperty("合同信息")
|
||||
private CrmContractRespVO contract;
|
||||
|
||||
@Schema(description = "负责人的用户编号", example = "25682")
|
||||
@ -56,20 +67,26 @@ public class CrmReceivableRespVO {
|
||||
private String processInstanceId;
|
||||
|
||||
@Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
@ExcelProperty("审批状态")
|
||||
private Integer auditStatus;
|
||||
|
||||
@Schema(description = "备注", example = "备注")
|
||||
@Schema(description = "工作流编号", example = "备注")
|
||||
@ExcelProperty("工作流编号")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@Schema(description = "创建人", example = "25682")
|
||||
@ExcelProperty("创建人")
|
||||
private String creator;
|
||||
@Schema(description = "创建人名字", example = "test")
|
||||
@ExcelProperty("创建人名字")
|
||||
private String creatorName;
|
||||
|
||||
}
|
||||
|
@ -30,12 +30,14 @@ import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
|
||||
import cn.iocoder.yudao.module.crm.service.receivable.CrmReceivableService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -86,7 +88,9 @@ public class CrmContractServiceImpl implements CrmContractService {
|
||||
private CrmContactService contactService;
|
||||
@Resource
|
||||
private CrmContractConfigService contractConfigService;
|
||||
|
||||
@Resource
|
||||
@Lazy // 延迟加载,避免循环依赖
|
||||
private CrmReceivableService receivableService;
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
@Resource
|
||||
@ -222,9 +226,12 @@ public class CrmContractServiceImpl implements CrmContractService {
|
||||
success = CRM_CONTRACT_DELETE_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void deleteContract(Long id) {
|
||||
// TODO @puhui999:如果被 CrmReceivableDO 所使用,则不允许删除
|
||||
// 校验存在
|
||||
CrmContractDO contract = validateContractExists(id);
|
||||
// 如果被 CrmReceivableDO 所使用,则不允许删除
|
||||
if (CollUtil.isNotEmpty(receivableService.getReceivableByContractId(contract.getId()))) {
|
||||
throw exception(CONTRACT_DELETE_FAIL);
|
||||
}
|
||||
// 删除
|
||||
contractMapper.deleteById(id);
|
||||
// 删除数据权限
|
||||
|
@ -122,4 +122,12 @@ public interface CrmReceivableService {
|
||||
*/
|
||||
Map<Long, BigDecimal> getReceivablePriceMapByContractId(Collection<Long> contractIds);
|
||||
|
||||
/**
|
||||
* 更具合同编号查询回款列表
|
||||
*
|
||||
* @param contractId 合同编号
|
||||
* @return 回款
|
||||
*/
|
||||
List<CrmReceivableDO> getReceivableByContractId(Long contractId);
|
||||
|
||||
}
|
||||
|
@ -37,10 +37,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
@ -81,7 +78,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
@Resource
|
||||
private BpmProcessInstanceApi bpmProcessInstanceApi;
|
||||
|
||||
// TODO @puhui999:操作日志没记录上
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_CREATE_SUB_TYPE, bizNo = "{{#receivable.id}}",
|
||||
@ -115,6 +111,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
|
||||
// 5. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("receivable", receivable);
|
||||
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
|
||||
return receivable.getId();
|
||||
}
|
||||
|
||||
@ -156,7 +153,6 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO @puhui999:操作日志没记录上
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_RECEIVABLE_TYPE, subType = CRM_RECEIVABLE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
||||
@ -165,10 +161,13 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
public void updateReceivable(CrmReceivableSaveReqVO updateReqVO) {
|
||||
Assert.notNull(updateReqVO.getId(), "回款编号不能为空");
|
||||
updateReqVO.setOwnerUserId(null).setCustomerId(null).setContractId(null).setPlanId(null); // 不允许修改的字段
|
||||
// 1.1 校验可回款金额超过上限
|
||||
validateReceivablePriceExceedsLimit(updateReqVO);
|
||||
// 1.2 校验存在
|
||||
// 1.1 校验存在
|
||||
CrmReceivableDO receivable = validateReceivableExists(updateReqVO.getId());
|
||||
updateReqVO.setOwnerUserId(receivable.getOwnerUserId()).setCustomerId(receivable.getCustomerId())
|
||||
.setContractId(receivable.getContractId()).setPlanId(receivable.getPlanId()); // 设置已存在的值
|
||||
// 1.2 校验可回款金额超过上限
|
||||
validateReceivablePriceExceedsLimit(updateReqVO);
|
||||
|
||||
// 1.3 只有草稿、审批中,可以编辑;
|
||||
if (!ObjectUtils.equalsAny(receivable.getAuditStatus(), CrmAuditStatusEnum.DRAFT.getStatus(),
|
||||
CrmAuditStatusEnum.PROCESS.getStatus())) {
|
||||
@ -180,8 +179,17 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
receivableMapper.updateById(updateObj);
|
||||
|
||||
// 3. 记录操作日志上下文
|
||||
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
|
||||
LogRecordContext.putVariable("receivable", receivable);
|
||||
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
|
||||
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(receivable, CrmReceivableSaveReqVO.class));
|
||||
}
|
||||
|
||||
private Integer getReceivablePeriod(Long planId) {
|
||||
if (Objects.isNull(planId)) {
|
||||
return null;
|
||||
}
|
||||
CrmReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(planId);
|
||||
return receivablePlan.getPeriod();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,8 +220,10 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
if (receivable.getPlanId() != null && receivablePlanService.getReceivablePlan(receivable.getPlanId()) != null) {
|
||||
throw exception(RECEIVABLE_DELETE_FAIL);
|
||||
}
|
||||
// TODO @puhui999:审批通过时,不允许删除;
|
||||
|
||||
// 1.3 审批通过时,不允许删除
|
||||
if (ObjUtil.equal(receivable.getAuditStatus(), CrmAuditStatusEnum.APPROVE.getStatus())) {
|
||||
throw exception(RECEIVABLE_DELETE_FAIL_IS_APPROVE);
|
||||
}
|
||||
// 2. 删除
|
||||
receivableMapper.deleteById(id);
|
||||
// 3. 删除数据权限
|
||||
@ -221,6 +231,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
|
||||
// 4. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("receivable", receivable);
|
||||
LogRecordContext.putVariable("period", getReceivablePeriod(receivable.getPlanId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -289,4 +300,9 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
|
||||
return receivableMapper.selectReceivablePriceMapByContractId(contractIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmReceivableDO> getReceivableByContractId(Long contractId) {
|
||||
return receivableMapper.selectList(CrmReceivableDO::getContractId, contractId);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user