package com.zhongdao.jlr.business.service.impl;

import com.util.Vo;
import com.zhongdao.jlr.business.dao.UserInfoDao;
import com.zhongdao.jlr.business.service.UserInfoService;
import com.zhongdao.jlr.pojo.BaseRole;
import com.zhongdao.jlr.pojo.EnterpriseJlr;
import com.zhongdao.jlr.pojo.JLRRole;
import com.zhongdao.jlr.pojo.JLRUser;
import jodd.util.BCrypt;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 处理用户信息管理的业务
 */
@Service(value = "userInfoService")
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoDao dao;

    @Override
    public List<JLRRole> getRoleInfo() {
        return dao.getRoleInfo();
    }

    @Override
    public List<EnterpriseJlr> getEnterpriseInfo() {
        return dao.getEnterpriseInfo();
    }

    @Override
    public Vo getUserInfo(HttpServletRequest request,String name,String phone,String role,String username) {
        return dao.getUserInfo(request,name,phone,role,username);
    }

    @Override
    public boolean updateUserInfo(JLRUser user) {
        //声明一个当前日期的对象
        Date date=new Date();
        //将当前日期存入对象中
        user.setUpdate_time(date);
        if(!TextUtils.isEmpty(user.getPassword())){
            //密码加密
            user.setPassword(BCrypt.hashpw(user.getPassword(),BCrypt.gensalt()));
        }
        return dao.updateUserInfo(user);
    }

    @Override
    public JLRUser getUser(String id) {
        return dao.getUser(id);
    }

    @Override
    public boolean deleteUser(JLRUser user) {
        return dao.deleteUser(user);
    }
}
