Browse Source

Merge branch 'dev' of xiongzhu/raex_back into master

sunkean 3 years ago
parent
commit
2ee6180e36

+ 21 - 0
src/main/java/com/izouma/nineth/enums/OperationType.java

@@ -0,0 +1,21 @@
+package com.izouma.nineth.enums;
+
+public enum OperationType {
+
+    INCREASE_STOCK("加库存"),
+
+    DECREASE_STOCK("减库存"),
+
+    INCREASE_SALE("加销量"),
+
+    DECREASE_SALE("减销量");
+    private final String description;
+
+    OperationType(String description) {
+        this.description = description;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}

+ 45 - 5
src/main/java/com/izouma/nineth/web/CacheController.java

@@ -1,26 +1,31 @@
 package com.izouma.nineth.web;
 package com.izouma.nineth.web;
 
 
-import com.izouma.nineth.repo.UserPropertyRepo;
+import com.izouma.nineth.enums.OperationType;
+import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.service.CacheService;
 import com.izouma.nineth.service.CacheService;
+import com.izouma.nineth.service.CollectionService;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.text.CaseUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 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 org.springframework.web.multipart.MultipartFile;
 
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Method;
+import java.util.Objects;
 
 
 @RestController
 @RestController
 @RequestMapping("/cache")
 @RequestMapping("/cache")
 @AllArgsConstructor
 @AllArgsConstructor
+@Slf4j
 public class CacheController {
 public class CacheController {
 
 
-    private final CacheService     cacheService;
+    private final CacheService cacheService;
+
+    private final CollectionService collectionService;
 
 
     @RequestMapping("/clear")
     @RequestMapping("/clear")
     @PreAuthorize("hasRole('ADMIN')")
     @PreAuthorize("hasRole('ADMIN')")
@@ -38,4 +43,39 @@ public class CacheController {
         }
         }
     }
     }
 
 
+    @PostMapping(value = "/operating/{collectionId}/{num}/{operationType}")
+    public void operatingStockOrSale(@PathVariable Long collectionId, @PathVariable int num, @PathVariable OperationType operationType) {
+        if (Objects.isNull(collectionId)) {
+            throw new BusinessException("collectionId参数错误");
+        }
+        if (0 >= num) {
+            throw new BusinessException("num参数错误");
+        }
+        if (Objects.isNull(operationType)) {
+            throw new BusinessException("操作类型不可为空");
+        }
+        switch (operationType) {
+            case INCREASE_STOCK:
+                log.info(String.format("collectionId:[%S]  加库存:[%S]", collectionId, num));
+                collectionService.increaseStock(collectionId, num);
+                break;
+            case DECREASE_STOCK:
+                log.info(String.format("collectionId:[%S]  减库存:[%S]", collectionId, num));
+                collectionService.decreaseStock(collectionId, num);
+                break;
+            case INCREASE_SALE:
+                log.info(String.format("collectionId:[%S]  加销量:[%S]", collectionId, num));
+                collectionService.increaseSale(collectionId, num);
+                break;
+            case DECREASE_SALE:
+                log.info(String.format("collectionId:[%S]  减销量:[%S]", collectionId, num));
+                collectionService.decreaseSale(collectionId, num);
+                break;
+            default:
+                String err = String.format("暂不支持的操作类型:[%S]", operationType);
+                log.info(err);
+                throw new BusinessException(err);
+        }
+    }
+
 }
 }

+ 48 - 1
src/main/vue/src/views/Cache.vue

@@ -16,6 +16,13 @@
                     <el-button @click="clearVipPoint">清除VipPoint</el-button>
                     <el-button @click="clearVipPoint">清除VipPoint</el-button>
                     <el-button @click="importVipPoint">导入VipPoint</el-button>
                     <el-button @click="importVipPoint">导入VipPoint</el-button>
                 </div>
                 </div>
+                <el-divider>库存/销量</el-divider>
+                <el-input v-model="collectionId" placeholder="输入collectionId"></el-input>
+                <el-input v-model="num" placeholder="输入num"></el-input>
+                <el-button @click="operatingStockOrSale('INCREASE_STOCK')">加库存</el-button>
+                <el-button @click="operatingStockOrSale('DECREASE_STOCK')">减库存</el-button>
+                <el-button @click="operatingStockOrSale('INCREASE_SALE')">加销量</el-button>
+                <el-button @click="operatingStockOrSale('DECREASE_SALE')">减销量</el-button>
             </div>
             </div>
         </div>
         </div>
     </div>
     </div>
@@ -26,7 +33,9 @@ export default {
     data() {
     data() {
         return {
         return {
             loading: false,
             loading: false,
-            param: null
+            param: null,
+            collectionId: '',
+            num: ''
         };
         };
     },
     },
     methods: {
     methods: {
@@ -43,6 +52,44 @@ export default {
                     this.$message.error(e.error || '失败');
                     this.$message.error(e.error || '失败');
                 });
                 });
         },
         },
+        operatingStockOrSale(operationType) {
+            let collectionId = this.collectionId.replace(/\s*/g,'');
+            let num = this.num.replace(/\s*/g,'');
+            var reg = /^[0-9]*$/
+            if (collectionId == null || collectionId === undefined || collectionId === '') {
+                this.$message.error('请输入collectionId')
+                return
+            }
+            if (num == null || num === undefined || num === '') {
+                this.$message.error('请输入num')
+                return
+            }
+            if(!reg.test(this.collectionId)){
+                this.$message.error('请正确输入collectionId,只允许输入数字')
+                return
+            }
+            if(!reg.test(this.num)){
+                this.$message.error('请正确输入num,只允许输入数字且必须大于0')
+                return
+            }
+            if (this.num <= 0) {
+                this.$message.error('num必须大于0')
+                return
+            }
+            this.loading = true
+            this.$http
+                .post('/cache/operating/' + this.collectionId + '/' + this.num + '/' + operationType)
+                .then(res => {
+                    this.loading = false;
+                    this.$message.success('成功');
+                    this.num = null
+                    this.collectionId = null
+                })
+                .catch(e => {
+                    this.loading = false;
+                    this.$message.error(e.error || '失败');
+                })
+        },
         clearUserProperty() {
         clearUserProperty() {
             this.loading = true;
             this.loading = true;
             this.$http
             this.$http