Commit 9819e05d4ef4936efa382fccbddf3bacc4e305e0
Merge branch 'develop' of https://gitee.com/aberizofur/ruoyi-vue-pro into develop
Showing
21 changed files
with
454 additions
and
19 deletions
sql/mysql/optinal/crm_20240114.sql
0 → 100644
| 1 | + | ||
| 2 | +-- ---------------------------- | ||
| 3 | +-- Table structure for crm_business_product | ||
| 4 | +-- ---------------------------- | ||
| 5 | +DROP TABLE IF EXISTS `crm_business_product`; | ||
| 6 | +CREATE TABLE `crm_business_product` ( | ||
| 7 | + `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 8 | + `business_id` bigint(0) NOT NULL COMMENT '商机ID', | ||
| 9 | + `product_id` bigint(0) NOT NULL COMMENT '产品ID', | ||
| 10 | + `price` decimal(18, 2) NOT NULL COMMENT '产品单价', | ||
| 11 | + `sales_price` decimal(18, 2) NULL DEFAULT NULL COMMENT '销售价格', | ||
| 12 | + `num` int(0) NULL DEFAULT NULL COMMENT '数量', | ||
| 13 | + `discount` decimal(10, 2) NULL DEFAULT NULL COMMENT '折扣', | ||
| 14 | + `subtotal` decimal(18, 2) NULL DEFAULT NULL COMMENT '小计(折扣后价格)', | ||
| 15 | + `unit` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '单位', | ||
| 16 | + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | ||
| 17 | + `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 18 | + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', | ||
| 19 | + `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间', | ||
| 20 | + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 21 | + `tenant_id` bigint(0) NOT NULL DEFAULT 1 COMMENT '租户编号', | ||
| 22 | + PRIMARY KEY (`id`) USING BTREE | ||
| 23 | +) ENGINE = InnoDB AUTO_INCREMENT = 29 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商机产品关联表' ROW_FORMAT = Dynamic; | ||
| 24 | + | ||
| 25 | +-- ---------------------------- | ||
| 26 | +-- Table structure for crm_business_status | ||
| 27 | +-- ---------------------------- | ||
| 28 | +DROP TABLE IF EXISTS `crm_business_status`; | ||
| 29 | +CREATE TABLE `crm_business_status` ( | ||
| 30 | + `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 31 | + `type_id` bigint(0) NOT NULL COMMENT '状态类型编号', | ||
| 32 | + `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '状态名', | ||
| 33 | + `percent` bigint(0) NULL DEFAULT NULL COMMENT '赢单率', | ||
| 34 | + `sort` int(0) NULL DEFAULT NULL COMMENT '排序', | ||
| 35 | + `tenant_id` bigint(0) NOT NULL DEFAULT 0 COMMENT '租户编号', | ||
| 36 | + PRIMARY KEY (`id`) USING BTREE | ||
| 37 | +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商机状态' ROW_FORMAT = Dynamic; | ||
| 38 | + | ||
| 39 | +-- ---------------------------- | ||
| 40 | +-- Table structure for crm_business_status_type | ||
| 41 | +-- ---------------------------- | ||
| 42 | +DROP TABLE IF EXISTS `crm_business_status_type`; | ||
| 43 | +CREATE TABLE `crm_business_status_type` ( | ||
| 44 | + `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 45 | + `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '状态类型名', | ||
| 46 | + `dept_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '使用的部门编号', | ||
| 47 | + `status` int(0) NOT NULL DEFAULT 1 COMMENT '开启状态', | ||
| 48 | + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | ||
| 49 | + `create_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 50 | + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', | ||
| 51 | + `update_time` datetime(0) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间', | ||
| 52 | + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 53 | + `tenant_id` bigint(0) NOT NULL DEFAULT 0 COMMENT '租户编号', | ||
| 54 | + PRIMARY KEY (`id`) USING BTREE | ||
| 55 | +) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商机状态类型' ROW_FORMAT = Dynamic; |
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| @@ -19,6 +19,7 @@ public interface ErrorCodeConstants { | @@ -19,6 +19,7 @@ public interface ErrorCodeConstants { | ||
| 19 | 19 | ||
| 20 | // ========== 商机管理 1-020-002-000 ========== | 20 | // ========== 商机管理 1-020-002-000 ========== |
| 21 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); | 21 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); |
| 22 | + ErrorCode BUSINESS_CONTRACT_EXISTS = new ErrorCode(1_020_002_001, "商机已关联合同,不能删除"); | ||
| 22 | 23 | ||
| 23 | // TODO @lilleo:商机状态、商机类型,都单独错误码段 | 24 | // TODO @lilleo:商机状态、商机类型,都单独错误码段 |
| 24 | 25 |
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/business/CrmBizEndStatus.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.enums.business; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.util.ObjUtil; | ||
| 4 | +import cn.hutool.core.util.ObjectUtil; | ||
| 5 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | ||
| 6 | +import lombok.Getter; | ||
| 7 | +import lombok.RequiredArgsConstructor; | ||
| 8 | + | ||
| 9 | +import java.util.Arrays; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * @author lzxhqs | ||
| 13 | + * @version 1.0 | ||
| 14 | + * @title CrmBizEndStatus | ||
| 15 | + * @description | ||
| 16 | + * @create 2024/1/12 | ||
| 17 | + */ | ||
| 18 | +@RequiredArgsConstructor | ||
| 19 | +@Getter | ||
| 20 | +public enum CrmBizEndStatus implements IntArrayValuable { | ||
| 21 | + WIN(1, "赢单"), | ||
| 22 | + LOSE(2, "输单"), | ||
| 23 | + INVALID(3, "无效"); | ||
| 24 | + | ||
| 25 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmBizEndStatus::getStatus).toArray(); | ||
| 26 | + | ||
| 27 | + public static boolean isWin(Integer status) { | ||
| 28 | + return ObjectUtil.equal(WIN.getStatus(), status); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public static boolean isLose(Integer status) { | ||
| 32 | + return ObjectUtil.equal(LOSE.getStatus(), status); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public static boolean isInvalid(Integer status) { | ||
| 36 | + return ObjectUtil.equal(INVALID.getStatus(), status); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 场景类型 | ||
| 41 | + */ | ||
| 42 | + private final Integer status; | ||
| 43 | + /** | ||
| 44 | + * 场景名称 | ||
| 45 | + */ | ||
| 46 | + private final String name; | ||
| 47 | + | ||
| 48 | + @Override | ||
| 49 | + public int[] array() { | ||
| 50 | + return ARRAYS; | ||
| 51 | + } | ||
| 52 | +} |
yudao-module-crm/yudao-module-crm-biz/pom.xml
| @@ -24,6 +24,11 @@ | @@ -24,6 +24,11 @@ | ||
| 24 | </dependency> | 24 | </dependency> |
| 25 | <dependency> | 25 | <dependency> |
| 26 | <groupId>cn.iocoder.boot</groupId> | 26 | <groupId>cn.iocoder.boot</groupId> |
| 27 | + <artifactId>yudao-module-system-biz</artifactId> | ||
| 28 | + <version>${revision}</version> | ||
| 29 | + </dependency> | ||
| 30 | + <dependency> | ||
| 31 | + <groupId>cn.iocoder.boot</groupId> | ||
| 27 | <artifactId>yudao-module-crm-api</artifactId> | 32 | <artifactId>yudao-module-crm-api</artifactId> |
| 28 | <version>${revision}</version> | 33 | <version>${revision}</version> |
| 29 | </dependency> | 34 | </dependency> |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessStatusTypeController.java
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | 9 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 9 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | 10 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| @@ -101,11 +102,12 @@ public class CrmBusinessStatusTypeController { | @@ -101,11 +102,12 @@ public class CrmBusinessStatusTypeController { | ||
| 101 | PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(pageReqVO); | 102 | PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(pageReqVO); |
| 102 | // 处理部门回显 | 103 | // 处理部门回显 |
| 103 | // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; | 104 | // TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈; |
| 104 | - Set<Long> deptIds = pageResult.getList().stream() | ||
| 105 | - .map(CrmBusinessStatusTypeDO::getDeptIds) | ||
| 106 | - .filter(Objects::nonNull) | ||
| 107 | - .flatMap(Collection::stream) | ||
| 108 | - .collect(Collectors.toSet()); | 105 | +// Set<Long> deptIds = pageResult.getList().stream() |
| 106 | +// .map(CrmBusinessStatusTypeDO::getDeptIds) | ||
| 107 | +// .filter(Objects::nonNull) | ||
| 108 | +// .flatMap(Collection::stream) | ||
| 109 | +// .collect(Collectors.toSet()); | ||
| 110 | + Set<Long> deptIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmBusinessStatusTypeDO::getDeptIds,Collection::stream); | ||
| 109 | List<DeptRespDTO> deptList = deptApi.getDeptList(deptIds); | 111 | List<DeptRespDTO> deptList = deptApi.getDeptList(deptIds); |
| 110 | return success(CrmBusinessStatusTypeConvert.INSTANCE.convertPage(pageResult, deptList)); | 112 | return success(CrmBusinessStatusTypeConvert.INSTANCE.convertPage(pageResult, deptList)); |
| 111 | } | 113 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/business/CrmBusinessSaveReqVO.java
| 1 | package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business; | 1 | package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.crm.enums.business.CrmBizEndStatus; | ||
| 3 | import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmCustomerParseFunction; | 6 | import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmCustomerParseFunction; |
| 4 | import com.mzt.logapi.starter.annotation.DiffLogField; | 7 | import com.mzt.logapi.starter.annotation.DiffLogField; |
| 5 | import io.swagger.v3.oas.annotations.media.Schema; | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| @@ -9,6 +12,8 @@ import org.springframework.format.annotation.DateTimeFormat; | @@ -9,6 +12,8 @@ import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | 12 | ||
| 10 | import java.math.BigDecimal; | 13 | import java.math.BigDecimal; |
| 11 | import java.time.LocalDateTime; | 14 | import java.time.LocalDateTime; |
| 15 | +import java.util.ArrayList; | ||
| 16 | +import java.util.List; | ||
| 12 | 17 | ||
| 13 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | 18 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 14 | 19 | ||
| @@ -66,7 +71,17 @@ public class CrmBusinessSaveReqVO { | @@ -66,7 +71,17 @@ public class CrmBusinessSaveReqVO { | ||
| 66 | @Schema(description = "备注", example = "随便") | 71 | @Schema(description = "备注", example = "随便") |
| 67 | @DiffLogField(name = "备注") | 72 | @DiffLogField(name = "备注") |
| 68 | private String remark; | 73 | private String remark; |
| 69 | - | ||
| 70 | // TODO @ljileo:修改的时候,应该可以传递添加的产品; | 74 | // TODO @ljileo:修改的时候,应该可以传递添加的产品; |
| 75 | + @Schema(description = "联系人编号", example = "110") | ||
| 76 | + @NotNull(message = "联系人编号不能为空") | ||
| 77 | + private Long contactId; | ||
| 78 | + | ||
| 79 | + @Schema(description = "1赢单2输单3无效", example = "1") | ||
| 80 | + @InEnum(CrmBizEndStatus.class) | ||
| 81 | + private Integer endStatus; | ||
| 82 | + | ||
| 83 | + @Schema(description = "商机产品列表", example = "") | ||
| 84 | + private List<CrmBusinessProductSaveReqVO> products = new ArrayList<>(); | ||
| 85 | + | ||
| 71 | 86 | ||
| 72 | } | 87 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/product/CrmBusinessProductPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.EqualsAndHashCode; | ||
| 7 | +import lombok.ToString; | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * @author lzxhqs | ||
| 12 | + */ | ||
| 13 | +@Schema(description = "管理后台 - 商机产品分页 Request VO") | ||
| 14 | +@Data | ||
| 15 | +@EqualsAndHashCode(callSuper = true) | ||
| 16 | +@ToString(callSuper = true) | ||
| 17 | +public class CrmBusinessProductPageReqVO extends PageParam { | ||
| 18 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/product/CrmBusinessProductRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product; | ||
| 2 | + | ||
| 3 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @author lzxhqs | ||
| 9 | + */ | ||
| 10 | +@Schema(description = "管理后台 - 商机产品关联 Response VO") | ||
| 11 | +@Data | ||
| 12 | +@ExcelIgnoreUnannotated | ||
| 13 | +public class CrmBusinessProductRespVO { | ||
| 14 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/product/CrmBusinessProductSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotNull; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.math.BigDecimal; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author lzxhqs | ||
| 11 | + */ | ||
| 12 | +@Schema(description = "管理后台 - CRM 商机产品关联表 创建/更新 Request VO") | ||
| 13 | +@Data | ||
| 14 | +public class CrmBusinessProductSaveReqVO { | ||
| 15 | + | ||
| 16 | + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "32129") | ||
| 17 | + private Long id; | ||
| 18 | + | ||
| 19 | + @Schema(description = "商机ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 20 | + @NotNull(message = "商机ID不能为空") | ||
| 21 | + private Integer businessId; | ||
| 22 | + | ||
| 23 | + @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 24 | + @NotNull(message = "产品ID不能为空") | ||
| 25 | + private Integer productId; | ||
| 26 | + | ||
| 27 | + @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 28 | + @NotNull(message = "产品单价不能为空") | ||
| 29 | + private BigDecimal price; | ||
| 30 | + | ||
| 31 | + @Schema(description = "销售价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 32 | + @NotNull(message = "销售价格不能为空") | ||
| 33 | + private BigDecimal salesPrice; | ||
| 34 | + | ||
| 35 | + @Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 36 | + @NotNull(message = "数量不能为空") | ||
| 37 | + private BigDecimal num; | ||
| 38 | + | ||
| 39 | + @Schema(description = "折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 40 | + @NotNull(message = "折扣不能为空") | ||
| 41 | + private BigDecimal discount; | ||
| 42 | + | ||
| 43 | + @Schema(description = "小计(折扣后价格)", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 44 | + @NotNull(message = "小计(折扣后价格)不能为空") | ||
| 45 | + private BigDecimal subtotal; | ||
| 46 | + | ||
| 47 | + @Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320") | ||
| 48 | + @NotNull(message = "单位不能为空") | ||
| 49 | + private String unit; | ||
| 50 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/vo/type/CrmBusinessStatusTypeSaveReqVO.java
| @@ -24,6 +24,6 @@ public class CrmBusinessStatusTypeSaveReqVO { | @@ -24,6 +24,6 @@ public class CrmBusinessStatusTypeSaveReqVO { | ||
| 24 | 24 | ||
| 25 | // TODO @ljlleo VO 里面,我们不使用默认值哈。这里 Lists.newArrayList() 看看怎么去掉。上面 deptIds 也是类似噢 | 25 | // TODO @ljlleo VO 里面,我们不使用默认值哈。这里 Lists.newArrayList() 看看怎么去掉。上面 deptIds 也是类似噢 |
| 26 | @Schema(description = "商机状态集合", requiredMode = Schema.RequiredMode.REQUIRED) | 26 | @Schema(description = "商机状态集合", requiredMode = Schema.RequiredMode.REQUIRED) |
| 27 | - private List<CrmBusinessStatusSaveReqVO> statusList = Lists.newArrayList(); | 27 | + private List<CrmBusinessStatusSaveReqVO> statusList; |
| 28 | 28 | ||
| 29 | } | 29 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/businessproduct/CrmBusinessProductConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.convert.businessproduct; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO; | ||
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO; | ||
| 5 | +import org.mapstruct.Mapper; | ||
| 6 | +import org.mapstruct.factory.Mappers; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author lzxhqs | ||
| 10 | + * @version 1.0 | ||
| 11 | + * @title CrmBusinessProductConvert | ||
| 12 | + * @description | ||
| 13 | + * @create 2024/1/12 | ||
| 14 | + */ | ||
| 15 | +@Mapper | ||
| 16 | +public interface CrmBusinessProductConvert { | ||
| 17 | + CrmBusinessProductConvert INSTANCE = Mappers.getMapper(CrmBusinessProductConvert.class); | ||
| 18 | + | ||
| 19 | + CrmBusinessProductDO convert(CrmBusinessProductSaveReqVO product); | ||
| 20 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/businessstatustype/CrmBusinessStatusTypeConvert.java
| @@ -39,9 +39,9 @@ public interface CrmBusinessStatusTypeConvert { | @@ -39,9 +39,9 @@ public interface CrmBusinessStatusTypeConvert { | ||
| 39 | 39 | ||
| 40 | default CrmBusinessStatusTypeRespVO convert(CrmBusinessStatusTypeDO bean, List<CrmBusinessStatusDO> statusList) { | 40 | default CrmBusinessStatusTypeRespVO convert(CrmBusinessStatusTypeDO bean, List<CrmBusinessStatusDO> statusList) { |
| 41 | // TODO @ljlleo 可以链式赋值,简化成一行; | 41 | // TODO @ljlleo 可以链式赋值,简化成一行; |
| 42 | - CrmBusinessStatusTypeRespVO result = convert(bean); | ||
| 43 | - result.setStatusList(statusList); | ||
| 44 | - return result; | 42 | +// CrmBusinessStatusTypeRespVO result = convert(bean); |
| 43 | +// result.setStatusList(statusList); | ||
| 44 | + return convert(bean).setStatusList(statusList); | ||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | } | 47 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | ||
| 5 | +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | ||
| 4 | import com.baomidou.mybatisplus.annotation.KeySequence; | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 8 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -52,6 +54,7 @@ public class CrmBusinessDO extends BaseDO { | @@ -52,6 +54,7 @@ public class CrmBusinessDO extends BaseDO { | ||
| 52 | * 客户编号 | 54 | * 客户编号 |
| 53 | * | 55 | * |
| 54 | * TODO @ljileo:这个字段,后续要写下关联的实体哈 | 56 | * TODO @ljileo:这个字段,后续要写下关联的实体哈 |
| 57 | + * 关联 {@link CrmCustomerDO#getId()} | ||
| 55 | */ | 58 | */ |
| 56 | private Long customerId; | 59 | private Long customerId; |
| 57 | /** | 60 | /** |
| @@ -101,6 +104,7 @@ public class CrmBusinessDO extends BaseDO { | @@ -101,6 +104,7 @@ public class CrmBusinessDO extends BaseDO { | ||
| 101 | * 负责人的用户编号 | 104 | * 负责人的用户编号 |
| 102 | * | 105 | * |
| 103 | * 关联 AdminUserDO 的 id 字段 | 106 | * 关联 AdminUserDO 的 id 字段 |
| 107 | + * {@link AdminUserDO#getId()} | ||
| 104 | */ | 108 | */ |
| 105 | private Long ownerUserId; | 109 | private Long ownerUserId; |
| 106 | 110 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessProductDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.dataobject.business; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | +import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; | ||
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | +import lombok.*; | ||
| 9 | + | ||
| 10 | +import java.math.BigDecimal; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 商机产品关联表 DO | ||
| 14 | + * | ||
| 15 | + * @author lzxhqs | ||
| 16 | + */ | ||
| 17 | +@TableName("crm_business_product") | ||
| 18 | +@KeySequence("crm_business_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 19 | +@Data | ||
| 20 | +@EqualsAndHashCode(callSuper = true) | ||
| 21 | +@ToString(callSuper = true) | ||
| 22 | +@Builder | ||
| 23 | +@NoArgsConstructor | ||
| 24 | +@AllArgsConstructor | ||
| 25 | +public class CrmBusinessProductDO extends BaseDO { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 主键 | ||
| 29 | + */ | ||
| 30 | + @TableId | ||
| 31 | + private Long id; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 商机ID | ||
| 35 | + * 关联 {@link CrmBusinessDO#getId()} | ||
| 36 | + */ | ||
| 37 | + private Long businessId; | ||
| 38 | + | ||
| 39 | + /** | ||
| 40 | + * 产品ID | ||
| 41 | + * 关联{@link CrmProductDO#getId()} | ||
| 42 | + */ | ||
| 43 | + private Long productId; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 产品单价 | ||
| 47 | + */ | ||
| 48 | + private BigDecimal price; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 销售价格 | ||
| 52 | + */ | ||
| 53 | + private BigDecimal salesPrice; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * 数量 | ||
| 57 | + */ | ||
| 58 | + private BigDecimal num; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * 折扣 | ||
| 62 | + */ | ||
| 63 | + private BigDecimal discount; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 小计(折扣后价格) | ||
| 67 | + */ | ||
| 68 | + private BigDecimal subtotal; | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * 单位 | ||
| 72 | + */ | ||
| 73 | + private String unit; | ||
| 74 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessStatusDO.java
| @@ -39,7 +39,7 @@ public class CrmBusinessStatusDO { | @@ -39,7 +39,7 @@ public class CrmBusinessStatusDO { | ||
| 39 | * | 39 | * |
| 40 | * TODO 这里是不是改成 Integer 存储,百分比 * 100 ; | 40 | * TODO 这里是不是改成 Integer 存储,百分比 * 100 ; |
| 41 | */ | 41 | */ |
| 42 | - private String percent; | 42 | + private Integer percent; |
| 43 | /** | 43 | /** |
| 44 | * 排序 | 44 | * 排序 |
| 45 | */ | 45 | */ |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/business/CrmBusinessStatusTypeDO.java
| 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; | 1 | package cn.iocoder.yudao.module.crm.dal.dataobject.business; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; | 5 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; |
| 5 | import com.baomidou.mybatisplus.annotation.KeySequence; | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| @@ -43,6 +44,7 @@ public class CrmBusinessStatusTypeDO extends BaseDO { | @@ -43,6 +44,7 @@ public class CrmBusinessStatusTypeDO extends BaseDO { | ||
| 43 | * 开启状态 | 44 | * 开启状态 |
| 44 | * | 45 | * |
| 45 | * TODO 改成 Integer,关联 CommonStatus | 46 | * TODO 改成 Integer,关联 CommonStatus |
| 47 | + * {@link CommonStatusEnum} | ||
| 46 | */ | 48 | */ |
| 47 | private Boolean status; | 49 | private Boolean status; |
| 48 | 50 |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessProductMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.dal.mysql.business; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO; | ||
| 6 | +import org.apache.ibatis.annotations.Mapper; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 商机产品 Mapper | ||
| 10 | + * @author lzxhqs | ||
| 11 | + */ | ||
| 12 | +@Mapper | ||
| 13 | +public interface CrmBusinessProductMapper extends BaseMapperX<CrmBusinessProductDO> { | ||
| 14 | + default void deleteByBusinessId(Long id) { | ||
| 15 | + delete(CrmBusinessProductDO::getBusinessId, id); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + default CrmBusinessProductDO selectByBusinessId(Long id) { | ||
| 19 | + return selectOne(CrmBusinessProductDO::getBusinessId, id); | ||
| 20 | + } | ||
| 21 | +} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/business/CrmBusinessStatusTypeMapper.java
| @@ -28,4 +28,15 @@ public interface CrmBusinessStatusTypeMapper extends BaseMapperX<CrmBusinessStat | @@ -28,4 +28,15 @@ public interface CrmBusinessStatusTypeMapper extends BaseMapperX<CrmBusinessStat | ||
| 28 | .eqIfPresent(CrmBusinessStatusTypeDO::getStatus, queryVO.getStatus()) | 28 | .eqIfPresent(CrmBusinessStatusTypeDO::getStatus, queryVO.getStatus()) |
| 29 | .inIfPresent(CrmBusinessStatusTypeDO::getId, queryVO.getIdList())); | 29 | .inIfPresent(CrmBusinessStatusTypeDO::getId, queryVO.getIdList())); |
| 30 | } | 30 | } |
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 根据ID和name查询 | ||
| 34 | + * | ||
| 35 | + * @param id 商机状态类型id | ||
| 36 | + * @param name 状态类型名 | ||
| 37 | + * @return result | ||
| 38 | + */ | ||
| 39 | + default CrmBusinessStatusTypeDO selectByIdAndName(Long id, String name) { | ||
| 40 | + return selectOne(CrmBusinessStatusTypeDO::getId, id, CrmBusinessStatusTypeDO::getName, name); | ||
| 41 | + } | ||
| 31 | } | 42 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java
| @@ -63,5 +63,8 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> { | @@ -63,5 +63,8 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> { | ||
| 63 | default Long selectCountByContactId(Long contactId) { | 63 | default Long selectCountByContactId(Long contactId) { |
| 64 | return selectCount(CrmContractDO::getContactId, contactId); | 64 | return selectCount(CrmContractDO::getContactId, contactId); |
| 65 | } | 65 | } |
| 66 | + default CrmContractDO selectByBizId(Long businessId) { | ||
| 67 | + return selectOne(CrmContractDO::getBusinessId, businessId); | ||
| 68 | + } | ||
| 66 | 69 | ||
| 67 | } | 70 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
| @@ -7,10 +7,18 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | @@ -7,10 +7,18 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 7 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO; |
| 8 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO; | 8 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO; |
| 9 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO; | 9 | import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO; |
| 10 | +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO; | ||
| 11 | +import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO; | ||
| 10 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; | 12 | import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; |
| 13 | +import cn.iocoder.yudao.module.crm.convert.businessproduct.CrmBusinessProductConvert; | ||
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; | 14 | import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; |
| 15 | +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO; | ||
| 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; | 16 | import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO; |
| 17 | +import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; | ||
| 13 | import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper; | 18 | import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper; |
| 19 | +import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessProductMapper; | ||
| 20 | +import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessMapper; | ||
| 21 | +import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper; | ||
| 14 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | 22 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| 15 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; | 23 | import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum; |
| 16 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; | 24 | import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission; |
| @@ -25,11 +33,14 @@ import org.springframework.stereotype.Service; | @@ -25,11 +33,14 @@ import org.springframework.stereotype.Service; | ||
| 25 | import org.springframework.transaction.annotation.Transactional; | 33 | import org.springframework.transaction.annotation.Transactional; |
| 26 | import org.springframework.validation.annotation.Validated; | 34 | import org.springframework.validation.annotation.Validated; |
| 27 | 35 | ||
| 36 | +import java.math.BigDecimal; | ||
| 37 | +import java.util.ArrayList; | ||
| 28 | import java.util.Collection; | 38 | import java.util.Collection; |
| 29 | import java.util.List; | 39 | import java.util.List; |
| 30 | 40 | ||
| 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 41 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 32 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | 42 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 43 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_CONTRACT_EXISTS; | ||
| 33 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS; | 44 | import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS; |
| 34 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; | 45 | import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; |
| 35 | 46 | ||
| @@ -46,6 +57,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -46,6 +57,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 46 | private CrmBusinessMapper businessMapper; | 57 | private CrmBusinessMapper businessMapper; |
| 47 | 58 | ||
| 48 | @Resource | 59 | @Resource |
| 60 | + private CrmBusinessProductMapper businessProductMapper; | ||
| 61 | + @Resource | ||
| 62 | + private CrmContractMapper contractMapper; | ||
| 63 | + | ||
| 64 | + @Resource | ||
| 65 | + private CrmContactBusinessMapper contactBusinessMapper; | ||
| 66 | + @Resource | ||
| 49 | private CrmPermissionService permissionService; | 67 | private CrmPermissionService permissionService; |
| 50 | @Resource | 68 | @Resource |
| 51 | private CrmContactBusinessService contactBusinessService; | 69 | private CrmContactBusinessService contactBusinessService; |
| @@ -61,17 +79,65 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -61,17 +79,65 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 61 | .setOwnerUserId(userId); | 79 | .setOwnerUserId(userId); |
| 62 | businessMapper.insert(business); | 80 | businessMapper.insert(business); |
| 63 | // TODO 商机待定:插入商机与产品的关联表;校验商品存在 | 81 | // TODO 商机待定:插入商机与产品的关联表;校验商品存在 |
| 64 | - | 82 | + verifyCrmBusinessProduct(business.getId()); |
| 83 | + if (!createReqVO.getProducts().isEmpty()) { | ||
| 84 | + createBusinessProducts(createReqVO.getProducts(), business.getId()); | ||
| 85 | + } | ||
| 65 | // TODO 商机待定:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表 | 86 | // TODO 商机待定:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表 |
| 87 | + createContactBusiness(business.getId(), createReqVO.getContactId()); | ||
| 66 | 88 | ||
| 67 | // 2. 创建数据权限 | 89 | // 2. 创建数据权限 |
| 90 | + // 设置当前操作的人为负责人 | ||
| 68 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) | 91 | permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType()) |
| 69 | - .setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 | 92 | + .setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); |
| 70 | 93 | ||
| 71 | // 4. 记录操作日志上下文 | 94 | // 4. 记录操作日志上下文 |
| 72 | LogRecordContext.putVariable("business", business); | 95 | LogRecordContext.putVariable("business", business); |
| 73 | return business.getId(); | 96 | return business.getId(); |
| 74 | } | 97 | } |
| 98 | + /** | ||
| 99 | + * @param businessId 商机id | ||
| 100 | + * @param contactId 联系人id | ||
| 101 | + * @throws | ||
| 102 | + * @description 联系人与商机的关联 | ||
| 103 | + * @author lzxhqs | ||
| 104 | + */ | ||
| 105 | + private void createContactBusiness(Long businessId, Long contactId) { | ||
| 106 | + CrmContactBusinessDO contactBusiness = new CrmContactBusinessDO(); | ||
| 107 | + contactBusiness.setBusinessId(businessId); | ||
| 108 | + contactBusiness.setContactId(contactId); | ||
| 109 | + contactBusinessMapper.insert(contactBusiness); | ||
| 110 | + | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + /** | ||
| 114 | + * @param products 产品集合 | ||
| 115 | + * @description 插入商机产品关联表 | ||
| 116 | + * @author lzxhqs | ||
| 117 | + */ | ||
| 118 | + private void createBusinessProducts(List<CrmBusinessProductSaveReqVO> products, Long businessId) { | ||
| 119 | + List<CrmBusinessProductDO> list = new ArrayList<>(); | ||
| 120 | + for (CrmBusinessProductSaveReqVO product : products) { | ||
| 121 | + CrmBusinessProductDO businessProductDO = CrmBusinessProductConvert.INSTANCE.convert(product); | ||
| 122 | + businessProductDO.setBusinessId(businessId); | ||
| 123 | + list.add(businessProductDO); | ||
| 124 | + } | ||
| 125 | + businessProductMapper.insertBatch(list); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * @param id businessId | ||
| 130 | + * @description 校验管理的产品存在则删除 | ||
| 131 | + * @author lzxhqs | ||
| 132 | + */ | ||
| 133 | + private void verifyCrmBusinessProduct(Long id) { | ||
| 134 | + CrmBusinessProductDO businessProductDO = businessProductMapper.selectByBusinessId(id); | ||
| 135 | + if (businessProductDO != null) { | ||
| 136 | + //通过商机Id删除 | ||
| 137 | + businessProductMapper.deleteByBusinessId(id); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + } | ||
| 75 | 141 | ||
| 76 | @Override | 142 | @Override |
| 77 | @Transactional(rollbackFor = Exception.class) | 143 | @Transactional(rollbackFor = Exception.class) |
| @@ -86,6 +152,10 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -86,6 +152,10 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 86 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); | 152 | CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class); |
| 87 | businessMapper.updateById(updateObj); | 153 | businessMapper.updateById(updateObj); |
| 88 | // TODO 商机待定:插入商机与产品的关联表;校验商品存在 | 154 | // TODO 商机待定:插入商机与产品的关联表;校验商品存在 |
| 155 | + verifyCrmBusinessProduct(updateReqVO.getId()); | ||
| 156 | + if (!updateReqVO.getProducts().isEmpty()) { | ||
| 157 | + createBusinessProducts(updateReqVO.getProducts(), updateReqVO.getId()); | ||
| 158 | + } | ||
| 89 | 159 | ||
| 90 | // TODO @商机待定:如果状态发生变化,插入商机状态变更记录表 | 160 | // TODO @商机待定:如果状态发生变化,插入商机状态变更记录表 |
| 91 | // 3. 记录操作日志上下文 | 161 | // 3. 记录操作日志上下文 |
| @@ -102,6 +172,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -102,6 +172,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 102 | // 校验存在 | 172 | // 校验存在 |
| 103 | CrmBusinessDO business = validateBusinessExists(id); | 173 | CrmBusinessDO business = validateBusinessExists(id); |
| 104 | // TODO @商机待定:需要校验有没关联合同。CrmContractDO 的 businessId 字段 | 174 | // TODO @商机待定:需要校验有没关联合同。CrmContractDO 的 businessId 字段 |
| 175 | + validateContractExists(id); | ||
| 105 | 176 | ||
| 106 | // 删除 | 177 | // 删除 |
| 107 | businessMapper.deleteById(id); | 178 | businessMapper.deleteById(id); |
| @@ -112,6 +183,19 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | @@ -112,6 +183,19 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { | ||
| 112 | LogRecordContext.putVariable("businessName", business.getName()); | 183 | LogRecordContext.putVariable("businessName", business.getName()); |
| 113 | } | 184 | } |
| 114 | 185 | ||
| 186 | + /** | ||
| 187 | + * @param businessId 商机id | ||
| 188 | + * @throws | ||
| 189 | + * @description 删除校验合同是关联合同 | ||
| 190 | + * @author lzxhqs | ||
| 191 | + */ | ||
| 192 | + private void validateContractExists(Long businessId) { | ||
| 193 | + CrmContractDO contract = contractMapper.selectByBizId(businessId); | ||
| 194 | + if(contract != null) { | ||
| 195 | + throw exception(BUSINESS_CONTRACT_EXISTS); | ||
| 196 | + } | ||
| 197 | + } | ||
| 198 | + | ||
| 115 | private CrmBusinessDO validateBusinessExists(Long id) { | 199 | private CrmBusinessDO validateBusinessExists(Long id) { |
| 116 | CrmBusinessDO crmBusiness = businessMapper.selectById(id); | 200 | CrmBusinessDO crmBusiness = businessMapper.selectById(id); |
| 117 | if (crmBusiness == null) { | 201 | if (crmBusiness == null) { |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessStatusTypeServiceImpl.java
| @@ -95,14 +95,18 @@ public class CrmBusinessStatusTypeServiceImpl implements CrmBusinessStatusTypeSe | @@ -95,14 +95,18 @@ public class CrmBusinessStatusTypeServiceImpl implements CrmBusinessStatusTypeSe | ||
| 95 | 95 | ||
| 96 | // TODO @ljlleo 这个方法,这个参考 validateDeptNameUnique 实现。 | 96 | // TODO @ljlleo 这个方法,这个参考 validateDeptNameUnique 实现。 |
| 97 | private void validateBusinessStatusTypeExists(String name, Long id) { | 97 | private void validateBusinessStatusTypeExists(String name, Long id) { |
| 98 | - LambdaQueryWrapper<CrmBusinessStatusTypeDO> wrapper = new LambdaQueryWrapperX<>(); | ||
| 99 | - if(null != id) { | ||
| 100 | - wrapper.ne(CrmBusinessStatusTypeDO::getId, id); | ||
| 101 | - } | ||
| 102 | - long cnt = businessStatusTypeMapper.selectCount(wrapper.eq(CrmBusinessStatusTypeDO::getName, name)); | ||
| 103 | - if (cnt > 0) { | 98 | + CrmBusinessStatusTypeDO businessStatusTypeDO = businessStatusTypeMapper.selectByIdAndName(id, name); |
| 99 | + if (businessStatusTypeDO != null) { | ||
| 104 | throw exception(BUSINESS_STATUS_TYPE_NAME_EXISTS); | 100 | throw exception(BUSINESS_STATUS_TYPE_NAME_EXISTS); |
| 105 | } | 101 | } |
| 102 | +// LambdaQueryWrapper<CrmBusinessStatusTypeDO> wrapper = new LambdaQueryWrapperX<>(); | ||
| 103 | +// if(null != id) { | ||
| 104 | +// wrapper.ne(CrmBusinessStatusTypeDO::getId, id); | ||
| 105 | +// } | ||
| 106 | +// long cnt = businessStatusTypeMapper.selectCount(wrapper.eq(CrmBusinessStatusTypeDO::getName, name)); | ||
| 107 | +// if (cnt > 0) { | ||
| 108 | +// throw exception(BUSINESS_STATUS_TYPE_NAME_EXISTS); | ||
| 109 | +// } | ||
| 106 | } | 110 | } |
| 107 | 111 | ||
| 108 | @Override | 112 | @Override |