crm: 1)调整合同的 CRM 前缀;2)增加基于客户查询合同分页

This commit is contained in:
YunaiV 2023-11-30 19:12:37 +08:00
parent fe4b51b9ad
commit 2d9f5cc4d0
35 changed files with 379 additions and 369 deletions

View File

@ -1,61 +0,0 @@
package cn.iocoder.yudao.module.crm.enums;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import java.util.Arrays;
// TODO @liuhongfeng这个状态还是搞成专属 CrmReceivableDO 专属的 status
/**
* 流程审批状态枚举类
* 0 未审核 1 审核通过 2 审核拒绝 3 审核中 4 已撤回 TODO @liuhongfeng这一行可以删除因为已经有枚举属性了哈
* @author 赤焰
*/
// TODO @liuhongfeng可以使用 @Getter@AllArgsConstructor 简化 get构造方法
public enum AuditStatusEnum implements IntArrayValuable {
// TODO @liuhongfeng草稿 010 审核中20 审核通过30 审核拒绝40 已撤回主要是留好间隙万一每个地方要做点拓展 然后枚举字段的顺序调整下审批中一定要放两个审批通过拒绝前面哈
/**
* 未审批
*/
AUDIT_NEW(0, "未审批"),
/**
* 审核通过
*/
AUDIT_FINISH(1, "审核通过"),
/**
* 审核拒绝
*/
AUDIT_REJECT(2, "审核拒绝"),
/**
* 审核中
*/
AUDIT_DOING(3, "审核中"),
/**
* 已撤回
*/
AUDIT_RETURN(4, "已撤回");
// TODO liuhongfengvalue 改成 statusdesc 改成 name
private final Integer value;
private final String desc;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(AuditStatusEnum::getValue).toArray();
AuditStatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return value;
}
public String getDesc() {
return desc;
}
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -11,6 +11,6 @@ public interface DictTypeConstants {
String CRM_CUSTOMER_INDUSTRY = "crm_customer_industry"; // CRM 客户所属行业
String CRM_CUSTOMER_LEVEL = "crm_customer_level"; // CRM 客户等级
String CRM_CUSTOMER_SOURCE = "crm_customer_source"; // CRM 客户来源
String CRM_RECEIVABLE_CHECK_STATUS = "crm_receivable_check_status"; // CRM 审批状态
String CRM_AUDIT_STATUS = "crm_audit_status"; // CRM 审批状态
}

View File

