package com.fs.store.mapper;

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.company.vo.CompanySmsLogsStatisticsVO;
import com.fs.company.vo.CompanyTuiMoneyStatisticsVO;
import com.fs.store.domain.FsStoreOrder;
import com.fs.store.domain.FsStoreOrderItem;
import com.fs.store.param.*;
import com.fs.store.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 FsStoreOrderMapper
{
    /**
     * 查询订单
     *
     * @param id 订单ID
     * @return 订单
     */
    public FsStoreOrder selectFsStoreOrderById(Long id);

    /**
     * 查询订单列表
     *
     * @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 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 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 oi on o.id = oi.order_id "+
            "left join fs_store_product 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> 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 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 oi on o.id = oi.order_id "+
            "left join fs_store_product 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 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 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 oi on o.id = oi.order_id "+
            "left join fs_store_product 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 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 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 where order_code=#{orderCode}")
    FsStoreOrder selectFsStoreOrderByOrderCode(String orderCode);
    @Update("update fs_store_order set status=-3 where id=#{orderId}")
    int cancelOrder(Long orderId);
    @Select({"<script> " +
            "select o.*  from fs_store_order 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 where extend_order_id=#{extendOrderId}")
    FsStoreOrder selectFsStoreOrderByExtendOrderId(String extendOrderId);
    @Select({"<script> " +
            "select b.number 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 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.id desc"+
            "</script>"})
    List<FsStoreOrderTuiVO> selectFsStoreOrderTuiListVO(String userId);
    @Select({"<script> " +
            "select ifnull(count(1),0) from fs_store_order 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 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 o  " +
            "where o.delivery_id=#{deliveryId}  limit 1 " +
            "</script>"})
    FsStoreOrder 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 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);
    @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({"<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 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 o  " +
            "where o.is_del=0 and o.is_sys_del=0 and o.status=3 " +
            "and o.company_id =#{companyId} " +
            "</script>"})
    List<FsStoreOrder> selectFsStoreOrderByCompanyId(@Param("companyId")Long companyId);
    @Select({"<script> " +
            "select * from fs_store_order o  " +
            "where o.delivery_id=#{deliveryId} " +
            "</script>"})
    List<FsStoreOrder> selectFsStoreOrderListByDeliveryId( @Param("deliveryId") String deliveryId);
    @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({"<script> " +
            "select o.*  from fs_store_order 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 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 where status=3 and tui_user_id > 0 and tui_user_money_status !=1 and DATE_ADD(finish_time,INTERVAL 7 DAY)  > now() ")
    List<FsStoreOrder> 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 o  left JOIN fs_store_product_package 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<FsStoreOrderExportVO> 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 o  left JOIN fs_store_product_package 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 o " +
            "left join fs_store_product_attr_value 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 o  left JOIN fs_store_product_package 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 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 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 set upload_time= #{uploadTime},certificates =#{certificates} where id = #{id}")
    int uploadCredentials(FsStoreOrder order);

    @Select("select certificates from fs_store_order where id = #{id} ")
    String getCredentialsById(Long id);
    @Select("select id from fs_store_order 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 WHERE order_create_type<>2 and item_json is NULL ORDER BY id DESC  LIMIT 30")
    List<FsStoreOrder> selectFsStoreOrderItemJson();

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

    @Select("select extend_order_id from fs_store_order 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 set delivery_id = #{deliveryId},status = #{status}  where extend_order_id =#{extendOrderId} ")
    void updateDelivery(FsStoreOrder fsStoreOrder);


    @Select("select id from fs_store_order 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 set status = #{status}  where order_code =#{orderCode}")
    void updateDeliveryStatus(FsStoreOrder fsStoreOrder);

    @Select("select id from fs_store_order 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 where delivery_type = 406 and pay_money <=1 and status = 2 and delivery_pay_status is null and pay_type != 3 ")
    List<FsStoreOrder> selectPayMoneyLessOne();

    @Select("select * from fs_store_order_item where order_id = #{orderId}")
    List<FsStoreOrderItem> 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 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 where user_id = #{userId} limit 1")
    FsStoreOrder selectOrderByUserIdLimit1(Long userId);

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