package com.fs.his.mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.fs.company.param.FsStoreStatisticsParam;
import com.fs.company.vo.FsStoreOrderStatisticsVO;
import com.fs.company.vo.FsStoreProductStatisticsVO;
import com.fs.crm.domain.Report;
import com.fs.crm.param.ReportParam;
import com.fs.his.domain.FsInquiryOrderMsg;
import com.fs.his.domain.FsStoreOrder;
import com.fs.his.domain.FsStoreOrderItem;
import com.fs.his.domain.FsStoreOrderLogs;
import com.fs.his.dto.FsStoreOrderAmountStatsQueryDto;
import com.fs.his.param.*;
import com.fs.his.vo.*;
import com.fs.hisStore.domain.FsStoreOrderScrm;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 订单Mapper接口
 *
 * @author fs
 * @date 2023-06-13
 */
public interface FsStoreOrderMapper
{
    /**
     * 查询订单
     *
     * @param orderId 订单主键
     * @return 订单
     */
    public FsStoreOrder selectFsStoreOrderByOrderId(Long orderId);

    /**
     * 查询订单列表
     *
     * @param fsStoreOrder 订单
     * @return 订单集合
     */
    public List<FsStoreOrder> selectFsStoreOrderList(FsStoreOrder fsStoreOrder);

    /**
     * 新增订单
     *
     * @param fsStoreOrder 订单
     * @return 结果
     */
    public int insertFsStoreOrder(FsStoreOrder fsStoreOrder);

    /**
     * 修改订单
     *
     * @param fsStoreOrder 订单
     * @return 结果
     */
    public int updateFsStoreOrder(FsStoreOrder fsStoreOrder);

    /**
     * 删除订单
     *
     * @param orderId 订单主键
     * @return 结果
     */
    public int deleteFsStoreOrderByOrderId(String orderId);

