package cn.com.ty.lift.ud.userAccount.mapper;

import cn.com.ty.lift.common.model.PushUserInfo;
import cn.com.ty.lift.ud.userAccount.mapper.entity.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 用户账号表 -Repository
 * 
 * @author Xson
 * @date 2020-05-13
 */
@Repository(value = "udUserAccountMapper")
public interface UserAccountMapper extends BaseMapper<UserAccount> {

    @Update("UPDATE user_account SET expert_flag=#{falg} WHERE user_id=#{id} ")
    void examineById(@Param("id") Long id, @Param("falg") Integer falg);

    /**
     * 删除账户信息
     * 
     * @param id
     */
    @Update("UPDATE user_account SET delete_flag = 1 WHERE user_id= #{id} ")
    void deleteAccount(Long id);

    /**
     * 根据ID查询用户信息
     * 
     * @param userId
     */
    @Select("SELECT * from user_account where user_id= #{userId}")
    UserAccount getOneById(Long userId);

    /**
     * 修改账户信息
     * 
     * @param mobile
     * @param userId
     */
    @Update("UPDATE user_account SET account = #{mobile} , mobile = #{mobile} WHERE user_id= #{userId} ")
    void updateInfo(@Param("mobile") String mobile, @Param("userId") Long userId);

    /**
     * 提出专家
     * 
     * @param userId
     */
    @Update("UPDATE user_account SET expert_flag = 0 WHERE user_id= #{userId} ")
    void updateUserExpert(@Param("userId") String userId);

    /**
     * 解冻账户信息
     * 
     * @param userId
     */
    @Update("UPDATE user_account SET delete_flag = 0 WHERE user_id= #{userId} ")
    void noDeleteAccount(Long userId);

    @Select("select ua.user_id,ua.device_model,ua.device_flag,ui.mobile,ui.`name`userName from user_account ua left join user_info ui on ui.user_id=ua.user_id where ua.user_id=#{userId}")
    PushUserInfo getPushUserInfoByUserId(@Param("userId") String userId);
}
