ct 2 днів тому
батько
коміт
e9ff382061

+ 7 - 1
fs-admin/src/main/java/com/fs/his/controller/FsStoreOrderController.java

@@ -201,7 +201,13 @@ public class FsStoreOrderController extends BaseController
             return AjaxResult.error("请筛选数据导出");
         }
         logger.info("tc>\n【咨询报告】:{}", SecurityUtils.getUserId());
-        Long count = fsStoreOrderService.selectFsStoreOrderListVOByExportCount(param);
+        Long count;
+        if (StringUtils.isNotBlank(param.getErpAccount())){
+            //金牛erp查询
+            count = fsStoreOrderService.selectFsStoreOrderListVOByErpAccountByExportCount(param);
+        } else {
+            count = fsStoreOrderService.selectFsStoreOrderListVOByExportCount(param);
+        }
         if (count>30000){
             return AjaxResult.error("导出数据不可超过3w条");
         }

+ 49 - 2
fs-service/src/main/java/com/fs/his/mapper/FsStoreOrderMapper.java

@@ -763,8 +763,27 @@ public interface FsStoreOrderMapper
             "<if test = 'maps.qwSubject == \"-1\"   '> " +
             "and so.qw_subject is null " +
             "</if>" +
-            " ${maps.params.dataScope} "+
-            " order by so.order_id desc" +
+            " ${maps.params.dataScope}\n" +
+            "        ORDER BY\n" +
+            "\n" +
+            "        <if test=\"maps.sortField == 'companyUserName'\">\n" +
+            "            cu.nick_name\n" +
+            "        </if>\n" +
+            "        <if test=\"maps.sortField == 'packageName'\">\n" +
+            "            so.package_name\n" +
+            "        </if>\n" +
+            "        <if test=\"maps.sortField == 'payPrice'\">\n" +
+            "            so.pay_price\n" +
+            "        </if>\n" +
+            "        <if test=\"maps.sortField == 'payMoney'\">\n" +
+            "            so.pay_money\n" +
+            "        </if>\n" +
+            "        <if test=\"maps.sortOrder != null and maps.sortOrder != ''\">\n" +
+            "            ${maps.sortOrder}\n" +
+            "        </if>\n" +
+            "        <if test=\"maps.sortField == null or maps.sortField == ''\">\n" +
+            "            so.order_id desc\n" +
+            "        </if>"+
             " limit 30000 "+
             "</script>"})
     List<FsStoreOrderExportVO> selectFsStoreOrderListVOByExport(@Param("maps") FsStoreOrderParam param);
@@ -877,6 +896,12 @@ public interface FsStoreOrderMapper
             "            <if test=\"maps.packageSecondName != null and maps.packageSecondName != '' \"> and so.package_second_name like concat('%', #{maps.packageSecondName}, '%')</if>"+
             "            <if test=\"maps.storeId != null \"> and so.store_id = #{maps.storeId}</if>\n" +
             "            <if test=\"maps.orderCode != null  and maps.orderCode != ''\"> and so.order_code = #{maps.orderCode}</if>\n" +
+            " <if test=\"maps.orderCodes != null  and maps.orderCodes.size > 0\">\n" +
+            "            and so.order_code in\n" +
+            "            <foreach collection=\"maps.orderCodes\" item=\"orderCode\" open=\"(\" close=\")\" separator=\",\">\n" +
+            "                #{orderCode}\n" +
+            "            </foreach>\n" +
+            "        </if>" +
             "            <if test=\"maps.prescribeCode != null  and maps.prescribeCode != ''\"> and p.prescribe_code = #{maps.prescribeCode}</if>\n" +
             "            <if test=\"maps.userName != null  and maps.userName != ''\"> and so.user_name like concat('%', #{maps.userName}, '%')</if>\n" +
             "            <if test=\"maps.userPhone != null  and maps.userPhone != ''\"> and so.user_phone = #{maps.userPhone}</if>\n" +
@@ -908,6 +933,12 @@ public interface FsStoreOrderMapper
             "            <if test=\"maps.tuieTime != null \">  and DATE(so.tui_money_time) &lt;= DATE(#{maps.tuieTime})</if>\n" +
             "            <if test=\"maps.companyUserNickName != null and  maps.companyUserNickName !='' \"> and cu.nick_name like concat( #{maps.companyUserNickName}, '%')"+
             "</if>" +
