package com.fs.oms.mapper;

import java.util.List;
import com.fs.oms.domain.OmsOrder;
import com.fs.oms.param.OmsInnerOrderParam;
import com.fs.oms.vo.OmsInnerOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * oms销售订单Mapper接口
 *
 * @author fs
 * @date 2023-06-26
 */
public interface OmsOrderMapper
{
    /**
     * 查询oms销售订单
     *
     * @param id oms销售订单ID
     * @return oms销售订单
     */
    public OmsOrder selectOmsOrderById(Long id);

    /**
     * 查询oms销售订单列表
     *
     * @param omsOrder oms销售订单
     * @return oms销售订单集合
     */
    public List<OmsOrder> selectOmsOrderList(OmsOrder omsOrder);

    /**
     * 新增oms销售订单
     *
     * @param omsOrder oms销售订单
     * @return 结果
     */
    public int insertOmsOrder(OmsOrder omsOrder);

    /**
     * 修改oms销售订单
     *
     * @param omsOrder oms销售订单
     * @return 结果
     */
    public int updateOmsOrder(OmsOrder omsOrder);

    /**
     * 删除oms销售订单
     *
     * @param id oms销售订单ID
     * @return 结果
     */
    public int deleteOmsOrderById(Long id);

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


    @Select({"<script> " +
            " select DISTINCT o.*,s.store_name,s.channel_type,u.user_name from oms_order o  left join oms_store s on o.store_id=s.store_id" +
            " LEFT JOIN fs_store_order_item i  on o.id=i.order_id LEFT JOIN fs_store_product p on i.product_id=p.product_id  " +
            " LEFT JOIN oms_logistics l on o.logistics_id=l.id " +
            "left join sys_user u on u.user_id=o.create_user_id " +
            "where 1=1 " +
            "<if test = 'maps.innerOrderNo != null and  maps.innerOrderNo !=\"\"    '> " +
            "and  ( o.inner_order_no like CONCAT('%',#{maps.innerOrderNo},'%') or o.outer_order_no like CONCAT('%',#{maps.outerOrderNo},'%')   )           " +
            "</if>" +
            "<if test = 'maps.barCodes != null and  maps.barCodes !=\"\"    '> " +
            "and  ( o.bar_codes like CONCAT('%',#{maps.barCodes},'%') or p.product_name like CONCAT('%',#{maps.barCodes},'%')  )           " +
            "</if>" +
            "<if test = 'maps.skuCodes != null and  maps.skuCodes !=\"\"    '> " +
            "and  ( o.sku_codes like CONCAT('%',#{maps.skuCodes},'%')  )           " +
            "</if>" +
            "<if test = 'maps.channelType != null     '> " +
            "and c.inner_order_source =#{maps.channelType} " +
            "</if>" +
            "<if test = 'maps.storeId != null     '> " +
            "and s.store_id =#{maps.storeId} " +
            "</if>" +
            "<if test = 'maps.logisticsUserName != null and  maps.logisticsUserName !=\"\"    '> " +
            "and l.user_name like CONCAT('%',#{maps.logisticsUserName},'%') " +
            "</if>" +
            "<if test = 'maps.logisticsUserPhone != null and  maps.logisticsUserPhone !=\"\"    '> " +
            "and l.user_phone like CONCAT('%',#{maps.logisticsUserPhone},'%') " +
            "</if>" +
            "<if test = 'maps.buyerNick != null and  maps.buyerNick !=\"\"    '> " +
            "and o.buyer_nick like CONCAT('%',#{maps.buyerNick},'%') " +
            "</if>" +
            "<if test = 'maps.buyerRemark != null and  maps.buyerRemark !=\"\"    '> " +
            "and o.buyer_remark like CONCAT('%',#{maps.buyerRemark},'%') " +
            "</if>" +
            "<if test = 'maps.orderRemark != null and  maps.orderRemark !=\"\"    '> " +
            "and o.order_remark like CONCAT('%',#{maps.orderRemark},'%') " +
            "</if>" +
            "<if test = 'maps.tags != null and  maps.tags !=\"\"    '> " +
            "and find_in_set(#{maps.tags}, o.tags)   " +
            "</if>" +
            "<if test = 'maps.isGift != null     '> " +
            "and o.is_gift =#{maps.isGift} " +
            "</if>" +
            "<if test = 'maps.orderTime != null and maps.orderTime != \"\" '> " +
            "and date_format(o.order_time,'%y%m%d') &gt;= date_format(#{maps.orderTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.payTime != null and maps.payTime != \"\" '> " +
            "and date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.createTime != null and maps.createTime != \"\" '> " +
            "and date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTime},'%y%m%d') " +
            "</if>" +
            "<if test = 'maps.predictDeliveryTime != null and maps.predictDeliveryTime != \"\" '> " +
            "and date_format(o.predict_delivery_time,'%y%m%d') &lt;= date_format(#{maps.predictDeliveryTime},'%y%m%d') " +
            "</if>" +
            " order by o.id desc "+
            "</script>"})
    public List<OmsInnerOrderVO> selectOmsInnerOrderListVO(@Param("maps") OmsInnerOrderParam omsOrder);
}
