Kaynağa Gözat

修改count接口

wangqifan 3 yıl önce
ebeveyn
işleme
9a8f3cd4ff

+ 6 - 2
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
+import javax.transaction.Status;
 import javax.transaction.Transactional;
 import java.time.LocalDateTime;
 import java.util.*;
@@ -126,6 +127,9 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
             "where asset_tag.tag_id in ?2 " +
             "and asset.user_id = ?1 " +
             "and asset.status = 'NORMAL' " +
-            "group by asset.id",nativeQuery = true)
-    List<Asset> findByTagsContain(Long userId,  List<Long> tagIds);
+            "group by asset.id", nativeQuery = true)
+    List<Asset> findByTagsContain(Long userId, List<Long> tagIds);
+
+    @Query("select count(id) from Asset where status = ?2 and name like ?1")
+    Long countDestroyed(String name, AssetStatus status);
 }

+ 3 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -196,6 +196,9 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Query("select count(id) from Collection where source = 'TRANSFER' and name like ?1")
     int countAllByNameLike(String name);
 
+    @Query("select sum(c.total) from Collection c where c.source = 'OFFICIAL' and c.name like ?1")
+    Long sumAllByNameLike(String name);
+
     Collection findFirstByOnShelfAndAssetId(boolean onShelf, Long assetId);
 
     List<Collection> findAllByOasisIdInAndSourceInAndStockGreaterThan(List<Long> oasisIds, List<CollectionSource> sources, int sale);

+ 5 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -75,6 +75,7 @@ public class CollectionService {
     private UserBalanceService            userBalanceService;
     private SysConfigService              sysConfigService;
     private NewsRepo                      newsRepo;
+    private AssetRepo                     assetRepo;
 
     private final Map<Long, ScheduledFuture<?>> tasks = new HashMap<>();
 
@@ -812,4 +813,8 @@ public class CollectionService {
         });
         return result;
     }
+
+    public Long countDestroyAssets(String search) {
+        return assetRepo.countDestroyed(search, AssetStatus.DESTROYED);
+    }
 }

+ 9 - 1
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -9,6 +9,7 @@ import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.CollectionPrivilegeRepo;
 import com.izouma.nineth.repo.CollectionRepo;
 import com.izouma.nineth.repo.NewsRepo;
+import com.izouma.nineth.service.AssetService;
 import com.izouma.nineth.service.CacheService;
 import com.izouma.nineth.service.CollectionService;
 import com.izouma.nineth.service.LikeService;
@@ -26,6 +27,7 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import javax.naming.Name;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.*;
@@ -124,7 +126,8 @@ public class CollectionController extends BaseController {
     @GetMapping("/myLikes")
     @ApiOperation("我收藏的")
     public List<CollectionDTO> myLikes(@RequestParam(defaultValue = "1") Long companyId) {
-        return collectionService.toDTO(collectionRepo.userLikes(SecurityUtils.getAuthenticatedUser().getId(), companyId));
+        return collectionService
+                .toDTO(collectionRepo.userLikes(SecurityUtils.getAuthenticatedUser().getId(), companyId));
     }
 
     @PreAuthorize("hasAnyRole('ADMIN','SAAS')")
@@ -232,10 +235,15 @@ public class CollectionController extends BaseController {
         pageQuery.getQuery().remove("salable");
         pageQuery.getQuery().put("inPaying", true);
         long transactingNum = collectionService.all(pageQuery).getTotal();
+        Long destroyedAssets = collectionService.countDestroyAssets(search);
+        Long total = collectionRepo.sumAllByNameLike(search);
+        Long tranferCount = total - destroyedAssets;
         Map<String, String> map = new HashMap<>();
         map.put("onlyShowNum", String.valueOf(onlyShowNum));
         map.put("consignmentNum", String.valueOf(consignmentNum));
         map.put("transactingNum", String.valueOf(transactingNum));
+        map.put("totalNum", String.valueOf(total));
+        map.put("tranferingNum", String.valueOf(tranferCount));
         return map;
     }
 }