package com.fs.store.mapper;

import java.util.List;

import com.fs.store.domain.FsStoreOrder;
import com.fs.store.domain.FsStoreOrderOffline;
import com.fs.store.param.FsStoreOrderOfflineParam;
import com.fs.store.vo.FsStoreOrderOfflineListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 线下订单Mapper接口
 *
 * @author fs
 * @date 2024-10-29
 */
public interface FsStoreOrderOfflineMapper
{
    /**
     * 查询线下订单
     *
     * @param orderId 线下订单ID
     * @return 线下订单
     */
    public FsStoreOrderOffline selectFsStoreOrderOfflineById(Long orderId);

    /**
     * 查询线下订单列表
     *
     * @param fsStoreOrderOffline 线下订单
     * @return 线下订单集合
     */
    public List<FsStoreOrderOffline> selectFsStoreOrderOfflineList(FsStoreOrderOffline fsStoreOrderOffline);

    /**
     * 新增线下订单
     *
     * @param fsStoreOrderOffline 线下订单
     * @return 结果
     */
    public int insertFsStoreOrderOffline(FsStoreOrderOffline fsStoreOrderOffline);

    /**
     * 修改线下订单
     *
     * @param fsStoreOrderOffline 线下订单
     * @return 结果
     */
    public int updateFsStoreOrderOffline(FsStoreOrderOffline fsStoreOrderOffline);

    /**
     * 删除线下订单
     *
     * @param orderId 线下订单ID
     * @return 结果
     */
    public int deleteFsStoreOrderOfflineById(Long orderId);

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

    @Select({"<script> " +
            "select o.*,c.company_name,cu.nick_name as company_user_name,uu.nick_name as upload_user_name," +
            "cc.customer_name,cc.mobile from fs_store_order_offline o  " +
            "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 company_user uu on uu.user_id = o.upload_user_id " +
            "left join crm_customer cc on cc.customer_id = o.crm_id " +
            "where 1=1 " +
            "<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.crmId != null     '> " +
            "and o.crm_id =#{maps.crmId} " +
            "</if>" +
            "<if test = 'maps.status != null     '> " +
            "and o.status =#{maps.status} " +
            "</if>" +
            " order by o.order_id desc "+
            "</script>"})
    List<FsStoreOrderOfflineListVO> selectFsStoreOrderOfflineListVO(@Param("maps") FsStoreOrderOfflineParam param);

    @Select({"<script> " +
            "select o.*,c.company_name,cu.nick_name as company_user_name,uu.nick_name as upload_user_name," +
            "cc.customer_name,cc.mobile from fs_store_order_offline o  " +
            "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 company_user uu on uu.user_id = o.upload_user_id " +
            "left join crm_customer cc on cc.customer_id = o.crm_id " +
            "where o.order_id = #{orderId} " +
            "</script>"})
    FsStoreOrderOfflineListVO selectFsStoreOrderOfflineVOById(@Param("orderId") Long orderId);

    @Update("update fs_store_order_offline set upload_time= #{uploadTime},certificates =#{certificates} where order_id = #{orderId}")
    int uploadCredentials(FsStoreOrderOffline order);
}
