wangys 5 vuotta sitten
vanhempi
commit
f2d225ce3a

+ 4 - 0
efunbox-base/efunbox-base-api/src/main/java/cn/efunbox/manage/base/entity/Manage.java

@@ -11,6 +11,7 @@ import org.hibernate.annotations.DynamicUpdate;
 
 import javax.persistence.*;
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -113,4 +114,7 @@ public class Manage implements Serializable {
 
     @Transient
     private Object company;
+
+    @Transient
+    private Double totalAmount;
 }

+ 16 - 2
efunbox-base/efunbox-base-api/src/main/java/cn/efunbox/manage/base/service/impl/ManageServiceImpl.java

@@ -3,6 +3,7 @@ package cn.efunbox.manage.base.service.impl;
 import cn.efunbox.manage.base.entity.*;
 import cn.efunbox.manage.base.enums.BaseStatusEnum;
 import cn.efunbox.manage.base.enums.IncomeStatusEnum;
+import cn.efunbox.manage.base.enums.ManageTypeEnum;
 import cn.efunbox.manage.base.repository.*;
 import cn.efunbox.manage.base.service.ManageService;
 import cn.efunbox.manage.base.vo.ManageVO;
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.Predicate;
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -48,10 +50,10 @@ public class ManageServiceImpl implements ManageService {
 
     @Override
     public ApiResult list(ManageVO manageVO) {
-        Pageable pageable = new PageRequest(manageVO.getPageNo() - 1, manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("gmtModified", BaseOrderEnum.DESC);}}));
+        Pageable pageable = new PageRequest(manageVO.getPageNo() - 1, manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("status", BaseOrderEnum.ASC);put("gmtModified", BaseOrderEnum.DESC);}}));
 //        manageVO.setStatus(BaseStatusEnum.NORMAL);
         if(!manageVO.getIsEntry()){
-            pageable = new PageRequest(manageVO.getPageNo() - 1,manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("happenTime", BaseOrderEnum.DESC);}}));
+            pageable = new PageRequest(manageVO.getPageNo() - 1,manageVO.getPageSize(), SortHelper.sortMap2Sort(new LinkedHashMap<String, BaseOrderEnum>(){{put("status", BaseOrderEnum.ASC);put("happenTime", BaseOrderEnum.DESC);}}));
             manageVO.setStatus(BaseStatusEnum.NORMAL);
         }
         Specification specification = (Specification<Manage>) (root, criteriaQuery, criteriaBuilder) -> {
@@ -178,6 +180,17 @@ public class ManageServiceImpl implements ManageService {
             return ApiResult.ok(null);
         }
         Page<Manage> manages = manageRepository.findAll(specification, pageable);
+        List<Manage> totalManages =  manageRepository.findAll(specification);
+        BigDecimal sum = new BigDecimal("0");
+        for (Manage manage: totalManages) {
+            if (Objects.equals(manage.getType(), ManageTypeEnum.COST)){
+                sum = sum.subtract(new BigDecimal(Double.toString(manage.getAmount())));
+                System.out.println(sum);
+            }else {
+                sum = sum.add(new BigDecimal(Double.toString(manage.getAmount())));
+                System.out.println(sum);
+            }
+        }
         if(Objects.isNull(manages)){
             return ApiResult.error(ApiCode.UNKNOWN_ERROR);
 
@@ -188,6 +201,7 @@ public class ManageServiceImpl implements ManageService {
         List<Long> companyIds = new ArrayList<>();
         List<Long> costTypeIds = new ArrayList<>();
         for(Manage m : manages){
+            m.setTotalAmount(sum.doubleValue());
             if(Objects.nonNull(m.getDeptId())){
                 deptIds.add(m.getDeptId());
             }