package com.fs.hisStore.mapper;

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

import com.alibaba.fastjson.JSONObject;
import com.fs.api.param.OrderListParam;
import com.fs.api.vo.OrderListVO;
import com.fs.company.param.CompanyStatisticsParam;
import com.fs.course.dto.FsOrderDeliveryNoteDTO;
import com.fs.his.domain.FsStoreOrder;
import com.fs.his.dto.FsStoreOrderAmountScrmStatsQueryDto;
import com.fs.his.vo.FsStoreOrderAmountScrmStatsVo;
import com.fs.his.vo.FsStoreOrderExcelVO;
import com.fs.hisStore.domain.FsStoreOrderScrm;
import com.fs.hisStore.domain.FsStoreOrderItemScrm;
import com.fs.hisStore.domain.ReportScrm;
import com.fs.hisStore.param.*;
import com.fs.hisStore.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 订单Mapper接口
 *
 * @author fs
 * @date 2022-03-15
 */
public interface FsStoreOrderScrmMapper
{
    /**
     * 查询订单
     *
     * @param id 订单ID
     * @return 订单
     */
    public FsStoreOrderScrm selectFsStoreOrderById(Long id);

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

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

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

    /**
     * 删除订单
     *
     * @param id 订单ID
     * @return 结果
     */
    public int deleteFsStoreOrderById(Long id);