    /**
     * 批量删除订单
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsStoreOrderByOrderIds(String[] orderIds);
    @Select("select order_id from fs_store_order where status = 3 and delivery_status = 0  and DATE(create_time)<='2024-3-1' ")
    List<Long> selectSyncExpressIds();
//    @Select({"<script> " +
//            "select so.*,st.store_name,us.nick_name,us.phone,d.doctor_name,p.patient_name,p.prescribe_code,c.company_name,cu.nick_name company_user_name " +
//            " FROM fs_store_order so LEFT JOIN fs_store st ON so.store_id =st.store_id " +
//            " LEFT JOIN fs_user us ON us.user_id=so.user_id " +
//            " LEFT JOIN fs_prescribe p ON p.prescribe_id =so.prescribe_id " +
//            " LEFT JOIN fs_doctor d ON so.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  " +
//            " WHERE 1=1 "+
//            "<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.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" +
//            "<if test=\"maps.userId != null  \"> and so.user_id = #{maps.userId}</if>\n" +
//            "<if test=\"maps.isFirst != null  \"> and so.is_first = #{maps.isFirst}</if>\n" +
//            "<if test=\"maps.status != null \"> and so.status = #{maps.status}</if>\n" +
//            "<if test=\"maps.source != null \"> and so.source = #{maps.source}</if>\n" +
//            "<if test=\"maps.deliverySn != null  and maps.deliverySn != ''\"> and so.delivery_sn = #{maps.deliverySn}</if>\n" +
//            "<if test=\"maps.prescribeId != null \"> and so.prescribe_id = #{maps.prescribeId}</if>\n" +
//            "<if test=\"maps.companyUserId != null \"> and so.company_user_id = #{maps.companyUserId}</if>\n" +
//            "<if test=\"maps.sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
//            "<if test=\"maps.eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
//            "<if test=\"maps.paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})</if>\n" +
//            "<if test=\"maps.payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})</if>\n" +
//            "<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>\n" +
//            "<if test=\"maps.deliverySendeTime != null \">  and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})</if>\n" +
//            "<if test=\"maps.deliveryImportsTime != null \">  and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})</if>\n" +
//            "<if test=\"maps.deliveryImporteTime != null \">  and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})</if>\n" +
//            "<if test=\"maps.tuisTime != null \">  and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})</if>\n" +
//            "<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> \n" +
//            "<if test = 'maps.companyId != null  and   maps.companyId != \"-1\" '> " + "and so.company_id =#{maps.companyId} " + "</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.customerId != null    '> and so.customer_id =#{maps.customerId} </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 == \"-1\"   '> and so.order_channel 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.qwSubject == \"-1\"'>and so.qw_subject 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>" +
//            " ${maps.params.dataScope} "+
//            " ORDER BY so.order_id desc "+
//            "</script>"})
    List<FsStoreOrderListVO> selectFsStoreOrderListVO(@Param("maps")FsStoreOrderParam fsStoreOrder);

    @Select({"<script> " +
            "select so.*,st.store_name,us.nick_name,us.phone,p.patient_age,p.patient_gender,p.patient_descs,p.patient_name,d.doctor_name,fp.prescribe_code FROM fs_store_order so LEFT JOIN fs_store st ON so.store_id =st.store_id LEFT JOIN fs_user us ON us.user_id=so.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 fs_prescribe fp on fp.prescribe_id=so.prescribe_id WHERE so.is_del=0 "+
            " <if test=\"storeId != null \"> and so.store_id = #{storeId}</if>\n" +
            "            <if test=\"orderCode != null  and orderCode != ''\"> and so.order_code = #{orderCode}</if>\n" +
            "            <if test=\"userId != null  and userId != ''\"> and so.user_id = #{userId}</if>\n" +
            "            <if test=\"userName != null  and userName != ''\"> and so.user_name like concat(#{userName}, '%')</if>\n" +
            "            <if test=\"userPhone != null  and userPhone != ''\"> and so.user_phone = #{userPhone}</if>\n" +
            "            <if test=\"userAddress != null  and userAddress != ''\"> and so.user_address = #{userAddress}</if>\n" +
            "            <if test=\"cartId != null  and cartId != ''\"> and so.cart_id = #{cartId}</if>\n" +
            "            <if test=\"totalNum != null  and totalNum != ''\"> and so.total_num = #{totalNum}</if>\n" +
            "            <if test=\"totalPrice != null \"> and so.total_price = #{totalPrice}</if>\n" +
            "            <if test=\"payPrice != null \"> and so.pay_price = #{payPrice}</if>\n" +
            "            <if test=\"payMoney != null \"> and so.pay_money = #{payMoney}</if>\n" +
            "            <if test=\"payTime != null \"> and so.pay_time = #{payTime}</if>\n" +
            "            <if test=\"payType != null  and payType != ''\"> and so.pay_type = #{payType}</if>\n" +
            "            <if test=\"status != null \"> and so.status = #{status}</if>\n" +
            "            <if test=\"refundStatus != null  and refundStatus != ''\"> and so.refund_status = #{refundStatus}</if>\n" +
            "            <if test=\"refundExplain != null  and refundExplain != ''\"> and so.refund_explain = #{refundExplain}</if>\n" +
            "            <if test=\"refundTime != null \"> and so.refund_time = #{refundTime}</if>\n" +
            "            <if test=\"refundReason != null  and refundReason != ''\"> and so.refund_reason = #{refundReason}</if>\n" +
            "            <if test=\"refundMoney != null \"> and so.refund_money = #{refundMoney}</if>\n" +
            "            <if test=\"deliveryCode != null  and deliveryCode != ''\"> and so.delivery_code = #{deliveryCode}</if>\n" +
            "            <if test=\"deliveryName != null  and deliveryName != ''\"> and so.delivery_name like concat('%', #{deliveryName}, '%')</if>\n" +
            "            <if test=\"deliverySn != null  and deliverySn != ''\"> and so.delivery_sn = #{deliverySn}</if>\n" +
            "            <if test=\"costPrice != null \"> and so.cost_price = #{costPrice}</if>\n" +
            "            <if test=\"shippingType != null \"> and so.shipping_type = #{shippingType}</if>\n" +
            "            <if test=\"isChannel != null  and isChannel != ''\"> and so.is_channel = #{isChannel}</if>\n" +
            "            <if test=\"isPrescribe != null \"> and so.is_prescribe = #{isPrescribe}</if>\n" +
            "            <if test=\"prescribeId != null \"> and so.prescribe_id = #{prescribeId}</if>\n" +
            "            <if test=\"finishTime != null \"> and so.finish_time = #{finishTime}</if>\n" +
            "            <if test=\"deliveryTime != null  and deliveryTime != ''\"> and so.delivery_time = #{deliveryTime}</if>\n" +
            "            <if test=\"tuiMoneyStatus != null \"> and so.tui_money_status = #{tuiMoneyStatus}</if>\n" +
            "            <if test=\"tuiUserId != null \"> and so.tui_user_id = #{tuiUserId}</if>\n" +
            "            <if test=\"sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{sTime})</if>\n" +
            "            <if test=\"eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{eTime})</if>\n" +
            "            <if test=\"paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{paysTime})</if>\n" +
            "            <if test=\"payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{payeTime})</if>\n" +
            "            <if test=\"orderCreateType != null \"> and so.order_create_type = #{orderCreateType}</if>"+
            "            <if test=\"patientName != null \"> and p.patient_name like concat('%', #{patientName}, '%')</if>"+
            "            <if test=\"doctorName != null \"> and d.doctor_name like concat('%', #{doctorName}, '%')</if>"+
            "            <if test=\"orderType != null \"> and so.order_type = #{orderType}</if>"+
            " ORDER BY so.order_id desc "+
            "</script>"})
    List<FsStoreOrderSVO> selectFsStoreOrderListSVO(FsStoreOrderListSParam fsStoreOrder);


    @Select("SELECT * FROM fs_store_order_item WHERE order_id =#{orderId}")
    List<FsStoreOrderItem> selectFsStoreOrderItemList(String orderId);

    @Select("SELECT * FROM fs_store_order_logs WHERE order_id =#{orderId}")
    List<FsStoreOrderLogs> selectFsFsStoreOrderLogsList(String orderId);

    @Select({"<script> " +
            "select o.order_id,o.bill_price,o.create_time,o.order_code,o.pay_price,o.status,o.delivery_sn,o.finish_time,o.item_json  from fs_store_order o    " +
            "where 1=1  " +
            "<if test = ' maps.userId != null '> " +
            "and o.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null     '> " +
            "and o.company_user_id = #{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.status != null and maps.status!=0    '> " +
            "and o.status = #{maps.status} " +
            "</if>" +
            " order by o.create_time desc "+
            "</script>"})
    List<FsStoreOrderListUVO> selectFsStoreOrderListUVO(@Param("maps")FsStoreOrderListUParam param);
    @Select({"<script> " +
            "select so.*,st.store_name,us.nick_name,us.phone,d.doctor_name,p.patient_name,p.prescribe_code,c.company_name,cu.nick_name company_user_name,cts.name as schedule_name,po.product_cost_price total_cost_money,po.inquiry_cost_price inquiry_money,po.total_cost_price,po.cost_discount_money inquiryDiscountMoney, total_money,p.diagnose " +
            " FROM fs_store_order so LEFT JOIN fs_store st ON so.store_id =st.store_id " +
            " LEFT JOIN fs_user us ON us.user_id=so.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_package_order po on po.order_id = so.package_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>\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" +
            "            <if test=\"maps.totalNum != null  and maps.totalNum != ''\"> and so.total_num = #{maps.totalNum}</if>\n" +
            "            <if test=\"maps.totalPrice != null \"> and so.total_price = #{maps.totalPrice}</if>\n" +
            "            <if test=\"maps.status != null \"> and so.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.source != null \"> and so.source = #{maps.source}</if>\n" +
            "            <if test=\"maps.refundStatus != null  and maps.refundStatus != ''\"> and so.refund_status = #{maps.refundStatus}</if>\n" +
            "            <if test=\"maps.refundExplain != null  and maps.refundExplain != ''\"> and so.refund_explain = #{maps.refundExplain}</if>\n" +
            "            <if test=\"maps.deliverySn != null  and maps.deliverySn != ''\"> and so.delivery_sn = #{maps.deliverySn}</if>\n" +
            "            <if test=\"maps.shippingType != null \"> and so.shipping_type = #{maps.shippingType}</if>\n" +
            "            <if test=\"maps.isChannel != null  and maps.isChannel != ''\"> and so.is_channel = #{maps.isChannel}</if>\n" +
            "            <if test=\"maps.isPrescribe != null \"> and so.is_prescribe = #{maps.isPrescribe}</if>\n" +
            "            <if test=\"maps.prescribeId != null \"> and so.prescribe_id = #{maps.prescribeId}</if>\n" +
            "            <if test=\"maps.companyUserId != null \"> and so.company_user_id = #{maps.companyUserId}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})</if>\n" +
            "            <if test=\"maps.payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})</if>\n" +
            "            <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>\n" +
            "            <if test=\"maps.deliverySendeTime != null \">  and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})</if>\n" +
            "            <if test=\"maps.deliveryImportsTime != null \">  and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})</if>\n" +
            "            <if test=\"maps.deliveryImporteTime != null \">  and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})</if>\n" +
            "            <if test=\"maps.tuisTime != null \">  and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})</if>\n" +
            "            <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.companyId != null  and   maps.companyId != \"-1\" '> " +
            "and so.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = ' maps.companyId == \"-1\" '> " +
            "and so.company_id is null " +
            "</if>" +
            "<if test=\"maps.userId != null  \"> and so.user_id = #{maps.userId}</if>\n" +
            "<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>" +
            " ${maps.params.dataScope} "+
            " ORDER BY so.order_id desc " +
            " limit 30000 "+
            "</script>"})
    List<FsStoreOrderExcelVO> selectFsStoreOrderExcelListVO(@Param("maps") FsStoreOrderParam fsStoreOrder);
    @Update({"<script> " +
            " update fs_store_order "+
            "<trim prefix=\"SET\" suffixOverrides=\",\">\n" +
            "            <if test=\"storeId != null\">store_id = #{storeId},</if>\n" +
            "            <if test=\"userId != null and userId != ''\">user_id = #{userId},</if>\n" +
            "            <if test=\"userName != null and userName != ''\">user_name = #{userName},</if>\n" +
            "            <if test=\"userPhone != null and userPhone != ''\">user_phone = #{userPhone},</if>\n" +
            "            <if test=\"userAddress != null and userAddress != ''\">user_address = #{userAddress},</if>\n" +
            "            <if test=\"cartId != null and cartId != ''\">cart_id = #{cartId},</if>\n" +
            "            <if test=\"totalNum != null and totalNum != ''\">total_num = #{totalNum},</if>\n" +
            "            <if test=\"totalPrice != null\">total_price = #{totalPrice},</if>\n" +
            "            <if test=\"payPrice != null\">pay_price = #{payPrice},</if>\n" +
            "            <if test=\"payMoney != null\">pay_money = #{payMoney},</if>\n" +
            "            <if test=\"isPay != null and isPay != ''\">is_pay = #{isPay},</if>\n" +
            "            <if test=\"payTime != null\">pay_time = #{payTime},</if>\n" +
            "            <if test=\"payType != null and payType != ''\">pay_type = #{payType},</if>\n" +
            "            <if test=\"createTime != null\">create_time = #{createTime},</if>\n" +
            "            <if test=\"updateTime != null\">update_time = #{updateTime},</if>\n" +
            "            <if test=\"status != null\">status = #{status},</if>\n" +
            "            <if test=\"refundStatus != null\">refund_status = #{refundStatus},</if>\n" +
            "            <if test=\"refundImg != null\">refund_img = #{refundImg},</if>\n" +
            "            <if test=\"refundExplain != null\">refund_explain = #{refundExplain},</if>\n" +
            "            <if test=\"refundTime != null\">refund_time = #{refundTime},</if>\n" +
            "            <if test=\"refundReason != null\">refund_reason = #{refundReason},</if>\n" +
            "            <if test=\"refundMoney != null\">refund_money = #{refundMoney},</if>\n" +
            "            <if test=\"deliveryCode != null\">delivery_code = #{deliveryCode},</if>\n" +
            "            <if test=\"deliveryName != null\">delivery_name = #{deliveryName},</if>\n" +
            "            <if test=\"deliverySn != null\">delivery_sn = #{deliverySn},</if>\n" +
            "            <if test=\"remark != null\">remark = #{remark},</if>\n" +
            "            <if test=\"isDel != null\">is_del = #{isDel},</if>\n" +
            "            <if test=\"costPrice != null\">cost_price = #{costPrice},</if>\n" +
            "            <if test=\"verifyCode != null\">verify_code = #{verifyCode},</if>\n" +
            "            <if test=\"shippingType != null\">shipping_type = #{shippingType},</if>\n" +
            "            <if test=\"isChannel != null\">is_channel = #{isChannel},</if>\n" +
            "            <if test=\"isPrescribe != null\">is_prescribe = #{isPrescribe},</if>\n" +
            "            <if test=\"prescribeId != null\">prescribe_id = #{prescribeId},</if>\n" +
            "            <if test=\"finishTime != null\">finish_time = #{finishTime},</if>\n" +
            "            <if test=\"deliveryTime != null\">delivery_time = #{deliveryTime},</if>\n" +
            "            <if test=\"tuiMoney != null\">tui_money = #{tuiMoney},</if>\n" +
            "            <if test=\"tuiMoneyStatus != null\">tui_money_status = #{tuiMoneyStatus},</if>\n" +
            "            <if test=\"tuiUserId != null\">tui_user_id = #{tuiUserId},</if>\n" +
            "            <if test=\"orderCreateType != null\">order_create_type = #{orderCreateType},</if>\n" +
            "        </trim>\n" +
            "        where order_code = #{orderCode}"+
            "</script>"})
    int updateFsStoreOrderByOrderCode(FsStoreOrder fsStoreOrder);
    @Select("SELECT * FROM fs_store_order WHERE order_code =#{orderCode}")
    FsStoreOrder selectFsStoreOrderByOrderCode(String orderCode);

    @Select("SELECT * FROM fs_store_order_scrm WHERE order_code =#{orderCode}")
    FsStoreOrderScrm selectFsStoreOrderScrmByOrderCode(String orderCode);

    @Select("select so.*,st.store_name,us.nick_name,us.phone,p.patient_age,p.patient_gender,p.patient_descs,p.patient_name," +
            "d.doctor_name,fp.prescribe_code,fd.doctor_name follow_doctor_name,c.company_name,cu.user_name company_user_name,pat.relation  " +
            "FROM fs_store_order_scrm so LEFT JOIN fs_store_scrm st ON so.store_id =st.store_id " +
            "LEFT JOIN fs_user us ON us.user_id=so.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 fs_prescribe fp on fp.prescribe_id=so.prescribe_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 fs_doctor fd on so.follow_doctor_id =fd.doctor_id " +
            "LEFT JOIN fs_patient pat ON pat.patient_id=p.patient_id  WHERE so.is_del=0  and so.id= #{orderId}")
    FsStoreOrderVO selectFsStoreOrderByOrderIdVO(@Param("orderId") Long orderId);

    @Update("update fs_store_order set status=-3 where order_id=#{orderId}")
    int cancelOrder(Long orderId);


    List<JSONObject> selectFsStoreOrderCounts(Map<String, Object> toMap);

    @Select({"<script> " +
            "select u.nick_name, count(o.order_id) as order_count,sum(IFNULL(o.pay_price,0)) as pay_price  from  fs_store_order o left join company_user u on o.company_user_id=u.user_id  " +
            "where o.status &gt; 1 " +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(o.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(o.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(o.create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(o.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(o.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(o.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(o.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(o.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "<if test = 'maps.startTime != null and maps.startTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.startTime},'%y%m%d')"+
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')"+
            "</if>" +
            "and  o.`company_user_id` IN " +
            "<foreach  item='item' index='index' collection='maps.users' open='(' separator=',' close=')'> #{item}    </foreach>"+
            " group by o.company_user_id "+
            "</script>"})
    List<FsStoreOrderStatisticsVO> selectFsStoreOrderStatisticsList(@Param("maps") FsStoreStatisticsParam param);



    @Select({"<script> " +
            "select u.nick_name, count(o.order_id) as order_count,sum(IFNULL(o.pay_price,0)) as pay_price  from  fs_package_order o left join company_user u on o.company_user_id=u.user_id  " +
            "where o.status &gt; 1 " +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(o.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(o.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(o.create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(o.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(o.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(o.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(o.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(o.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "<if test = 'maps.startTime != null and maps.startTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.startTime},'%y%m%d')"+
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')"+
            "</if>" +
            "and  o.`company_user_id` IN " +
            "<foreach  item='item' index='index' collection='maps.users' open='(' separator=',' close=')'> #{item}    </foreach>"+
            " group by o.company_user_id "+
            "</script>"})
    List<FsStoreOrderStatisticsVO> selectFsPackageOrderStatisticsList(@Param("maps")FsStoreStatisticsParam param);


    @Select({"<script> " +
            "select u.nick_name, count(o.order_id) as order_count,sum(IFNULL(o.pay_money,0)) as pay_price  from  fs_inquiry_order o left join company_user u on o.company_user_id=u.user_id  " +
            "where o.status &gt; 1 " +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(o.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(o.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(o.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(o.create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(o.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(o.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(o.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(o.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(o.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "<if test = 'maps.startTime != null and maps.startTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.startTime},'%y%m%d')"+
            "</if>" +
            "<if test = 'maps.endTime != null and maps.endTime != \"\" '> " +
            "AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')"+
            "</if>" +
            "and  o.`company_user_id` IN " +
            "<foreach  item='item' index='index' collection='maps.users' open='(' separator=',' close=')'> #{item}    </foreach>"+
            " group by o.company_user_id "+
            "</script>"})
    List<FsStoreOrderStatisticsVO> selectFsInquiryOrderStatisticsList(@Param("maps")FsStoreStatisticsParam param);


    @Select({"<script> " +
            "select so.*,st.store_name,us.nick_name,us.phone,p.patient_age,p.patient_gender,p.patient_descs,p.patient_name," +
            "d.doctor_name,fp.prescribe_code FROM fs_store_order so " +
            "LEFT JOIN fs_store st ON so.store_id =st.store_id " +
            "LEFT JOIN fs_user us ON us.user_id=so.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 fs_prescribe fp on fp.prescribe_id=so.prescribe_id " +
            "WHERE so.is_del=0  "+
            " <if test=\"storeId != null \"> and so.store_id = #{storeId}</if>\n" +
            " <if test=\"userCouponId != null \"> and so.user_coupon_id=#{userCouponId}</if>\n" +
            "            <if test=\"orderCode != null  and orderCode != ''\"> and so.order_code = #{orderCode}</if>\n" +
            "            <if test=\"userId != null  and userId != ''\"> and so.user_id = #{userId}</if>\n" +
            "            <if test=\"userName != null  and userName != ''\"> and so.user_name like concat('%', #{userName}, '%')</if>\n" +
            "            <if test=\"userPhone != null  and userPhone != ''\"> and so.user_phone = #{userPhone}</if>\n" +
            "            <if test=\"userAddress != null  and userAddress != ''\"> and so.user_address = #{userAddress}</if>\n" +
            "            <if test=\"cartId != null  and cartId != ''\"> and so.cart_id = #{cartId}</if>\n" +
            "            <if test=\"totalNum != null  and totalNum != ''\"> and so.total_num = #{totalNum}</if>\n" +
            "            <if test=\"totalPrice != null \"> and so.total_price = #{totalPrice}</if>\n" +
            "            <if test=\"payPrice != null \"> and so.pay_price = #{payPrice}</if>\n" +
            "            <if test=\"payMoney != null \"> and so.pay_money = #{payMoney}</if>\n" +
            "            <if test=\"payTime != null \"> and so.pay_time = #{payTime}</if>\n" +
            "            <if test=\"payType != null  and payType != ''\"> and so.pay_type = #{payType}</if>\n" +
            "            <if test=\"status != null \"> and so.status = #{status}</if>\n" +
            "            <if test=\"customerId != null \"> and so.customer_id = #{customerId}</if>\n" +
            "            <if test=\"refundStatus != null  and refundStatus != ''\"> and so.refund_status = #{refundStatus}</if>\n" +
            "            <if test=\"refundExplain != null  and refundExplain != ''\"> and so.refund_explain = #{refundExplain}</if>\n" +
            "            <if test=\"refundTime != null \"> and so.refund_time = #{refundTime}</if>\n" +
            "            <if test=\"refundReason != null  and refundReason != ''\"> and so.refund_reason = #{refundReason}</if>\n" +
            "            <if test=\"refundMoney != null \"> and so.refund_money = #{refundMoney}</if>\n" +
            "            <if test=\"deliveryCode != null  and deliveryCode != ''\"> and so.delivery_code = #{deliveryCode}</if>\n" +
            "            <if test=\"deliveryName != null  and deliveryName != ''\"> and so.delivery_name like concat('%', #{deliveryName}, '%')</if>\n" +
            "            <if test=\"deliverySn != null  and deliverySn != ''\"> and so.delivery_sn = #{deliverySn}</if>\n" +
            "            <if test=\"costPrice != null \"> and so.cost_price = #{costPrice}</if>\n" +
            "            <if test=\"shippingType != null \"> and so.shipping_type = #{shippingType}</if>\n" +
            "            <if test=\"isChannel != null  and isChannel != ''\"> and so.is_channel = #{isChannel}</if>\n" +
            "            <if test=\"isPrescribe != null \"> and so.is_prescribe = #{isPrescribe}</if>\n" +
            "            <if test=\"prescribeId != null \"> and so.prescribe_id = #{prescribeId}</if>\n" +
            "            <if test=\"finishTime != null \"> and so.finish_time = #{finishTime}</if>\n" +
            "            <if test=\"deliveryTime != null  and deliveryTime != ''\"> and so.delivery_time = #{deliveryTime}</if>\n" +
            "            <if test=\"tuiMoneyStatus != null \"> and so.tui_money_status = #{tuiMoneyStatus}</if>\n" +
            "            <if test=\"tuiUserId != null \"> and so.tui_user_id = #{tuiUserId}</if>\n" +
            "            <if test=\"companyId != null \"> and so.company_id = #{companyId}</if>\n" +
            "            <if test=\"companyUserId != null \"> and so.company_user_id = #{companyUserId}</if>\n" +
            "            <if test=\"sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{sTime})</if>\n" +
            "            <if test=\"eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{eTime})</if>\n" +
            "            <if test=\"paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{paysTime})</if>\n" +
            "            <if test=\"payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{payeTime})</if>\n" +
            "            <if test=\"orderCreateType != null \"> and so.order_create_type = #{orderCreateType}</if>"+
            "            <if test=\"patientName != null \"> and p.patient_name like concat('%', #{patientName}, '%')</if>"+
            "            <if test=\"doctorName != null \"> and d.doctor_name like concat('%', #{doctorName}, '%')</if>"+
            "            <if test=\"orderType != null \"> and so.order_type = #{orderType}</if>"+
            " ORDER BY so.order_id desc "+
            "</script>"})
    List<FsStoreOrderVO> selectFsStoreOrderCusListVO(FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.order_id,o.order_code,o.pay_price,o.status,o.item_json,st.store_name,p.patient_name,o.pay_money,o.pay_type,o.create_time,o.pay_time,o.delivery_status,c.company_name,u.nick_name as company_user_name from fs_store_order o    " +
            " LEFT JOIN fs_store st ON o.store_id =st.store_id " +
            " LEFT JOIN fs_prescribe p ON p.prescribe_id = o.prescribe_id " +
            "left join company c on o.company_id=c.company_id "+
            "left join company_user u on o.company_user_id=u.user_id "+
            "where 1=1  " +
            "<if test = 'maps.orderCode != null  and maps.orderCode !=\"\"    '> " +
            "and o.order_code =#{maps.orderCode} " +
            "</if>" +
            "<if test = 'maps.deliverySn != null  and maps.deliverySn !=\"\"    '> " +
            "and o.delivery_sn =#{maps.deliverySn} " +
            "</if>" +
            "<if test = 'maps.payType != null   '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.userName != null and maps.userName !=\"\"   '> " +
            "and o.user_name =#{maps.userName} " +
            "</if>" +
            "<if test = 'maps.userPhone != null and maps.userPhone !=\"\"   '> " +
            "and o.user_phone =#{maps.userPhone} " +
            "</if>" +
            "<if test = 'maps.patientName != null and maps.patientName !=\"\"    '> " +
            "and p.patient_name like concat('%', #{maps.patientName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null   '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test='maps.sTime != null ' >  " +
            "and DATE(o.create_time) &gt;= DATE(#{maps.sTime}) " +
            "</if>" +
            "<if test='maps.eTime != null ' >  " +
            "and DATE(o.create_time) &lt;= DATE(#{maps.eTime}) " +
            "</if>" +
            "<if test='maps.paysTime != null ' >  " +
            "and DATE(o.pay_time) &gt;= DATE(#{maps.paysTime}) " +
            "</if>" +
            "<if test='maps.payeTime != null ' >  " +
            "and DATE(o.pay_time) &lt;= DATE(#{maps.payeTime}) " +
            "</if>" +
            "<if test='maps.deliverySendsTime != null ' >  " +
            "and DATE(o.delivery_send_time) &gt;= DATE(#{maps.deliverySendsTime}) " +
            "</if>" +
            "<if test='maps.deliverySendeTime != null ' >  " +
            "and DATE(o.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime}) " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = ' maps.doctorId != null '> " +
            "and o.doctor_id = #{maps.doctorId} " +
            "</if>" +
            "<if test = ' maps.userId != null '> " +
            "and o.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = 'maps.status != null and maps.status!=0    '> " +
            "and o.status = #{maps.status} " +
            "</if>" +
            " order by o.create_time desc "+
            "</script>"})
    List<FsStoreOrderListDVO> selectFsStoreOrderListDVO(@Param("maps") FsStoreOrderListDParam param);


    @Select({"select * from fs_store_order  where delivery_code=#{deliveryCode}  limit 1"})
    FsStoreOrder selectFsStoreOrderByDeliveryCode(@Param("deliveryCode")String deliveryCode);
    @Select({"<script> " +
            "select count(1) from fs_store_order  " +
            "where 1=1 " +
            "<if test = 'type != null and  type ==1  '> " +
            "and  DATE_FORMAT(create_time, '%Y-%m-%d')  = DATE_FORMAT(NOW(), '%Y-%m-%d') " +
            "</if>" +
            "<if test = 'companyId != null  '> " +
            "and  company_id=#{companyId} " +
            "</if>" +
            "</script>"})
    Long selectFsStoreOrderTotalCount(@Param("type") int type, @Param("companyId") Long companyId);
    @Select("select order_id from fs_store_order WHERE `status`= 2 and  extend_order_id is null ")
    List<Long> selectFsStoreOrderNoCreateOms();
    @Select("select order_id from fs_store_order WHERE `status`= 2 and order_type=2 and store_id in(select store_id from fs_store where delivery_type=1) and  extend_order_id is null ")
    List<Long> selectFsStoreOrderNoTuiOrder();
    @Select("select * from fs_store_order o where o.delivery_sn=#{deliverySn}")
    List<FsStoreOrder> selectFsStoreOrderListByDeliverySn( @Param("deliverySn") String deliverySn);

    @Select("select * from fs_store_order o where o.delivery_sn=#{deliverySn} limit 1")
    FsStoreOrder selectFsStoreOrderListByDeliverySnLOne(String deliverySn);

    @Select("UPDATE fs_store_order SET `is_after_sales`=0 WHERE `status`=4 and DATE(finish_time) < DATE_SUB(CURDATE(), INTERVAL #{storeAfterSalesDay} DAY)")
    void updateFsStoreOrderIsAfterSales(Integer storeAfterSalesDay);
    @Select("select * from fs_store_order WHERE `status`>0 and DATE(follow_time) = CURDATE() ")
    List<FsStoreOrder> selectStoreOrderIdByFollow();

    @Select({"<script> " +
            "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 , csc.name miniProgramName" +
            " 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 (SELECT sp.*,ROW_NUMBER() OVER (PARTITION BY sp.business_code ORDER BY sp.create_time DESC) as rn\n" +
            "        FROM fs_store_payment sp) sp_latest ON sp_latest.business_code = so.order_code AND sp_latest.rn = 1\n" +
            "        LEFT JOIN fs_course_play_source_config csc ON csc.appid = sp_latest.app_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>\n" +
            "            <if test=\"maps.coursePlaySourceConfigId != null\"> and csc.id = #{maps.coursePlaySourceConfigId}</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.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" +
            "            <if test=\"maps.totalNum != null  and maps.totalNum != ''\"> and so.total_num = #{maps.totalNum}</if>\n" +
            "            <if test=\"maps.totalPrice != null \"> and so.total_price = #{maps.totalPrice}</if>\n" +
            "            <if test=\"maps.status != null and maps.status != 6\"> and so.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.status == 6\">\n" +
            "                and so.`status`= 2\n" +
            "                and (\n" +
            "                so.store_id in (select store_id from fs_store where delivery_type=2 or delivery_type=1)\n" +
            "                )\n" +
            "                and  (so.extend_order_id is null or  so.extend_order_id like '')\n" +
            "            </if>" +
            "            <if test=\"maps.refundStatus != null  and maps.refundStatus != ''\"> and so.refund_status = #{maps.refundStatus}</if>\n" +
            "            <if test=\"maps.refundExplain != null  and maps.refundExplain != ''\"> and so.refund_explain = #{maps.refundExplain}</if>\n" +
            "            <if test=\"maps.deliverySn != null  and maps.deliverySn != ''\"> and so.delivery_sn = #{maps.deliverySn}</if>\n" +
            "            <if test=\"maps.shippingType != null \"> and so.shipping_type = #{maps.shippingType}</if>\n" +
            "            <if test=\"maps.isChannel != null  and maps.isChannel != ''\"> and so.is_channel = #{maps.isChannel}</if>\n" +
            "            <if test=\"maps.isPrescribe != null \"> and so.is_prescribe = #{maps.isPrescribe}</if>\n" +
            "            <if test=\"maps.prescribeId != null \"> and so.prescribe_id = #{maps.prescribeId}</if>\n" +
            "            <if test=\"maps.companyUserId != null \"> and so.company_user_id = #{maps.companyUserId}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})</if>\n" +
            "            <if test=\"maps.payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})</if>\n" +
            "            <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>\n" +
            "            <if test=\"maps.deliverySendeTime != null \">  and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})</if>\n" +
            "            <if test=\"maps.deliveryImportsTime != null \">  and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})</if>\n" +
            "            <if test=\"maps.deliveryImporteTime != null \">  and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})</if>\n" +
            "            <if test=\"maps.tuisTime != null \">  and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})</if>\n" +
            "            <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.userId != null  \"> and so.user_id = #{maps.userId}</if>\n" +
            "<if test = 'maps.companyId != null  and   maps.companyId != \"-1\" '> " +
            "and so.company_id =#{maps.companyId} " +
            "</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>" +
            " ${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);
    @Select("select msg_id, msg_type, from_account, to_account, content, create_time, order_id,msg_content_type,msg_key from fs_inquiry_order_msg\n" +
            " where (from_account=#{userId} and to_account=#{followDoctorId}) or( from_account=#{followDoctorId} and to_account=#{userId})")
    List<FsInquiryOrderMsg> selectFsInquiryOrderMsgByStoreOrderId(@Param("userId")Long userId,@Param("followDoctorId") Long followDoctorId);
    @Select("select * FROM fs_store_order  WHERE `status`=4 and is_after_sales=1 and DATE(finish_time) < DATE_SUB(CURDATE(), INTERVAL #{storeAfterSalesDay} DAY)")
    List<FsStoreOrder>  selectFsStoreOrderNoIsAfterSales(Integer storeAfterSalesDay);
    @Select("select * from fs_store_order where user_id=#{userId} and follow_doctor_id=#{doctorId} and `status`>1 and (finish_time is null OR(DATE(finish_time) > DATE_SUB(CURDATE(), INTERVAL 30 DAY)))")
    List<FsStoreOrder> selectFsStoreOrderByUserIdAndDoctorId(@Param("userId")long userId, @Param("doctorId")long doctorId);
    @Select("SELECT * from fs_store_order WHERE `status`>1  AND follow_status=0 AND date(follow_end_time) <= date(NOW())")
    List<FsStoreOrder> selectFsStoreOrderEndFollow();
    @Select("SELECT * from fs_store_order WHERE follow_status=0 and `status`>1  AND date(follow_end_time) >= date(NOW()) and user_id=#{userId} and follow_doctor_id=#{followDoctorId}")
    List<FsStoreOrder> selectFsStoreOrderEndFollowByUserIdAndDocId(@Param("userId")Long userId,@Param("followDoctorId") Long followDoctorId);
    @Select("SELECT follow_id FROM fs_follow where   user_id=#{userId}  and doctor_id=#{followDoctorId} LIMIT 1")
    Long selectFsStoreOrderFollow(@Param("userId")Long userId,@Param("followDoctorId") Long followDoctorId);
    @Select("select * from fs_store_order where pay_type=3 and delivery_pay_status  is null and delivery_type=406 and  `status`=3 and DATE(update_time) < DATE_SUB(CURDATE(), INTERVAL 7 DAY)")
    List<FsStoreOrder> selectEndDeliveryOrder();

    @Select("select * from fs_store_order where order_code in("+
            "'1816260362530455552')")
    List<FsStoreOrder> selectOrderIds();

    @Select("select * from fs_store_order where item_json LIKE '%https://htj-1258038825.cos.ap-beijing.myqcloud.com%' and status != -3 order by order_id desc limit 1 ")
    List<FsStoreOrder> selectFsStoreOrderListByUpdate();
    @Select("SELECT user_id from (select COUNT(*) count,user_id  from fs_store_order WHERE   `status`>1  GROUP BY user_id) f where count >=10")
    List<Long> selectFsStoreOrderByUser10();


    @Select("select * from fs_store_order where order_code in(\n" +
            "1759579519322161152,\n" +
            "1759532942662565888\n" +
            ")")
    List<FsStoreOrder> selectOrders();
    @Select("select order_id from fs_store_order WHERE `status`>0 and  package_order_id is null ")
    List<Long> selectFsStoreOrderByOrderByCostPrice();
    @Select("SELECT order_id FROM fs_store_order where status=2 and extend_order_id ='XN' and create_time < DATE_SUB(NOW(), INTERVAL 3 DAY)")
    List<FsStoreOrder> selectFinishStoreOrderByXN();
    @Select("SELECT * FROM fs_store_order  where follow_doctor_id=#{fromId} and date(follow_end_time)>date(NOW())")
    List<FsStoreOrder> selectStoreOrderIdByFollowDoctorId(Long fromId);
    @Update("UPDATE fs_store_order SET follow_doctor_id = #{toId} WHERE follow_doctor_id = #{fromId}")
    int updateFsStoreOrderByFollow(FsUpdateFollowParam fsDoctor);

    @Select("select * from fs_store_order where status=3 and delivery_status = 4 and delivery_type!='419' and  delivery_update_time <= DATE_SUB(NOW(), INTERVAL 30 DAY); ")
    List<FsStoreOrder> selectFsStoreOrderByProblemOrder();
    @Select("select order_id,follow_doctor_id from fs_store_order where user_id=#{userId} and `status`>1 and DATE_ADD(follow_end_time , INTERVAL 30 DAY)> CURDATE() order by order_id desc limit 1")
    FsUserFollowDoctorVO selectFsFollowDoctorIdByUserId(Long userId);

    @Select("select company_id,ANY_VALUE(prescribe_id) prescribe_id,ANY_VALUE(store_id) store_id  from fs_store_order where user_id=#{userId} and follow_doctor_id=#{doctorId} and `status`>1 and (DATE(follow_end_time) > DATE_SUB(CURDATE(), INTERVAL 30 DAY)) GROUP BY company_id")
    List<FsStoreOrder> selectFsStoreOrderByUserIdAndDoctorIdAndCompany(@Param("userId") Long userId, @Param("doctorId")Long doctorId);


    List<JSONObject> selectFsPackageOrderCounts(Map<String, Object> map);

    List<JSONObject> selectFsInquiryOrderCounts(Map<String, Object> map);

    @Select({"<script> " +
            "SELECT ANY_VALUE(x.product_id) product_id,SUM(x.num) num, ANY_VALUE(p.product_name) product_name,ANY_VALUE(p.price) price,ANY_VALUE(p.bar_code) as barCode FROM fs_store_order_item x LEFT JOIN fs_store_product p ON p.product_id=x.product_id WHERE order_id IN (SELECT order_id FROM fs_store_order WHERE `status`>1 " +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(create_time,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m') " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==6 '> " +
            "and PERIOD_DIFF(DATE_FORMAT(NOW(),'%Y%m'),DATE_FORMAT(create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "and  company_user_id IN " +
            "<foreach  item='item' index='index' collection='maps.users' open='(' separator=',' close=')'> #{item}    </foreach>"+
            ") \n" +
            "GROUP BY x.product_id  ORDER BY num desc"+
            "</script>"})
    List<FsStoreProductStatisticsVO> selescChartProdVOStatisticsList(@Param("maps")FsStoreStatisticsParam param);
    @Select("select store_id,order_code,delivery_code,delivery_sn from fs_store_order  where `status`=3 and create_time>\"2024-11-01\" and delivery_type is null  ")
    List<FsStoreOrder> selectFsStoreOrderByNoTui();
    @Select("select o.order_id,o.order_code,o.delivery_code,o.package_name,o.package_second_name,o.user_name,cu.nick_name as company_user_nick_name,p.pay_code from fs_store_order o left join company_user cu on cu.user_id=o.company_user_id left join fs_store_payment p on p.business_code=o.order_code  where order_id=#{orderId} and p.status=1 limit 1  ")
    FsStoreOrderExportDataVO selectFsStoreOrderExportDataVOByOrderId(long orderId);
    @Select({"<script> " +
            "select count(1) " +
            " FROM fs_store_order so LEFT JOIN fs_store st ON so.store_id =st.store_id " +
            " LEFT JOIN fs_user us ON us.user_id=so.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_package_order po on po.order_id = so.package_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>\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" +
            "            <if test=\"maps.totalNum != null  and maps.totalNum != ''\"> and so.total_num = #{maps.totalNum}</if>\n" +
            "            <if test=\"maps.totalPrice != null \"> and so.total_price = #{maps.totalPrice}</if>\n" +
            "            <if test=\"maps.status != null \"> and so.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.source != null \"> and so.source = #{maps.source}</if>\n" +
            "            <if test=\"maps.refundStatus != null  and maps.refundStatus != ''\"> and so.refund_status = #{maps.refundStatus}</if>\n" +
            "            <if test=\"maps.refundExplain != null  and maps.refundExplain != ''\"> and so.refund_explain = #{maps.refundExplain}</if>\n" +
            "            <if test=\"maps.deliverySn != null  and maps.deliverySn != ''\"> and so.delivery_sn = #{maps.deliverySn}</if>\n" +
            "            <if test=\"maps.shippingType != null \"> and so.shipping_type = #{maps.shippingType}</if>\n" +
            "            <if test=\"maps.isChannel != null  and maps.isChannel != ''\"> and so.is_channel = #{maps.isChannel}</if>\n" +
            "            <if test=\"maps.isPrescribe != null \"> and so.is_prescribe = #{maps.isPrescribe}</if>\n" +
            "            <if test=\"maps.prescribeId != null \"> and so.prescribe_id = #{maps.prescribeId}</if>\n" +
            "            <if test=\"maps.companyUserId != null \"> and so.company_user_id = #{maps.companyUserId}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})</if>\n" +
            "            <if test=\"maps.payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})</if>\n" +
            "            <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>\n" +
            "            <if test=\"maps.deliverySendeTime != null \">  and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})</if>\n" +
            "            <if test=\"maps.deliveryImportsTime != null \">  and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})</if>\n" +
            "            <if test=\"maps.deliveryImporteTime != null \">  and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})</if>\n" +
            "            <if test=\"maps.tuisTime != null \">  and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})</if>\n" +
            "            <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>" +
            "<if test = ' maps.companyId == \"-1\" '> " +
            "and so.company_id is null " +
            "</if>" +
            "<if test=\"maps.userId != null  \"> and so.user_id = #{maps.userId}</if>\n" +
            "<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>" +
            " ${maps.params.dataScope} "+
            " ORDER BY so.order_id desc " +
            "</script>"})
    Long selectFsStoreOrderExcelListVOCount(@Param("maps") FsStoreOrderParam fsStoreOrder);
    @Select({"<script> " +
            "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 " +
            " 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>\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" +
            "            <if test=\"maps.totalNum != null  and maps.totalNum != ''\"> and so.total_num = #{maps.totalNum}</if>\n" +
            "            <if test=\"maps.totalPrice != null \"> and so.total_price = #{maps.totalPrice}</if>\n" +
            "            <if test=\"maps.status != null and maps.status != 6\"> and so.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.status == 6\">\n" +
            "                and so.`status`= 2\n" +
            "                and (\n" +
            "                so.store_id in (select store_id from fs_store where delivery_type=2 or delivery_type=1)\n" +
            "                )\n" +
            "                and  (so.extend_order_id is null or  so.extend_order_id like '')\n" +
            "            </if>" +

            "            <if test=\"maps.refundStatus != null  and maps.refundStatus != ''\"> and so.refund_status = #{maps.refundStatus}</if>\n" +
            "            <if test=\"maps.refundExplain != null  and maps.refundExplain != ''\"> and so.refund_explain = #{maps.refundExplain}</if>\n" +
            "            <if test=\"maps.deliverySn != null  and maps.deliverySn != ''\"> and so.delivery_sn = #{maps.deliverySn}</if>\n" +
            "            <if test=\"maps.shippingType != null \"> and so.shipping_type = #{maps.shippingType}</if>\n" +
            "            <if test=\"maps.isChannel != null  and maps.isChannel != ''\"> and so.is_channel = #{maps.isChannel}</if>\n" +
            "            <if test=\"maps.isPrescribe != null \"> and so.is_prescribe = #{maps.isPrescribe}</if>\n" +
            "            <if test=\"maps.prescribeId != null \"> and so.prescribe_id = #{maps.prescribeId}</if>\n" +
            "            <if test=\"maps.companyUserId != null \"> and so.company_user_id = #{maps.companyUserId}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(so.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(so.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.paysTime != null \">  and DATE(so.pay_time) &gt;= DATE(#{maps.paysTime})</if>\n" +
            "            <if test=\"maps.payeTime != null \">  and DATE(so.pay_time) &lt;= DATE(#{maps.payeTime})</if>\n" +
            "            <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>\n" +
            "            <if test=\"maps.deliverySendeTime != null \">  and DATE(so.delivery_send_time) &lt;= DATE(#{maps.deliverySendeTime})</if>\n" +
            "            <if test=\"maps.deliveryImportsTime != null \">  and DATE(so.delivery_import_time) &gt;= DATE(#{maps.deliveryImportsTime})</if>\n" +
            "            <if test=\"maps.deliveryImporteTime != null \">  and DATE(so.delivery_import_time) &lt;= DATE(#{maps.deliveryImporteTime})</if>\n" +
            "            <if test=\"maps.tuisTime != null \">  and DATE(so.tui_money_time) &gt;= DATE(#{maps.tuisTime})</if>\n" +
            "            <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>" +
            "<if test=\"maps.userId != null  \"> and so.user_id = #{maps.userId}</if>\n" +
            "<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>" +
            " ${maps.params.dataScope} "+
            " order by so.order_id desc" +
            "</script>"})
    Long selectFsStoreOrderListVOByExportCount(@Param("maps") FsStoreOrderParam param);

    @Select("select * from fs_store_order where extend_order_id  like 'SO%' and `status`=2 ")
    List<FsStoreOrder> selectOmsOrderdeliveryOp();

    @Select("select * from fs_store_order_scrm where extend_order_id  is not null and `status`=1 ")
    List<FsStoreOrderScrm> selectOmsOrderdeliveryOpScrm();
    List<FsStoreOrder> selectFsStoreOrderByOrderIdIn(@Param("ids") List<Long> ids);

    List<FsStoreOrder> selectFsStoreOrderStatisticsByUserId(@Param("ids") List<Long> ids);

    @Select({"<script> " +
            "select ifnull(count(1),0) from fs_store_order o  " +
            "where o.company_id=#{companyId} and company_user_id=#{userId} " +
            "<if test = 'type==1   '> " +
            " AND date_format(o.create_time,'%y%m%d') = date_format(now(),'%y%m%d') " +
            "</if>" +
            "<if test = 'type==2   '> " +
            " AND o.status=0 " +
            "</if>" +
            "</script>"})
    Integer selectFsStoreOrderCountByType(@Param("companyId") Long companyId,@Param("userId") long userId, @Param("type")int type);

    @Select("select * from fs_store_order where  `status`=2 and extend_order_id is not null and extend_order_id != '' ")
    List<FsStoreOrder> selectWdtOmsOrderdeliveryOp();

    @Select("select * from fs_store_order_scrm where  `status`=1 and extend_order_id is not null and extend_order_id != '' ")
    List<FsStoreOrderScrm> selectWdtOmsOrderdeliveryOpScrm();

    int batchUpdateErpByOrderIds(@Param("maps") List<Map<String, String>> maps);

    @Select(" select * from fs_store_order where order_code=#{orderCode} and store_id=#{storeId}")
    FsStoreOrder getOrderByOrderCodeAndStoreId(@Param("orderCode")String orderCode,@Param("storeId") Long storeId);

    @Update("UPDATE fs_store_order SET delivery_code = #{order.deliveryCode} , delivery_name = #{order.deliveryName} , delivery_sn = #{order.deliverySn}   WHERE follow_doctor_id = #{order.orderId}")
    int updateStoreOrderDeliveryInfo(@Param("order") FsStoreOrder order);
    @Update("UPDATE fs_store_order SET delivery_code = #{deliveryCode} WHERE extend_order_id = #{extendOrderId}")
    int updateFsStoreOrderByExtendOrderId(@Param("extendOrderId")String extendOrderId,@Param("deliveryCode")String deliveryCode);

    @Select("select * from fs_store_order where  `status`=3 and (extend_order_id is not null or extend_order_id != '') and (delivery_sn is not null or delivery_sn != '')")
    List<FsStoreOrder> selectShippedOrder();

    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);

    Map<String,BigDecimal> selectFsStoreOrderStatistics(@Param("maps") FsStoreOrderParam fsStoreOrder);

    String selectFsStoreOrderProductStatistics(@Param("maps")FsStoreOrderParam fsStoreOrder);


    List<Report> selectOrderByCustomerIds(@Param("map") ReportParam param);

    FsStoreOrderAmountStatsVo selectFsStoreOrderAmountStats(FsStoreOrderAmountStatsQueryDto queryDto);

    List<FsStoreOrder> selectOutTimeOrderList(@Param("unPayTime")Integer unPayTime);
}
