Jelajahi Sumber

财务导出

zouxuan 3 tahun lalu
induk
melakukan
12a48a146d

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentPaymentRouteOrderDao.java

@@ -94,4 +94,6 @@ public interface StudentPaymentRouteOrderDao extends BaseDAO<Long, StudentPaymen
     StudentPaymentRouteOrder getByOrderNo(String orderNo);
 
     FeeFlagNumDto getCountFeeFlagNum(@Param("orderNo") String orderNo);
+
+    List<FeeFlagNumDto> queryCountFeeFlagNum(@Param("orderNos") List<String> orderNos);
 }

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/FeeFlagNumDto.java

@@ -3,6 +3,15 @@ package com.ym.mec.biz.dal.dto;
 public class FeeFlagNumDto {
     private Integer totalNum;
     private Integer yesNum;
+    private String orderNo;
+
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
 
     public Integer getTotalNum() {
         return totalNum;

+ 132 - 114
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ExportServiceImpl.java

@@ -182,6 +182,8 @@ public class ExportServiceImpl implements ExportService {
     @Value("${spring.profiles.active:dev}")
     private String profiles;
 
+    public static String goodsSellReceiptMerNo = "";
+
 
     @Override
     public Map<String,String> getExportMap(ExportDto exportDto) throws IOException {
@@ -2260,13 +2262,6 @@ public class ExportServiceImpl implements ExportService {
         if (!CollectionUtils.isEmpty(orderDetails)) {
             orderDetailMap = orderDetails.stream().collect(Collectors.groupingBy(StudentPaymentOrderDetail::getPaymentOrderId));
         }
-        //获取零星收费订单(订单类型是SPORADIC)
-//        Map<String, Integer> chargeTypeMap = new HashMap<>();
-//        if(studentPaymentOrderExportDtos.stream().anyMatch(e-> e.getGroupType() == GroupType.SPORADIC && e.getType() != OrderTypeEnum.DEGREE_REGISTRATION)){
-//            String sporadicIds = studentPaymentOrderExportDtos.stream().filter(e -> e.getGroupType() == GroupType.SPORADIC && e.getType() != OrderTypeEnum.DEGREE_REGISTRATION)
-//                    .map(e -> e.getMusicGroupId()).collect(Collectors.joining(","));
-//            chargeTypeMap = sporadicChargeInfoService.getMap("sporadic_charge_info","id_","charge_type_",sporadicIds,String.class,Integer.class);
-//        }
         //获取对外订单关联的合作单位
         Map<Integer, String> cooperationOrganMap = new HashMap<>();
         List<Integer> cooperationOrganIds = studentPaymentOrderExportDtos.stream()
@@ -2308,7 +2303,13 @@ public class ExportServiceImpl implements ExportService {
         //获取学员名称
         Map<Integer, String> studentNameMap = studentService.getMap("sys_user", "id_", "username_", studentIds, tenantId, Integer.class, String.class);
 
-
+        //用于计算手续费
+        Map<String, FeeFlagNumDto> feeFlagMap = new HashMap<>();
+        if(studentPaymentOrderExportDtos.stream().anyMatch(e->Objects.equals(e.getPaymentChannel(),"ADAPAY"))){
+            List<String> orderNoList = studentPaymentOrderExportDtos.stream().filter(e -> Objects.equals(e.getPaymentChannel(), "ADAPAY")).map(e -> e.getOrderNo()).distinct().collect(Collectors.toList());
+            List<FeeFlagNumDto> feeFlagNumDtos = studentPaymentRouteOrderDao.queryCountFeeFlagNum(orderNoList);
+            feeFlagMap = feeFlagNumDtos.stream().collect(Collectors.toMap(FeeFlagNumDto::getOrderNo, Function.identity()));
+        }
         for (StudentPaymentOrderExportDto basicOrder : studentPaymentOrderExportDtos) {
             if(basicOrder.getRouteAmount().compareTo(BigDecimal.ZERO) == 0){
                 continue;
@@ -2316,7 +2317,7 @@ public class ExportServiceImpl implements ExportService {
             basicOrder.getUser().setUsername(studentNameMap.get(basicOrder.getUserId()));
             //填充业务数据
             //计算手续费
-            this.calcPlatformFee(basicOrder,serviceChargeMap,orderCountMap,tenantConfig);
+            this.calcPlatformFee(basicOrder,serviceChargeMap,orderCountMap,tenantConfig,feeFlagMap);
             //获取乐团信息
             this.initMusicGroupInfo(basicOrder,musicGroupNameMap,firstMusicMap,userLastMusicIdMap,userLastMusicNameMap,calenderCooperationMap);
             //备注信息
@@ -2333,17 +2334,11 @@ public class ExportServiceImpl implements ExportService {
                     }
                 }
             }
-            //VIP课程组相关
-            if(basicOrder.getGroupType() == GroupType.VIP){
-                if(StringUtils.isNotEmpty(basicOrder.getMusicGroupId()) && basicOrder.getClassGroupId() != null) {
-                    VipGroup vipGroupInfo = vipGroupDao.findVipGroupInfo(Integer.parseInt(basicOrder.getMusicGroupId()), basicOrder.getClassGroupId());
-                    if (vipGroupInfo != null) {
-                        basicOrder.setSchoolName(vipGroupInfo.getSchoolName());
-                        basicOrder.setSubjectName(vipGroupInfo.getSubjectName());
-                        basicOrder.setEduTeacher(vipGroupInfo.getEducationalTeacherName());
-                    }
-                }
-                if(basicOrder.getTypeDesc() == null){
+            //根据订单类型初始化业务数据
+            Optional.ofNullable(groupTypeConsumerMap1.get(basicOrder.getType())).ifPresent(consumer -> consumer.accept(basicOrder));
+
+            if(basicOrder.getTypeDesc() == null){
+                if(basicOrder.getGroupType() == GroupType.VIP){
                     //学员没有历史VIP课程则导出为【VIP课新增】
                     //学员有历史VIP课程到导出为【VIP课续费]
                     if(Objects.equals(userFirstVipMap.get(basicOrder.getUserId()),basicOrder.getMusicGroupId())){
@@ -2351,43 +2346,7 @@ public class ExportServiceImpl implements ExportService {
                     }else {
                         basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.RENEW_VIP);
                     }
-                }
-            }else if(basicOrder.getGroupType() == GroupType.SPORADIC && basicOrder.getType() != OrderTypeEnum.DEGREE_REGISTRATION){
-//                basicOrder.setChargeType(chargeTypeMap.get(basicOrder.getMusicGroupId()));
-                if (basicOrder.getChargeType() != null) {
-                    for (SporadicChargeTypeEnum chargeType : SporadicChargeTypeEnum.values()) {
-                        if (!chargeType.getCode().equals(basicOrder.getChargeType())) continue;
-                        basicOrder.setSporadicType(chargeType.getMsg());
-                    }
-                }
-            }else if(basicOrder.getGroupType() == GroupType.PRACTICE && StringUtils.isNotEmpty(basicOrder.getMusicGroupId())){
-                PracticeCourseDto practiceGroup = practiceGroupDao.findByGroupId(Integer.parseInt(basicOrder.getMusicGroupId()));
-                if (practiceGroup != null) {
-                    basicOrder.setSubjectName(practiceGroup.getSubjectName());
-                    basicOrder.setEduTeacher(practiceGroup.getEduTeacherName());
-                }
-            }else if(basicOrder.getGroupType() == GroupType.REPLACEMENT && StringUtils.isNotEmpty(basicOrder.getMusicGroupId())){
-                ReplacementInstrumentActivityStatDto info = replacementInstrumentActivityDao.getInfo(Integer.parseInt(basicOrder.getMusicGroupId()));
-                if (info != null) {
-                    basicOrder.setSubjectName(info.getSubjectName());
-                    basicOrder.setCooperationOrganName(info.getCooperationOrganName());
-                    basicOrder.setMemo(info.getBrand() + "(" + info.getSpecification() + ")");
-                    CooperationOrgan cooperationOrganEduTeacher = musicGroupDao.findCooperationOrganEduTeacher(info.getCooperationOrganId());
-                    if (cooperationOrganEduTeacher != null) {
-                        basicOrder.setEduTeacher(cooperationOrganEduTeacher.getLinkman());
-                    }
-                }
-            }else if (basicOrder.getGroupType() == GroupType.MUSIC) {
-                StudentRegistration studentRegistration = studentRegistrationDao.findStudentByMusicGroupIdAndUserId(basicOrder.getMusicGroupId(), basicOrder.getUserId());
-                if (studentRegistration != null) {
-                    basicOrder.setSubjectName(studentRegistration.getSubjectName());
-                    basicOrder.setSchoolName(studentRegistration.getSchoolName());
-                    basicOrder.setCooperationOrganName(studentRegistration.getRemark());
-                    basicOrder.setEduTeacher(studentRegistration.getName());
-                }
-            }
-            if(basicOrder.getTypeDesc() == null){
-                if(basicOrder.getGroupType().equals(GroupType.SUBJECT_CHANGE)){
+                }else if(basicOrder.getGroupType().equals(GroupType.SUBJECT_CHANGE)){
                     basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.NEW_MUSIC);
                 }else if(basicOrder.getGroupType().equals(GroupType.REPAIR)){
                     basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.REPAIR);
@@ -2395,39 +2354,26 @@ public class ExportServiceImpl implements ExportService {
                     basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.OTHER);
                 }
             }
-
+            String paymentChannel = "";
+            if (basicOrder.getPaymentChannel() == null) {
+            } else if (basicOrder.getPaymentChannel().equals("YQPAY")) {
+                paymentChannel = "双乾";
+            } else if (basicOrder.getPaymentChannel().equals("ADAPAY")) {
+                paymentChannel = "汇付";
+            } else if (basicOrder.getPaymentChannel().equals("BALANCE")) {
+                paymentChannel = "余额";
+            }
+            basicOrder.setPaymentChannel(paymentChannel);
             //如果有订单详情
             List<StudentPaymentOrderDetail> detailList = orderDetailMap.get(basicOrder.getId());
             if (!CollectionUtils.isEmpty(detailList)) {
-                if(basicOrder.getServiceAmount().compareTo(BigDecimal.ZERO) > 0){
-                    //计算服务收入
-                    Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setServiceFee(basicOrder,orderDetail,userFirstVipMap);
-                    detailList.stream().forEach(con);
-                }else if(basicOrder.getSaleAmount().compareTo(BigDecimal.ZERO) > 0){
-                    //计算销售收入
-                    Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setSaleFee(basicOrder,orderDetail);
-                    detailList.stream().forEach(con);
-                }else {
-                    continue;
-                }
+                this.calcOrderDetail(basicOrder, detailList,userFirstVipMap);
                 continue;
             }
             //如果没有订单详情,则计算商品收入
             List<SellOrder> sellOrderList = sellOrderMap.get(basicOrder.getId());
             if (!CollectionUtils.isEmpty(sellOrderList)) {
-                if(basicOrder.getServiceAmount().compareTo(BigDecimal.ZERO) > 0){
-                    //计算服务收入(如果商品编号是76)那么算乐器保养费用
-                    if(sellOrderList.stream().anyMatch(e -> e.getGoodsId().equals("76"))){
-                        sellOrderList.stream().forEach(e->basicOrder.setMaintenanceProductFee(basicOrder.getMaintenanceProductFee().add(e.getActualAmount())));
-                    }
-                }else if(basicOrder.getSaleAmount().compareTo(BigDecimal.ZERO) > 0){
-                    //计算销售收入,排除商品编号是76的商品,其他的商品按分类统计
-                    for (SellOrder e : sellOrderList) {
-                        this.setSaleFee(basicOrder,e,goodsMap.get(e.getGoodsId()));
-                    }
-                }else {
-                    continue;
-                }
+                this.calcSellOrder(basicOrder,sellOrderList,goodsMap);
                 continue;
             }
             //如果只有订单,那么按分类统计
@@ -2438,22 +2384,96 @@ public class ExportServiceImpl implements ExportService {
                 //计算销售收入
                 this.setSaleFee(basicOrder);
             }
-            String paymentChannel = "";
-            if (basicOrder.getPaymentChannel() == null) {
-            } else if (basicOrder.getPaymentChannel().equals("YQPAY")) {
-                paymentChannel = "双乾";
-            } else if (basicOrder.getPaymentChannel().equals("ADAPAY")) {
-                paymentChannel = "汇付";
-            } else if (basicOrder.getPaymentChannel().equals("BALANCE")) {
-                paymentChannel = "余额";
-            }
-            basicOrder.setPaymentChannel(paymentChannel);
-            basicOrder.setOrderAmount(basicOrder.getExpectAmount().add(basicOrder.getCouponRemitFee()));
         }
         HSSFWorkbook workbook = getHSSFWorkbook(studentPaymentOrderExportDtos,headColumns,ExportEnum.ROUTE_ORDER_LIST1);
         exportManagerDownload(workbook,managerDownload);
     }
 
+    //按订单详情计算
+    public void calcOrderDetail(StudentPaymentOrderExportDto basicOrder,List<StudentPaymentOrderDetail> detailList,Map<Integer, String> userFirstVipMap){
+        if(basicOrder.getServiceAmount().compareTo(BigDecimal.ZERO) > 0){
+            //计算服务收入
+            Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setServiceFee(basicOrder,orderDetail,userFirstVipMap);
+            detailList.stream().forEach(con);
+        }else if(basicOrder.getSaleAmount().compareTo(BigDecimal.ZERO) > 0){
+            //计算销售收入
+            Consumer<StudentPaymentOrderDetail> con = (orderDetail)->this.setSaleFee(basicOrder,orderDetail);
+            detailList.stream().forEach(con);
+        }
+    }
+
+    //按商品订单计算收入
+    public void calcSellOrder(StudentPaymentOrderExportDto basicOrder,List<SellOrder> sellOrderList,Map<Integer, Goods> goodsMap){
+        if(basicOrder.getServiceAmount().compareTo(BigDecimal.ZERO) > 0){
+            //计算服务收入(如果商品编号是76)那么算乐器保养费用
+            if(sellOrderList.stream().anyMatch(e -> e.getGoodsId().equals("76"))){
+                sellOrderList.stream().forEach(e->basicOrder.setMaintenanceProductFee(basicOrder.getMaintenanceProductFee().add(e.getActualAmount())));
+            }
+        }else if(basicOrder.getSaleAmount().compareTo(BigDecimal.ZERO) > 0){
+            //计算销售收入,排除商品编号是76的商品,其他的商品按分类统计
+            for (SellOrder e : sellOrderList) {
+                this.setSaleFee(basicOrder,e,goodsMap.get(e.getGoodsId()));
+            }
+        }
+    }
+
+    //用于初始化业务数据
+    Map<GroupType,Consumer<StudentPaymentOrderExportDto>> groupTypeConsumerMap1 = new HashMap<>(GroupType.values().length);
+    @PostConstruct
+    public void initGroupTypeConsumerMap1(){
+        groupTypeConsumerMap1.put(GroupType.VIP,(basicOrder)->{
+            if(StringUtils.isNotEmpty(basicOrder.getMusicGroupId()) && basicOrder.getClassGroupId() != null) {
+                VipGroup vipGroupInfo = vipGroupDao.findVipGroupInfo(Integer.parseInt(basicOrder.getMusicGroupId()), basicOrder.getClassGroupId());
+                if (vipGroupInfo != null) {
+                    basicOrder.setSchoolName(vipGroupInfo.getSchoolName());
+                    basicOrder.setSubjectName(vipGroupInfo.getSubjectName());
+                    basicOrder.setEduTeacher(vipGroupInfo.getEducationalTeacherName());
+                }
+            }
+        });
+        groupTypeConsumerMap1.put(GroupType.SPORADIC,(basicOrder)->{
+            if(basicOrder.getType() != OrderTypeEnum.DEGREE_REGISTRATION && basicOrder.getChargeType() != null){
+                for (SporadicChargeTypeEnum chargeType : SporadicChargeTypeEnum.values()) {
+                    if (!chargeType.getCode().equals(basicOrder.getChargeType())) continue;
+                    basicOrder.setSporadicType(chargeType.getMsg());
+                }
+            }
+        });
+        groupTypeConsumerMap1.put(GroupType.PRACTICE,(basicOrder)->{
+            if(StringUtils.isNotEmpty(basicOrder.getMusicGroupId())){
+                PracticeCourseDto practiceGroup = practiceGroupDao.findByGroupId(Integer.parseInt(basicOrder.getMusicGroupId()));
+                if (practiceGroup != null) {
+                    basicOrder.setSubjectName(practiceGroup.getSubjectName());
+                    basicOrder.setEduTeacher(practiceGroup.getEduTeacherName());
+                }
+            }
+        });
+        groupTypeConsumerMap1.put(GroupType.REPLACEMENT,(basicOrder)->{
+            if(StringUtils.isNotEmpty(basicOrder.getMusicGroupId())) {
+                ReplacementInstrumentActivityStatDto info = replacementInstrumentActivityDao.getInfo(Integer.parseInt(basicOrder.getMusicGroupId()));
+                if (info != null) {
+                    basicOrder.setSubjectName(info.getSubjectName());
+                    basicOrder.setCooperationOrganName(info.getCooperationOrganName());
+                    basicOrder.setMemo(info.getBrand() + "(" + info.getSpecification() + ")");
+                    CooperationOrgan cooperationOrganEduTeacher = musicGroupDao.findCooperationOrganEduTeacher(info.getCooperationOrganId());
+                    if (cooperationOrganEduTeacher != null) {
+                        basicOrder.setEduTeacher(cooperationOrganEduTeacher.getLinkman());
+                    }
+                }
+            }
+        });
+        groupTypeConsumerMap1.put(GroupType.MUSIC,(basicOrder)->{
+            StudentRegistration studentRegistration = studentRegistrationDao.findStudentByMusicGroupIdAndUserId(basicOrder.getMusicGroupId(), basicOrder.getUserId());
+            if (studentRegistration != null) {
+                basicOrder.setSubjectName(studentRegistration.getSubjectName());
+                basicOrder.setSchoolName(studentRegistration.getSchoolName());
+                basicOrder.setCooperationOrganName(studentRegistration.getRemark());
+                basicOrder.setEduTeacher(studentRegistration.getName());
+            }
+        });
+    }
+
+    //用于金额计算
     Map<GroupType,Consumer<StudentPaymentOrderExportDto>> groupTypeConsumerMap = new HashMap<>(GroupType.values().length);
     @PostConstruct
     public void initGroupTypeConsumerMap(){
@@ -2464,8 +2484,12 @@ public class ExportServiceImpl implements ExportService {
         groupTypeConsumerMap.put(GroupType.PRACTICE,(orderDto)->orderDto.setPracticeCourseFee(orderDto.getPracticeCourseFee().add(orderDto.getActualAmount())));
         groupTypeConsumerMap.put(GroupType.REPAIR,(orderDto)->orderDto.setRepairFee(orderDto.getRepairFee().add(orderDto.getActualAmount())));
         groupTypeConsumerMap.put(GroupType.SPORADIC, this::accept);
+        if(StringUtils.isEmpty(goodsSellReceiptMerNo)){
+            goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
+        }
     }
 
+    //用于金额计算
     Map<Integer,Consumer<StudentPaymentOrderExportDto>> chargeTypeConsumerMap = new HashMap<>(SporadicChargeTypeEnum.values().length);
     @PostConstruct
     public void initChargeTypeConsumerMap(){
@@ -2527,23 +2551,21 @@ public class ExportServiceImpl implements ExportService {
     }
 
     public void setServiceFee(StudentPaymentOrderExportDto basicOrder, StudentPaymentOrderDetail orderDetail,Map<Integer, String> userFirstVipMap){
-        Optional.ofNullable(orderDetailTypeServiceConsumerMap.get(orderDetail.getType())).ifPresent(consumer -> consumer.accept(basicOrder, orderDetail));
-        if(orderDetail.getType() == OrderDetailTypeEnum.VIP && basicOrder.getTypeDesc() == null){
+        //分润订单可能多个,必须是指定账户。如果是内部库存转化部分收入为云教练收入
+        if(basicOrder.getRouteMerNo().equals(goodsSellReceiptMerNo)){
+            basicOrder.setCloudTeacherFee(basicOrder.getCloudTeacherFee().add(orderDetail.getIncome()));
+        }else {
+            Optional.ofNullable(orderDetailTypeServiceConsumerMap.get(orderDetail.getType())).ifPresent(consumer -> consumer.accept(basicOrder, orderDetail));
+            if (orderDetail.getType() == OrderDetailTypeEnum.VIP && basicOrder.getTypeDesc() == null) {
                 //学员没有历史VIP课程则导出为【VIP课新增】
-                //学员有历史VIP课程到导出为【VIP课续费]
-            if(Objects.equals(userFirstVipMap.get(basicOrder.getUserId()),basicOrder.getMusicGroupId())){
-                basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.NEW_VIP);
-            }else {
-                basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.RENEW_VIP);
+                //学员有历史VIP课程到导出为【VIP课续费】
+                if (Objects.equals(userFirstVipMap.get(basicOrder.getUserId()), basicOrder.getMusicGroupId())) {
+                    basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.NEW_VIP);
+                } else {
+                    basicOrder.setTypeDesc(StudentPaymentOrderExportDto.TypeDesc.RENEW_VIP);
+                }
             }
         }
-        //如果是内部库存转化部分收入为云教练收入
-        if(orderDetail.getType() == OrderDetailTypeEnum.MUSICAL ||
-                orderDetail.getType() == OrderDetailTypeEnum.TEACHING ||
-                orderDetail.getType() == OrderDetailTypeEnum.OTHER ||
-                orderDetail.getType() == OrderDetailTypeEnum.ACCESSORIES){
-            basicOrder.setCloudTeacherFee(basicOrder.getCloudTeacherFee().add(orderDetail.getIncome()));
-        }
     }
     public void setSaleFee(StudentPaymentOrderExportDto basicOrder,StudentPaymentOrderDetail orderDetail){
         BigDecimal price = orderDetail.getPrice();
@@ -2551,9 +2573,6 @@ public class ExportServiceImpl implements ExportService {
             case OTHER:
                 basicOrder.setOtherFee(basicOrder.getOtherFee().add(price));
                 break;
-            case MAINTENANCE:
-                basicOrder.setMaintenanceFee(basicOrder.getMaintenanceFee().add(price));
-                break;
             case MUSICAL:
                 if (orderDetail.getKitGroupPurchaseType() != null && orderDetail.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
                     basicOrder.setLeaseFee(price);
@@ -2589,11 +2608,9 @@ public class ExportServiceImpl implements ExportService {
 
     //计算汇付手续费和平台手续费
     public void calcPlatformFee(StudentPaymentOrderExportDto row,Map<String,BigDecimal> serviceChargeMap,
-                                Map<String,Integer> orderCountMap,TenantConfig tenantConfig){
+                                Map<String,Integer> orderCountMap,TenantConfig tenantConfig,Map<String, FeeFlagNumDto> feeFlagMap){
         BigDecimal currentFee = BigDecimal.ZERO;
         if (row.getPaymentChannel() != null && row.getPaymentChannel().equals("ADAPAY")) {
-            FeeFlagNumDto countFeeFlagNum = studentPaymentRouteOrderDao.getCountFeeFlagNum(row.getOrderNo());
-
             Integer times = orderCountMap.get(row.getOrderNo());
             if (times == null) {
                 times = 1;
@@ -2613,7 +2630,8 @@ public class ExportServiceImpl implements ExportService {
 
                 currentFee = row.getRouteAmount().multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
                 BigDecimal totalFee = row.getActualAmount().multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
-                if (totalFee.subtract(transferFee.add(currentFee)).doubleValue() < 0 || times == countFeeFlagNum.getTotalNum()) {
+                FeeFlagNumDto countFeeFlagNum = feeFlagMap.get(row.getOrderNo());
+                if (totalFee.subtract(transferFee.add(currentFee)).doubleValue() < 0 || countFeeFlagNum == null || times == countFeeFlagNum.getTotalNum()) {
                     currentFee = totalFee.subtract(transferFee);
                     serviceChargeMap.put(row.getOrderNo(), totalFee);
                 } else {

+ 1 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -590,6 +590,7 @@
         <result column="service_fee_" property="serviceFee"/>
         <result column="routeBalance" property="routeBalance"/>
         <result column="feeFlag" property="feeFlag"/>
+        <result column="orderAmount" property="orderAmount"/>
         <collection property="orderDetailList" ofType="com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail">
             <result column="detail_id_" property="id"/>
             <result column="detail_type_" property="type"/>

+ 20 - 8
mec-biz/src/main/resources/config/mybatis/StudentPaymentRouteOrderMapper.xml

@@ -288,18 +288,21 @@ calender_id_,create_time_,create_by_,update_time_,update_by_,tenant_id_,type_
 
     <select id="ExportQueryPage1" resultMap="com.ym.mec.biz.dal.dao.StudentPaymentOrderDao.orderAndDetail"
             parameterType="map">
-        SELECT spo.*,spro.route_amount_ routeAmount,
-               spro.route_balance_amount_ routeBalance,
-               spro.sale_amount_,
-               spro.service_amount_,
-               spro.service_fee_,
-               spro.mer_no_ routeMerNo,
-               spro.fee_flag_ feeFlag,
-               sci.charge_type_
+        SELECT spo.*,
+        SUM(spro.route_amount_) routeAmount,
+        SUM(spro.route_balance_amount_) routeBalance,
+        SUM(spro.sale_amount_) sale_amount_,
+        SUM(spro.service_amount_) service_amount_,
+        SUM(spro.service_fee_) service_fee_,
+        SUM(spro.mer_no_) routeMerNo,
+        SUM(spro.fee_flag_) feeFlag,
+        sci.charge_type_,
+        spo.expect_amount_ + spo.coupon_remit_fee_ orderAmount
         FROM student_payment_route_order spro
         LEFT JOIN student_payment_order spo ON spo.order_no_ = spro.order_no_
         LEFT JOIN sporadic_charge_info sci ON spo.music_group_id_ = sci.id_
         <include refid="queryPaymentOrder"/>
+        GROUP BY spro.mer_no_
         ORDER BY spro.id_
     </select>
 
@@ -428,5 +431,14 @@ calender_id_,create_time_,create_by_,update_time_,update_by_,tenant_id_,type_
         FROM student_payment_route_order WHERE order_no_=#{orderNo}
     </select>
 
+    <select id="queryCountFeeFlagNum" resultType="com.ym.mec.biz.dal.dto.FeeFlagNumDto">
+        SELECT SUM(1) totalNum,
+               SUM(IF(fee_flag_='Y',1, 0)) yesNum, order_no_ orderNo
+        FROM student_payment_route_order WHERE order_no_ IN
+        <foreach collection="orderNos" item="orderNo" open="(" close=")" separator=",">
+            #{orderNo}
+        </foreach>
+    </select>
+
 
 </mapper>