From bfe7b653a9d376b31699ef5eef34a8817546f84c Mon Sep 17 00:00:00 2001
From: 101captain <237651143@qq.com>
Date: 星期五, 27 五月 2022 17:20:47 +0800
Subject: [PATCH] bug修改
---
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComStreetServiceImpl.java | 121 +++++++++++++++++++++++++++-------------
1 files changed, 82 insertions(+), 39 deletions(-)
diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComStreetServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComStreetServiceImpl.java
index 6eac509..370380c 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComStreetServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComStreetServiceImpl.java
@@ -1,5 +1,17 @@
package com.panzhihua.service_community.service.impl;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import com.panzhihua.common.model.vos.user.AdministratorsUserVO;
+import com.panzhihua.common.service.user.UserService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -12,15 +24,9 @@
import com.panzhihua.common.model.vos.community.ComStreetVO;
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.ComStreetService;
-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;
/**
* @author: llming
@@ -34,17 +40,19 @@
@Resource
private ComStreetDAO comStreetDAO;
+ @Resource
+ private UserService userService;
+
/**
* 新增社区
*
- * @param comStreetVO 街道信息
+ * @param comStreetVO
+ * 街道信息
* @return 新增结果
*/
@Override
- public R addStreet(ComStreetVO comStreetVO) {
- String password = comStreetVO.getPassword();
- String encode = new BCryptPasswordEncoder().encode(password);
- comStreetVO.setPassword(encode);
+ @Transactional
+ public R<ComStreetVO> addStreet(ComStreetVO comStreetVO) {
ComStreetDO comStreetDO = new ComStreetDO();
LambdaQueryWrapper<ComStreetDO> param = new QueryWrapper<ComStreetDO>().lambda();
param.eq(ComStreetDO::getName, comStreetVO.getName());
@@ -53,41 +61,68 @@
param.eq(ComStreetDO::getAreaCode, comStreetVO.getAreaCode());
Integer integer = comStreetDAO.selectCount(param);
if (integer > 0) {
- return R.fail("街道已经存在");
+ return R.fail(500, "街道已经存在");
}
- BeanUtils.copyProperties(comStreetVO, comStreetDO);
- int insert = comStreetDAO.insert(comStreetDO);
- if (insert > 0) {
- ComStreetDO comStreetDO1 = comStreetDAO.selectOne(param);
- BeanUtils.copyProperties(comStreetDO1, comStreetVO);
- return R.ok(comStreetVO);
+ AdministratorsUserVO administratorsUserVO=new AdministratorsUserVO();
+ administratorsUserVO.setType(3);
+ administratorsUserVO.setAccount(comStreetVO.getAccount());
+ administratorsUserVO.setPassword(comStreetVO.getPassword());
+ administratorsUserVO.setSocialType(1);
+ administratorsUserVO.setRoleId(777777777L);
+ administratorsUserVO.setStreetId(0L);
+ administratorsUserVO.setName(comStreetVO.getName());
+ R r=userService.addUserBackstageProperty(administratorsUserVO);
+ if(R.isOk(r)){
+ BeanUtils.copyProperties(comStreetVO, comStreetDO);
+ int insert = comStreetDAO.insert(comStreetDO);
+ if (insert > 0) {
+ AdministratorsUserVO administratorsUserVO1=new AdministratorsUserVO();
+ administratorsUserVO1.setUserId(Long.parseLong(r.getData().toString()));
+ administratorsUserVO1.setStreetId(comStreetDO.getStreetId());
+ userService.updateStreet(administratorsUserVO1);
+ ComStreetDO comStreetDO1 = comStreetDAO.selectOne(param);
+ BeanUtils.copyProperties(comStreetDO1, comStreetVO);
+ return R.ok(comStreetVO);
+ }
+ return R.fail(500, "");
}
- return R.fail();
+ return R.fail("账号已存在");
}
-
/**
* 查询街道
*
- * @param comStreetVO 街道名
+ * @param comStreetVO
+ * 街道名
* @return 社区集合
*/
@Override
public R listStreet(ComStreetVO comStreetVO) {
- List<ComStreetVO> vos = Lists.newArrayList();
LambdaQueryWrapper<ComStreetDO> param = new QueryWrapper<ComStreetDO>().lambda();
- param.eq(ComStreetDO::getProvinceCode, comStreetVO.getProvinceCode());
- param.eq(ComStreetDO::getCityCode, comStreetVO.getCityCode());
- param.eq(ComStreetDO::getAreaCode, comStreetVO.getCityCode());
- List<ComStreetDO> ComStreetDOS = comStreetDAO.selectList(param);
- BeanUtils.copyProperties(vos, ComStreetDOS);
- return R.ok(vos);
+ if (comStreetVO.getProvinceCode() != null) {
+ param.eq(ComStreetDO::getProvinceCode, comStreetVO.getProvinceCode());
+ }
+ if (comStreetVO.getCityCode() != null) {
+ param.eq(ComStreetDO::getCityCode, comStreetVO.getCityCode());
+ }
+ if (comStreetVO.getAreaCode() != null) {
+ param.eq(ComStreetDO::getAreaCode, comStreetVO.getAreaCode());
+ }
+ List<ComStreetVO> voList = Lists.newArrayList();
+ List<ComStreetDO> comStreetDOS = comStreetDAO.selectList(param);
+ comStreetDOS.forEach(dos -> {
+ ComStreetVO vo = new ComStreetVO();
+ BeanUtils.copyProperties(dos, vo);
+ voList.add(vo);
+ });
+ return R.ok(voList);
}
/**
* 社区详情
*
- * @param streetId 街道id
+ * @param streetId
+ * 街道id
* @return 社区详情
*/
@Override
@@ -105,7 +140,8 @@
/**
* 分页查询社区
*
- * @param pageComStreetDTO 查询参数
+ * @param pageComStreetDTO
+ * 查询参数
* @return 分页集合
*/
@Override
@@ -114,37 +150,44 @@
Long pageNum = pageComStreetDTO.getPageNum();
Long pageSize = pageComStreetDTO.getPageSize();
if (null == pageNum || 0 == pageNum) {
- pageNum = 1l;
+ pageNum = 1L;
}
if (null == pageSize || 0 == pageSize) {
- pageSize = 10l;
+ pageSize = 10L;
}
page.setSize(pageSize);
page.setCurrent(pageNum);
LambdaQueryWrapper<ComStreetDO> userLambdaQueryWrapper = Wrappers.lambdaQuery();
- if (!pageComStreetDTO.getName().isEmpty()) {
+ if (pageComStreetDTO.getName() != null) {
userLambdaQueryWrapper.like(ComStreetDO::getName, pageComStreetDTO.getName());
}
Page userPage = new Page(pageNum, pageSize);
- IPage<ComStreetDO> doPager = comStreetDAO.selectPage(userPage, userLambdaQueryWrapper);
+ IPage<ComStreetDO> doPager =
+ comStreetDAO.selectPage(userPage, userLambdaQueryWrapper.orderByDesc(ComStreetDO::getCreateAt));
return R.ok(doPager);
}
-
/**
- * 批量删除社区
+ * 批量删除街道
*
- * @param streetIds 社区id
+ * @param streetIds
+ * 社区id
* @return 删除结果
*/
@Override
public R delectStreat(List<Long> streetIds) {
+ // 不能删除,已经绑定了社区的街道
+ LambdaQueryWrapper<ComActDO> comActDOParam =
+ new QueryWrapper<ComActDO>().lambda().in(ComActDO::getStreetId, streetIds);
+ List<ComActDO> comActDOS = comActDAO.selectList(comActDOParam);
+ if (comActDOS != null && comActDOS.size() > 0) {
+ return R.fail("删除失败,批量删除街道中,街道下有社区无法删除!");
+ }
int delete = comStreetDAO.deleteBatchIds(streetIds);
if (delete > 0) {
return R.ok();
}
return R.fail();
}
-
}
--
Gitblit v1.7.1