diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java index 4ab84d5bb9..63f2bb10ad 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/enums/ErrorCodeConstants.java @@ -16,4 +16,10 @@ public interface ErrorCodeConstants { // ========== 品牌相关编号 1008002000 ========== ErrorCode BRAND_NOT_EXISTS = new ErrorCode(1008002000, "品牌不存在"); + + // ========== 规格名称 1008003000 ========== + ErrorCode ATTR_KEY_NOT_EXISTS = new ErrorCode(1008003000, "规格名称不存在"); + + // ========== 规格值 1008004000 ========== + ErrorCode ATTR_VALUE_NOT_EXISTS = new ErrorCode(1008004000, "规格值不存在"); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/AttrKeyController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/AttrKeyController.java new file mode 100755 index 0000000000..9e11a3e589 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/AttrKeyController.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey; + +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.annotations.*; + +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.product.controller.admin.attrkey.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrkey.AttrKeyDO; +import cn.iocoder.yudao.module.product.convert.attrkey.AttrKeyConvert; +import cn.iocoder.yudao.module.product.service.attrkey.AttrKeyService; + +@Api(tags = "管理后台 - 规格名称") +@RestController +@RequestMapping("/product/attr-key") +@Validated +public class AttrKeyController { + + @Resource + private AttrKeyService attrKeyService; + + @PostMapping("/create") + @ApiOperation("创建规格名称") + @PreAuthorize("@ss.hasPermission('product:attr-key:create')") + public CommonResult createAttrKey(@Valid @RequestBody AttrKeyCreateReqVO createReqVO) { + return success(attrKeyService.createAttrKey(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新规格名称") + @PreAuthorize("@ss.hasPermission('product:attr-key:update')") + public CommonResult updateAttrKey(@Valid @RequestBody AttrKeyUpdateReqVO updateReqVO) { + attrKeyService.updateAttrKey(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除规格名称") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) + @PreAuthorize("@ss.hasPermission('product:attr-key:delete')") + public CommonResult deleteAttrKey(@RequestParam("id") Integer id) { + attrKeyService.deleteAttrKey(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得规格名称") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) + @PreAuthorize("@ss.hasPermission('product:attr-key:query')") + public CommonResult getAttrKey(@RequestParam("id") Integer id) { + AttrKeyDO attrKey = attrKeyService.getAttrKey(id); + return success(AttrKeyConvert.INSTANCE.convert(attrKey)); + } + + @GetMapping("/list") + @ApiOperation("获得规格名称列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('product:attr-key:query')") + public CommonResult> getAttrKeyList(@RequestParam("ids") Collection ids) { + List list = attrKeyService.getAttrKeyList(ids); + return success(AttrKeyConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得规格名称分页") + @PreAuthorize("@ss.hasPermission('product:attr-key:query')") + public CommonResult> getAttrKeyPage(@Valid AttrKeyPageReqVO pageVO) { + PageResult pageResult = attrKeyService.getAttrKeyPage(pageVO); + return success(AttrKeyConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出规格名称 Excel") + @PreAuthorize("@ss.hasPermission('product:attr-key:export')") + @OperateLog(type = EXPORT) + public void exportAttrKeyExcel(@Valid AttrKeyExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = attrKeyService.getAttrKeyList(exportReqVO); + // 导出 Excel + List datas = AttrKeyConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "规格名称.xls", "数据", AttrKeyExcelVO.class, datas); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyBaseVO.java new file mode 100755 index 0000000000..13a939e7a2 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyBaseVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +/** +* 规格名称 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class AttrKeyBaseVO { + + @ApiModelProperty(value = "规格名称") + private String attrName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyCreateReqVO.java new file mode 100755 index 0000000000..bd79af8b72 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 规格名称创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrKeyCreateReqVO extends AttrKeyBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExcelVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExcelVO.java new file mode 100755 index 0000000000..b275459671 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExcelVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 规格名称 Excel VO + * + * @author 芋道源码 + */ +@Data +public class AttrKeyExcelVO { + + @ExcelProperty("主键") + private Integer id; + + @ExcelProperty("创建时间") + private Date createTime; + + @ExcelProperty("规格名称") + private String attrName; + + @ExcelProperty("状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExportReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExportReqVO.java new file mode 100755 index 0000000000..aa33e0977e --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyExportReqVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 规格名称 Excel 导出 Request VO", description = "参数和 AttrKeyPageReqVO 是一致的") +@Data +public class AttrKeyExportReqVO { + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + + @ApiModelProperty(value = "规格名称") + private String attrName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyPageReqVO.java new file mode 100755 index 0000000000..3045d3e655 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyPageReqVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 规格名称分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrKeyPageReqVO extends PageParam { + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + + @ApiModelProperty(value = "规格名称") + private String attrName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyRespVO.java new file mode 100755 index 0000000000..0e6ce07a83 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 规格名称 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrKeyRespVO extends AttrKeyBaseVO { + + @ApiModelProperty(value = "主键", required = true) + private Integer id; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyUpdateReqVO.java new file mode 100755 index 0000000000..b1b9f70b7b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrkey/vo/AttrKeyUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrkey.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 规格名称更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrKeyUpdateReqVO extends AttrKeyBaseVO { + + @ApiModelProperty(value = "主键", required = true) + @NotNull(message = "主键不能为空") + private Integer id; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/AttrValueController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/AttrValueController.java new file mode 100755 index 0000000000..d495964027 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/AttrValueController.java @@ -0,0 +1,100 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue; + +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.annotations.*; + +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.product.controller.admin.attrvalue.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrvalue.AttrValueDO; +import cn.iocoder.yudao.module.product.convert.attrvalue.AttrValueConvert; +import cn.iocoder.yudao.module.product.service.attrvalue.AttrValueService; + +@Api(tags = "管理后台 - 规格值") +@RestController +@RequestMapping("/product/attr-value") +@Validated +public class AttrValueController { + + @Resource + private AttrValueService attrValueService; + + @PostMapping("/create") + @ApiOperation("创建规格值") + @PreAuthorize("@ss.hasPermission('product:attr-value:create')") + public CommonResult createAttrValue(@Valid @RequestBody AttrValueCreateReqVO createReqVO) { + return success(attrValueService.createAttrValue(createReqVO)); + } + + @PutMapping("/update") + @ApiOperation("更新规格值") + @PreAuthorize("@ss.hasPermission('product:attr-value:update')") + public CommonResult updateAttrValue(@Valid @RequestBody AttrValueUpdateReqVO updateReqVO) { + attrValueService.updateAttrValue(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @ApiOperation("删除规格值") + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class) + @PreAuthorize("@ss.hasPermission('product:attr-value:delete')") + public CommonResult deleteAttrValue(@RequestParam("id") Integer id) { + attrValueService.deleteAttrValue(id); + return success(true); + } + + @GetMapping("/get") + @ApiOperation("获得规格值") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class) + @PreAuthorize("@ss.hasPermission('product:attr-value:query')") + public CommonResult getAttrValue(@RequestParam("id") Integer id) { + AttrValueDO attrValue = attrValueService.getAttrValue(id); + return success(AttrValueConvert.INSTANCE.convert(attrValue)); + } + + @GetMapping("/list") + @ApiOperation("获得规格值列表") + @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) + @PreAuthorize("@ss.hasPermission('product:attr-value:query')") + public CommonResult> getAttrValueList(@RequestParam("ids") Collection ids) { + List list = attrValueService.getAttrValueList(ids); + return success(AttrValueConvert.INSTANCE.convertList(list)); + } + + @GetMapping("/page") + @ApiOperation("获得规格值分页") + @PreAuthorize("@ss.hasPermission('product:attr-value:query')") + public CommonResult> getAttrValuePage(@Valid AttrValuePageReqVO pageVO) { + PageResult pageResult = attrValueService.getAttrValuePage(pageVO); + return success(AttrValueConvert.INSTANCE.convertPage(pageResult)); + } + + @GetMapping("/export-excel") + @ApiOperation("导出规格值 Excel") + @PreAuthorize("@ss.hasPermission('product:attr-value:export')") + @OperateLog(type = EXPORT) + public void exportAttrValueExcel(@Valid AttrValueExportReqVO exportReqVO, + HttpServletResponse response) throws IOException { + List list = attrValueService.getAttrValueList(exportReqVO); + // 导出 Excel + List datas = AttrValueConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "规格值.xls", "数据", AttrValueExcelVO.class, datas); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueBaseVO.java new file mode 100755 index 0000000000..213536d5d8 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueBaseVO.java @@ -0,0 +1,24 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +/** +* 规格值 Base VO,提供给添加、修改、详细的子 VO 使用 +* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 +*/ +@Data +public class AttrValueBaseVO { + + @ApiModelProperty(value = "规格键id") + private String attrKeyId; + + @ApiModelProperty(value = "规格值名字") + private String attrValueName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueCreateReqVO.java new file mode 100755 index 0000000000..f1fde199c4 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueCreateReqVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 规格值创建 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrValueCreateReqVO extends AttrValueBaseVO { + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExcelVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExcelVO.java new file mode 100755 index 0000000000..ba8deb0808 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExcelVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * 规格值 Excel VO + * + * @author 芋道源码 + */ +@Data +public class AttrValueExcelVO { + + @ExcelProperty("主键") + private Integer id; + + @ExcelProperty("创建时间") + private Date createTime; + + @ExcelProperty("规格键id") + private String attrKeyId; + + @ExcelProperty("规格值名字") + private String attrValueName; + + @ExcelProperty("状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExportReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExportReqVO.java new file mode 100755 index 0000000000..0036dd2c20 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueExportReqVO.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel(value = "管理后台 - 规格值 Excel 导出 Request VO", description = "参数和 AttrValuePageReqVO 是一致的") +@Data +public class AttrValueExportReqVO { + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + + @ApiModelProperty(value = "规格键id") + private String attrKeyId; + + @ApiModelProperty(value = "规格值名字") + private String attrValueName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValuePageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValuePageReqVO.java new file mode 100755 index 0000000000..e9e534242b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValuePageReqVO.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("管理后台 - 规格值分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrValuePageReqVO extends PageParam { + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "开始创建时间") + private Date beginCreateTime; + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @ApiModelProperty(value = "结束创建时间") + private Date endCreateTime; + + @ApiModelProperty(value = "规格键id") + private String attrKeyId; + + @ApiModelProperty(value = "规格值名字") + private String attrValueName; + + @ApiModelProperty(value = "状态: 1 开启 ,2 禁用") + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueRespVO.java new file mode 100755 index 0000000000..630a14e1c8 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; + +@ApiModel("管理后台 - 规格值 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrValueRespVO extends AttrValueBaseVO { + + @ApiModelProperty(value = "主键", required = true) + private Integer id; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueUpdateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueUpdateReqVO.java new file mode 100755 index 0000000000..52d8d4d9dc --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/attrvalue/vo/AttrValueUpdateReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo; + +import lombok.*; +import java.util.*; +import io.swagger.annotations.*; +import javax.validation.constraints.*; + +@ApiModel("管理后台 - 规格值更新 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AttrValueUpdateReqVO extends AttrValueBaseVO { + + @ApiModelProperty(value = "主键", required = true) + @NotNull(message = "主键不能为空") + private Integer id; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrkey/AttrKeyConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrkey/AttrKeyConvert.java new file mode 100755 index 0000000000..28d87d1380 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrkey/AttrKeyConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.product.convert.attrkey; + +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.product.controller.admin.attrkey.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrkey.AttrKeyDO; + +/** + * 规格名称 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface AttrKeyConvert { + + AttrKeyConvert INSTANCE = Mappers.getMapper(AttrKeyConvert.class); + + AttrKeyDO convert(AttrKeyCreateReqVO bean); + + AttrKeyDO convert(AttrKeyUpdateReqVO bean); + + AttrKeyRespVO convert(AttrKeyDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrvalue/AttrValueConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrvalue/AttrValueConvert.java new file mode 100755 index 0000000000..0414546d4b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/attrvalue/AttrValueConvert.java @@ -0,0 +1,34 @@ +package cn.iocoder.yudao.module.product.convert.attrvalue; + +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.product.controller.admin.attrvalue.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrvalue.AttrValueDO; + +/** + * 规格值 Convert + * + * @author 芋道源码 + */ +@Mapper +public interface AttrValueConvert { + + AttrValueConvert INSTANCE = Mappers.getMapper(AttrValueConvert.class); + + AttrValueDO convert(AttrValueCreateReqVO bean); + + AttrValueDO convert(AttrValueUpdateReqVO bean); + + AttrValueRespVO convert(AttrValueDO bean); + + List convertList(List list); + + PageResult convertPage(PageResult page); + + List convertList02(List list); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrkey/AttrKeyDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrkey/AttrKeyDO.java new file mode 100755 index 0000000000..d4e6416885 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrkey/AttrKeyDO.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.product.dal.dataobject.attrkey; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 规格名称 DO + * + * @author 芋道源码 + */ +@TableName("product_attr_key") +@KeySequence("product_attr_key_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AttrKeyDO extends BaseDO { + + /** + * 主键 + */ + @TableId + private Integer id; + /** + * 规格名称 + */ + private String attrName; + /** + * 状态: 1 开启 ,2 禁用 + */ + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrvalue/AttrValueDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrvalue/AttrValueDO.java new file mode 100755 index 0000000000..10db084088 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/attrvalue/AttrValueDO.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.product.dal.dataobject.attrvalue; + +import lombok.*; +import java.util.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 规格值 DO + * + * @author 芋道源码 + */ +@TableName("product_attr_value") +@KeySequence("product_attr_value_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AttrValueDO extends BaseDO { + + /** + * 主键 + */ + @TableId + private Integer id; + /** + * 规格键id + */ + private String attrKeyId; + /** + * 规格值名字 + */ + private String attrValueName; + /** + * 状态: 1 开启 ,2 禁用 + */ + private Integer status; + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrkey/AttrKeyMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrkey/AttrKeyMapper.java new file mode 100755 index 0000000000..7df806d4b7 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrkey/AttrKeyMapper.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.module.product.dal.mysql.attrkey; + +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.product.dal.dataobject.attrkey.AttrKeyDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.product.controller.admin.attrkey.vo.*; + +/** + * 规格名称 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface AttrKeyMapper extends BaseMapperX { + + default PageResult selectPage(AttrKeyPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .betweenIfPresent(AttrKeyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .likeIfPresent(AttrKeyDO::getAttrName, reqVO.getAttrName()) + .eqIfPresent(AttrKeyDO::getStatus, reqVO.getStatus()) + .orderByDesc(AttrKeyDO::getId)); + } + + default List selectList(AttrKeyExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .betweenIfPresent(AttrKeyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .likeIfPresent(AttrKeyDO::getAttrName, reqVO.getAttrName()) + .eqIfPresent(AttrKeyDO::getStatus, reqVO.getStatus()) + .orderByDesc(AttrKeyDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrvalue/AttrValueMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrvalue/AttrValueMapper.java new file mode 100755 index 0000000000..d29f470697 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/attrvalue/AttrValueMapper.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.product.dal.mysql.attrvalue; + +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.product.dal.dataobject.attrvalue.AttrValueDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo.*; + +/** + * 规格值 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface AttrValueMapper extends BaseMapperX { + + default PageResult selectPage(AttrValuePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .betweenIfPresent(AttrValueDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .eqIfPresent(AttrValueDO::getAttrKeyId, reqVO.getAttrKeyId()) + .likeIfPresent(AttrValueDO::getAttrValueName, reqVO.getAttrValueName()) + .eqIfPresent(AttrValueDO::getStatus, reqVO.getStatus()) + .orderByDesc(AttrValueDO::getId)); + } + + default List selectList(AttrValueExportReqVO reqVO) { + return selectList(new LambdaQueryWrapperX() + .betweenIfPresent(AttrValueDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) + .eqIfPresent(AttrValueDO::getAttrKeyId, reqVO.getAttrKeyId()) + .likeIfPresent(AttrValueDO::getAttrValueName, reqVO.getAttrValueName()) + .eqIfPresent(AttrValueDO::getStatus, reqVO.getStatus()) + .orderByDesc(AttrValueDO::getId)); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyService.java new file mode 100755 index 0000000000..09fe3c9f57 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.product.service.attrkey; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.product.controller.admin.attrkey.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrkey.AttrKeyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 规格名称 Service 接口 + * + * @author 芋道源码 + */ +public interface AttrKeyService { + + /** + * 创建规格名称 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createAttrKey(@Valid AttrKeyCreateReqVO createReqVO); + + /** + * 更新规格名称 + * + * @param updateReqVO 更新信息 + */ + void updateAttrKey(@Valid AttrKeyUpdateReqVO updateReqVO); + + /** + * 删除规格名称 + * + * @param id 编号 + */ + void deleteAttrKey(Integer id); + + /** + * 获得规格名称 + * + * @param id 编号 + * @return 规格名称 + */ + AttrKeyDO getAttrKey(Integer id); + + /** + * 获得规格名称列表 + * + * @param ids 编号 + * @return 规格名称列表 + */ + List getAttrKeyList(Collection ids); + + /** + * 获得规格名称分页 + * + * @param pageReqVO 分页查询 + * @return 规格名称分页 + */ + PageResult getAttrKeyPage(AttrKeyPageReqVO pageReqVO); + + /** + * 获得规格名称列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 规格名称列表 + */ + List getAttrKeyList(AttrKeyExportReqVO exportReqVO); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImpl.java new file mode 100755 index 0000000000..cae54d8367 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.product.service.attrkey; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.product.controller.admin.attrkey.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrkey.AttrKeyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.product.convert.attrkey.AttrKeyConvert; +import cn.iocoder.yudao.module.product.dal.mysql.attrkey.AttrKeyMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; + +/** + * 规格名称 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class AttrKeyServiceImpl implements AttrKeyService { + + @Resource + private AttrKeyMapper attrKeyMapper; + + @Override + public Integer createAttrKey(AttrKeyCreateReqVO createReqVO) { + // 插入 + AttrKeyDO attrKey = AttrKeyConvert.INSTANCE.convert(createReqVO); + attrKeyMapper.insert(attrKey); + // 返回 + return attrKey.getId(); + } + + @Override + public void updateAttrKey(AttrKeyUpdateReqVO updateReqVO) { + // 校验存在 + this.validateAttrKeyExists(updateReqVO.getId()); + // 更新 + AttrKeyDO updateObj = AttrKeyConvert.INSTANCE.convert(updateReqVO); + attrKeyMapper.updateById(updateObj); + } + + @Override + public void deleteAttrKey(Integer id) { + // 校验存在 + this.validateAttrKeyExists(id); + // 删除 + attrKeyMapper.deleteById(id); + } + + private void validateAttrKeyExists(Integer id) { + if (attrKeyMapper.selectById(id) == null) { + throw exception(ATTR_KEY_NOT_EXISTS); + } + } + + @Override + public AttrKeyDO getAttrKey(Integer id) { + return attrKeyMapper.selectById(id); + } + + @Override + public List getAttrKeyList(Collection ids) { + return attrKeyMapper.selectBatchIds(ids); + } + + @Override + public PageResult getAttrKeyPage(AttrKeyPageReqVO pageReqVO) { + return attrKeyMapper.selectPage(pageReqVO); + } + + @Override + public List getAttrKeyList(AttrKeyExportReqVO exportReqVO) { + return attrKeyMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueService.java new file mode 100755 index 0000000000..cf5f52b911 --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueService.java @@ -0,0 +1,70 @@ +package cn.iocoder.yudao.module.product.service.attrvalue; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrvalue.AttrValueDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +/** + * 规格值 Service 接口 + * + * @author 芋道源码 + */ +public interface AttrValueService { + + /** + * 创建规格值 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createAttrValue(@Valid AttrValueCreateReqVO createReqVO); + + /** + * 更新规格值 + * + * @param updateReqVO 更新信息 + */ + void updateAttrValue(@Valid AttrValueUpdateReqVO updateReqVO); + + /** + * 删除规格值 + * + * @param id 编号 + */ + void deleteAttrValue(Integer id); + + /** + * 获得规格值 + * + * @param id 编号 + * @return 规格值 + */ + AttrValueDO getAttrValue(Integer id); + + /** + * 获得规格值列表 + * + * @param ids 编号 + * @return 规格值列表 + */ + List getAttrValueList(Collection ids); + + /** + * 获得规格值分页 + * + * @param pageReqVO 分页查询 + * @return 规格值分页 + */ + PageResult getAttrValuePage(AttrValuePageReqVO pageReqVO); + + /** + * 获得规格值列表, 用于 Excel 导出 + * + * @param exportReqVO 查询条件 + * @return 规格值列表 + */ + List getAttrValueList(AttrValueExportReqVO exportReqVO); + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueServiceImpl.java new file mode 100755 index 0000000000..197dcbe19b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/attrvalue/AttrValueServiceImpl.java @@ -0,0 +1,82 @@ +package cn.iocoder.yudao.module.product.service.attrvalue; + +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.util.*; +import cn.iocoder.yudao.module.product.controller.admin.attrvalue.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrvalue.AttrValueDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import cn.iocoder.yudao.module.product.convert.attrvalue.AttrValueConvert; +import cn.iocoder.yudao.module.product.dal.mysql.attrvalue.AttrValueMapper; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; + +/** + * 规格值 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class AttrValueServiceImpl implements AttrValueService { + + @Resource + private AttrValueMapper attrValueMapper; + + @Override + public Integer createAttrValue(AttrValueCreateReqVO createReqVO) { + // 插入 + AttrValueDO attrValue = AttrValueConvert.INSTANCE.convert(createReqVO); + attrValueMapper.insert(attrValue); + // 返回 + return attrValue.getId(); + } + + @Override + public void updateAttrValue(AttrValueUpdateReqVO updateReqVO) { + // 校验存在 + this.validateAttrValueExists(updateReqVO.getId()); + // 更新 + AttrValueDO updateObj = AttrValueConvert.INSTANCE.convert(updateReqVO); + attrValueMapper.updateById(updateObj); + } + + @Override + public void deleteAttrValue(Integer id) { + // 校验存在 + this.validateAttrValueExists(id); + // 删除 + attrValueMapper.deleteById(id); + } + + private void validateAttrValueExists(Integer id) { + if (attrValueMapper.selectById(id) == null) { + throw exception(ATTR_VALUE_NOT_EXISTS); + } + } + + @Override + public AttrValueDO getAttrValue(Integer id) { + return attrValueMapper.selectById(id); + } + + @Override + public List getAttrValueList(Collection ids) { + return attrValueMapper.selectBatchIds(ids); + } + + @Override + public PageResult getAttrValuePage(AttrValuePageReqVO pageReqVO) { + return attrValueMapper.selectPage(pageReqVO); + } + + @Override + public List getAttrValueList(AttrValueExportReqVO exportReqVO) { + return attrValueMapper.selectList(exportReqVO); + } + +} diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImplTest.java new file mode 100755 index 0000000000..c32cc7462b --- /dev/null +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/attrkey/AttrKeyServiceImplTest.java @@ -0,0 +1,168 @@ +package cn.iocoder.yudao.module.product.service.attrkey; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.mock.mockito.MockBean; + +import javax.annotation.Resource; + +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; + +import cn.iocoder.yudao.module.product.controller.admin.attrkey.vo.*; +import cn.iocoder.yudao.module.product.dal.dataobject.attrkey.AttrKeyDO; +import cn.iocoder.yudao.module.product.dal.mysql.attrkey.AttrKeyMapper; +import cn.iocoder.yudao.framework.common.pojo.PageResult; + +import javax.annotation.Resource; +import org.springframework.context.annotation.Import; +import java.util.*; + +import static cn.hutool.core.util.RandomUtil.*; +import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** +* {@link AttrKeyServiceImpl} 的单元测试类 +* +* @author 芋道源码 +*/ +@Import(AttrKeyServiceImpl.class) +public class AttrKeyServiceImplTest extends BaseDbUnitTest { + + @Resource + private AttrKeyServiceImpl attrKeyService; + + @Resource + private AttrKeyMapper attrKeyMapper; + + @Test + public void testCreateAttrKey_success() { + // 准备参数 + AttrKeyCreateReqVO reqVO = randomPojo(AttrKeyCreateReqVO.class); + + // 调用 + Integer attrKeyId = attrKeyService.createAttrKey(reqVO); + // 断言 + assertNotNull(attrKeyId); + // 校验记录的属性是否正确 + AttrKeyDO attrKey = attrKeyMapper.selectById(attrKeyId); + assertPojoEquals(reqVO, attrKey); + } + + @Test + public void testUpdateAttrKey_success() { + // mock 数据 + AttrKeyDO dbAttrKey = randomPojo(AttrKeyDO.class); + attrKeyMapper.insert(dbAttrKey);// @Sql: 先插入出一条存在的数据 + // 准备参数 + AttrKeyUpdateReqVO reqVO = randomPojo(AttrKeyUpdateReqVO.class, o -> { + o.setId(dbAttrKey.getId()); // 设置更新的 ID + }); + + // 调用 + attrKeyService.updateAttrKey(reqVO); + // 校验是否更新正确 + AttrKeyDO attrKey = attrKeyMapper.selectById(reqVO.getId()); // 获取最新的 + assertPojoEquals(reqVO, attrKey); + } + + @Test + public void testUpdateAttrKey_notExists() { + // 准备参数 + AttrKeyUpdateReqVO reqVO = randomPojo(AttrKeyUpdateReqVO.class); + + // 调用, 并断言异常 + assertServiceException(() -> attrKeyService.updateAttrKey(reqVO), ATTR_KEY_NOT_EXISTS); + } + + @Test + public void testDeleteAttrKey_success() { + // mock 数据 + AttrKeyDO dbAttrKey = randomPojo(AttrKeyDO.class); + attrKeyMapper.insert(dbAttrKey);// @Sql: 先插入出一条存在的数据 + // 准备参数 + Integer id = dbAttrKey.getId(); + + // 调用 + attrKeyService.deleteAttrKey(id); + // 校验数据不存在了 + assertNull(attrKeyMapper.selectById(id)); + } + + @Test + public void testDeleteAttrKey_notExists() { + // 准备参数 +// Integer id = randomIntegerId(); + Integer id = 1; + + // 调用, 并断言异常 + assertServiceException(() -> attrKeyService.deleteAttrKey(id), ATTR_KEY_NOT_EXISTS); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetAttrKeyPage() { + // mock 数据 + AttrKeyDO dbAttrKey = randomPojo(AttrKeyDO.class, o -> { // 等会查询到 + o.setCreateTime(null); + o.setAttrName(null); + o.setStatus(null); + }); + attrKeyMapper.insert(dbAttrKey); + // 测试 createTime 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setCreateTime(null))); + // 测试 attrName 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setAttrName(null))); + // 测试 status 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setStatus(null))); + // 准备参数 + AttrKeyPageReqVO reqVO = new AttrKeyPageReqVO(); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + reqVO.setAttrName(null); + reqVO.setStatus(null); + + // 调用 + PageResult pageResult = attrKeyService.getAttrKeyPage(reqVO); + // 断言 + assertEquals(1, pageResult.getTotal()); + assertEquals(1, pageResult.getList().size()); + assertPojoEquals(dbAttrKey, pageResult.getList().get(0)); + } + + @Test + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 + public void testGetAttrKeyList() { + // mock 数据 + AttrKeyDO dbAttrKey = randomPojo(AttrKeyDO.class, o -> { // 等会查询到 + o.setCreateTime(null); + o.setAttrName(null); + o.setStatus(null); + }); + attrKeyMapper.insert(dbAttrKey); + // 测试 createTime 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setCreateTime(null))); + // 测试 attrName 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setAttrName(null))); + // 测试 status 不匹配 + attrKeyMapper.insert(cloneIgnoreId(dbAttrKey, o -> o.setStatus(null))); + // 准备参数 + AttrKeyExportReqVO reqVO = new AttrKeyExportReqVO(); + reqVO.setBeginCreateTime(null); + reqVO.setEndCreateTime(null); + reqVO.setAttrName(null); + reqVO.setStatus(null); + + // 调用 + List list = attrKeyService.getAttrKeyList(reqVO); + // 断言 + assertEquals(1, list.size()); + assertPojoEquals(dbAttrKey, list.get(0)); + } + +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/UserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/UserController.java index 358f966e7d..795c8162c8 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/UserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/UserController.java @@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti */ @Slf4j @Api("用户管理") -@RestController +@RestController(value = "memberUserController") @RequestMapping("/user") public class UserController {