From dd031a2d62991222ca682bd3c687bf47f46d2d6d Mon Sep 17 00:00:00 2001
From: 张天森 <1292933220@qq.com>
Date: 星期一, 10 十月 2022 17:15:00 +0800
Subject: [PATCH] update
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActServiceImpl.java | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 202 insertions(+), 28 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActServiceImpl.java
index a251b6d..5c4f4f1 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActServiceImpl.java
@@ -1,20 +1,31 @@
package com.panzhihua.service_community.service.impl;
-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.vos.R;
-import com.panzhihua.common.model.vos.community.ComActVO;
-import com.panzhihua.common.model.vos.community.ComMngStructOtherBuildVO;
-import com.panzhihua.service_community.dao.ComActDAO;
-import com.panzhihua.service_community.model.dos.ComActDO;
-import com.panzhihua.service_community.service.ComActService;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.panzhihua.common.model.vos.community.ComActPasswordVo;
+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 javax.annotation.Resource;
-import java.util.List;
+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
@@ -26,19 +37,39 @@
public class ComActServiceImpl implements ComActService {
@Resource
private ComActDAO comActDAO;
+ @Resource
+ private ComStreetDAO comStreetDAO;
+
/**
* 新增社区
*
- * @param comActVO 社区信息
+ * @param comActVO
+ * 社区信息
* @return 新增结果
*/
@Override
public R addCommunity(ComActVO comActVO) {
- ComActDO comActDO=new ComActDO();
- BeanUtils.copyProperties(comActVO,comActDO);
+ 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()));
+ if (integer > 0) {
+ return R.fail("社区已经存在");
+ }
+ BeanUtils.copyProperties(comActVO, comActDO);
+ comActDO.setPlaintextPassword(password);
int insert = comActDAO.insert(comActDO);
- if (insert>0) {
- return R.ok();
+ if (insert > 0) {
+ ComActDO comActDO1 =
+ comActDAO.selectOne(new QueryWrapper<ComActDO>().lambda().eq(ComActDO::getName, comActVO.getName()));
+ BeanUtils.copyProperties(comActDO1, comActVO);
+ return R.ok(comActVO);
}
return R.fail();
}
@@ -46,15 +77,42 @@
/**
* 编辑社区
*
- * @param comActVO 编辑内容
+ * @param comActVO
+ * 编辑内容
* @return 编辑结果
*/
@Override
public R putCommunity(ComActVO comActVO) {
- ComActDO comActDO=new ComActDO();
- BeanUtils.copyProperties(comActVO,comActDO);
+ 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 (update > 0) {
+ if (a == 1) {
+ // 修改登录账户的密码
+ comActDAO.updateAccountPassword(comActVO.getPassword(), account, communityId);
+ }
return R.ok();
}
return R.fail();
@@ -63,19 +121,21 @@
/**
* 查询社区
*
- * @param comActVO 登录人的经纬度、或者指定区域的社区
+ * @param comActVO
+ * 登录人的经纬度、或者指定区域的社区
* @return 社区集合
*/
@Override
public R listCommunity(ComActVO comActVO) {
- List<ComActVO> comActVOS=comActDAO.listCommunity(comActVO);
+ List<ComActVO> comActVOS = comActDAO.listCommunity(comActVO);
return R.ok(comActVOS);
}
/**
* 社区详情
*
- * @param communityId 社区id
+ * @param communityId
+ * 社区id
* @return 社区详情
*/
@Override
@@ -84,16 +144,24 @@
if (ObjectUtils.isEmpty(comActDO)) {
return R.fail();
}
- ComActVO comActVO=new ComActVO();
- BeanUtils.copyProperties(comActDO,comActVO);
+ 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 查询参数
+ * @param pageComActDTO
+ * 查询参数
* @return 分页集合
*/
@Override
@@ -101,10 +169,10 @@
Page page = new Page<>();
Long pageNum = pageComActDTO.getPageNum();
Long pageSize = pageComActDTO.getPageSize();
- if (null==pageNum||0==pageNum) {
+ if (null == pageNum || 0 == pageNum) {
pageNum = 1l;
}
- if (null==pageSize||0==pageSize) {
+ if (null == pageSize || 0 == pageSize) {
pageSize = 10l;
}
page.setSize(pageSize);
@@ -113,7 +181,113 @@
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() {
+ return R.ok(this.comActDAO.getCommunityLists());
+ }
+
+ @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);
+ }
}
--
Gitblit v1.7.1