+            "<if test=\"maps.companyIds != null and  maps.companyIds.size >0\">\n" +
+            "            and so.company_id in\n" +
+            "            <foreach collection=\"maps.companyIds\" item=\"companyId\" open=\"(\" close=\")\" separator=\",\">\n" +
+            "                #{companyId}\n" +
+            "            </foreach>\n" +
+            "        </if>" +
             "<if test = 'maps.companyId != null  and   maps.companyId != \"-1\" '> " +
             "and so.company_id =#{maps.companyId} " +
             "</if>" +
@@ -980,6 +1011,12 @@ public interface FsStoreOrderMapper
             "            <if test=\"maps.storeId != null \"> and so.store_id = #{maps.storeId}</if>\n" +
             "            <if test=\"maps.source != null \"> and so.source = #{maps.source}</if>\n" +
             "            <if test=\"maps.orderCode != null  and maps.orderCode != ''\"> and so.order_code = #{maps.orderCode}</if>\n" +
+            "            <if test=\"maps.orderCodes != null  and maps.orderCodes.size > 0\">\n" +
+            "               and so.order_code in\n" +
+            "               <foreach collection=\"maps.orderCodes\" item=\"orderCode\" open=\"(\" close=\")\" separator=\",\">\n" +
+            "                #{orderCode}\n" +
+            "               </foreach>\n" +
+            "            </if>" +
             "            <if test=\"maps.prescribeCode != null  and maps.prescribeCode != ''\"> and p.prescribe_code = #{maps.prescribeCode}</if>\n" +
             "            <if test=\"maps.userName != null  and maps.userName != ''\"> and so.user_name like concat('%', #{maps.userName}, '%')</if>\n" +
             "            <if test=\"maps.userPhone != null  and maps.userPhone != ''\"> and so.user_phone = #{maps.userPhone}</if>\n" +
@@ -1020,6 +1057,12 @@ public interface FsStoreOrderMapper
 
             " and cu.nick_name like concat( #{maps.companyUserNickName}, '%') " +
             "</if>" +
+            "<if test=\"maps.companyIds != null and  maps.companyIds.size >0\">\n" +
+            "and so.company_id in\n" +
+            "<foreach collection=\"maps.companyIds\" item=\"companyId\" open=\"(\" close=\")\" separator=\",\">\n" +
+            "#{companyId}\n" +
+            "</foreach>\n" +
+            "</if>" +
             "<if test = 'maps.companyId != null  and   maps.companyId != \"-1\" '> " +
             "and so.company_id =#{maps.companyId} " +
             "</if>" +
@@ -1116,4 +1159,8 @@ public interface FsStoreOrderMapper
     List<FsStoreOrderListVO> selectFsStoreOrderListVOByErpAccount(@Param("maps") FsStoreOrderParam fsStoreOrder);
 
     List<FsStoreOrder> selectFsStoreOrderByFsUserId(@Param("fsUserId") Long fsUserId);
+
+    Long selectFsStoreOrderListVOByErpAccountByExportCount(@Param("maps")FsStoreOrderParam param);
+
+    List<FsStoreOrderErpExportVO> selectFsStoreOrderListErpVOByExport(@Param("maps")FsStoreOrderParam fsStoreOrder);
 }

+ 2 - 0
fs-service/src/main/java/com/fs/his/param/FsStoreOrderParam.java

@@ -152,7 +152,9 @@ public class FsStoreOrderParam extends BaseEntity implements Serializable {
     /** $column.columnComment */
     @JsonFormat(pattern = "yyyy-MM-dd")
     private Date finishTime;
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date sTime;
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date eTime;
     private Date paysTime;
     private Date payeTime;

+ 2 - 0
fs-service/src/main/java/com/fs/his/service/IFsStoreOrderService.java

@@ -258,4 +258,6 @@ public interface IFsStoreOrderService
     List<FsStoreOrder> selectFsStoreOrderByFsUserId(Long fsUserId);
 
     String importOrderStatusData(List<FsStoreOrderStatusExcelVO> list);
+
+    Long selectFsStoreOrderListVOByErpAccountByExportCount(FsStoreOrderParam param);
 }

+ 47 - 6
fs-service/src/main/java/com/fs/his/service/impl/FsExportTaskServiceImpl.java

