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