package cn.hnthyy.thmz.mapper.thmz;

import cn.hnthyy.thmz.entity.thmz.Receipt;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface ReceiptMapper {
    /**
     * 新增发票范围
     *
     * @param receipt
     * @return
     */
    @Insert("INSERT INTO t_receipt(user_id_code,receipt_begin,receipt_end,receipt_current,zy_receipt_begin,zy_receipt_end,zy_receipt_current,update_date) VALUES (#{userIdCode,jdbcType=VARCHAR}," +
            "#{receiptBegin,jdbcType=VARCHAR},#{receiptEnd,jdbcType=VARCHAR},#{receiptCurrent,jdbcType=VARCHAR},#{zyReceiptBegin,jdbcType=VARCHAR},#{zyReceiptEnd,jdbcType=VARCHAR}," +
            "#{zyReceiptCurrent,jdbcType=VARCHAR},#{updateDate,jdbcType=TIMESTAMP})")
    int insertReceipt(Receipt receipt);

    /**
     * 根据用户id查询用户的发票范围
     *
     * @param userIdCode
     * @return
     */
    @Select("select * from t_receipt where user_id_code=#{userIdCode,jdbcType=VARCHAR}")
    Receipt selectByUserIdCode(@Param("userIdCode") String userIdCode);

    /**
     * 变更发票范围
     *
     * @param receipt
     * @return
     */
    @Update({"<script>",
            "update t_receipt",
            "<trim prefix='set' prefixOverrides=',' suffix=' where user_id_code = #{userIdCode,jdbcType=VARCHAR}' >",
            "<when test='receiptBegin!=null'>",
            "receipt_begin=#{receiptBegin,jdbcType=VARCHAR}",
            "</when>",
            "<when test='receiptEnd!=null'>",
            ",receipt_end=#{receiptEnd,jdbcType=VARCHAR}",
            "</when>",
            "<when test='receiptCurrent!=null'>",
            ",receipt_current=#{receiptCurrent,jdbcType=VARCHAR}",
            "</when>",
            "<when test='zyReceiptBegin!=null'>",
            ",zy_receipt_begin=#{zyReceiptBegin,jdbcType=VARCHAR}",
            "</when>",
            "<when test='zyReceiptEnd!=null'>",
            ",zy_receipt_end=#{zyReceiptEnd,jdbcType=VARCHAR}",
            "</when>",
            "<when test='zyReceiptCurrent!=null'>",
            ",zy_receipt_current=#{zyReceiptCurrent,jdbcType=VARCHAR}",
            "</when>",
            "<when test='updateDate!=null'>",
            ",update_date=#{updateDate,jdbcType=TIMESTAMP}",
            "</when>",
            "</trim>",
            "</script>"})
    int updateReceipt(Receipt receipt);
}