    /**
     * 批量删除订单
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsStoreOrderByIds(Long[] ids);

//    @Select({"<script> " +
//            "select o.*,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
//            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
//            "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
//            "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
//            "</if>" +
//            "where 1=1 " +
//            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
//            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
//            "</if>" +
//            "<if test = 'maps.isPayRemain != null      '> " +
//            "and o.is_pay_remain =#{maps.isPayRemain} " +
//            "</if>" +
//            "<if test = 'maps.userId != null      '> " +
//            "and o.user_id =#{maps.userId} " +
//            "</if>" +
//            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
//            "and o.delivery_id =#{maps.deliveryId} " +
//            "</if>" +
//            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
//            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
//            "</if>" +
//            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
//            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
//            "</if>" +
//            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
//            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
//            "</if>" +
//            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
//            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
//            "</if>" +
//            "<if test = 'maps.status != null    '> " +
//            "and o.status =#{maps.status} " +
//            "</if>" +
//            "<if test = 'maps.isUpload != null and maps.isUpload == 0    '> " +
//            "and o.certificates is null  " +
//            "</if>" +
//            "<if test = 'maps.isUpload != null and maps.isUpload == 1    '> " +
//            "and o.certificates is not null " +
//            "</if>" +
//            "<if test = 'maps.deliveryStatus != null    '> " +
//            "and o.delivery_status =#{maps.deliveryStatus} " +
//            "</if>" +
//            "<if test = 'maps.deliveryPayStatus != null    '> " +
//            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
//            "</if>" +
//            "<if test = 'maps.companyId != null    '> " +
//            "and o.company_id =#{maps.companyId} " +
//            "</if>" +
//            "<if test = 'maps.isHealth != null and maps.isHealth !=  \"\"  '> " +
//            "and o.company_id is null " +
//            "</if>" +
//            "<if test = 'maps.notHealth != null '> " +
//            "and o.company_id is not null " +
//            "</if>" +
//            "<if test = 'maps.companyUserId != null    '> " +
//            "and o.company_user_id =#{maps.companyUserId} " +
//            "</if>" +
//            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
//            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
//            "</if>" +
//            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
//            "and fsp.product_name like concat('%', #{maps.productName}, '%') " +
//            "</if>" +
//            "<if test = 'maps.orderType != null    '> " +
//            "and o.order_type =#{maps.orderType} " +
//            "</if>" +
//            "<if test = 'maps.payType != null    '> " +
//            "and o.pay_type =#{maps.payType} " +
//            "</if>" +
//            "<if test = 'maps.scheduleId != null    '> " +
//            "and o.schedule_id =#{maps.scheduleId} " +
//            "</if>" +
//            "<if test = 'maps.createTimeList != null    '> " +
//            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
//            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
//            "</if>" +
//
//            "<if test = 'maps.deliverySendTimeList != null    '> " +
//            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
//            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
//            "</if>" +
//            "<if test = 'maps.paidStatus != null    '> " +
//            "and o.paid =#{maps.paidStatus} " +
//            "</if>" +
//            "<if test = 'maps.payTimeList != null    '> " +
//            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
//            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
//            "</if>" +
//            "<if test = 'maps.deliveryImportTimeList != null    '> " +
//            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
//            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
//            "</if>" +
//            "<if test = 'maps.deptId != null    '> " +
//            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
//            "</if>" +
//            " ${maps.params.dataScope} "+
//            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
//            " group by o.id "+
//            "</if>" +
//            " order by o.id desc "+
//            "</script>"})
    List<FsStoreOrderVO> selectFsStoreOrderListVO(@Param("maps")FsStoreOrderParam param);


    @Select({"<script> " +
            "select o.*,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
            "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
            "</if>" +
            "where 1=1  " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.isPayRemain != null      '> " +
            "and o.is_pay_remain =#{maps.isPayRemain} " +
            "</if>" +
            "<if test = 'maps.orderVisit != null      '> " +
            "and o.order_visit =#{maps.orderVisit} " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 0    '> " +
            "and o.certificates is null  " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 1    '> " +
            "and o.certificates is not null " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            "and fsp.product_name like concat('%', #{maps.productName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.payType != null    '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.scheduleId != null    '> " +
            "and o.schedule_id =#{maps.scheduleId} " +
            "</if>" +
            "<if test = 'maps.createTimeList == null    '> " +
            "and o.create_time >= '2023-10-01' " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.deliverySendTimeList != null    '> " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            " group by o.id "+
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    List<FsStoreOrderVO> selectFsStoreOrderAllListVO(@Param("maps")FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.*,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,fp.pay_money as lastPayMoney   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
            " left join (select * from fs_store_payment_scrm where is_pay_remain = 1 and status = 1) fp on o.id = fp.order_id  "+
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            "left join fs_store_order_item_scrm oi on o.id = oi.order_id "+
            "left join fs_store_product_scrm fsp on fsp.product_id = oi.product_id"+
            "</if>" +
            "where 1=1 " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.isPayRemain != null      '> " +
            "and o.is_pay_remain =#{maps.isPayRemain} " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 0    '> " +
            "and o.certificates is null  " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 1    '> " +
            "and o.certificates is not null " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.isHealth != null and maps.isHealth !=  \"\"  '> " +
            "and o.company_id is null " +
            "</if>" +
            "<if test = 'maps.notHealth != null '> " +
            "and o.company_id is not null " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            "and fsp.product_name like concat('%', #{maps.productName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.payType != null    '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.scheduleId != null    '> " +
            "and o.schedule_id =#{maps.scheduleId} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.deliverySendTimeList != null    '> " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            "<if test = 'maps.productName != null and  maps.productName !=  \"\" '> " +
            " group by o.id "+
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    List<FsStoreOrderVO> selectFsPayRemainListVO(@Param("maps")FsStoreOrderParam param);

    @Select({"<script> " +
            "select f.phone as tuiNickName,o.*,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id left join fs_user f on o.tui_user_id = f.user_id left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
            "where 1=1 and o.tui_user_id is not null " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.isPayRemain != null      '> " +
            "and o.is_pay_remain =#{maps.isPayRemain} " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.deliverySendTimeList != null    '> " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
            "</if>" +

            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            " order by o.id desc "+
            "</script>"})
    List<FsPromotionOrderVO> selectFsPromotionOrderListVO(@Param("maps")FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.id,o.order_code,o.item_json,o.pay_price,o.status,o.is_package,o.package_json,o.delivery_id,o.finish_time  from fs_store_order_scrm o  " +
            "where o.is_del=0 and o.is_sys_del=0 " +
            "<if test = 'maps.status != null and maps.status != \"\"     '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.keyword != null and  maps.keyword !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.keyword},'%') " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null     '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.userId != null     '> " +
            "and o.user_id=#{maps.userId} " +
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    List<FsMyStoreOrderListQueryVO> selectFsMyStoreOrderListVO(@Param("maps")FsMyStoreOrderQueryParam param);
    @Select("select * from fs_store_order_scrm where order_code=#{orderCode}")
    FsStoreOrderScrm selectFsStoreOrderByOrderCode(String orderCode);
    @Update("update fs_store_order_scrm set status=-3 where id=#{orderId}")
    int cancelOrder(Long orderId);
    @Select({"<script> " +
            "select o.*  from fs_store_order_scrm o  " +
            "where o.is_del=0 and o.is_sys_del=0 " +
            "<if test = 'maps.status != null and maps.status != \"\"     '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.keyword != null and  maps.keyword !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.keyword},'%') " +
            "</if>" +
            "<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.companyId != null     '> " +
            "and o.company_id=#{maps.companyId} " +
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    List<FsMyStoreOrderListQueryVO> selectFsCompanyStoreOrderListVO(@Param("maps")FsMyStoreOrderQueryParam param);
    @Select("select * from fs_store_order_scrm where extend_order_id=#{extendOrderId}")
    FsStoreOrderScrm selectFsStoreOrderByExtendOrderId(String extendOrderId);
    @Select({"<script> " +
            "select b.money as tui_price,b.bill_type,b.create_time,o.id as order_id,o.order_code,o.pay_price,u.nickname,u.avatar from fs_user_bill b inner join  fs_store_order_scrm o on b.business_id=o.id left join fs_user u on u.user_id=o.user_id  " +
            "where b.user_id=#{userId} and b.category='brokerage_price'   " +
            " order by b.bill_id desc"+
            "</script>"})
    List<FsStoreOrderTuiVO> selectFsStoreOrderTuiListVO(String userId);
    @Select({"<script> " +
            "select ifnull(count(1),0) from fs_store_order_scrm o  " +
            "where o.user_id=#{uid} and o.package_id=#{packageId} and o.status &lt;&gt; -3 " +
            "</script>"})
    int checkPackageOrderCount(@Param("uid") long uid, @Param("packageId")String packageId);
    @Select({"<script> " +
            "select ifnull(count(1),0) from fs_store_order_scrm o  " +
            "where o.user_id=#{userId}  and o.status =#{status} " +
            "</script>"})
    int selectFsStoreOrderCount(@Param("userId")long userId,@Param("status")int status);

    @Select({"<script> " +
            "select * from fs_store_order_scrm o  " +
            "where o.delivery_id=#{deliveryId}  limit 1 " +
            "</script>"})
    FsStoreOrderScrm selectFsStoreOrderByDeliveryId(@Param("deliveryId")String deliveryId);
    @Select({"<script> " +
            "select o.*,u.nickname,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
            "where 1=1 " +
            "<if test = 'orderCode != null '> " +
            "and o.order_code = #{orderCode} " +
            "</if>" +
            "</script>"})
    FsStoreOrderVO selectFsStoreOrderVOByOrderCode(@Param("orderCode") String orderCode);

    Long selectFsStoreOrderTotalCount(@Param("type")int type,@Param("companyId")Long companyId,@Param("companyUserId")Long companyUserId);
    @Select({"<script> " +
            "select o.id as orderid ,o.order_code as order_code,o.create_time as orderdate,o.total_price as amount,o.real_name as customername,o.user_phone as tel,o.user_address as address,o.delivery_name as express,o.delivery_id as packageno   from fs_store_order_scrm o  " +
            "where o.is_del=0 and o.is_sys_del=0 " +
            "<if test = 'maps.companyId != null     '> " +
            "and o.company_id =#{maps.companyId} " +
            "</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>" +
            " order by o.id desc "+
            "</script>"})
    List<OrderListVO> selectCompanyStoreOrderListAPI(@Param("maps")OrderListParam param);
    @Select({"<script> " +
            "select o.*  from fs_store_order_scrm o  " +
            "where o.is_del=0 and o.is_sys_del=0 and o.status=3 " +
            "and o.company_id =#{companyId} " +
            "</script>"})
    List<FsStoreOrderScrm> selectFsStoreOrderByCompanyId(@Param("companyId")Long companyId);
    @Select({"<script> " +
            "select * from fs_store_order_scrm o  " +
            "where o.delivery_id=#{deliveryId} " +
            "</script>"})
    List<FsStoreOrderScrm> selectFsStoreOrderListByDeliveryId(@Param("deliveryId") String deliveryId);
    @Select({"<script> " +
            "select ifnull(count(1),0) from fs_store_order_scrm 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({"<script> " +
            "select o.*  from fs_store_order_scrm o  " +
            "where o.is_del=0 and o.is_sys_del=0 and o.status &gt; 0 " +
            "<if test = 'maps.userId != null     '> " +
            "and o.user_id=#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.companyId != null     '> " +
            "and o.company_id=#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.customerId != null     '> " +
            "and o.customer_id=#{maps.customerId} " +
            "</if>" +
            "<if test = 'maps.userId != null     '> " +
            "and o.user_id=#{maps.userId} " +
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    List<FsCustomerStoreOrderListQueryVO> selectFsCustomerStoreOrderListQuery(@Param("maps")FsCustomerStoreOrderListQueryParam param);

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

    @Select({"<script> " +
            "select u.nick_name, count(o.id) as order_count,sum(IFNULL(o.pay_price,0)) as pay_price  from  fs_store_order_scrm o left join company_user u on o.company_user_id=u.user_id  " +
            "where o.status &gt; 0 " +
            "<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("select * from fs_store_order_scrm where status=3 and tui_user_id > 0 and tui_user_money_status !=1 and DATE_ADD(finish_time,INTERVAL 7 DAY)  > now() ")
    List<FsStoreOrderScrm> selectFsStoreOrderListByFinish7Day();

    @Select({"<script> " +
            "select o.*,cts.name as scheduleName,u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title ,CASE WHEN o.certificates IS NULL OR o.certificates = '' THEN 0 ELSE 1 END AS is_upload  " +
            " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
            " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id left join company_tcm_schedule cts on cts.id = o.schedule_id " +
            "where 1=1 " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.isHealth != null and maps.isHealth !=  \"\"  '> " +
            "and o.company_id is null " +
            "</if>" +
            "<if test = 'maps.notHealth != null and maps.notHealth !=  \"\"  '> " +
            "and o.company_id is not null " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.payType != null    '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliverySendTimeList != null    '> " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 0    '> " +
            "and o.certificates is null  " +
            "</if>" +
            "<if test = 'maps.scheduleId != null    '> " +
            "and o.schedule_id =#{maps.scheduleId} " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 1    '> " +
            "and o.certificates is not null " +
            "</if>" +
            " ${maps.params.dataScope} "+
            " order by o.id desc limit 50000"+
            "</script>"})
    List<FsStoreOrderErpExportVO> selectFsStoreOrderListVOByExport(@Param("maps") FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.*, " +
            "u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title " +
            " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
            " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id " +
            "where 1=1 " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.isHealth != null and maps.isHealth !=  \"\"  '> " +
            "and o.company_id is null " +
            "</if>" +
            "<if test = 'maps.notHealth != null and maps.notHealth !=  \"\"  '> " +
            "and o.company_id is not null " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.payType != null    '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            " order by o.id desc"+
            "</script>"})
    List<FsStoreOrderPromotionExportVO> selectFsPromotionOrderListVOByExport(@Param("maps") FsStoreOrderParam param);

    @Select("select o.order_id,sum(p.brokerage * o.num) as brokerage,sum(p.brokerage_two * o.num) as brokerage_two, " +
            "sum(p.brokerage_three * o.num) as brokerage_three from fs_store_order_item_scrm o " +
            "left join fs_store_product_attr_value_scrm p on o.product_id = p.product_id where o.order_id = #{orderId}")
    FsStoreOrderBrokerageVO selectBrokerage(Long orderId);

    @Select({"<script> " +
            "select o.*,fp.pay_money as lastPayMoney,u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time,cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber ,p.title as package_title " +
            " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
            " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id left join (select * from fs_store_payment_scrm where is_pay_remain != 0 and status != 0) fp on o.id = fp.order_id " +
            "where 1=1 " +
            "<if test = 'maps.isPayRemain != null     '> " +
            "and o.is_pay_remain = #{maps.isPayRemain} " +
            "</if>" +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            " order by o.id desc "+
            "</script>"})
    List<FsStorePayRemainOrderExportVO> selectFsStorePayRemainOrderListVOByExport(@Param("maps") FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.*,u.nickname,u.phone,u.register_code,u.register_date,u.source, c.company_name ,cu.nick_name as company_user_nick_name ,cu.phonenumber as company_usere_phonenumber   from fs_store_order_scrm o left join fs_user u on o.user_id=u.user_id  left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id  " +
            "where o.customer_id=#{maps.customerId} " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test = 'maps.status != null    '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            " ${maps.params.dataScope} "+
            " order by o.id desc "+
            "</script>"})
    List<FsStoreOrderVO> selectFsCustomerStoreOrderListVO(@Param("maps")FsStoreOrderParam param);

    @Update("update fs_store_order_scrm set upload_time= #{uploadTime},certificates =#{certificates} where id = #{id}")
    int uploadCredentials(FsStoreOrderScrm order);

    @Select("select certificates from fs_store_order_scrm where id = #{id} ")
    String getCredentialsById(Long id);
    @Select("select id from fs_store_order_scrm where extend_order_id is  null and status=1 and create_time > #{startTime} ")
    List<Long> selectFsStoreOrderToPushByIds(@Param("startTime")String startTime);

    @Select(" SELECT * from fs_store_order_scrm WHERE order_create_type<>2 and item_json is NULL ORDER BY id DESC  LIMIT 30")
    List<FsStoreOrderScrm> selectFsStoreOrderItemJson();

    @Update(" update fs_store_order_scrm set item_json= #{itemJson} where id=#{id} ")
    int uploadItemJson(FsStoreOrderScrm order);

    @Select("select extend_order_id from fs_store_order_scrm where create_time >= '2023-09-18 00:00:00' AND create_time <= '2023-09-19 00:00:00' and extend_order_id is not null and status = 1 ")
    List<String> selectErpCode();

    @Update("update fs_store_order_scrm set delivery_id = #{deliveryId},status = #{status}  where extend_order_id =#{extendOrderId} ")
    void updateDelivery(FsStoreOrderScrm fsStoreOrder);


    @Select("select id from fs_store_order_scrm where create_time >= '2023-08-01 00:00:00' AND create_time <= '2023-09-01 00:00:00'  and status = 3 and delivery_status != 3  ")
    List<Long> selectOrderId();

    @Update("update fs_store_order_scrm set status = #{status}  where order_code =#{orderCode}")
    void updateDeliveryStatus(FsStoreOrderScrm fsStoreOrder);

    @Select("select id from fs_store_order_scrm where status = 2  and DATE(pay_time)>='2023-11-1' and DATE(create_time)<='2024-2-7' and company_id is null ")
    List<Long> selectSyncExpressIds();


    List<Long> selectAddTuiMoney();

    @Select("select * from fs_store_order_scrm where delivery_type = 406 and pay_money <=1 and status = 2 and delivery_pay_status is null and pay_type != 3 ")
    List<FsStoreOrderScrm> selectPayMoneyLessOne();

    @Select("select * from fs_store_order_item_scrm where order_id = #{orderId}")
    List<FsStoreOrderItemScrm> selectOrderItem(Long orderId);


    @Select({"<script> " +
            "select count(1) as tuiMoneyCount ,sum(IFNULL(l.tui_money,0)) as tuiMoney,u.nick_name as  nickName from  fs_store_order_scrm l left join company_user u on l.company_user_id=u.user_id  " +
            "where l.status>0  " +
            "<if test = 'maps.type != null and maps.type ==1 '> " +
            "and TO_DAYS(l.create_time) = TO_DAYS(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==2 '> " +
            "and TO_DAYS(NOW()) - TO_DAYS(l.create_time) &lt;= 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==3 '> " +
            "and YEARWEEK(DATE_FORMAT(l.create_time,'%Y-%m-%d')) = YEARWEEK(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==4 '> " +
            "and YEARWEEK(DATE_FORMAT(l.create_time,'%Y-%m-%d')) = YEARWEEK(NOW())-1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==5 '> " +
            "and DATE_FORMAT(l.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(l.create_time,'%Y%m')) = 1 " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==7 '> " +
            "and QUARTER(l.create_time) = QUARTER(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==8 '> " +
            "and QUARTER(l.create_time) = QUARTER(DATE_SUB(NOW(),INTERVAL 1 QUARTER)) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==9 '> " +
            "and YEAR(l.create_time)=YEAR(NOW()) " +
            "</if>" +
            "<if test = 'maps.type != null and maps.type ==10 '> " +
            "and  YEAR(l.create_time) = YEAR(DATE_SUB(NOW(),INTERVAL 1 YEAR))" +
            "</if>" +
            "and  l.company_user_id IN " +
            "<foreach  item='item' index='index' collection='maps.users' open='(' separator=',' close=')'> #{item}    </foreach>"+
            " group by l.company_user_id order by tuiMoney desc"+
            "</script>"})
    List<CompanyTuiMoneyStatisticsVO> selectSoreTuiMoneyStatisticsList(@Param("maps")CompanyStatisticsParam param);

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

    @Select("select * from fs_store_order_scrm where user_id = #{userId} limit 1")
    FsStoreOrderScrm selectOrderByUserIdLimit1(Long userId);

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

    @Select("select id from fs_store_order_scrm WHERE `status`= 1  and  extend_order_id is null ")
    List<Long> selectFsStoreOrderNoCreateOms();

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

    @Select("select fso.id from fs_store_order_scrm fso inner join fs_store_order_audit_scrm fsoa on fsoa.order_id = fso.id where fso.`status`= 1 and fso.extend_order_id is null and fsoa.audit_status = 4")
    List<Long> selectFsStoreOrderNoCreateOmsAndReviewed();

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

    int selectFsStoreOrderCountByParam(FsStoreOrderStatisticsParam param);

    BigDecimal selectFsStoreOrderByPayPriceCount(FsStoreOrderStatisticsParam param);

    /**
     * 订单维度分页查询接口
     * @param param 查询条件
     * @return List<OrderStatisticsVo>
     * **/
    List<OrderStatisticsVo> selectOrderDimensionStatisticsList(@Param("param") OrderStatisticsParam param);


