mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package com.panzhihua.service_community.service.impl;
 
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
import javax.annotation.Resource;
 
import com.panzhihua.common.model.vos.community.ComActPasswordVo;
import com.panzhihua.common.model.vos.community.ComBasicDataVo;
import com.panzhihua.common.model.vos.partybuilding.ComPbMemberTypeVO;
import com.panzhihua.service_community.dao.ComPbMemberDAO;
import com.panzhihua.service_community.util.MyAESUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
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.panzhihua.common.model.dtos.community.PageComActDTO;
import com.panzhihua.common.model.dtos.community.switchs.SearchCommunityDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComActVO;
import com.panzhihua.common.model.vos.community.switchs.CommunitySwitchAllAppletsVO;
import com.panzhihua.common.model.vos.community.switchs.StreetAllAppletsVO;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ComStreetDAO;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ComStreetDO;
import com.panzhihua.service_community.service.ComActService;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 社区
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2020-12-15 10:13
 **/
@Service
public class ComActServiceImpl implements ComActService {
    @Resource
    private ComActDAO comActDAO;
    @Resource
    private ComStreetDAO comStreetDAO;
    @Resource
    private ComPbMemberDAO comPbMemberDAO;
 
    /**
     * 新增社区
     *
     * @param comActVO
     *            社区信息
     * @return 新增结果
     */
    @Override
    public R addCommunity(ComActVO comActVO) {
        String password = comActVO.getPassword();
        String encode = new BCryptPasswordEncoder().encode(password);
        comActVO.setPassword(encode);
        ComStreetDO comStreetDO = comStreetDAO.selectById(comActVO.getStreetId());
        if (comStreetDO == null) {
            return R.fail("当前街道不存在!");
        }
        ComActDO comActDO = new ComActDO();
        Integer integer =
            comActDAO.selectCount(new QueryWrapper<ComActDO>().lambda()
                    .eq(ComActDO::getName, comActVO.getName())
                    .eq(ComActDO::getCityCode,comActVO.getCityCode())
                    .eq(ComActDO::getAreaCode,comActVO.getAreaCode())
                    .eq(ComActDO::getProvinceCode,comActVO.getProvinceCode())
                    .eq(ComActDO::getAppId,comActVO.getAppId())
            );
        if (integer > 0) {
            return R.fail("社区已经存在");
        }
        BeanUtils.copyProperties(comActVO, comActDO);
        comActDO.setPlaintextPassword(password);
        int insert = comActDAO.insert(comActDO);
        if (insert > 0) {
            ComActDO comActDO1 =
                comActDAO.selectOne(new QueryWrapper<ComActDO>().lambda()
                        .eq(ComActDO::getCommunityId, comActVO.getCommunityId())
                );
            BeanUtils.copyProperties(comActDO1, comActVO);
            return R.ok(comActVO);
        }
        return R.fail();
    }
 
