feat(新增-商品管理): 添加功能

Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
bunny 2024-03-26 14:56:44 +08:00
parent 3d69821e67
commit a8ba62125f
6 changed files with 58 additions and 0 deletions

View File

@ -22,4 +22,5 @@ public class MessageConstant {
public static final String MENU_IS_NOT_EXIST = "菜单不存在"; public static final String MENU_IS_NOT_EXIST = "菜单不存在";
public static final String SAVE_DTO_IS_NULL = "添加参数不能为空"; public static final String SAVE_DTO_IS_NULL = "添加参数不能为空";
public static final String UPDATE_DTO_IS_NULL = "修改参数不能为空"; public static final String UPDATE_DTO_IS_NULL = "修改参数不能为空";
public static final String FIND_ID_IS_NOT_EMPTY = "查询ID不能为空";
} }

View File

@ -1,9 +1,12 @@
package com.atguigu.spzx.manger.controller; package com.atguigu.spzx.manger.controller;
import com.atguigu.spzx.manger.service.CategoryBrandService;
import com.atguigu.spzx.manger.service.ProductService; import com.atguigu.spzx.manger.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto; import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.Product; import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.vo.result.Result; import com.atguigu.spzx.model.vo.result.Result;
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -13,12 +16,16 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "商品管理") @Tag(name = "商品管理")
@RestController @RestController
@RequestMapping(value = "/admin/product/product") @RequestMapping(value = "/admin/product/product")
public class ProductController { public class ProductController {
@Autowired @Autowired
private ProductService productService; private ProductService productService;
@Autowired
private CategoryBrandService categoryBrandService;
@Operation(summary = "列表查询", description = "列表查询") @Operation(summary = "列表查询", description = "列表查询")
@GetMapping("{page}/{limit}") @GetMapping("{page}/{limit}")
@ -26,4 +33,11 @@ public class ProductController {
PageInfo<Product> pageInfo = productService.findByPage(page, limit, dto); PageInfo<Product> pageInfo = productService.findByPage(page, limit, dto);
return Result.success(pageInfo); return Result.success(pageInfo);
} }
@Operation(summary = "添加功能", description = "添加功能")
@GetMapping("findBrandByCategoryId/{categoryId}")
public Result<List<Brand>> findBrandByCategoryId(@PathVariable Long categoryId) {
List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
return Result.build(brandList, ResultCodeEnum.SUCCESS);
}
} }

View File

@ -1,6 +1,7 @@
package com.atguigu.spzx.manger.mapper; package com.atguigu.spzx.manger.mapper;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto; import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand; import com.atguigu.spzx.model.entity.product.CategoryBrand;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -31,4 +32,12 @@ public interface CategoryBrandMapper {
* @param id 删除的ID * @param id 删除的ID
*/ */
void deleteById(Long id); void deleteById(Long id);
/**
* 添加功能
*
* @param categoryId 查询ID
* @return List<Brand>
*/
List<Brand> findBrandByCategoryId(Long categoryId);
} }

View File

@ -1,9 +1,12 @@
package com.atguigu.spzx.manger.service; package com.atguigu.spzx.manger.service;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto; import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand; import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import java.util.List;
public interface CategoryBrandService { public interface CategoryBrandService {
/** /**
* 分类品牌列表 * 分类品牌列表
@ -35,4 +38,12 @@ public interface CategoryBrandService {
* @param id 删除的ID * @param id 删除的ID
*/ */
void deleteById(Long id); void deleteById(Long id);
/**
* 添加功能
*
* @param categoryId 查询ID
* @return List<Brand>
*/
List<Brand> findBrandByCategoryId(Long categoryId);
} }

View File

@ -5,6 +5,7 @@ import com.atguigu.exception.BunnyException;
import com.atguigu.spzx.manger.mapper.CategoryBrandMapper; import com.atguigu.spzx.manger.mapper.CategoryBrandMapper;
import com.atguigu.spzx.manger.service.CategoryBrandService; import com.atguigu.spzx.manger.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto; import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand; import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.utils.StringEmptyUtil; import com.atguigu.utils.StringEmptyUtil;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
@ -76,4 +77,16 @@ public class CategoryBrandServiceImpl implements CategoryBrandService {
emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY); emptyUtil.isEmpty(id, MessageConstant.DELETE_ID_IS_NOT_EMPTY);
categoryBrandMapper.deleteById(id); categoryBrandMapper.deleteById(id);
} }
/**
* 添加功能
*
* @param categoryId 查询ID
* @return List<Brand>
*/
@Override
public List<Brand> findBrandByCategoryId(Long categoryId) {
emptyUtil.isEmpty(categoryId, MessageConstant.FIND_ID_IS_NOT_EMPTY);
return categoryBrandMapper.findBrandByCategoryId(categoryId);
}
} }

View File

@ -53,4 +53,14 @@
</where> </where>
order by cb.id desc order by cb.id desc
</select> </select>
<!-- 添加功能 -->
<select id="findBrandByCategoryId" resultType="com.atguigu.spzx.model.entity.product.Brand">
select b.*
from category_brand cb
left join brand b on b.id = cb.brand_id
where cb.category_id = #{categoryId}
and cb.is_deleted = 0
order by cb.id desc
</select>
</mapper> </mapper>