From 27223edb936dc87349738fb3ccd5bffd519bf487 Mon Sep 17 00:00:00 2001 From: zhangyuan Date: Tue, 26 May 2020 10:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=84=E7=BB=87=E6=9C=BA?= =?UTF-8?q?=E6=9E=84=E6=97=B6=EF=BC=8C=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E6=89=80=E5=B1=9E=E6=9C=BA=E6=9E=84=EF=BC=8C=E7=BE=A4?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epdc/modules/police/dao/PoliceDao.java | 32 +++++ .../modules/police/service/PoliceService.java | 11 ++ .../service/impl/PoliceServiceImpl.java | 115 +++++++++++++++++- .../project/dao/PropertyProjectDao.java | 40 +++++- .../service/PropertyProjectService.java | 11 ++ .../impl/PropertyProjectServiceImpl.java | 110 +++++++++++++++++ .../consumer/OrganizationModifyConsumer.java | 62 ++++++++++ .../resources/mapper/police/PoliceDao.xml | 28 +++++ .../mapper/project/PropertyProjectDao.xml | 28 +++++ 9 files changed, 429 insertions(+), 8 deletions(-) create mode 100644 epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/rocketmq/consumer/OrganizationModifyConsumer.java diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java index 27d3358..3e5f4f0 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/dao/PoliceDao.java @@ -18,6 +18,8 @@ package com.elink.esua.epdc.modules.police.dao; import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.group.GroupDTO; +import com.elink.esua.epdc.dto.police.PoliceDTO; import com.elink.esua.epdc.dto.police.form.PoliceFormDTO; import com.elink.esua.epdc.dto.police.result.PoliceResultDTO; import com.elink.esua.epdc.modules.police.entity.PoliceEntity; @@ -54,4 +56,34 @@ public interface PoliceDao extends BaseDao { * @since 2020/5/21 14:54 */ PoliceResultDTO selectPoliceGroupInfo(PoliceFormDTO dto); + + /** + * 查询需要修改组织机构信息事件 + * + * @return java.util.List + * @params [deptId] + * @author liuchuang + * @since 2020/3/7 2:08 + */ + List selectListOfOrganizationInfo(String deptId); + + /** + * 更新网格名称 + * + * @return void + * @params [newDeptName, deptId] + * @author liuchuang + * @since 2020/3/7 1:20 + */ + void updateGridByDeptId(String newDeptName, Long deptId); + + /** + * 查询需要修改名称的党员群 + * + * @return java.util.List + * @params [deptId] + * @author liuchuang + * @since 2020/3/7 2:08 + */ + List selectListOfPartyGroups(String deptId); } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/PoliceService.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/PoliceService.java index a444111..0bd9e41 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/PoliceService.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/PoliceService.java @@ -24,6 +24,7 @@ import com.elink.esua.epdc.dto.police.PoliceDTO; import com.elink.esua.epdc.dto.police.form.PoliceFormDTO; import com.elink.esua.epdc.dto.police.result.PoliceResultDTO; import com.elink.esua.epdc.modules.police.entity.PoliceEntity; +import com.elink.esua.epdc.modules.rocketmq.dto.OrganizationModifyDTO; import java.util.List; import java.util.Map; @@ -115,4 +116,14 @@ public interface PoliceService extends BaseService { * @date 2020-05-21 */ PoliceResultDTO getPoliceAndGroup(PoliceFormDTO dto); + + /** + * 民警信息修改组织机构信息 + * + * @return void + * @params [dto] + * @author liuchuang + * @since 2020/3/7 1:23 + */ + void modifyOrganizationInfo(OrganizationModifyDTO dto); } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java index 14c98e9..ed71c8b 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/police/service/impl/PoliceServiceImpl.java @@ -33,26 +33,29 @@ import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO; import com.elink.esua.epdc.dto.ParentAndAllDeptDTO; import com.elink.esua.epdc.dto.constant.GroupConstant; import com.elink.esua.epdc.dto.enums.GroupStateEnum; +import com.elink.esua.epdc.dto.events.form.GroupFormDTO; +import com.elink.esua.epdc.dto.group.GroupDTO; import com.elink.esua.epdc.dto.police.PoliceDTO; import com.elink.esua.epdc.dto.police.form.PoliceFormDTO; import com.elink.esua.epdc.dto.police.result.PoliceResultDTO; import com.elink.esua.epdc.modules.feign.AdminFeignClient; +import com.elink.esua.epdc.modules.feign.EventFeignClient; import com.elink.esua.epdc.modules.group.dao.GroupDao; import com.elink.esua.epdc.modules.group.entity.GroupEntity; +import com.elink.esua.epdc.modules.group.service.GroupService; import com.elink.esua.epdc.modules.police.dao.PoliceDao; import com.elink.esua.epdc.modules.police.entity.PoliceEntity; import com.elink.esua.epdc.modules.police.redis.PoliceRedis; import com.elink.esua.epdc.modules.police.service.PoliceService; +import com.elink.esua.epdc.modules.rocketmq.dto.OrganizationModifyDTO; +import com.elink.esua.epdc.modules.topic.service.TopicService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import static java.util.stream.Collectors.toList; @@ -71,6 +74,15 @@ public class PoliceServiceImpl extends BaseServiceImpl @Autowired private PoliceRedis policeRedis; + @Autowired + private TopicService topicService; + + @Autowired + private EventFeignClient eventFeignClient; + + @Autowired + private GroupService groupService; + @Resource private GroupDao groupDao; @@ -276,4 +288,99 @@ public class PoliceServiceImpl extends BaseServiceImpl } return parentAndAllDeptDTO; } + + @Override + @Transactional(rollbackFor = Exception.class) + public void modifyOrganizationInfo(OrganizationModifyDTO dto) { + // 查询需要修改组织机构信息邻里党群 + List groupList = baseDao.selectListOfOrganizationInfo(dto.getDeptId().toString()); + if (null != groupList && groupList.size() > 0) { + // 组织机构信息处理 + List entities = handleOrganizationInfo(dto, groupList); + // 更新民警组织机构信息 + updateBatchById(entities); + } + ParentAndAllDeptDTO parentAndAllDeptDTO = getParentAndAllDeptDTO(String.valueOf(dto.getDeptId())); + // 更新网格名称 + baseDao.updateGridByDeptId(parentAndAllDeptDTO.getGrid(), dto.getDeptId()); + // 修改网格党员群名称 + if (OrganizationTypeConstant.ORG_TYPE_COMMUNITY_PARTY.equals(dto.getTypeKey()) + || OrganizationTypeConstant.ORG_TYPE_GRID_PARTY.equals(dto.getTypeKey())) { + // 查询需要修改名称的党员群 + List partyGroups = baseDao.selectListOfPartyGroups(dto.getDeptId().toString()); + if (null != partyGroups && partyGroups.size() > 0) { + List partyEntities = createPartyGroupName(partyGroups); + // 更新党员群名称 + groupService.updateBatchById(partyEntities); + // 更新话题表党员群名称 + topicService.modifyPartyGroupNameByGroupId(ConvertUtils.sourceToTarget(partyEntities, GroupDTO.class)); + // 更新事件表、议题表、项目表党员群名称 + eventFeignClient.modifyPartyGroupName(ConvertUtils.sourceToTarget(partyEntities, GroupFormDTO.class)); + } + } + } + + /** + * 组织机构信息处理 + * + * @return java.util.List + * @params [dto, topicList] + * @author liuchuang + * @since 2020/3/7 2:14 + */ + private List handleOrganizationInfo(OrganizationModifyDTO dto, List topicList) { + List entities = new ArrayList<>(); + for (PoliceDTO topic : topicList) { + PoliceEntity entity = new PoliceEntity(); + if (StringUtils.isNotEmpty(topic.getParentDeptIds()) && StringUtils.isNotEmpty(topic.getParentDeptNames())) { + List parentDeptIds = Arrays.asList(topic.getParentDeptIds().split(",")); + List parentDeptNames = Arrays.asList(topic.getParentDeptNames().split("-")); + int index = parentDeptIds.indexOf(dto.getDeptId().toString()); + if (index >= 0 && parentDeptNames.size() > index) { + parentDeptNames.set(index, dto.getNewDeptName()); + entity.setId(topic.getId()); + entity.setParentDeptNames(StringUtils.join(parentDeptNames, "-")); + } + } + + if (StringUtils.isNotEmpty(topic.getAllDeptIds()) && StringUtils.isNotEmpty(topic.getAllDeptNames())) { + List allDeptIds = Arrays.asList(topic.getAllDeptIds().split(",")); + List allDeptNames = Arrays.asList(topic.getAllDeptNames().split("-")); + int index = allDeptIds.indexOf(dto.getDeptId().toString()); + if (index >= 0 && allDeptNames.size() > index) { + allDeptNames.set(index, dto.getNewDeptName()); + entity.setId(topic.getId()); + entity.setAllDeptNames(StringUtils.join(allDeptNames, "-")); + } + } + + entities.add(entity); + } + + return entities; + } + + /** + * 生成新的群名称 + * + * @return java.util.List + * @params [partyGroups] + * @author liuchuang + * @since 2020/3/7 12:08 + */ + private List createPartyGroupName(List partyGroups) { + List groupEntities = new ArrayList<>(); + for (GroupDTO group : partyGroups) { + String[] allDeptNames = group.getAllDeptNames().split("-"); + int len = allDeptNames.length; + if (len == 4) { + GroupEntity entity = new GroupEntity(); + entity.setId(group.getId()); + entity.setGroupName(allDeptNames[len - 1] + "警民群"); + groupEntities.add(entity); + } + } + + return groupEntities; + } } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/dao/PropertyProjectDao.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/dao/PropertyProjectDao.java index 9a87c4e..a447954 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/dao/PropertyProjectDao.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/dao/PropertyProjectDao.java @@ -18,6 +18,8 @@ package com.elink.esua.epdc.modules.project.dao; import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.group.GroupDTO; +import com.elink.esua.epdc.dto.project.PropertyProjectDTO; import com.elink.esua.epdc.dto.project.form.ProjectDetailFormDTO; import com.elink.esua.epdc.dto.project.form.ProjectListFormDTO; import com.elink.esua.epdc.dto.project.result.ProjectDetailResultDTO; @@ -39,7 +41,7 @@ public interface PropertyProjectDao extends BaseDao { /** * 项目列表 * - * @return java.util.List + * @return java.util.List * @params [params] * @author zhangyuan * @since 2019/10/11 14:54 @@ -49,7 +51,7 @@ public interface PropertyProjectDao extends BaseDao { /** * 项目列表 * - * @return java.util.List + * @return java.util.List * @params [params] * @author zhangyuan * @since 2019/10/11 14:54 @@ -59,7 +61,7 @@ public interface PropertyProjectDao extends BaseDao { /** * 项目详情 * - * @return java.util.List + * @return java.util.List * @params [params] * @author zhangyuan * @since 2019/10/11 14:54 @@ -69,10 +71,40 @@ public interface PropertyProjectDao extends BaseDao { /** * 项目详情V2 * - * @return java.util.List + * @return java.util.List * @params [params] * @author zhangyuan * @since 2019/10/11 14:54 */ ProjectDetailResultDTO selectDetailByIdV2(ProjectDetailFormDTO dto); + + /** + * 查询需要修改组织机构信息事件 + * + * @return java.util.List + * @params [deptId] + * @author liuchuang + * @since 2020/3/7 2:08 + */ + List selectListOfOrganizationInfo(String deptId); + + /** + * 更新网格名称 + * + * @return void + * @params [newDeptName, deptId] + * @author liuchuang + * @since 2020/3/7 1:20 + */ + void updateGridByDeptId(String newDeptName, Long deptId); + + /** + * 查询需要修改名称的党员群 + * + * @return java.util.List + * @params [deptId] + * @author liuchuang + * @since 2020/3/7 2:08 + */ + List selectListOfPartyGroups(String deptId); } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/service/PropertyProjectService.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/service/PropertyProjectService.java index 033a385..1c53e83 100644 --- a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/service/PropertyProjectService.java +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/project/service/PropertyProjectService.java @@ -25,6 +25,7 @@ import com.elink.esua.epdc.dto.project.form.ProjectListFormDTO; import com.elink.esua.epdc.dto.project.result.ProjectDetailResultDTO; import com.elink.esua.epdc.dto.project.result.ProjectListResultDTO; import com.elink.esua.epdc.modules.project.entity.PropertyProjectEntity; +import com.elink.esua.epdc.modules.rocketmq.dto.OrganizationModifyDTO; import java.util.List; import java.util.Map; @@ -126,4 +127,14 @@ public interface PropertyProjectService extends BaseService groupList = baseDao.selectListOfOrganizationInfo(dto.getDeptId().toString()); + if (null != groupList && groupList.size() > 0) { + // 组织机构信息处理 + List entities = handleOrganizationInfo(dto, groupList); + // 更新邻里党群组织机构信息 + updateBatchById(entities); + } + // 更新网格名称 + baseDao.updateGridByDeptId(dto.getNewDeptName(), dto.getDeptId()); + // 修改网格党员群名称 + if (OrganizationTypeConstant.ORG_TYPE_COMMUNITY_PARTY.equals(dto.getTypeKey()) + || OrganizationTypeConstant.ORG_TYPE_GRID_PARTY.equals(dto.getTypeKey())) { + // 查询需要修改名称的党员群 + List partyGroups = baseDao.selectListOfPartyGroups(dto.getDeptId().toString()); + if (null != partyGroups && partyGroups.size() > 0) { + List partyEntities = createPartyGroupName(partyGroups); + // 更新党员群名称 + groupService.updateBatchById(partyEntities); + // 更新话题表党员群名称 + topicService.modifyPartyGroupNameByGroupId(ConvertUtils.sourceToTarget(partyEntities, GroupDTO.class)); + // 更新事件表、议题表、项目表党员群名称 + eventFeignClient.modifyPartyGroupName(ConvertUtils.sourceToTarget(partyEntities, GroupFormDTO.class)); + } + } + } + + /** + * 组织机构信息处理 + * + * @return java.util.List + * @params [dto, topicList] + * @author liuchuang + * @since 2020/3/7 2:14 + */ + private List handleOrganizationInfo(OrganizationModifyDTO dto, List topicList) { + List entities = new ArrayList<>(); + for (PropertyProjectDTO topic : topicList) { + PropertyProjectEntity entity = new PropertyProjectEntity(); + if (StringUtils.isNotEmpty(topic.getParentDeptIds()) && StringUtils.isNotEmpty(topic.getParentDeptNames())) { + List parentDeptIds = Arrays.asList(topic.getParentDeptIds().split(",")); + List parentDeptNames = Arrays.asList(topic.getParentDeptNames().split("-")); + int index = parentDeptIds.indexOf(dto.getDeptId().toString()); + if (index >= 0 && parentDeptNames.size() > index) { + parentDeptNames.set(index, dto.getNewDeptName()); + entity.setId(topic.getId()); + entity.setParentDeptNames(StringUtils.join(parentDeptNames, "-")); + } + } + + if (StringUtils.isNotEmpty(topic.getAllDeptIds()) && StringUtils.isNotEmpty(topic.getAllDeptNames())) { + List allDeptIds = Arrays.asList(topic.getAllDeptIds().split(",")); + List allDeptNames = Arrays.asList(topic.getAllDeptNames().split("-")); + int index = allDeptIds.indexOf(dto.getDeptId().toString()); + if (index >= 0 && allDeptNames.size() > index) { + allDeptNames.set(index, dto.getNewDeptName()); + entity.setId(topic.getId()); + entity.setAllDeptNames(StringUtils.join(allDeptNames, "-")); + } + } + + entities.add(entity); + } + + return entities; + } + + /** + * 生成新的群名称 + * + * @return java.util.List + * @params [partyGroups] + * @author liuchuang + * @since 2020/3/7 12:08 + */ + private List createPartyGroupName(List partyGroups) { + List groupEntities = new ArrayList<>(); + for (GroupDTO group : partyGroups) { + String[] allDeptNames = group.getAllDeptNames().split("-"); + int len = allDeptNames.length; + if (len == 4) { + GroupEntity entity = new GroupEntity(); + entity.setId(group.getId()); + entity.setGroupName(allDeptNames[len - 1] + "群"); + groupEntities.add(entity); + } + } + + return groupEntities; + } } \ No newline at end of file diff --git a/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/rocketmq/consumer/OrganizationModifyConsumer.java b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/rocketmq/consumer/OrganizationModifyConsumer.java new file mode 100644 index 0000000..dd99d15 --- /dev/null +++ b/epdc-cloud-property/src/main/java/com/elink/esua/epdc/modules/rocketmq/consumer/OrganizationModifyConsumer.java @@ -0,0 +1,62 @@ +package com.elink.esua.epdc.modules.rocketmq.consumer; + +import com.alibaba.fastjson.JSONObject; +import com.elink.esua.epdc.commons.tools.constant.RocketMqConstant; +import com.elink.esua.epdc.modules.group.service.GroupService; +import com.elink.esua.epdc.modules.police.service.PoliceService; +import com.elink.esua.epdc.modules.project.service.PropertyProjectService; +import com.elink.esua.epdc.modules.rocketmq.dto.OrganizationModifyDTO; +import com.elink.esua.epdc.modules.topic.service.TopicService; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.spring.annotation.MessageModel; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.apache.rocketmq.spring.core.RocketMQListener; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 组织机构信息修改-监听MQ消息 + * + * @Author:liuchuang + * @Date:2020/3/7 1:54 + */ +@Slf4j +@Component +@RocketMQMessageListener(topic = RocketMqConstant.MQ_TOPIC_ORGANIZATION, consumerGroup = "${rocketmq.consumer.group}", messageModel = MessageModel.BROADCASTING) +public class OrganizationModifyConsumer implements RocketMQListener { + + @Autowired + private GroupService groupService; + + @Autowired + private TopicService topicService; + + @Autowired + private PropertyProjectService propertyProjectService; + + @Autowired + private PoliceService policeService; + + @Override + public void onMessage(MessageExt messageExt) { + log.info("EPDC-GROUP-SERVER消费消息START:{topic:{}, msgId:{}}", RocketMqConstant.MQ_TOPIC_ORGANIZATION, messageExt.getMsgId()); + try { + String charset = "UTF-8"; + String body = new String(messageExt.getBody(), charset); + OrganizationModifyDTO dto = JSONObject.parseObject(body, OrganizationModifyDTO.class); + // 话题修改组织机构信息 + topicService.modifyOrganizationInfo(dto); + // 邻里党群修改组织机构信息 + groupService.modifyOrganizationInfo(dto); + // 物业项目修改组织机构信息 + propertyProjectService.modifyOrganizationInfo(dto); + // 民警修改组织机构信息 + policeService.modifyOrganizationInfo(dto); + log.info("EPDC-GROUP-SERVER消费消息END:{topic:{}, msgId:{}, body:{}}", RocketMqConstant.MQ_TOPIC_ORGANIZATION, messageExt.getMsgId(), body); + } catch (Exception e) { + log.info("EPDC-GROUP-SERVER消费消息失败:msgId:{}", messageExt.getMsgId()); + e.printStackTrace(); + } + } +} diff --git a/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml b/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml index c5396ee..9edecf7 100644 --- a/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml +++ b/epdc-cloud-property/src/main/resources/mapper/police/PoliceDao.xml @@ -102,4 +102,32 @@ GROUP BY ep.ID + + + + + UPDATE epdc_police SET DEPT_NAME = #{newDeptName} WHERE DEPT_ID = #{deptId} + + + \ No newline at end of file diff --git a/epdc-cloud-property/src/main/resources/mapper/project/PropertyProjectDao.xml b/epdc-cloud-property/src/main/resources/mapper/project/PropertyProjectDao.xml index c81a83d..40ce56d 100644 --- a/epdc-cloud-property/src/main/resources/mapper/project/PropertyProjectDao.xml +++ b/epdc-cloud-property/src/main/resources/mapper/project/PropertyProjectDao.xml @@ -199,4 +199,32 @@ GROUP BY ep.ID + + + + + UPDATE epdc_property_project SET GRID = #{newDeptName} WHERE GRID_ID = #{deptId} + + + \ No newline at end of file