| | |
| | | package com.highdatas.mdm.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.highdatas.mdm.entity.*; |
| | | import com.highdatas.mdm.mapper.MasterAuthorSubscribeMapper; |
| | |
| | | import com.highdatas.mdm.util.DbUtils; |
| | | import com.highdatas.mdm.util.pool.MqEntity; |
| | | import com.highdatas.mdm.util.pool.MqMessage; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * @since 2020-04-20 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class MasterAuthorSubscribeServiceImpl extends ServiceImpl<MasterAuthorSubscribeMapper, MasterAuthorSubscribe> implements IMasterAuthorSubscribeService { |
| | | @Autowired |
| | | IMasterAuthorService masterAuthorService; |
| | |
| | | IMaintainService maintainService; |
| | | @Autowired |
| | | DispenseService dispenseService; |
| | | |
| | | @Autowired |
| | | IMasterAuthorSubscribeService masterAuthorSubscribeService; |
| | | /** |
| | | * |
| | | * @description: 生成版本的需要检测哪些需要自动注册 |
| | | * @param status 流程状态 |
| | | * @param maintainId 数据版本id |
| | | * @return: |
| | | * |
| | | */ |
| | | @Override |
| | | public void dealFlow(String maintainId, ActivitiStatus status) { |
| | | if (!ActivitiStatus.open.equals(status)) { |
| | | return; |
| | | } |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | |
| | | SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintain.getTableName()); |
| | | |
| | | MaintainField maintainFieldByMaintain = fieldService.getMaintainFieldByMaintain(maintainId); |
| | | Set<String> userIdList = new HashSet<>(); |
| | | |
| | | Set<TUser> allUser = DbUtils.getAllUser(); |
| | | |
| | | for (TUser user : allUser) { |
| | | List<MasterAuthor> userAuthor = masterAuthorService.getUserAuthor(user.getUserId(), null); |
| | | |
| | | List<MasterAuthor> authorMaintainFieldList = userAuthor.stream() |
| | | .filter(masterAuthor -> menuByTableName.getId().equalsIgnoreCase(masterAuthor.getMenuId())) |
| | | .collect(Collectors.toList()); |
| | | int count = authorMaintainFieldList.size(); |
| | | if (count == 0) { |
| | | continue; |
| | | try { |
| | | if (!ActivitiStatus.open.equals(status)) { |
| | | return; |
| | | } |
| | | for (MasterAuthor masterAuthor : authorMaintainFieldList) { |
| | | String maintainFieldId = masterAuthor.getMaintainFieldId(); |
| | | Maintain maintain = maintainService.selectById(maintainId); |
| | | |
| | | if (maintainFieldId.equalsIgnoreCase(Constant.All) || maintainFieldId.equalsIgnoreCase(maintainFieldByMaintain.getId())) { |
| | | userIdList.add(user.getUserId()); |
| | | SysMenu menuByTableName = menuMappingService.getMenuByTableName(maintain.getTableName()); |
| | | |
| | | MaintainField maintainFieldByMaintain = fieldService.getMaintainFieldByMaintain(maintainId); |
| | | Set<String> userIdList = new HashSet<>(); |
| | | |
| | | Set<TUser> allUser = DbUtils.getAllUser(); |
| | | |
| | | for (TUser user : allUser) { |
| | | List<MasterAuthor> userAuthor = masterAuthorService.getUserAuthor(user.getUserId(), null); |
| | | |
| | | List<MasterAuthor> authorMaintainFieldList = userAuthor.stream() |
| | | .filter(masterAuthor -> menuByTableName.getId().equalsIgnoreCase(masterAuthor.getMenuId())) |
| | | .collect(Collectors.toList()); |
| | | int count = authorMaintainFieldList.size(); |
| | | if (count == 0) { |
| | | continue; |
| | | } |
| | | for (MasterAuthor masterAuthor : authorMaintainFieldList) { |
| | | String maintainFieldId = masterAuthor.getMaintainFieldId(); |
| | | |
| | | if (maintainFieldId.equalsIgnoreCase(Constant.All) || maintainFieldId.equalsIgnoreCase(maintainFieldByMaintain.getId())) { |
| | | userIdList.add(user.getUserId()); |
| | | } |
| | | } |
| | | } |
| | | log.info("已订阅用户数" + userIdList.size() + " 主题:" + menuByTableName.getName()); |
| | | for (String userId : userIdList) { |
| | | |
| | | int i = masterAuthorSubscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("user_id", userId).eq("menu_id", menuByTableName.getId())); |
| | | if (i == 0) { |
| | | continue; |
| | | } |
| | | |
| | | log.info("已订阅用户" + userId + " 主题:" + menuByTableName.getName()); |
| | | |
| | | MqEntity mqEntity = new MqEntity(); |
| | | mqEntity.setUserId(userId); |
| | | mqEntity.setIncrement(true); |
| | | mqEntity.setMsgTopicName(Constant.Master); |
| | | mqEntity.setType(Constant.Master); |
| | | mqEntity.setDataId(menuByTableName.getId()); |
| | | mqEntity.setMaintainId(maintainId); |
| | | mqEntity.setMsgTagName(menuByTableName.getId()); |
| | | MqEntity.MsgBodyBean msgBody = mqEntity.getMsgBody(); |
| | | msgBody.setVersion(maintainId); |
| | | mqEntity.setMsgKey(DbUtils.getUUID(16)); |
| | | MqMessage mqMessage = new MqMessage(mqEntity); |
| | | dispenseService.pushActiveMq(mqMessage); |
| | | } |
| | | } |
| | | catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | for (String userId : userIdList) { |
| | | MqEntity mqEntity = new MqEntity(); |
| | | mqEntity.setUserId(userId); |
| | | mqEntity.setIncrement(true); |
| | | mqEntity.setMsgTopicName(Constant.Master); |
| | | mqEntity.setType(Constant.Master); |
| | | mqEntity.setDataId(menuByTableName.getId()); |
| | | mqEntity.setMaintainId(maintainId); |
| | | mqEntity.setMsgTagName(menuByTableName.getId()); |
| | | MqEntity.MsgBodyBean msgBody = mqEntity.getMsgBody(); |
| | | msgBody.setVersion(maintainId); |
| | | mqEntity.setMsgKey(DbUtils.getUUID(16)); |
| | | MqMessage mqMessage = new MqMessage(mqEntity); |
| | | dispenseService.pushActiveMq(mqMessage); |
| | | } |
| | | } |
| | | } |