Преглед на файлове

feature:线下筛选医院

wuyongyi преди 1 година
родител
ревизия
7d7fc56c2b
променени са 2 файла, в които са добавени 285 реда и са изтрити 1 реда
  1. 284 0
      src/main/java/com/ywt/mg/services/OfflineNewService.java
  2. 1 1
      src/main/java/com/ywt/mg/web/controllers/OfflineController.java

+ 284 - 0
src/main/java/com/ywt/mg/services/OfflineNewService.java

@@ -434,5 +434,289 @@ public class OfflineNewService {
         return customExcelItemList;
     }
 
+    public Map queryNewOfflineListCommon(DownloadOfflineListNewRequest request) {
+        Map map = new HashMap();
+        List<Object> paramList = new ArrayList<>();
+        String whereSql = " ( 1=1 )";
+        try {
+            // 添加测试账号过滤
+            String testAdminIds = parameterConfigurer.getTestAdminIds();
+            String testDoctorIds = parameterConfigurer.getTestDoctorIds();
+            String adminStr = "," + request.getCurrentAdminId() + ",";
+            String testAdminIdsStr = "," + testAdminIds + ",";
+
+            // 不是测试账号
+            if (!(testAdminIdsStr.contains(adminStr))) {
+                String[] testDoctorIdsArr = testDoctorIds.split(",");
+                if (!Checker.isNone(testDoctorIdsArr)) {
+                    String sqlSubFrom = "";
+                    for (String doctorId : testDoctorIdsArr) {
+                        sqlSubFrom += "doctor_id != " + doctorId + " and ";
+                    }
+                    sqlSubFrom = sqlSubFrom.substring(0, sqlSubFrom.lastIndexOf("and"));
+                    whereSql += String.format(" and ((%s) or doctor_id is null)", sqlSubFrom);
+                }
+            }
+            String orderNo = request.getOrderNo();
+            if (!Checker.isNull(orderNo)) {
+                whereSql += " and ( order_no like ?)";
+                paramList.add("%" + orderNo.trim() + "%");
+            }
+
+            String patientName = request.getPatientName();
+            if (!Checker.isNull(patientName)) {
+                whereSql += " and ( real_name like ?)";
+                paramList.add("%" + patientName.trim() + "%");
+            }
+
+            String patientMobile = request.getPatientMobile();
+            if (!Checker.isNull(patientMobile)) {
+                whereSql += " and ( mobile like ?)";
+                paramList.add("%" + patientMobile + "%");
+            }
+
+            //status	1-已支付、2-已退费,3-已结算
+            String status = request.getStatus();
+            if (!Checker.isNull(status)) {
+                int orderStatusInt = Integer.parseInt(status);
+                if (orderStatusInt == 1) {
+                    whereSql += " and ( payment_status = ? and (refund_status <> ? or refund_status is null) and (settlement_status <> ? or settlement_status is null) )";
+                    paramList.add(PaymentStatusEnum.Success.getValue());
+                    paramList.add(RefundStatusEnum.SUCCESS.getValue());
+                    paramList.add(SettlementStatusEnum.SETTLED.getValue());
+                } else if (orderStatusInt == 2) {
+                    whereSql += " and ( refund_status = ?)";
+                    paramList.add(RefundStatusEnum.SUCCESS.getValue());
+                } else if (orderStatusInt == 3) {
+                    whereSql += " and ( settlement_status = ? and (refund_status <> ? or refund_status is null))";
+                    paramList.add(SettlementStatusEnum.SETTLED.getValue());
+                    paramList.add(RefundStatusEnum.SUCCESS.getValue());
+                }
+            }
+            //payment_status	tinyint	3	支付状态(0-待支付,1-支付处理中,2-支付成功,3-支付失败)
+            String paymentStatus = request.getPaymentStatus();
+            if (!Checker.isNull(paymentStatus)) {
+                whereSql += " and ( payment_status = ?)";
+                paramList.add(Integer.parseInt(paymentStatus));
+            }
+
+            String doctorName = request.getDoctorName();
+            if (!Checker.isNull(doctorName)) {
+                whereSql += " and ( doctor_name like ?  )";
+                paramList.add("%" + doctorName.trim() + "%");
+            }
+            String source = request.getSource();
+            int searchHospitalId = request.getHospitalId();
+            if (searchHospitalId > -1 && StringHelper.isNullOrWhiteSpace(source)) {
+                List<Integer> filteredSources = convertHospitalId2OfflineSources(searchHospitalId);
+                if (!Checker.isNone(filteredSources)) {
+                    whereSql += String.format(" and ( source in (%s)  )", filteredSources.stream().map(String::valueOf).collect(Collectors.joining(",")));
+                }
+            }
+
+            String hisClinicCode = request.getHisClinicCode();
+            if (!Checker.isNull(hisClinicCode)) {
+                whereSql += " and ( his_clinic_code like ?  )";
+                paramList.add("%" + hisClinicCode.trim() + "%");
+            }
+
+//            if (hospitalId != -1) {
+//                whereSql += " and ( hospital_id = ?  )";
+//                paramList.add(hospitalId);
+//            }
+
+            String formatDate = "yyyy-MM-dd";
+
+            SimpleDateFormat format = new SimpleDateFormat(formatDate);
+            String payTimeEnd = Checker.getStringValue(request.getPayTimeEnd());
+            if (!Checker.isNull(payTimeEnd)) {
+                whereSql += " and ( pay_time < ?)";
+                Date date = format.parse(payTimeEnd);
+
+                //把日期往后增加一天.整数往后推,负数往前移动
+                Calendar calendar = new GregorianCalendar();
+                calendar.setTime(date);
+                calendar.add(Calendar.DATE, 1);
+                //这个时间就是日期往后推一天的结果
+                date = calendar.getTime();
+                paramList.add(date);
+            }
+            String payTimeStart = Checker.getStringValue(request.getPayTimeStart());
+            if (!Checker.isNull(payTimeStart)) {
+                whereSql += " and ( pay_time >= ?)";
+                Date date = format.parse(payTimeStart);
+                paramList.add(date);
+            }
+            String refundTimeEnd = request.getRefundTimeEnd();
+            if (!Checker.isNull(refundTimeEnd)) {
+                whereSql += " and ( refund_time < ?)";
+                Date date = format.parse(refundTimeEnd);
+
+                //把日期往后增加一天.整数往后推,负数往前移动
+                Calendar calendar = new GregorianCalendar();
+                calendar.setTime(date);
+                calendar.add(Calendar.DATE, 1);
+                //这个时间就是日期往后推一天的结果
+                date = calendar.getTime();
+                paramList.add(date);
+            }
+
+            String createTimeEnd = Checker.getStringValue(request.getCreateEndTime());
+            if (!Checker.isNull(createTimeEnd)) {
+                whereSql += " and ( pay_time < ?)";
+                Date date = format.parse(createTimeEnd);
+
+                //把日期往后增加一天.整数往后推,负数往前移动
+                Calendar calendar = new GregorianCalendar();
+                calendar.setTime(date);
+                calendar.add(Calendar.DATE, 1);
+                //这个时间就是日期往后推一天的结果
+                date = calendar.getTime();
+                paramList.add(date);
+            }
+            String createTimeStart = Checker.getStringValue(request.getCreateStartTime());
+            if (!Checker.isNull(createTimeStart)) {
+                whereSql += " and ( pay_time >= ?)";
+                Date date = format.parse(createTimeStart);
+                paramList.add(date);
+            }
+
+
+            String refundTimeStart = request.getRefundTimeStart();
+            if (!Checker.isNull(refundTimeStart)) {
+                whereSql += " and ( refund_time >= ?)";
+                Date date = format.parse(refundTimeStart);
+                paramList.add(date);
+            }
+            if (!StringHelper.isNullOrWhiteSpace(source)) {
+                whereSql += " and ( source = ?)";
+                paramList.add(Integer.parseInt(source));
+            }
+
+            // 过滤掉删除和待支付的
+            whereSql += " and ( deleted = 0  ) and (payment_status > ?) ";
+            paramList.add(PaymentStatusEnum.Pending.getValue());
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        map.put(ConstantDef.KEY_WHERE_SQL, whereSql);
+        map.put(ConstantDef.KEY_PARAM_LIST, paramList);
+        return map;
+    }
+
+    public List<OfflineConsultation> queryNewDownloadOfflineList(DownloadOfflineListNewRequest request) {
+        Map map = queryOfflineListCommon(request);
+        String whereSql = (String) map.get(ConstantDef.KEY_WHERE_SQL);
+        List paramList = (List) map.get(ConstantDef.KEY_PARAM_LIST);
+        String sqlBuilder = "select * from offline_consultation where " + whereSql + "order by create_time desc";
+        return jdbcTemplate.query(sqlBuilder, paramList.toArray(), new BeanPropertyRowMapper<>(OfflineConsultation.class));
+    }
+
+
+    public void downloadNewOfflineListCommon(int downloadRecordId, String fileName, DownloadOfflineListNewRequest request) {
+        try {
+            // 单元格
+            String col0 = "订单号";
+            String col1 = "支付流水号";
+            String col1_1 = "交易流水号";
+            String col1_2 = "支付渠道";
+            String col2 = "患者姓名";
+            String col3 = "患者手机号";
+            String col4 = "身份证号";
+            String col5 = "医院流水号";
+            String col6 = "医生姓名";
+            String col7 = "科室";
+            String col8 = "医院";
+            String col9 = "诊查费";
+            String col10 = "状态";
+            String col11 = "支付状态";
+            String col12 = "支付时间";
+            String col13 = "退款时间";
+            String col14 = "备注";
+            String col15 = "来源";
+            String[] columns = new String[]{col0, col1, col1_1, col1_2, col2, col3, col4, col5, col6, col7, col8, col9, col10,
+                    col11, col12, col13, col14, col15};
+            // 按条件查找记录
+            // 若不指定医院(如公司后台发起查询),默认 hospitalId = -1 表示查询全部医院数据;否则根据指定的医院 id 查询
+            if (request.getHospitalId() <= 0) {
+                request.setHospitalId(-1);
+            }
+            List<OfflineConsultation> offlineList = queryNewDownloadOfflineList(request);
+            Map<String, Integer> statisticalDataMap = new HashMap<>();
+            int payTotal = 0, refundTotal = 0;
+            ExcelDataMap map = new ExcelDataMap(columns);
+            if (!Checker.isNone(offlineList)) {
+                // 遍历
+                List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByOfflineConsultationList(offlineList);
+                for (OfflineConsultation v : offlineList) {
+                    String orderNoStr = Checker.getStringValue(v.getOrderNo());
+                    String paymentNoStr = Checker.getStringValue(v.getPaymentNo());
+                    OrderPayment orderPayment = orderPaymentService.getOrderPaymentByOrderId(orderPaymentList, Checker.getIntegerValue(v.getOrderId()));
+                    String transactionIdStr = orderPaymentService.getTransactionIdByOrderPayment(orderPayment);
+                    String paymentChannel = orderPaymentService.getPaymentChannelByOrderPayment(orderPayment);
+                    String patientNameNoStr = Checker.getStringValue(v.getRealName());
+                    String patientMobileStr = Checker.getStringValue(v.getMobile());
+                    String idNoStr = Checker.getStringValue(v.getIdNo());
+                    String hisClinicCodeStr = Checker.getStringValue(v.getHisClinicCode() + "");
+                    String doctorNameStr = Checker.getStringValue(v.getDoctorName());
+                    String deptNameStr = Checker.getStringValue(v.getDeptName());
+                    String hospitalNameStr = hospitalCacheService.getCacheHospitalNameByHospitalId(Checker.getIntegerValue(v.getHospitalId()));
+                    String totalStr = FormatUtil.intShrink100ToStr(v.getTotal());
+                    String orderStatusStr = getOfflineStatusStr(v);
+                    String paymentStatusStr = PaymentStatusEnum.getPaymentStatus(Checker.getIntegerValue(v.getPaymentStatus())).getDisplayName();
+                    String payTimeStr = FormatUtil.createTimeFormatList(v.getPayTime());
+                    String refundTimeStr = FormatUtil.createTimeFormatList(v.getRefundTime());
+                    String remarkStr = Checker.getStringValue(v.getRefundRemark());
+                    String sourceStr = OfflineConsultationSourceEnum.getDisplayName(Checker.getIntegerValue(v.getSource()));
+
+                    int paymentChannelInt = Checker.getIntegerValue(v.getPaymentChannel());
+                    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(v.getTotal());
+                    if (Checker.getIntegerValue(v.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
+                        payTotal += amountInt;
+                        payValue += amountInt;
+                        statisticalDataMap.put(payKey, payValue);
+                    }
+                    if (Checker.getIntegerValue(v.getRefundStatus()) == RefundStatusEnum.SUCCESS.getValue()) {
+                        refundTotal += amountInt;
+                        refundValue += amountInt;
+                        statisticalDataMap.put(refundKey, refundValue);
+                    }
+                    map.getStringListSafely(col0).add(orderNoStr);
+                    map.getStringListSafely(col1).add(paymentNoStr);
+                    map.getStringListSafely(col2).add(patientNameNoStr);
+                    map.getStringListSafely(col1_1).add(transactionIdStr);
+                    map.getStringListSafely(col1_2).add(paymentChannel);
+                    map.getStringListSafely(col3).add(patientMobileStr);
+                    map.getStringListSafely(col4).add(idNoStr);
+                    map.getStringListSafely(col5).add(hisClinicCodeStr);
+                    map.getStringListSafely(col6).add(doctorNameStr);
+                    map.getStringListSafely(col7).add(deptNameStr);
+                    map.getStringListSafely(col8).add(hospitalNameStr);
+                    map.getStringListSafely(col9).add(totalStr);
+                    map.getStringListSafely(col10).add(orderStatusStr);
+                    map.getStringListSafely(col11).add(paymentStatusStr);
+                    map.getStringListSafely(col12).add(payTimeStr);
+                    map.getStringListSafely(col13).add(refundTimeStr);
+                    map.getStringListSafely(col14).add(remarkStr);
+                    map.getStringListSafely(col15).add(sourceStr);
+                }
+            }
+            // 得到统计
+            int size = offlineList.size();
+            List<ExcelCollectPojo> itemList = getStatisticsData(size, payTotal, refundTotal, statisticalDataMap);
+            // 创建文件 并且上传到 OSS,最后保存到本地数据库
+            int bill = 0;
+            downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, size, bill);
+        } catch (Exception e) {
+            logger.error("/offline/downloadOfflineList(): {}", e.getMessage(), e);
+            e.printStackTrace();
+        }
+    }
+
 
 }

+ 1 - 1
src/main/java/com/ywt/mg/web/controllers/OfflineController.java

@@ -53,7 +53,7 @@ public class OfflineController {
         Thread t = new Thread() {
             @Override
             public void run() {
-                offlineNewService.downloadOfflineListCommon(downloadRecordId, fileName, request);
+                offlineNewService.downloadNewOfflineListCommon(downloadRecordId, fileName, request);
             }
         };
         t.start();