【新增】回款计划 功能

This commit is contained in:
liuhongfeng 2023-10-20 23:48:19 +08:00
parent 73f4fc8ceb
commit 34a5785768
20 changed files with 1116 additions and 0 deletions

View File

@ -93,3 +93,38 @@ CREATE TABLE `crm_receivable` (
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号', `tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '回款管理' ROW_FORMAT = DYNAMIC; ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '回款管理' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- 回款计划表
-- ----------------------------
DROP TABLE IF EXISTS `crm_receivable_plan`;
CREATE TABLE `crm_receivable_plan` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`index_no` bigint(20) NULL DEFAULT NULL COMMENT '期数',
`receivable_id` bigint(20) NULL DEFAULT NULL COMMENT '回款ID',
`status` tinyint(4) NOT NULL COMMENT '完成状态',
`check_status` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '审批状态',
`process_instance_id` bigint(20) NULL DEFAULT NULL COMMENT '工作流编号',
`price` decimal(10, 2) NULL DEFAULT NULL COMMENT '计划回款金额',
`return_time` datetime NULL DEFAULT NULL COMMENT '计划回款日期',
`remind_days` bigint(20) NULL DEFAULT NULL COMMENT '提前几天提醒',
`remind_time` datetime NULL DEFAULT NULL COMMENT '提醒日期',
`customer_id` bigint(20) NULL DEFAULT NULL COMMENT '客户ID',
`contract_id` bigint(20) NULL DEFAULT NULL COMMENT '合同ID',
`owner_user_id` bigint(20) NULL DEFAULT NULL COMMENT '负责人',
`sort` int(11) NULL DEFAULT NULL COMMENT '显示顺序',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '回款计划' ROW_FORMAT = DYNAMIC;

View File

@ -184,3 +184,64 @@ VALUES (
'回款管理导出', 'crm:receivable:export', 3, 5, @parentId, '回款管理导出', 'crm:receivable:export', 3, 5, @parentId,
'', '', '', 0 '', '', '', 0
); );
-- ----------------------------
-- 回款计划菜单
-- ----------------------------
-- 菜单 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status, component_name
)
VALUES (
'回款计划管理', '', 2, 0, 2375,
'receivable-plan', '', 'crm/receivablePlan/index', 0, 'ReceivablePlan'
);
-- 按钮父菜单ID
-- 暂时只支持 MySQL如果你是 OraclePostgreSQLSQLServer 的话需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();
-- 按钮 SQL
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'回款计划查询', 'crm:receivable-plan:query', 3, 1, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'回款计划创建', 'crm:receivable-plan:create', 3, 2, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'回款计划更新', 'crm:receivable-plan:update', 3, 3, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'回款计划删除', 'crm:receivable-plan:delete', 3, 4, @parentId,
'', '', '', 0
);
INSERT INTO system_menu(
name, permission, type, sort, parent_id,
path, icon, component, status
)
VALUES (
'回款计划导出', 'crm:receivable-plan:export', 3, 5, @parentId,
'', '', '', 0
);

View File

@ -17,4 +17,6 @@ public interface ErrorCodeConstants {
ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在"); ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_030_000_001, "回款管理不存在");
ErrorCode RECEIVABLE_PLAN_NOT_EXISTS = new ErrorCode(1_040_000_001, "回款计划不存在");
} }

View File

