mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
🔨 CRM:优化产品代码的实现
This commit is contained in:
parent
c463f831f4
commit
a11d5dc5f1
@ -7,10 +7,11 @@ package cn.iocoder.yudao.module.crm.enums;
|
||||
*/
|
||||
public interface DictTypeConstants {
|
||||
|
||||
// ========== CRM 模块 ==========
|
||||
String CRM_CUSTOMER_INDUSTRY = "crm_customer_industry"; // CRM 客户所属行业
|
||||
String CRM_CUSTOMER_LEVEL = "crm_customer_level"; // CRM 客户等级
|
||||
String CRM_CUSTOMER_SOURCE = "crm_customer_source"; // CRM 客户来源
|
||||
String CRM_AUDIT_STATUS = "crm_audit_status"; // CRM 审批状态
|
||||
String CRM_PRODUCT_UNIT = "crm_product_unit"; // CRM 产品单位
|
||||
String CRM_PRODUCT_STATUS = "crm_product_status"; // CRM 产品状态
|
||||
|
||||
}
|
||||
|
@ -50,18 +50,16 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode CRM_PERMISSION_DELETE_SELF_PERMISSION_FAIL_EXIST_OWNER = new ErrorCode(1_020_007_007, "删除数据权限失败,原因:不能删除负责人");
|
||||
|
||||
// ========== 产品 1_020_008_000 ==========
|
||||
ErrorCode CRM_PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在");
|
||||
ErrorCode CRM_PRODUCT_NO_EXISTS = new ErrorCode(1_020_008_001, "产品编号已存在");
|
||||
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_020_008_000, "产品不存在");
|
||||
ErrorCode PRODUCT_NO_EXISTS = new ErrorCode(1_020_008_001, "产品编号已存在");
|
||||
|
||||
// ========== 产品分类 1_020_009_000 ==========
|
||||
ErrorCode CRM_PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");
|
||||
ErrorCode CRM_PRODUCT_CATEGORY_EXISTS = new ErrorCode(1_020_009_001, "产品分类已存在");
|
||||
|
||||
ErrorCode CRM_PRODUCT_CATEGORY_USED = new ErrorCode(1_020_009_002, "产品分类已关联产品");
|
||||
|
||||
ErrorCode CRM_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1_020_009_003, "父分类不存在");
|
||||
ErrorCode CRM_CATEGORY_PARENT_NOT_FIRST_LEVEL = new ErrorCode(1_020_009_004, "父分类不能是二级分类");
|
||||
ErrorCode CRM_CATEGORY_EXISTS_CHILDREN = new ErrorCode(1_020_009_005, "存在子分类,无法删除");
|
||||
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");
|
||||
ErrorCode PRODUCT_CATEGORY_EXISTS = new ErrorCode(1_020_009_001, "产品分类已存在");
|
||||
ErrorCode PRODUCT_CATEGORY_USED = new ErrorCode(1_020_009_002, "产品分类已关联产品");
|
||||
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXISTS = new ErrorCode(1_020_009_003, "父分类不存在");
|
||||
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_FIRST_LEVEL = new ErrorCode(1_020_009_004, "父分类不能是二级分类");
|
||||
ErrorCode product_CATEGORY_EXISTS_CHILDREN = new ErrorCode(1_020_009_005, "存在子分类,无法删除");
|
||||
|
||||
// ========== 商机状态类型 1_020_010_000 ==========
|
||||
ErrorCode BUSINESS_STATUS_TYPE_NOT_EXISTS = new ErrorCode(1_020_010_000, "商机状态类型不存在");
|
||||
|
@ -21,7 +21,9 @@ public enum CrmBizTypeEnum implements IntArrayValuable {
|
||||
CRM_CUSTOMER(2, "客户"),
|
||||
CRM_CONTACT(3, "联系人"),
|
||||
CRM_BUSINESS(4, "商机"),
|
||||
CRM_CONTRACT(5, "合同");
|
||||
CRM_CONTRACT(5, "合同"),
|
||||
CRM_PRODUCT(6, "产品")
|
||||
;
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CrmBizTypeEnum::getType).toArray();
|
||||
|
||||
|
@ -7,12 +7,15 @@ import lombok.Getter;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* CRM 商品状态
|
||||
*
|
||||
* @author ZanGe丶
|
||||
* @create 2023-11-30 21:53
|
||||
* @since 2023-11-30 21:53
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CrmProductStatusEnum implements IntArrayValuable {
|
||||
|
||||
DISABLE(0, "下架"),
|
||||
ENABLE(1, "上架");
|
||||
|
||||
@ -32,13 +35,4 @@ public enum CrmProductStatusEnum implements IntArrayValuable {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否处于【上架】状态
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 是否处于【上架】状态
|
||||
*/
|
||||
public static boolean isEnable(Integer status) {
|
||||
return ENABLE.getStatus().equals(status);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.*;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.convert.product.CrmProductConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService;
|
||||
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -19,12 +28,17 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - 产品")
|
||||
@Tag(name = "管理后台 - CRM 产品")
|
||||
@RestController
|
||||
@RequestMapping("/crm/product")
|
||||
@Validated
|
||||
@ -32,18 +46,23 @@ public class CrmProductController {
|
||||
|
||||
@Resource
|
||||
private CrmProductService productService;
|
||||
@Resource
|
||||
private CrmProductCategoryService productCategoryService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建产品")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:create')")
|
||||
public CommonResult<Long> createProduct(@Valid @RequestBody CrmProductCreateReqVO createReqVO) {
|
||||
public CommonResult<Long> createProduct(@Valid @RequestBody CrmProductSaveReqVO createReqVO) {
|
||||
return success(productService.createProduct(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新产品")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:update')")
|
||||
public CommonResult<Boolean> updateProduct(@Valid @RequestBody CrmProductUpdateReqVO updateReqVO) {
|
||||
public CommonResult<Boolean> updateProduct(@Valid @RequestBody CrmProductSaveReqVO updateReqVO) {
|
||||
productService.updateProduct(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
@ -63,7 +82,7 @@ public class CrmProductController {
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:query')")
|
||||
public CommonResult<CrmProductRespVO> getProduct(@RequestParam("id") Long id) {
|
||||
CrmProductDO product = productService.getProduct(id);
|
||||
return success(CrmProductConvert.INSTANCE.convert(product));
|
||||
return success(BeanUtils.toBean(product, CrmProductRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ -71,19 +90,31 @@ public class CrmProductController {
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:query')")
|
||||
public CommonResult<PageResult<CrmProductRespVO>> getProductPage(@Valid CrmProductPageReqVO pageVO) {
|
||||
PageResult<CrmProductDO> pageResult = productService.getProductPage(pageVO);
|
||||
return success(CrmProductConvert.INSTANCE.convertPage(pageResult));
|
||||
return success(new PageResult<>(getProductDetailList(pageResult.getList()), pageResult.getTotal()));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出产品 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportProductExcel(@Valid CrmProductExportReqVO exportReqVO,
|
||||
public void exportProductExcel(@Valid CrmProductPageReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<CrmProductDO> list = productService.getProductList(exportReqVO);
|
||||
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<CrmProductDO> list = productService.getProductPage(exportReqVO).getList();
|
||||
// 导出 Excel
|
||||
List<CrmProductExcelVO> datas = CrmProductConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "产品.xls", "数据", CrmProductExcelVO.class, datas);
|
||||
ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class,
|
||||
getProductDetailList(list));
|
||||
}
|
||||
|
||||
private List<CrmProductRespVO> getProductDetailList(List<CrmProductDO> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||
convertSetByFlatMap(list, user -> Stream.of(Long.valueOf(user.getCreator()), user.getOwnerUserId())));
|
||||
List<CrmProductCategoryDO> productCategoryList = productCategoryService.getProductCategoryList(
|
||||
convertSet(list, CrmProductDO::getCategoryId));
|
||||
return CrmProductConvert.INSTANCE.convertList(list, userMap, productCategoryList);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 产品创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmProductCreateReqVO extends CrmProductBaseVO {
|
||||
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
|
||||
@NotNull(message = "负责人的用户编号不能为空")
|
||||
private Long ownerUserId;
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
// TODO 芋艿:这个导出最后搞 那暂时就放着不动了哈
|
||||
/**
|
||||
* 产品 Excel VO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Data
|
||||
public class CrmProductExcelVO {
|
||||
|
||||
@ExcelProperty("主键id")
|
||||
private Long id;
|
||||
|
||||
@ExcelProperty("产品名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("产品编码")
|
||||
private String no;
|
||||
|
||||
@ExcelProperty("单位")
|
||||
private String unit;
|
||||
|
||||
@ExcelProperty("价格")
|
||||
private Long price;
|
||||
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat("crm_product_status") // TODO 代码优化:建议设置到对应的 XXXDictTypeConstants 枚举类中
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("产品分类ID")
|
||||
private Long categoryId;
|
||||
|
||||
@ExcelProperty("产品描述")
|
||||
private String description;
|
||||
|
||||
@ExcelProperty("负责人的用户编号")
|
||||
private Long ownerUserId;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO 芋艿:这个导出最后搞
|
||||
@Schema(description = "管理后台 - 产品 Excel 导出 Request VO,参数和 ProductPageReqVO 是一致的")
|
||||
@Data
|
||||
public class CrmProductExportReqVO {
|
||||
|
||||
@Schema(description = "产品名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "产品编码")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "单位")
|
||||
private String unit;
|
||||
|
||||
@Schema(description = "价格", example = "8911")
|
||||
private Long price;
|
||||
|
||||
@Schema(description = "状态", example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "产品分类ID", example = "1738")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "产品描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "负责人的用户编号", example = "31926")
|
||||
private Long ownerUserId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
@ -5,14 +5,8 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
// TODO @zange-ok:按照需求,裁剪下筛选的字段,目前应该只要 name 和 status
|
||||
@Schema(description = "管理后台 - 产品分页 Request VO")
|
||||
@Schema(description = "管理后台 - CRM 产品分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@ -21,29 +15,7 @@ public class CrmProductPageReqVO extends PageParam {
|
||||
@Schema(description = "产品名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "产品编码")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "单位")
|
||||
private String unit;
|
||||
|
||||
@Schema(description = "价格", example = "8911")
|
||||
private Long price;
|
||||
|
||||
@Schema(description = "状态", example = "2")
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "产品分类ID", example = "1738")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "产品描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "负责人的用户编号", example = "31926")
|
||||
private Long ownerUserId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
|
@ -1,24 +1,70 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 产品 Response VO")
|
||||
@Schema(description = "管理后台 - CRM 产品 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmProductRespVO extends CrmProductBaseVO {
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CrmProductRespVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
|
||||
@Schema(description = "产品编号", example = "20529")
|
||||
@ExcelProperty("产品编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "好产品")
|
||||
@ExcelProperty("产品名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "产品编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "12306")
|
||||
@ExcelProperty("产品编码")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "单位", example = "2")
|
||||
@ExcelProperty(value = "单位", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.CRM_PRODUCT_UNIT)
|
||||
private Integer unit;
|
||||
|
||||
@Schema(description = "价格, 单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911")
|
||||
@ExcelProperty("价格,单位:分")
|
||||
private Long price;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架")
|
||||
@ExcelProperty(value = "单位", converter = DictConvert.class)
|
||||
@DictFormat(DictTypeConstants.CRM_PRODUCT_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
private Long categoryId;
|
||||
@Schema(description = "产品分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "衣服")
|
||||
@ExcelProperty("产品分类")
|
||||
private String categoryName;
|
||||
|
||||
@Schema(description = "产品描述", example = "你说的对")
|
||||
@ExcelProperty("产品描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
|
||||
@NotNull(message = "负责人的用户编号不能为空")
|
||||
private Long ownerUserId;
|
||||
@Schema(description = "负责人的用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
|
||||
@ExcelProperty("负责人")
|
||||
private String ownerUserName;
|
||||
|
||||
@Schema(description = "创建人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private String creator;
|
||||
@Schema(description = "创建人名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
|
||||
@ExcelProperty("创建人")
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
@ -1,19 +1,16 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
// TODO @zange-ok:需要加 CRM 前置噢
|
||||
/**
|
||||
* 产品 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Schema(description = "管理后台 - CRM 产品创建/修改 Request VO")
|
||||
@Data
|
||||
public class CrmProductBaseVO {
|
||||
public class CrmProductSaveReqVO {
|
||||
|
||||
// TODO @zange:example 要写哈;主要是接口文档,可以基于 example 可以生产请求参数
|
||||
@Schema(description = "产品编号", example = "20529")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "好产品")
|
||||
@NotNull(message = "产品名称不能为空")
|
||||
@ -24,22 +21,25 @@ public class CrmProductBaseVO {
|
||||
private String no;
|
||||
|
||||
@Schema(description = "单位", example = "2")
|
||||
private String unit;
|
||||
private Integer unit;
|
||||
|
||||
@Schema(description = "价格", example = "8911")
|
||||
@Schema(description = "价格, 单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "8911")
|
||||
@NotNull(message = "价格不能为空")
|
||||
private Long price;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "上架")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "产品分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "产品分类ID不能为空")
|
||||
@Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "产品分类编号不能为空")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "产品描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
// TODO @zange-ok:这个字段只有 create 可以传递,update 不传递;所以放到 create 和 resp 里;
|
||||
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
|
||||
@NotNull(message = "负责人的用户编号不能为空")
|
||||
private Long ownerUserId;
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 产品更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class CrmProductUpdateReqVO extends CrmProductBaseVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
|
||||
@NotNull(message = "主键id不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
@ -1,15 +1,18 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExcelVO;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
|
||||
/**
|
||||
* 产品 Convert
|
||||
@ -21,16 +24,17 @@ public interface CrmProductConvert {
|
||||
|
||||
CrmProductConvert INSTANCE = Mappers.getMapper(CrmProductConvert.class);
|
||||
|
||||
CrmProductDO convert(CrmProductCreateReqVO bean);
|
||||
|
||||
CrmProductDO convert(CrmProductUpdateReqVO bean);
|
||||
|
||||
CrmProductRespVO convert(CrmProductDO bean);
|
||||
|
||||
List<CrmProductRespVO> convertList(List<CrmProductDO> list);
|
||||
|
||||
PageResult<CrmProductRespVO> convertPage(PageResult<CrmProductDO> page);
|
||||
|
||||
List<CrmProductExcelVO> convertList02(List<CrmProductDO> list);
|
||||
default List<CrmProductRespVO> convertList(List<CrmProductDO> list,
|
||||
Map<Long, AdminUserRespDTO> userMap,
|
||||
List<CrmProductCategoryDO> categoryList) {
|
||||
List<CrmProductRespVO> voList = BeanUtils.toBean(list, CrmProductRespVO.class);
|
||||
Map<Long, CrmProductCategoryDO> categoryMap = convertMap(categoryList, CrmProductCategoryDO::getId);
|
||||
for (CrmProductRespVO vo : voList) {
|
||||
MapUtils.findAndThen(categoryMap, vo.getCategoryId(), category -> vo.setCategoryName(category.getName()));
|
||||
MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
|
||||
MapUtils.findAndThen(userMap, Long.valueOf(vo.getCreator()), user -> vo.setCreatorName(user.getNickname()));
|
||||
}
|
||||
return voList;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* 产品 DO
|
||||
* CRM 产品 DO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@ -23,7 +23,7 @@ import lombok.*;
|
||||
public class CrmProductDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键 id
|
||||
* 编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
@ -37,20 +37,24 @@ public class CrmProductDO extends BaseDO {
|
||||
private String no;
|
||||
/**
|
||||
* 单位
|
||||
*
|
||||
* 字典 {@link cn.iocoder.yudao.module.crm.enums.DictTypeConstants#CRM_PRODUCT_UNIT}
|
||||
*/
|
||||
private String unit;
|
||||
private Integer unit;
|
||||
/**
|
||||
* 价格
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Long price;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 关联 {@link CrmProductStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 产品分类 ID
|
||||
* 关联 {@link CrmProductCategoryDO#id}
|
||||
*
|
||||
* 关联 {@link CrmProductCategoryDO#getId()} 字段
|
||||
*/
|
||||
private Long categoryId;
|
||||
/**
|
||||
@ -59,6 +63,8 @@ public class CrmProductDO extends BaseDO {
|
||||
private String description;
|
||||
/**
|
||||
* 负责人的用户编号
|
||||
*
|
||||
* 关联 AdminUserDO 的 id 字段
|
||||
*/
|
||||
private Long ownerUserId;
|
||||
|
||||
|
@ -3,15 +3,12 @@ package cn.iocoder.yudao.module.crm.dal.mysql.product;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品 Mapper
|
||||
* CRM 产品 Mapper
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@ -25,14 +22,8 @@ public interface CrmProductMapper extends BaseMapperX<CrmProductDO> {
|
||||
.orderByDesc(CrmProductDO::getId));
|
||||
}
|
||||
|
||||
default List<CrmProductDO> selectList(CrmProductExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<CrmProductDO>()
|
||||
.likeIfPresent(CrmProductDO::getName, reqVO.getName())
|
||||
.eqIfPresent(CrmProductDO::getStatus, reqVO.getStatus())
|
||||
.orderByDesc(CrmProductDO::getId));
|
||||
}
|
||||
|
||||
default CrmProductDO selectByNo(String no) {
|
||||
return selectOne(CrmProductDO::getNo, no);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 产品表
|
||||
*/
|
||||
package cn.iocoder.yudao.module.crm.dal.mysql.product;
|
@ -6,10 +6,11 @@ import cn.iocoder.yudao.module.crm.controller.admin.product.vo.productcategory.C
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品分类 Service 接口
|
||||
* CRM 产品分类 Service 接口
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@ -48,9 +49,17 @@ public interface CrmProductCategoryService {
|
||||
/**
|
||||
* 获得产品分类列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @param listReqVO 列表请求
|
||||
* @return 产品分类列表
|
||||
*/
|
||||
List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO treeListReqVO);
|
||||
List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO listReqVO);
|
||||
|
||||
/**
|
||||
* 获得产品分类列表
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @return 产品分类列表
|
||||
*/
|
||||
List<CrmProductCategoryDO> getProductCategoryList(Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -19,7 +20,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
import static cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO.PARENT_ID_NULL;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
|
||||
// TODO @zange-ok:这个类所在的包,放到 product 下;
|
||||
/**
|
||||
* 产品分类 Service 实现类
|
||||
*
|
||||
@ -29,10 +29,11 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
@Validated
|
||||
public class CrmProductCategoryServiceImpl implements CrmProductCategoryService {
|
||||
|
||||
@Resource
|
||||
@Resource(name = "crmProductCategoryMapper")
|
||||
private CrmProductCategoryMapper productCategoryMapper;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
@Lazy // 延迟加载,解决循环依赖问题
|
||||
private CrmProductService crmProductService;
|
||||
|
||||
@Override
|
||||
@ -63,7 +64,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
|
||||
CrmProductCategoryDO productCategoryDO = productCategoryMapper.selectByName(updateReqVO.getName());
|
||||
if (productCategoryDO != null &&
|
||||
ObjUtil.notEqual(productCategoryDO.getId(), updateReqVO.getId())) {
|
||||
throw exception(CRM_PRODUCT_CATEGORY_EXISTS);
|
||||
throw exception(PRODUCT_CATEGORY_EXISTS);
|
||||
}
|
||||
// 更新
|
||||
CrmProductCategoryDO updateObj = CrmProductCategoryConvert.INSTANCE.convert(updateReqVO);
|
||||
@ -77,11 +78,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
|
||||
validateProductCategoryExists(id);
|
||||
// 校验是否还有子分类
|
||||
if (productCategoryMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(CRM_CATEGORY_EXISTS_CHILDREN);
|
||||
throw exception(product_CATEGORY_EXISTS_CHILDREN);
|
||||
}
|
||||
// 校验是否被产品使用
|
||||
if (crmProductService.getProductByCategoryId(id) !=null) {
|
||||
throw exception(CRM_PRODUCT_CATEGORY_USED);
|
||||
throw exception(PRODUCT_CATEGORY_USED);
|
||||
}
|
||||
// 删除
|
||||
productCategoryMapper.deleteById(id);
|
||||
@ -89,7 +90,7 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
|
||||
|
||||
private void validateProductCategoryExists(Long id) {
|
||||
if (productCategoryMapper.selectById(id) == null) {
|
||||
throw exception(CRM_PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,11 +102,11 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
|
||||
// 父分类不存在
|
||||
CrmProductCategoryDO category = productCategoryMapper.selectById(id);
|
||||
if (category == null) {
|
||||
throw exception(CRM_CATEGORY_PARENT_NOT_EXISTS);
|
||||
throw exception(PRODUCT_CATEGORY_PARENT_NOT_EXISTS);
|
||||
}
|
||||
// 父分类不能是二级分类
|
||||
if (!Objects.equals(category.getParentId(), PARENT_ID_NULL)) {
|
||||
throw exception(CRM_CATEGORY_PARENT_NOT_FIRST_LEVEL);
|
||||
throw exception(PRODUCT_CATEGORY_PARENT_NOT_FIRST_LEVEL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +116,13 @@ public class CrmProductCategoryServiceImpl implements CrmProductCategoryService
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO treeListReqVO) {
|
||||
return productCategoryMapper.selectList(treeListReqVO);
|
||||
public List<CrmProductCategoryDO> getProductCategoryList(CrmProductCategoryListReqVO listReqVO) {
|
||||
return productCategoryMapper.selectList(listReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmProductCategoryDO> getProductCategoryList(Collection<Long> ids) {
|
||||
return productCategoryMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package cn.iocoder.yudao.module.crm.service.product;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@ -12,7 +10,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 产品 Service 接口
|
||||
* CRM 产品 Service 接口
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@ -24,14 +22,14 @@ public interface CrmProductService {
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProduct(@Valid CrmProductCreateReqVO createReqVO);
|
||||
Long createProduct(@Valid CrmProductSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新产品
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateProduct(@Valid CrmProductUpdateReqVO updateReqVO);
|
||||
void updateProduct(@Valid CrmProductSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
@ -64,14 +62,6 @@ public interface CrmProductService {
|
||||
*/
|
||||
PageResult<CrmProductDO> getProductPage(CrmProductPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得产品列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 产品列表
|
||||
*/
|
||||
List<CrmProductDO> getProductList(CrmProductExportReqVO exportReqVO);
|
||||
|
||||
/**
|
||||
* 获得产品
|
||||
*
|
||||
|
@ -3,27 +3,32 @@ package cn.iocoder.yudao.module.crm.service.product;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductExportReqVO;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.convert.product.CrmProductConvert;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.product.CrmProductMapper;
|
||||
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
||||
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
|
||||
// TODO 芋艿:数据权限
|
||||
/**
|
||||
* 产品 Service 实现类
|
||||
* CRM 产品 Service 实现类
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@ -31,35 +36,71 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
@Validated
|
||||
public class CrmProductServiceImpl implements CrmProductService {
|
||||
|
||||
@Resource
|
||||
@Resource(name = "crmProductMapper")
|
||||
private CrmProductMapper productMapper;
|
||||
|
||||
@Resource
|
||||
private CrmProductCategoryService productCategoryService;
|
||||
@Resource
|
||||
private CrmPermissionService permissionService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@Override
|
||||
public Long createProduct(CrmProductCreateReqVO createReqVO) {
|
||||
// 校验产品编号是否存在
|
||||
validateProductNoDuplicate(createReqVO.getNo());
|
||||
// TODO @zange-ok:需要校验 categoryId 是否存在;
|
||||
public Long createProduct(CrmProductSaveReqVO createReqVO) {
|
||||
// 校验产品
|
||||
adminUserApi.validateUserList(Collections.singleton(createReqVO.getOwnerUserId()));
|
||||
validateProductNoDuplicate(null, createReqVO.getNo());
|
||||
validateProductCategoryExists(createReqVO.getCategoryId());
|
||||
// 插入
|
||||
CrmProductDO product = CrmProductConvert.INSTANCE.convert(createReqVO);
|
||||
|
||||
// 插入产品
|
||||
CrmProductDO product = BeanUtils.toBean(createReqVO, CrmProductDO.class);
|
||||
productMapper.insert(product);
|
||||
// 返回
|
||||
|
||||
// 插入数据权限
|
||||
permissionService.createPermission(new CrmPermissionCreateReqBO().setUserId(product.getOwnerUserId())
|
||||
.setBizType(CrmBizTypeEnum.CRM_PRODUCT.getType()).setBizId(product.getId())
|
||||
.setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
|
||||
return product.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProduct(CrmProductUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
public void updateProduct(CrmProductSaveReqVO updateReqVO) {
|
||||
// 校验产品
|
||||
updateReqVO.setOwnerUserId(null); // 不修改负责人
|
||||
validateProductExists(updateReqVO.getId());
|
||||
// TODO @zange-ok:需要校验 categoryId 是否存在;
|
||||
validateProductNoDuplicate(updateReqVO.getId(), updateReqVO.getNo());
|
||||
validateProductCategoryExists(updateReqVO.getCategoryId());
|
||||
// 更新
|
||||
CrmProductDO updateObj = CrmProductConvert.INSTANCE.convert(updateReqVO);
|
||||
|
||||
// 更新产品
|
||||
CrmProductDO updateObj = BeanUtils.toBean(updateReqVO, CrmProductDO.class);
|
||||
productMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
private void validateProductExists(Long id) {
|
||||
CrmProductDO product = productMapper.selectById(id);
|
||||
if (product == null) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateProductNoDuplicate(Long id, String no) {
|
||||
CrmProductDO product = productMapper.selectByNo(no);
|
||||
if (product == null
|
||||
|| product.getId().equals(id)) {
|
||||
return;
|
||||
}
|
||||
throw exception(PRODUCT_NO_EXISTS);
|
||||
}
|
||||
|
||||
private void validateProductCategoryExists(Long categoryId) {
|
||||
CrmProductCategoryDO category = productCategoryService.getProductCategory(categoryId);
|
||||
if (category == null) {
|
||||
throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProduct(Long id) {
|
||||
// 校验存在
|
||||
@ -68,21 +109,6 @@ public class CrmProductServiceImpl implements CrmProductService {
|
||||
productMapper.deleteById(id);
|
||||
}
|
||||
|
||||
// TODO @zange-ok:validateProductExists 要不只校验是否存在;然后是否 no 重复,交给 validateProductNo,名字改成 validateProductNoDuplicate,和别的模块保持一致哈;
|
||||
private void validateProductExists(Long id) {
|
||||
CrmProductDO product = productMapper.selectById(id);
|
||||
if (product == null) {
|
||||
throw exception(CRM_PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateProductCategoryExists(Long categoryId) {
|
||||
CrmProductCategoryDO productCategory = productCategoryService.getProductCategory(categoryId);
|
||||
if (productCategory == null) {
|
||||
throw exception(CRM_PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrmProductDO getProduct(Long id) {
|
||||
return productMapper.selectById(id);
|
||||
@ -101,21 +127,9 @@ public class CrmProductServiceImpl implements CrmProductService {
|
||||
return productMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CrmProductDO> getProductList(CrmProductExportReqVO exportReqVO) {
|
||||
return productMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CrmProductDO getProductByCategoryId(Long categoryId) {
|
||||
return productMapper.selectOne(new LambdaQueryWrapper<CrmProductDO>().eq(CrmProductDO::getCategoryId, categoryId));
|
||||
}
|
||||
|
||||
private void validateProductNoDuplicate(String no) {
|
||||
CrmProductDO product = productMapper.selectOne(new LambdaQueryWrapper<CrmProductDO>().eq(CrmProductDO::getNo, no));
|
||||
if (product != null) {
|
||||
throw exception(CRM_PRODUCT_NO_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -108,16 +108,12 @@ public class CrmCrmReceivableServiceImplTest extends BaseDbUnitTest {
|
||||
o.setPlanId(null);
|
||||
o.setCustomerId(null);
|
||||
o.setContractId(null);
|
||||
o.setCheckStatus(null);
|
||||
o.setProcessInstanceId(null);
|
||||
o.setReturnTime(null);
|
||||
o.setReturnType(null);
|
||||
o.setPrice(null);
|
||||
o.setOwnerUserId(null);
|
||||
o.setBatchId(null);
|
||||
o.setSort(null);
|
||||
o.setDataScope(null);
|
||||
o.setDataScopeDeptIds(null);
|
||||
o.setAuditStatus(null);
|
||||
o.setRemark(null);
|
||||
o.setCreateTime(null);
|
||||
|
@ -58,7 +58,7 @@ public class DictDataController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list-all-simple")
|
||||
@GetMapping({"/list-all-simple", "simple-list"})
|
||||
@Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
|
||||
// 无需添加权限认证,因为前端全局都需要
|
||||
public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
|
||||
|
Loading…
Reference in New Issue
Block a user