package com.winsun.mapper;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.winsun.bean.Order;
import com.winsun.bean.OrderView;

@Mapper
@Component
public interface OrderMapper extends BaseMapper<Order> {

    @Insert("insert into `hhr_order_history` values(#{id},#{status},#{date},#{operator}) ")
    Integer inserOrderHis(@Param("id") String id, @Param("status") String status, @Param("date") Date date, @Param("operator") String operator);


    @Select("<script>SELECT * FROM `hhr_order` <where> ${ew.sqlSegment} </where> </script>")
    List<Map<String, Object>> downloadOrder(@Param("ew") Wrapper<Order> wrapper);

    @Select("select *  from `hhr_order_history` where  order_id = #{oredrId}")
    List<Map<String,Object>> selectOrderHis(String oredrId);

    @Update("update `hhr_order` set order_status = #{orderStatus}, accept_name = #{acceptName}," +
            " accept_result = #{acceptResult}, accept_comment = #{acceptComment}, accept_date = #{acceptDate} " +
            " where order_number = #{orderNumber}")
    Integer updateOrderSUByOrderNumberIsNotNull(@Param("orderNumber") String orderNumber,@Param("orderStatus") String orderStatus,
                              @Param("acceptName") String acceptName,@Param("acceptResult") String acceptResult,
                              @Param("acceptComment") String acceptComment,@Param("acceptDate") Date acceptDate);

    @Update("update `hhr_order` set order_status = #{orderStatus}, accept_name = #{acceptName}," +
            " accept_result = #{acceptResult}, accept_date = #{acceptDate} " +
            " where order_number = #{orderNumber}")
    Integer updateOrderSUByOrderNumberIsNull(@Param("orderNumber") String orderNumber,@Param("orderStatus") String orderStatus,
                                                @Param("acceptName") String acceptName,@Param("acceptResult") String acceptResult,
                                                @Param("acceptDate") Date acceptDate);

    @Update("update `hhr_order` set order_status = #{orderStatus},company = #{company},kuaidi_order = #{kuaidiOrder},send_type = #{sendType}  where order_number = #{orderNumber}")
    Integer updateOrderKDIsNotNull(@Param("orderNumber") String orderNumber,@Param("company") String company,@Param("kuaidiOrder") String kuaidiOrder,@Param("sendType") String sendType,@Param("orderStatus") String orderStatus);

    @Update("update `hhr_order` set order_status = #{orderStatus},send_type = #{sendType}  where order_number = #{orderNumber}")
    Integer updateOrderKDIsNull(@Param("orderNumber") String orderNumber,@Param("sendType") String sendType,@Param("orderStatus") String orderStatus);

    @Select("select id  from `hhr_order` where  order_number = #{orderNumber}")
    String selectIdByOrderNumber(String orderNumber);

    @Select("select xb_order_id xbOrderId  from `hhr_order` where  order_number = #{orderNumber}")
    String selectxbOrderIdByOrderNumber(String orderNumber);

    @Select("select ysm from `hhr_user` where  id = #{id}")
    String selectYsmById(String id);
}
