CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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);
    }
}