    /**
     * 编辑社区
     *
     * @param comActVO
     *            编辑内容
     * @return 编辑结果
     */
    @Override
    public R putCommunity(ComActVO comActVO) {
        ComActDO comActDO = new ComActDO();
        String password = comActVO.getPassword();
        String account = comActVO.getAccount();
        Long communityId = comActVO.getCommunityId();
        // String contacts = comActVO.getContacts();
        int a = 0;
        if (!ObjectUtils.isEmpty(password)) {
            String encode = new BCryptPasswordEncoder().encode(password);
            comActVO.setPassword(encode);
            comActDO.setPlaintextPassword(password);
            a = 1;
        }
        ComStreetDO comStreetDO = comStreetDAO.selectById(comActVO.getStreetId());
        if (comStreetDO == null) {
            return R.fail("当前街道不存在!");
        }
        // if(!ObjectUtils.isEmpty(account)||!ObjectUtils.isEmpty(contacts)){
        // a=1;
        // }
        BeanUtils.copyProperties(comActVO, comActDO);
//        ComActDO selectOne = comActDAO.selectOne(new QueryWrapper<ComActDO>().lambda().eq(ComActDO::getAccount, account));
//        if (null != selectOne && selectOne.getAccount().equals(comActVO.getAccount())) {
//            return R.fail("该登录账号重复,请重新修改");
//        }
        int update = comActDAO.updateById(comActDO);
        if (update > 0) {
            if (a == 1) {
                // 修改登录账户的密码
                comActDAO.updateAccountPassword(comActVO.getPassword(), account, communityId);
            }
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 查询社区
     *
     * @param comActVO
     *            登录人的经纬度、或者指定区域的社区
     * @return 社区集合
     */
    @Override
    public R listCommunity(ComActVO comActVO) {
        List<ComActVO> comActVOS = comActDAO.listCommunity(comActVO);
        return R.ok(comActVOS);
    }
 
    /**
     * 社区详情
     *
     * @param communityId
     *            社区id
     * @return 社区详情
     */
    @Override
    public R detailCommunity(Long communityId) {
        ComActDO comActDO = comActDAO.selectById(communityId);
        if (ObjectUtils.isEmpty(comActDO)) {
            return R.fail();
        }
        ComActVO comActVO = new ComActVO();
        BeanUtils.copyProperties(comActDO, comActVO);
        comActVO.setAreaName(comActDAO.selectAreaName(comActVO.getAreaCode()));
        comActVO.setAccount(null);
        comActVO.setPassword(null);
        comActVO.setAddress(null);
        comActVO.setContacts(null);
        comActVO.setCreateAt(null);
        comActVO.setState(null);
        comActVO.setDistance(null);
        return R.ok(comActVO);
    }
 
    /**
     * 分页查询社区
     *
     * @param pageComActDTO
     *            查询参数
     * @return 分页集合
     */
    @Override
    public R pageCommunity(PageComActDTO pageComActDTO) {
        Page page = new Page<>();
        Long pageNum = pageComActDTO.getPageNum();
        Long pageSize = pageComActDTO.getPageSize();
        if (null == pageNum || 0 == pageNum) {
            pageNum = 1l;
        }
        if (null == pageSize || 0 == pageSize) {
            pageSize = 10l;
        }
        page.setSize(pageSize);
        page.setCurrent(pageNum);
        IPage<ComActVO> iPage = comActDAO.pageCommunity(page, pageComActDTO);
        return R.ok(iPage);
    }
 
    /**
     * 查询平台所有的社区
     *
     * @return 社区集合 按照创建顺序倒序排列
     */
    @Override
    public R listCommunityAll(String areaCode) {
        List<ComActDO> comActDOS = comActDAO.selectList(new QueryWrapper<ComActDO>().lambda().eq(ComActDO::getState, 0)
            .eq(ComActDO::getAreaCode, areaCode).orderByDesc(ComActDO::getCreateAt));
        List<ComActVO> comActVOS = new ArrayList<>();
        if (!ObjectUtils.isEmpty(comActDOS)) {
            comActDOS.forEach(comActDO -> {
                ComActVO comActVO = new ComActVO();
                BeanUtils.copyProperties(comActDO, comActVO);
                comActVOS.add(comActVO);
            });
        }
        return R.ok(comActVOS);
    }
 
    /**
     * 删除社区
     *
     * @param communityId
     *            社区id
     * @return 删除结果
     */
    @Override
    public R delectCommunity(Long communityId) {
        int delete = comActDAO.deleteById(communityId);
        if (delete > 0) {
            return R.ok();
        }
        return R.fail();
    }
 
    /**
     * 综治后台-查询社区列表
     * 
     * @return 社区列表
     */
    @Override
    public R getCommunityLists(String appId) {
        return R.ok(this.comActDAO.getCommunityLists(appId));
    }
 
    @Override
    public R getWestCommunityLists(String areaCode) {
        return R.ok(this.comActDAO.getWestCommunityLists(areaCode));
    }
 
    /**
     * 查询社区所有列表
     * 
     * @return 社区列表
     */
    @Override
    public R getCommunityAllList(String appId) {
        // 查询街道列表
        List<StreetAllAppletsVO> streetList = this.comActDAO.getStreetList(appId);
        streetList.forEach(street -> {
            // 查询街道下社区列表
            List<CommunitySwitchAllAppletsVO> communityList =
                this.comActDAO.getCommunityListByStreetId(street.getStreetId());
            if (!communityList.isEmpty()) {
                street.setChildList(communityList);
                street.setCount(communityList.size());
            }
        });
        streetList = streetList.stream().sorted(Comparator.comparing(StreetAllAppletsVO::getCount).reversed())
            .collect(Collectors.toList());
        return R.ok(streetList);
    }
 
    /**
     * 根据名字查询所有社区列表
     * 
     * @param name
     *            社区名字
     * @return 社区列表
     */
    @Override
    public R communitySwitchSearchList(String name,String appId) {
        return R.ok(this.comActDAO.getCommunityListByName(name,appId));
    }
 
    /**
     * 根据经纬度以及距离搜索附近社区列表
     * 
     * @param communityDTO
     *            请求参数
     * @return 社区列表
     */
    @Override
    public R communitySwitchSearchDistanceList(SearchCommunityDTO communityDTO) {
        return R.ok(this.comActDAO.getCommunityListByNearby(communityDTO));
    }
 
    @Override
    public R getCommunityPassword(Long communityId){
        ComActPasswordVo comActPasswordVo=comActDAO.getCommunityPassword(communityId);
        try {
            comActPasswordVo.setPassword(MyAESUtil.Decrypt(comActPasswordVo.getPassword(),"Ryo7M3n8loC5Abcd"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok(comActPasswordVo);
    }
    @Override
    public R selectIds(Long id){
        return R.ok(this.comActDAO.selectIds(id));
    }
 
    @Override
    public R selectBasicData(){
        //社区数
        Integer community = comActDAO.countCommunity();
        //商家数
        Integer merchants = comActDAO.countMerchants();
        //党员数
        Integer pbMember = comActDAO.countPbMember();
        //报道单位
        Integer pbUnit = comActDAO.countPbUnit();
        //实有人口
        Integer population = comActDAO.countPopulation();
        //实有房屋
        Integer populationHouse = comActDAO.countPopulationHouse();
        //社会组织
        Integer socialOrg = comActDAO.countSocialOrg();
        //志愿者
        Integer volunteer = comActDAO.countVolunteer();
 
        ComBasicDataVo comBasicDataVo = new ComBasicDataVo();
        comBasicDataVo.setCommunity(community);
        comBasicDataVo.setMerchants(merchants);
        comBasicDataVo.setPbMember(pbMember);
        comBasicDataVo.setPbUnit(pbUnit);
        comBasicDataVo.setPopulation(population);
        comBasicDataVo.setPopulationHouse(populationHouse);
        comBasicDataVo.setSocialOrg(socialOrg);
        comBasicDataVo.setVolunteer(volunteer);
        return R.ok(comBasicDataVo);
    }
 
    @Override
    public R statisticsPbMemberType(){
        List<ComPbMemberTypeVO> comPbMemberTypeVOS = comPbMemberDAO.statisticsPbMemberType();
        return R.ok(comPbMemberTypeVOS);
    }
 
    public R selectUnitByNatureName(){
        List<ComPbMemberTypeVO> comPbMemberTypeVOS = comPbMemberDAO.selectUnitByNatureName();
        return R.ok(comPbMemberTypeVOS);
    }
}