完成管理后台分类 商品 规格 运费模板 素材等功能

This commit is contained in:
hupeng
2023-06-09 11:04:20 +08:00
parent 6ff21a3799
commit 31fc0da4b5
97 changed files with 4511 additions and 70 deletions

View File

@ -1,106 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule;
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 co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.pojo.CommonResult;
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
import co.yixiang.yshop.framework.operatelog.core.annotations.OperateLog;
import static co.yixiang.yshop.framework.operatelog.core.enums.OperateTypeEnum.*;
import co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo.*;
import co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule.StoreProductRuleDO;
import co.yixiang.yshop.module.shop.convert.storeproductrule.StoreProductRuleConvert;
import co.yixiang.yshop.module.shop.service.storeproductrule.StoreProductRuleService;
@Tag(name = "管理后台 - 商品规则值(规格)")
@RestController
@RequestMapping("/shop/store-product-rule")
@Validated
public class StoreProductRuleController {
@Resource
private StoreProductRuleService storeProductRuleService;
@PostMapping("/save/{id}")
@Operation(summary = "创建与更新商品规则值(规格)")
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:create')")
public CommonResult<Integer> createStoreProductRule(@Valid @RequestBody StoreProductRuleCreateReqVO createReqVO,@PathVariable Integer id) {
if(id != null && id > 0){
StoreProductRuleUpdateReqVO updateReqVO = new StoreProductRuleUpdateReqVO();
updateReqVO.setId(id);
updateReqVO.setRuleName(createReqVO.getRuleName());
updateReqVO.setRuleValue(createReqVO.getRuleValue());
storeProductRuleService.updateStoreProductRule(updateReqVO);
return success(1);
}else{
return success(storeProductRuleService.createStoreProductRule(createReqVO));
}
}
@DeleteMapping("/delete")
@Operation(summary = "删除商品规则值(规格)")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:delete')")
public CommonResult<Boolean> deleteStoreProductRule(@RequestParam("id") Integer id) {
storeProductRuleService.deleteStoreProductRule(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得商品规则值(规格)")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:query')")
public CommonResult<StoreProductRuleRespVO> getStoreProductRule(@RequestParam("id") Integer id) {
StoreProductRuleDO storeProductRule = storeProductRuleService.getStoreProductRule(id);
return success(StoreProductRuleConvert.INSTANCE.convert(storeProductRule));
}
@GetMapping("/list")
@Operation(summary = "获得商品规则值(规格)列表")
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:query')")
public CommonResult<List<StoreProductRuleRespVO>> getStoreProductRuleList(@RequestParam("ids") Collection<Integer> ids) {
List<StoreProductRuleDO> list = storeProductRuleService.getStoreProductRuleList(ids);
return success(StoreProductRuleConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@Operation(summary = "获得商品规则值(规格)分页")
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:query')")
public CommonResult<PageResult<StoreProductRuleRespVO>> getStoreProductRulePage(@Valid StoreProductRulePageReqVO pageVO) {
PageResult<StoreProductRuleDO> pageResult = storeProductRuleService.getStoreProductRulePage(pageVO);
System.out.println("aa:"+pageResult);
return success(StoreProductRuleConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出商品规则值(规格) Excel")
@PreAuthorize("@ss.hasPermission('shop:store-product-rule:export')")
@OperateLog(type = EXPORT)
public void exportStoreProductRuleExcel(@Valid StoreProductRuleExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<StoreProductRuleDO> list = storeProductRuleService.getStoreProductRuleList(exportReqVO);
// 导出 Excel
List<StoreProductRuleExcelVO> datas = StoreProductRuleConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "商品规则值(规格).xls", "数据", StoreProductRuleExcelVO.class, datas);
}
}

View File

@ -1,31 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo;
import com.alibaba.fastjson.JSONArray;
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 StoreProductRuleBaseVO {
@Schema(description = "id", required = false, example = "有值表示是更新没值是添加")
private Integer id;
@Schema(description = "规格名称", required = true, example = "赵六")
@NotNull(message = "规格名称不能为空")
private String ruleName;
@Schema(description = "规格值", required = true)
@NotNull(message = "规格值不能为空")
private JSONArray ruleValue;
}

View File

@ -1,14 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.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 StoreProductRuleCreateReqVO extends StoreProductRuleBaseVO {
}

View File

@ -1,32 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo;
import com.alibaba.fastjson.JSONArray;
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;
/**
* 商品规则值(规格) Excel VO
*
* @author yshop
*/
@Data
public class StoreProductRuleExcelVO {
@ExcelProperty("id")
private Integer id;
@ExcelProperty("规格名称")
private String ruleName;
@ExcelProperty("规格值")
private JSONArray ruleValue;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,15 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import co.yixiang.yshop.framework.common.pojo.PageParam;
@Schema(description = "管理后台 - 商品规则值(规格) Excel 导出 Request VO参数和 StoreProductRulePageReqVO 是一致的")
@Data
public class StoreProductRuleExportReqVO {
@Schema(description = "规格名称", example = "赵六")
private String ruleName;
}

View File

@ -1,17 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import co.yixiang.yshop.framework.common.pojo.PageParam;
@Schema(description = "管理后台 - 商品规则值(规格)分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class StoreProductRulePageReqVO extends PageParam {
@Schema(description = "规格名称", example = "赵六")
private String ruleName;
}

View File

@ -1,19 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.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 StoreProductRuleRespVO extends StoreProductRuleBaseVO {
@Schema(description = "id", required = true, example = "2067")
private Integer id;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

View File

@ -1,18 +0,0 @@
package co.yixiang.yshop.module.shop.controller.admin.storeproductrule.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 StoreProductRuleUpdateReqVO extends StoreProductRuleBaseVO {
@Schema(description = "id", required = true, example = "2067")
@NotNull(message = "id不能为空")
private Integer id;
}

View File

@ -1,34 +0,0 @@
package co.yixiang.yshop.module.shop.convert.storeproductrule;
import java.util.*;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo.*;
import co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule.StoreProductRuleDO;
/**
* 商品规则值(规格) Convert
*
* @author yshop
*/
@Mapper
public interface StoreProductRuleConvert {
StoreProductRuleConvert INSTANCE = Mappers.getMapper(StoreProductRuleConvert.class);
StoreProductRuleDO convert(StoreProductRuleCreateReqVO bean);
StoreProductRuleDO convert(StoreProductRuleUpdateReqVO bean);
StoreProductRuleRespVO convert(StoreProductRuleDO bean);
List<StoreProductRuleRespVO> convertList(List<StoreProductRuleDO> list);
PageResult<StoreProductRuleRespVO> convertPage(PageResult<StoreProductRuleDO> page);
List<StoreProductRuleExcelVO> convertList02(List<StoreProductRuleDO> list);
}

View File

@ -1,42 +0,0 @@
package co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import co.yixiang.yshop.framework.mybatis.core.dataobject.BaseDO;
/**
* 商品规则值(规格) DO
*
* @author yshop
*/
@TableName(value = "yshop_store_product_rule",autoResultMap = true)
@KeySequence("yshop_store_product_rule_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StoreProductRuleDO extends BaseDO {
/**
* id
*/
@TableId
private Integer id;
/**
* 规格名称
*/
private String ruleName;
/**
* 规格值
*/
@TableField(typeHandler = FastjsonTypeHandler.class)
private JSONArray ruleValue;
}

View File

@ -1,32 +0,0 @@
package co.yixiang.yshop.module.shop.dal.mysql.storeproductrule;
import java.util.*;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
import co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule.StoreProductRuleDO;
import org.apache.ibatis.annotations.Mapper;
import co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo.*;
/**
* 商品规则值(规格) Mapper
*
* @author yshop
*/
@Mapper
public interface StoreProductRuleMapper extends BaseMapperX<StoreProductRuleDO> {
default PageResult<StoreProductRuleDO> selectPage(StoreProductRulePageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<StoreProductRuleDO>()
.likeIfPresent(StoreProductRuleDO::getRuleName, reqVO.getRuleName())
.orderByDesc(StoreProductRuleDO::getId));
}
default List<StoreProductRuleDO> selectList(StoreProductRuleExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<StoreProductRuleDO>()
.likeIfPresent(StoreProductRuleDO::getRuleName, reqVO.getRuleName())
.orderByDesc(StoreProductRuleDO::getId));
}
}

View File

@ -1,70 +0,0 @@
package co.yixiang.yshop.module.shop.service.storeproductrule;
import java.util.*;
import javax.validation.*;
import co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo.*;
import co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule.StoreProductRuleDO;
import co.yixiang.yshop.framework.common.pojo.PageResult;
/**
* 商品规则值(规格) Service 接口
*
* @author yshop
*/
public interface StoreProductRuleService {
/**
* 创建商品规则值(规格)
*
* @param createReqVO 创建信息
* @return 编号
*/
Integer createStoreProductRule(@Valid StoreProductRuleCreateReqVO createReqVO);
/**
* 更新商品规则值(规格)
*
* @param updateReqVO 更新信息
*/
void updateStoreProductRule(@Valid StoreProductRuleUpdateReqVO updateReqVO);
/**
* 删除商品规则值(规格)
*
* @param id 编号
*/
void deleteStoreProductRule(Integer id);
/**
* 获得商品规则值(规格)
*
* @param id 编号
* @return 商品规则值(规格)
*/
StoreProductRuleDO getStoreProductRule(Integer id);
/**
* 获得商品规则值(规格)列表
*
* @param ids 编号
* @return 商品规则值(规格)列表
*/
List<StoreProductRuleDO> getStoreProductRuleList(Collection<Integer> ids);
/**
* 获得商品规则值(规格)分页
*
* @param pageReqVO 分页查询
* @return 商品规则值(规格)分页
*/
PageResult<StoreProductRuleDO> getStoreProductRulePage(StoreProductRulePageReqVO pageReqVO);
/**
* 获得商品规则值(规格)列表, 用于 Excel 导出
*
* @param exportReqVO 查询条件
* @return 商品规则值(规格)列表
*/
List<StoreProductRuleDO> getStoreProductRuleList(StoreProductRuleExportReqVO exportReqVO);
}

View File

@ -1,82 +0,0 @@
package co.yixiang.yshop.module.shop.service.storeproductrule;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import co.yixiang.yshop.module.shop.controller.admin.storeproductrule.vo.*;
import co.yixiang.yshop.module.shop.dal.dataobject.storeproductrule.StoreProductRuleDO;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.shop.convert.storeproductrule.StoreProductRuleConvert;
import co.yixiang.yshop.module.shop.dal.mysql.storeproductrule.StoreProductRuleMapper;
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
import static co.yixiang.yshop.module.shop.enums.ErrorCodeConstants.*;
/**
* 商品规则值(规格) Service 实现类
*
* @author yshop
*/
@Service
@Validated
public class StoreProductRuleServiceImpl implements StoreProductRuleService {
@Resource
private StoreProductRuleMapper storeProductRuleMapper;
@Override
public Integer createStoreProductRule(StoreProductRuleCreateReqVO createReqVO) {
// 插入
StoreProductRuleDO storeProductRule = StoreProductRuleConvert.INSTANCE.convert(createReqVO);
storeProductRuleMapper.insert(storeProductRule);
// 返回
return storeProductRule.getId();
}
@Override
public void updateStoreProductRule(StoreProductRuleUpdateReqVO updateReqVO) {
// 校验存在
validateStoreProductRuleExists(updateReqVO.getId());
// 更新
StoreProductRuleDO updateObj = StoreProductRuleConvert.INSTANCE.convert(updateReqVO);
storeProductRuleMapper.updateById(updateObj);
}
@Override
public void deleteStoreProductRule(Integer id) {
// 校验存在
validateStoreProductRuleExists(id);
// 删除
storeProductRuleMapper.deleteById(id);
}
private void validateStoreProductRuleExists(Integer id) {
if (storeProductRuleMapper.selectById(id) == null) {
throw exception(STORE_PRODUCT_RULE_NOT_EXISTS);
}
}
@Override
public StoreProductRuleDO getStoreProductRule(Integer id) {
return storeProductRuleMapper.selectById(id);
}
@Override
public List<StoreProductRuleDO> getStoreProductRuleList(Collection<Integer> ids) {
return storeProductRuleMapper.selectBatchIds(ids);
}
@Override
public PageResult<StoreProductRuleDO> getStoreProductRulePage(StoreProductRulePageReqVO pageReqVO) {
return storeProductRuleMapper.selectPage(pageReqVO);
}
@Override
public List<StoreProductRuleDO> getStoreProductRuleList(StoreProductRuleExportReqVO exportReqVO) {
return storeProductRuleMapper.selectList(exportReqVO);
}
}

View File

@ -1,12 +0,0 @@
<?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="co.yixiang.yshop.module.shop.dal.mysql.storeproductrule.StoreProductRuleMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>