@ -1,8 +0,0 @@
package cn.iocoder.yudao.module.crm.enums;
// TODO @liuhongfeng这个的作用是
/**
* @author 赤焰
*/
public enum ReturnTypeEnum {
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.crm.enums.common;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* CRM 的审批状态
*
* @author 赤焰
*/
@RequiredArgsConstructor
@Getter
public enum CrmAuditStatusEnum implements IntArrayValuable {
DRAFT(0, "未提交"),
PROCESS(10, "审批中"),
APPROVE(20, "审核通过"),
REJECT(30, "审核不通过"),
CANCEL(40, "已取消");
private final Integer status;
private final String name;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmAuditStatusEnum::getStatus).toArray();
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -19,7 +19,7 @@ public enum CrmBizTypeEnum implements IntArrayValuable {
CRM_LEADS(1, "线索"),
CRM_CUSTOMER(2, "客户"),
CRM_CONTACTS(3, "联系人"),
CRM_CONTACT(3, "联系人"),
CRM_BUSINESS(4, "商机"),
CRM_CONTRACT(5, "合同");

View File

@ -151,7 +151,7 @@ public class CrmContactController {
// 1. 获取客户列表
List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList(
convertSet(contactList, CrmContactDO::getCustomerId));
// 2. 获取创建人人列表
// 2. 获取创建人责人列表
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList,
contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
// 3. 直属上级

View File

@ -1,13 +1,20 @@
package cn.iocoder.yudao.module.crm.controller.admin.contract;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.service.contract.ContractService;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -20,8 +27,12 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -29,22 +40,27 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
@RestController
@RequestMapping("/crm/contract")
@Validated
public class ContractController {
public class CrmContractController {
@Resource
private ContractService contractService;
private CrmContractService contractService;
@Resource
private CrmCustomerService customerService;
@Resource
private AdminUserApi adminUserApi;
@PostMapping("/create")
@Operation(summary = "创建合同")
@PreAuthorize("@ss.hasPermission('crm:contract:create')")
public CommonResult<Long> createContract(@Valid @RequestBody ContractCreateReqVO createReqVO) {
public CommonResult<Long> createContract(@Valid @RequestBody CrmContractCreateReqVO createReqVO) {
return success(contractService.createContract(createReqVO, getLoginUserId()));
}
@PutMapping("/update")
@Operation(summary = "更新合同")
@PreAuthorize("@ss.hasPermission('crm:contract:update')")
public CommonResult<Boolean> updateContract(@Valid @RequestBody ContractUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateContract(@Valid @RequestBody CrmContractUpdateReqVO updateReqVO) {
contractService.updateContract(updateReqVO);
return success(true);
}
@ -63,28 +79,56 @@ public class ContractController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<ContractRespVO> getContract(@RequestParam("id") Long id) {
ContractDO contract = contractService.getContract(id);
CrmContractDO contract = contractService.getContract(id);
return success(ContractConvert.INSTANCE.convert(contract));
}
@GetMapping("/page")
@Operation(summary = "获得合同分页")
@PreAuthorize("@ss.hasPermission('crm:contract:query')")
public CommonResult<PageResult<ContractRespVO>> getContractPage(@Valid ContractPageReqVO pageVO) {
PageResult<ContractDO> pageResult = contractService.getContractPage(pageVO);
return success(ContractConvert.INSTANCE.convertPage(pageResult));
public CommonResult<PageResult<ContractRespVO>> getContractPage(@Valid CrmContractPageReqVO pageVO) {
PageResult<CrmContractDO> pageResult = contractService.getContractPage(pageVO);
return success(convertDetailContractPage(pageResult));
}
@GetMapping("/page-by-customer")
@Operation(summary = "获得联系人分页,基于指定客户")
public CommonResult<PageResult<ContractRespVO>> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) {
Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空");
PageResult<CrmContractDO> pageResult = contractService.getContractPageByCustomer(pageVO);
return success(convertDetailContractPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出合同 Excel")
@PreAuthorize("@ss.hasPermission('crm:contract:export')")
@OperateLog(type = EXPORT)
public void exportContractExcel(@Valid ContractExportReqVO exportReqVO,
public void exportContractExcel(@Valid CrmContractPageReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ContractDO> list = contractService.getContractList(exportReqVO);
PageResult<CrmContractDO> pageResult = contractService.getContractPage(exportReqVO);
// 导出 Excel
List<ContractExcelVO> datas = ContractConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "合同.xls", "数据", ContractExcelVO.class, datas);
ExcelUtils.write(response, "合同.xls", "数据", CrmContractExcelVO.class,
ContractConvert.INSTANCE.convertList02(pageResult.getList()));
}
/**
* 转换成详细的联系人分页即读取关联信息
*
* @param pageResult 联系人分页
* @return 详细的联系人分页
*/
private PageResult<ContractRespVO> convertDetailContractPage(PageResult<CrmContractDO> pageResult) {
List<CrmContractDO> contactList = pageResult.getList();
if (CollUtil.isEmpty(contactList)) {
return PageResult.empty(pageResult.getTotal());
}
// 1. 获取客户列表
List<CrmCustomerDO> customerList = customerService.getCustomerList(
convertSet(contactList, CrmContractDO::getCustomerId));
// 2. 获取创建人负责人列表
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList,
contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
return ContractConvert.INSTANCE.convertPage(pageResult, userMap, customerList);
}
@PutMapping("/transfer")

View File

@ -1,37 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - CRM 合同 Excel 导出 Request VO参数和 ContractPageReqVO 是一致的")
@Data
public class ContractExportReqVO {
@Schema(description = "合同名称", example = "王五")
private String name;
@Schema(description = "客户编号", example = "18336")
private Long customerId;
@Schema(description = "商机编号", example = "10864")
private Long businessId;
@Schema(description = "下单日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] orderDate;
@Schema(description = "合同编号")
private String no;
@Schema(description = "整单折扣")
private Integer discountPercent;
@Schema(description = "产品总金额", example = "19510")
private Integer productPrice;
}

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContractRespVO extends ContractBaseVO {
public class ContractRespVO extends CrmContractBaseVO {
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
private Long id;
@ -19,4 +19,19 @@ public class ContractRespVO extends ContractBaseVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "创建人", example = "25682")
private String creator;
@Schema(description = "创建人名字", example = "test")
private String creatorName;
@Schema(description = "客户名字", example = "test")
private String customerName;
@Schema(description = "负责人", example = "test")
private String ownerUserName;
@Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
private Integer auditStatus;
}

View File

@ -9,13 +9,12 @@ import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
// TODO @dhb52所有类带下 Crm 前缀避免和别的模块重复
/**
* 合同 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class ContractBaseVO {
public class CrmContractBaseVO {
// TODO @dhb52类似 no 字段的 example 要写xia

View File

@ -9,6 +9,6 @@ import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContractCreateReqVO extends ContractBaseVO {
public class CrmContractCreateReqVO extends CrmContractBaseVO {
}

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime;
* @author dhb52
*/
@Data
public class ContractExcelVO {
public class CrmContractExcelVO {
@ExcelProperty("合同编号")
private Long id;

View File

@ -5,17 +5,15 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - CRM 合同分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContractPageReqVO extends PageParam {
public class CrmContractPageReqVO extends PageParam {
@Schema(description = "合同编号", example = "XYZ008")
private String no;
@Schema(description = "合同名称", example = "王五")
private String name;
@ -26,17 +24,4 @@ public class ContractPageReqVO extends PageParam {
@Schema(description = "商机编号", example = "10864")
private Long businessId;
@Schema(description = "下单日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] orderDate;
@Schema(description = "合同编号")
private String no;
@Schema(description = "整单折扣")
private Integer discountPercent;
@Schema(description = "产品总金额", example = "19510")
private Integer productPrice;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -14,19 +15,12 @@ public class CrmContractTransferReqVO {
@NotNull(message = "联系人编号不能为空")
private Long id;
/**
* 新负责人的用户编号
*/
@Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "新负责人的用户编号不能为空")
private Long newOwnerUserId;
/**
* 老负责人加入团队后的权限级别如果 null 说明移除
*
* 关联 {@link CrmPermissionLevelEnum}
*/
@Schema(description = "老负责人加入团队后的权限级别", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@InEnum(value = CrmPermissionLevelEnum.class)
private Integer oldOwnerPermissionLevel;
}

View File

@ -11,7 +11,7 @@ import javax.validation.constraints.NotNull;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ContractUpdateReqVO extends ContractBaseVO {
public class CrmContractUpdateReqVO extends CrmContractBaseVO {
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
@NotNull(message = "合同编号不能为空")

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.crm.enums.AuditStatusEnum;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -34,7 +34,7 @@ public class CrmReceivableBaseVO {
// TODO @liuhongfeng这个字段应该不是前端传递的噢而是后端自己生成的
@Schema(description = "审批状态", example = "1")
@InEnum(AuditStatusEnum.class)
@InEnum(CrmAuditStatusEnum.class)
private Integer checkStatus;
@Schema(description = "回款日期")

View File

@ -28,7 +28,7 @@ public class CrmReceivableExcelVO {
private Long contractId;
@ExcelProperty(value = "审批状态", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_RECEIVABLE_CHECK_STATUS)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_AUDIT_STATUS)
private Integer checkStatus;
@ExcelProperty("工作流编号")

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.crm.enums.AuditStatusEnum;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -28,7 +28,7 @@ public class CrmReceivablePlanBaseVO {
private Integer status;
@Schema(description = "审批状态", example = "1")
@InEnum(AuditStatusEnum.class)
@InEnum(CrmAuditStatusEnum.class)
private Integer checkStatus;
@Schema(description = "计划回款金额", example = "29675")

View File

@ -31,7 +31,7 @@ public class CrmReceivablePlanExcelVO {
private Integer status;
@ExcelProperty(value = "审批状态", converter = DictConvert.class)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_RECEIVABLE_CHECK_STATUS)
@DictFormat(cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_AUDIT_STATUS)
private Integer checkStatus;
//@ExcelProperty("工作流编号")

View File

@ -19,6 +19,7 @@ import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
// TODO 芋艿convert 后面在梳理下略微有点乱
/**
* CRM 联系人 Convert
*
@ -44,6 +45,7 @@ public interface ContactConvert {
List<CrmContactRespVO> list = converList(pageResult.getList(), userMap, customerList, parentContactList);
return convertPage(pageResult).setList(list);
}
List<CrmContactSimpleRespVO> convertAllList(List<CrmContactDO> list);
@Mappings({

View File

@ -2,14 +2,20 @@ package cn.iocoder.yudao.module.crm.convert.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/**
* 合同 Convert
@ -21,17 +27,17 @@ public interface ContractConvert {
ContractConvert INSTANCE = Mappers.getMapper(ContractConvert.class);
ContractDO convert(ContractCreateReqVO bean);
CrmContractDO convert(CrmContractCreateReqVO bean);
ContractDO convert(ContractUpdateReqVO bean);
CrmContractDO convert(CrmContractUpdateReqVO bean);
ContractRespVO convert(ContractDO bean);
ContractRespVO convert(CrmContractDO bean);
List<ContractRespVO> convertList(List<ContractDO> list);
List<ContractRespVO> convertList(List<CrmContractDO> list);
PageResult<ContractRespVO> convertPage(PageResult<ContractDO> page);
PageResult<ContractRespVO> convertPage(PageResult<CrmContractDO> page);
List<ContractExcelVO> convertList02(List<ContractDO> list);
List<CrmContractExcelVO> convertList02(List<CrmContractDO> list);
@Mappings({
@Mapping(target = "bizId", source = "reqVO.id"),
@ -39,4 +45,25 @@ public interface ContractConvert {
})
CrmPermissionTransferReqBO convert(CrmContractTransferReqVO reqVO, Long userId);
default PageResult<ContractRespVO> convertPage(PageResult<CrmContractDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList) {
return new PageResult<>(converList(pageResult.getList(), userMap, customerList), pageResult.getTotal());
}
default List<ContractRespVO> converList(List<CrmContractDO> contractList, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList) {
List<ContractRespVO> result = convertList(contractList);
Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId);
result.forEach(item -> {
setUserInfo(item, userMap);
findAndThen(customerMap, item.getCustomerId(), customer -> item.setCustomerName(customer.getName()));
});
return result;
}
static void setUserInfo(ContractRespVO contract, Map<Long, AdminUserRespDTO> userMap) {
findAndThen(userMap, contract.getOwnerUserId(), user -> contract.setOwnerUserName(user.getNickname()));
findAndThen(userMap, Long.parseLong(contract.getCreator()), user -> contract.setCreatorName(user.getNickname()));
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.contract;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -8,8 +9,9 @@ import lombok.*;
import java.time.LocalDateTime;
// TODO 芋艿实体的梳理
/**
* 合同 DO
* CRM 合同 DO
*
* @author dhb52
*/
@ -21,7 +23,7 @@ import java.time.LocalDateTime;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ContractDO extends BaseDO {
public class CrmContractDO extends BaseDO {
/**
* 合同编号
@ -89,4 +91,18 @@ public class ContractDO extends BaseDO {
*/
private String remark;
/**
* 负责人的用户编号
*
* 关联 AdminUserDO id 字段
*/
private Long ownerUserId;
/**
* 审批状态
*
* 枚举 {@link CrmAuditStatusEnum}
*/
private Integer auditStatus;
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.receivable;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -50,13 +51,13 @@ public class CrmReceivableDO extends BaseDO {
/**
* 合同 ID
*
* 对应实体 {@link cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO}
* 对应实体 {@link CrmContractDO}
*/
private Long contractId;
// TODO @liuhongfeng对应字典参考别的模块枚举 {@link XXXX}另外这个字段就叫 status整体状态不只审批
/**
* 审批状态
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_RECEIVABLE_CHECK_STATUS}
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_AUDIT_STATUS}
*/
private Integer checkStatus;
/**

View File

@ -48,7 +48,7 @@ public class CrmReceivablePlanDO extends BaseDO {
/**
* 审批状态
*
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_RECEIVABLE_CHECK_STATUS}
* 对应字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_AUDIT_STATUS}
* // TODO @liuhongfeng关联的枚举
*/
private Integer checkStatus;

View File

@ -30,7 +30,7 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
default PageResult<CrmContactDO> selectPageByCustomer(CrmContactPageReqVO pageVO) {
return selectPage(pageVO, new LambdaQueryWrapperX<CrmContactDO>()
.eq(CrmContactDO::getCustomerId, pageVO.getCustomerId())
.eq(CrmContactDO::getCustomerId, pageVO.getCustomerId()) // 必须传递
.likeIfPresent(CrmContactDO::getName, pageVO.getName())
.eqIfPresent(CrmContactDO::getMobile, pageVO.getMobile())
.eqIfPresent(CrmContactDO::getTelephone, pageVO.getTelephone())

View File

@ -1,45 +0,0 @@
package cn.iocoder.yudao.module.crm.dal.mysql.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 合同 Mapper
*
* @author dhb52
*/
@Mapper
public interface ContractMapper extends BaseMapperX<ContractDO> {
default PageResult<ContractDO> selectPage(ContractPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ContractDO>()
.likeIfPresent(ContractDO::getName, reqVO.getName())
.eqIfPresent(ContractDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ContractDO::getBusinessId, reqVO.getBusinessId())
.betweenIfPresent(ContractDO::getOrderDate, reqVO.getOrderDate())
.eqIfPresent(ContractDO::getNo, reqVO.getNo())
.eqIfPresent(ContractDO::getDiscountPercent, reqVO.getDiscountPercent())
.eqIfPresent(ContractDO::getProductPrice, reqVO.getProductPrice())
.orderByDesc(ContractDO::getId));
}
default List<ContractDO> selectList(ContractExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ContractDO>()
.likeIfPresent(ContractDO::getName, reqVO.getName())
.eqIfPresent(ContractDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ContractDO::getBusinessId, reqVO.getBusinessId())
.betweenIfPresent(ContractDO::getOrderDate, reqVO.getOrderDate())
.eqIfPresent(ContractDO::getNo, reqVO.getNo())
.eqIfPresent(ContractDO::getDiscountPercent, reqVO.getDiscountPercent())
.eqIfPresent(ContractDO::getProductPrice, reqVO.getProductPrice())
.orderByDesc(ContractDO::getId));
}
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.crm.dal.mysql.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import org.apache.ibatis.annotations.Mapper;
/**
* CRM 合同 Mapper
*
* @author dhb52
*/
@Mapper
public interface CrmContractMapper extends BaseMapperX<CrmContractDO> {
default PageResult<CrmContractDO> selectPage(CrmContractPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmContractDO>()
.likeIfPresent(CrmContractDO::getNo, reqVO.getNo())
.likeIfPresent(CrmContractDO::getName, reqVO.getName())
.eqIfPresent(CrmContractDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(CrmContractDO::getBusinessId, reqVO.getBusinessId())
.orderByDesc(CrmContractDO::getId));
}
default PageResult<CrmContractDO> selectPageByCustomer(CrmContractPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CrmContractDO>()
.eq(CrmContractDO::getCustomerId, reqVO.getCustomerId()) // 必须传递
.likeIfPresent(CrmContractDO::getNo, reqVO.getNo())
.likeIfPresent(CrmContractDO::getName, reqVO.getName())
.eqIfPresent(CrmContractDO::getBusinessId, reqVO.getBusinessId())
.orderByDesc(CrmContractDO::getId));
}
}

View File

@ -61,13 +61,13 @@ public class CrmContactServiceImpl implements CrmContactService {
// 2. 创建数据权限
crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(userId)
.setBizType(CrmBizTypeEnum.CRM_CONTACTS.getType()).setBizId(contact.getId())
.setBizType(CrmBizTypeEnum.CRM_CONTACT.getType()).setBizId(contact.getId())
.setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
return contact.getId();
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
public void updateContact(CrmContactUpdateReqVO updateReqVO) {
// 1. 校验存在
validateContactExists(updateReqVO.getId());
@ -98,7 +98,7 @@ public class CrmContactServiceImpl implements CrmContactService {
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
public void deleteContact(Long id) {
// 校验存在
validateContactExists(id);
@ -114,7 +114,7 @@ public class CrmContactServiceImpl implements CrmContactService {
// TODO 芋艿是否要做数据权限的校验
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACTS, bizId = "#id", level = CrmPermissionLevelEnum.READ)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.READ)
public CrmContactDO getContact(Long id) {
return contactMapper.selectById(id);
}
@ -134,9 +134,9 @@ public class CrmContactServiceImpl implements CrmContactService {
}
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageVO.customerId", level = CrmPermissionLevelEnum.READ)
public PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageVO) {
return contactMapper.selectPageByCustomer(pageVO);
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ)
public PageResult<CrmContactDO> getContactPageByCustomer(CrmContactPageReqVO pageReqVO) {
return contactMapper.selectPageByCustomer(pageReqVO);
}
@Override

View File

@ -1,81 +0,0 @@
package cn.iocoder.yudao.module.crm.service.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* 合同 Service 接口
*
* @author dhb52
*/
public interface ContractService {
/**
* 创建合同
*
* @param createReqVO 创建信息
* @param userId 用户编号
* @return 编号
*/
Long createContract(@Valid ContractCreateReqVO createReqVO, Long userId);
/**
* 更新合同
*
* @param updateReqVO 更新信息
*/
void updateContract(@Valid ContractUpdateReqVO updateReqVO);
/**
* 删除合同
*
* @param id 编号
*/
void deleteContract(Long id);
/**
* 获得合同
*
* @param id 编号
* @return 合同
*/
ContractDO getContract(Long id);
/**
* 获得合同列表
*
* @param ids 编号
* @return 合同列表
*/
List<ContractDO> getContractList(Collection<Long> ids);
/**
* 获得合同分页
*
* @param pageReqVO 分页查询
* @return 合同分页
*/
PageResult<ContractDO> getContractPage(ContractPageReqVO pageReqVO);
/**
* 获得合同列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 合同列表
*/
List<ContractDO> getContractList(ContractExportReqVO exportReqVO);
/**
* 合同转移
*
* @param reqVO 请求
* @param userId 用户编号
*/
void transferContract(CrmContractTransferReqVO reqVO, Long userId);
}

View File

@ -0,0 +1,89 @@
package cn.iocoder.yudao.module.crm.service.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* CRM 合同 Service 接口
*
* @author dhb52
*/
public interface CrmContractService {
/**
* 创建合同
*
* @param createReqVO 创建信息
* @param userId 用户编号
* @return 编号
*/
Long createContract(@Valid CrmContractCreateReqVO createReqVO, Long userId);
/**
* 更新合同
*
* @param updateReqVO 更新信息
*/
void updateContract(@Valid CrmContractUpdateReqVO updateReqVO);
/**
* 删除合同
*
* @param id 编号
*/
void deleteContract(Long id);
/**
* 获得合同
*
* @param id 编号
* @return 合同
*/
CrmContractDO getContract(Long id);
/**
* 获得合同列表
*
* @param ids 编号
* @return 合同列表
*/
List<CrmContractDO> getContractList(Collection<Long> ids);
/**
* 获得合同分页
*
* 数据权限基于 {@link CrmContractDO} 读取
*
* @param pageReqVO 分页查询
* @return 合同分页
*/
PageResult<CrmContractDO> getContractPage(CrmContractPageReqVO pageReqVO);
/**
* 获得合同分页基于指定客户
*
* 数据权限基于 {@link CrmCustomerDO} 读取
*
* @param pageReqVO 分页查询
* @return 联系人分页
*/
PageResult<CrmContractDO> getContractPageByCustomer(CrmContractPageReqVO pageReqVO);
/**
* 合同转移
*
* @param reqVO 请求
* @param userId 用户编号
*/
void transferContract(CrmContractTransferReqVO reqVO, Long userId);
}

View File

@ -3,13 +3,16 @@ package cn.iocoder.yudao.module.crm.service.contract;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.*;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO;
import cn.iocoder.yudao.module.crm.convert.contract.ContractConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper;
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
import org.springframework.stereotype.Service;
@ -24,48 +27,47 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_EXISTS;
/**
* 合同 Service 实现类
* CRM 合同 Service 实现类
*
* @author dhb52
*/
@Service
@Validated
public class ContractServiceImpl implements ContractService {
public class CrmContractServiceImpl implements CrmContractService {
@Resource
private ContractMapper contractMapper;
private CrmContractMapper contractMapper;
@Resource
private CrmPermissionService crmPermissionService;
@Override
public Long createContract(ContractCreateReqVO createReqVO, Long userId) {
public Long createContract(CrmContractCreateReqVO createReqVO, Long userId) {
// 插入
ContractDO contract = ContractConvert.INSTANCE.convert(createReqVO);
CrmContractDO contract = ContractConvert.INSTANCE.convert(createReqVO);
contractMapper.insert(contract);
// 创建数据权限
crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType())
.setBizId(contract.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
// 返回
crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(userId)
.setBizType(CrmBizTypeEnum.CRM_CONTRACT.getType()).setBizId(contract.getId())
.setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
return contract.getId();
}
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, level = CrmPermissionLevelEnum.WRITE)
public void updateContract(ContractUpdateReqVO updateReqVO) {
public void updateContract(CrmContractUpdateReqVO updateReqVO) {
// 校验存在
validateContractExists(updateReqVO.getId());
// 更新
ContractDO updateObj = ContractConvert.INSTANCE.convert(updateReqVO);
CrmContractDO updateObj = ContractConvert.INSTANCE.convert(updateReqVO);
contractMapper.updateById(updateObj);
}
@Override
@Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, level = CrmPermissionLevelEnum.WRITE)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
public void deleteContract(Long id) {
// 校验存在
validateContractExists(id);
@ -73,22 +75,23 @@ public class ContractServiceImpl implements ContractService {
contractMapper.deleteById(id);
}
private ContractDO validateContractExists(Long id) {
ContractDO contract = contractMapper.selectById(id);
private CrmContractDO validateContractExists(Long id) {
CrmContractDO contract = contractMapper.selectById(id);
if (contract == null) {
throw exception(CONTRACT_NOT_EXISTS);
}
return contract;
}
// TODO 芋艿是否要做数据权限的校验
@Override
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, level = CrmPermissionLevelEnum.READ)
public ContractDO getContract(Long id) {
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTRACT, bizId = "#id", level = CrmPermissionLevelEnum.READ)
public CrmContractDO getContract(Long id) {
return contractMapper.selectById(id);
}
@Override
public List<ContractDO> getContractList(Collection<Long> ids) {
public List<CrmContractDO> getContractList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
@ -96,13 +99,14 @@ public class ContractServiceImpl implements ContractService {
}
@Override
public PageResult<ContractDO> getContractPage(ContractPageReqVO pageReqVO) {
public PageResult<CrmContractDO> getContractPage(CrmContractPageReqVO pageReqVO) {
return contractMapper.selectPage(pageReqVO);
}
@Override
public List<ContractDO> getContractList(ContractExportReqVO exportReqVO) {
return contractMapper.selectList(exportReqVO);
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#pageReqVO.customerId", level = CrmPermissionLevelEnum.READ)
public PageResult<CrmContractDO> getContractPageByCustomer(CrmContractPageReqVO pageReqVO) {
return contractMapper.selectPageByCustomer(pageReqVO);
}
@Override

View File

@ -1,4 +0,0 @@
/**
* 合同
*/
package cn.iocoder.yudao.module.crm.service.contract;

View File

@ -10,12 +10,12 @@ import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivableP
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivablePlanPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivablePlanUpdateReqVO;
import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivablePlanConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.CrmReceivablePlanMapper;
import cn.iocoder.yudao.module.crm.enums.AuditStatusEnum;
import cn.iocoder.yudao.module.crm.service.contract.ContractService;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -40,7 +40,7 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService {
@Resource
private CrmReceivablePlanMapper crmReceivablePlanMapper;
@Resource
private ContractService contractService;
private CrmContractService contractService;
@Resource
private CrmCustomerService crmCustomerService;
@ -52,7 +52,7 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService {
receivablePlan.setStatus(CommonStatusEnum.ENABLE.getStatus());
}
if (ObjectUtil.isNull(receivablePlan.getCheckStatus())){
receivablePlan.setCheckStatus(AuditStatusEnum.AUDIT_NEW.getValue());
receivablePlan.setCheckStatus(CrmAuditStatusEnum.DRAFT.getStatus());
}
checkReceivablePlan(receivablePlan);
@ -68,7 +68,7 @@ public class CrmReceivablePlanServiceImpl implements CrmReceivablePlanService {
throw exception(CONTRACT_NOT_EXISTS);
}
ContractDO contract = contractService.getContract(receivablePlan.getContractId());
CrmContractDO contract = contractService.getContract(receivablePlan.getContractId());
if(ObjectUtil.isNull(contract)){
throw exception(CONTRACT_NOT_EXISTS);
}

View File

@ -10,13 +10,13 @@ import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivableE
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivablePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.CrmReceivableUpdateReqVO;
import cn.iocoder.yudao.module.crm.convert.receivable.CrmReceivableConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivableDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.CrmReceivablePlanDO;
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.CrmReceivableMapper;
import cn.iocoder.yudao.module.crm.enums.AuditStatusEnum;
import cn.iocoder.yudao.module.crm.service.contract.ContractService;
import cn.iocoder.yudao.module.crm.enums.common.CrmAuditStatusEnum;
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -41,7 +41,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
@Resource
private CrmReceivableMapper crmReceivableMapper;
@Resource
private ContractService contractService;
private CrmContractService contractService;
@Resource
private CrmCustomerService crmCustomerService;
@Resource
@ -57,7 +57,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
receivable.setStatus(CommonStatusEnum.ENABLE.getStatus());
}
if (ObjectUtil.isNull(receivable.getCheckStatus())){
receivable.setCheckStatus(AuditStatusEnum.AUDIT_NEW.getValue());
receivable.setCheckStatus(CrmAuditStatusEnum.DRAFT.getStatus());
}
// TODO @liuhongfeng一般来说逻辑的写法是要先检查后操作 db所以你这个 check 应该放到 CrmReceivableDO receivable 之前
@ -75,7 +75,7 @@ public class CrmReceivableServiceImpl implements CrmReceivableService {
throw exception(CONTRACT_NOT_EXISTS);
}
ContractDO contract = contractService.getContract(receivable.getContractId());
CrmContractDO contract = contractService.getContract(receivable.getContractId());
if(ObjectUtil.isNull(contract)){
throw exception(CONTRACT_NOT_EXISTS);
}

View File

@ -2,12 +2,12 @@ package cn.iocoder.yudao.module.crm.service.contract;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractCreateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractExportReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.ContractUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.ContractDO;
import cn.iocoder.yudao.module.crm.dal.mysql.contract.ContractMapper;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractUpdateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Import;
@ -26,54 +26,54 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTRACT_NOT_
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link ContractServiceImpl} 的单元测试类
* {@link CrmContractServiceImpl} 的单元测试类
*
* @author dhb52
*/
@Import(ContractServiceImpl.class)
@Import(CrmContractServiceImpl.class)
public class ContractServiceImplTest extends BaseDbUnitTest {
@Resource
private ContractServiceImpl contractService;
private CrmContractServiceImpl contractService;
@Resource
private ContractMapper contractMapper;
private CrmContractMapper contractMapper;
@Test
public void testCreateContract_success() {
// 准备参数
ContractCreateReqVO reqVO = randomPojo(ContractCreateReqVO.class);
CrmContractCreateReqVO reqVO = randomPojo(CrmContractCreateReqVO.class);
// 调用
Long contractId = contractService.createContract(reqVO, getLoginUserId());
// 断言
assertNotNull(contractId);
// 校验记录的属性是否正确
ContractDO contract = contractMapper.selectById(contractId);
CrmContractDO contract = contractMapper.selectById(contractId);
assertPojoEquals(reqVO, contract);
}
@Test
public void testUpdateContract_success() {
// mock 数据
ContractDO dbContract = randomPojo(ContractDO.class);
CrmContractDO dbContract = randomPojo(CrmContractDO.class);
contractMapper.insert(dbContract);// @Sql: 先插入出一条存在的数据
// 准备参数
ContractUpdateReqVO reqVO = randomPojo(ContractUpdateReqVO.class, o -> {
CrmContractUpdateReqVO reqVO = randomPojo(CrmContractUpdateReqVO.class, o -> {
o.setId(dbContract.getId()); // 设置更新的 ID
});
// 调用
contractService.updateContract(reqVO);
// 校验是否更新正确
ContractDO contract = contractMapper.selectById(reqVO.getId()); // 获取最新的
CrmContractDO contract = contractMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, contract);
}
@Test
public void testUpdateContract_notExists() {
// 准备参数
ContractUpdateReqVO reqVO = randomPojo(ContractUpdateReqVO.class);
CrmContractUpdateReqVO reqVO = randomPojo(CrmContractUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> contractService.updateContract(reqVO), CONTRACT_NOT_EXISTS);
@ -82,7 +82,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
@Test
public void testDeleteContract_success() {
// mock 数据
ContractDO dbContract = randomPojo(ContractDO.class);
CrmContractDO dbContract = randomPojo(CrmContractDO.class);
contractMapper.insert(dbContract);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbContract.getId();
@ -106,7 +106,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetContractPage() {
// mock 数据
ContractDO dbContract = randomPojo(ContractDO.class, o -> { // 等会查询到
CrmContractDO dbContract = randomPojo(CrmContractDO.class, o -> { // 等会查询到
o.setName(null);
o.setCustomerId(null);
o.setBusinessId(null);
@ -131,7 +131,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
// 测试 productPrice 不匹配
contractMapper.insert(cloneIgnoreId(dbContract, o -> o.setProductPrice(null)));
// 准备参数
ContractPageReqVO reqVO = new ContractPageReqVO();
CrmContractPageReqVO reqVO = new CrmContractPageReqVO();
reqVO.setName(null);
reqVO.setCustomerId(null);
reqVO.setBusinessId(null);
@ -141,7 +141,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
reqVO.setProductPrice(null);
// 调用
PageResult<ContractDO> pageResult = contractService.getContractPage(reqVO);
PageResult<CrmContractDO> pageResult = contractService.getContractPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
@ -152,7 +152,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetContractList() {
// mock 数据
ContractDO dbContract = randomPojo(ContractDO.class, o -> { // 等会查询到
CrmContractDO dbContract = randomPojo(CrmContractDO.class, o -> { // 等会查询到
o.setName("合同名称");
o.setCustomerId(null);
o.setBusinessId(null);
@ -187,7 +187,7 @@ public class ContractServiceImplTest extends BaseDbUnitTest {
reqVO.setProductPrice(null);
// 调用
List<ContractDO> list = contractService.getContractList(reqVO);
List<CrmContractDO> list = contractService.getContractList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbContract, list.get(0));