Commit 164b5c08 authored by libin's avatar libin

Merge branch 'staff-statistics' into dev

parents 146b16c0 f5e83a5b
...@@ -10,6 +10,7 @@ import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO; ...@@ -10,6 +10,7 @@ import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO;
import com.github.wxiaoqi.security.admin.vo.WalletPostionVo; import com.github.wxiaoqi.security.admin.vo.WalletPostionVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum; import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum;
import com.xxfc.platform.order.feign.OrderFeign; import com.xxfc.platform.order.feign.OrderFeign;
import com.xxfc.platform.order.pojo.dto.OrderDTO; import com.xxfc.platform.order.pojo.dto.OrderDTO;
...@@ -250,7 +251,7 @@ public class StaffStatisticsBiz { ...@@ -250,7 +251,7 @@ public class StaffStatisticsBiz {
//2.根据员工id范围和其他条件分页查询 //2.根据员工id范围和其他条件分页查询
List<Integer> userIds = allStaffs.stream().map(UserStaffBo::getUserId).collect(Collectors.toList()); List<Integer> userIds = allStaffs.stream().map(UserStaffBo::getUserId).collect(Collectors.toList());
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds, staffStatisticsFindDTO.getStartDate(), staffStatisticsFindDTO.getEndDate()); List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds, staffStatisticsFindDTO.getStartDate(), staffStatisticsFindDTO.getEndDate());
Map<Integer, Map<String, Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>>>> sellingWaterMap = new HashMap<>(); Map<Integer, Map<String, Map<Integer, List<AppUserSellingWaterDTO>>>> sellingWaterMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)) { if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)) {
//3.根据订单id查询订单相关信息 //3.根据订单id查询订单相关信息
...@@ -265,7 +266,7 @@ public class StaffStatisticsBiz { ...@@ -265,7 +266,7 @@ public class StaffStatisticsBiz {
sellingWaterMap = appUserSellingWaterDTOS.stream().collect(Collectors.groupingBy(AppUserSellingWaterDTO::getUserId, sellingWaterMap = appUserSellingWaterDTOS.stream().collect(Collectors.groupingBy(AppUserSellingWaterDTO::getUserId,
Collectors.groupingBy(AppUserSellingWaterDTO::getStateGroup, Collectors.groupingBy(AppUserSellingWaterDTO::getOrderType, Collectors.groupingBy(AppUserSellingWaterDTO::getStatus, Collectors.toList()))))); Collectors.groupingBy(AppUserSellingWaterDTO::getStateGroup, Collectors.groupingBy(AppUserSellingWaterDTO::getOrderType,Collectors.toList()))));
} }
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap(); Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
...@@ -275,13 +276,13 @@ public class StaffStatisticsBiz { ...@@ -275,13 +276,13 @@ public class StaffStatisticsBiz {
String stateGroup = String.format("%d-%d-%d", userStaffBo.getUserId(), userStaffBo.getPostionId(), userStaffBo.getCompanyId() == null ? NO_COMPANY_STATE : userStaffBo.getCompanyId()); String stateGroup = String.format("%d-%d-%d", userStaffBo.getUserId(), userStaffBo.getPostionId(), userStaffBo.getCompanyId() == null ? NO_COMPANY_STATE : userStaffBo.getCompanyId());
StaffStatisticsBo staffStatisticsBo = creatDefaultStaffStatistics(userStaffBo); StaffStatisticsBo staffStatisticsBo = creatDefaultStaffStatistics(userStaffBo);
if (!sellingWaterMap.isEmpty()) { if (!sellingWaterMap.isEmpty()) {
Map<String, Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>>> userSellingWaterMap = sellingWaterMap.get(userStaffBo.getUserId()); Map<String, Map<Integer, List<AppUserSellingWaterDTO>>> userSellingWaterMap = sellingWaterMap.get(userStaffBo.getUserId());
if (userSellingWaterMap != null && !userSellingWaterMap.isEmpty()) { if (userSellingWaterMap != null && !userSellingWaterMap.isEmpty()) {
AtomicReference<BigDecimal> royaltyAmountAtomicReference = new AtomicReference<>(BigDecimal.ZERO); AtomicReference<BigDecimal> royaltyAmountAtomicReference = new AtomicReference<>(BigDecimal.ZERO);
List<String> postionNames = new ArrayList<>(staffStatisticsBo.getPostionNames()); List<String> postionNames = Lists.newArrayList(staffStatisticsBo.getPostionNames());
List<Integer> postionIds = new ArrayList<>(staffStatisticsBo.getPostionIds()); List<Integer> postionIds = Lists.newArrayList(staffStatisticsBo.getPostionIds());
List<String> companyNames = new ArrayList<>(staffStatisticsBo.getCompanyNames()); List<String> companyNames = Lists.newArrayList(staffStatisticsBo.getCompanyNames());
List<Integer> compnayIds = new ArrayList<>(staffStatisticsBo.getCompnayIds()); List<Integer> compnayIds = Lists.newArrayList(staffStatisticsBo.getCompnayIds());
userSellingWaterMap.forEach((K, V) -> { userSellingWaterMap.forEach((K, V) -> {
if (!K.equals(stateGroup)) { if (!K.equals(stateGroup)) {
String[] sates = K.split("-"); String[] sates = K.split("-");
...@@ -319,7 +320,7 @@ public class StaffStatisticsBiz { ...@@ -319,7 +320,7 @@ public class StaffStatisticsBiz {
return staffStatisticsBos; return staffStatisticsBos;
} }
private StaffStatisticsBo wrapStaffStatistics(Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>> waterDTOSMap, AtomicReference<BigDecimal> royaltyAmountAtomicReference, StaffStatisticsBo staffStatisticsBo) { private StaffStatisticsBo wrapStaffStatistics(Map<Integer, List<AppUserSellingWaterDTO>> waterDTOSMap, AtomicReference<BigDecimal> royaltyAmountAtomicReference, StaffStatisticsBo staffStatisticsBo) {
waterDTOSMap.forEach((K, V) -> { waterDTOSMap.forEach((K, V) -> {
Map<String, Object> orderRentResultMap = wrapStaffStatisticsMap(V); Map<String, Object> orderRentResultMap = wrapStaffStatisticsMap(V);
BigDecimal royaltyAmount = royaltyAmountAtomicReference.get(); BigDecimal royaltyAmount = royaltyAmountAtomicReference.get();
...@@ -345,34 +346,45 @@ public class StaffStatisticsBiz { ...@@ -345,34 +346,45 @@ public class StaffStatisticsBiz {
return staffStatisticsBo; return staffStatisticsBo;
} }
private Map<String, Object> wrapStaffStatisticsMap(Map<Integer, List<AppUserSellingWaterDTO>> sellingWaters) { private Map<String, Object> wrapStaffStatisticsMap(List<AppUserSellingWaterDTO> sellingWaters) {
Map<String, Object> staffStatisticsResultMap = new HashMap<>(2); Map<String, Object> staffStatisticsResultMap = new HashMap<>(2);
AtomicInteger orderCounter = new AtomicInteger(0); AtomicInteger orderCounter = new AtomicInteger(0);
if (sellingWaters == null || sellingWaters.isEmpty()) { if (CollectionUtils.isEmpty(sellingWaters)) {
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, BigDecimal.ZERO); staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, BigDecimal.ZERO);
staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get()); staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get());
} }
BigDecimal totalAmount = BigDecimal.ZERO; BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal royaltyAmount = BigDecimal.ZERO; BigDecimal royaltyAmount = BigDecimal.ZERO;
Set<Map.Entry<Integer, List<AppUserSellingWaterDTO>>> sellingWaterSet = sellingWaters.entrySet(); Map<Integer, List<AppUserSellingWaterDTO>> orderSellingMap = sellingWaters.stream().collect(Collectors.groupingBy(AppUserSellingWaterDTO::getOrderId, Collectors.toList()));
for (Map.Entry<Integer, List<AppUserSellingWaterDTO>> sellingWaterEntry : sellingWaterSet) { Set<Map.Entry<Integer, List<AppUserSellingWaterDTO>>> orderSellingSet = orderSellingMap.entrySet();
List<AppUserSellingWaterDTO> waterDTOS = sellingWaterEntry.getValue(); for (Map.Entry<Integer, List<AppUserSellingWaterDTO>> orderSellingEntry : orderSellingSet) {
for (AppUserSellingWaterDTO waterDTO : waterDTOS) { BigDecimal inAmount = BigDecimal.ZERO;
if (sellingWaterEntry.getKey() == 0) { BigDecimal outAmount = BigDecimal.ZERO;
royaltyAmount = royaltyAmount.add(waterDTO.getCommission()); boolean isCommissionZero=false;
totalAmount = totalAmount.add(waterDTO.getPrice()); List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = orderSellingEntry.getValue();
orderCounter.incrementAndGet(); for (AppUserSellingWaterDTO waterDTO : appUserSellingWaterDTOS) {
if (waterDTO.getStatus() == 0) {
royaltyAmount = royaltyAmount.add(waterDTO.getCommission());
totalAmount = totalAmount.add(waterDTO.getPrice());
inAmount = inAmount.add(waterDTO.getCommission());
isCommissionZero = waterDTO.getCommission().intValue()==0;
}
if (waterDTO.getStatus() == 1) {
royaltyAmount = royaltyAmount.subtract(waterDTO.getCommission());
totalAmount = totalAmount.subtract(waterDTO.getPrice());
outAmount = outAmount.add(waterDTO.getCommission());
isCommissionZero=!isCommissionZero;
}
} }
if (sellingWaterEntry.getKey() == 1) { if(appUserSellingWaterDTOS.size()==1 || inAmount.subtract(outAmount).intValue()>0 || isCommissionZero){
royaltyAmount = royaltyAmount.subtract(waterDTO.getCommission()); orderCounter.incrementAndGet();
totalAmount = totalAmount.subtract(waterDTO.getPrice());
} }
} }
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, totalAmount); staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, totalAmount);
staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get()); staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get());
staffStatisticsResultMap.put(TOTAL_COMMISSION_VAL, royaltyAmount); staffStatisticsResultMap.put(TOTAL_COMMISSION_VAL, royaltyAmount);
}
return staffStatisticsResultMap; return staffStatisticsResultMap;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment