| @ -1,5 +1,19 @@ | |||
| <?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="org.jeecg.modules.sysMiniapp.product.mapper.AppProductMapper"> | |||
| <select id="getAppProductsByCateGory" resultType="org.jeecg.modules.sysMiniapp.product.entity.AppProduct"> | |||
| SELECT | |||
| p.id as id, | |||
| p.`name` as name, | |||
| p.pdf as pdf | |||
| FROM | |||
| app_product AS p | |||
| LEFT JOIN app_product_category_join AS c ON p.id = c.product_id | |||
| <where> | |||
| c.category_id = #{categoryId} | |||
| <if test="name!= null"> | |||
| AND p.`name` LIKE CONCAT('%',#{name},'%') | |||
| </if> | |||
| </where> | |||
| </select> | |||
| </mapper> | |||
| @ -0,0 +1,62 @@ | |||
| package org.jeecg.modules.miniapp.product.controller; | |||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
| import com.baomidou.mybatisplus.core.metadata.IPage; | |||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.lang.StringUtils; | |||
| import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
| import org.jeecg.common.api.vo.Result; | |||
| import org.jeecg.common.aspect.annotation.AutoLog; | |||
| import org.jeecg.common.constant.SymbolConstant; | |||
| import org.jeecg.common.system.base.controller.JeecgController; | |||
| import org.jeecg.common.system.query.QueryGenerator; | |||
| import org.jeecg.common.util.oConvertUtils; | |||
| import org.jeecg.config.shiro.IgnoreAuth; | |||
| import org.jeecg.modules.miniapp.product.entity.CategoryProductDTO; | |||
| import org.jeecg.modules.miniapp.product.service.impl.MProductServiceImpl; | |||
| import org.jeecg.modules.sysMiniapp.product.entity.AppProduct; | |||
| import org.jeecg.modules.sysMiniapp.product.entity.Product; | |||
| import org.jeecg.modules.sysMiniapp.product.service.IAppProductService; | |||
| import org.jeecg.modules.sysMiniapp.productCategoryJoin.entity.AppProductCategoryJoin; | |||
| import org.jeecg.modules.sysMiniapp.productCategoryJoin.mapper.AppProductCategoryJoinMapper; | |||
| import org.jeecg.modules.sysMiniapp.productCategoryJoin.service.IAppProductCategoryJoinService; | |||
| import org.springframework.beans.BeanUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import java.util.Set; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| * @Description: 产品管理 | |||
| * @Author: jeecg-boot | |||
| * @Date: 2025-02-16 | |||
| * @Version: V1.0 | |||
| */ | |||
| @Api(tags="产品管理") | |||
| @RestController | |||
| @RequestMapping("/miniapp/product") | |||
| @Slf4j | |||
| public class MProductController { | |||
| @Autowired | |||
| MProductServiceImpl mProductService; | |||
| @ApiOperation(value="产品管理-查询所有产品服务", notes="产品管理-查询所有产品服务") | |||
| @GetMapping(value = "/categories") | |||
| @IgnoreAuth | |||
| public Result<List<CategoryProductDTO>> query(@RequestParam(name = "name",required = false)String name) { | |||
| return mProductService.getAllCateGoryProduct(name); | |||
| } | |||
| } | |||
| @ -0,0 +1,17 @@ | |||
| package org.jeecg.modules.miniapp.product.entity; | |||
| import lombok.Data; | |||
| import org.jeecg.modules.sysMiniapp.product.entity.AppProduct; | |||
| import java.util.List; | |||
| /** | |||
| * @author tanzs | |||
| * @date 2025/2/18 21:39 | |||
| */ | |||
| @Data | |||
| public class CategoryProductDTO { | |||
| private Integer categoryId; | |||
| private String categoryName; | |||
| private List<AppProduct> products; | |||
| } | |||
| @ -0,0 +1,11 @@ | |||
| package org.jeecg.modules.miniapp.product.service; | |||
| import org.jeecg.common.api.vo.Result; | |||
| import org.jeecg.modules.miniapp.product.entity.CategoryProductDTO; | |||
| import java.util.List; | |||
| public interface MProductService { | |||
| Result<List<CategoryProductDTO>> getAllCateGoryProduct(String name); | |||
| } | |||
| @ -0,0 +1,80 @@ | |||
| package org.jeecg.modules.miniapp.product.service.impl; | |||
| import cn.hutool.core.util.StrUtil; | |||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.jeecg.common.api.vo.Result; | |||
| import org.jeecg.modules.miniapp.product.entity.CategoryProductDTO; | |||
| import org.jeecg.modules.miniapp.product.service.MProductService; | |||
| import org.jeecg.modules.sysMiniapp.product.entity.AppProduct; | |||
| import org.jeecg.modules.sysMiniapp.product.service.impl.AppProductServiceImpl; | |||
| import org.jeecg.modules.sysMiniapp.productCategory.entity.AppCategory; | |||
| import org.jeecg.modules.sysMiniapp.productCategory.mapper.AppCategoryMapper; | |||
| import org.jeecg.modules.sysMiniapp.productCategory.service.impl.AppCategoryServiceImpl; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.ArrayList; | |||
| import java.util.Collections; | |||
| import java.util.Comparator; | |||
| import java.util.List; | |||
| /** | |||
| * @author tanzs | |||
| * @date 2025/2/18 21:37 | |||
| */ | |||
| @Service | |||
| @Slf4j | |||
| public class MProductServiceImpl implements MProductService { | |||
| @Autowired | |||
| AppProductServiceImpl appProductService; | |||
| @Autowired | |||
| AppCategoryServiceImpl appCategoryService; | |||
| /** | |||
| * 查询所有分类 | |||
| * @param name | |||
| * @return | |||
| */ | |||
| @Override | |||
| public Result<List<CategoryProductDTO>> getAllCateGoryProduct(String name) { | |||
| // 构建全部数据 | |||
| List<CategoryProductDTO> result = new ArrayList<CategoryProductDTO>(); | |||
| CategoryProductDTO categoryProductDTO = new CategoryProductDTO(); | |||
| categoryProductDTO.setCategoryId(0); | |||
| categoryProductDTO.setCategoryName("全部"); | |||
| // 查询全部产品服务 | |||
| List<AppProduct> appProducts = new ArrayList<AppProduct>(); | |||
| if (StrUtil.isNotEmpty(name)){ | |||
| LambdaQueryWrapper<AppProduct> productLambdaQueryWrapper = new LambdaQueryWrapper<>(); | |||
| productLambdaQueryWrapper.like(AppProduct::getName,name); | |||
| appProducts = appProductService.list(productLambdaQueryWrapper); | |||
| }else { | |||
| appProducts = appProductService.list(); | |||
| } | |||
| categoryProductDTO.setProducts(appProducts); | |||
| result.add(categoryProductDTO); | |||
| // 构建分类与产品的DTO | |||
| List<AppCategory> appCategories = appCategoryService.list(); | |||
| for(AppCategory category : appCategories){ | |||
| CategoryProductDTO categoryProduct = new CategoryProductDTO(); | |||
| categoryProduct.setCategoryId(category.getId()); | |||
| categoryProduct.setCategoryName(category.getCategoryName()); | |||
| // 查询分类下关联的产品 | |||
| List<AppProduct> categoryProducts = appProductService.getBaseMapper().getAppProductsByCateGory(name,category.getId()); | |||
| categoryProduct.setProducts(categoryProducts); | |||
| result.add(categoryProduct); | |||
| } | |||
| // 结果升序 | |||
| Collections.sort(result, new Comparator<CategoryProductDTO>() { | |||
| @Override | |||
| public int compare(CategoryProductDTO o1, CategoryProductDTO o2) { | |||
| // 根据 categoryId 进行升序排序 | |||
| return o1.getCategoryId().compareTo(o2.getCategoryId()); | |||
| } | |||
| }); | |||
| return Result.OK(result); | |||
| } | |||
| } | |||