完成了基本的商品管理

This commit is contained in:
chen-xin-zhi 2024-10-29 19:28:32 +08:00
parent 6439c3eb0b
commit 9c250566cf
13 changed files with 148 additions and 2 deletions

View File

@ -0,0 +1,16 @@
package com.cultural.heritage.controller.operategood;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/category")
@Slf4j
@Tag(name = "商品类别接口")
public class CategoryController {
}

View File

@ -3,11 +3,14 @@ package com.cultural.heritage.controller.operategood;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.common.ResultUtils;
import com.cultural.heritage.constant.UserConstant;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.dto.CommonDelBatchRequest;
import com.cultural.heritage.model.dto.CommonRequest;
import com.cultural.heritage.model.dto.good.GoodAddRequest;
import com.cultural.heritage.model.dto.good.GoodQueryRequest;
@ -23,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 商品接口
@ -112,9 +117,22 @@ public class GoodController {
}
// @PostMapping("/delBatch")
/**
* 批量删除商品
* @param commonDelBatchRequest 批量删除请求体
* @return 是否批量删除成功
*/
@PostMapping("/delBatch")
// @AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
// public BaseResponse<Boolean> delBatchGoods(List<Integer> )
public BaseResponse<Boolean> delBatchGoods(@RequestBody CommonDelBatchRequest commonDelBatchRequest) {
List<Integer> idList = commonDelBatchRequest.getIdList();
boolean result = goodService.removeBatchByIds(idList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
}

View File

@ -0,0 +1,8 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.Category;
public interface CategoryMapper extends BaseMapper<Category> {
}

View File

@ -0,0 +1,16 @@
package com.cultural.heritage.model.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class CommonDelBatchRequest implements Serializable {
private List<Integer> idList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -21,6 +21,11 @@ public class GoodAddRequest implements Serializable {
*/
private String type;
/**
* 商品价格
*/
private Double price;
/**
* 商品图片
*/

View File

@ -29,6 +29,11 @@ public class GoodQueryRequest extends PageRequest implements Serializable {
*/
private Integer festivalOrder;
/**
* 是否上架
*/
private Integer isShelves;
@TableField(exist = false)
private static final long serialVersionUID = 1L;

View File

@ -23,6 +23,11 @@ public class GoodUpdateRequest implements Serializable {
*/
private String type;
/**
* 商品价格
*/
private Double price;
/**
* 商品图片
*/

View File

@ -0,0 +1,39 @@
package com.cultural.heritage.model.entity;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class Category implements Serializable {
/**
* id
*/
private Integer id;
/**
* 类别名称
*/
private String typeName;
/**
* 类别图片
*/
private String typeUrl;
/**
* 类别介绍
*/
private String typeInfo;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -27,6 +27,11 @@ public class Good {
*/
private String type;
/**
* 商品价格
*/
private Double price;
/**
* 商品图片
*/

View File

@ -0,0 +1,9 @@
package com.cultural.heritage.service.operategood;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.Category;
public interface CategoryService extends IService<Category> {
}

View File

@ -0,0 +1,11 @@
package com.cultural.heritage.service.operategood.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.mapper.CategoryMapper;
import com.cultural.heritage.model.entity.Category;
import com.cultural.heritage.service.operategood.CategoryService;
import org.springframework.stereotype.Service;
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
}

View File

@ -26,6 +26,7 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
String name = goodQueryRequest.getName();
String type = goodQueryRequest.getType();
Integer festivalOrder = goodQueryRequest.getFestivalOrder();
Integer isShelves = goodQueryRequest.getIsShelves();
String sortField = goodQueryRequest.getSortField();
String sortOrder = goodQueryRequest.getSortOrder();
@ -34,6 +35,7 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
queryWrapper.eq(StringUtils.isNotBlank(name), "name", name);
queryWrapper.eq(StringUtils.isNotBlank(type), "type", type);
queryWrapper.eq(festivalOrder != null, "festivalOrder", festivalOrder);
queryWrapper.eq(isShelves != null, "isShelves", isShelves);
queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
sortField);
return queryWrapper;

View File

@ -0,0 +1,7 @@
<?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="com.cultural.heritage.mapper.CategoryMapper">
</mapper>