/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.mapper;

import com.ifish.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

/**
 *
 * @author Administrator
 */
public interface Tbl_User_Mapper {

    /**
     * 根据手机号获取用户对象
     *
     * @return
     */
    @Select("SELECT user_id,nick_name,user_password,phone_number,user_img,user_sex,signature,login_count,phone_type,update_time,login_time,create_time,login_type,remarks,"
            + "address,P2PVerify_code1,P2PVerify_code2,gwell_userID,is_register_gwell,user_type,shops_user_id,netease_token,is_register_netease,latitude,longitude from tbl_user where phone_number=#{phoneNumber}")
    User getUserByPhoneNumber(@Param("phoneNumber") String phoneNumber);

    /**
     * 根据用户ID获取用户对象
     *
     * @param userid
     * @return
     */
    @Select("SELECT user_id,nick_name,user_password,phone_number,user_img,user_sex,signature,login_count,phone_type,update_time,login_time,create_time,login_type,remarks,"
            + "address,P2PVerify_code1,P2PVerify_code2,gwell_userID,is_register_gwell,user_type,shops_user_id,netease_token,is_register_netease,latitude,longitude from tbl_user where user_id=#{userid}")
    User getUserByUserId(@Param("userid") String userid);

    /**
     * 每次登陆后修改登陆时间、次数和手机类型
     *
     * @param userId
     * @param loginType
     * @return
     */
    @Update("update tbl_user set login_count=if(login_count is null,1,login_count+1),login_type=#{logintype},login_time=current_timestamp() where user_id=#{userid}")
    Integer executeLoginUpdate(@Param("userid") Integer userId, @Param("logintype") String loginType);

    /**
     * 修改用户账号信息
     *
     * @param user
     * @return
     */
    @UpdateProvider(type = Tbl_User_MapperSql.class, method = "updateUser")
    Integer updateUser(@Param("user") User user);
}
