package cn.com.ty.lift.ud.userAccount.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.ty.lift.common.model.PushUserInfo;
import cn.com.ty.lift.ud.applyExpert.mapper.ApplyExpertMapper;
import cn.com.ty.lift.ud.operation.mapper.UserLevelRuleMapper;
import cn.com.ty.lift.ud.operation.mapper.entity.UserLevelRuleEntity;
import cn.com.ty.lift.ud.userAccount.mapper.UserAccountMapper;
import cn.com.ty.lift.ud.userAccount.mapper.entity.UserAccount;
import cn.com.ty.lift.ud.userAccount.service.IUserAccountService;
import cn.com.ty.lift.ud.userInfo.mapper.UserInfoMapper;
import cn.com.ty.lift.ud.userInfo.mapper.entity.UserInfoEntity;

/**
 * 用户账号表 -ServiceImpl
 *
 * @author Xson
 * @date 2020-05-13
 */
@Service
@Transactional
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements IUserAccountService {

    @Autowired
    private UserAccountMapper udUserAccountMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private UserLevelRuleMapper userLevelRuleMapper;

    @Autowired
    private ApplyExpertMapper applyExpertMapper;

    /**
     * 删除账号信息
     * 
     * @param id
     */
    @Override
    public void deleteAccount(Long id) {
        udUserAccountMapper.deleteAccount(id);
    }

    /**
     * 根据ID查询用户信息
     * 
     * @param userId
     * @return
     */
    @Override
    public UserAccount getOneById(Long userId) {
        UserAccount userAccount = udUserAccountMapper.getOneById(userId);
        return userAccount;
    }

    /**
     * 修改账户信息
     * 
     * @param mobile
     */
    @Override
    public void updateInfo(String mobile, Long userId) {
        udUserAccountMapper.updateInfo(mobile, userId);
    }

    @Override
    public void updateUserExpert(String userId) {
        UserInfoEntity selectById = userInfoMapper.getByUserId(Long.parseLong(userId));
        UserLevelRuleEntity selectById2 = userLevelRuleMapper.selectById(selectById.getUserLevel());
        userInfoMapper.updateByLevelName(selectById2.getName(),selectById.getUserId());
        udUserAccountMapper.updateUserExpert(userId);
        applyExpertMapper.updateStatusByUserId(userId);
    }

    /**
     * 解冻账户信息
     * 
     * @param userId
     */
    @Override
    public void noDeleteAccount(Long userId) {
        udUserAccountMapper.noDeleteAccount(userId);
    }

    @Override
    public PushUserInfo getPushUserInfoByUserId(String userId) {
        return udUserAccountMapper.getPushUserInfoByUserId(userId);
    }
}
