Browse Source

Merge remote-tracking branch 'origin/dev' into dev

ouyang 3 years ago
parent
commit
c88330711e

+ 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;
+    }
+}

+ 3 - 2
src/main/java/com/izouma/nineth/repo/DestroyRecordRepo.java

@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -17,6 +18,6 @@ public interface DestroyRecordRepo extends JpaRepository<DestroyRecord, Long>, J
     void softDelete(Long id);
     void softDelete(Long id);
 
 
     @Query(nativeQuery = true, value = "SELECT user.avatar avatar,user.nickname nickname,sum( destroy_record.record ) num FROM destroy_record LEFT JOIN user ON destroy_record.user_id = user.id WHERE destroy_record.asset_id IN ( SELECT asset.id FROM asset LEFT JOIN blind_box_item ON asset.collection_id = blind_box_item.collection_id where blind_box_item.blind_box_id = ?1 )" +
     @Query(nativeQuery = true, value = "SELECT user.avatar avatar,user.nickname nickname,sum( destroy_record.record ) num FROM destroy_record LEFT JOIN user ON destroy_record.user_id = user.id WHERE destroy_record.asset_id IN ( SELECT asset.id FROM asset LEFT JOIN blind_box_item ON asset.collection_id = blind_box_item.collection_id where blind_box_item.blind_box_id = ?1 )" +
-            "and destroy_record.name like ?2 and destroy_record.name not like ?3 GROUP BY destroy_record.user_id ORDER BY sum( destroy_record.record ) DESC")
-    List<Map<String, String>> destroyRecordRank(Long blindBoxId, String rare, String not);
+            "and destroy_record.name like ?2 and destroy_record.name not like ?3 and destroy_record.created_at > ?4 GROUP BY destroy_record.user_id ORDER BY sum( destroy_record.record ) DESC")
+    List<Map<String, String>> destroyRecordRank(Long blindBoxId, String rare, String not, LocalDateTime countDateTime);
 }
 }

+ 0 - 1
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -869,7 +869,6 @@ public class AssetService {
         //加积分
         //加积分
         userRepo.addDestroyPoint(userId, 1);
         userRepo.addDestroyPoint(userId, 1);
     }
     }
-
     public double getRoyalties(Long minterId, double royalties, Long userId) {
     public double getRoyalties(Long minterId, double royalties, Long userId) {
         if (royalties == 3) {
         if (royalties == 3) {
             return 3;
             return 3;

+ 4 - 1
src/main/java/com/izouma/nineth/service/DestroyRecordService.java

@@ -17,6 +17,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.time.LocalDateTime;
 import java.util.Comparator;
 import java.util.Comparator;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -36,11 +37,13 @@ public class DestroyRecordService {
     }
     }
 
 
     public List<RecordRank> destroyRecordRank(String rare) {
     public List<RecordRank> destroyRecordRank(String rare) {
+        LocalDateTime countDateTime = LocalDateTime.of(2000,1,1,0,0,0);
         String not = null;
         String not = null;
         if (Constants.Rarity.SSR.equals(rare)) {
         if (Constants.Rarity.SSR.equals(rare)) {
             not = "%" + Constants.Rarity.U + " #%";
             not = "%" + Constants.Rarity.U + " #%";
         }
         }
         if (Constants.Rarity.SR.equals(rare)) {
         if (Constants.Rarity.SR.equals(rare)) {
+            countDateTime = LocalDateTime.of(2022,7,23,21,0,0);
             not = "%" + Constants.Rarity.SSR + " #%";
             not = "%" + Constants.Rarity.SSR + " #%";
         }
         }
         if (Constants.Rarity.U.equals(rare)) {
         if (Constants.Rarity.U.equals(rare)) {
@@ -51,7 +54,7 @@ public class DestroyRecordService {
             throw new BusinessException("请先配置盲盒id");
             throw new BusinessException("请先配置盲盒id");
         }
         }
         Long blindBoxId = Long.parseLong(sysConfig.getValue());
         Long blindBoxId = Long.parseLong(sysConfig.getValue());
-        List<Map<String, String>> map = destroyRecordRepo.destroyRecordRank(blindBoxId, "%" + rare + " #%", not);
+        List<Map<String, String>> map = destroyRecordRepo.destroyRecordRank(blindBoxId, "%" + rare + " #%", not, countDateTime);
         JSONArray jsonArray = new JSONArray();
         JSONArray jsonArray = new JSONArray();
         jsonArray.addAll(map);
         jsonArray.addAll(map);
         List<RecordRank> recordRanks = jsonArray.toJavaList(RecordRank.class);
         List<RecordRank> recordRanks = jsonArray.toJavaList(RecordRank.class);

+ 1 - 0
src/main/java/com/izouma/nineth/service/PayEaseService.java

@@ -322,6 +322,7 @@ public class PayEaseService {
                 case "ERROR":
                 case "ERROR":
                     throw new BusinessException(response1.getString("error"));
                     throw new BusinessException(response1.getString("error"));
                 case "FAIL":
                 case "FAIL":
+                case "FAILED":
                     throw new BusinessException(response1.getString("errorMessage"));
                     throw new BusinessException(response1.getString("errorMessage"));
                 case "CANCEL":
                 case "CANCEL":
                     throw new BusinessException(response1.getString("已取消"));
                     throw new BusinessException(response1.getString("已取消"));

+ 0 - 1
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -196,7 +196,6 @@ public class AssetController extends BaseController {
     public void destroy(@RequestParam Long id ,@RequestParam String tradeCode) {
     public void destroy(@RequestParam Long id ,@RequestParam String tradeCode) {
         assetService.destroy(id, SecurityUtils.getAuthenticatedUser().getId(),tradeCode);
         assetService.destroy(id, SecurityUtils.getAuthenticatedUser().getId(),tradeCode);
     }
     }
-
     @ApiOperation("开盲盒")
     @ApiOperation("开盲盒")
     @PostMapping("/open")
     @PostMapping("/open")
     public void open(@RequestParam Long id) {
     public void open(@RequestParam Long id) {

+ 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

+ 1 - 1
src/test/java/com/izouma/nineth/service/DestroyRecordServiceTest.java

@@ -11,6 +11,6 @@ class DestroyRecordServiceTest extends ApplicationTests {
 
 
     @Test
     @Test
     void destroyRecordRank() {
     void destroyRecordRank() {
-        destroyRecordService.destroyRecordRank("U");
+        destroyRecordService.destroyRecordRank("SR");
     }
     }
 }
 }

+ 22 - 0
src/test/java/com/izouma/nineth/service/PayEaseServiceTest.java

@@ -0,0 +1,22 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.utils.SnowflakeIdWorker;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.math.BigDecimal;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class PayEaseServiceTest extends ApplicationTests {
+    @Autowired
+    private PayEaseService payEaseService;
+
+    @Test
+    public void transfer() {
+
+        payEaseService.transfer(new SnowflakeIdWorker(1, 1).nextId() + "",
+                "熊竹", "6222024301070380161", new BigDecimal("1"), "15077886171");
+    }
+}