liujie
2025-06-20 49251095c2cc2414064270aa6c9175463c56ad20
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package com.panzhihua.westcommittee.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.beust.jcommander.internal.Lists;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.west.SystemUserVo;
import com.panzhihua.common.utlis.PayUtil;
import com.panzhihua.common.utlis.StringUtils;
import com.panzhihua.westcommittee.dao.SystemUserLevelMapper;
import com.panzhihua.westcommittee.dao.SystemUserMapper;
import com.panzhihua.westcommittee.model.entity.*;
import com.panzhihua.westcommittee.model.vo.RegionVO;
import com.panzhihua.westcommittee.service.*;
import com.panzhihua.westcommittee.utils.ExcelUtil;
import com.panzhihua.westcommittee.warpper.SystemUserList;
import com.panzhihua.westcommittee.warpper.SystemUserListVo;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import sun.security.util.Password;
 
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
 
/**
 * @author zhibing.pu
 * @Date 2025/2/18 22:30
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser> implements ISystemUserService {
    private final IComActService comActService;
    private final SystemUserLevelMapper systemUserLevelMapper;
    private final IComStreetService comStreetService;
    private final ExcelUtil excelUtil;
    private final IDepartmentService departmentService;
    private final ISystemPostService systemPostService;
 
    /**
     * 获取列表数据
     * @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);
    }
 
    /**
     * 获取区县-街道-社区树
     * @return
     */
    @Override
    public List<RegionVO> getRegionTree(SystemUserVo loginUserInfo) {
        log.info("getRegionTree入参:{}", JSONObject.toJSONString(loginUserInfo));
        SystemUser systemUser = getById(loginUserInfo.getId());
        Integer accountLevel = systemUser.getAccountLevel();
        List<RegionVO> regionTree = new ArrayList<>();
        switch (accountLevel) {
            case 1:
                regionTree = baseMapper.getRegion("510400");
                baseMapper.getStreet("510400");
                regionTree.forEach(district -> {
                    district.setTier(2);
                    List<RegionVO> streets = baseMapper.getStreet(district.getId());
                    district.setChildren(streets);
                    streets.forEach(street -> {
                        street.setTier(3);
                        List<RegionVO> communities = baseMapper.getCommunity(street.getId());
                        communities.forEach(e -> e.setTier(4));
                        street.setChildren(communities);
                    });
                });
                break;
            case 2:
                regionTree = baseMapper.getStreet(systemUser.getDistrictsCode());
                regionTree.forEach(regionVO -> {
                    regionVO.setTier(3);
                    List<RegionVO> communities = baseMapper.getCommunity(regionVO.getId());
                    communities.forEach(e -> e.setTier(4));
                    regionVO.setChildren(communities);
                });
                break;
            case 3:
                ComStreet street = comStreetService.getById(systemUser.getStreetId());
                RegionVO streetVO = new RegionVO();
                streetVO.setId(street.getStreetId());
                streetVO.setName(street.getName());
                streetVO.setTier(3);
                List<RegionVO> communities = baseMapper.getCommunity(systemUser.getStreetId());
                communities.forEach(e -> e.setTier(4));
                streetVO.setChildren(communities);
                regionTree = Lists.newArrayList(streetVO);
                break;
            case 4:
                ComAct byId = comActService.getById(systemUser.getCommunityId());
                RegionVO regionVO = new RegionVO();
                regionVO.setTier(4);
                regionVO.setId(byId.getCommunityId().toString());
                regionVO.setName(byId.getName());
                regionTree = Lists.newArrayList(regionVO);
                break;
        }
 
        return regionTree;
    }
 
    @Override
    public String getCreateByIdPhone(Long createBy) {
        return this.baseMapper.getCreateByIdPhone(createBy);
    }
 
    @SneakyThrows
    @Override
    public R<?> importUser(String s, MultipartFile file) {
        List<List<List<String>>> upload = excelUtil.upload(s, file);
        List<List<String>> lists = upload.get(0);
        for (List<String> list : lists) {
            String name = list.get(0);
            String postName = list.get(1);
            String deptName = list.get(2);
            String roleId = list.get(3);
            String phone = list.get(4);
            String pwd = list.get(5);
 
            long count = this.count(new LambdaQueryWrapper<SystemUser>().eq(SystemUser::getPhone, phone).ne(SystemUser::getStatus, 3));
            if (0 == count) {
                SystemUser systemUser = new SystemUser();
                systemUser.setName(name);
                systemUser.setPhone(phone);
                systemUser.setPassword(PayUtil.MD5(pwd).toLowerCase());
 
                try {
                    Department name1 = departmentService.getOne(new QueryWrapper<Department>().eq("name", deptName));
                    systemUser.setOneDepartmentId(name1.getId());
                    systemUser.setDistricts(name1.getDistricts());
                    systemUser.setDistrictsCode(name1.getDistrictsCode());
                    systemUser.setStreet(name1.getStreet());
                    systemUser.setStreetId(name1.getStreetId());
                    systemUser.setCommunity(name1.getCommunity());
                    systemUser.setCommunityId(name1.getCommunityId());
                    systemUser.setAccountLevel(name1.getTier());
                    systemUser.setStatus(1);
                    systemUser.setSystemRoleId(Integer.valueOf(roleId));
                    systemUser.setCreateTime(LocalDateTime.now());
 
                    SystemPost name2 = systemPostService.getOne(new QueryWrapper<SystemPost>().eq("name", postName));
                    systemUser.setSystemPostId(name2.getId());
                    save(systemUser);
 
                } catch (Exception e) {
                    System.out.println(deptName);
                    System.out.println(postName);
                    e.printStackTrace();
                }
            }
        }
 
 
        return R.ok();
    }
 
    public static void main(String[] args) throws Exception {
        System.out.println(PayUtil.MD5("111111").toLowerCase());
    }
 
}