diff --git a/sql/mysql/optinal/crm.sql b/sql/mysql/optinal/crm.sql index e69de29bb2..1cb1371aed 100644 --- a/sql/mysql/optinal/crm.sql +++ b/sql/mysql/optinal/crm.sql @@ -0,0 +1,15 @@ +-- `ruoyi-vue-pro`.crm_contact_business_link definition + +CREATE TABLE `crm_contact_business_link` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', + `contact_id` int(11) DEFAULT NULL COMMENT '联系人id', + `business_id` int(11) DEFAULT NULL COMMENT '商机id', + `creator` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updater` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', + `tenant_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '租户编号', + PRIMARY KEY (`id`), + UNIQUE KEY `crm_contact_business_link_un` (`contact_id`,`business_id`,`deleted`,`tenant_id`) +) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='联系人商机关联表'; \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java index a1ae599db7..222253f9f4 100644 --- a/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java +++ b/yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java @@ -23,6 +23,7 @@ public interface ErrorCodeConstants { // ========== 联系人管理 1-020-003-000 ========== ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在"); + ErrorCode CONTACT_BUSINESS_LINK_NOT_EXISTS = new ErrorCode( 1_020_003_001, "联系人商机关联不存在"); // ========== 回款 1-020-004-000 ========== ErrorCode RECEIVABLE_NOT_EXISTS = new ErrorCode(1_020_004_000, "回款不存在"); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/CrmContactBusinessLinkController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/CrmContactBusinessLinkController.java new file mode 100644 index 0000000000..9824ec0052 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/CrmContactBusinessLinkController.java @@ -0,0 +1,121 @@ +package cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink; + +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import javax.validation.constraints.*; +import javax.validation.*; +import javax.servlet.http.*; +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS; + +import cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo.*; +import cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink.CrmContactBusinessLinkDO; +import cn.iocoder.yudao.module.crm.service.contactbusinesslink.CrmContactBusinessLinkService; + +@Tag(name = "管理后台 - 联系人商机关联") +@RestController +@RequestMapping("/crm/contact-business-link") +@Validated +public class CrmContactBusinessLinkController { + + @Resource + private CrmContactBusinessLinkService contactBusinessLinkService; + @Resource + private CrmBusinessService crmBusinessService; + + @PostMapping("/create") + @Operation(summary = "创建联系人商机关联") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:create')") + public CommonResult createContactBusinessLink(@Valid @RequestBody CrmContactBusinessLinkSaveReqVO createReqVO) { + return success(contactBusinessLinkService.createContactBusinessLink(createReqVO)); + } + @PostMapping("/create-batch") + @Operation(summary = "创建联系人商机关联") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:create')") + @Transactional(rollbackFor = Exception.class) + public CommonResult createContactBusinessLinkBatch(@Valid @RequestBody List createReqVO) { + createReqVO.stream().forEach(item -> { + CrmBusinessDO crmBusinessDO = crmBusinessService.getBusiness(item.getBusinessId()); + if(crmBusinessDO == null){ + throw exception(BUSINESS_NOT_EXISTS); + } + }); + contactBusinessLinkService.createContactBusinessLinkBatch(createReqVO); + return success(true); + } + @PutMapping("/update") + @Operation(summary = "更新联系人商机关联") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:update')") + public CommonResult updateContactBusinessLink(@Valid @RequestBody CrmContactBusinessLinkSaveReqVO updateReqVO) { + contactBusinessLinkService.updateContactBusinessLink(updateReqVO); + return success(true); + } + @DeleteMapping("/delete-batch") + @Operation(summary = "批量删除联系人商机关联") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:delete')") + public CommonResult deleteContactBusinessLinkBatch(@Valid @RequestBody List deleteList) { + contactBusinessLinkService.deleteContactBusinessLink(deleteList); + return success(true); + } + @GetMapping("/get") + @Operation(summary = "获得联系人商机关联") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:query')") + public CommonResult getContactBusinessLink(@RequestParam("id") Long id) { + CrmContactBusinessLinkDO contactBusinessLink = contactBusinessLinkService.getContactBusinessLink(id); + return success(BeanUtils.toBean(contactBusinessLink, CrmContactBusinessLinkRespVO.class)); + } + @GetMapping("/page-by-contact") + @Operation(summary = "获得联系人商机关联") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:query')") + public CommonResult> getContactBusinessLinkByContact(@Valid CrmContactBusinessLinkPageReqVO pageReqVO) { + PageResult contactBusinessLink = contactBusinessLinkService.getContactBusinessLinkPageByContact(pageReqVO); + return success(contactBusinessLink); + } + @GetMapping("/page") + @Operation(summary = "获得联系人商机关联分页") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:query')") + public CommonResult> getContactBusinessLinkPage(@Valid CrmContactBusinessLinkPageReqVO pageReqVO) { + PageResult pageResult = contactBusinessLinkService.getContactBusinessLinkPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, CrmContactBusinessLinkRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出联系人商机关联 Excel") + @PreAuthorize("@ss.hasPermission('crm:contact-business-link:export')") + @OperateLog(type = EXPORT) + public void exportContactBusinessLinkExcel(@Valid CrmContactBusinessLinkPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = contactBusinessLinkService.getContactBusinessLinkPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "联系人商机关联.xls", "数据", CrmContactBusinessLinkRespVO.class, + BeanUtils.toBean(list, CrmContactBusinessLinkRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkPageReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkPageReqVO.java new file mode 100644 index 0000000000..20a90279e8 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkPageReqVO.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 联系人商机关联分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CrmContactBusinessLinkPageReqVO extends PageParam { + + @Schema(description = "联系人id", example = "20878") + private Long contactId; + + @Schema(description = "商机id", example = "7638") + private Long businessId; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkRespVO.java new file mode 100644 index 0000000000..a31adb4d64 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkRespVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 联系人商机关联 Response VO") +@Data +@ExcelIgnoreUnannotated +public class CrmContactBusinessLinkRespVO { + + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17220") + @ExcelProperty("主键") + private Long id; + + @Schema(description = "联系人id", example = "20878") + @ExcelProperty("联系人id") + private Long contactId; + + @Schema(description = "商机id", example = "7638") + @ExcelProperty("商机id") + private Long businessId; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkSaveReqVO.java new file mode 100644 index 0000000000..507924b7b0 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contactbusinesslink/vo/CrmContactBusinessLinkSaveReqVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; +import java.util.*; + +@Schema(description = "管理后台 - 联系人商机关联新增/修改 Request VO") +@Data +public class CrmContactBusinessLinkSaveReqVO { + + @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "17220") + private Long id; + + @Schema(description = "联系人id", example = "20878") + @NotNull(message="联系人不能为空") + private Long contactId; + + @Schema(description = "商机id", example = "7638") + @NotNull(message="商机不能为空") + private Long businessId; + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java index e93fc9ab3e..affb57b558 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/business/CrmBusinessConvert.java @@ -32,6 +32,7 @@ public interface CrmBusinessConvert { CrmBusinessDO convert(CrmBusinessUpdateReqVO bean); CrmBusinessRespVO convert(CrmBusinessDO bean); + List convert(List bean); PageResult convertPage(PageResult page); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contactbusinessslink/CrmContactBusinessLinkConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contactbusinessslink/CrmContactBusinessLinkConvert.java new file mode 100644 index 0000000000..6ffc3584ab --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contactbusinessslink/CrmContactBusinessLinkConvert.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.module.crm.convert.contactbusinessslink; + +import cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo.CrmContactBusinessLinkSaveReqVO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink.CrmContactBusinessLinkDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface CrmContactBusinessLinkConvert { + CrmContactBusinessLinkConvert INSTANCE = Mappers.getMapper(CrmContactBusinessLinkConvert.class); + CrmContactBusinessLinkDO convert(CrmContactBusinessLinkSaveReqVO bean); + List convert(List bean); +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contactbusinesslink/CrmContactBusinessLinkDO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contactbusinesslink/CrmContactBusinessLinkDO.java new file mode 100644 index 0000000000..4b3a5988a6 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contactbusinesslink/CrmContactBusinessLinkDO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 联系人商机关联 DO + * + * @author 芋道源码 + */ +@TableName("crm_contact_business_link") +@KeySequence("crm_contact_business_link_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class CrmContactBusinessLinkDO extends BaseDO { + + /** + * 主键 + */ + @TableId + private Long id; + /** + * 联系人id + */ + private Long contactId; + /** + * 商机id + */ + private Long businessId; + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contactbusinesslink/CrmContactBusinessLinkMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contactbusinesslink/CrmContactBusinessLinkMapper.java new file mode 100644 index 0000000000..6bcdd723b3 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contactbusinesslink/CrmContactBusinessLinkMapper.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink.CrmContactBusinessLinkDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo.*; + +/** + * 联系人商机关联 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface CrmContactBusinessLinkMapper extends BaseMapperX { + + default PageResult selectPage(CrmContactBusinessLinkPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(CrmContactBusinessLinkDO::getContactId, reqVO.getContactId()) + .eqIfPresent(CrmContactBusinessLinkDO::getBusinessId, reqVO.getBusinessId()) + .betweenIfPresent(CrmContactBusinessLinkDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(CrmContactBusinessLinkDO::getId)); + } + default PageResult selectPageByContact(CrmContactBusinessLinkPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(CrmContactBusinessLinkDO::getContactId, reqVO.getContactId()) + .orderByDesc(CrmContactBusinessLinkDO::getId)); + } +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java index 697587fa3c..d961247994 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java @@ -88,7 +88,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService { } @Override - @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, level = CrmPermissionLevelEnum.READ) + @CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS,bizId = "#id", level = CrmPermissionLevelEnum.READ) public CrmBusinessDO getBusiness(Long id) { return businessMapper.selectById(id); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkService.java new file mode 100644 index 0000000000..c212a61006 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkService.java @@ -0,0 +1,69 @@ +package cn.iocoder.yudao.module.crm.service.contactbusinesslink; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO; +import cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo.*; +import cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink.CrmContactBusinessLinkDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +/** + * 联系人商机关联 Service 接口 + * + * @author 芋道源码 + */ +public interface CrmContactBusinessLinkService { + + /** + * 创建联系人商机关联 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createContactBusinessLink(@Valid CrmContactBusinessLinkSaveReqVO createReqVO); + /** + * 创建联系人商机关联 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + void createContactBusinessLinkBatch(@Valid List createReqVO); + /** + * 更新联系人商机关联 + * + * @param updateReqVO 更新信息 + */ + void updateContactBusinessLink(@Valid CrmContactBusinessLinkSaveReqVO updateReqVO); + + /** + * 删除联系人商机关联 + * + * @param createReqVO 删除列表 + */ + void deleteContactBusinessLink(@Valid List createReqVO); + + /** + * 获得联系人商机关联 + * + * @param id 编号 + * @return 联系人商机关联 + */ + CrmContactBusinessLinkDO getContactBusinessLink(Long id); + /** + * 获得联系人商机关联分页 + * + * @param pageReqVO 编号 + * @return 联系人商机关联 + */ + PageResult getContactBusinessLinkPageByContact(CrmContactBusinessLinkPageReqVO pageReqVO); + /** + * 获得联系人商机关联分页 + * + * @param pageReqVO 分页查询 + * @return 联系人商机关联分页 + */ + PageResult getContactBusinessLinkPage(CrmContactBusinessLinkPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkServiceImpl.java new file mode 100644 index 0000000000..879f8126ed --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contactbusinesslink/CrmContactBusinessLinkServiceImpl.java @@ -0,0 +1,111 @@ +package cn.iocoder.yudao.module.crm.service.contactbusinesslink; + +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO; +import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert; +import cn.iocoder.yudao.module.crm.convert.contactbusinessslink.CrmContactBusinessLinkConvert; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +import cn.iocoder.yudao.module.crm.controller.admin.contactbusinesslink.vo.*; +import cn.iocoder.yudao.module.crm.dal.dataobject.contactbusinesslink.CrmContactBusinessLinkDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessLinkMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; + +/** + * 联系人商机关联 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class CrmContactBusinessLinkServiceImpl implements CrmContactBusinessLinkService { + + @Resource + private CrmContactBusinessLinkMapper contactBusinessLinkMapper; + @Resource + private CrmBusinessService crmBusinessService; + + @Override + public Long createContactBusinessLink(CrmContactBusinessLinkSaveReqVO createReqVO) { + // 插入 + CrmContactBusinessLinkDO contactBusinessLink = BeanUtils.toBean(createReqVO, CrmContactBusinessLinkDO.class); + contactBusinessLinkMapper.insert(contactBusinessLink); + // 返回 + return contactBusinessLink.getId(); + } + + @Override + public void createContactBusinessLinkBatch(List createReqVOList) { + // 插入 + List saveDoList = CrmContactBusinessLinkConvert.INSTANCE.convert(createReqVOList); + contactBusinessLinkMapper.insertBatch(saveDoList); + } + + @Override + public void updateContactBusinessLink(CrmContactBusinessLinkSaveReqVO updateReqVO) { + // 校验存在 + validateContactBusinessLinkExists(updateReqVO.getId()); + // 更新 + CrmContactBusinessLinkDO updateObj = BeanUtils.toBean(updateReqVO, CrmContactBusinessLinkDO.class); + contactBusinessLinkMapper.updateById(updateObj); + } + + @Override + public void deleteContactBusinessLink(List createReqVO) { + // 删除 + createReqVO.forEach(item -> { + contactBusinessLinkMapper.delete(new LambdaQueryWrapperX() + .eq(CrmContactBusinessLinkDO::getBusinessId,item.getBusinessId()) + .eq(CrmContactBusinessLinkDO::getContactId,item.getContactId()) + .eq(CrmContactBusinessLinkDO::getDeleted,0)); + }); + } + + private void validateContactBusinessLinkExists(Long id) { + if (contactBusinessLinkMapper.selectById(id) == null) { + throw exception(CONTACT_BUSINESS_LINK_NOT_EXISTS); + } + } + + @Override + public CrmContactBusinessLinkDO getContactBusinessLink(Long id) { + return contactBusinessLinkMapper.selectById(id); + } + + @Override + public PageResult getContactBusinessLinkPageByContact(CrmContactBusinessLinkPageReqVO pageReqVO) { + CrmContactBusinessLinkPageReqVO crmContactBusinessLinkPageReqVO = new CrmContactBusinessLinkPageReqVO(); + crmContactBusinessLinkPageReqVO.setContactId(pageReqVO.getContactId()); + PageResult businessLinkDOS = contactBusinessLinkMapper.selectPageByContact(crmContactBusinessLinkPageReqVO); + List businessDOS = crmBusinessService.getBusinessList(CollectionUtils.convertList(businessLinkDOS.getList(), + CrmContactBusinessLinkDO::getBusinessId)); + PageResult pageResult = new PageResult(); + pageResult.setList(CrmBusinessConvert.INSTANCE.convert(businessDOS)); + pageResult.setTotal(businessLinkDOS.getTotal()); + return pageResult; + + } + + @Override + public PageResult getContactBusinessLinkPage(CrmContactBusinessLinkPageReqVO pageReqVO) { + return contactBusinessLinkMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file