@ -0,0 +1,105 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
import cn.iocoder.yudao.module.crm.convert.receivable.ReceivablePlanConvert;
import cn.iocoder.yudao.module.crm.service.receivable.ReceivablePlanService;
/**
* @author 赤焰
*/
@Tag(name = "管理后台 - 回款计划")
@RestController
@RequestMapping("/crm/receivable-plan")
@Validated
public class ReceivablePlanController {
@Resource
private ReceivablePlanService receivablePlanService;
@PostMapping("/create")
@Operation(summary = "创建回款计划")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:create')")
public CommonResult<Long> createReceivablePlan(@Valid @RequestBody ReceivablePlanCreateReqVO createReqVO) {
return success(receivablePlanService.createReceivablePlan(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新回款计划")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:update')")
public CommonResult<Boolean> updateReceivablePlan(@Valid @RequestBody ReceivablePlanUpdateReqVO updateReqVO) {
receivablePlanService.updateReceivablePlan(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除回款计划")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:delete')")
public CommonResult<Boolean> deleteReceivablePlan(@RequestParam("id") Long id) {
receivablePlanService.deleteReceivablePlan(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得回款计划")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
public CommonResult<ReceivablePlanRespVO> getReceivablePlan(@RequestParam("id") Long id) {
ReceivablePlanDO receivablePlan = receivablePlanService.getReceivablePlan(id);
return success(ReceivablePlanConvert.INSTANCE.convert(receivablePlan));
}
@GetMapping("/list")
@Operation(summary = "获得回款计划列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
public CommonResult<List<ReceivablePlanRespVO>> getReceivablePlanList(@RequestParam("ids") Collection<Long> ids) {
List<ReceivablePlanDO> list = receivablePlanService.getReceivablePlanList(ids);
return success(ReceivablePlanConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得回款计划分页")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:query')")
public CommonResult<PageResult<ReceivablePlanRespVO>> getReceivablePlanPage(@Valid ReceivablePlanPageReqVO pageVO) {
PageResult<ReceivablePlanDO> pageResult = receivablePlanService.getReceivablePlanPage(pageVO);
return success(ReceivablePlanConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出回款计划 Excel")
@PreAuthorize("@ss.hasPermission('crm:receivable-plan:export')")
@OperateLog(type = EXPORT)
public void exportReceivablePlanExcel(@Valid ReceivablePlanExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<ReceivablePlanDO> list = receivablePlanService.getReceivablePlanList(exportReqVO);
// 导出 Excel
List<ReceivablePlanExcelVO> datas = ReceivablePlanConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "回款计划.xls", "数据", ReceivablePlanExcelVO.class, datas);
}
}

View File

@ -0,0 +1,68 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 回款计划 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class ReceivablePlanBaseVO {
@Schema(description = "期数")
private Long indexNo;
@Schema(description = "回款ID", example = "19852")
private Long receivableId;
@Schema(description = "完成状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
//@NotNull(message = "完成状态不能为空")
private Integer status;
@Schema(description = "审批状态", example = "1")
private String checkStatus;
@Schema(description = "工作流编号", example = "8909")
private Long processInstanceId;
@Schema(description = "计划回款金额", example = "29675")
private BigDecimal price;
@Schema(description = "计划回款日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime returnTime;
@Schema(description = "提前几天提醒")
private Long remindDays;
@Schema(description = "提醒日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime remindTime;
@Schema(description = "客户ID", example = "18026")
private Long customerId;
@Schema(description = "合同ID", example = "3473")
private Long contractId;
@Schema(description = "负责人", example = "17828")
private Long ownerUserId;
@Schema(description = "显示顺序")
private Integer sort;
@Schema(description = "备注", example = "随便")
private String remark;
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 回款计划创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReceivablePlanCreateReqVO extends ReceivablePlanBaseVO {
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.ExcelProperty;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
/**
* 回款计划 Excel VO
*
* @author 芋道源码
*/
@Data
public class ReceivablePlanExcelVO {
@ExcelProperty("ID")
private Long id;
@ExcelProperty("期数")
private Long indexNo;
@ExcelProperty("回款ID")
private Long receivableId;
@ExcelProperty(value = "完成状态", converter = DictConvert.class)
@DictFormat("common_status") // TODO 代码优化建议设置到对应的 XXXDictTypeConstants 枚举类中
private Integer status;
@ExcelProperty(value = "审批状态", converter = DictConvert.class)
@DictFormat("crm_receivable_check_status") // TODO 代码优化建议设置到对应的 XXXDictTypeConstants 枚举类中
private String checkStatus;
//@ExcelProperty("工作流编号")
//private Long processInstanceId;
@ExcelProperty("计划回款金额")
private BigDecimal price;
@ExcelProperty("计划回款日期")
private LocalDateTime returnTime;
@ExcelProperty("提前几天提醒")
private Long remindDays;
@ExcelProperty("提醒日期")
private LocalDateTime remindTime;
@ExcelProperty("客户ID")
private Long customerId;
@ExcelProperty("合同ID")
private Long contractId;
@ExcelProperty("负责人")
private Long ownerUserId;
//@ExcelProperty("显示顺序")
//private Integer sort;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.time.LocalDateTime;
import org.springframework.format.annotation.DateTimeFormat;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 回款计划 Excel 导出 Request VO参数和 ReceivablePlanPageReqVO 是一致的")
@Data
public class ReceivablePlanExportReqVO {
@Schema(description = "期数")
private Long indexNo;
@Schema(description = "完成状态", example = "2")
private Integer status;
@Schema(description = "审批状态", example = "1")
private String checkStatus;
@Schema(description = "计划回款日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] returnTime;
@Schema(description = "提前几天提醒")
private Long remindDays;
@Schema(description = "提醒日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] remindTime;
@Schema(description = "客户ID", example = "18026")
private Long customerId;
@Schema(description = "合同ID", example = "3473")
private Long contractId;
@Schema(description = "负责人", example = "17828")
private Long ownerUserId;
@Schema(description = "备注", example = "随便")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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 = "管理后台 - 回款计划分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReceivablePlanPageReqVO extends PageParam {
@Schema(description = "期数")
private Long indexNo;
@Schema(description = "完成状态", example = "2")
private Integer status;
@Schema(description = "审批状态", example = "1")
private String checkStatus;
@Schema(description = "计划回款日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] returnTime;
@Schema(description = "提前几天提醒")
private Long remindDays;
@Schema(description = "提醒日期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] remindTime;
@Schema(description = "客户ID", example = "18026")
private Long customerId;
@Schema(description = "合同ID", example = "3473")
private Long contractId;
@Schema(description = "负责人", example = "17828")
private Long ownerUserId;
@Schema(description = "备注", example = "随便")
private String remark;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 回款计划 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReceivablePlanRespVO extends ReceivablePlanBaseVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25153")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.crm.controller.admin.receivable.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 回款计划更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReceivablePlanUpdateReqVO extends ReceivablePlanBaseVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25153")
@NotNull(message = "ID不能为空")
private Long id;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.crm.convert.receivable;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
/**
* 回款计划 Convert
*
* @author 芋道源码
*/
@Mapper
public interface ReceivablePlanConvert {
ReceivablePlanConvert INSTANCE = Mappers.getMapper(ReceivablePlanConvert.class);
ReceivablePlanDO convert(ReceivablePlanCreateReqVO bean);
ReceivablePlanDO convert(ReceivablePlanUpdateReqVO bean);
ReceivablePlanRespVO convert(ReceivablePlanDO bean);
List<ReceivablePlanRespVO> convertList(List<ReceivablePlanDO> list);
PageResult<ReceivablePlanRespVO> convertPage(PageResult<ReceivablePlanDO> page);
List<ReceivablePlanExcelVO> convertList02(List<ReceivablePlanDO> list);
}

View File

@ -0,0 +1,94 @@
package cn.iocoder.yudao.module.crm.dal.dataobject.receivable;
import lombok.*;
import java.util.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 回款计划 DO
*
* @author 芋道源码
*/
@TableName("crm_receivable_plan")
@KeySequence("crm_receivable_plan_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReceivablePlanDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
* 期数
*/
private Long indexNo;
/**
* 回款ID
*/
private Long receivableId;
/**
* 完成状态
*
* 枚举 {@link TODO common_status 对应的类}
*/
private Integer status;
/**
* 审批状态
*
* 枚举 {@link TODO crm_receivable_check_status 对应的类}
*/
private String checkStatus;
/**
* 工作流编号
*/
private Long processInstanceId;
/**
* 计划回款金额
*/
private BigDecimal price;
/**
* 计划回款日期
*/
private LocalDateTime returnTime;
/**
* 提前几天提醒
*/
private Long remindDays;
/**
* 提醒日期
*/
private LocalDateTime remindTime;
/**
* 客户ID
*/
private Long customerId;
/**
* 合同ID
*/
private Long contractId;
/**
* 负责人
*/
private Long ownerUserId;
/**
* 显示顺序
*/
private Integer sort;
/**
* 备注
*/
private String remark;
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.yudao.module.crm.dal.mysql.receivable;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
/**
* 回款计划 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ReceivablePlanMapper extends BaseMapperX<ReceivablePlanDO> {
default PageResult<ReceivablePlanDO> selectPage(ReceivablePlanPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ReceivablePlanDO>()
.eqIfPresent(ReceivablePlanDO::getIndexNo, reqVO.getIndexNo())
.eqIfPresent(ReceivablePlanDO::getStatus, reqVO.getStatus())
.eqIfPresent(ReceivablePlanDO::getCheckStatus, reqVO.getCheckStatus())
.betweenIfPresent(ReceivablePlanDO::getReturnTime, reqVO.getReturnTime())
.eqIfPresent(ReceivablePlanDO::getRemindDays, reqVO.getRemindDays())
.betweenIfPresent(ReceivablePlanDO::getRemindTime, reqVO.getRemindTime())
.eqIfPresent(ReceivablePlanDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ReceivablePlanDO::getContractId, reqVO.getContractId())
.eqIfPresent(ReceivablePlanDO::getOwnerUserId, reqVO.getOwnerUserId())
.eqIfPresent(ReceivablePlanDO::getRemark, reqVO.getRemark())
.betweenIfPresent(ReceivablePlanDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ReceivablePlanDO::getId));
}
default List<ReceivablePlanDO> selectList(ReceivablePlanExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ReceivablePlanDO>()
.eqIfPresent(ReceivablePlanDO::getIndexNo, reqVO.getIndexNo())
.eqIfPresent(ReceivablePlanDO::getStatus, reqVO.getStatus())
.eqIfPresent(ReceivablePlanDO::getCheckStatus, reqVO.getCheckStatus())
.betweenIfPresent(ReceivablePlanDO::getReturnTime, reqVO.getReturnTime())
.eqIfPresent(ReceivablePlanDO::getRemindDays, reqVO.getRemindDays())
.betweenIfPresent(ReceivablePlanDO::getRemindTime, reqVO.getRemindTime())
.eqIfPresent(ReceivablePlanDO::getCustomerId, reqVO.getCustomerId())
.eqIfPresent(ReceivablePlanDO::getContractId, reqVO.getContractId())
.eqIfPresent(ReceivablePlanDO::getOwnerUserId, reqVO.getOwnerUserId())
.eqIfPresent(ReceivablePlanDO::getRemark, reqVO.getRemark())
.betweenIfPresent(ReceivablePlanDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ReceivablePlanDO::getId));
}
}

View File

@ -0,0 +1,70 @@
package cn.iocoder.yudao.module.crm.service.receivable;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
/**
* 回款计划 Service 接口
*
* @author 芋道源码
*/
public interface ReceivablePlanService {
/**
* 创建回款计划
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createReceivablePlan(@Valid ReceivablePlanCreateReqVO createReqVO);
/**
* 更新回款计划
*
* @param updateReqVO 更新信息
*/
void updateReceivablePlan(@Valid ReceivablePlanUpdateReqVO updateReqVO);
/**
* 删除回款计划
*
* @param id 编号
*/
void deleteReceivablePlan(Long id);
/**
* 获得回款计划
*
* @param id 编号
* @return 回款计划
*/
ReceivablePlanDO getReceivablePlan(Long id);
/**
* 获得回款计划列表
*
* @param ids 编号
* @return 回款计划列表
*/
List<ReceivablePlanDO> getReceivablePlanList(Collection<Long> ids);
/**
* 获得回款计划分页
*
* @param pageReqVO 分页查询
* @return 回款计划分页
*/
PageResult<ReceivablePlanDO> getReceivablePlanPage(ReceivablePlanPageReqVO pageReqVO);
/**
* 获得回款计划列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 回款计划列表
*/
List<ReceivablePlanDO> getReceivablePlanList(ReceivablePlanExportReqVO exportReqVO);
}

View File

@ -0,0 +1,93 @@
package cn.iocoder.yudao.module.crm.service.receivable;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.convert.receivable.ReceivablePlanConvert;
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.ReceivablePlanMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
/**
* 回款计划 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ReceivablePlanServiceImpl implements ReceivablePlanService {
@Resource
private ReceivablePlanMapper receivablePlanMapper;
@Override
public Long createReceivablePlan(ReceivablePlanCreateReqVO createReqVO) {
// 插入
ReceivablePlanDO receivablePlan = ReceivablePlanConvert.INSTANCE.convert(createReqVO);
if(ObjectUtil.isNull(receivablePlan.getStatus())){
receivablePlan.setStatus(CommonStatusEnum.ENABLE.getStatus());
}
receivablePlanMapper.insert(receivablePlan);
// 返回
return receivablePlan.getId();
}
@Override
public void updateReceivablePlan(ReceivablePlanUpdateReqVO updateReqVO) {
// 校验存在
validateReceivablePlanExists(updateReqVO.getId());
// 更新
ReceivablePlanDO updateObj = ReceivablePlanConvert.INSTANCE.convert(updateReqVO);
receivablePlanMapper.updateById(updateObj);
}
@Override
public void deleteReceivablePlan(Long id) {
// 校验存在
validateReceivablePlanExists(id);
// 删除
receivablePlanMapper.deleteById(id);
}
private void validateReceivablePlanExists(Long id) {
if (receivablePlanMapper.selectById(id) == null) {
throw exception(RECEIVABLE_PLAN_NOT_EXISTS);
}
}
@Override
public ReceivablePlanDO getReceivablePlan(Long id) {
return receivablePlanMapper.selectById(id);
}
@Override
public List<ReceivablePlanDO> getReceivablePlanList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return receivablePlanMapper.selectBatchIds(ids);
}
@Override
public PageResult<ReceivablePlanDO> getReceivablePlanPage(ReceivablePlanPageReqVO pageReqVO) {
return receivablePlanMapper.selectPage(pageReqVO);
}
@Override
public List<ReceivablePlanDO> getReceivablePlanList(ReceivablePlanExportReqVO exportReqVO) {
return receivablePlanMapper.selectList(exportReqVO);
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.receivable.ReceivablePlanMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@ -0,0 +1,231 @@
package cn.iocoder.yudao.module.crm.service.receivable;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import javax.annotation.Resource;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
import cn.iocoder.yudao.module.crm.controller.admin.receivable.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.receivable.ReceivablePlanDO;
import cn.iocoder.yudao.module.crm.dal.mysql.receivable.ReceivablePlanMapper;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import javax.annotation.Resource;
import org.springframework.context.annotation.Import;
import java.util.*;
import java.time.LocalDateTime;
import static cn.hutool.core.util.RandomUtil.*;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*;
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
/**
* {@link ReceivablePlanServiceImpl} 的单元测试类
*
* @author 芋道源码
*/
@Import(ReceivablePlanServiceImpl.class)
public class ReceivablePlanServiceImplTest extends BaseDbUnitTest {
@Resource
private ReceivablePlanServiceImpl receivablePlanService;
@Resource
private ReceivablePlanMapper receivablePlanMapper;
@Test
public void testCreateReceivablePlan_success() {
// 准备参数
ReceivablePlanCreateReqVO reqVO = randomPojo(ReceivablePlanCreateReqVO.class);
// 调用
Long receivablePlanId = receivablePlanService.createReceivablePlan(reqVO);
// 断言
assertNotNull(receivablePlanId);
// 校验记录的属性是否正确
ReceivablePlanDO receivablePlan = receivablePlanMapper.selectById(receivablePlanId);
assertPojoEquals(reqVO, receivablePlan);
}
@Test
public void testUpdateReceivablePlan_success() {
// mock 数据
ReceivablePlanDO dbReceivablePlan = randomPojo(ReceivablePlanDO.class);
receivablePlanMapper.insert(dbReceivablePlan);// @Sql: 先插入出一条存在的数据
// 准备参数
ReceivablePlanUpdateReqVO reqVO = randomPojo(ReceivablePlanUpdateReqVO.class, o -> {
o.setId(dbReceivablePlan.getId()); // 设置更新的 ID
});
// 调用
receivablePlanService.updateReceivablePlan(reqVO);
// 校验是否更新正确
ReceivablePlanDO receivablePlan = receivablePlanMapper.selectById(reqVO.getId()); // 获取最新的
assertPojoEquals(reqVO, receivablePlan);
}
@Test
public void testUpdateReceivablePlan_notExists() {
// 准备参数
ReceivablePlanUpdateReqVO reqVO = randomPojo(ReceivablePlanUpdateReqVO.class);
// 调用, 并断言异常
assertServiceException(() -> receivablePlanService.updateReceivablePlan(reqVO), RECEIVABLE_PLAN_NOT_EXISTS);
}
@Test
public void testDeleteReceivablePlan_success() {
// mock 数据
ReceivablePlanDO dbReceivablePlan = randomPojo(ReceivablePlanDO.class);
receivablePlanMapper.insert(dbReceivablePlan);// @Sql: 先插入出一条存在的数据
// 准备参数
Long id = dbReceivablePlan.getId();
// 调用
receivablePlanService.deleteReceivablePlan(id);
// 校验数据不存在了
assertNull(receivablePlanMapper.selectById(id));
}
@Test
public void testDeleteReceivablePlan_notExists() {
// 准备参数
Long id = randomLongId();
// 调用, 并断言异常
assertServiceException(() -> receivablePlanService.deleteReceivablePlan(id), RECEIVABLE_PLAN_NOT_EXISTS);
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetReceivablePlanPage() {
// mock 数据
ReceivablePlanDO dbReceivablePlan = randomPojo(ReceivablePlanDO.class, o -> { // 等会查询到
o.setIndexNo(null);
o.setStatus(null);
o.setCheckStatus(null);
o.setReturnTime(null);
o.setRemindDays(null);
o.setRemindTime(null);
o.setCustomerId(null);
o.setContractId(null);
o.setOwnerUserId(null);
o.setRemark(null);
o.setCreateTime(null);
});
receivablePlanMapper.insert(dbReceivablePlan);
// 测试 indexNo 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setIndexNo(null)));
// 测试 status 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setStatus(null)));
// 测试 checkStatus 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCheckStatus(null)));
// 测试 returnTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setReturnTime(null)));
// 测试 remindDays 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemindDays(null)));
// 测试 remindTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemindTime(null)));
// 测试 customerId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCustomerId(null)));
// 测试 contractId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setContractId(null)));
// 测试 ownerUserId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setOwnerUserId(null)));
// 测试 remark 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemark(null)));
// 测试 createTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCreateTime(null)));
// 准备参数
ReceivablePlanPageReqVO reqVO = new ReceivablePlanPageReqVO();
reqVO.setIndexNo(null);
reqVO.setStatus(null);
reqVO.setCheckStatus(null);
reqVO.setReturnTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setRemindDays(null);
reqVO.setRemindTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setCustomerId(null);
reqVO.setContractId(null);
reqVO.setOwnerUserId(null);
reqVO.setRemark(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<ReceivablePlanDO> pageResult = receivablePlanService.getReceivablePlanPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());
assertPojoEquals(dbReceivablePlan, pageResult.getList().get(0));
}
@Test
@Disabled // TODO 请修改 null 为需要的值然后删除 @Disabled 注解
public void testGetReceivablePlanList() {
// mock 数据
ReceivablePlanDO dbReceivablePlan = randomPojo(ReceivablePlanDO.class, o -> { // 等会查询到
o.setIndexNo(null);
o.setStatus(null);
o.setCheckStatus(null);
o.setReturnTime(null);
o.setRemindDays(null);
o.setRemindTime(null);
o.setCustomerId(null);
o.setContractId(null);
o.setOwnerUserId(null);
o.setRemark(null);
o.setCreateTime(null);
});
receivablePlanMapper.insert(dbReceivablePlan);
// 测试 indexNo 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setIndexNo(null)));
// 测试 status 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setStatus(null)));
// 测试 checkStatus 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCheckStatus(null)));
// 测试 returnTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setReturnTime(null)));
// 测试 remindDays 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemindDays(null)));
// 测试 remindTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemindTime(null)));
// 测试 customerId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCustomerId(null)));
// 测试 contractId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setContractId(null)));
// 测试 ownerUserId 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setOwnerUserId(null)));
// 测试 remark 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setRemark(null)));
// 测试 createTime 不匹配
receivablePlanMapper.insert(cloneIgnoreId(dbReceivablePlan, o -> o.setCreateTime(null)));
// 准备参数
ReceivablePlanExportReqVO reqVO = new ReceivablePlanExportReqVO();
reqVO.setIndexNo(null);
reqVO.setStatus(null);
reqVO.setCheckStatus(null);
reqVO.setReturnTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setRemindDays(null);
reqVO.setRemindTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
reqVO.setCustomerId(null);
reqVO.setContractId(null);
reqVO.setOwnerUserId(null);
reqVO.setRemark(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
List<ReceivablePlanDO> list = receivablePlanService.getReceivablePlanList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbReceivablePlan, list.get(0));
}
}

View File

@ -3,3 +3,5 @@ DELETE FROM "crm_contract";
DELETE FROM "crm_clue"; DELETE FROM "crm_clue";
DELETE FROM "crm_receivable"; DELETE FROM "crm_receivable";
DELETE FROM "crm_receivable_plan";

View File

@ -73,3 +73,28 @@ CREATE TABLE IF NOT EXISTS "crm_receivable" (
"deleted" bit NOT NULL DEFAULT FALSE, "deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id") PRIMARY KEY ("id")
) COMMENT '回款管理'; ) COMMENT '回款管理';
CREATE TABLE IF NOT EXISTS "crm_receivable_plan" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"index_no" bigint,
"receivable_id" bigint,
"status" int NOT NULL,
"check_status" varchar,
"process_instance_id" bigint,
"price" varchar,
"return_time" varchar,
"remind_days" bigint,
"remind_time" varchar,
"customer_id" bigint,
"contract_id" bigint,
"owner_user_id" bigint,
"sort" int,
"remark" varchar,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
PRIMARY KEY ("id")
) COMMENT '回款计划';