|
@@ -0,0 +1,305 @@
|
|
|
+package com.ywt.mg.services;
|
|
|
+
|
|
|
+import com.ywt.mg.configs.ParameterConfigurer;
|
|
|
+import com.ywt.mg.core.utils.Checker;
|
|
|
+import com.ywt.mg.domain.models.ConstantDef;
|
|
|
+import com.ywt.mg.domain.models.enums.PrescriptionInfoStatusEnum;
|
|
|
+import com.ywt.mg.domain.models.enums.RefundStatusEnum;
|
|
|
+import com.ywt.mg.domain.models.enums.SinopharmEnum;
|
|
|
+import com.ywt.mg.domain.ywtDrugEntities.Pharmacy;
|
|
|
+import com.ywt.mg.domain.ywtDrugEntities.PrescriptionInfo;
|
|
|
+import com.ywt.mg.params.pharamcy.PharamcyDownloadPresRequest;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PharamacyService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(PharamacyService.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AuthService authService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PharmacyCacheService pharmacyCacheService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate ywtDrugJdbcTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ParameterConfigurer parameterConfigurer;
|
|
|
+
|
|
|
+
|
|
|
+ private static final String KEY_WHERE_SQL = "whereSql";
|
|
|
+
|
|
|
+ private static final String KEY_PARAM_LIST = "paramList";
|
|
|
+ private static final String INJECTIONS_MAP = "injectionsMap";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public List<PrescriptionInfo> downloadPrescriptionlist(PharamcyDownloadPresRequest request) {
|
|
|
+ Map<String, Object> map = buildQueryPrescriptionListSQLParam(request);
|
|
|
+ String whereSql = (String) map.get(KEY_WHERE_SQL);
|
|
|
+ List<Object> paramList = (List<Object>) map.get(KEY_PARAM_LIST);
|
|
|
+ // 分页查找
|
|
|
+ // 拼凑sql语句
|
|
|
+ String sqlBuilder = "select *,biz_no_3th as bizNo3th from prescription_info where " + whereSql + " order by create_on desc";
|
|
|
+ return ywtDrugJdbcTemplate.query(sqlBuilder, paramList.toArray(), new BeanPropertyRowMapper<>(PrescriptionInfo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> buildQueryPrescriptionListSQLParam(PharamcyDownloadPresRequest request) {
|
|
|
+ List<Object> paramList = new ArrayList<>();
|
|
|
+ String whereSql = " ( 1=1 )";
|
|
|
+
|
|
|
+ String doctorname = request.getDoctorName();
|
|
|
+ if (!Checker.isNull(doctorname)) {
|
|
|
+ whereSql += " and ( doctor_name like ?)";
|
|
|
+ paramList.add("%" + doctorname + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ String patientname = request.getPatientName();
|
|
|
+ if (!Checker.isNull(patientname)) {
|
|
|
+ whereSql += " and ( patient_name like ?)";
|
|
|
+ paramList.add("%" + patientname + "%");
|
|
|
+ }
|
|
|
+ String deptname = request.getDeptName();
|
|
|
+ if (!Checker.isNull(deptname)) {
|
|
|
+ whereSql += " and ( dept like ?)";
|
|
|
+ paramList.add("%" + deptname + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ whereSql += " and (deleted = 0 or deleted is null) ";
|
|
|
+
|
|
|
+ List<Pharmacy> pharmacyList = pharmacyCacheService.getPharmacyList();
|
|
|
+
|
|
|
+ String selectPharmacyId = Checker.getStringValue(request.getSelectPharmacyId());
|
|
|
+ if (!Checker.isNull(selectPharmacyId)) {
|
|
|
+ whereSql += " and pharmacy_id = ? ";
|
|
|
+ paramList.add(Integer.parseInt(selectPharmacyId));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // todo: 多药房数据查询
|
|
|
+ whereSql += " and (pharmacy_id = ?";
|
|
|
+ paramList.add(request.getPharmacyId());
|
|
|
+ for (Pharmacy pharmacy : pharmacyList) {
|
|
|
+ if (!Checker.isNone(pharmacy) && pharmacy.getTreeCode().startsWith(request.getPharmacyId() + "|")) {
|
|
|
+ whereSql += " or pharmacy_id = ?";
|
|
|
+ paramList.add(pharmacy.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ whereSql += " ) ";
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo: v4.3.6 广三生殖药房可以看到所有的订单,而其他子药房看不到'待支付'的订单 (所以这里需要针对不是"生殖药房"的子药房进行过滤), parentId != -1 表示是子药房, leader = 0,表示除"生殖药房"的子药房
|
|
|
+ Pharmacy pharmacy = pharmacyList.stream().filter(p -> Checker.getIntegerValue(p.getId()) == request.getPharmacyId()).findFirst().orElse(null);
|
|
|
+ if (!Checker.isNone(pharmacy) && Checker.getIntegerValue(pharmacy.getParentId()) != -1 && Checker.getIntegerValue(pharmacy.getLeader()) == 0) {
|
|
|
+ whereSql += " and ( status != ? ) ";
|
|
|
+ paramList.add(PrescriptionInfoStatusEnum.WaitForPayment.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加测试账号过滤
|
|
|
+ String testAdminIds = parameterConfigurer.getTestAdminIds();
|
|
|
+ String testDoctorIds = parameterConfigurer.getTestDoctorIds();
|
|
|
+ String adminStr = "," + request.getAdminId() + ",";
|
|
|
+ String testAdminIdsStr = "," + testAdminIds + ",";
|
|
|
+
|
|
|
+ // 不是测试账号
|
|
|
+ if (!(testAdminIdsStr.contains(adminStr))) {
|
|
|
+ String[] testDoctorIdsArr = testDoctorIds.split(",");
|
|
|
+ if (!Checker.isNone(testDoctorIdsArr)) {
|
|
|
+ StringBuilder sqlSub = new StringBuilder();
|
|
|
+ for (String doctorId : testDoctorIdsArr) {
|
|
|
+ sqlSub.append("doctor_id != ").append(doctorId).append(" and ");
|
|
|
+ }
|
|
|
+ String sqlSubStr = sqlSub.substring(0, sqlSub.lastIndexOf("and"));
|
|
|
+ whereSql += String.format(" and ((%s) or doctor_id is null)", sqlSubStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1-待支付; 2-配送中/待取药; 3-已完成
|
|
|
+ * 4-已退费; 5-已过期; 10-退费中
|
|
|
+ */
|
|
|
+ if (!Checker.isNone(request.getStatus())) {
|
|
|
+ int statusInt = Integer.parseInt(request.getStatus());
|
|
|
+ int pharmacyIdInt = authService.getCurrentPharmacyId();
|
|
|
+ int selectPharmacyIdInt = Checker.isNone(selectPharmacyId) ? 0 : Integer.parseInt(selectPharmacyId);
|
|
|
+ // todo: 这是暂时的做法,后续需要优化
|
|
|
+ boolean bl = pharmacyIdInt == ConstantDef.GS_PHARMACY_ID || pharmacyIdInt == ConstantDef.GUANGSAN_ID || pharmacyIdInt == 1 || pharmacyIdInt == 4 || pharmacyIdInt == 5 || pharmacyIdInt == 12 || pharmacyIdInt == 13 || pharmacyIdInt == 14
|
|
|
+ || request.getPharmacyId() == ConstantDef.GS_PHARMACY_ID || request.getPharmacyId() == ConstantDef.GUANGSAN_ID ||request.getPharmacyId() == 1 || request.getPharmacyId() == 4 || request.getPharmacyId() == 5 || request.getPharmacyId() == 12 || request.getPharmacyId() == 13 || request.getPharmacyId() == 14
|
|
|
+ || selectPharmacyIdInt == ConstantDef.GS_PHARMACY_ID || selectPharmacyIdInt == ConstantDef.GUANGSAN_ID || selectPharmacyIdInt == 1 || selectPharmacyIdInt == 4 || selectPharmacyIdInt == 5 || selectPharmacyIdInt == 12 || selectPharmacyIdInt == 13 || selectPharmacyIdInt == 14;
|
|
|
+ if (bl) {
|
|
|
+ // 退费中
|
|
|
+ if (statusInt == 10) {
|
|
|
+ whereSql += " and ( refund_status = ? ) ";
|
|
|
+ paramList.add(RefundStatusEnum.PENDING.getValue());
|
|
|
+ } else {
|
|
|
+ whereSql += " and ( status = ? and (refund_status != ? or refund_status is null) ) ";
|
|
|
+ paramList.add(Integer.parseInt(request.getStatus()));
|
|
|
+ paramList.add(RefundStatusEnum.PENDING.getValue());
|
|
|
+ }
|
|
|
+ } else if (authService.getCurrentPharmacyId() == ConstantDef.GK_PHARMACY_ID) {
|
|
|
+ // 国控大药房状态:1-待支付、2-待取药、3-已退费、4-已过期
|
|
|
+ switch (statusInt) {
|
|
|
+ case 2:
|
|
|
+ whereSql += " and ( status = 2 or status = 3) ";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ whereSql += " and ( status = 4) ";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ whereSql += " and ( status = 5) ";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ whereSql += " and ( status = ?) ";
|
|
|
+ paramList.add(statusInt);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNone(request.getPaymentStatus())) {
|
|
|
+ whereSql += " and ( payment_status = ? ) ";
|
|
|
+ paramList.add(Integer.parseInt(request.getPaymentStatus()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNone(request.getPreBizNo())) {
|
|
|
+ whereSql += " and ( pre_biz_no like ? ) ";
|
|
|
+ paramList.add("%" + request.getPreBizNo().trim() + "%");
|
|
|
+ }
|
|
|
+ if (!Checker.isNone(request.getBizNo3th())) {
|
|
|
+ whereSql += " and ( biz_no_3th like ? ) ";
|
|
|
+ paramList.add("%" + request.getBizNo3th().trim() + "%");
|
|
|
+ }
|
|
|
+ if (!Checker.isNone(request.getOrderNo())) {
|
|
|
+ whereSql += " and ( order_no like ? ) ";
|
|
|
+ paramList.add("%" + request.getOrderNo().trim() + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNone(request.getPaymentChannel())) {
|
|
|
+ whereSql += " and ( payment_channel = ? ) ";
|
|
|
+ paramList.add(Integer.parseInt(request.getPaymentChannel()));
|
|
|
+ }
|
|
|
+
|
|
|
+ String Format_Date = "yyyy-MM-dd";
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat(Format_Date);
|
|
|
+ String createTimeEnd = request.getCreateTimeEnd();
|
|
|
+ String createTimeStart = request.getCreateTimeStart();
|
|
|
+ String payTimeEnd = request.getPayTimeEnd();
|
|
|
+ String payTimeStart = request.getPayTimeStart();
|
|
|
+ String refundTimeEnd = request.getRefundTimeEnd();
|
|
|
+ String refundTimeStart = request.getRefundTimeStart();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 创建时间
|
|
|
+ if (!Checker.isNull(createTimeEnd)) {
|
|
|
+ whereSql += " and ( create_on < ?)";
|
|
|
+ Date date = format.parse(createTimeEnd);
|
|
|
+ //把日期往后增加一天.整数往后推,负数往前移动
|
|
|
+ Calendar calendar = new GregorianCalendar();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ //这个时间就是日期往后推一天的结果
|
|
|
+ date = calendar.getTime();
|
|
|
+
|
|
|
+ paramList.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!Checker.isNull(createTimeStart)) {
|
|
|
+ whereSql += " and ( create_on >= ?)";
|
|
|
+ Date date = format.parse(createTimeStart);
|
|
|
+ paramList.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 支付时间
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNull(payTimeStart)) {
|
|
|
+ whereSql += " and ( pay_time >= ?)";
|
|
|
+ Date date = format.parse(payTimeStart);
|
|
|
+ paramList.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 退费时间搜索
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNull(refundTimeStart)) {
|
|
|
+ whereSql += " and ( refund_time >= ?)";
|
|
|
+ Date date = format.parse(refundTimeStart);
|
|
|
+ paramList.add(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNull(request.getSource())) {
|
|
|
+ whereSql += " and ( source = ?)";
|
|
|
+ paramList.add(Integer.parseInt(request.getSource()));
|
|
|
+ }
|
|
|
+ if (!Checker.isNull(request.getReceiveStatus())) {
|
|
|
+ int receiveStatusInt = Integer.parseInt(request.getReceiveStatus());
|
|
|
+ // receiveStatus: 1-成功,2-失败
|
|
|
+ if (receiveStatusInt == 1) {
|
|
|
+ whereSql += " and ( sinopharm & ? = ?)";
|
|
|
+ paramList.add(SinopharmEnum.CONFIRM_ORDER.getValue());
|
|
|
+ paramList.add(SinopharmEnum.CONFIRM_ORDER.getValue());
|
|
|
+ } else {
|
|
|
+ whereSql += " and ( sinopharm & ? = ?)";
|
|
|
+ paramList.add(SinopharmEnum.Failure.getValue());
|
|
|
+ paramList.add(SinopharmEnum.Failure.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Checker.isNull(selectPharmacyId)) {
|
|
|
+ whereSql += " and pharmacy_id = ? ";
|
|
|
+ paramList.add(Integer.parseInt(selectPharmacyId));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!Checker.isNull(request.getPatientNo())) {
|
|
|
+ whereSql += " and patient_no = ? ";
|
|
|
+ paramList.add(request.getPatientNo().trim());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // logger.info("buildQueryPrescriptionListSQLParam(): whereSql = " + whereSql);
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("whereSql", whereSql);
|
|
|
+ map.put("paramList", paramList);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+}
|