mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-09-16 10:01:53 +08:00
Merge remote-tracking branch 'upstream/develop' into crm-msg
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
@@ -24,19 +25,17 @@ import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
@@ -85,13 +84,13 @@ public class CrmBusinessStatusTypeController {
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:business-status-type:query')")
|
||||
public CommonResult<CrmBusinessStatusTypeRespVO> getBusinessStatusType(@RequestParam("id") Long id) {
|
||||
CrmBusinessStatusTypeDO businessStatusType = businessStatusTypeService.getBusinessStatusType(id);
|
||||
CrmBusinessStatusTypeDO statusType = businessStatusTypeService.getBusinessStatusType(id);
|
||||
// 处理状态回显
|
||||
// TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈;
|
||||
// TODO @lzxhqs:可以在 businessStatusService 加个 getBusinessStatusListByTypeId 方法,直接返回 List<CrmBusinessStatusDO> 哈,常用的,尽量封装个简单易懂的方法,不用追求绝对通用哈;
|
||||
CrmBusinessStatusQueryVO queryVO = new CrmBusinessStatusQueryVO();
|
||||
queryVO.setTypeId(id);
|
||||
List<CrmBusinessStatusDO> statusList = businessStatusService.selectList(queryVO);
|
||||
return success(CrmBusinessStatusTypeConvert.INSTANCE.convert(businessStatusType, statusList));
|
||||
return success(CrmBusinessStatusTypeConvert.INSTANCE.convert(statusType, statusList));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@@ -100,12 +99,7 @@ public class CrmBusinessStatusTypeController {
|
||||
public CommonResult<PageResult<CrmBusinessStatusTypeRespVO>> getBusinessStatusTypePage(@Valid CrmBusinessStatusTypePageReqVO pageReqVO) {
|
||||
PageResult<CrmBusinessStatusTypeDO> pageResult = businessStatusTypeService.getBusinessStatusTypePage(pageReqVO);
|
||||
// 处理部门回显
|
||||
// TODO @ljlleo:可以使用 CollectionUtils.convertSet 替代常用的 stream 操作,更简洁一点;下面几个也是哈;
|
||||
Set<Long> deptIds = pageResult.getList().stream()
|
||||
.map(CrmBusinessStatusTypeDO::getDeptIds)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
Set<Long> deptIds = CollectionUtils.convertSetByFlatMap(pageResult.getList(), CrmBusinessStatusTypeDO::getDeptIds,Collection::stream);
|
||||
List<DeptRespDTO> deptList = deptApi.getDeptList(deptIds);
|
||||
return success(CrmBusinessStatusTypeConvert.INSTANCE.convertPage(pageResult, deptList));
|
||||
}
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.business.vo.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.enums.business.CrmBizEndStatus;
|
||||
import cn.iocoder.yudao.module.crm.framework.operatelog.core.CrmCustomerParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.DiffLogField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -9,10 +12,11 @@ import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO @ljileo:DiffLogField function 完善一下
|
||||
@Schema(description = "管理后台 - CRM 商机创建/更新 Request VO")
|
||||
@Data
|
||||
public class CrmBusinessSaveReqVO {
|
||||
@@ -54,7 +58,7 @@ public class CrmBusinessSaveReqVO {
|
||||
@DiffLogField(name = "商机金额")
|
||||
private Integer price;
|
||||
|
||||
// TODO @ljileo:折扣使用 Integer 类型,存储时,默认 * 100;展示的时候,前端需要 / 100;避免精度丢失问题
|
||||
// TODO @lzxhqs:折扣使用 Integer 类型,存储时,默认 * 100;展示的时候,前端需要 / 100;避免精度丢失问题
|
||||
@Schema(description = "整单折扣")
|
||||
@DiffLogField(name = "整单折扣")
|
||||
private Integer discountPercent;
|
||||
@@ -67,6 +71,15 @@ public class CrmBusinessSaveReqVO {
|
||||
@DiffLogField(name = "备注")
|
||||
private String remark;
|
||||
|
||||
// TODO @ljileo:修改的时候,应该可以传递添加的产品;
|
||||
@Schema(description = "结束状态", example = "1")
|
||||
@InEnum(CrmBizEndStatus.class)
|
||||
private Integer endStatus;
|
||||
|
||||
// TODO @lzxhqs:不设置默认 new ArrayList<>();一般 pojo 不设置默认值哈
|
||||
@Schema(description = "商机产品列表")
|
||||
private List<CrmBusinessProductSaveReqVO> products = new ArrayList<>();
|
||||
|
||||
@Schema(description = "联系人编号", example = "110")
|
||||
private Long contactId; // 使用场景,在【联系人详情】添加商机时,如果需要关联两者,需要传递 contactId 字段
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
// TODO @lzxhqs:这个类,如果没用到,可以考虑删除哈
|
||||
@Schema(description = "管理后台 - 商机产品分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmBusinessProductPageReqVO extends PageParam {
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 商机产品关联 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CrmBusinessProductRespVO {
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.business.vo.product;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 商机产品关联表 创建/更新 Request VO")
|
||||
@Data
|
||||
public class CrmBusinessProductSaveReqVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "32129")
|
||||
private Long id;
|
||||
|
||||
// TODO @lzxhqs:这个字段,应该是 Long 类型
|
||||
@Schema(description = "商机编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "商机编号不能为空")
|
||||
private Integer businessId;
|
||||
|
||||
// TODO @lzxhqs:这个字段,应该是 Long 类型
|
||||
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "产品编号不能为空")
|
||||
private Integer productId;
|
||||
|
||||
@Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "产品单价不能为空")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "销售价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "销售价格不能为空")
|
||||
private BigDecimal salesPrice;
|
||||
|
||||
@Schema(description = "数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "数量不能为空")
|
||||
private BigDecimal num;
|
||||
|
||||
@Schema(description = "折扣", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "折扣不能为空")
|
||||
private BigDecimal discount;
|
||||
|
||||
@Schema(description = "小计(折扣后价格)", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "小计(折扣后价格)不能为空")
|
||||
private BigDecimal subtotal;
|
||||
|
||||
// TODO @lzxhqs:字符串,用 @NotEmpty,因为要考虑 "" 前端搞了这个玩意
|
||||
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "30320")
|
||||
@NotNull(message = "单位不能为空")
|
||||
private String unit;
|
||||
|
||||
}
|
@@ -21,11 +21,11 @@ public class CrmBusinessStatusSaveReqVO {
|
||||
@NotEmpty(message = "状态名不能为空")
|
||||
private String name;
|
||||
|
||||
// TODO @lilleo:percent 应该是 Integer;
|
||||
// TODO @lzxhqs::percent 应该是 Integer;
|
||||
@Schema(description = "赢单率")
|
||||
private String percent;
|
||||
|
||||
// TODO @lilleo:这个是不是不用前端新增和修改的时候传递,交给顺序计算出来,存储起来就好了;
|
||||
// TODO @lzxhqs:这个是不是不用前端新增和修改的时候传递,交给顺序计算出来,存储起来就好了;
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
|
@@ -19,11 +19,11 @@ public class CrmBusinessStatusTypeSaveReqVO {
|
||||
@NotEmpty(message = "状态类型名不能为空")
|
||||
private String name;
|
||||
|
||||
// TODO @lzxhqs: VO 里面,我们不使用默认值哈。这里 Lists.newArrayList() 看看怎么去掉。上面 deptIds 也是类似噢
|
||||
@Schema(description = "使用的部门编号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<Long> deptIds = Lists.newArrayList();
|
||||
|
||||
// TODO @ljlleo VO 里面,我们不使用默认值哈。这里 Lists.newArrayList() 看看怎么去掉。上面 deptIds 也是类似噢
|
||||
@Schema(description = "商机状态集合", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<CrmBusinessStatusSaveReqVO> statusList = Lists.newArrayList();
|
||||
private List<CrmBusinessStatusSaveReqVO> statusList;
|
||||
|
||||
}
|
||||
|
@@ -125,11 +125,8 @@ public class CrmContactController {
|
||||
@Operation(summary = "获得联系人的精简列表")
|
||||
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
|
||||
public CommonResult<List<CrmContactRespVO>> getSimpleContactList() {
|
||||
// TODO @puhui999:这种还是搞个 getContactList 方法好点哈;
|
||||
CrmContactPageReqVO reqVO = new CrmContactPageReqVO();
|
||||
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
|
||||
PageResult<CrmContactDO> pageResult = contactService.getContactPage(reqVO, getLoginUserId());
|
||||
return success(convertList(pageResult.getList(), contact -> // 只返回 id、name 字段
|
||||
List<CrmContactDO> list = contactService.getSimpleContactList(getLoginUserId());
|
||||
return success(convertList(list, contact -> // 只返回 id、name 字段
|
||||
new CrmContactRespVO().setId(contact.getId()).setName(contact.getName())));
|
||||
}
|
||||
|
||||
|
@@ -1,83 +1,116 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.contract.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
// TODO @puhui999:导出注解哈
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - CRM 合同 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CrmContractRespVO {
|
||||
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
|
||||
@ExcelProperty("合同编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "合同名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五")
|
||||
@ExcelProperty("合同名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18336")
|
||||
@ExcelProperty("客户编号")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "商机编号", example = "10864")
|
||||
@ExcelProperty("商机编号")
|
||||
private Long businessId;
|
||||
|
||||
@Schema(description = "工作流编号", example = "1043")
|
||||
@ExcelProperty("工作流编号")
|
||||
private Long processInstanceId;
|
||||
|
||||
@Schema(description = "下单日期", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("下单日期")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime orderDate;
|
||||
|
||||
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17144")
|
||||
@ExcelProperty("负责人的用户编号")
|
||||
private Long ownerUserId;
|
||||
|
||||
// TODO @芋艿:未来应该支持自动生成;
|
||||
@Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "20230101")
|
||||
@ExcelProperty("合同编号")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
@ExcelProperty("开始时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
@ExcelProperty("结束时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime endTime;
|
||||
|
||||
@Schema(description = "合同金额", example = "5617")
|
||||
@ExcelProperty("合同金额")
|
||||
private Integer price;
|
||||
|
||||
@Schema(description = "整单折扣")
|
||||
@ExcelProperty("整单折扣")
|
||||
private Integer discountPercent;
|
||||
|
||||
@Schema(description = "产品总金额", example = "19510")
|
||||
@ExcelProperty("产品总金额")
|
||||
private Integer productPrice;
|
||||
|
||||
@Schema(description = "联系人编号", example = "18546")
|
||||
@ExcelProperty("联系人编号")
|
||||
private Long contactId;
|
||||
|
||||
@Schema(description = "公司签约人", example = "14036")
|
||||
@ExcelProperty("公司签约人")
|
||||
private Long signUserId;
|
||||
|
||||
@Schema(description = "最后跟进时间")
|
||||
@ExcelProperty("最后跟进时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime contactLastTime;
|
||||
|
||||
@Schema(description = "备注", example = "你猜")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "创建人", example = "25682")
|
||||
@ExcelProperty("创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "创建人名字", example = "test")
|
||||
@ExcelProperty("创建人名字")
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description = "客户名字", example = "test")
|
||||
@ExcelProperty("客户名字")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "负责人", example = "test")
|
||||
@ExcelProperty("负责人")
|
||||
private String ownerUserName;
|
||||
|
||||
@Schema(description = "审批状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
|
||||
@ExcelProperty("审批状态")
|
||||
private Integer auditStatus;
|
||||
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import java.util.Map;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - 跟进记录")
|
||||
@@ -37,7 +38,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
|
||||
public class CrmFollowUpRecordController {
|
||||
|
||||
@Resource
|
||||
private CrmFollowUpRecordService crmFollowUpRecordService;
|
||||
private CrmFollowUpRecordService followUpRecordService;
|
||||
@Resource
|
||||
private CrmContactService contactService;
|
||||
@Resource
|
||||
@@ -47,15 +48,7 @@ public class CrmFollowUpRecordController {
|
||||
@Operation(summary = "创建跟进记录")
|
||||
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:create')")
|
||||
public CommonResult<Long> createFollowUpRecord(@Valid @RequestBody CrmFollowUpRecordSaveReqVO createReqVO) {
|
||||
return success(crmFollowUpRecordService.createFollowUpRecord(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新跟进记录")
|
||||
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:update')")
|
||||
public CommonResult<Boolean> updateFollowUpRecord(@Valid @RequestBody CrmFollowUpRecordSaveReqVO updateReqVO) {
|
||||
crmFollowUpRecordService.updateFollowUpRecord(updateReqVO);
|
||||
return success(true);
|
||||
return success(followUpRecordService.createFollowUpRecord(createReqVO));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@@ -63,7 +56,7 @@ public class CrmFollowUpRecordController {
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:delete')")
|
||||
public CommonResult<Boolean> deleteFollowUpRecord(@RequestParam("id") Long id) {
|
||||
crmFollowUpRecordService.deleteFollowUpRecord(id);
|
||||
followUpRecordService.deleteFollowUpRecord(id, getLoginUserId());
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@@ -72,7 +65,7 @@ public class CrmFollowUpRecordController {
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:query')")
|
||||
public CommonResult<CrmFollowUpRecordRespVO> getFollowUpRecord(@RequestParam("id") Long id) {
|
||||
CrmFollowUpRecordDO followUpRecord = crmFollowUpRecordService.getFollowUpRecord(id);
|
||||
CrmFollowUpRecordDO followUpRecord = followUpRecordService.getFollowUpRecord(id);
|
||||
return success(BeanUtils.toBean(followUpRecord, CrmFollowUpRecordRespVO.class));
|
||||
}
|
||||
|
||||
@@ -80,7 +73,7 @@ public class CrmFollowUpRecordController {
|
||||
@Operation(summary = "获得跟进记录分页")
|
||||
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:query')")
|
||||
public CommonResult<PageResult<CrmFollowUpRecordRespVO>> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) {
|
||||
PageResult<CrmFollowUpRecordDO> pageResult = crmFollowUpRecordService.getFollowUpRecordPage(pageReqVO);
|
||||
PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO);
|
||||
/// 拼接数据
|
||||
Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactList(
|
||||
convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())), CrmContactDO::getId);
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
||||
@@ -8,6 +9,7 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusTypeDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
@@ -45,4 +47,11 @@ public interface CrmBusinessConvert {
|
||||
return voPageResult;
|
||||
}
|
||||
|
||||
@Mapping(target = "id", source = "reqBO.bizId")
|
||||
CrmBusinessDO convert(CrmUpdateFollowUpReqBO reqBO);
|
||||
|
||||
default List<CrmBusinessDO> convertList(List<CrmUpdateFollowUpReqBO> list) {
|
||||
return CollectionUtils.convertList(list, INSTANCE::convert);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.businessproduct;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
// TODO @lzxhqs:看看是不是用 BeanUtils 替代了
|
||||
/**
|
||||
* @author lzxhqs
|
||||
* @version 1.0
|
||||
* @title CrmBusinessProductConvert
|
||||
* @description
|
||||
* @create 2024/1/12
|
||||
*/
|
||||
@Mapper
|
||||
public interface CrmBusinessProductConvert {
|
||||
CrmBusinessProductConvert INSTANCE = Mappers.getMapper(CrmBusinessProductConvert.class);
|
||||
|
||||
CrmBusinessProductDO convert(CrmBusinessProductSaveReqVO product);
|
||||
}
|
@@ -14,6 +14,7 @@ import java.util.Map;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
// TODO @lzxhqs:看看是不是用 BeanUtils 替代了
|
||||
/**
|
||||
* 商机状态类型 Convert
|
||||
*
|
||||
@@ -24,7 +25,6 @@ public interface CrmBusinessStatusTypeConvert {
|
||||
|
||||
CrmBusinessStatusTypeConvert INSTANCE = Mappers.getMapper(CrmBusinessStatusTypeConvert.class);
|
||||
|
||||
|
||||
CrmBusinessStatusTypeRespVO convert(CrmBusinessStatusTypeDO bean);
|
||||
|
||||
PageResult<CrmBusinessStatusTypeRespVO> convertPage(PageResult<CrmBusinessStatusTypeDO> page);
|
||||
@@ -38,10 +38,7 @@ public interface CrmBusinessStatusTypeConvert {
|
||||
}
|
||||
|
||||
default CrmBusinessStatusTypeRespVO convert(CrmBusinessStatusTypeDO bean, List<CrmBusinessStatusDO> statusList) {
|
||||
// TODO @ljlleo 可以链式赋值,简化成一行;
|
||||
CrmBusinessStatusTypeRespVO result = convert(bean);
|
||||
result.setStatusList(statusList);
|
||||
return result;
|
||||
return convert(bean).setStatusList(statusList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
@@ -66,4 +67,11 @@ public interface CrmContactConvert {
|
||||
findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname()));
|
||||
}
|
||||
|
||||
@Mapping(target = "id", source = "reqBO.bizId")
|
||||
CrmContactDO convert(CrmUpdateFollowUpReqBO reqBO);
|
||||
|
||||
default List<CrmContactDO> convertList(List<CrmUpdateFollowUpReqBO> list) {
|
||||
return CollectionUtils.convertList(list, INSTANCE::convert);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.dataobject.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.enums.business.CrmBizEndStatus;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -52,6 +54,7 @@ public class CrmBusinessDO extends BaseDO {
|
||||
* 客户编号
|
||||
*
|
||||
* TODO @ljileo:这个字段,后续要写下关联的实体哈
|
||||
* 关联 {@link CrmCustomerDO#getId()}
|
||||
*/
|
||||
private Long customerId;
|
||||
/**
|
||||
@@ -77,9 +80,9 @@ public class CrmBusinessDO extends BaseDO {
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 1赢单2输单3无效
|
||||
* 结束状态
|
||||
*
|
||||
* TODO @lijie:搞个枚举;
|
||||
* 枚举 {@link CrmBizEndStatus}
|
||||
*/
|
||||
private Integer endStatus;
|
||||
/**
|
||||
@@ -93,7 +96,7 @@ public class CrmBusinessDO extends BaseDO {
|
||||
/**
|
||||
* 跟进状态
|
||||
*
|
||||
* TODO @lijie:目前就是 Boolean;是否跟进
|
||||
* TODO @lzxhqs:目前就是 Boolean;是否跟进
|
||||
*/
|
||||
private Integer followUpStatus;
|
||||
|
||||
|
@@ -0,0 +1,80 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.dataobject.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 商机产品关联表 DO
|
||||
*
|
||||
* @author lzxhqs
|
||||
*/
|
||||
@TableName("crm_business_product")
|
||||
@KeySequence("crm_business_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CrmBusinessProductDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 商机编号
|
||||
*
|
||||
* 关联 {@link CrmBusinessDO#getId()}
|
||||
*/
|
||||
private Long businessId;
|
||||
|
||||
/**
|
||||
* 产品编号
|
||||
*
|
||||
* 关联 {@link CrmProductDO#getId()}
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
// TODO @lzxhqs:改成 Integer,单位:分。目前整体倾向放大 100 倍哈
|
||||
/**
|
||||
* 产品单价
|
||||
*/
|
||||
private BigDecimal price;
|
||||
|
||||
/**
|
||||
* 销售价格
|
||||
*/
|
||||
private BigDecimal salesPrice;
|
||||
|
||||
// TODO @lzxhqs:改成 count
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private BigDecimal num;
|
||||
|
||||
// TODO @lzxhqs:改成 discountPercent
|
||||
/**
|
||||
* 折扣
|
||||
*/
|
||||
private BigDecimal discount;
|
||||
|
||||
// TODO @lzxhqs:改成 totalPrice;总计价格,和现有项目风格一致;
|
||||
/**
|
||||
* 小计(折扣后价格)
|
||||
*/
|
||||
private BigDecimal subtotal;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
}
|
@@ -35,11 +35,9 @@ public class CrmBusinessStatusDO {
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 赢单率
|
||||
*
|
||||
* TODO 这里是不是改成 Integer 存储,百分比 * 100 ;
|
||||
* 赢单率,百分比
|
||||
*/
|
||||
private String percent;
|
||||
private Integer percent;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.dataobject.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
@@ -43,6 +44,7 @@ public class CrmBusinessStatusTypeDO extends BaseDO {
|
||||
* 开启状态
|
||||
*
|
||||
* TODO 改成 Integer,关联 CommonStatus
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Boolean status;
|
||||
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.crm.dal.mysql.business;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 商机产品 Mapper // TODO @lzxhqs:类注释,和作者之间要有一个空行
|
||||
* @author lzxhqs
|
||||
*/
|
||||
@Mapper
|
||||
public interface CrmBusinessProductMapper extends BaseMapperX<CrmBusinessProductDO> {
|
||||
default void deleteByBusinessId(Long id) { // TODO @lzxhqs:第一个方法,和类之间最好空一行;
|
||||
delete(CrmBusinessProductDO::getBusinessId, id);
|
||||
}
|
||||
|
||||
default CrmBusinessProductDO selectByBusinessId(Long id) { // TODO @lzxhqs:id 最好改成 businessId,上面也是;这样一看更容易懂
|
||||
return selectOne(CrmBusinessProductDO::getBusinessId, id);
|
||||
}
|
||||
}
|
@@ -28,4 +28,17 @@ public interface CrmBusinessStatusTypeMapper extends BaseMapperX<CrmBusinessStat
|
||||
.eqIfPresent(CrmBusinessStatusTypeDO::getStatus, queryVO.getStatus())
|
||||
.inIfPresent(CrmBusinessStatusTypeDO::getId, queryVO.getIdList()));
|
||||
}
|
||||
|
||||
// TODO @lzxhqs:这个可以改成 selectByName。业务上基于在判断 id 匹配;这样更通用一些;mapper 尽量通用,不关注或者特别关联业务;
|
||||
/**
|
||||
* 根据ID和name查询
|
||||
*
|
||||
* @param id 商机状态类型id
|
||||
* @param name 状态类型名
|
||||
* @return result
|
||||
*/
|
||||
default CrmBusinessStatusTypeDO selectByIdAndName(Long id, String name) {
|
||||
return selectOne(CrmBusinessStatusTypeDO::getId, id, CrmBusinessStatusTypeDO::getName, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -63,5 +63,8 @@ public interface CrmContractMapper extends BaseMapperX<CrmContractDO> {
|
||||
default Long selectCountByContactId(Long contactId) {
|
||||
return selectCount(CrmContractDO::getContactId, contactId);
|
||||
}
|
||||
default CrmContractDO selectByBizId(Long businessId) { // TODO @lzxhqs:1)方法和方法之间要有空行;2)selectCountByBusinessId,一个是应该求数量,一个是不要缩写 BizId 可读性;
|
||||
return selectOne(CrmContractDO::getBusinessId, businessId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusi
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -35,6 +36,13 @@ public interface CrmBusinessService {
|
||||
*/
|
||||
void updateBusiness(@Valid CrmBusinessSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新商机相关跟进信息
|
||||
*
|
||||
* @param updateFollowUpReqBOList 跟进信息
|
||||
*/
|
||||
void updateBusinessFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList);
|
||||
|
||||
/**
|
||||
* 删除商机
|
||||
*
|
||||
|
@@ -7,14 +7,22 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
|
||||
import cn.iocoder.yudao.module.crm.convert.businessproduct.CrmBusinessProductConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessProductMapper;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessMapper;
|
||||
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.permission.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
@@ -25,11 +33,13 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_CONTRACT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
||||
|
||||
@@ -45,6 +55,15 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
@Resource
|
||||
private CrmBusinessMapper businessMapper;
|
||||
|
||||
@Resource
|
||||
private CrmBusinessProductMapper businessProductMapper;
|
||||
// TODO @lzxhqs:不直接调用这个 mapper,要调用对方的 service;每个业务独立收敛
|
||||
@Resource
|
||||
private CrmContractMapper contractMapper;
|
||||
|
||||
// TODO @lzxhqs:不直接调用这个 mapper,要调用对方的 service;每个业务独立收敛
|
||||
@Resource
|
||||
private CrmContactBusinessMapper contactBusinessMapper;
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
@Resource
|
||||
@@ -61,18 +80,72 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
.setOwnerUserId(userId);
|
||||
businessMapper.insert(business);
|
||||
// TODO 商机待定:插入商机与产品的关联表;校验商品存在
|
||||
|
||||
// TODO lzxhqs:新增时,是不是不用调用这个方法哈;
|
||||
verifyCrmBusinessProduct(business.getId());
|
||||
// TODO @lzxhqs:用 CollUtils.isNotEmpty;
|
||||
if (!createReqVO.getProducts().isEmpty()) {
|
||||
createBusinessProducts(createReqVO.getProducts(), business.getId());
|
||||
}
|
||||
// TODO 商机待定:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表
|
||||
createContactBusiness(business.getId(), createReqVO.getContactId());
|
||||
|
||||
// 2. 创建数据权限
|
||||
// 设置当前操作的人为负责人
|
||||
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
|
||||
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
|
||||
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||
|
||||
// 4. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("business", business);
|
||||
return business.getId();
|
||||
}
|
||||
|
||||
// TODO @lzxhqs:CrmContactBusinessService 调用这个;这样逻辑才能收敛哈;
|
||||
/**
|
||||
* @param businessId 商机id
|
||||
* @param contactId 联系人id
|
||||
* @throws
|
||||
* @description 联系人与商机的关联
|
||||
* @author lzxhqs
|
||||
*/
|
||||
private void createContactBusiness(Long businessId, Long contactId) {
|
||||
CrmContactBusinessDO contactBusiness = new CrmContactBusinessDO();
|
||||
contactBusiness.setBusinessId(businessId);
|
||||
contactBusiness.setContactId(contactId);
|
||||
contactBusinessMapper.insert(contactBusiness);
|
||||
|
||||
}
|
||||
|
||||
// TODO @lzxhqs:这个方法注释格式不对;删除@description,然后把 插入商机产品关联表 作为方法注释;
|
||||
/**
|
||||
* @param products 产品集合
|
||||
* @description 插入商机产品关联表
|
||||
* @author lzxhqs
|
||||
*/
|
||||
private void createBusinessProducts(List<CrmBusinessProductSaveReqVO> products, Long businessId) {
|
||||
// TODO @lzxhqs:可以用 CollectionUtils.convertList;
|
||||
List<CrmBusinessProductDO> list = new ArrayList<>();
|
||||
for (CrmBusinessProductSaveReqVO product : products) {
|
||||
CrmBusinessProductDO businessProductDO = CrmBusinessProductConvert.INSTANCE.convert(product);
|
||||
businessProductDO.setBusinessId(businessId);
|
||||
list.add(businessProductDO);
|
||||
}
|
||||
businessProductMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id businessId
|
||||
* @description 校验管理的产品存在则删除
|
||||
* @author lzxhqs
|
||||
*/
|
||||
private void verifyCrmBusinessProduct(Long id) {
|
||||
CrmBusinessProductDO businessProductDO = businessProductMapper.selectByBusinessId(id);
|
||||
if (businessProductDO != null) {
|
||||
//通过商机Id删除
|
||||
businessProductMapper.deleteByBusinessId(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
||||
@@ -86,6 +159,11 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class);
|
||||
businessMapper.updateById(updateObj);
|
||||
// TODO 商机待定:插入商机与产品的关联表;校验商品存在
|
||||
// TODO @lzxhqs:更新时,可以调用 CollectionUtils 的 diffList,尽量避免这种先删除再插入;而是新增的插入、变更的更新,没的删除;不然这个表每次更新,会多好多数据;
|
||||
verifyCrmBusinessProduct(updateReqVO.getId());
|
||||
if (!updateReqVO.getProducts().isEmpty()) {
|
||||
createBusinessProducts(updateReqVO.getProducts(), updateReqVO.getId());
|
||||
}
|
||||
|
||||
// TODO @商机待定:如果状态发生变化,插入商机状态变更记录表
|
||||
// 3. 记录操作日志上下文
|
||||
@@ -93,6 +171,11 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
LogRecordContext.putVariable("businessName", oldBusiness.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBusinessFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) {
|
||||
businessMapper.updateBatch(CrmBusinessConvert.INSTANCE.convertList(updateFollowUpReqBOList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
||||
@@ -102,6 +185,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
// 校验存在
|
||||
CrmBusinessDO business = validateBusinessExists(id);
|
||||
// TODO @商机待定:需要校验有没关联合同。CrmContractDO 的 businessId 字段
|
||||
validateContractExists(id);
|
||||
|
||||
// 删除
|
||||
businessMapper.deleteById(id);
|
||||
@@ -112,6 +196,19 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
LogRecordContext.putVariable("businessName", business.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param businessId 商机id
|
||||
* @throws
|
||||
* @description 删除校验合同是关联合同
|
||||
* @author lzxhqs
|
||||
*/
|
||||
private void validateContractExists(Long businessId) {
|
||||
CrmContractDO contract = contractMapper.selectByBizId(businessId);
|
||||
if (contract != null) {
|
||||
throw exception(BUSINESS_CONTRACT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private CrmBusinessDO validateBusinessExists(Long id) {
|
||||
CrmBusinessDO crmBusiness = businessMapper.selectById(id);
|
||||
if (crmBusiness == null) {
|
||||
|
@@ -95,14 +95,18 @@ public class CrmBusinessStatusTypeServiceImpl implements CrmBusinessStatusTypeSe
|
||||
|
||||
// TODO @ljlleo 这个方法,这个参考 validateDeptNameUnique 实现。
|
||||
private void validateBusinessStatusTypeExists(String name, Long id) {
|
||||
LambdaQueryWrapper<CrmBusinessStatusTypeDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
if(null != id) {
|
||||
wrapper.ne(CrmBusinessStatusTypeDO::getId, id);
|
||||
}
|
||||
long cnt = businessStatusTypeMapper.selectCount(wrapper.eq(CrmBusinessStatusTypeDO::getName, name));
|
||||
if (cnt > 0) {
|
||||
CrmBusinessStatusTypeDO businessStatusTypeDO = businessStatusTypeMapper.selectByIdAndName(id, name);
|
||||
if (businessStatusTypeDO != null) {
|
||||
throw exception(BUSINESS_STATUS_TYPE_NAME_EXISTS);
|
||||
}
|
||||
// LambdaQueryWrapper<CrmBusinessStatusTypeDO> wrapper = new LambdaQueryWrapperX<>();
|
||||
// if(null != id) {
|
||||
// wrapper.ne(CrmBusinessStatusTypeDO::getId, id);
|
||||
// }
|
||||
// long cnt = businessStatusTypeMapper.selectCount(wrapper.eq(CrmBusinessStatusTypeDO::getName, name));
|
||||
// if (cnt > 0) {
|
||||
// throw exception(BUSINESS_STATUS_TYPE_NAME_EXISTS);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransformReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -33,6 +34,13 @@ public interface CrmClueService {
|
||||
*/
|
||||
void updateClue(@Valid CrmClueSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新线索相关的跟进信息
|
||||
*
|
||||
* @param clueUpdateFollowUpReqBO 信息
|
||||
*/
|
||||
void updateClueFollowUp(CrmUpdateFollowUpReqBO clueUpdateFollowUpReqBO);
|
||||
|
||||
/**
|
||||
* 删除线索
|
||||
*
|
||||
|
@@ -2,8 +2,11 @@ package cn.iocoder.yudao.module.crm.service.clue;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO;
|
||||
@@ -17,8 +20,13 @@ 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.permission.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.service.impl.DiffParseFunction;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -28,11 +36,12 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -57,46 +66,82 @@ public class CrmClueServiceImpl implements CrmClueService {
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@Override
|
||||
// TODO @min:补充相关几个方法的操作日志;
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}",
|
||||
success = CRM_LEADS_CREATE_SUCCESS)
|
||||
public Long createClue(CrmClueSaveReqVO createReqVO) {
|
||||
// 校验关联数据
|
||||
// 1. 校验关联数据
|
||||
validateRelationDataExists(createReqVO);
|
||||
|
||||
// 插入
|
||||
// 2. 插入
|
||||
CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class);
|
||||
clueMapper.insert(clue);
|
||||
// 返回
|
||||
|
||||
// 3. 创建数据权限
|
||||
CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO()
|
||||
.setBizType(CrmBizTypeEnum.CRM_LEADS.getType())
|
||||
.setBizId(clue.getId())
|
||||
// 设置当前操作的人为负责人
|
||||
.setUserId(getLoginUserId())
|
||||
.setLevel(CrmPermissionLevelEnum.OWNER.getLevel());
|
||||
crmPermissionService.createPermission(createReqBO);
|
||||
|
||||
// 4. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("clue", clue);
|
||||
return clue.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
||||
success = CRM_LEADS_UPDATE_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateClue(CrmClueSaveReqVO updateReqVO) {
|
||||
// 校验线索是否存在
|
||||
validateClueExists(updateReqVO.getId());
|
||||
// 校验关联数据
|
||||
Assert.notNull(updateReqVO.getId(), "线索编号不能为空");
|
||||
// 1. 校验线索是否存在
|
||||
CrmClueDO oldClue = validateClueExists(updateReqVO.getId());
|
||||
// 2. 校验关联数据
|
||||
validateRelationDataExists(updateReqVO);
|
||||
|
||||
// 更新
|
||||
// 3. 更新
|
||||
CrmClueDO updateObj = BeanUtils.toBean(updateReqVO, CrmClueDO.class);
|
||||
clueMapper.updateById(updateObj);
|
||||
|
||||
// 3. 记录操作日志上下文
|
||||
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmCustomerSaveReqVO.class));
|
||||
LogRecordContext.putVariable("clueName", oldClue.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void deleteClue(Long id) {
|
||||
// 校验存在
|
||||
validateClueExists(id);
|
||||
// 删除
|
||||
clueMapper.deleteById(id);
|
||||
// 删除数据权限
|
||||
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id);
|
||||
public void updateClueFollowUp(CrmUpdateFollowUpReqBO clueUpdateFollowUpReqBO) {
|
||||
clueMapper.updateById(BeanUtils.toBean(clueUpdateFollowUpReqBO, CrmClueDO.class).setId(clueUpdateFollowUpReqBO.getBizId()));
|
||||
}
|
||||
|
||||
private void validateClueExists(Long id) {
|
||||
if (clueMapper.selectById(id) == null) {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
||||
success = CRM_LEADS_DELETE_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void deleteClue(Long id) {
|
||||
// 1. 校验存在
|
||||
CrmClueDO clue = validateClueExists(id);
|
||||
|
||||
// 2. 删除
|
||||
clueMapper.deleteById(id);
|
||||
|
||||
// 3. 删除数据权限
|
||||
crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id);
|
||||
|
||||
// 4. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("clueName", clue.getName());
|
||||
}
|
||||
|
||||
private CrmClueDO validateClueExists(Long id) {
|
||||
CrmClueDO crmClueDO = clueMapper.selectById(id);
|
||||
if (crmClueDO == null) {
|
||||
throw exception(CLUE_NOT_EXISTS);
|
||||
}
|
||||
return crmClueDO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,29 +184,24 @@ public class CrmClueServiceImpl implements CrmClueService {
|
||||
List<CrmClueDO> clues = getClueList(clueIds, userId);
|
||||
if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) {
|
||||
clueIds.removeAll(convertSet(clues, CrmClueDO::getId));
|
||||
// TODO @min:可以使用 StrUtil.join(",", clueIds) 简化这种常见操作
|
||||
throw exception(CLUE_ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
throw exception(CLUE_ANY_CLUE_NOT_EXISTS, StrUtil.join(",", clueIds));
|
||||
}
|
||||
|
||||
// 过滤出未转化的客户
|
||||
// TODO @min:1)存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了;2)常见的过滤逻辑,可以使用 CollectionUtils.filterList()
|
||||
List<CrmClueDO> unTransformClues = clues.stream()
|
||||
.filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList();
|
||||
// 传入的线索中包含已经转化的情况,抛出业务异常
|
||||
if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) {
|
||||
// TODO @min:可以使用 StrUtil.join(",", clueIds) 简化这种常见操作
|
||||
clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId));
|
||||
throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
// 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了
|
||||
List<CrmClueDO> translatedClues = CollectionUtils.filterList(clues,
|
||||
clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus()));
|
||||
if (CollUtil.isNotEmpty(translatedClues)) {
|
||||
throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, StrUtil.join(",", convertSet(translatedClues, CrmClueDO::getId)));
|
||||
}
|
||||
|
||||
// 遍历线索(未转化的线索),创建对应的客户
|
||||
unTransformClues.forEach(clue -> {
|
||||
reqVO.getIds().forEach(id -> {
|
||||
// 1. 创建客户
|
||||
CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null);
|
||||
CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(id, CrmCustomerSaveReqVO.class).setId(null);
|
||||
Long customerId = customerService.createCustomer(customerSaveReqVO, userId);
|
||||
// TODO @puhui999:如果有跟进记录,需要一起转过去;
|
||||
// TODO @puhui999:如果有跟进记录,需要一起转过去;提问:艿艿这里是复制线索所有的跟进吗?还是直接把线索相关的跟进 bizType、bizId 全改为关联客户?
|
||||
// 2. 更新线索
|
||||
clueMapper.updateById(new CrmClueDO().setId(clue.getId())
|
||||
clueMapper.updateById(new CrmClueDO().setId(id)
|
||||
.setTransformStatus(Boolean.TRUE).setCustomerId(customerId));
|
||||
});
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReq
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -57,6 +58,13 @@ public interface CrmContactService {
|
||||
*/
|
||||
void updateOwnerUserIdByCustomerId(Long customerId, Long ownerUserId);
|
||||
|
||||
/**
|
||||
* 更新联系人相关跟进信息
|
||||
*
|
||||
* @param updateFollowUpReqBOList 跟进信息
|
||||
*/
|
||||
void updateContactFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList);
|
||||
|
||||
/**
|
||||
* 获得联系人
|
||||
*
|
||||
@@ -89,6 +97,14 @@ public interface CrmContactService {
|
||||
*/
|
||||
List<CrmContactDO> getContactList();
|
||||
|
||||
/**
|
||||
* 获取联系人列表(校验权限)
|
||||
*
|
||||
* @param userId 用户编号
|
||||
* @return 联系人列表
|
||||
*/
|
||||
List<CrmContactDO> getSimpleContactList(Long userId);
|
||||
|
||||
/**
|
||||
* 获得联系人分页
|
||||
*
|
||||
|
@@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
@@ -32,6 +33,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
||||
@@ -192,6 +194,11 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
contactMapper.updateOwnerUserIdByCustomerId(customerId, ownerUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContactFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) {
|
||||
contactMapper.updateBatch(CrmContactConvert.INSTANCE.convertList(updateFollowUpReqBOList));
|
||||
}
|
||||
|
||||
//======================= 查询相关 =======================
|
||||
|
||||
@Override
|
||||
@@ -221,6 +228,13 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
return contactMapper.selectList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmContactDO> getSimpleContactList(Long userId) {
|
||||
CrmContactPageReqVO reqVO = new CrmContactPageReqVO();
|
||||
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
|
||||
return contactMapper.selectPage(reqVO, userId).getList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CrmContactDO> getContactPage(CrmContactPageReqVO pageReqVO, Long userId) {
|
||||
return contactMapper.selectPage(pageReqVO, userId);
|
||||
|
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractSaveR
|
||||
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 cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -41,6 +42,21 @@ public interface CrmContractService {
|
||||
*/
|
||||
void deleteContract(Long id);
|
||||
|
||||
/**
|
||||
* 合同转移
|
||||
*
|
||||
* @param reqVO 请求
|
||||
* @param userId 用户编号
|
||||
*/
|
||||
void transferContract(CrmContractTransferReqVO reqVO, Long userId);
|
||||
|
||||
/**
|
||||
* 更新合同相关的更进信息
|
||||
*
|
||||
* @param contractUpdateFollowUpReqBO 信息
|
||||
*/
|
||||
void updateContractFollowUp(CrmUpdateFollowUpReqBO contractUpdateFollowUpReqBO);
|
||||
|
||||
/**
|
||||
* 获得合同
|
||||
*
|
||||
@@ -78,14 +94,6 @@ public interface CrmContractService {
|
||||
*/
|
||||
PageResult<CrmContractDO> getContractPageByCustomerId(CrmContractPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 合同转移
|
||||
*
|
||||
* @param reqVO 请求
|
||||
* @param userId 用户编号
|
||||
*/
|
||||
void transferContract(CrmContractTransferReqVO reqVO, Long userId);
|
||||
|
||||
/**
|
||||
* 查询属于某个联系人的合同数量
|
||||
*
|
||||
|
@@ -13,6 +13,7 @@ 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.permission.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
@@ -135,6 +136,11 @@ public class CrmContractServiceImpl implements CrmContractService {
|
||||
LogRecordContext.putVariable("contract", contract);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContractFollowUp(CrmUpdateFollowUpReqBO contractUpdateFollowUpReqBO) {
|
||||
contractMapper.updateById(BeanUtils.toBean(contractUpdateFollowUpReqBO, CrmContractDO.class).setId(contractUpdateFollowUpReqBO.getBizId()));
|
||||
}
|
||||
|
||||
//======================= 查询相关 =======================
|
||||
|
||||
@Override
|
||||
|
@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageR
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -90,6 +91,13 @@ public interface CrmCustomerService {
|
||||
*/
|
||||
void lockCustomer(@Valid CrmCustomerLockReqVO lockReqVO, Long userId);
|
||||
|
||||
/**
|
||||
* 更新客户相关更进信息
|
||||
*
|
||||
* @param customerUpdateFollowUpReqBO 请求
|
||||
*/
|
||||
void updateCustomerFollowUp(CrmUpdateFollowUpReqBO customerUpdateFollowUpReqBO);
|
||||
|
||||
// ==================== 公海相关操作 ====================
|
||||
|
||||
/**
|
||||
|
@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionU
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
@@ -203,6 +204,11 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
LogRecordContext.putVariable("customer", customer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCustomerFollowUp(CrmUpdateFollowUpReqBO customerUpdateFollowUpReqBO) {
|
||||
customerMapper.updateById(BeanUtils.toBean(customerUpdateFollowUpReqBO, CrmCustomerDO.class).setId(customerUpdateFollowUpReqBO.getBizId()));
|
||||
}
|
||||
|
||||
// ==================== 公海相关操作 ====================
|
||||
|
||||
@Override
|
||||
@@ -221,16 +227,16 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
||||
// 1.3. 校验客户是否锁定
|
||||
validateCustomerIsLocked(customer, true);
|
||||
|
||||
// 2. 设置负责人为 NULL
|
||||
// 2.1 设置负责人为 NULL
|
||||
int updateOwnerUserIncr = customerMapper.updateOwnerUserIdById(customer.getId(), null);
|
||||
if (updateOwnerUserIncr == 0) {
|
||||
throw exception(CUSTOMER_UPDATE_OWNER_USER_FAIL);
|
||||
}
|
||||
// 3. 删除负责人数据权限
|
||||
// 2.2 删除负责人数据权限
|
||||
permissionService.deletePermission(CrmBizTypeEnum.CRM_CUSTOMER.getType(), customer.getId(),
|
||||
CrmPermissionLevelEnum.OWNER.getLevel());
|
||||
// TODO @puhui999:联系人的负责人,也要设置为 null;这块和领取是对应的;因为领取后,负责人也要关联过来;
|
||||
// 提问:那是不是可以这样理解客户所有联系人的负责人默认为客户的负责人,然后添加客户团队成员时才存在“同时分配给”的操作?
|
||||
|
||||
// 3. 联系人的负责人,也要设置为 null。因为:因为领取后,负责人也要关联过来,这块和 receiveCustomer 是对应的
|
||||
contactService.updateOwnerUserIdByCustomerId(customer.getId(), null);
|
||||
|
||||
// 记录操作日志上下文
|
||||
|
@@ -14,7 +14,7 @@ import jakarta.validation.Valid;
|
||||
public interface CrmFollowUpRecordService {
|
||||
|
||||
/**
|
||||
* 创建跟进记录
|
||||
* 创建跟进记录 (数据权限基于 bizType、 bizId)
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
@@ -22,18 +22,12 @@ public interface CrmFollowUpRecordService {
|
||||
Long createFollowUpRecord(@Valid CrmFollowUpRecordSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新跟进记录
|
||||
* 删除跟进记录 (数据权限基于 bizType、 bizId)
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
* @param id 编号
|
||||
* @param userId 用户编号
|
||||
*/
|
||||
void updateFollowUpRecord(@Valid CrmFollowUpRecordSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除跟进记录
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteFollowUpRecord(Long id);
|
||||
void deleteFollowUpRecord(Long id, Long userId);
|
||||
|
||||
/**
|
||||
* 获得跟进记录
|
||||
@@ -44,7 +38,7 @@ public interface CrmFollowUpRecordService {
|
||||
CrmFollowUpRecordDO getFollowUpRecord(Long id);
|
||||
|
||||
/**
|
||||
* 获得跟进记录分页
|
||||
* 获得跟进记录分页 (数据权限基于 bizType、 bizId)
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 跟进记录分页
|
||||
|
@@ -1,16 +1,36 @@
|
||||
package cn.iocoder.yudao.module.crm.service.followup;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.permission.CrmPermissionDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.followup.CrmFollowUpRecordMapper;
|
||||
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.permission.core.annotations.CrmPermission;
|
||||
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.clue.CrmClueService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -25,36 +45,134 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
|
||||
@Resource
|
||||
private CrmFollowUpRecordMapper crmFollowUpRecordMapper;
|
||||
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
@Resource
|
||||
private CrmBusinessService businessService;
|
||||
@Resource
|
||||
private CrmClueService clueService;
|
||||
@Resource
|
||||
private CrmContactService contactService;
|
||||
@Resource
|
||||
private CrmContractService contractService;
|
||||
@Resource
|
||||
private CrmCustomerService customerService;
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizTypeValue = "#createReqVO.bizType", bizId = "#createReqVO.bizId", level = CrmPermissionLevelEnum.WRITE)
|
||||
public Long createFollowUpRecord(CrmFollowUpRecordSaveReqVO createReqVO) {
|
||||
// 创建更进记录
|
||||
CrmFollowUpRecordDO followUpRecord = BeanUtils.toBean(createReqVO, CrmFollowUpRecordDO.class);
|
||||
crmFollowUpRecordMapper.insert(followUpRecord);
|
||||
// TODO @puhui999:需要更新 bizId 对应的记录;
|
||||
// TODO @puhui999:需要更新 businessIds、contactIds 对应的记录;
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// TODO @puhui999:感觉可以这里基于 type 做 102 到 104 这种判断;然后,每个类型的调用封装一个小方法,之后调用这些小方法;再之后,74-76、80-82 也是等价的处理;
|
||||
// 2. 更新 bizId 对应的记录;
|
||||
updateBizTypeFollowUp(followUpRecord, now);
|
||||
// 3.1 更新 contactIds 对应的记录
|
||||
if (CollUtil.isNotEmpty(createReqVO.getContactIds())) {
|
||||
contactService.updateContactFollowUpBatch(convertList(createReqVO.getContactIds(), contactId ->
|
||||
new CrmUpdateFollowUpReqBO().setBizId(contactId).setContactNextTime(followUpRecord.getNextTime())
|
||||
.setContactLastTime(now).setContactLastContent(followUpRecord.getContent())));
|
||||
}
|
||||
// 3.2 需要更新 businessIds、contactIds 对应的记录
|
||||
if (CollUtil.isNotEmpty(createReqVO.getBusinessIds())) {
|
||||
businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(), businessId ->
|
||||
new CrmUpdateFollowUpReqBO().setBizId(businessId).setContactNextTime(followUpRecord.getNextTime())
|
||||
.setContactLastTime(now).setContactLastContent(followUpRecord.getContent())));
|
||||
}
|
||||
return followUpRecord.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFollowUpRecord(CrmFollowUpRecordSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateFollowUpRecordExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CrmFollowUpRecordDO updateObj = BeanUtils.toBean(updateReqVO, CrmFollowUpRecordDO.class);
|
||||
crmFollowUpRecordMapper.updateById(updateObj);
|
||||
/**
|
||||
* 执行更新
|
||||
*
|
||||
* @param followUpRecord 跟进记录
|
||||
* @param now 跟进时间
|
||||
*/
|
||||
private void updateBizTypeFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
updateBusinessFollowUp(followUpRecord, now);
|
||||
updateClueFollowUp(followUpRecord, now);
|
||||
updateContactFollowUp(followUpRecord, now);
|
||||
updateContractFollowUp(followUpRecord, now);
|
||||
updateCustomerFollowUp(followUpRecord, now);
|
||||
}
|
||||
|
||||
private void updateBusinessFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_BUSINESS.getType(), followUpRecord.getBizType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新商机跟进信息
|
||||
businessService.updateBusinessFollowUpBatch(Collections.singletonList(new CrmUpdateFollowUpReqBO()
|
||||
.setBizId(followUpRecord.getBizId()).setContactNextTime(followUpRecord.getNextTime()).setContactLastTime(now)
|
||||
.setContactLastContent(followUpRecord.getContent())));
|
||||
}
|
||||
|
||||
private void updateClueFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_LEADS.getType(), followUpRecord.getBizType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新线索跟进信息
|
||||
clueService.updateClueFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
|
||||
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
|
||||
}
|
||||
|
||||
private void updateContactFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTACT.getType(), followUpRecord.getBizType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新联系人跟进信息
|
||||
contactService.updateContactFollowUpBatch(Collections.singletonList(new CrmUpdateFollowUpReqBO()
|
||||
.setBizId(followUpRecord.getBizId()).setContactNextTime(followUpRecord.getNextTime()).setContactLastTime(now)
|
||||
.setContactLastContent(followUpRecord.getContent())));
|
||||
}
|
||||
|
||||
private void updateContractFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CONTRACT.getType(), followUpRecord.getBizType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新合同跟进信息
|
||||
contractService.updateContractFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
|
||||
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
|
||||
}
|
||||
|
||||
private void updateCustomerFollowUp(CrmFollowUpRecordDO followUpRecord, LocalDateTime now) {
|
||||
if (ObjUtil.notEqual(CrmBizTypeEnum.CRM_CUSTOMER.getType(), followUpRecord.getBizType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新客户跟进信息
|
||||
customerService.updateCustomerFollowUp(new CrmUpdateFollowUpReqBO().setBizId(followUpRecord.getBizId()).setContactLastTime(now)
|
||||
.setContactNextTime(followUpRecord.getNextTime()).setContactLastContent(followUpRecord.getContent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFollowUpRecord(Long id) {
|
||||
public void deleteFollowUpRecord(Long id, Long userId) {
|
||||
// 校验存在
|
||||
validateFollowUpRecordExists(id);
|
||||
CrmFollowUpRecordDO followUpRecord = validateFollowUpRecordExists(id);
|
||||
// 校验权限
|
||||
List<CrmPermissionDO> permissionList = permissionService.getPermissionListByBiz(
|
||||
followUpRecord.getBizType(), followUpRecord.getBizId());
|
||||
boolean condition = anyMatch(permissionList, permission ->
|
||||
ObjUtil.equal(permission.getUserId(), userId) && ObjUtil.equal(permission.getLevel(), CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||
if (!condition) {
|
||||
throw exception(FOLLOW_UP_RECORD_DELETE_DENIED);
|
||||
}
|
||||
|
||||
// 删除
|
||||
crmFollowUpRecordMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateFollowUpRecordExists(Long id) {
|
||||
if (crmFollowUpRecordMapper.selectById(id) == null) {
|
||||
private CrmFollowUpRecordDO validateFollowUpRecordExists(Long id) {
|
||||
CrmFollowUpRecordDO followUpRecord = crmFollowUpRecordMapper.selectById(id);
|
||||
if (followUpRecord == null) {
|
||||
throw exception(FOLLOW_UP_RECORD_NOT_EXISTS);
|
||||
}
|
||||
return followUpRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +180,9 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
|
||||
return crmFollowUpRecordMapper.selectById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizTypeValue = "#pageReqVO.bizType", bizId = "#pageReqVO.bizId", level = CrmPermissionLevelEnum.READ)
|
||||
public PageResult<CrmFollowUpRecordDO> getFollowUpRecordPage(CrmFollowUpRecordPageReqVO pageReqVO) {
|
||||
return crmFollowUpRecordMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
@@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.crm.service.followup.bo;
|
||||
|
||||
import com.mzt.logapi.starter.annotation.DiffLogField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 跟进信息 Update Req BO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Data
|
||||
public class CrmUpdateFollowUpReqBO {
|
||||
|
||||
@Schema(description = "数据编号", example = "3167")
|
||||
@NotNull(message = "数据编号不能为空")
|
||||
private Long bizId;
|
||||
|
||||
@Schema(description = "最后跟进时间")
|
||||
@DiffLogField(name = "最后跟进时间")
|
||||
@NotNull(message = "最后跟进时间不能为空")
|
||||
private LocalDateTime contactLastTime;
|
||||
|
||||
@Schema(description = "下次联系时间")
|
||||
@DiffLogField(name = "下次联系时间")
|
||||
private LocalDateTime contactNextTime;
|
||||
|
||||
@Schema(description = "最后更进内容")
|
||||
@DiffLogField(name = "最后更进内容")
|
||||
@NotNull(message = "最后更进内容不能为空")
|
||||
private String contactLastContent;
|
||||
|
||||
}
|
Reference in New Issue
Block a user