|
|
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.los.Util.IDeptUtils;
|
|
|
+import org.springblade.los.app.dto.ProfitCustomersSort;
|
|
|
import org.springblade.los.app.service.IndexService;
|
|
|
import org.springblade.los.basic.corps.entity.BCorps;
|
|
|
import org.springblade.los.basic.corps.mapper.CorpsMapper;
|
|
|
@@ -70,12 +71,24 @@ public class IndexServiceImpl implements IndexService {
|
|
|
}
|
|
|
}
|
|
|
List<Bills> billsList = billsMapper.selectList(lambdaQueryWrapper);
|
|
|
- amountD = billsList.stream().map(Bills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- amountC = billsList.stream().map(Bills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
List<Long> billIds = new ArrayList<>();
|
|
|
if (!billsList.isEmpty()) {
|
|
|
+ amountD = billsList.stream().map(Bills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ amountC = billsList.stream().map(Bills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
billIds = billsList.stream().map(Bills::getId).collect(Collectors.toList());
|
|
|
}
|
|
|
+ List<AeaBills> aeaBillsList = aeaBillsMapper.selectList(new LambdaQueryWrapper<AeaBills>()
|
|
|
+ .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(AeaBills::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(business_type,'AE,AI')")
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), AeaBills::getBranchId, branchId)
|
|
|
+ .ge(ObjectUtils.isNotNull(startDate), AeaBills::getBillDate, startDate)
|
|
|
+ .le(ObjectUtils.isNotNull(endDate), AeaBills::getBillDate, endDate));
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ amountD = aeaBillsList.stream().map(AeaBills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ amountC = aeaBillsList.stream().map(AeaBills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ billIds.addAll(aeaBillsList.stream().map(AeaBills::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
LambdaQueryWrapper<Amends> amendsLambdaQueryWrapper = new LambdaQueryWrapper<Amends>()
|
|
|
.eq(Amends::getTenantId, AuthUtil.getTenantId())
|
|
|
.eq(Amends::getIsDeleted, 0)
|
|
|
@@ -102,17 +115,6 @@ public class IndexServiceImpl implements IndexService {
|
|
|
.map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
}
|
|
|
}
|
|
|
- List<AeaBills> aeaBillsList = aeaBillsMapper.selectList(new LambdaQueryWrapper<AeaBills>()
|
|
|
- .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
- .eq(AeaBills::getIsDeleted, 0)
|
|
|
- .apply("find_in_set(business_type,'AE,AI')")
|
|
|
- .eq(ObjectUtils.isNotNull(branchId), AeaBills::getBranchId, branchId)
|
|
|
- .ge(ObjectUtils.isNotNull(startDate), AeaBills::getBillDate, startDate)
|
|
|
- .le(ObjectUtils.isNotNull(endDate), AeaBills::getBillDate, endDate));
|
|
|
- if (!amendsList.isEmpty()) {
|
|
|
- amountD = aeaBillsList.stream().map(AeaBills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- amountC = aeaBillsList.stream().map(AeaBills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- }
|
|
|
return R.data(amountD.subtract(amountC));
|
|
|
}
|
|
|
|
|
|
@@ -291,4 +293,357 @@ public class IndexServiceImpl implements IndexService {
|
|
|
}
|
|
|
return R.data(corpsList);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R profitCustomersSort(String branchId) {
|
|
|
+ List<Long> corpIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<Bills> lambdaQueryWrapper = new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Bills::getBranchId, branchId);
|
|
|
+ String jurisdiction = sysClient.getParamService("data.jurisdiction");
|
|
|
+ if ("1".equals(jurisdiction)) {
|
|
|
+ if (!AuthUtil.getUserRole().contains("admin") && !AuthUtil.getUserRole().contains("老板")
|
|
|
+ && !AuthUtil.getUserRole().contains("副总") && !AuthUtil.getUserRole().contains("财务")
|
|
|
+ && !AuthUtil.getUserRole().contains("经理")) {
|
|
|
+ if (AuthUtil.getUserRole().contains("操作经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorDept, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("操作员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorId, AuthUtil.getUserId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("销售经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcDeptId, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("业务员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcId, AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(Bills::getCreateUser, AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ lambdaQueryWrapper.eq(Bills::getBranchId, deptUtils.getDeptPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(lambdaQueryWrapper);
|
|
|
+ List<Long> billIds = new ArrayList<>();
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ billIds = billsList.stream().map(Bills::getId).collect(Collectors.toList());
|
|
|
+ corpIdList = billsList.stream().map(Bills::getCorpId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<AeaBills> aeaBillsList = aeaBillsMapper.selectList(new LambdaQueryWrapper<AeaBills>()
|
|
|
+ .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(AeaBills::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(business_type,'AE,AI')")
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), AeaBills::getBranchId, branchId));
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ billIds.addAll(aeaBillsList.stream().map(AeaBills::getId).collect(Collectors.toList()));
|
|
|
+ corpIdList.addAll(aeaBillsList.stream().map(AeaBills::getCorpId).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<Amends> amendsLambdaQueryWrapper = new LambdaQueryWrapper<Amends>()
|
|
|
+ .eq(Amends::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Amends::getIsDeleted, 0)
|
|
|
+ .in(!billIds.isEmpty(), Amends::getOrigId, billIds)
|
|
|
+ .apply("find_in_set(business_type,'SEA,SIA,AEA,AIA')")
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Amends::getBranchId, branchId);
|
|
|
+ List<Amends> amendsList = amendsMapper.selectList(amendsLambdaQueryWrapper);
|
|
|
+ List<FeeCenter> feeCenterList = new ArrayList<>();
|
|
|
+ if (!amendsList.isEmpty()) {
|
|
|
+ List<Long> ids = amendsList.stream().map(Amends::getId).collect(Collectors.toList());
|
|
|
+ feeCenterList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .in(FeeCenter::getId, ids));
|
|
|
+ }
|
|
|
+ List<BCorps> corpsList = corpsMapper.selectList(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .in(BCorps::getId, corpIdList));
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ List<ProfitCustomersSort> customersSortList = new ArrayList<>();
|
|
|
+ for (BCorps item : corpsList) {
|
|
|
+ ProfitCustomersSort detail = new ProfitCustomersSort();
|
|
|
+ detail.setCorpId(item.getCorpId());
|
|
|
+ detail.setCorpName(item.getShortName());
|
|
|
+ BigDecimal amount = new BigDecimal("0.00");
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ BigDecimal amountD = billsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(Bills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountC = billsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(Bills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ BigDecimal amountD = aeaBillsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(AeaBills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountC = aeaBillsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(AeaBills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ if (!amendsList.isEmpty()) {
|
|
|
+ List<Long> amends = amendsList.stream().filter(e -> e.getCorpId().equals(item.getId()))
|
|
|
+ .map(Amends::getId).distinct().collect(Collectors.toList());
|
|
|
+ if (!amends.isEmpty()) {
|
|
|
+ List<FeeCenter> feeCenters = feeCenterList.stream().filter(e -> amends.contains(e.getPid())).collect(Collectors.toList());
|
|
|
+ if (!feeCenters.isEmpty()) {
|
|
|
+ BigDecimal amountD = feeCenters.stream().filter(e -> "USD".equals(e.getCurCode()) && "D".equals(e.getDc()))
|
|
|
+ .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getAmount())), BigDecimal::add);
|
|
|
+ BigDecimal amountC = feeCenters.stream().filter(e -> "USD".equals(e.getCurCode()) && "C".equals(e.getDc()))
|
|
|
+ .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getAmount())), BigDecimal::add);
|
|
|
+ amountD = amountD.add(feeCenters.stream().filter(e -> "CNY".equals(e.getCurCode()) && "D".equals(e.getDc()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ amountC = amountC.add(feeCenters.stream().filter(e -> "CNY".equals(e.getCurCode()) && "C".equals(e.getDc()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setAmount(amount);
|
|
|
+ customersSortList.add(detail);
|
|
|
+ }
|
|
|
+ //从大到小排序
|
|
|
+ List<ProfitCustomersSort> sortList = customersSortList.stream()
|
|
|
+ .sorted(Comparator.comparing(ProfitCustomersSort::getAmount).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ BigDecimal total = new BigDecimal("0.00");
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ map1.put("name", sortList.get(i).getCorpName());
|
|
|
+ map1.put("value", sortList.get(i).getAmount());
|
|
|
+ total = total.add(sortList.get(i).getAmount());
|
|
|
+ mapList.add(map1);
|
|
|
+ }
|
|
|
+ map.put("mapList", mapList);
|
|
|
+ map.put("total", total);
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R CargoVolumeCustomersSort(String branchId) {
|
|
|
+ List<Long> corpIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<Bills> lambdaQueryWrapper = new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Bills::getBranchId, branchId);
|
|
|
+ String jurisdiction = sysClient.getParamService("data.jurisdiction");
|
|
|
+ if ("1".equals(jurisdiction)) {
|
|
|
+ if (!AuthUtil.getUserRole().contains("admin") && !AuthUtil.getUserRole().contains("老板")
|
|
|
+ && !AuthUtil.getUserRole().contains("副总") && !AuthUtil.getUserRole().contains("财务")
|
|
|
+ && !AuthUtil.getUserRole().contains("经理")) {
|
|
|
+ if (AuthUtil.getUserRole().contains("操作经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorDept, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("操作员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorId, AuthUtil.getUserId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("销售经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcDeptId, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("业务员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcId, AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(Bills::getCreateUser, AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ lambdaQueryWrapper.eq(Bills::getBranchId, deptUtils.getDeptPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(lambdaQueryWrapper);
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ corpIdList = billsList.stream().map(Bills::getCorpId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<BCorps> corpsList = corpsMapper.selectList(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .in(BCorps::getId, corpIdList));
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ List<ProfitCustomersSort> customersSortList = new ArrayList<>();
|
|
|
+ for (BCorps item : corpsList) {
|
|
|
+ ProfitCustomersSort detail = new ProfitCustomersSort();
|
|
|
+ detail.setCorpId(item.getCorpId());
|
|
|
+ detail.setCorpName(item.getShortName());
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ detail.setTeu(billsList.stream().map(Bills::getTeu).filter(Objects::nonNull).mapToInt(Integer::intValue).sum());
|
|
|
+ } else {
|
|
|
+ detail.setTeu(0);
|
|
|
+ }
|
|
|
+ customersSortList.add(detail);
|
|
|
+ }
|
|
|
+ //从大到小排序
|
|
|
+ List<ProfitCustomersSort> sortList = customersSortList.stream()
|
|
|
+ .sorted(Comparator.comparing(ProfitCustomersSort::getTeu).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ int teu = 0;
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ map1.put("name", sortList.get(i).getCorpName());
|
|
|
+ map1.put("value", sortList.get(i).getTeu());
|
|
|
+ teu = teu + sortList.get(i).getTeu();
|
|
|
+ mapList.add(map1);
|
|
|
+ }
|
|
|
+ map.put("mapList", mapList);
|
|
|
+ map.put("total", teu);
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R customersSortDetailList(String branchId, String type) {
|
|
|
+ if ("0".equals(type)){
|
|
|
+ List<Long> corpIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<Bills> lambdaQueryWrapper = new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Bills::getBranchId, branchId);
|
|
|
+ String jurisdiction = sysClient.getParamService("data.jurisdiction");
|
|
|
+ if ("1".equals(jurisdiction)) {
|
|
|
+ if (!AuthUtil.getUserRole().contains("admin") && !AuthUtil.getUserRole().contains("老板")
|
|
|
+ && !AuthUtil.getUserRole().contains("副总") && !AuthUtil.getUserRole().contains("财务")
|
|
|
+ && !AuthUtil.getUserRole().contains("经理")) {
|
|
|
+ if (AuthUtil.getUserRole().contains("操作经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorDept, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("操作员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorId, AuthUtil.getUserId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("销售经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcDeptId, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("业务员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcId, AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(Bills::getCreateUser, AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ lambdaQueryWrapper.eq(Bills::getBranchId, deptUtils.getDeptPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(lambdaQueryWrapper);
|
|
|
+ List<Long> billIds = new ArrayList<>();
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ billIds = billsList.stream().map(Bills::getId).collect(Collectors.toList());
|
|
|
+ corpIdList = billsList.stream().map(Bills::getCorpId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<AeaBills> aeaBillsList = aeaBillsMapper.selectList(new LambdaQueryWrapper<AeaBills>()
|
|
|
+ .eq(AeaBills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(AeaBills::getIsDeleted, 0)
|
|
|
+ .apply("find_in_set(business_type,'AE,AI')")
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), AeaBills::getBranchId, branchId));
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ billIds.addAll(aeaBillsList.stream().map(AeaBills::getId).collect(Collectors.toList()));
|
|
|
+ corpIdList.addAll(aeaBillsList.stream().map(AeaBills::getCorpId).distinct().collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<Amends> amendsLambdaQueryWrapper = new LambdaQueryWrapper<Amends>()
|
|
|
+ .eq(Amends::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Amends::getIsDeleted, 0)
|
|
|
+ .in(!billIds.isEmpty(), Amends::getOrigId, billIds)
|
|
|
+ .apply("find_in_set(business_type,'SEA,SIA,AEA,AIA')")
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Amends::getBranchId, branchId);
|
|
|
+ List<Amends> amendsList = amendsMapper.selectList(amendsLambdaQueryWrapper);
|
|
|
+ List<FeeCenter> feeCenterList = new ArrayList<>();
|
|
|
+ if (!amendsList.isEmpty()) {
|
|
|
+ List<Long> ids = amendsList.stream().map(Amends::getId).collect(Collectors.toList());
|
|
|
+ feeCenterList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .in(FeeCenter::getId, ids));
|
|
|
+ }
|
|
|
+ List<BCorps> corpsList = corpsMapper.selectList(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .in(BCorps::getId, corpIdList));
|
|
|
+ List<ProfitCustomersSort> customersSortList = new ArrayList<>();
|
|
|
+ for (BCorps item : corpsList) {
|
|
|
+ ProfitCustomersSort detail = new ProfitCustomersSort();
|
|
|
+ detail.setCorpId(item.getCorpId());
|
|
|
+ detail.setCorpName(item.getShortName());
|
|
|
+ BigDecimal amount = new BigDecimal("0.00");
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ BigDecimal amountD = billsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(Bills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountC = billsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(Bills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ if (!aeaBillsList.isEmpty()) {
|
|
|
+ BigDecimal amountD = aeaBillsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(AeaBills::getAmountDrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountC = aeaBillsList.stream().filter(e -> e.getCorpId().equals(item.getId())).map(AeaBills::getAmountCrLoc).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ if (!amendsList.isEmpty()) {
|
|
|
+ List<Long> amends = amendsList.stream().filter(e -> e.getCorpId().equals(item.getId()))
|
|
|
+ .map(Amends::getId).distinct().collect(Collectors.toList());
|
|
|
+ if (!amends.isEmpty()) {
|
|
|
+ List<FeeCenter> feeCenters = feeCenterList.stream().filter(e -> amends.contains(e.getPid())).collect(Collectors.toList());
|
|
|
+ if (!feeCenters.isEmpty()) {
|
|
|
+ BigDecimal amountD = feeCenters.stream().filter(e -> "USD".equals(e.getCurCode()) && "D".equals(e.getDc()))
|
|
|
+ .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getAmount())), BigDecimal::add);
|
|
|
+ BigDecimal amountC = feeCenters.stream().filter(e -> "USD".equals(e.getCurCode()) && "C".equals(e.getDc()))
|
|
|
+ .reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getExrate().multiply(y.getAmount())), BigDecimal::add);
|
|
|
+ amountD = amountD.add(feeCenters.stream().filter(e -> "CNY".equals(e.getCurCode()) && "D".equals(e.getDc()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ amountC = amountC.add(feeCenters.stream().filter(e -> "CNY".equals(e.getCurCode()) && "C".equals(e.getDc()))
|
|
|
+ .map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ BigDecimal subAmount = amountD.subtract(amountC);
|
|
|
+ amount = amount.add(subAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail.setAmount(amount);
|
|
|
+ customersSortList.add(detail);
|
|
|
+ }
|
|
|
+ //从大到小排序
|
|
|
+ List<ProfitCustomersSort> sortList = customersSortList.stream()
|
|
|
+ .sorted(Comparator.comparing(ProfitCustomersSort::getAmount).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return R.data(sortList);
|
|
|
+ }else{
|
|
|
+ List<Long> corpIdList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<Bills> lambdaQueryWrapper = new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(ObjectUtils.isNotNull(branchId), Bills::getBranchId, branchId);
|
|
|
+ String jurisdiction = sysClient.getParamService("data.jurisdiction");
|
|
|
+ if ("1".equals(jurisdiction)) {
|
|
|
+ if (!AuthUtil.getUserRole().contains("admin") && !AuthUtil.getUserRole().contains("老板")
|
|
|
+ && !AuthUtil.getUserRole().contains("副总") && !AuthUtil.getUserRole().contains("财务")
|
|
|
+ && !AuthUtil.getUserRole().contains("经理")) {
|
|
|
+ if (AuthUtil.getUserRole().contains("操作经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorDept, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("操作员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getOperatorId, AuthUtil.getUserId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("销售经理")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcDeptId, AuthUtil.getDeptId());
|
|
|
+ } else if (AuthUtil.getUserRole().contains("业务员")) {
|
|
|
+ lambdaQueryWrapper.like(Bills::getSrcId, AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ lambdaQueryWrapper.eq(Bills::getCreateUser, AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ lambdaQueryWrapper.eq(Bills::getBranchId, deptUtils.getDeptPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(lambdaQueryWrapper);
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ corpIdList = billsList.stream().map(Bills::getCorpId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<BCorps> corpsList = corpsMapper.selectList(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0)
|
|
|
+ .in(BCorps::getId, corpIdList));
|
|
|
+ List<ProfitCustomersSort> customersSortList = new ArrayList<>();
|
|
|
+ for (BCorps item : corpsList) {
|
|
|
+ ProfitCustomersSort detail = new ProfitCustomersSort();
|
|
|
+ detail.setCorpId(item.getCorpId());
|
|
|
+ detail.setCorpName(item.getShortName());
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ detail.setTeu(billsList.stream().map(Bills::getTeu).filter(Objects::nonNull).mapToInt(Integer::intValue).sum());
|
|
|
+ } else {
|
|
|
+ detail.setTeu(0);
|
|
|
+ }
|
|
|
+ customersSortList.add(detail);
|
|
|
+ }
|
|
|
+ //从大到小排序
|
|
|
+ List<ProfitCustomersSort> sortList = customersSortList.stream()
|
|
|
+ .sorted(Comparator.comparing(ProfitCustomersSort::getTeu).reversed())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return R.data(sortList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R salesmanTicketNum(String branchId, String startDate, String endDate) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R containerVolumeTrend(String branchId, String startDate) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|