package com.ld.igds.phone.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.phone.constant.PhoneConstant;
|
import com.ld.igds.phone.param.ParamUser;
|
import com.ld.igds.phone.util.PhoneRespUtil;
|
import com.ld.igds.phone.dto.AuthUser;
|
import com.ld.igds.phone.dto.DtoUser;
|
import com.ld.igds.phone.dto.PhoneResponse;
|
import com.ld.igds.phone.mapper.PhoneCommonMapper;
|
import com.ld.igds.phone.param.PhoneRequest;
|
import com.ld.igds.phone.service.PhoneService;
|
import com.ld.igds.phone.util.PhoneUtil;
|
import com.ld.igds.util.RedisUtil;
|
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.authentication.encoding.PasswordEncoder;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
|
/**
|
* 用户信息修改接口实现
|
* @author chen
|
*/
|
@Service
|
public class ServiceImpl5004 implements PhoneService {
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private PhoneCommonMapper phoneCommonMapper;
|
@Resource(name = "bdf2.passwordEncoder")
|
private PasswordEncoder passwordEncoder;
|
|
@Override
|
public String getInterfaceId() {
|
return PhoneConstant.API_PHONE_5004;
|
}
|
|
@SuppressWarnings("unchecked")
|
@Override
|
public PhoneResponse<Object> execute(PhoneRequest<JSONObject> req, AuthUser authUser)
|
throws Exception {
|
ParamUser param = JSONObject.parseObject(req.getData().toJSONString(),
|
ParamUser.class);
|
|
if (StringUtils.isEmpty(param.getNewPassword1())) {
|
return PhoneRespUtil.error(RespCodeEnum.CODE_1007, "修改信息中密码不能为空!");
|
}
|
if (!param.getNewPassword1().equals(param.getNewPassword2())) {
|
return PhoneRespUtil.error(RespCodeEnum.CODE_1007, "两次密码不一致!");
|
}
|
|
//对密码进行加密处理
|
String salt = String.valueOf(RandomUtils.nextInt(100));
|
String password = passwordEncoder.encodePassword(
|
param.getNewPassword1(), salt);
|
//设置加密密码和加密盐
|
param.setPassword(password);
|
param.setSalt(salt);
|
param.setUsername(authUser.getUsername());
|
param.setCompanyId(authUser.getCompanyId());
|
|
//更新用户信息
|
phoneCommonMapper.phoneUpdateUser(param);
|
|
//将更新后的用户信息存入缓存中
|
authUser.setCname(param.getNewCname());
|
authUser.setMobile(param.getNewMobile());
|
redisUtil.set(PhoneUtil.createKey(req.getTokenAuth()),
|
authUser, 60*60*24);
|
|
DtoUser dto = new DtoUser();
|
dto.setCname(authUser.getCname());
|
dto.setUsername(authUser.getUsername());
|
dto.setMobile(authUser.getMobile());
|
|
return PhoneRespUtil.success(dto, req);
|
}
|
}
|