Parcourir la source

fixed hot product

zero il y a 1 an
Parent
commit
eb4cf36e51

+ 11 - 11
src/main/java/com/example/xiaoshiweixinback/controller/ProductController.java

@@ -35,6 +35,7 @@ public class ProductController {
     private final AssoPersonProductService assoPersonProductService;
     private final ImportProductService importProductService;
     private final ImportTaskService importTaskService;
+
     @Operation(summary = "查询爆款产品")
     @PostMapping("/queryHotProduct")
     public Response queryHotProduct(@RequestBody ProductDTO productDTO) {
@@ -60,19 +61,18 @@ public class ProductController {
     @PostMapping("/follow")
     public Response follow(@RequestBody AssoPersonProductDTO assoPersonProductDTO) {
         Records records = new Records();
-        Integer id =null;
+        Integer id = null;
         try {
-             id = assoPersonProductService.add(assoPersonProductDTO);
+            id = assoPersonProductService.add(assoPersonProductDTO);
             if (id == null) {
                 return Response.noPermissions("已超过可关注数量");
             }
             if (id.equals(-2)) {
                 return Response.noPermissions("无关注产品的权益");
             }
+        } catch (BusinessException e) {
+            return Response.error(e.getErrorCode(), e.getMessage());
         }
-    catch (BusinessException e){
-            return Response.error(e.getErrorCode(),e.getMessage());
-    }
         records.setData(id);
         return Response.success(records);
     }
@@ -105,11 +105,11 @@ public class ProductController {
     @Operation(summary = "添加或更新爆款产品")
     @PostMapping("/addOrUpdateHotProduct")
     public Response addOrUpdateHotProduct(@RequestBody HotProductAddDTO hotProductAddDTO) {
-        Integer id =null;
+        Integer id = null;
         try {
-             id = productService.addOrUpdateHotProduct(hotProductAddDTO,null);
+            id = productService.addOrUpdateHotProduct(hotProductAddDTO, null);
         } catch (BusinessException e) {
-            return Response.error(e.getErrorCode(),e.getMessage());
+            return Response.error(e.getErrorCode(), e.getMessage());
         }
         return Response.success(id);
     }
@@ -144,9 +144,9 @@ public class ProductController {
     @Operation(summary = "导入产品")
     @PostMapping("/ImportProductBatch")
     public Response importProduct(@RequestBody MultipartFile file) throws Exception {
-        File newFile=  FileUtils.multipartFileToFile(file);
-        ImportTask importTask =importTaskService.addImportTask(newFile,2);
-        importProductService.importProject(newFile,importTask);
+        File newFile = FileUtils.multipartFileToFile(file);
+        ImportTask importTask = importTaskService.addImportTask(newFile, 2);
+        importProductService.importProject(newFile, importTask);
         return Response.success("records");
     }
 }

+ 3 - 2
src/main/java/com/example/xiaoshiweixinback/service/ProductService.java

@@ -46,6 +46,7 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
     private final AssoPersonProductService assoPersonProductService;
     private final ProductCategoryService productCategoryService;
     private final AssoproductCategoryService assoproductCategoryService;
+    private final ProductMapper productMapper;
 
     /**
      * 查询爆款产品
@@ -79,11 +80,11 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> {
         getProductDTO.setCurrent(current);
         getProductDTO.setSize(size);
         getProductDTO.setCategoryIds(ids);
-        if (personnelVO!=null&&!personnelVO.getPersonType().equals(0)) {
+        if (personnelVO != null && !personnelVO.getPersonType().equals(0)) {
             getProductDTO.setIfShow(true);
         }
         if (ids != null) {
-            List<ProductVO> productVOs = this.getBaseMapper().getProductByCategory(getProductDTO);
+            List<ProductVO> productVOs = productMapper.getProductByCategory(getProductDTO);
             Long count = this.getBaseMapper().getProductCount(getProductDTO);
             this.loadProduct(productVOs, false);
             records.setData(productVOs);

+ 9 - 9
src/main/resources/mapper/ProductMapper.xml

@@ -10,7 +10,7 @@
         left join asso_product_category as apc on p.id =product_id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            p.if_hot = true  and p.search_condition IS NOT NULL and p.search_condition != ''
+            p.if_hot = true and p.search_condition IS NOT NULL and p.search_condition != ''
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
@@ -36,12 +36,10 @@
             <if test="getProductDTO.bestSellingBrand!=null and getProductDTO.bestSellingBrand!=''">
                 and p.best_selling_brand like CONCAT('%',#{getProductDTO.bestSellingBrand},'%')
             </if>
-            order by p.create_time desc
+            order by p.create_time desc,p.id desc
             <if test="getProductDTO.current!=null and getProductDTO.size!=null">
                 limit ${(getProductDTO.current -1)*getProductDTO.size},${getProductDTO.size}
             </if>
-
-
         </where>
 
     </select>
@@ -52,7 +50,7 @@
         asso_product_category as apc on p.id =product_id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            p.if_hot = true  and p.search_condition IS NOT NULL and p.search_condition != ''
+            p.if_hot = true and p.search_condition IS NOT NULL and p.search_condition != ''
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
@@ -93,14 +91,15 @@
         left join product as p on app.product_id =p.id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            app.person_uuid  = #{getProductDTO.personUuid}
+            app.person_uuid = #{getProductDTO.personUuid}
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
 
             <if test="getProductDTO.concernTypes!=null and getProductDTO.concernTypes.size()>0">
                 and app.concern_type in
-                <foreach collection="getProductDTO.concernTypes" index="index" item="item" open="(" separator="," close=") ">
+                <foreach collection="getProductDTO.concernTypes" index="index" item="item" open="(" separator=","
+                         close=") ">
                     #{item}
                 </foreach>
             </if>
@@ -145,14 +144,15 @@
         left join product as p on app.product_id =p.id
         left join person as pe on p.create_id =pe.uuid
         <where>
-            app.person_uuid  = #{getProductDTO.personUuid}
+            app.person_uuid = #{getProductDTO.personUuid}
             <if test="getProductDTO.name!=null and getProductDTO.name!=''">
                 and p.name like CONCAT('%',#{getProductDTO.name},'%')
             </if>
 
             <if test="getProductDTO.concernTypes!=null and getProductDTO.concernTypes.size()>0">
                 and app.concern_type in
-                <foreach collection="getProductDTO.concernTypes" index="index" item="item" open="(" separator="," close=") ">
+                <foreach collection="getProductDTO.concernTypes" index="index" item="item" open="(" separator=","
+                         close=") ">
                     #{item}
                 </foreach>
             </if>