mitao
2025-03-14 08f1b1f1804a8bd833d42f257908d80e88387b55
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.panzhihua.sangeshenbian.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.sangeshenbian.dao.SystemUserMapper;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.model.vo.RegionVO;
import com.panzhihua.sangeshenbian.model.vo.UpdatePasswordDTO;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import com.panzhihua.sangeshenbian.warpper.SystemUserList;
import com.panzhihua.sangeshenbian.warpper.SystemUserListVo;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Optional;
 
/**
 * @author zhibing.pu
 * @Date 2025/2/18 22:30
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService {
    
    /**
     * 获取列表数据
     * @param query
     * @return
     */
    @Override
    public IPage<SystemUserListVo> list(SystemUser user, SystemUserList query) {
        Page page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());
        IPage<SystemUserListVo> list = this.baseMapper.list(page, user, query);
        return list;
    }
 
    /**
     * 根据手机号码查询小程序用户在三个身边的上级角色用户
     * @param phone
     * @return
     */
    @Override
    public Optional<SystemUser> getSystemUserAdminByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            return Optional.empty();
        }
        return this.lambdaQuery()
                .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3)
                .eq(SystemUser::getIsAdmin, 1).last("LIMIT 1").oneOpt();
    }
 
    @Override
    public Optional<SystemUser> getSystemUserByPhone(String phone) {
        if (StringUtils.isBlank(phone)) {
            return Optional.empty();
        }
        return this.lambdaQuery()
                .eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3).last("LIMIT 1").oneOpt();
    }
 
    /**
     * 获取行政区划数据
     *
     * @param pcode
     * @return
     */
    @Override
    public List<RegionVO> getRegion(String pcode) {
        return this.baseMapper.getRegion(pcode);
    }
    
    
    /**
     * 获取街道数据
     *
     * @param areaCode
     * @return
     */
    @Override
    public List<RegionVO> getStreet(String areaCode) {
        return this.baseMapper.getStreet(areaCode);
    }
    
    
    /**
     * 获取社区数据
     *
     * @param streetId
     * @return
     */
    @Override
    public List<RegionVO> getCommunity(String streetId) {
        return this.baseMapper.getCommunity(streetId);
    }
 
    /**
     * 修改密码
     * @param dto
     * @param systemUserVo
     */
    @Override
    public void updatePassword(UpdatePasswordDTO dto, SystemUserVo systemUserVo) {
        if (systemUserVo == null) {
            throw new ServiceException("用户不存在");
        }
        if (systemUserVo.getPassword().equals(dto.getNewPassword())) {
            throw new ServiceException("新密码不能与旧密码相同");
        }
        if (!systemUserVo.getPassword().equals(dto.getOldPassword())) {
            throw new ServiceException("旧密码错误");
        }
        this.lambdaUpdate().set(SystemUser::getPassword, dto.getNewPassword()).eq(SystemUser::getId, systemUserVo.getId()).update();
    }
}