【增加CRM:产品以及产品分类】
This commit is contained in:
parent
ecf728966f
commit
bf42f8e9ff
|
@ -63,3 +63,45 @@ CREATE TABLE `crm_receivable_plan` (
|
|||
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '回款计划' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- 产品表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `crm_product`;
|
||||
CREATE TABLE `crm_product`
|
||||
(
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品名称',
|
||||
`no` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '产品编码',
|
||||
`unit` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '单位',
|
||||
`price` bigint(20) NULL DEFAULT 0 COMMENT '价格',
|
||||
`status` tinyint(2) NOT NULL DEFAULT 1 COMMENT '状态 1-上架 0-下架',
|
||||
`category_id` bigint(20) NOT NULL COMMENT '产品分类ID',
|
||||
`description` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '产品描述',
|
||||
`owner_user_id` bigint(20) NOT NULL COMMENT '负责人的用户编号',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
|
||||
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '产品表' ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- 产品分类表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `crm_product_category`;
|
||||
CREATE TABLE `crm_product_category`
|
||||
(
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '名称',
|
||||
`parent_id` bigint(20) NOT NULL COMMENT '父级id',
|
||||
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`tenant_id` bigint(20) NOT NULL DEFAULT 0 COMMENT '租户编号',
|
||||
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '产品分类表' ROW_FORMAT = Dynamic;
|
|
@ -17,4 +17,8 @@ INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `st
|
|||
INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1400, 7, '微信支付', '7', 'crm_return_type', 0, 'default', '', '', '1', '2023-10-18 21:55:53', '1', '2023-10-18 21:55:53', b'0');
|
||||
INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1401, 8, '其他', '8', 'crm_return_type', 0, 'default', '', '', '1', '2023-10-18 21:56:06', '1', '2023-10-18 21:56:06', b'0');
|
||||
|
||||
INSERT INTO `system_dict_type` (`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES (604, '产品状态', 'crm_product_status', 0, '', '1', '2023-10-30 21:47:59', '1', '2023-10-30 21:48:45', b'0', '1970-01-01 00:00:00');
|
||||
|
||||
INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1412, 1, '上架', '1', 'crm_product_status', 0, 'success', '', '', '1', '2023-10-30 21:49:34', '1', '2023-10-30 21:49:34', b'0');
|
||||
INSERT INTO `system_dict_data` (`id`, `sort`, `label`, `value`, `dict_type`, `status`, `color_type`, `css_class`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (1411, 0, '下架', '0', 'crm_product_status', 0, 'success', '', '', '1', '2023-10-30 21:49:13', '1', '2023-10-30 21:49:13', b'0');
|
||||
|
||||
|
|
|
@ -41,4 +41,11 @@ public interface ErrorCodeConstants {
|
|||
ErrorCode CRM_PERMISSION_MODEL_NOT_EXISTS = new ErrorCode(1_020_007_002, "{}不存在");
|
||||
ErrorCode CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS = new ErrorCode(1_020_007_003, "{}操作失败,原因:转移对象已经是该负责人");
|
||||
|
||||
// ========== 产品 1_020_008_000 ==========
|
||||
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 PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_020_009_000, "产品分类不存在");
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO;
|
||||
import cn.iocoder.yudao.module.crm.convert.product.ProductConvert;
|
||||
import cn.iocoder.yudao.module.crm.service.product.ProductService;
|
||||
|
||||
@Tag(name = "管理后台 - 产品")
|
||||
@RestController
|
||||
@RequestMapping("/crm/product")
|
||||
@Validated
|
||||
public class ProductController {
|
||||
|
||||
@Resource
|
||||
private ProductService productService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建产品")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:create')")
|
||||
public CommonResult<Long> createProduct(@Valid @RequestBody ProductCreateReqVO createReqVO) {
|
||||
return success(productService.createProduct(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新产品")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:update')")
|
||||
public CommonResult<Boolean> updateProduct(@Valid @RequestBody ProductUpdateReqVO updateReqVO) {
|
||||
productService.updateProduct(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除产品")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:delete')")
|
||||
public CommonResult<Boolean> deleteProduct(@RequestParam("id") Long id) {
|
||||
productService.deleteProduct(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得产品")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:query')")
|
||||
public CommonResult<ProductRespVO> getProduct(@RequestParam("id") Long id) {
|
||||
ProductDO product = productService.getProduct(id);
|
||||
return success(ProductConvert.INSTANCE.convert(product));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得产品列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:query')")
|
||||
public CommonResult<List<ProductRespVO>> getProductList(@RequestParam("ids") Collection<Long> ids) {
|
||||
List<ProductDO> list = productService.getProductList(ids);
|
||||
return success(ProductConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得产品分页")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:query')")
|
||||
public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageVO) {
|
||||
PageResult<ProductDO> pageResult = productService.getProductPage(pageVO);
|
||||
return success(ProductConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出产品 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportProductExcel(@Valid ProductExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<ProductDO> list = productService.getProductList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<ProductExcelVO> datas = ProductConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "产品.xls", "数据", ProductExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 产品 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class ProductBaseVO {
|
||||
|
||||
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotNull(message = "产品名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "产品编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "产品编码不能为空")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "单位")
|
||||
private String unit;
|
||||
|
||||
@Schema(description = "价格", example = "8911")
|
||||
private Long price;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "产品分类ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1738")
|
||||
@NotNull(message = "产品分类ID不能为空")
|
||||
private Long categoryId;
|
||||
|
||||
@Schema(description = "产品描述", example = "你说的对")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
|
||||
@NotNull(message = "负责人的用户编号不能为空")
|
||||
private Long ownerUserId;
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 产品创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCreateReqVO extends ProductBaseVO {
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 产品 Excel VO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Data
|
||||
public class ProductExcelVO {
|
||||
|
||||
@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;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 产品 Excel 导出 Request VO,参数和 ProductPageReqVO 是一致的")
|
||||
@Data
|
||||
public class ProductExportReqVO {
|
||||
|
||||
@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;
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 产品分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductPageReqVO 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")
|
||||
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;
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 产品 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductRespVO extends ProductBaseVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.product.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 产品更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductUpdateReqVO extends ProductBaseVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20529")
|
||||
@NotNull(message = "主键id不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO;
|
||||
import cn.iocoder.yudao.module.crm.convert.productcategory.ProductCategoryConvert;
|
||||
import cn.iocoder.yudao.module.crm.service.productcategory.ProductCategoryService;
|
||||
|
||||
@Tag(name = "管理后台 - 产品分类")
|
||||
@RestController
|
||||
@RequestMapping("/crm/product-category")
|
||||
@Validated
|
||||
public class ProductCategoryController {
|
||||
|
||||
@Resource
|
||||
private ProductCategoryService productCategoryService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建产品分类")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product-category:create')")
|
||||
public CommonResult<Long> createProductCategory(@Valid @RequestBody ProductCategoryCreateReqVO createReqVO) {
|
||||
return success(productCategoryService.createProductCategory(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新产品分类")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product-category:update')")
|
||||
public CommonResult<Boolean> updateProductCategory(@Valid @RequestBody ProductCategoryUpdateReqVO updateReqVO) {
|
||||
productCategoryService.updateProductCategory(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除产品分类")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('crm:product-category:delete')")
|
||||
public CommonResult<Boolean> deleteProductCategory(@RequestParam("id") Long id) {
|
||||
productCategoryService.deleteProductCategory(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得产品分类")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product-category:query')")
|
||||
public CommonResult<ProductCategoryRespVO> getProductCategory(@RequestParam("id") Long id) {
|
||||
ProductCategoryDO productCategory = productCategoryService.getProductCategory(id);
|
||||
return success(ProductCategoryConvert.INSTANCE.convert(productCategory));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得产品分类列表")
|
||||
@PreAuthorize("@ss.hasPermission('crm:product-category:query')")
|
||||
public CommonResult<List<ProductCategoryRespVO>> getProductCategoryList(@Valid ProductCategoryListReqVO treeListReqVO) {
|
||||
List<ProductCategoryDO> list = productCategoryService.getProductCategoryList(treeListReqVO);
|
||||
return success(ProductCategoryConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 产品分类 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class ProductCategoryBaseVO {
|
||||
|
||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotNull(message = "名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "父级id", requiredMode = Schema.RequiredMode.REQUIRED, example = "4680")
|
||||
@NotNull(message = "父级id不能为空")
|
||||
private Long parentId;
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 产品分类创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCategoryCreateReqVO extends ProductCategoryBaseVO {
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 产品分类 List VO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Schema(description = "管理后台 - 产品分类列表 Request VO")
|
||||
@Data
|
||||
public class ProductCategoryListReqVO {
|
||||
|
||||
@ExcelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("父级id")
|
||||
private Long parentId;
|
||||
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 产品分类 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCategoryRespVO extends ProductCategoryBaseVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 产品分类更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCategoryUpdateReqVO extends ProductCategoryBaseVO {
|
||||
|
||||
@Schema(description = "主键id", requiredMode = Schema.RequiredMode.REQUIRED, example = "23902")
|
||||
@NotNull(message = "主键id不能为空")
|
||||
private Long id;
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package cn.iocoder.yudao.module.crm.convert.product;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO;
|
||||
|
||||
/**
|
||||
* 产品 Convert
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductConvert {
|
||||
|
||||
ProductConvert INSTANCE = Mappers.getMapper(ProductConvert.class);
|
||||
|
||||
ProductDO convert(ProductCreateReqVO bean);
|
||||
|
||||
ProductDO convert(ProductUpdateReqVO bean);
|
||||
|
||||
ProductRespVO convert(ProductDO bean);
|
||||
|
||||
List<ProductRespVO> convertList(List<ProductDO> list);
|
||||
|
||||
PageResult<ProductRespVO> convertPage(PageResult<ProductDO> page);
|
||||
|
||||
List<ProductExcelVO> convertList02(List<ProductDO> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package cn.iocoder.yudao.module.crm.convert.productcategory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO;
|
||||
|
||||
/**
|
||||
* 产品分类 Convert
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductCategoryConvert {
|
||||
|
||||
ProductCategoryConvert INSTANCE = Mappers.getMapper(ProductCategoryConvert.class);
|
||||
|
||||
ProductCategoryDO convert(ProductCategoryCreateReqVO bean);
|
||||
|
||||
ProductCategoryDO convert(ProductCategoryUpdateReqVO bean);
|
||||
|
||||
ProductCategoryRespVO convert(ProductCategoryDO bean);
|
||||
|
||||
List<ProductCategoryRespVO> convertList(List<ProductCategoryDO> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package cn.iocoder.yudao.module.crm.dal.dataobject.product;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 产品 DO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@TableName("crm_product")
|
||||
@KeySequence("crm_product_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ProductDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 产品名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 产品编码
|
||||
*/
|
||||
private String no;
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
/**
|
||||
* 价格
|
||||
*/
|
||||
private Long price;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link TODO crm_product_status 对应的类}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 产品分类ID
|
||||
*/
|
||||
private Long categoryId;
|
||||
/**
|
||||
* 产品描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 负责人的用户编号
|
||||
*/
|
||||
private Long ownerUserId;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package cn.iocoder.yudao.module.crm.dal.dataobject.productcategory;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 产品分类 DO
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@TableName("crm_product_category")
|
||||
@KeySequence("crm_product_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ProductCategoryDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 父级id
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package cn.iocoder.yudao.module.crm.dal.mysql.product;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*;
|
||||
|
||||
/**
|
||||
* 产品 Mapper
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductMapper extends BaseMapperX<ProductDO> {
|
||||
|
||||
default PageResult<ProductDO> selectPage(ProductPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ProductDO>()
|
||||
.likeIfPresent(ProductDO::getName, reqVO.getName())
|
||||
.likeIfPresent(ProductDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ProductDO::getUnit, reqVO.getUnit())
|
||||
.eqIfPresent(ProductDO::getPrice, reqVO.getPrice())
|
||||
.eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(ProductDO::getCategoryId, reqVO.getCategoryId())
|
||||
.eqIfPresent(ProductDO::getDescription, reqVO.getDescription())
|
||||
.eqIfPresent(ProductDO::getOwnerUserId, reqVO.getOwnerUserId())
|
||||
.betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ProductDO::getId));
|
||||
}
|
||||
|
||||
default List<ProductDO> selectList(ProductExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<ProductDO>()
|
||||
.likeIfPresent(ProductDO::getName, reqVO.getName())
|
||||
.likeIfPresent(ProductDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ProductDO::getUnit, reqVO.getUnit())
|
||||
.eqIfPresent(ProductDO::getPrice, reqVO.getPrice())
|
||||
.eqIfPresent(ProductDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(ProductDO::getCategoryId, reqVO.getCategoryId())
|
||||
.eqIfPresent(ProductDO::getDescription, reqVO.getDescription())
|
||||
.eqIfPresent(ProductDO::getOwnerUserId, reqVO.getOwnerUserId())
|
||||
.betweenIfPresent(ProductDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ProductDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.iocoder.yudao.module.crm.dal.mysql.productcategory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*;
|
||||
|
||||
/**
|
||||
* 产品分类 Mapper
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductCategoryMapper extends BaseMapperX<ProductCategoryDO> {
|
||||
|
||||
|
||||
default List<ProductCategoryDO> selectList(ProductCategoryListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<ProductCategoryDO>()
|
||||
.likeIfPresent(ProductCategoryDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ProductCategoryDO::getParentId, reqVO.getParentId())
|
||||
.orderByDesc(ProductCategoryDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package cn.iocoder.yudao.module.crm.service.product;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 产品 Service 接口
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
public interface ProductService {
|
||||
|
||||
/**
|
||||
* 创建产品
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProduct(@Valid ProductCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新产品
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateProduct(@Valid ProductUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除产品
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteProduct(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 产品
|
||||
*/
|
||||
ProductDO getProduct(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 产品列表
|
||||
*/
|
||||
List<ProductDO> getProductList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得产品分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 产品分页
|
||||
*/
|
||||
PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得产品列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 产品列表
|
||||
*/
|
||||
List<ProductDO> getProductList(ProductExportReqVO exportReqVO);
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
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.ProductCreateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductExportReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductPageReqVO;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.ProductUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.crm.convert.product.ProductConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.product.ProductDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.product.ProductMapper;
|
||||
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.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.PRODUCT_NO_EXISTS;
|
||||
|
||||
/**
|
||||
* 产品 Service 实现类
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@Resource
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public Long createProduct(ProductCreateReqVO createReqVO) {
|
||||
//校验产品编号是否存在
|
||||
validateProductNo(createReqVO.getNo());
|
||||
// 插入
|
||||
ProductDO product = ProductConvert.INSTANCE.convert(createReqVO);
|
||||
productMapper.insert(product);
|
||||
// 返回
|
||||
return product.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProduct(ProductUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateProductExists(updateReqVO.getId(), updateReqVO.getNo());
|
||||
// 更新
|
||||
ProductDO updateObj = ProductConvert.INSTANCE.convert(updateReqVO);
|
||||
productMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProduct(Long id) {
|
||||
// 校验存在
|
||||
validateProductExists(id, null);
|
||||
// 删除
|
||||
productMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateProductExists(Long id, String no) {
|
||||
ProductDO product = productMapper.selectById(id);
|
||||
if (product == null) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
if (no != null && no.equals(product.getNo())) {
|
||||
throw exception(PRODUCT_NO_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductDO getProduct(Long id) {
|
||||
return productMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductDO> getProductList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
return productMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductDO> getProductPage(ProductPageReqVO pageReqVO) {
|
||||
return productMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductDO> getProductList(ProductExportReqVO exportReqVO) {
|
||||
return productMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
private void validateProductNo(String no) {
|
||||
ProductDO product = productMapper.selectOne(new LambdaQueryWrapper<ProductDO>().eq(ProductDO::getNo, no));
|
||||
if (product != null) {
|
||||
throw exception(PRODUCT_NO_EXISTS);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package cn.iocoder.yudao.module.crm.service.productcategory;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 产品分类 Service 接口
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
public interface ProductCategoryService {
|
||||
|
||||
/**
|
||||
* 创建产品分类
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createProductCategory(@Valid ProductCategoryCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新产品分类
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateProductCategory(@Valid ProductCategoryUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除产品分类
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteProductCategory(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品分类
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 产品分类
|
||||
*/
|
||||
ProductCategoryDO getProductCategory(Long id);
|
||||
|
||||
/**
|
||||
* 获得产品分类列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 产品分类列表
|
||||
*/
|
||||
List<ProductCategoryDO> getProductCategoryList(ProductCategoryListReqVO treeListReqVO);
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package cn.iocoder.yudao.module.crm.service.productcategory;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.productcategory.vo.*;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.productcategory.ProductCategoryDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import cn.iocoder.yudao.module.crm.convert.productcategory.ProductCategoryConvert;
|
||||
import cn.iocoder.yudao.module.crm.dal.mysql.productcategory.ProductCategoryMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
/**
|
||||
* 产品分类 Service 实现类
|
||||
*
|
||||
* @author ZanGe丶
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductCategoryServiceImpl implements ProductCategoryService {
|
||||
|
||||
@Resource
|
||||
private ProductCategoryMapper productCategoryMapper;
|
||||
|
||||
@Override
|
||||
public Long createProductCategory(ProductCategoryCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
ProductCategoryDO productCategory = ProductCategoryConvert.INSTANCE.convert(createReqVO);
|
||||
productCategoryMapper.insert(productCategory);
|
||||
// 返回
|
||||
return productCategory.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProductCategory(ProductCategoryUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateProductCategoryExists(updateReqVO.getId());
|
||||
// 更新
|
||||
ProductCategoryDO updateObj = ProductCategoryConvert.INSTANCE.convert(updateReqVO);
|
||||
productCategoryMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProductCategory(Long id) {
|
||||
// 校验存在
|
||||
validateProductCategoryExists(id);
|
||||
// 删除
|
||||
productCategoryMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateProductCategoryExists(Long id) {
|
||||
if (productCategoryMapper.selectById(id) == null) {
|
||||
throw exception(PRODUCT_CATEGORY_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductCategoryDO getProductCategory(Long id) {
|
||||
return productCategoryMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProductCategoryDO> getProductCategoryList(ProductCategoryListReqVO treeListReqVO) {
|
||||
return productCategoryMapper.selectList(treeListReqVO);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.product.ProductMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.crm.dal.mysql.productcategory.ProductCategoryMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue