diff --git a/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/form/LogOperationListFormDTO.java b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/form/LogOperationListFormDTO.java new file mode 100644 index 0000000000..3fe203b482 --- /dev/null +++ b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/form/LogOperationListFormDTO.java @@ -0,0 +1,13 @@ +package com.epmet.dto.form; + +import lombok.Data; + +@Data +public class LogOperationListFormDTO { + + private String condition; + + private Integer pageNo = 1; + + private Integer pageSize = 10; +} diff --git a/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/region/LogOperationResultDTO.java b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/region/LogOperationResultDTO.java new file mode 100644 index 0000000000..a9cca21013 --- /dev/null +++ b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/dto/region/LogOperationResultDTO.java @@ -0,0 +1,53 @@ +package com.epmet.dto.region; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +import java.util.Date; + +/** + * + */ +@Data +public class LogOperationResultDTO { + + /** + * 大类别。登录login,项目流转project + */ + private String category; + /** + * 类型枚举,小类别。登录login,logout退出,shift_project议题转项目等 + */ + private String type; + + /** + * 类型枚举名称 + */ + private String typeDisplay; + + /** + * 内容 + */ + private String content; + + /** + * 操作目标ID + */ + private String targetId; + + /** + * 操作人ID + */ + private String customerId; + private String operatorId; + private String operatorName; + private String operatorMobile; + + /** + * 操作时间,该时间不是插入数据的时间,而是操作发生的真实时间 + */ + private Long operatingTime; + +} diff --git a/epmet-admin/epmet-admin-client/src/main/java/com/epmet/enums/LogOperationTypeEnum.java b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/enums/LogOperationTypeEnum.java new file mode 100644 index 0000000000..892d41ed34 --- /dev/null +++ b/epmet-admin/epmet-admin-client/src/main/java/com/epmet/enums/LogOperationTypeEnum.java @@ -0,0 +1,44 @@ +//package com.epmet.enums; +// +//import lombok.Data; +// +///** +// * 操作日志类型枚举 +// */ +//public enum LogOperationTypeEnum { +// LOGIN("login", "登录"), +// LOGOUT("logout", "退出登录"); +// +// private String type; +// private String typeDisplay; +// +// public String getType() { +// return type; +// } +// +// public String getTypeDisplay() { +// return typeDisplay; +// } +// +// LogOperationTypeEnum(String type, String typeDisplay) { +// this.type = type; +// this.typeDisplay = typeDisplay; +// } +// +// public static LogOperationTypeEnum get(String type) { +// for (LogOperationTypeEnum t : LogOperationTypeEnum.values()) { +// if (t.type.equals(type)) { +// return t; +// } +// } +// return null; +// } +// +// public static String getDisplay(String type) { +// LogOperationTypeEnum object = get(type); +// if (object == null) { +// return null; +// } +// return object.typeDisplay; +// } +//} diff --git a/epmet-admin/epmet-admin-server/pom.xml b/epmet-admin/epmet-admin-server/pom.xml index 8efabd48a9..b628e79745 100644 --- a/epmet-admin/epmet-admin-server/pom.xml +++ b/epmet-admin/epmet-admin-server/pom.xml @@ -54,6 +54,31 @@ feign-httpclient 10.3.0 + + + + com.epmet + epmet-commons-rocketmq + 2.0.0 + + + + + com.epmet + epmet-user-client + 2.0.0 + compile + + + com.epmet + epmet-message-client + 2.0.0 + + + com.epmet + epmet-auth-client + 2.0.0 + @@ -109,6 +134,10 @@ false + + + 192.168.1.140:9876;192.168.1.141:9876 + epmet_message @@ -141,6 +170,10 @@ false + + + 192.168.1.140:9876;192.168.1.141:9876 + epmet_message @@ -170,6 +203,10 @@ true + + + 192.168.10.161:9876 + epmet_message @@ -199,6 +236,10 @@ true + + + 192.168.11.187:9876;192.168.11.184:9876 + epmet_message diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/AdminApplication.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/AdminApplication.java index 89ac2c70d8..ea0ca31624 100644 --- a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/AdminApplication.java +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/AdminApplication.java @@ -10,6 +10,8 @@ package com.epmet; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; /** * 管理后台 @@ -18,6 +20,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; * @since 1.0.0 */ @SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients public class AdminApplication { public static void main(String[] args) { diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/controller/LogOperationController.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/controller/LogOperationController.java new file mode 100644 index 0000000000..13ed1b9bd1 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/controller/LogOperationController.java @@ -0,0 +1,46 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.security.user.LoginUserUtil; +import com.epmet.commons.tools.utils.IpUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.LogOperationListFormDTO; +import com.epmet.dto.region.LogOperationResultDTO; +import com.epmet.service.LogOperationService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + +@RequestMapping("log/operation") +@RestController +public class LogOperationController { + + @Autowired + private LogOperationService logOperationService; + + @Autowired + private LoginUserUtil loginUserUtil; + + @PostMapping("/list") + public Result> listLogOperations(@RequestBody LogOperationListFormDTO input, HttpServletRequest request) { + ValidatorUtils.validateEntity(input); + String condition = input.getCondition(); + Integer pageNo = input.getPageNo(); + Integer pageSize = input.getPageSize(); + + String customerId = loginUserUtil.getLoginUserCustomerId(); + List resultList = logOperationService.listOperationLogs(condition, customerId, pageNo, pageSize); + if (CollectionUtils.isEmpty(resultList)) { + resultList = new ArrayList<>(); + } + return new Result>().ok(resultList); + } + +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/dao/LogOperationDao.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/dao/LogOperationDao.java new file mode 100644 index 0000000000..a63a5aa8e4 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/dao/LogOperationDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.LogOperationEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 操作日指标 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-06-07 + */ +@Mapper +public interface LogOperationDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/entity/LogOperationEntity.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/entity/LogOperationEntity.java new file mode 100644 index 0000000000..d3f3f20402 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/entity/LogOperationEntity.java @@ -0,0 +1,89 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 操作日指标 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-06-07 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("log_operation") +public class LogOperationEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 大类别。登录login,项目流转project + */ + private String category; + /** + * 类型枚举,小类别。登录login,logout退出,shift_project议题转项目等 + */ + private String type; + + private String typeDisplay; + + private String ip; + + private String fromApp; + + private String fromClient; + + /** + * 内容 + */ + private String content; + + /** + * 操作目标ID + */ + private String targetId; + + private String customerId; + + /** + * 操作人ID + */ + private String operatorId; + /** + * 操作人姓名 + */ + private String operatorName; + + /** + * 操作人手机号 + */ + private String operatorMobile; + + /** + * 操作时间,该时间不是插入数据的时间,而是操作发生的真实时间 + */ + private Date operatingTime; + +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/RocketMQConsumerRegister.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/RocketMQConsumerRegister.java new file mode 100644 index 0000000000..ef71399b7d --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/RocketMQConsumerRegister.java @@ -0,0 +1,68 @@ +package com.epmet.mq.listener; + +import com.epmet.commons.rocketmq.constants.ConsomerGroupConstants; +import com.epmet.commons.rocketmq.constants.TopicConstants; +import com.epmet.commons.tools.enums.EnvEnum; +import com.epmet.mq.listener.listener.AuthOperationLogListener; +import com.epmet.mq.listener.listener.ProjectOperationLogListener; +import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.client.exception.MQClientException; +import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; + +@Component +public class RocketMQConsumerRegister { + @Value("${spring.profiles.active}") + private String env; + @Value("${rocketmq.name-server}") + private String nameServer; + + /** + * @return + * @Description 注册监听器 + * @author wxz + * @date 2021.03.03 16:09 + */ + @PostConstruct + public void registerAllListeners() { + try { + if (!EnvEnum.LOCAL.getCode().equals(env)) { + register(nameServer, ConsomerGroupConstants.AUTH_OPERATION_LOG_GROUP, MessageModel.CLUSTERING, TopicConstants.AUTH, "*", new AuthOperationLogListener()); + register(nameServer, ConsomerGroupConstants.PROJECT_OPERATION_LOG_GROUP, MessageModel.CLUSTERING, TopicConstants.PROJECT_CHANGED, "*", new ProjectOperationLogListener()); + } + } catch (MQClientException e) { + e.printStackTrace(); + } + } + + public void register(String nameServer, String group, MessageModel messageModel, String topic, String subException, MessageListenerConcurrently listener) throws MQClientException { + // 实例化消费者 + DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(group); + + // 设置NameServer的地址 + consumer.setNamesrvAddr(nameServer); + consumer.setMessageModel(messageModel); + consumer.setInstanceName(buildInstanceName()); + // 订阅一个或者多个Topic,以及Tag来过滤需要消费的消息 + consumer.subscribe(topic, subException); + // 注册回调实现类来处理从broker拉取回来的消息 + consumer.registerMessageListener(listener); + // 启动消费者实例 + consumer.start(); + } + + private String buildInstanceName() { + String instanceName = ""; + for (int i = 0; i < 4; i++) { + int t = (int) (Math.random() * 10); + instanceName = instanceName.concat(t + ""); + } + + return instanceName; + } + +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/LogOperationHelper.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/LogOperationHelper.java new file mode 100644 index 0000000000..b8c82f6640 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/LogOperationHelper.java @@ -0,0 +1,63 @@ +package com.epmet.mq.listener.bean.log; + +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.feign.ResultDataResolver; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.feign.EpmetUserOpenFeignClient; + +/** + * 操作日志帮助类 单例 + */ +public class LogOperationHelper implements ResultDataResolver { + + private EpmetUserOpenFeignClient userOpenFeignClient; + + private LogOperationHelper() { + } + + /** + * @Description 利用类只能加载一次的特性,保证类静态变量只能生成一份,实现单例 + * @return + * @author wxz + * @date 2021.06.09 16:55 + */ + private static class SingletonInnerClass { + public static LogOperationHelper instance = new LogOperationHelper(); + } + + /** + * @Description 获取实例 + * @return + * @author wxz + * @date 2021.06.09 16:54 + */ + public static LogOperationHelper getInstance() { + return SingletonInnerClass.instance; + } + + /** + * @Description 获取操作人信息 + * @return + * @author wxz + * @date 2021.06.09 16:57 + */ + public OperatorInfo getOperatorInfo(String userId) { + if (userOpenFeignClient == null) { + synchronized (this) { + if (userOpenFeignClient == null) { + userOpenFeignClient = SpringContextUtils.getBean(EpmetUserOpenFeignClient.class); + } + } + } + + CustomerStaffDTO form = new CustomerStaffDTO(); + form.setUserId(userId); + Result result = userOpenFeignClient.getCustomerStaffInfoByUserId(form); + CustomerStaffDTO staffInfo = getResultDataOrThrowsException(result, ServiceConstant.EPMET_ADMIN_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), + "调用epmet-user服务获取staff信息发生异常"); + return new OperatorInfo(staffInfo.getCustomerId(), staffInfo.getMobile(), staffInfo.getRealName()); + } +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/OperatorInfo.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/OperatorInfo.java new file mode 100644 index 0000000000..6dfd9ba7d9 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/bean/log/OperatorInfo.java @@ -0,0 +1,12 @@ +package com.epmet.mq.listener.bean.log; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class OperatorInfo { + private String customerId; + private String mobile; + private String name; +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/AuthOperationLogListener.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/AuthOperationLogListener.java new file mode 100644 index 0000000000..4f9e361fc5 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/AuthOperationLogListener.java @@ -0,0 +1,95 @@ +package com.epmet.mq.listener.listener; + +import com.alibaba.fastjson.JSON; +import com.epmet.auth.constants.AuthOperationEnum; +import com.epmet.commons.rocketmq.messages.LoginMQMsg; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.feign.ResultDataResolver; +import com.epmet.commons.tools.utils.IpUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.entity.LogOperationEntity; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.mq.listener.bean.log.LogOperationHelper; +import com.epmet.mq.listener.bean.log.OperatorInfo; +import com.epmet.service.LogOperationService; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.message.MessageExt; +import org.redisson.api.RLock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @author wxz + * @Description 登录操作日志监听器 + + * @return + * @date 2021.06.07 16:12 + */ +public class AuthOperationLogListener implements MessageListenerConcurrently { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { + try { + msgs.forEach(msg -> consumeMessage(msg)); + } catch (Exception e) { + logger.error(ExceptionUtils.getErrorStackTrace(e)); + return ConsumeConcurrentlyStatus.RECONSUME_LATER; + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } + + private void consumeMessage(MessageExt messageExt) { + String tags = messageExt.getTags(); + String msg = new String(messageExt.getBody()); + logger.info("认证操作日志监听器-收到消息内容:{}", msg); + LoginMQMsg msgObj = JSON.parseObject(msg, LoginMQMsg.class); + + //获取操作人信息 + OperatorInfo operatorInfo = LogOperationHelper.getInstance().getOperatorInfo(msgObj.getUserId()); + LogOperationEntity logEntity = new LogOperationEntity(); + logEntity.setCategory(messageExt.getTopic()); + logEntity.setType(tags); + logEntity.setTypeDisplay(AuthOperationEnum.getDisplay(tags)); + logEntity.setIp(msgObj.getIp()); + logEntity.setFromApp(msgObj.getFromApp()); + logEntity.setFromClient(msgObj.getFromClient()); + logEntity.setTargetId(""); + logEntity.setCustomerId(operatorInfo.getCustomerId()); + logEntity.setOperatorId(msgObj.getUserId()); + logEntity.setOperatorName(operatorInfo.getName()); + logEntity.setOperatorMobile(operatorInfo.getMobile()); + logEntity.setOperatingTime(msgObj.getLoginTime()); + logEntity.setContent("成功登录系统"); + + DistributedLock distributedLock = null; + RLock lock = null; + try { + distributedLock = SpringContextUtils.getBean(DistributedLock.class); + lock = distributedLock.getLock(String.format("lock:auth_operation_log:%s:%s", logEntity.getType(), logEntity.getOperatorId()), + 30L, 30L, TimeUnit.SECONDS); + SpringContextUtils.getBean(LogOperationService.class).log(logEntity); + } catch (RenException e) { + // 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试 + logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + } catch (Exception e) { + // 不是我们自己抛出的异常,可以让MQ重试 + logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + throw e; + } finally { + distributedLock.unLock(lock); + } + } +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/ProjectOperationLogListener.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/ProjectOperationLogListener.java new file mode 100644 index 0000000000..13384ea62e --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/mq/listener/listener/ProjectOperationLogListener.java @@ -0,0 +1,110 @@ +package com.epmet.mq.listener.listener; + +import com.alibaba.fastjson.JSON; +import com.epmet.commons.rocketmq.messages.LoginMQMsg; +import com.epmet.commons.rocketmq.messages.ProjectChangedMQMsg; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.exception.ExceptionUtils; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.SpringContextUtils; +import com.epmet.entity.LogOperationEntity; +import com.epmet.mq.listener.bean.log.LogOperationHelper; +import com.epmet.mq.listener.bean.log.OperatorInfo; +import com.epmet.service.LogOperationService; +import org.apache.commons.lang3.StringUtils; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; +import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; +import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; +import org.apache.rocketmq.common.message.MessageExt; +import org.redisson.api.RLock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * @author wxz + * @Description 项目操作日志监听器 + + * @return + * @date 2021.06.08 22.21 + */ +public class ProjectOperationLogListener implements MessageListenerConcurrently { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { + try { + msgs.forEach(msg -> consumeMessage(msg)); + } catch (Exception e) { + logger.error(ExceptionUtils.getErrorStackTrace(e)); + return ConsumeConcurrentlyStatus.RECONSUME_LATER; + } + return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + } + + private void consumeMessage(MessageExt messageExt) { + //String tags = messageExt.getTags(); + String msg = new String(messageExt.getBody()); + logger.info("项目变动操作日志监听器-收到消息内容:{}", msg); + ProjectChangedMQMsg msgObj = JSON.parseObject(msg, ProjectChangedMQMsg.class); + + String content = StringUtils.isBlank(msgObj.getOperationBrief()) ? "" : msgObj.getOperationBrief(); + + OperatorInfo operatorInfo = LogOperationHelper.getInstance().getOperatorInfo(msgObj.getOperatorId()); + + LogOperationEntity logEntity = new LogOperationEntity(); + logEntity.setCategory(messageExt.getTopic()); + logEntity.setType(msgObj.getOperation()); + logEntity.setTypeDisplay(getOperationTypeDisplay(msgObj.getOperation())); + logEntity.setTargetId(msgObj.getProjectId()); + logEntity.setIp(msgObj.getIp()); + logEntity.setFromApp(msgObj.getFromApp()); + logEntity.setFromClient(msgObj.getFromClient()); + logEntity.setCustomerId(operatorInfo.getCustomerId()); + logEntity.setOperatorId(msgObj.getOperatorId()); + logEntity.setOperatorMobile(operatorInfo.getMobile()); + logEntity.setOperatorName(operatorInfo.getName()); + logEntity.setOperatingTime(msgObj.getOperatingTime()); + logEntity.setContent(content); + + DistributedLock distributedLock = null; + RLock lock = null; + try { + distributedLock = SpringContextUtils.getBean(DistributedLock.class); + lock = distributedLock.getLock(String.format("lock:project_operation_log:%s:%s", logEntity.getType(), logEntity.getTargetId()), + 30L, 30L, TimeUnit.SECONDS); + SpringContextUtils.getBean(LogOperationService.class).log(logEntity); + } catch (RenException e) { + // 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试 + logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + } catch (Exception e) { + // 不是我们自己抛出的异常,可以让MQ重试 + logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); + throw e; + } finally { + distributedLock.unLock(lock); + } + } + + private String getOperationTypeDisplay(String type) { + switch (type) { + case "response": + return "项目响应处理"; + case "issue_shift_project": + return "议题转项目"; + case "close": + return "项目结案"; + case "return": + return "项目退回"; + case "transfer": + return "项目吹哨"; + case "created": + return "项目立项"; + default: + return null; + } + } +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/LogOperationService.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/LogOperationService.java new file mode 100644 index 0000000000..67b3736395 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/LogOperationService.java @@ -0,0 +1,28 @@ +package com.epmet.service; + +import com.epmet.dto.region.LogOperationResultDTO; +import com.epmet.entity.LogOperationEntity; + +import java.util.List; + +/** + * 操作日志 + */ +public interface LogOperationService { + + /** + * @Description 记录日志 + * @return + * @author wxz + * @date 2021.06.07 21:56 + */ + void log(LogOperationEntity msg); + + /** + * @Description 查询操作日志 列表 + * @return + * @author wxz + * @date 2021.06.07 21:56 + */ + List listOperationLogs(String condition, String customerId, Integer pageNo, Integer pageSize); +} diff --git a/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/impl/LogOperationServiceImpl.java b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/impl/LogOperationServiceImpl.java new file mode 100644 index 0000000000..09b9269063 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/java/com/epmet/service/impl/LogOperationServiceImpl.java @@ -0,0 +1,181 @@ +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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.epmet.auth.constants.AuthOperationEnum; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.feign.ResultDataResolver; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.LogOperationDao; +import com.epmet.dto.CustomerStaffDTO; +import com.epmet.dto.form.CustomerStaffFormDTO; +import com.epmet.dto.region.LogOperationResultDTO; +import com.epmet.entity.LogOperationEntity; +import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.service.LogOperationService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.stream.Collectors; + +@Service +public class LogOperationServiceImpl implements LogOperationService, ResultDataResolver { + + @Autowired + private LogOperationDao logOperationDao; + + @Autowired + private EpmetUserOpenFeignClient userOpenFeignClient; + + @Override + public void log(LogOperationEntity msg) { + LambdaQueryWrapper w = new LambdaQueryWrapper<>(); + w.eq(LogOperationEntity::getType, msg.getType()); + w.eq(LogOperationEntity::getTargetId, msg.getTargetId()); + w.eq(LogOperationEntity::getOperatorId, msg.getOperatorId()); + w.eq(LogOperationEntity::getOperatingTime, msg.getOperatingTime()); + + Integer existsCount = logOperationDao.selectCount(w); + if (existsCount > 0) { + // 该日志已存在,不做任何操作 + return; + } + logOperationDao.insert(msg); + } + + @Override + public List listOperationLogs(String condition, String customerId, Integer pageNo, Integer pageSize) { + // 1.条件查询 + //List logDtos = listByOperatorMobile(condition, customerId, pageNo, pageSize); + //if (CollectionUtils.isEmpty(logDtos)) { + // logDtos = listByOperatorName(condition, pageNo, pageSize); + //} + // + //if (CollectionUtils.isEmpty(logDtos)) { + // return new ArrayList<>(); + //} + + // 2.直接分页查询 + // 条件查询,排序 + LambdaQueryWrapper w = new LambdaQueryWrapper<>(); + if (StringUtils.isNotBlank(condition)) { + w.like(LogOperationEntity::getOperatorName, condition) + .or() + .like(LogOperationEntity::getOperatorMobile, condition); + } + w.eq(LogOperationEntity::getCustomerId, customerId); + w.orderByDesc(LogOperationEntity::getOperatingTime); + IPage iPage = logOperationDao.selectPage(new Page<>(pageNo, pageSize), w); + List logEntities = iPage.getRecords(); + Set userIds = logEntities.stream().map(l -> l.getOperatorId()).collect(Collectors.toSet()); + + return convertLogOperationEntity2DTO(logEntities, getStaffMapByUserIds(userIds)); + } + + private Map getStaffMapByUserIds(Set userIds) { + CustomerStaffFormDTO form = new CustomerStaffFormDTO(); + form.setUserIds(new ArrayList<>(userIds)); + Result> result = userOpenFeignClient.list(form); + List staffs = getResultDataOrThrowsException(result, ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "调用user服务发生异常"); + + HashMap staffMap = new HashMap<>(); + staffs.forEach(s -> { + staffMap.put(s.getUserId(), s); + }); + + return staffMap; + } + + /** + * 通过操作人手机号查询操作日志列表 + * + * @param operatorMobile + * @param customerId + */ + private List listByOperatorMobile(String operatorMobile, String customerId, Integer pageNo, Integer pageSize) { + CustomerStaffFormDTO form = new CustomerStaffFormDTO(); + form.setCustomerId(customerId); + form.setMobile(operatorMobile); + Result> result = userOpenFeignClient.list(form); + List staffs = getResultDataOrThrowsException(result, ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "调用user服务发生异常"); + + if (staffs.size() == 0) { + return null; + } + CustomerStaffDTO staff = staffs.get(0); + + QueryWrapper w = new QueryWrapper<>(); + w.lambda() + .eq(LogOperationEntity::getOperatorId, staff.getUserId()) + .eq(LogOperationEntity::getDelFlag, 0) + .orderByDesc(LogOperationEntity::getOperatingTime); + + IPage iPage = logOperationDao.selectPage(new Page<>(pageNo, pageSize), w); + + HashMap staffMap = new HashMap<>(); + staffMap.put(staff.getUserId(), staff); + + return convertLogOperationEntity2DTO(iPage.getRecords(), staffMap); + } + + /** + * @Description 通过操作人姓名查询操作日志列表 + * @return + * @author wxz + * @date 2021.06.08 11:12 + */ + private List listByOperatorName(String operatorName, Integer pageNo, Integer pageSize) { + CustomerStaffFormDTO form = new CustomerStaffFormDTO(); + form.setRealName(operatorName); + Result> result = userOpenFeignClient.list(form); + List staffs = getResultDataOrThrowsException(result, ServiceConstant.EPMET_USER_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "调用user服务查询工作人员信息发生异常"); + + List userIds = new ArrayList<>(); + HashMap staffMap = new HashMap(); + staffs.forEach(s -> { + staffMap.put(s.getUserId(), s); + userIds.add(s.getUserId()); + }); + + if (CollectionUtils.isEmpty(userIds)) { + return new ArrayList<>(); + } + LambdaQueryWrapper w = new LambdaQueryWrapper<>(); + w.in(LogOperationEntity::getOperatorId, userIds); + w.eq(LogOperationEntity::getDelFlag, 0); + w.orderByDesc(LogOperationEntity::getOperatingTime); + + IPage iPage = logOperationDao.selectPage(new Page<>(pageNo, pageSize), w); + + return convertLogOperationEntity2DTO(iPage.getRecords(), staffMap); + } + + /** + * @Description 将操作日志entity转化为dto列表 + * @return + * @author wxz + * @date 2021.06.08 11:12 + */ + private List convertLogOperationEntity2DTO(List logOperationEntities, Map staffMap) { + return logOperationEntities.stream().map(l -> { + LogOperationResultDTO ldto = new LogOperationResultDTO(); + ldto.setCategory(l.getCategory()); + ldto.setContent(l.getContent()); + ldto.setOperatingTime(l.getOperatingTime().getTime()/1000); + ldto.setOperatorId(l.getOperatorId()); + ldto.setTargetId(l.getTargetId()); + ldto.setType(l.getType()); + ldto.setTypeDisplay(l.getTypeDisplay()); + ldto.setCustomerId(l.getCustomerId()); + ldto.setOperatorMobile(staffMap.get(l.getOperatorId()).getMobile()); + ldto.setOperatorName(staffMap.get(l.getOperatorId()).getRealName()); + return ldto; + }).collect(Collectors.toList()); + } +} diff --git a/epmet-admin/epmet-admin-server/src/main/resources/bootstrap.yml b/epmet-admin/epmet-admin-server/src/main/resources/bootstrap.yml index 89f42ed404..0d9082cec3 100644 --- a/epmet-admin/epmet-admin-server/src/main/resources/bootstrap.yml +++ b/epmet-admin/epmet-admin-server/src/main/resources/bootstrap.yml @@ -134,3 +134,6 @@ shutdown: graceful: enable: true #是否开启优雅停机 waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警 + +rocketmq: + name-server: @rocketmq.nameserver@ \ No newline at end of file diff --git a/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.3__add_log_ope_table.sql b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.3__add_log_ope_table.sql new file mode 100644 index 0000000000..c6ccb2e1e9 --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.3__add_log_ope_table.sql @@ -0,0 +1,21 @@ +CREATE TABLE `log_operation` ( + `ID` varchar(64) NOT NULL COMMENT '主键ID', + `TYPE` varchar(64) NOT NULL COMMENT '动作类型枚举', + `TYPE_DISPLAY` varchar(64) NOT NULL COMMENT '操作类型中文展示', + `CONTENT` varchar(512) NOT NULL COMMENT '内容', + `CATEGORY` varchar(64) NOT NULL COMMENT '操作类型大类。例如login和logout都属于login大类。项目立项,项目流转,项目结案都属于项目大类', + `IP` varchar(15) NOT NULL COMMENT 'IP地址', + `FROM_APP` varchar(10) NOT NULL COMMENT '所用的APP', + `FROM_CLIENT` varchar(10) NOT NULL COMMENT '所用的client', + `TARGET_ID` varchar(64) NOT NULL COMMENT '操作目标ID', + `OPERATOR_ID` varchar(64) NOT NULL COMMENT '操作人ID', + `OPERATOR_NAME` varchar(15) NOT NULL COMMENT '操作者姓名', + `OPERATOR_MOBILE` varchar(11) NOT NULL COMMENT '操作者电话', + `OPERATING_TIME` datetime NOT NULL COMMENT '操作时间,该时间不是插入数据的时间,而是操作发生的真实时间', + `DEL_FLAG` int(11) NOT NULL DEFAULT '0' COMMENT '删除标识 0.未删除 1.已删除', + `REVISION` int(11) NOT NULL COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='操作日指标' \ No newline at end of file diff --git a/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.4__addlog_ope_col.sql b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.4__addlog_ope_col.sql new file mode 100644 index 0000000000..e2bcec3b6d --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/resources/db/migration/V0.0.4__addlog_ope_col.sql @@ -0,0 +1 @@ +alter table log_operation add CUSTOMER_ID varchar(64) comment '客户id' not null after OPERATOR_ID; \ No newline at end of file diff --git a/epmet-admin/epmet-admin-server/src/main/resources/logback-spring.xml b/epmet-admin/epmet-admin-server/src/main/resources/logback-spring.xml index 215a9500e7..fc97e8f1c9 100644 --- a/epmet-admin/epmet-admin-server/src/main/resources/logback-spring.xml +++ b/epmet-admin/epmet-admin-server/src/main/resources/logback-spring.xml @@ -134,7 +134,7 @@ - + diff --git a/epmet-admin/epmet-admin-server/src/main/resources/mapper/LogOperationDao.xml b/epmet-admin/epmet-admin-server/src/main/resources/mapper/LogOperationDao.xml new file mode 100644 index 0000000000..5f34d339ad --- /dev/null +++ b/epmet-admin/epmet-admin-server/src/main/resources/mapper/LogOperationDao.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-auth-client/pom.xml b/epmet-auth-client/pom.xml new file mode 100644 index 0000000000..1aee53c24e --- /dev/null +++ b/epmet-auth-client/pom.xml @@ -0,0 +1,14 @@ + + + + epmet-cloud + com.epmet + 2.0.0 + + 4.0.0 + + epmet-auth-client + + \ No newline at end of file diff --git a/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationConstants.java b/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationConstants.java new file mode 100644 index 0000000000..2cffd341ee --- /dev/null +++ b/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationConstants.java @@ -0,0 +1,9 @@ +package com.epmet.auth.constants; + +/** + * 认证操作常量 + */ +public interface AuthOperationConstants { + String LOGIN = "login"; + String LOGOUT = "logout"; +} diff --git a/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationEnum.java b/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationEnum.java new file mode 100644 index 0000000000..fb112e7c36 --- /dev/null +++ b/epmet-auth-client/src/main/java/com/epmet/auth/constants/AuthOperationEnum.java @@ -0,0 +1,43 @@ +package com.epmet.auth.constants; + +/** + * 认证操作枚举 + */ +public enum AuthOperationEnum { + + LOGIN(AuthOperationConstants.LOGIN, "登录"), + LOGOUT(AuthOperationConstants.LOGOUT, "退出"); + + private String operationType; + private String operationDisplay; + + AuthOperationEnum(String operationType, String operationDisplay) { + this.operationType = operationType; + this.operationDisplay = operationDisplay; + } + + public String getOperationType() { + return operationType; + } + + public String getOperationDisplay() { + return operationDisplay; + } + + public static AuthOperationEnum get(String operationType) { + for (AuthOperationEnum e : AuthOperationEnum.values()) { + if (e.getOperationType().equals(operationType)) { + return e; + } + } + return null; + } + + public static String getDisplay(String operationType) { + AuthOperationEnum obj = get(operationType); + if (obj == null) { + return null; + } + return obj.getOperationDisplay(); + } +} diff --git a/epmet-auth/pom.xml b/epmet-auth/pom.xml index 07d993b821..b0fb3a4617 100644 --- a/epmet-auth/pom.xml +++ b/epmet-auth/pom.xml @@ -133,6 +133,11 @@ 2.0.0 compile + + com.epmet + epmet-auth-client + 2.0.0 + diff --git a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java index 144e18d024..65e718aacf 100644 --- a/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java +++ b/epmet-auth/src/main/java/com/epmet/controller/ThirdLoginController.java @@ -1,7 +1,10 @@ package com.epmet.controller; +import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.UserDTO; import com.epmet.dto.form.*; import com.epmet.dto.result.StaffOrgsResultDTO; import com.epmet.dto.result.UserTokenResultDTO; diff --git a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java index 8dd958fe36..4d848f2dcf 100644 --- a/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java +++ b/epmet-auth/src/main/java/com/epmet/service/impl/ThirdLoginServiceImpl.java @@ -5,14 +5,19 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.epmet.auth.constants.AuthOperationConstants; import com.epmet.common.token.constant.LoginConstant; +import com.epmet.commons.rocketmq.messages.LoginMQMsg; +import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.security.dto.GovTokenDto; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.security.password.PasswordUtils; +import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.*; import com.epmet.commons.tools.validator.PhoneValidatorUtils; import com.epmet.constant.AuthHttpUrlConstant; @@ -34,7 +39,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.*; import java.util.stream.Collectors; @@ -44,7 +52,7 @@ import java.util.stream.Collectors; */ @Slf4j @Service -public class ThirdLoginServiceImpl implements ThirdLoginService { +public class ThirdLoginServiceImpl implements ThirdLoginService, ResultDataResolver { private static final Logger logger = LoggerFactory.getLogger(ThirdLoginServiceImpl.class); @Autowired @@ -61,6 +69,10 @@ public class ThirdLoginServiceImpl implements ThirdLoginService { private GovOrgOpenFeignClient govOrgOpenFeignClient; @Autowired private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Autowired + private EpmetMessageOpenFeignClient messageOpenFeignClient; + @Autowired + private LoginUserUtil loginUserUtil; /** * @param formDTO @@ -170,8 +182,17 @@ public class ThirdLoginServiceImpl implements ThirdLoginService { this.saveLatestGovTokenDto(staffLatestAgencyResultDTO, userWechatDTO, token); UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); userTokenResultDTO.setToken(token); - return userTokenResultDTO; + //7.发送登录事件 + try { + sendLoginEvent(staffLatestAgencyResultDTO.getStaffId(), formDTO.getAppId(), AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WXMP); + } catch (RenException e) { + log.error(e.getInternalMsg()); + } catch (Exception e) { + log.error("【工作端workLogin登录】发送登录事件失败,程序继续执行。"); + } + + return userTokenResultDTO; } /** @@ -392,6 +413,15 @@ public class ThirdLoginServiceImpl implements ThirdLoginService { UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); userTokenResultDTO.setToken(token); + + //6.发送登录事件 + try { + sendLoginEvent(customerStaff.getUserId(), formDTO.getAppId(), AppClientConstant.APP_GOV, AppClientConstant.CLIENT_WXMP); + } catch (RenException e) { + log.error(e.getInternalMsg()); + } catch (Exception e) { + log.error("【工作端enterOrg登录】发送登录事件失败,程序继续执行。错误信息"); + } return userTokenResultDTO; } @@ -635,4 +665,29 @@ public class ThirdLoginServiceImpl implements ThirdLoginService { logger.info(String.format("发送短信验证码成功,手机号[%s]", formDTO.getMobile())); } + + /** + * @Description 发送登录事件 + * @return + * @author wxz + * @date 2021.06.08 15:27 + */ + private void sendLoginEvent(String userId, String appId, String fromApp, String fromClient) { + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + + LoginMQMsg loginMQMsg = new LoginMQMsg(); + loginMQMsg.setUserId(userId); + loginMQMsg.setLoginTime(new Date()); + loginMQMsg.setAppId(appId); + loginMQMsg.setIp(IpUtils.getIpAddr(request)); + loginMQMsg.setFromApp(fromApp); + loginMQMsg.setFromClient(fromClient); + + SystemMsgFormDTO form = new SystemMsgFormDTO(); + form.setMessageType(AuthOperationConstants.LOGIN); + form.setContent(loginMQMsg); + messageOpenFeignClient.sendSystemMsgByMQ(form); + //getResultDataOrThrowsException(result, ServiceConstant.EPMET_MESSAGE_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "调用Message服务,发送登录事件到MQ失败"); + } + } diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java index 5acfebb90e..ef5970dbb3 100644 --- a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/ConsomerGroupConstants.java @@ -31,4 +31,14 @@ public interface ConsomerGroupConstants { */ String GROUP_ACHIEVEMENT_COMPONENTS_GROUP = "group_achievement_components_group"; + /** + * 认证操作日志消费组 + */ + String AUTH_OPERATION_LOG_GROUP = "auth_operation_log_group"; + + /** + * 项目操作日志小肥猪 + */ + String PROJECT_OPERATION_LOG_GROUP = "project_operation_log_group"; + } diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java index bd9fed05eb..70d4e006f8 100644 --- a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/constants/TopicConstants.java @@ -1,5 +1,8 @@ package com.epmet.commons.rocketmq.constants; +/** + * 话题列表常量,其他服务要想发送消息到mq,则应当引入epmet-commons-rocketmq模块,并且使用此常量 + */ public interface TopicConstants { /** * 初始化客户 @@ -13,4 +16,9 @@ public interface TopicConstants { * 小组成就 */ String GROUP_ACHIEVEMENT = "group_achievement"; + + /** + * 认证 + */ + String AUTH = "auth"; } diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/LoginMQMsg.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/LoginMQMsg.java new file mode 100644 index 0000000000..646db43501 --- /dev/null +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/LoginMQMsg.java @@ -0,0 +1,26 @@ +package com.epmet.commons.rocketmq.messages; + +import lombok.Data; + +import java.util.Date; + +@Data +public class LoginMQMsg { + + /** + * 谁登录 + */ + private String userId; + private String appId; + /** + * 什么时间登录的 + */ + private Date loginTime; + + private String ip; + + private String fromApp; + + private String fromClient; + +} diff --git a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/ProjectChangedMQMsg.java b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/ProjectChangedMQMsg.java index d93871bd55..5f33faae98 100644 --- a/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/ProjectChangedMQMsg.java +++ b/epmet-commons/epmet-commons-rocketmq/src/main/java/com/epmet/commons/rocketmq/messages/ProjectChangedMQMsg.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import java.io.Serializable; +import java.util.Date; /** * desc:项目变动通知消息实体类 @@ -18,4 +19,22 @@ public class ProjectChangedMQMsg implements Serializable { * 操作类型 议题转项目issue_shift_project, 处理:response, 结案close,退回return,部门流转transfer,立项created */ private String operation; + +// ============> new + private String projectId; + private String operatorId; + private Date operatingTime; + /** + * 操作简介 + */ + private String operationBrief; + + /** + * 操作者ip + */ + private String ip; + private String fromApp; + private String fromClient; + + } diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java new file mode 100644 index 0000000000..1e44b924c2 --- /dev/null +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/feign/ResultDataResolver.java @@ -0,0 +1,50 @@ +package com.epmet.commons.tools.feign; + +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.utils.Result; +import org.apache.commons.lang3.StringUtils; + +/** + * Feign请求结果解析器 + */ +public interface ResultDataResolver { + + /** + * @Description 获取Result种的data,如果失败(返回result为null或者result.success为false),那么返回null + * @return + * @author wxz + * @date 2021.06.07 22:45 + */ + //default R tryGetResultData(Result result, String targetServiceName) { + // Logger logger = LoggerFactory.getLogger(ResultDataResolver.class); + // if (result == null) { + // logger.error("调用{}服务发生错误,返回Result为null", targetServiceName); + // return null; + // } + // if (!result.success()) { + // logger.error("调用{}服务发生错误,错误信息:{}", targetServiceName, result.getInternalMsg()); + // return null; + // } + // return result.getData(); + //} + + /** + * @Description 获取Result种的data,如果失败(返回result为null或者result.success为false),那么抛出异常 + * @return + * @author wxz + * @date 2021.06.07 22:45 + */ + default R getResultDataOrThrowsException(Result result, String targetServiceName, Integer errorCode, String errorInternalMsg) { + if (result == null) { + throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode(), "调用{}服务发生错误,返回Result为null", targetServiceName); + } + if (!result.success()) { + Integer finalErrorCode = errorCode == null ? result.getCode() : errorCode; + String finalErrorInternalMsg = StringUtils.isBlank(errorInternalMsg) ? result.getInternalMsg() : errorInternalMsg; + throw new RenException(finalErrorCode, finalErrorInternalMsg); + } + return result.getData(); + } + +} diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java index 410549aecb..bb5e6f7b5d 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/security/user/LoginUserUtil.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import javax.servlet.http.HttpServletRequest; +import java.util.Enumeration; import java.util.List; /** diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index b6c6863d2f..8f61556641 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -258,6 +258,7 @@ lb://epmet-auth-server + lb://epmet-admin-server lb://epmet-oss-server diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java index 282dc7b711..bc71d2817a 100644 --- a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/constant/SystemMessageType.java @@ -1,7 +1,7 @@ package com.epmet.constant; /** - * 系统消息类型 + * 系统消息类型(可以理解为动作,约等于rocket mq中的tag) */ public interface SystemMessageType { diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java index 4e8e7c954a..a6204e07ac 100644 --- a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/send/SendMqMsgUtil.java @@ -37,7 +37,7 @@ public class SendMqMsgUtil { } /** - * desc: 发送小组成就消息,计算小组成就 + * desc: 发送项目变动事件消息 * * @param msgContent * @return boolean diff --git a/epmet-module/epmet-message/epmet-message-server/pom.xml b/epmet-module/epmet-message/epmet-message-server/pom.xml index eb728ed8c6..2e114d9299 100644 --- a/epmet-module/epmet-message/epmet-message-server/pom.xml +++ b/epmet-module/epmet-message/epmet-message-server/pom.xml @@ -125,6 +125,12 @@ epmet-commons-rocketmq 2.0.0 + + + com.epmet + epmet-auth-client + 2.0.0 + diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java index db9be4c1ba..6813dcd362 100644 --- a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/SystemMessageServiceImpl.java @@ -1,6 +1,8 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; +import com.epmet.auth.constants.AuthOperationConstants; +import com.epmet.auth.constants.AuthOperationEnum; import com.epmet.commons.rocketmq.constants.TopicConstants; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; @@ -43,7 +45,7 @@ public class SystemMessageServiceImpl implements SystemMessageService { //发送mq消息 try { - Message meMessage = new Message(getTopicByMsgType(messageType), contentStr.getBytes(RemotingHelper.DEFAULT_CHARSET)); + Message meMessage = new Message(getTopicByMsgType(messageType), messageType, contentStr.getBytes(RemotingHelper.DEFAULT_CHARSET)); rocketMQTemplate.getProducer().send(meMessage); } catch (Exception e) { String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); @@ -70,6 +72,12 @@ public class SystemMessageServiceImpl implements SystemMessageService { case SystemMessageType.GROUP_ACHIEVEMENT: topic = TopicConstants.GROUP_ACHIEVEMENT; break; + case AuthOperationConstants.LOGIN: + topic = TopicConstants.AUTH; + break; + case AuthOperationConstants.LOGOUT: + topic = TopicConstants.AUTH; + break; } return topic; } diff --git a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java index 2c0cf4bb23..b1f1701e75 100644 --- a/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java +++ b/epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java @@ -125,6 +125,8 @@ public class IssueServiceImpl extends BaseServiceImpl imp private IssueProjectTagDictService issueProjectTagDictService; @Autowired private IssueVoteDetailDao issueVoteDetailDao; + @Autowired + private EpmetMessageOpenFeignClient messageOpenFeignClient; @Value("${openapi.scan.server.url}") @@ -1041,6 +1043,9 @@ public class IssueServiceImpl extends BaseServiceImpl imp if(!resiGroupOpenFeignClient.sendEvent(eventParam).success()){ logger.warn("com.epmet.service.impl.IssueServiceImpl.shiftProjectV2,话题被转为项目积分事件发送失败,参数:{}", JSON.toJSONString(formDTO)); } + + //8.记录日志 + //SendMqMsgUtil.build().openFeignClient(messageOpenFeignClient).sendProjectChangedMqMsg(); } /** diff --git a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java index ff85abe02b..ad3fec6959 100644 --- a/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java +++ b/epmet-module/gov-project/gov-project-server/src/main/java/com/epmet/service/impl/ProjectProcessServiceImpl.java @@ -31,7 +31,9 @@ import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.scan.param.TextScanParamDTO; import com.epmet.commons.tools.scan.param.TextTaskDTO; import com.epmet.commons.tools.scan.result.SyncScanResult; +import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.IpUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.ScanContentUtils; import com.epmet.constant.ProjectConstant; @@ -71,7 +73,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import javax.servlet.http.HttpServletRequest; import java.util.*; import java.util.stream.Collectors; @@ -116,6 +121,8 @@ public class ProjectProcessServiceImpl extends BaseServiceImpl page(Map params) { @@ -386,8 +393,18 @@ public class ProjectProcessServiceImpl extends BaseServiceImpl processStaff = epmetUserFeignClient.getCustomerStaffInfoByUserId(form); + + ProjectEntity projectEntity = projectService.selectById(projectId); + return String.format("将项目\"%s\"吹哨给%s%s处理", projectEntity.getTitle(), departmentName, processStaff.getData().getRealName()); + } + /** * @Description 项目流转给流转工作人员推送消息 * @author sun @@ -741,7 +773,16 @@ public class ProjectProcessServiceImpl extends BaseServiceImpl getProjectByIssue(ShiftProjectsFromDTO fromDTO) { List resultList = new ArrayList<>(); @@ -1168,8 +1226,19 @@ public class ProjectServiceImpl extends BaseServiceImpl implements ProjectTraceS private EpmetUserFeignClient epmetUserFeignClient; @Autowired private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; + @Autowired + private LoginUserUtil loginUserUtil; @Override public List getPendProjectList(TokenDto tokenDto, ProjectListFromDTO fromDTO) { @@ -509,7 +516,16 @@ public class ProjectTraceServiceImpl implements ProjectTraceS } //项目实时统计消息 - ProjectChangedMQMsg mqMsg = new ProjectChangedMQMsg(projectEntity.getCustomerId(), ProjectConstant.OPERATION_CREATED); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String mqMsgBrief = String.format("创建了\"%s\"的项目", formDTO.getTitle()); + ProjectChangedMQMsg mqMsg = new ProjectChangedMQMsg(projectEntity.getCustomerId(), ProjectConstant.OPERATION_CREATED, + projectEntity.getId(), + formDTO.getUserId(), + new Date(), + mqMsgBrief, + IpUtils.getIpAddr(request), + loginUserUtil.getLoginUserApp(), + loginUserUtil.getLoginUserClient()); boolean msgResult = SendMqMsgUtil.build().openFeignClient(epmetMessageOpenFeignClient).sendProjectChangedMqMsg(mqMsg); if (!msgResult) { log.error("项目实时统计消息发送失败"); diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffFormDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffFormDTO.java index 43acb11d1c..f5317723e6 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffFormDTO.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerStaffFormDTO.java @@ -4,6 +4,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import java.io.Serializable; +import java.util.List; /** * @Description 根据手机号+客户id获取工作人员基本信息 @@ -13,9 +14,23 @@ import java.io.Serializable; @Data public class CustomerStaffFormDTO implements Serializable { private static final long serialVersionUID = 7619815083427853431L; - @NotBlank(message = "手机号不能为空") + + // 根据手机号+客户id获取工作人员基本信息 + public interface GetCustomerStaffInfo {} + + @NotBlank(message = "手机号不能为空", groups = { GetCustomerStaffInfo.class }) private String mobile; - @NotBlank(message = "客户id不能为空") + @NotBlank(message = "客户id不能为空", groups = { GetCustomerStaffInfo.class }) private String customerId; + + /** + * 姓名 + */ + private String realName; + + /** + * 用户id集合 + */ + private List userIds; } diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index 1f619168ae..fcf24efc39 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -531,6 +531,26 @@ public interface EpmetUserOpenFeignClient { @PostMapping("/epmetuser/badge/userbadges") Result> userBadges(@RequestBody UserBadgesFormDTO formDTO); + /** + * 根据用户ID获取工作人员基本信息 + * + * @param formDTO + * @return com.epmet.commons.tools.utils.Result + * @author zhaoqifeng + * @date 2020/4/22 10:05 + **/ + @PostMapping(value = "/epmetuser/customerstaff/getstaffinfobyuserid") + Result getCustomerStaffInfoByUserId(@RequestBody CustomerStaffDTO formDTO); + + /** + * @Description 通用批量查询 + * @return + * @author wxz + * @date 2021.06.08 10:54 + */ + @PostMapping(value = "/epmetuser/customerstaff/list") + Result> list(CustomerStaffFormDTO input); + /** * @Description 查询网格员角色 * @Param forms diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java index c4cb042786..db88733c0e 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java @@ -374,6 +374,16 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "userBadges", formDTO); } + @Override + public Result getCustomerStaffInfoByUserId(CustomerStaffDTO formDTO) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerStaffInfoByUserId", formDTO); + } + + @Override + public Result> list(CustomerStaffFormDTO input) { + return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "list", input); + } + @Override public Result> staffGridRole(List forms) { return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "staffGridRole", forms); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java index e1eefc0a94..cb9673ccf6 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/CustomerStaffController.java @@ -20,6 +20,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; +import com.epmet.commons.tools.security.user.LoginUserUtil; import com.epmet.commons.tools.utils.ExcelUtils; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.AssertUtils; @@ -32,10 +33,12 @@ import com.epmet.dto.form.*; import com.epmet.dto.result.*; import com.epmet.excel.CustomerStaffExcel; import com.epmet.service.CustomerStaffService; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotBlank; import java.util.List; import java.util.Map; @@ -53,6 +56,9 @@ public class CustomerStaffController { @Autowired private CustomerStaffService customerStaffService; + @Autowired + private LoginUserUtil loginUserUtil; + @GetMapping("page") public Result> page(@RequestParam Map params) { PageData page = customerStaffService.page(params); @@ -116,7 +122,7 @@ public class CustomerStaffController { **/ @PostMapping(value = "getcustomerstaffinfo") public Result getCustomerStaffInfo(@RequestBody CustomerStaffFormDTO formDTO) { - ValidatorUtils.validateEntity(formDTO); + ValidatorUtils.validateEntity(formDTO, CustomerStaffFormDTO.GetCustomerStaffInfo.class); return customerStaffService.getCustomerStaffInfo(formDTO); } @@ -410,4 +416,17 @@ public class CustomerStaffController { return new Result().ok(customerStaffService.getStaffBasicInfo(fromDTO)); } + /** + * @Description 通用列表查询。可以指定customerId,如果指定了,则使用指定的,如果未指定,则使用当前登录用户的customerId + * @return + * @author wxz + * @date 2021.06.08 10:54 + */ + @PostMapping("list") + public Result> list(@RequestBody CustomerStaffFormDTO input) { + List staffs = customerStaffService.list(input.getCustomerId(), input.getRealName(), input.getMobile(), input.getUserIds()); + return new Result>().ok(staffs); + } + + } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java index 6a580a6372..d0679eb2b6 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/CustomerStaffDao.java @@ -205,4 +205,12 @@ public interface CustomerStaffDao extends BaseDao { * @date 2021/6/9 1:36 下午 */ List selectUserName(@Param("userIds")List userIds); + + /** + * 通用列表查询 + * @param customerId + * @param realName + * @return + */ + List listDTOS(@Param("customerId") String customerId, @Param("realName") String realName, @Param("mobile") String mobile, @Param("userIds") List userIds); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java index 833791fc54..7f5b43161e 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/CustomerStaffService.java @@ -321,4 +321,12 @@ public interface CustomerStaffService extends BaseService { * @return */ BasicInfoResultDTO getStaffBasicInfo(StaffBasicInfoFromDTO fromDTO); + + /** + * @Description 根据姓名查询工作人员 + * @return + * @author wxz + * @date 2021.06.08 10:52 + */ + List list(String customerId, String realName, String mobile, List ids); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java index 8d5f22aa64..aea728c458 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/CustomerStaffServiceImpl.java @@ -18,6 +18,7 @@ package com.epmet.service.impl; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.entity.DataScope; @@ -57,6 +58,7 @@ import com.epmet.service.GovStaffRoleService; import com.epmet.service.StaffRoleService; import com.epmet.service.UserService; import com.epmet.util.ModuleConstant; +import kotlin.jvm.internal.Lambda; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; @@ -723,4 +725,8 @@ public class CustomerStaffServiceImpl extends BaseServiceImpl list(String customerId, String realName, String mobile, List userIds) { + return baseDao.listDTOS(customerId, realName, mobile, userIds); + } } diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml index e6db9c61a6..9e3265747c 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/CustomerStaffDao.xml @@ -358,6 +358,48 @@ LIMIT 1 + +