package com.community.huiju.dao;

import com.community.huiju.model.TaUserLicenseOrder;
import com.community.huiju.model.TpBillOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TaUserLicenseOrderMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TaUserLicenseOrder record);

    int insertSelective(TaUserLicenseOrder record);

    TaUserLicenseOrder selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TaUserLicenseOrder record);

    int updateByPrimaryKey(TaUserLicenseOrder record);

    /**
     * 缴费记录
     * @return
     */
    @ResultMap("BaseResultMap")
    @Select("select * from ta_user_license_order where community_id = #{communityId} and ta_user_id = #{userId} and order_status = 1 order by update_date DESC")
    List<TaUserLicenseOrder> selectRecords(@Param("communityId") Integer communityId, @Param("userId") Integer userId);

    /**
     * 根据订单号查询
     * @param orderNo
     * @return
     */
    @ResultMap("BaseResultMap")
    @Select("select * from ta_user_license_order where order_number=#{orderNo}")
    List<TaUserLicenseOrder> selectByOrderNumber(String orderNo);

    /**
     * 可关闭的订单
     * @return
     */
    @ResultMap("BaseResultMap")
    @Select("SELECT t.* from ta_user_license_order t where TIMESTAMPDIFF(MINUTE,create_date,now()) >= 10 and t.order_status in (0,2)")
    List<TaUserLicenseOrder> selectCloseOrder();
}