Browse Source

fix some bug

Mr.qian 1 month ago
parent
commit
6f79ed7485

+ 35 - 23
mall-service/src/main/java/com/txz/mall/controller/ProductController.java

@@ -7,7 +7,9 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.txz.mall.core.Result;
 import com.txz.mall.core.ResultCode;
+import com.txz.mall.model.StoreCombination;
 import com.txz.mall.model.StoreProduct;
+import com.txz.mall.service.StoreCombinationService;
 import com.txz.mall.service.StoreProductService;
 import dto.StoreProductAddRequest;
 import dto.StoreProductDTO;
@@ -36,12 +38,15 @@ import java.util.List;
 @RestController
 @RequestMapping("/product")
 public class ProductController {
-
+    
     private static Logger log = LoggerFactory.getLogger(ProductController.class);
-
+    
     @Resource
     private StoreProductService storeProductService;
-
+    
+    @Resource
+    private StoreCombinationService storeCombinationService;
+    
     @DeleteMapping("/delete")
     @ApiOperation(value = "商品删除")
     public Result delete(@RequestParam("ids") List<Long> ids) {
@@ -52,7 +57,7 @@ public class ProductController {
             ids.forEach(id -> {
                 StoreProduct storeProduct = new StoreProduct();
                 storeProduct.setId(id);
-//                storeProduct.setIsRecycle(1);
+                //                storeProduct.setIsRecycle(1);
                 storeProduct.setIsDelete(1);
                 storeProduct.setUpdateTime(new Date());
                 storeProductService.update(storeProduct);
@@ -63,7 +68,7 @@ public class ProductController {
         }
         return Result.success();
     }
-
+    
     @PutMapping("/update")
     @ApiOperation(value = "商品更新")
     public Result update(@RequestBody @Validated StoreProductAddRequest request) {
@@ -76,7 +81,7 @@ public class ProductController {
         storeProductService.update(request);
         return Result.success();
     }
-
+    
     @PostMapping("/updateShowStatus")
     @ApiOperation(value = "商品上下架")
     public Result updateShowStatus(@RequestParam Long id, @RequestParam Integer ShowStatus) {
@@ -86,11 +91,11 @@ public class ProductController {
         if (id == null) {
             return Result.fail(ResultCode.ID_IS_NULL);
         }
-
+        
         try {
             StoreProduct storeProduct = new StoreProduct();
             storeProduct.setUpdateTime(new Date());
-//            storeProduct.setUpdateUserId(userId);
+            //            storeProduct.setUpdateUserId(userId);
             storeProduct.setId(id);
             storeProduct.setIsShow(ShowStatus);
             storeProductService.update(storeProduct);
@@ -100,17 +105,17 @@ public class ProductController {
         }
         return Result.success();
     }
-
+    
     @PostMapping("/list")
     @ApiOperation(value = "商品获取列表")
     public Result<List<StoreProduct>> list(@RequestBody StoreProductDTO dto) {
-
+        
         PageHelper.startPage(dto.getPage(), dto.getSize());
-
+        
         Condition condition = new Condition(StoreProduct.class);
         Criteria criteria = condition.createCriteria();
         criteria.andEqualTo("isDelete", 0);
-      //  condition.setOrderByClause("create_time DESC");
+        //  condition.setOrderByClause("create_time DESC");
         if (StringUtils.isNotBlank(dto.getStoreName())) {
             criteria.andLike("storeName", "%" + dto.getStoreName() + "%");
         }
@@ -132,7 +137,7 @@ public class ProductController {
         if (dto.getMinPrice() != null && dto.getMaxPrice() != null) {
             criteria.andBetween("price", dto.getMinPrice(), dto.getMaxPrice());
         }
-
+        
         if (new Integer(0).equals(dto.getSortWay())) {
             condition.setOrderByClause("create_time desc");
         } else if (new Integer(1).equals(dto.getSortWay())) {
@@ -143,10 +148,10 @@ public class ProductController {
             condition.setOrderByClause("ficti asc");
         } else if (new Integer(4).equals(dto.getSortWay())) {
             condition.setOrderByClause("ficti desc");
-        }else{
+        } else {
             condition.setOrderByClause("create_time desc");
         }
-
+        
         PageInfo pageInfo = null;
         try {
             List<StoreProduct> list = storeProductService.findByCondition(condition);
@@ -157,27 +162,27 @@ public class ProductController {
         }
         return Result.success(pageInfo);
     }
-
+    
     @ApiOperation("商品导入")
     @PostMapping("/import")
     public Result importFile(@JSONField(serialize = false) @RequestParam("file") MultipartFile file) {
         storeProductService.importFile(file);
         return Result.success();
     }
-
+    
     @ApiOperation("商品导入模版")
     @PostMapping("/export")
     public Result exportFile(HttpServletResponse response) {
         storeProductService.exportFile(response);
         return Result.success();
     }
-
+    
     @ApiOperation(value = "商品详情")
     @GetMapping(value = "/detail")
     public Result<StoreProductInfoVO> info(@RequestParam Long id) {
         return Result.success(storeProductService.getInfo(id));
     }
-
+    
     @PostMapping("/batchShowStatus")
     @ApiOperation(value = "批量商品上下架")
     public Result batchShowStatus(@RequestParam("ids") List<Long> ids, @RequestParam("showStatus") Integer showStatus) {
@@ -187,15 +192,22 @@ public class ProductController {
         if (CollectionUtils.isEmpty(ids)) {
             return Result.fail(ResultCode.ID_IS_NULL);
         }
-
+        
         try {
             ids.forEach(id -> {
                 StoreProduct storeProduct = new StoreProduct();
                 storeProduct.setUpdateTime(new Date());
-//                storeProduct.setUpdateUserId(userId);
+                //                storeProduct.setUpdateUserId(userId);
                 storeProduct.setId(id);
                 storeProduct.setIsShow(showStatus);
                 storeProductService.update(storeProduct);
+                
+                StoreCombination storeCombination = new StoreCombination();
+                storeCombination.setUpdateTime(new Date());
+                storeCombination.setProductId(id);
+                storeCombination.setIsShow(showStatus);
+                storeCombinationService.update(storeCombination);
+                
             });
         } catch (Exception e) {
             log.error("更新对象操作异常e:{}", e);
@@ -203,13 +215,13 @@ public class ProductController {
         }
         return Result.success();
     }
-
+    
     @ApiOperation(value = "获取商品各状态数量")
     @GetMapping(value = "/status/num")
     public Result<StoreProductCountItemVO> getOrderStatusNum() {
         return Result.success(storeProductService.getOrderStatusNum());
     }
-
+    
     @ApiOperation(value = "新增商品")
     @PostMapping(value = "/add")
     public Result<String> save(@RequestBody @Validated StoreProductAddRequest request) {