@@ -4,14 +4,18 @@ import java.util.Date;
 import java.util.List;
 
 import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.utils.ParseUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.config.cloud.CloudHostProper;
+import com.fs.his.domain.FsStoreOrderDf;
 import com.fs.his.mapper.FsStoreOrderMapper;
 import com.fs.his.mapper.FsStorePaymentMapper;
 import com.fs.his.param.FsStoreOrderParam;
 import com.fs.his.param.FsStorePaymentParam;
 import com.fs.his.service.IFsStoreOrderService;
 import com.fs.his.utils.PhoneUtil;
+import com.fs.his.vo.FsStoreOrderErpExportVO;
 import com.fs.his.vo.FsStoreOrderExcelVO;
 import com.fs.his.vo.FsStoreOrderExportVO;
 import com.fs.his.vo.FsStorePaymentExcelVO;
@@ -36,8 +40,10 @@ public class FsExportTaskServiceImpl implements IFsExportTaskService
     @Autowired
     FsStoreOrderMapper fsStoreOrderMapper;
     @Autowired
-
     FsStorePaymentMapper fsStorePaymentMapper;
+
+    @Autowired
+    private CloudHostProper cloudHostProper;
     /**
      * 查询导出任务
      *
@@ -119,10 +125,44 @@ public class FsExportTaskServiceImpl implements IFsExportTaskService
     @Async
     @Override
     public void exportStore1Data(FsStoreOrderParam fsStoreOrder,boolean isAdmin) {
-        List<FsStoreOrderExportVO> list = fsStoreOrderMapper.selectFsStoreOrderListVOByExport(fsStoreOrder);
+        if ("金牛明医".equals(cloudHostProper.getCompanyName())){
+            exportErpData(fsStoreOrder, isAdmin);
+        } else {
+            List<FsStoreOrderExportVO> list = fsStoreOrderMapper.selectFsStoreOrderListVOByExport(fsStoreOrder);
+            //对手机号脱敏
+            if (list != null) {
+                for (FsStoreOrderExportVO vo : list) {
+                    vo.setFollowFrequency(6);
+                    if (vo.getCycle()!=null){
+                        vo.setFollowCount(vo.getCycle()/ vo.getFollowFrequency());
+                    }
+                    if (vo.getUserPhone() != null &&  !isAdmin) {
+                        vo.setUserPhone(vo.getUserPhone().replaceAll("(\\d{3})\\d*(\\d{4})", "$1****$2"));
+                    }
+                    if (vo.getUserPhone() != null && isAdmin && vo.getUserPhone().length()>11) {
+                        vo.setUserPhone(PhoneUtil.decryptPhone(vo.getUserPhone()));
+                    }
+                    if (vo.getUserAddress() != null) {
+                        vo.setUserAddress(ParseUtils.parseAddress(vo.getUserAddress()));
+                    }
+                }
+            }
+            ExcelUtil<FsStoreOrderExportVO> util = new ExcelUtil<FsStoreOrderExportVO>(FsStoreOrderExportVO.class);
+            AjaxResult result= util.exportExcel(list, "订单数据");
+            FsExportTask task=fsExportTaskMapper.selectFsExportTaskByTaskId(fsStoreOrder.getTaskId());
+            task.setFinishTime(new Date());
+            task.setStatus(1);
+            task.setFileUrl(result.get("msg").toString());
+            fsExportTaskMapper.updateFsExportTask(task);
+        }
+
+    }
+
+    private void exportErpData(FsStoreOrderParam fsStoreOrder, boolean isAdmin) {
+        List<FsStoreOrderErpExportVO> erpList = fsStoreOrderMapper.selectFsStoreOrderListErpVOByExport(fsStoreOrder);
         //对手机号脱敏
-        if (list != null) {
-            for (FsStoreOrderExportVO vo : list) {
+        if (erpList != null) {
+            for (FsStoreOrderErpExportVO vo : erpList) {
                 vo.setFollowFrequency(6);
                 if (vo.getCycle()!=null){
                     vo.setFollowCount(vo.getCycle()/ vo.getFollowFrequency());
@@ -138,14 +178,15 @@ public class FsExportTaskServiceImpl implements IFsExportTaskService
                 }
             }
         }
-        ExcelUtil<FsStoreOrderExportVO> util = new ExcelUtil<FsStoreOrderExportVO>(FsStoreOrderExportVO.class);
-        AjaxResult result= util.exportExcel(list, "订单数据");
+        ExcelUtil<FsStoreOrderErpExportVO> util = new ExcelUtil<FsStoreOrderErpExportVO>(FsStoreOrderErpExportVO.class);
+        AjaxResult result= util.exportExcel(erpList, "订单数据");
         FsExportTask task=fsExportTaskMapper.selectFsExportTaskByTaskId(fsStoreOrder.getTaskId());
         task.setFinishTime(new Date());
         task.setStatus(1);
         task.setFileUrl(result.get("msg").toString());
         fsExportTaskMapper.updateFsExportTask(task);
     }
+
     @Async
     @Override
     public void exportStoreData(FsStoreOrderParam fsStoreOrder) {

+ 5 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsStoreOrderServiceImpl.java

@@ -3549,4 +3549,9 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService {
         return successMsg.toString();
     }
 
+    @Override
+    public Long selectFsStoreOrderListVOByErpAccountByExportCount(FsStoreOrderParam param) {
+        return fsStoreOrderMapper.selectFsStoreOrderListVOByErpAccountByExportCount(param);
+    }
+
 }

+ 12 - 0
fs-service/src/main/java/com/fs/his/vo/FsStoreOrderErpExportVO.java

@@ -0,0 +1,12 @@
+package com.fs.his.vo;
+
+import com.fs.common.annotation.Excel;
+import lombok.Data;
+
+@Data
+public class FsStoreOrderErpExportVO extends FsStoreOrderExportVO{
+    @Excel(name = "ERP电话",sort = 1)
+    private String erpPhone;
+    @Excel(name = "ERP账户",sort = 2)
+    private String erpAccount;
+}

+ 465 - 0
fs-service/src/main/resources/mapper/his/FsStoreOrderMapper.xml

@@ -1134,4 +1134,469 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where user_id = #{fsUserId} and create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
         order by create_time desc limit 3
     </select>
+    <select id="selectFsStoreOrderListVOByErpAccountByExportCount" resultType="java.lang.Long">
+        select count(1)
+        from fs_store_order so
+        LEFT JOIN fs_store st ON so.store_id =st.store_id
+        left join fs_user u on so.user_id=u.user_id
+        LEFT JOIN fs_prescribe p ON p.prescribe_id =so.prescribe_id
+        LEFT JOIN fs_doctor d ON p.doctor_id= d.doctor_id
+        left join company c on c.company_id=so.company_id
+        left join company_user cu on cu.user_id=so.company_user_id
+        left join company_tcm_schedule cts on cts.id = so.schedule_id
+        left join fs_patient pat on pat.patient_id = p.patient_id
+        LEFT JOIN fs_store_order_df df on df.order_id=so.order_id
+        WHERE so.is_del=0
+        <if test="maps.packageSecondName != null and maps.packageSecondName != '' ">
+            and so.package_second_name like concat('%', #{maps.packageSecondName}, '%')
+        </if>
+        <if test="maps.storeId != null ">
+            and so.store_id = #{maps.storeId}
+        </if>
+        <if test="maps.source != null ">
+            and so.source = #{maps.source}
+        </if>
+        <if test="maps.orderCodes != null  and maps.orderCodes.size > 0">
+            and so.order_code in
+            <foreach collection="maps.orderCodes" item="orderCode" open="(" close=")" separator=",">
+                #{orderCode}
+            </foreach>
+        </if>
+        <if test="maps.orderCode != null  and maps.orderCode != ''">
+            and so.order_code = #{maps.orderCode}
+        </if>
+        <if test="maps.prescribeCode != null  and maps.prescribeCode != ''">
+            and p.prescribe_code = #{maps.prescribeCode}
+        </if>
+        <if test="maps.userName != null  and maps.userName != ''">
+            and so.user_name like concat('%', #{maps.userName}, '%')
+        </if>
+        <if test="maps.userPhone != null  and maps.userPhone != ''">
+            and so.user_phone = #{maps.userPhone}
+        </if>
+        <if test="maps.totalNum != null  and maps.totalNum != ''">
+            and so.total_num = #{maps.totalNum}
+        </if>
+        <if test="maps.totalPrice != null">
+            and so.total_price = #{maps.totalPrice}
+        </if>
+        <if test="maps.status != null and maps.status != 6">
+            and so.status = #{maps.status}
+        </if>
+        <if test="maps.status == 6">
+            and so.`status`= 2
+            and ( so.store_id in (select store_id from fs_store where delivery_type=2 or delivery_type=1))
+            and  (so.extend_order_id is null or  so.extend_order_id like '')
+        </if>
+        <if test="maps.refundStatus != null  and maps.refundStatus != ''">
+            and so.refund_status = #{maps.refundStatus}
+        </if>
+        <if test="maps.refundExplain != null  and maps.refundExplain != ''">
+            and so.refund_explain = #{maps.refundExplain}
+        </if>
+        <if test="maps.deliverySn != null  and maps.deliverySn != ''">
+            and so.delivery_sn = #{maps.deliverySn}
+        </if>
+        <if test="maps.shippingType != null">
+            and so.shipping_type = #{maps.shippingType}
+        </if>
+        <if test="maps.isChannel != null and maps.isChannel != ''">
+            and so.is_channel = #{maps.isChannel}
+        </if>
+        <if test="maps.isPrescribe != null">
+            and so.is_prescribe = #{maps.isPrescribe}
+        </if>
+        <if test="maps.prescribeId != null">
+            and so.prescribe_id = #{maps.prescribeId}
+        </if>
+        <if test="maps.companyUserId != null">
+            and so.company_user_id = #{maps.companyUserId}
+        </if>
+        <if test="maps.sTime != null">
+            and DATE(so.create_time) &gt;= DATE(#{maps.sTime})
+        </if>
+        <if test="maps.eTime != null">
+            and DATE(so.create_time) &lt;= DATE(#{maps.eTime})
+        </if>
+        <if test="maps.paysTime != null">
+            and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})
+        </if>
+        <if test="maps.payeTime != null">
+            and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})
+        </if>
+        <if test="maps.orderCreateType != null">
+            and so.order_create_type = #{maps.orderCreateType}
+        </if>
+        <if test="maps.patientName != null">
+            and p.patient_name like concat('%', #{maps.patientName}, '%')
+        </if>
+        <if test="maps.doctorName != null">
+            and d.doctor_name like concat('%', #{maps.doctorName}, '%')
+        </if>
+        <if test="maps.orderType != null">
+            and so.order_type = #{maps.orderType}
+        </if>
+        <if test="maps.deliverySendsTime != null ">
+            and DATE(so.delivery_send_time) &gt;= DATE(#{maps.deliverySendsTime})
+        </if>
+        <if test="maps.deliverySendeTime != null">
+            and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})
+        </if>
+        <if test="maps.deliveryImportsTime != null">
+            and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})
+        </if>
+        <if test="maps.deliveryImporteTime != null">
+            and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})
+        </if>
+        <if test="maps.tuisTime != null ">
+            and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})
+        </if>
+        <if test="maps.tuieTime != null">
+            and DATE(so.tui_money_time) &lt;= DATE(#{maps.tuieTime})
+        </if>
+        <if test = "maps.companyUserNickName != null and  maps.companyUserNickName !=  '' ">
+            and cu.nick_name like concat( #{maps.companyUserNickName}, '%')
+        </if>
+        <if test="maps.companyIds != null and  maps.companyIds.size >0">
+            and so.company_id in
+            <foreach collection="maps.companyIds" item="companyId" open="(" close=")" separator=",">
+                #{companyId}
+            </foreach>
+        </if>
+        <if test = "maps.companyId != null  and   maps.companyId != '-1' ">
+            and so.company_id =#{maps.companyId}
+        </if>
+        <if test="maps.userId != null ">
+            and so.user_id = #{maps.userId}</if>
+        <if test = "maps.companyId == '-1' ">
+            and so.company_id is null
+        </if>
+        <if test = "maps.deliveryStatus != null">
+            and so.delivery_status =#{maps.deliveryStatus}
+        </if>
+        <if test = "maps.deliveryPayStatus != null">
+            and so.delivery_pay_status =#{maps.deliveryPayStatus}
+        </if>
+        <if test = "maps.tuiMoneyStatus != null">
+            and so.tui_money_status =#{maps.tuiMoneyStatus}
+        </if>
+        <if test = "maps.deptId != null">
+            AND (so.dept_id = #{maps.deptId} OR so.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) ))
+        </if>
+        <if test="maps.packageName != null and maps.packageName != '' ">
+         and so.package_name like concat('%', #{maps.packageName}, '%')
+        </if>
+        <if test = "maps.payType != null">
+            and so.pay_type IN
+            <foreach collection="maps.payType.split(',')"  item='item' index='index'  open='(' separator=',' close=')'>
+                #{item}
+            </foreach>
+        </if>
+        <if test = "maps.scheduleId != null  and  maps.scheduleId != '-1' " >
+            and so.schedule_id IN
+            <foreach collection="maps.scheduleId.split(',')"  item='item' index='index'  open='(' separator=',' close=')'>
+             #{item}
+            </foreach>
+        </if>
+        <if test = "maps.scheduleId == '-1' "  >
+            and so.schedule_id is null
+        </if>
+        <if test = "maps.orderBuyType != null  and  maps.orderBuyType != '-1'">
+            and so.order_buy_type IN
+            <foreach collection="maps.orderBuyType.split(',')"  item='item' index='index'  open='(' separator=',' close=')'>
+                #{item}
+            </foreach>
+        </if>
+        <if test = "maps.orderBuyType == '-1' " >
+            and so.order_buy_type is null
+        </if>
+        <if test = "maps.orderChannel != null  and  maps.orderChannel != '-1' " >
+            and so.order_channel IN
+            <foreach collection="maps.orderChannel.split(',')"  item='item' index='index'  open='(' separator=',' close=')'>
+                #{item}
+            </foreach>
+        </if>
+        <if test = "maps.orderChannel == '-1'">
+            and so.order_channel is null
+        </if>
+        <if test = "maps.qwSubject != null  and  maps.qwSubject != '-1'">
+            and so.qw_subject IN
+            <foreach collection="maps.qwSubject.split(',')"  item='item' index='index'  open='(' separator=',' close=')'>
+                #{item}
+        </foreach>
+        </if>
+        <if test ="maps.qwSubject == '-1' ">
+            and so.qw_subject is null
+        </if>
+        <if test="maps.erpPhoneNumber != null and maps.erpPhoneNumber != ''">
+            and so.erp_phone like concat(#{maps.erpPhoneNumber},'%')
+        </if>
+        <if test="maps.erpAccount != null and maps.erpAccount != '未分拣' and maps.erpAccount != ''">
+            and df.login_account like #{maps.erpAccount}
+        </if>
+        <if test="maps.erpAccount == '未分拣'">
+            and ( df.login_account is null or df.login_account like '')
+        </if>
+        ${maps.params.dataScope}
+    </select>
+    <select id="selectFsStoreOrderListErpVOByExport" resultType="com.fs.his.vo.FsStoreOrderErpExportVO">
+        SELECT
+        so.*,
+        u.nick_name,
+        u.phone,
+        p.patient_name,
+        TIMESTAMPDIFF(YEAR, pat.birthday, CURDATE()) AS age,
+        pat.sex,
+        p.prescribe_code,
+        d.doctor_name,
+        pat.relation,
+        CONCAT(u.nick_name, '(', LEFT(u.phone, 3), '****', RIGHT(u.phone, 4), ')') AS `user`,
+        c.company_name,
+        cu.nick_name AS company_user_nick_name,
+        cts.name AS schedule_name,
+        st.store_name,df.login_account as erp_account
+        FROM fs_store_order so
+        LEFT JOIN fs_store st ON so.store_id = st.store_id
+        LEFT JOIN fs_user u ON so.user_id = u.user_id
+        LEFT JOIN fs_prescribe p ON p.prescribe_id = so.prescribe_id
+        LEFT JOIN fs_doctor d ON p.doctor_id = d.doctor_id
+        LEFT JOIN company c ON c.company_id = so.company_id
+        LEFT JOIN company_user cu ON cu.user_id = so.company_user_id
+        LEFT JOIN company_tcm_schedule cts ON cts.id = so.schedule_id
+        LEFT JOIN fs_patient pat ON pat.patient_id = p.patient_id
+        LEFT JOIN fs_store_order_df df on df.order_id=so.order_id
+        WHERE so.is_del = 0
+
+        <!-- 动态条件 -->
+        <if test="maps.packageSecondName != null and maps.packageSecondName != ''">
+            AND so.package_second_name LIKE CONCAT('%', #{maps.packageSecondName}, '%')
+        </if>
+        <if test="maps.storeId != null">
+            AND so.store_id = #{maps.storeId}
+        </if>
+        <if test="maps.source != null">
+            AND so.source = #{maps.source}
+        </if>
+        <if test="maps.orderCodes != null  and maps.orderCodes.size > 0">
+            and so.order_code in
+            <foreach collection="maps.orderCodes" item="orderCode" open="(" close=")" separator=",">
+                #{orderCode}
+            </foreach>
+        </if>
+        <if test="maps.orderCode != null and maps.orderCode != ''">
+            AND so.order_code = #{maps.orderCode}
+        </if>
+        <if test="maps.prescribeCode != null and maps.prescribeCode != ''">
+            AND p.prescribe_code = #{maps.prescribeCode}
+        </if>
+        <if test="maps.userName != null and maps.userName != ''">
+            AND so.user_name LIKE CONCAT('%', #{maps.userName}, '%')
+        </if>
+        <if test="maps.userPhone != null and maps.userPhone != ''">
+            AND so.user_phone = #{maps.userPhone}
+        </if>
+        <if test="maps.totalNum != null and maps.totalNum != ''">
+            AND so.total_num = #{maps.totalNum}
+        </if>
+        <if test="maps.totalPrice != null">
+            AND so.total_price = #{maps.totalPrice}
+        </if>
+        <if test="maps.status != null and maps.status != 6">
+            AND so.status = #{maps.status}
+        </if>
+        <if test="maps.status == 6">
+            AND so.`status` = 2
+            AND (
+            so.store_id IN (SELECT store_id FROM fs_store WHERE delivery_type=2 OR delivery_type=1)
+            )
+            AND (so.extend_order_id IS NULL OR so.extend_order_id = '')
+        </if>
+        <if test="maps.refundStatus != null and maps.refundStatus != ''">
+            AND so.refund_status = #{maps.refundStatus}
+        </if>
+        <if test="maps.refundExplain != null and maps.refundExplain != ''">
+            AND so.refund_explain = #{maps.refundExplain}
+        </if>
+        <if test="maps.deliverySn != null and maps.deliverySn != ''">
+            AND so.delivery_sn = #{maps.deliverySn}
+        </if>
+        <if test="maps.shippingType != null">
+            AND so.shipping_type = #{maps.shippingType}
+        </if>
+        <if test="maps.isChannel != null and maps.isChannel != ''">
+            AND so.is_channel = #{maps.isChannel}
+        </if>
+        <if test="maps.isPrescribe != null">
+            AND so.is_prescribe = #{maps.isPrescribe}
+        </if>
+        <if test="maps.prescribeId != null">
+            AND so.prescribe_id = #{maps.prescribeId}
+        </if>
+        <if test="maps.companyUserId != null">
+            AND so.company_user_id = #{maps.companyUserId}
+        </if>
+        <if test="maps.sTime != null">
+            AND DATE(so.create_time) &gt;= DATE(#{maps.sTime})
+        </if>
+        <if test="maps.eTime != null">
+            AND DATE(so.create_time) &lt;= DATE(#{maps.eTime})
+        </if>
+        <if test="maps.paysTime != null">
+            AND DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})
+        </if>
+        <if test="maps.payeTime != null">
+            AND DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})
+        </if>
+        <if test="maps.orderCreateType != null">
+            AND so.order_create_type = #{maps.orderCreateType}
+        </if>
+        <if test="maps.patientName != null">
+            AND p.patient_name LIKE CONCAT('%', #{maps.patientName}, '%')
+        </if>
+        <if test="maps.doctorName != null">
+            AND d.doctor_name LIKE CONCAT('%', #{maps.doctorName}, '%')
+        </if>
+        <if test="maps.orderType != null">
+            AND so.order_type = #{maps.orderType}
+        </if>
+        <if test="maps.deliverySendsTime != null">
+            AND DATE(so.delivery_send_time) &gt;= DATE(#{maps.deliverySendsTime})
+        </if>
+        <if test="maps.deliverySendeTime != null">
+            AND DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})
+        </if>
+        <if test="maps.deliveryImportsTime != null">
+            AND DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})
+        </if>
+        <if test="maps.deliveryImporteTime != null">
+            AND DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})
+        </if>
+        <if test="maps.tuisTime != null">
+            AND DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})
+        </if>
+        <if test="maps.tuieTime != null">
+            AND DATE(so.tui_money_time) &lt;= DATE(#{maps.tuieTime})
+        </if>
+        <if test="maps.companyUserNickName != null and maps.companyUserNickName != ''">
+            AND cu.nick_name LIKE CONCAT(#{maps.companyUserNickName}, '%')
+        </if>
+        <if test="maps.userId != null">
+            AND so.user_id = #{maps.userId}
+        </if>
+        <if test="maps.companyIds != null and  maps.companyIds.size >0">
+            and so.company_id in
+            <foreach collection="maps.companyIds" item="companyId" open="(" close=")" separator=",">
+                #{companyId}
+            </foreach>
+        </if>
+        <choose>
+            <when test="maps.companyId != null and maps.companyId == '-1'">
+                AND so.company_id IS NULL
+            </when>
+            <when test="maps.companyId != null">
+                AND so.company_id = #{maps.companyId}
+            </when>
+        </choose>
+        <if test="maps.deliveryStatus != null">
+            AND so.delivery_status = #{maps.deliveryStatus}
+        </if>
+        <if test="maps.deliveryPayStatus != null">
+            AND so.delivery_pay_status = #{maps.deliveryPayStatus}
+        </if>
+        <if test="maps.tuiMoneyStatus != null">
+            AND so.tui_money_status = #{maps.tuiMoneyStatus}
+        </if>
+        <if test="maps.deptId != null">
+            AND (so.dept_id = #{maps.deptId} OR so.dept_id IN (
+            SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors)
+            )
+        </if>
+        <if test="maps.packageName != null and maps.packageName != ''">
+            AND so.package_name LIKE CONCAT('%', #{maps.packageName}, '%')
+        </if>
+        <if test="maps.payType != null">
+            AND so.pay_type IN
+            <foreach collection="maps.payType.split(',')" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <choose>
+            <when test="maps.scheduleId != null and maps.scheduleId == '-1'">
+                AND so.schedule_id IS NULL
+            </when>
+            <when test="maps.scheduleId != null">
+                AND so.schedule_id IN
+                <foreach collection="maps.scheduleId.split(',')" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        <choose>
+            <when test="maps.orderBuyType != null and maps.orderBuyType == '-1'">
+                AND so.order_buy_type IS NULL
+            </when>
+            <when test="maps.orderBuyType != null">
+                AND so.order_buy_type IN
+                <foreach collection="maps.orderBuyType.split(',')" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        <choose>
+            <when test="maps.orderChannel != null and maps.orderChannel == '-1'">
+                AND so.order_channel IS NULL
+            </when>
+            <when test="maps.orderChannel != null">
+                AND so.order_channel IN
+                <foreach collection="maps.orderChannel.split(',')" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        <choose>
+            <when test="maps.qwSubject != null and maps.qwSubject == '-1'">
+                AND so.qw_subject IS NULL
+            </when>
+            <when test="maps.qwSubject != null">
+                AND so.qw_subject IN
+                <foreach collection="maps.qwSubject.split(',')" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        <if test="maps.erpPhoneNumber != null and maps.erpPhoneNumber != ''">
+            and so.erp_phone like concat(#{maps.erpPhoneNumber},'%')
+        </if>
+        <if test="maps.erpAccount != null and maps.erpAccount != '未分拣' and maps.erpAccount != ''">
+            and df.login_account like #{maps.erpAccount}
+        </if>
+        <if test="maps.erpAccount == '未分拣'">
+            and ( df.login_account is null or df.login_account like '')
+        </if>
+
+        ${maps.params.dataScope}
+        ORDER BY
+
+        <if test="maps.sortField == 'companyUserName'">
+            cu.nick_name
+        </if>
+        <if test="maps.sortField == 'packageName'">
+            so.package_name
+        </if>
+        <if test="maps.sortField == 'payPrice'">
+            so.pay_price
+        </if>
+        <if test="maps.sortField == 'payMoney'">
+            so.pay_money
+        </if>
+        <if test="maps.sortOrder != null and maps.sortOrder != ''">
+            ${maps.sortOrder}
+        </if>
+        <if test="maps.sortField == null or maps.sortField == ''">
+            so.order_id desc
+        </if>
+        LIMIT 30000
+
+
+    </select>
 </mapper>