商品规格属性代码生成

This commit is contained in:
franky 2022-05-15 22:55:18 +08:00
parent 0d017e4b1c
commit 9f9004624b
29 changed files with 1233 additions and 1 deletions

View File

@ -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, "规格值不存在");
}

View File

@ -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<Integer> createAttrKey(@Valid @RequestBody AttrKeyCreateReqVO createReqVO) {
return success(attrKeyService.createAttrKey(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新规格名称")
@PreAuthorize("@ss.hasPermission('product:attr-key:update')")
public CommonResult<Boolean> 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<Boolean> 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<AttrKeyRespVO> 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<List<AttrKeyRespVO>> getAttrKeyList(@RequestParam("ids") Collection<Integer> ids) {
List<AttrKeyDO> list = attrKeyService.getAttrKeyList(ids);
return success(AttrKeyConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得规格名称分页")
@PreAuthorize("@ss.hasPermission('product:attr-key:query')")
public CommonResult<PageResult<AttrKeyRespVO>> getAttrKeyPage(@Valid AttrKeyPageReqVO pageVO) {
PageResult<AttrKeyDO> 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<AttrKeyDO> list = attrKeyService.getAttrKeyList(exportReqVO);
// 导出 Excel
List<AttrKeyExcelVO> datas = AttrKeyConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "规格名称.xls", "数据", AttrKeyExcelVO.class, datas);
}
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Integer> createAttrValue(@Valid @RequestBody AttrValueCreateReqVO createReqVO) {
return success(attrValueService.createAttrValue(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新规格值")
@PreAuthorize("@ss.hasPermission('product:attr-value:update')")
public CommonResult<Boolean> 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<Boolean> 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<AttrValueRespVO> 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<List<AttrValueRespVO>> getAttrValueList(@RequestParam("ids") Collection<Integer> ids) {
List<AttrValueDO> list = attrValueService.getAttrValueList(ids);
return success(AttrValueConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得规格值分页")
@PreAuthorize("@ss.hasPermission('product:attr-value:query')")
public CommonResult<PageResult<AttrValueRespVO>> getAttrValuePage(@Valid AttrValuePageReqVO pageVO) {
PageResult<AttrValueDO> 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<AttrValueDO> list = attrValueService.getAttrValueList(exportReqVO);
// 导出 Excel
List<AttrValueExcelVO> datas = AttrValueConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "规格值.xls", "数据", AttrValueExcelVO.class, datas);
}
}

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<AttrKeyRespVO> convertList(List<AttrKeyDO> list);
PageResult<AttrKeyRespVO> convertPage(PageResult<AttrKeyDO> page);
List<AttrKeyExcelVO> convertList02(List<AttrKeyDO> list);
}

View File

@ -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<AttrValueRespVO> convertList(List<AttrValueDO> list);
PageResult<AttrValueRespVO> convertPage(PageResult<AttrValueDO> page);
List<AttrValueExcelVO> convertList02(List<AttrValueDO> list);
}

View File

@ -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") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 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;
}

View File

@ -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") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 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;
}

View File

@ -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<AttrKeyDO> {
default PageResult<AttrKeyDO> selectPage(AttrKeyPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AttrKeyDO>()
.betweenIfPresent(AttrKeyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.likeIfPresent(AttrKeyDO::getAttrName, reqVO.getAttrName())
.eqIfPresent(AttrKeyDO::getStatus, reqVO.getStatus())
.orderByDesc(AttrKeyDO::getId));
}
default List<AttrKeyDO> selectList(AttrKeyExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<AttrKeyDO>()
.betweenIfPresent(AttrKeyDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.likeIfPresent(AttrKeyDO::getAttrName, reqVO.getAttrName())
.eqIfPresent(AttrKeyDO::getStatus, reqVO.getStatus())
.orderByDesc(AttrKeyDO::getId));
}
}

View File

@ -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<AttrValueDO> {
default PageResult<AttrValueDO> selectPage(AttrValuePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<AttrValueDO>()
.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<AttrValueDO> selectList(AttrValueExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<AttrValueDO>()
.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));
}
}

View File

@ -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<AttrKeyDO> getAttrKeyList(Collection<Integer> ids);
/**
* 获得规格名称分页
*
* @param pageReqVO 分页查询
* @return 规格名称分页
*/
PageResult<AttrKeyDO> getAttrKeyPage(AttrKeyPageReqVO pageReqVO);
/**
* 获得规格名称列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 规格名称列表
*/
List<AttrKeyDO> getAttrKeyList(AttrKeyExportReqVO exportReqVO);
}

View File

@ -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<AttrKeyDO> getAttrKeyList(Collection<Integer> ids) {
return attrKeyMapper.selectBatchIds(ids);
}
@Override
public PageResult<AttrKeyDO> getAttrKeyPage(AttrKeyPageReqVO pageReqVO) {
return attrKeyMapper.selectPage(pageReqVO);
}
@Override
public List<AttrKeyDO> getAttrKeyList(AttrKeyExportReqVO exportReqVO) {
return attrKeyMapper.selectList(exportReqVO);
}
}

View File

@ -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<AttrValueDO> getAttrValueList(Collection<Integer> ids);
/**
* 获得规格值分页
*
* @param pageReqVO 分页查询
* @return 规格值分页
*/
PageResult<AttrValueDO> getAttrValuePage(AttrValuePageReqVO pageReqVO);
/**
* 获得规格值列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 规格值列表
*/
List<AttrValueDO> getAttrValueList(AttrValueExportReqVO exportReqVO);
}

View File

@ -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<AttrValueDO> getAttrValueList(Collection<Integer> ids) {
return attrValueMapper.selectBatchIds(ids);
}
@Override
public PageResult<AttrValueDO> getAttrValuePage(AttrValuePageReqVO pageReqVO) {
return attrValueMapper.selectPage(pageReqVO);
}
@Override
public List<AttrValueDO> getAttrValueList(AttrValueExportReqVO exportReqVO) {
return attrValueMapper.selectList(exportReqVO);
}
}

View File

@ -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<AttrKeyDO> 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<AttrKeyDO> list = attrKeyService.getAttrKeyList(reqVO);
// 断言
assertEquals(1, list.size());
assertPojoEquals(dbAttrKey, list.get(0));
}
}

View File

@ -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 {