    /**
     * 订单销售维度分页查询接口
     * @param param 查询条件
     * @return List<OrderStatisticsVo>
     * **/
    List<OrderStatisticsVo> selectOrderSaleStatisticsList(@Param("param") OrderStatisticsParam param);

    List<FsStoreOrderCountsVO> selectFsStoreOrderCountsByDept(Map<String, Object> map);

    List<FsStoreOrderScrm> computePayMoney(@Param("customerIds")List<Long> customerIds);

    FsStoreOrderScrm selectLastByCustomerId(@Param("customerId")Long customerId);

    List<Map<String, Object>> selectFsStoreProductCountsByDept(Map<String, Object> map);

    /**
     * 批量查询订单信息
     * @param ids 订单id
     * **/
    List<FsStoreOrderScrm> selectStoreOrderScrmInId(@Param("ids") Long[] ids);
    void batchUpdateInOrderCode(@Param("list") List<FsOrderDeliveryNoteDTO> dtoList);

    @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_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 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.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_scrm "+
            "<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(FsStoreOrderScrm fsStoreOrder);

    FsStoreOrderAmountScrmStatsVo selectFsStoreOrderAmountScrmStats(FsStoreOrderAmountScrmStatsQueryDto queryDto);

    List<FsStoreOrderVO> selectFsStoreOrderListVOByErpAccount(@Param("maps")FsStoreOrderParam param);

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

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

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

