Browse Source

fix 修改门诊缴费订单接口

DYH2020 2 years ago
parent
commit
ada8730ce2

+ 10 - 0
src/main/java/com/ywt/mg/domain/models/ConstantDef.java

@@ -160,4 +160,14 @@ public class ConstantDef {
      */
     public static final String MARKER_PROJECT_PATH_PUBLIC = "/up/marketting_project/public";
 
+    /**
+     * map统计里面支付key的前缀
+     */
+    public static final String PAY_KEY_PREFIX = "payTotal_";
+
+    /**
+     * map统计里面支付key的前缀
+     */
+    public static final String REFUND_KEY_PREFIX = "refundTotal_";
+
 }

+ 23 - 0
src/main/java/com/ywt/mg/params/outpatientOrder/QueryOutPatientOrderListRequest.java

@@ -60,6 +60,13 @@ public class QueryOutPatientOrderListRequest implements Serializable {
     @ApiModelProperty(value = "判断医院后台还是公司后台")
     private int hosp;
 
+    @ApiModelProperty(value = "支付流水号")
+    private String paymentno;
+
+    @ApiModelProperty(value = "支付渠道")
+    private String paymentChannel;
+
+
     private boolean isAdmin = false;
 
     private String terminal;
@@ -223,4 +230,20 @@ public class QueryOutPatientOrderListRequest implements Serializable {
     public void setHosp(int hosp) {
         this.hosp = hosp;
     }
+
+    public String getPaymentno() {
+        return paymentno;
+    }
+
+    public void setPaymentno(String paymentno) {
+        this.paymentno = paymentno;
+    }
+
+    public String getPaymentChannel() {
+        return paymentChannel;
+    }
+
+    public void setPaymentChannel(String paymentChannel) {
+        this.paymentChannel = paymentChannel;
+    }
 }

+ 100 - 31
src/main/java/com/ywt/mg/services/OutpatientOrderService.java

@@ -5,10 +5,7 @@ import com.ywt.mg.core.SqlHelper;
 import com.ywt.mg.core.utils.Checker;
 import com.ywt.mg.core.utils.DateUtil;
 import com.ywt.mg.core.utils.FormatUtil;
-import com.ywt.mg.domain.entities.OrderPayment;
-import com.ywt.mg.domain.entities.OutpatientOrder;
-import com.ywt.mg.domain.entities.RefundLog;
-import com.ywt.mg.domain.entities.User;
+import com.ywt.mg.domain.entities.*;
 import com.ywt.mg.domain.models.ConstantDef;
 import com.ywt.mg.domain.models.ExcelDataMap;
 import com.ywt.mg.domain.models.enums.*;
@@ -221,7 +218,7 @@ public class OutpatientOrderService {
             //把日期往后增加一天.整数往后推,负数往前移动
             Calendar calendar = new GregorianCalendar();
             calendar.setTime(date);
-            calendar.add(calendar.DATE, 1);
+            calendar.add(Calendar.DATE, 1);
             date = calendar.getTime();   //这个时间就是日期往后推一天的结果
 
             paramList.add(date);
@@ -250,6 +247,18 @@ public class OutpatientOrderService {
             logger.error("OutpatientOrderService#queryOutPatientOrderListCommonNew(transactionId={} ):\n {} ", transactionId, e.getMessage(), e);
         }
 
+        String paymentno = request.getPaymentno();
+        if (!Checker.isNone(paymentno)) {
+            whereSql += " and ( payment_no like ?)";
+            paramList.add("%" + paymentno.trim() + "%");
+        }
+
+        String paymentChannel = request.getPaymentChannel();
+        if (!Checker.isNone(paymentChannel)) {
+            whereSql += " and ( payment_channel = ?)";
+            paramList.add(Integer.parseInt(paymentChannel));
+        }
+
         whereSql += " and ( deleted = 0 )";
         Map map = new HashMap();
         map.put(ConstantDef.KEY_WHERE_SQL, whereSql);
@@ -257,12 +266,13 @@ public class OutpatientOrderService {
         return map;
     }
 
-    public void downloadOutPatientOrderListCommon(int downloadRecordId, String fileName, QueryOutPatientOrderListRequest request,  int adminId) {
+    public void downloadOutPatientOrderListCommon(int downloadRecordId, String fileName, QueryOutPatientOrderListRequest request, int adminId) {
         try {
             boolean isAdmin = request.isAdmin();
             String col0 = "订单号";
             String col1 = "支付流水号";
             String col2 = "交易流水号";
+            String col2_1 = "支付渠道";
             String col3 = "患者姓名";
             String col4 = "患者手机号";
             String col5 = "诊疗卡";
@@ -276,18 +286,19 @@ public class OutpatientOrderService {
             String col13 = "支付状态";
             String col14 = "创建时间";
             String col15 = "支付时间";
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10,
+            String[] columns = new String[]{col0, col1, col2, col2_1, col3, col4, col5, col6, col7, col8, col9, col10,
                     col11, col12, col13, col14, col15};
             if (isAdmin == false) {
-                columns = new String[]{col0, col1, col2, col3, col4, col5, col6, col7, col9, col10,
+                columns = new String[]{col0, col1, col2, col2_1, col3, col4, col5, col6, col7, col9, col10,
                         col12, col13, col14, col15};
             }
 
             List<OutpatientOrder> list = queryOutPatientOrderList(request, adminId);
             List<User> userList = getUserListByOutpatientOrderViewList(list, list.size());
             List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByOutPatientOrderList(list);
-            int payTotal = 0;
             ExcelDataMap map = new ExcelDataMap(columns);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
+            int payTotal = 0, refundTotal = 0;
             if (!Checker.isNone(list)) {
                 for (OutpatientOrder p : list) {
                     String orderNoValue = Checker.getStringValue(p.getOrderNo());
@@ -314,21 +325,30 @@ public class OutpatientOrderService {
                     }
                     // 交易流水号
                     String transactionId = orderPaymentService.getTransactionIdByOrderId(orderPaymentList, Checker.getIntegerValue(p.getOrderId()));
-//
-//                    String[] bodyStr = new String[]{orderNoValue, paymentNoValue, transactionId, patientNameValue, mobileValue, hisPatientId, doctorNameValue, deptNameValue,
-//                            hospitalNameValue, terminal, total, expressStr, outpatientStatusStr, paymentStatusStr, createTimeValue, payTimeValue};
-//                    if (isAdmin == false) {
-//                        bodyStr = new String[]{orderNoValue, paymentNoValue, transactionId, patientNameValue, mobileValue, hisPatientId, doctorNameValue, deptNameValue, terminal,
-//                                total, outpatientStatusStr, paymentStatusStr, createTimeValue, payTimeValue};
-//                    }
+                    int paymentChannelInt = Checker.getIntegerValue(p.getPaymentChannel());
+                    String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
+
+                    String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannelInt;
+                    String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannelInt;
+                    int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                    int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                    int amountInt = Checker.getIntegerValue(p.getTotal());
                     if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
-                        payTotal += Checker.getIntegerValue(p.getTotal());
+                        payTotal += amountInt;
+                        payValue += amountInt;
+                        statisticalDataMap.put(payKey, payValue);
+                    }
+                    if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                        refundTotal += amountInt;
+                        refundValue += amountInt;
+                        statisticalDataMap.put(refundKey, refundValue);
                     }
 
                     if (isAdmin == false) {
                         map.getStringListSafely(col0).add(orderNoValue);
                         map.getStringListSafely(col1).add(paymentNoValue);
                         map.getStringListSafely(col2).add(transactionId);
+                        map.getStringListSafely(col2_1).add(paymentChannel);
                         map.getStringListSafely(col3).add(patientNameValue);
                         map.getStringListSafely(col4).add(mobileValue);
                         map.getStringListSafely(col5).add(hisPatientId);
@@ -346,6 +366,7 @@ public class OutpatientOrderService {
                         map.getStringListSafely(col0).add(orderNoValue);
                         map.getStringListSafely(col1).add(paymentNoValue);
                         map.getStringListSafely(col2).add(transactionId);
+                        map.getStringListSafely(col2_1).add(paymentChannel);
                         map.getStringListSafely(col3).add(patientNameValue);
                         map.getStringListSafely(col4).add(mobileValue);
                         map.getStringListSafely(col5).add(hisPatientId);
@@ -363,7 +384,7 @@ public class OutpatientOrderService {
                 }
             }
             int size = list.size();
-            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal);
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             logger.error("/outPatient/downloadOutPatientOrderList(): {}", e.getMessage(), e);
@@ -427,35 +448,57 @@ public class OutpatientOrderService {
      * @param payTotal 总金额
      * @return {@link List<ExcelCollectPojo> }
      */
-    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal) {
+    private List<ExcelCollectPojo> getStatisticsData(int size, int payTotal, int refundTotal, Map<String, Integer> statisticalDataMap) {
         int startRows = size + 3;
         int startColumn = 3;
 
         List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
         customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows + 1, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows + 1, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
+        customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows + 1, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
+        PaymentChannelEnum[] paymentChannelList = PaymentChannelEnum.values();
+        if (!Checker.isNone(paymentChannelList)) {
+            for (int i = 0, j = paymentChannelList.length; i < j; i++) {
+                int paymentChannel = paymentChannelList[i].getValue();
+                if (paymentChannel <= 0) continue;
+                startRows += 1;
+                String paymentChannelName = paymentChannelList[i].getDisplayName();
+                String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannel;
+                String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannel;
+                // 按支付渠道统计
+                int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{paymentChannelName + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{paymentChannelName + "退款总额", FormatUtil.intShrink100ToStr(refundValue)}));
+                customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{paymentChannelName + "实际支付金额", FormatUtil.intShrink100ToStr(payValue - refundValue)}));
+            }
+        }
         return customExcelItemList;
     }
 
-    public void downloadOutPatientOrderBillListNew(int downloadRecordId, String fileName,  QueryOutPatientOrderListRequest request, int adminId){
+    public void downloadOutPatientOrderBillListNew(int downloadRecordId, String fileName, QueryOutPatientOrderListRequest request, int adminId) {
         try {
-                    String col0 = "交易类型*";
-                    String col1 = "系统参考号*";
-                    String col2 = "交易金额*";
-                    String col3 =  "交易日期*";
-                    String col4 = "订单号";
-                    String col5 = "类型";
-            String[] columns = new String[]{col0, col1, col2, col3, col4, col5};
+            String col0 = "交易类型*";
+            String col1 = "系统参考号*";
+            String col2 = "交易金额*";
+            String col3 = "交易日期*";
+            String col4 = "订单号";
+            String col5 = "类型";
+            String col6 = "支付渠道";
+            String[] columns = new String[]{col0, col1, col2, col3, col4, col5, col6};
             //给第二行设置背景、字体颜色、对齐方式等等;
             // 只搜索已支付的订单
             request.setPaymentstatus(PaymentStatusEnum.Success.getValue() + "");
             List<OutpatientOrder> outpatientOrderList = queryOutPatientOrderList(request, adminId);
             ExcelDataMap map = new ExcelDataMap(columns);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
+            int payTotal = 0, refundTotal = 0, rowSize = 0;
             if (!Checker.isNone(outpatientOrderList)) {
                 // 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
                 List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByOutPatientOrderList(outpatientOrderList);
                 Date billStartTime = DateUtil.stringToDate(request.getBillStartTime() + ConstantDef.BILL_TIME_START_FORMAT);
                 Date billEndTime = DateUtil.stringToDate(request.getBillEndTime() + ConstantDef.BILL_TIME_END_FORMAT);
-                for (OutpatientOrder p : outpatientOrderList){
+                for (OutpatientOrder p : outpatientOrderList) {
                     if (!Checker.isNone(p) && Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()
                             && !Checker.isNone(p.getPayTime())) {
                         Date paymentTime = Checker.getDateValue(p.getPayTime());
@@ -472,13 +515,26 @@ public class OutpatientOrderService {
                             String orderNo = Checker.getStringValue(p.getOrderNo());
                             // 类型
                             String typeStr = "门诊缴费";
-//                            String[] bodyStr = {type, transactionId, totalStr, paymentTimeStr, orderNo, typeStr};
+                            // 支付渠道
+                            int paymentChannelInt = Checker.getIntegerValue(p.getPaymentChannel());
+                            String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
                             map.getStringListSafely(col0).add(type);
                             map.getStringListSafely(col1).add(transactionId);
                             map.getStringListSafely(col2).add(totalStr);
                             map.getStringListSafely(col3).add(paymentTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeStr);
+                            map.getStringListSafely(col6).add(paymentChannel);
+                            rowSize++;
+
+                            String payKey = ConstantDef.PAY_KEY_PREFIX + paymentChannelInt;
+                            int payValue = statisticalDataMap.getOrDefault(payKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getTotal());
+                            if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                                payTotal += amountInt;
+                                payValue += amountInt;
+                                statisticalDataMap.put(payKey, payValue);
+                            }
                         }
                     }
                 }
@@ -502,19 +558,32 @@ public class OutpatientOrderService {
                             String orderNo = Checker.getStringValue(p.getOrderNo());
                             // 类型
                             String typeName = "门诊缴费";
+                            // 支付渠道
+                            int paymentChannelInt = Checker.getIntegerValue(p.getPaymentChannel());
+                            String paymentChannel = PaymentChannelEnum.getDisplayName(paymentChannelInt);
                             map.getStringListSafely(col0).add(type);
                             map.getStringListSafely(col1).add(transactionId);
                             map.getStringListSafely(col2).add(totalStr);
                             map.getStringListSafely(col3).add(refundTimeStr);
                             map.getStringListSafely(col4).add(orderNo);
                             map.getStringListSafely(col5).add(typeName);
-//                            String[] bodyStr = {type, transactionId, totalStr, refundTimeStr, orderNo, typeName};
+                            map.getStringListSafely(col6).add(paymentChannel);
+                            rowSize++;
+
+                            String refundKey = ConstantDef.REFUND_KEY_PREFIX + paymentChannelInt;
+                            int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
+                            int amountInt = Checker.getIntegerValue(p.getTotal());
+                            if (Checker.getIntegerValue(p.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                                refundTotal += amountInt;
+                                refundValue += amountInt;
+                                statisticalDataMap.put(refundKey, refundValue);
+                            }
                         }
                     }
                 }
             }
             int size = outpatientOrderList.size();
-            List<ExcelCollectPojo> itemList = new ArrayList<>();
+            List<ExcelCollectPojo> itemList = getStatisticsData(rowSize, payTotal, refundTotal, statisticalDataMap);
             downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size);
         } catch (Exception e) {
             logger.error("/registeredOrder/downloadRegisteredOrderList: {}", e.getMessage(), e);

+ 2 - 0
src/main/java/com/ywt/mg/services/RegisteredOrderService.java

@@ -584,6 +584,8 @@ public class RegisteredOrderService {
         if (!Checker.isNone(itemList)) {
             List<Integer> integerList = itemList.stream().map(RegisteredOrder::getPaymentChannel).collect(Collectors.toList());
             // 去重
+            integerList = integerList.stream().filter(p -> !Checker.isNone(p)).collect(Collectors.toList());
+            if (Checker.isNone(integerList)) return customExcelItemList;
             List<Integer> paymentChannelList = new ArrayList<Integer>(new TreeSet<Integer>(integerList));
             if (!Checker.isNone(paymentChannelList)) {
                 for (int i = 0, j = paymentChannelList.size(); i < j; i++) {