package com.winsun.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.winsun.bean.OrderView;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @Author: chancy
 * @Date: 2020/2/18 17:04
 */
@Mapper
@Component
public interface OrderViewMapper extends BaseMapper<OrderView> {

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

    /**
     * 智能平台推送接收
     * @return
     */
    @Update("<script>UPDATE `hhr_order` set th_status = #{status},order_status = #{orderStatus} <where> ${ew.sqlSegment} </where> </script>")
    Integer IntelligentPlatformPush(@Param("ew") Wrapper<Object> wrapper,@Param("status")String status,@Param("orderStatus")String orderStatus);

    @Select("<script>SELECT id FROM `hhr_order` <where> ${ew.sqlSegment} </where> </script>")
    String selectOrderId(@Param("ew") Wrapper<Object> wrapper);

    @Insert("insert into`hhr_order_history`(order_id, status, create_date) values(#{id}, #{status}, #{createTime})")
    int insertOrderHistory(@Param("id")String id,@Param("status")String status,@Param("createTime") Timestamp createTime);

    @Select("select * from order_view where orderSeq = #{orderSeq}")
    Map<String, Object> queryorderSeq(@Param("orderSeq")String orderSeq);

    @Update("update hhr_order set rh_time = #{rhTime} where orderSeq=#{orderSeq}")
    int updatePayRhTime(@Param("rhTime") String rhTime, @Param("orderSeq") String orderSeq);

    @Select("select * from order_view where orderNumber=#{orderNumber} and status !=#{status} ")
    List<Map<String,Object>> orderViewToStatusList(@Param("orderNumber")String orderNumber,@Param("status")String status);

    @Select("select order_university_name from order_view where orderSeq = #{kdOrderId}")
    String selectByKdOrderId (@Param("kdOrderId") String kdOrderId);

    /**
     * 根据订单编号删除订单
     *
     * @param orderSeq
     */
    @Delete("delete from order_view where orderSeq = #{orderSeq}")
    void deleteOrderSeq(@Param("orderSeq") String orderSeq);
}