    Long selectFsStoreOrderListVOByErpAccountByExportCount(@Param("maps")FsStoreOrderParam param);

    @Select({"<script> " +
            "select o.*,cts.name as scheduleName,u.nickname,u.phone,cc.push_code,cc.create_time as customer_create_time," +
            "cc.source,cc.customer_code, c.company_name ,cu.nick_name as company_user_nick_name ," +
            "cu.phonenumber as company_usere_phonenumber ,p.title as package_title ," +
            "CASE WHEN o.certificates IS NULL OR o.certificates = '' THEN 0 ELSE 1 END AS is_upload " +
            ",df.login_account as erp_account," +
            "        csc.name miniProgramName " +
            " from fs_store_order_scrm o  left JOIN fs_store_product_package_scrm p on o.package_id=p.package_id left join fs_user u on o.user_id=u.user_id  " +
            " left join company c on c.company_id=o.company_id left join company_user cu on cu.user_id=o.company_user_id left join crm_customer cc on cc.customer_id=o.customer_id left join company_tcm_schedule cts on cts.id = o.schedule_id " +
            " LEFT JOIN fs_store_order_df df on df.order_id=o.id " +
            " LEFT JOIN ( " +
            " SELECT " +
            " sp.*, " +
            "ROW_NUMBER() OVER (PARTITION BY sp.business_code ORDER BY sp.create_time DESC) as rn " +
            "FROM fs_store_payment_scrm sp " +
            " ) sp_latest ON sp_latest.business_code = o.order_code AND sp_latest.rn = 1 " +
            " LEFT JOIN fs_course_play_source_config csc ON csc.appid = sp_latest.app_id " +
            "where 1=1 " +
            "<if test = 'maps.orderCode != null and  maps.orderCode !=\"\"    '> " +
            "and o.order_code like CONCAT('%',#{maps.orderCode},'%') " +
            "</if>" +
            "<if test=\"maps.orderCodes != null  and maps.orderCodes.size > 0\">" +
            "            and o.order_code in" +
            "            <foreach collection=\"maps.orderCodes\" item=\"orderCode\" open=\"(\" close=\")\" separator=\",\">" +
            "                #{orderCode}" +
            "            </foreach>" +
            "        </if>" +
            "<if test = 'maps.userId != null      '> " +
            "and o.user_id =#{maps.userId} " +
            "</if>" +
            "<if test = 'maps.deliveryId != null  and  maps.deliveryId !=\"\"    '> " +
            "and o.delivery_id =#{maps.deliveryId} " +
            "</if>" +
            "<if test = 'maps.nickname != null and  maps.nickname !=\"\"     '> " +
            "and u.nickname like CONCAT('%',#{maps.nickname},'%') " +
            "</if>" +
            "<if test = 'maps.realName != null and  maps.realName !=\"\"     '> " +
            "and o.real_name like CONCAT('%',#{maps.realName},'%') " +
            "</if>" +
            "<if test = 'maps.phone != null and  maps.phone !=\"\"     '> " +
            "and u.phone like CONCAT('%',#{maps.phone},'%') " +
            "</if>" +
            "<if test = 'maps.userPhone != null and  maps.userPhone !=\"\"     '> " +
            "and o.user_phone like CONCAT('%',#{maps.userPhone},'%') " +
            "</if>" +
            "<if test=\"maps.status != null and maps.status != 6\">" +
            "            AND o.status = #{maps.status}" +
            "        </if>" +
            "<if test=\"maps.status == 6\">" +
            "            AND o.`status` = 1" +
            "            AND (" +
            "            o.store_id IN (SELECT store_id FROM fs_store WHERE delivery_type=2 OR delivery_type=1)" +
            "            )" +
            "            AND (o.extend_order_id IS NULL OR o.extend_order_id = '')" +
            "        </if>" +
            "<if test = 'maps.deliveryStatus != null    '> " +
            "and o.delivery_status =#{maps.deliveryStatus} " +
            "</if>" +
            "<if test = 'maps.deliveryPayStatus != null    '> " +
            "and o.delivery_pay_status =#{maps.deliveryPayStatus} " +
            "</if>" +
            "<if test = 'maps.companyId != null    '> " +
            "and o.company_id =#{maps.companyId} " +
            "</if>" +
            "<if test = 'maps.isHealth != null and maps.isHealth !=  \"\"  '> " +
            "and o.company_id is null " +
            "</if>" +
            "<if test = 'maps.notHealth != null and maps.notHealth !=  \"\"  '> " +
            "and o.company_id is not null " +
            "</if>" +
            "<if test = 'maps.companyUserId != null    '> " +
            "and o.company_user_id =#{maps.companyUserId} " +
            "</if>" +
            "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> " +
            "and cu.nick_name like concat('%', #{maps.companyUserNickName}, '%') " +
            "</if>" +
            "<if test = 'maps.orderType != null    '> " +
            "and o.order_type =#{maps.orderType} " +
            "</if>" +
            "<if test = 'maps.payType != null    '> " +
            "and o.pay_type =#{maps.payType} " +
            "</if>" +
            "<if test = 'maps.createTimeList != null    '> " +
            " AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d') " +
            " AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTimeList != null    '> " +
            " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
            " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliverySendTimeList != null    '> " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deliveryImportTimeList != null    '> " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d') " +
            " AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.deptId != null    '> " +
            "  AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) )) " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 0    '> " +
            "and o.certificates is null  " +
            "</if>" +
            "<if test = 'maps.scheduleId != null    '> " +
            "and o.schedule_id =#{maps.scheduleId} " +
            "</if>" +
            "<if test = 'maps.isUpload != null and maps.isUpload == 1    '> " +
            "and o.certificates is not null " +
            "</if>" +
            " <if test=\"maps.erpPhoneNumber != null and maps.erpPhoneNumber != ''\">" +
            " and o.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'\">" +
            "    o.package_name" +
            "</if>" +
            "<if test=\"maps.sortField == 'payPrice'\">" +
            "    o.pay_price" +
            "</if>" +
            "<if test=\"maps.sortField == 'payMoney'\">" +
            "    o.pay_money" +
            "</if>" +
            "<if test=\"maps.sortOrder != null and maps.sortOrder != ''\">" +
            "    ${maps.sortOrder}" +
            "</if>" +
            "<if test=\"maps.sortField == null or maps.sortField == ''\">" +
            "    o.id desc " +
            "</if> " +
            " limit 50000 "+
            "</script>"})
    List<FsStoreOrderErpExportVO> selectFsStoreOrderErpListVOByExport(@Param("maps") FsStoreOrderParam param);

    @Select("select * from fs_store_order_scrm where  `status`=2 and (extend_order_id is not null and extend_order_id != '') and (delivery_id is not null and delivery_id != '')")
    List<FsStoreOrderScrm> selectShippedOrder();
    /**
     * 获取发货单数据
     * @param maps 查询参数
     * @return list
     * **/
    List<FsStoreOrderDeliveryNoteExportVO> getDeliveryNote(@Param("maps") FsStoreOrderParam maps);
    /**
     * 获取订单用户信息
     * @param list 订单号
     * @return lsit
     * **/
    List<FsStoreOrderCodeOpenIdVo> selectOrderCodeOpenIdInOrderCode(@Param("list") List<String> list);
    /**
     * 获取未结算订单
     * **/
    List<FsStoreOrderScrm> getUnsettledOrder();

}
