Parcourir la source

Merge branch 'feat-mq-20211117' into master

Qutong il y a 3 ans
Parent
commit
32a1be6977
32 fichiers modifiés avec 1374 ajouts et 108 suppressions
  1. 5 0
      hnqz-common/hnqz-common-bom/pom.xml
  2. 6 0
      hnqz-common/hnqz-common-core/pom.xml
  3. 133 0
      hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/entity/BaseMap.java
  4. 27 0
      hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/util/SpringContextHolder.java
  5. 28 0
      hnqz-common/hnqz-common-mq/pom.xml
  6. 29 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/annotation/RabbitMqComponent.java
  7. 363 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/client/RabbitMqClient.java
  8. 54 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/config/RabbitMqConfig.java
  9. 31 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/core/BaseRabbiMqHandler.java
  10. 39 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/core/MapMessageConverter.java
  11. 27 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/BaseApplicationEvent.java
  12. 8 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/BusEventHandler.java
  13. 21 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/EventObj.java
  14. 29 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/HnqzRemoteApplicationEvent.java
  15. 30 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/exchange/DelayExchangeBuilder.java
  16. 10 0
      hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/listenter/MqListener.java
  17. 3 0
      hnqz-common/hnqz-common-mq/src/main/resources/META-INF/spring.factories
  18. 1 0
      hnqz-common/pom.xml
  19. 11 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/CacheConstants.java
  20. 21 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/MqConstants.java
  21. 57 0
      hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/entity/WmReportOpt.java
  22. 4 0
      hnqz-upms/hnqz-upms-biz/pom.xml
  23. 218 82
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/ReportExportController.java
  24. 14 2
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageController.java
  25. 61 13
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmTaskController.java
  26. 7 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmReport.java
  27. 13 0
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java
  28. 7 7
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/ReportExportService.java
  29. 3 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmScorePackageService.java
  30. 0 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/ReportExportServiceImpl.java
  31. 47 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmReportServiceImpl.java
  32. 67 1
      hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageServiceImpl.java

+ 5 - 0
hnqz-common/hnqz-common-bom/pom.xml

@@ -113,6 +113,11 @@
 				<artifactId>hnqz-common-taxhelper</artifactId>
 				<version>${hnqz.version}</version>
 			</dependency>
+			<dependency>
+				<groupId>com.qunzhixinxi</groupId>
+				<artifactId>hnqz-common-mq</artifactId>
+				<version>${hnqz.version}</version>
+			</dependency>
 			<!--<dependency>-->
 			<!--	<groupId>com.qunzhixinxi</groupId>-->
 			<!--	<artifactId>hnqz-common-transaction</artifactId>-->

+ 6 - 0
hnqz-common/hnqz-common-core/pom.xml

@@ -66,5 +66,11 @@
 			<groupId>io.swagger</groupId>
 			<artifactId>swagger-annotations</artifactId>
 		</dependency>
+		<!-- commons-beanutils -->
+		<dependency>
+			<groupId>commons-beanutils</groupId>
+			<artifactId>commons-beanutils</artifactId>
+			<version>1.9.4</version>
+		</dependency>
 	</dependencies>
 </project>

+ 133 - 0
hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/entity/BaseMap.java

@@ -0,0 +1,133 @@
+package com.qunzhixinxi.hnqz.common.core.entity;
+
+import cn.hutool.core.util.ObjectUtil;
+import lombok.NoArgsConstructor;
+import org.apache.commons.beanutils.ConvertUtils;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * 自定义Map
+ */
+@NoArgsConstructor
+public class BaseMap extends HashMap<String, Object> {
+
+	public BaseMap(Map<String, Object> map) {
+        this.putAll(map);
+    }
+
+    @Override
+    public BaseMap put(String key, Object value) {
+        super.put(key, Optional.ofNullable(value).orElse(""));
+        return this;
+    }
+
+    public BaseMap add(String key, Object value) {
+        super.put(key, Optional.ofNullable(value).orElse(""));
+        return this;
+    }
+
+    @SuppressWarnings("unchecked")
+    public <T> T get(String key) {
+        Object obj = super.get(key);
+        if (ObjectUtil.isNotEmpty(obj)) {
+            return (T) obj;
+        } else {
+            return null;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public Boolean getBoolean(String key) {
+        Object obj = super.get(key);
+        if (ObjectUtil.isNotEmpty(obj)) {
+            return Boolean.valueOf(obj.toString());
+        } else {
+            return false;
+        }
+    }
+
+    public Long getLong(String key) {
+        Object v = get(key);
+        if (ObjectUtil.isNotEmpty(v)) {
+            return new Long(v.toString());
+        }
+        return null;
+    }
+
+    public Long[] getLongs(String key) {
+        Object v = get(key);
+        if (ObjectUtil.isNotEmpty(v)) {
+            return (Long[]) v;
+        }
+        return null;
+    }
+
+    public List<Long> getListLong(String key) {
+        List<String> list = get(key);
+        if (ObjectUtil.isNotEmpty(list)) {
+            return list.stream().map(e -> new Long(e)).collect(Collectors.toList());
+        } else {
+            return null;
+        }
+    }
+
+    public Long[] getLongIds(String key) {
+        Object ids = get(key);
+        if (ObjectUtil.isNotEmpty(ids)) {
+            return (Long[]) ConvertUtils.convert(ids.toString().split(","), Long.class);
+        } else {
+            return null;
+        }
+    }
+
+
+    public Integer getInt(String key, Integer def) {
+        Object v = get(key);
+        if (ObjectUtil.isNotEmpty(v)) {
+            return Integer.parseInt(v.toString());
+        } else {
+            return def;
+        }
+    }
+
+    public Integer getInt(String key) {
+        Object v = get(key);
+        if (ObjectUtil.isNotEmpty(v)) {
+            return Integer.parseInt(v.toString());
+        } else {
+            return 0;
+        }
+    }
+
+    public BigDecimal getBigDecimal(String key) {
+        Object v = get(key);
+        if (ObjectUtil.isNotEmpty(v)) {
+            return new BigDecimal(v.toString());
+        }
+        return new BigDecimal("0");
+    }
+
+
+    @SuppressWarnings("unchecked")
+    public <T> T get(String key, T def) {
+        Object obj = super.get(key);
+        if (ObjectUtil.isEmpty(obj)) {
+            return def;
+        }
+        return (T) obj;
+    }
+
+    public static BaseMap toBaseMap(Map<String, Object> obj) {
+        BaseMap map = new BaseMap();
+        map.putAll(obj);
+        return map;
+    }
+
+
+}

+ 27 - 0
hnqz-common/hnqz-common-core/src/main/java/com/qunzhixinxi/hnqz/common/core/util/SpringContextHolder.java

@@ -19,6 +19,7 @@
 
 package com.qunzhixinxi.hnqz.common.core.util;
 
+import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.context.ApplicationContext;
@@ -97,4 +98,30 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
 		SpringContextHolder.clearHolder();
 	}
 
+	/**
+	 * 从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型.
+	 */
+	public static <T> T getHandler(String name, Class<T> cls) {
+		T t = null;
+		if (StrUtil.isNotBlank(name)) {
+			checkApplicationContext();
+			try {
+				t = applicationContext.getBean(name, cls);
+			} catch (Exception e) {
+				log.error("####################" + name + "未定义");
+			}
+		}
+		return t;
+	}
+
+	/**
+	 * 检查
+	 */
+	private static void checkApplicationContext() {
+		if (applicationContext == null) {
+			throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder");
+		}
+	}
+
+
 }

+ 28 - 0
hnqz-common/hnqz-common-mq/pom.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<parent>
+		<artifactId>hnqz-common</artifactId>
+		<groupId>com.qunzhixinxi</groupId>
+		<version>3.9.0</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+
+	<artifactId>hnqz-common-mq</artifactId>
+	<description>消息队列</description>
+	<version>3.9.0</version>
+
+	<dependencies>
+		<!-- 核心模块 -->
+		<dependency>
+			<groupId>com.qunzhixinxi</groupId>
+			<artifactId>hnqz-common-core</artifactId>
+		</dependency>
+		<!-- 消息总线 rabbitmq -->
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
+		</dependency>
+	</dependencies>
+</project>

+ 29 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/annotation/RabbitMqComponent.java

@@ -0,0 +1,29 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.annotation;
+
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.stereotype.Component;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * 消息队列初始化注解
+ * @author Hengchen.Sun
+ * @date 2021/08/23 16:25:23
+ * @version 1.0.0
+ */
+@Documented
+@Inherited
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Component
+public @interface RabbitMqComponent {
+    @AliasFor(
+            annotation = Component.class
+    )
+    String value();
+}

+ 363 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/client/RabbitMqClient.java

@@ -0,0 +1,363 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.client;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.qunzhixinxi.hnqz.common.core.entity.BaseMap;
+import com.qunzhixinxi.hnqz.common.rabbitmq.annotation.RabbitMqComponent;
+import com.qunzhixinxi.hnqz.common.rabbitmq.event.EventObj;
+import com.qunzhixinxi.hnqz.common.rabbitmq.event.HnqzRemoteApplicationEvent;
+import com.qunzhixinxi.hnqz.common.rabbitmq.exchange.DelayExchangeBuilder;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.*;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.bus.BusProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.Resource;
+import java.lang.reflect.Method;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * rabbitmq消息队列客户端
+ *
+ * @author Hengchen.sun
+ * @version 1.0.0
+ * @date 2021/08/23 16:27:18
+ */
+@Slf4j
+@Configuration
+public class RabbitMqClient {
+
+	private final RabbitAdmin rabbitAdmin;
+
+	private final RabbitTemplate rabbitTemplate;
+
+	private final Map<String, Object> sentObj = new HashMap<>();
+
+	@Autowired
+	public RabbitMqClient(RabbitAdmin rabbitAdmin, RabbitTemplate rabbitTemplate) {
+		this.rabbitAdmin = rabbitAdmin;
+		this.rabbitTemplate = rabbitTemplate;
+	}
+
+	@Resource
+	private SimpleMessageListenerContainer messageListenerContainer;
+
+	@Resource
+	BusProperties busProperties;
+
+	@Resource
+	private ApplicationEventPublisher publisher;
+
+	@Resource
+	private ApplicationContext applicationContext;
+
+
+	/**
+	 * 初始化队列
+	 */
+	@Bean
+	public void initQueue() {
+		Map<String, Object> beansWithRabbitComponentMap = this.applicationContext.getBeansWithAnnotation(RabbitMqComponent.class);
+		Class<?> clazz;
+		log.info(">>>>>>>>>>>> 初始化队列开始 <<<<<<<<<<<<");
+		for (Map.Entry<String, Object> entry : beansWithRabbitComponentMap.entrySet()) {
+			//获取到实例对象的class信息
+			clazz = entry.getValue().getClass();
+			Method[] methods = clazz.getMethods();
+			RabbitListener rabbitListener = clazz.getAnnotation(RabbitListener.class);
+			if (ObjectUtil.isNotEmpty(rabbitListener)) {
+				createQueue(rabbitListener);
+			}
+			for (Method method : methods) {
+				RabbitListener methodRabbitListener = method.getAnnotation(RabbitListener.class);
+				if (ObjectUtil.isNotEmpty(methodRabbitListener)) {
+					createQueue(methodRabbitListener);
+				}
+			}
+		}
+		log.info(">>>>>>>>>>>> 初始化队列结束 <<<<<<<<<<<<");
+
+	}
+
+	/**
+	 * 创建队列
+	 *
+	 * @param rabbitListener 监听
+	 */
+	private void createQueue(RabbitListener rabbitListener) {
+		String[] queues = rabbitListener.queues();
+		DirectExchange directExchange = createExchange(DelayExchangeBuilder.DEFAULT_DIRECT_EXCHANGE);
+		//创建交换机
+		rabbitAdmin.declareExchange(directExchange);
+		if (ObjectUtil.isNotEmpty(queues)) {
+			for (String queueName : queues) {
+				Queue queue = new Queue(queueName);
+				addQueue(queue);
+				Binding binding = BindingBuilder.bind(queue).to(directExchange).with(queueName);
+				rabbitAdmin.declareBinding(binding);
+				log.info("## 队列创建成功:【{}】 ##", queueName);
+			}
+		}
+	}
+
+
+	/**
+	 * 发送远程事件
+	 *
+	 * @param handlerName 绑定名称
+	 * @param baseMap     事件
+	 */
+	public void publishEvent(String handlerName, BaseMap baseMap) {
+		EventObj eventObj = new EventObj();
+		eventObj.setHandlerName(handlerName);
+		eventObj.setBaseMap(baseMap);
+		publisher.publishEvent(new HnqzRemoteApplicationEvent(eventObj, busProperties.getId()));
+	}
+
+	/**
+	 * 转换Message对象
+	 *
+	 * @param messageType 返回消息类型 MessageProperties类中常量
+	 * @param msg
+	 * @return 信息对象
+	 */
+	public Message getMessage(String messageType, Object msg) {
+		MessageProperties messageProperties = new MessageProperties();
+		messageProperties.setContentType(messageType);
+		return new Message(msg.toString().getBytes(), messageProperties);
+	}
+
+	/**
+	 * 有绑定Key的Exchange发送
+	 *
+	 * @param routingKey 路由key
+	 * @param msg        信息
+	 */
+	public void sendMessageToExchange(TopicExchange topicExchange, String routingKey, Object msg) {
+		Message message = getMessage(MessageProperties.CONTENT_TYPE_JSON, msg);
+		rabbitTemplate.send(topicExchange.getName(), routingKey, message);
+	}
+
+	/**
+	 * 没有绑定KEY的Exchange发送
+	 *
+	 * @param exchange 交换机
+	 * @param msg      信息
+	 */
+	public void sendMessageToExchange(TopicExchange topicExchange, AbstractExchange exchange, String msg) {
+		addExchange(exchange);
+		log.info("RabbitMQ 发送信息{} -> {}", exchange.getName(), msg);
+		rabbitTemplate.convertAndSend(topicExchange.getName(), msg);
+	}
+
+
+	/**
+	 * 发送消息
+	 *
+	 * @param queueName 队列名称
+	 * @param params    消息内容map
+	 */
+	public void sendMessage(String queueName, Object params) {
+		log.info("发送消息到mq:{}", params);
+		try {
+			rabbitTemplate.convertAndSend(DelayExchangeBuilder.DEFAULT_DIRECT_EXCHANGE, queueName, params, message -> message);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 发送消息
+	 *
+	 * @param queueName 队列名称
+	 */
+	public void sendMessage(String queueName) {
+		this.send(queueName, this.sentObj, 0);
+		this.sentObj.clear();
+	}
+
+
+	/**
+	 * 添加发送信息
+	 *
+	 * @param key   信息key
+	 * @param value 信息值
+	 * @return 客户端
+	 */
+	public RabbitMqClient put(String key, Object value) {
+		this.sentObj.put(key, value);
+		return this;
+	}
+
+	/**
+	 * 延迟发送消息
+	 *
+	 * @param queueName  队列名称
+	 * @param params     消息内容params
+	 * @param expiration 延迟时间 单位毫秒
+	 */
+	public void sendMessage(String queueName, Object params, Integer expiration) {
+		this.send(queueName, params, expiration);
+	}
+
+	/**
+	 * 发送消息
+	 *
+	 * @param queueName  队列名
+	 * @param params     参数
+	 * @param expiration 过期时间
+	 */
+	private void send(String queueName, Object params, Integer expiration) {
+		Queue queue = new Queue(queueName);
+		addQueue(queue);
+		CustomExchange customExchange = DelayExchangeBuilder.buildExchange();
+		rabbitAdmin.declareExchange(customExchange);
+		Binding binding = BindingBuilder.bind(queue).to(customExchange).with(queueName).noargs();
+		rabbitAdmin.declareBinding(binding);
+		log.debug("发送时间:{}", LocalDateTime.now());
+		messageListenerContainer.setQueueNames(queueName);
+		rabbitTemplate.convertAndSend(DelayExchangeBuilder.DEFAULT_DELAY_EXCHANGE, queueName, params, message -> {
+			if (expiration != null && expiration > 0) {
+				message.getMessageProperties().setHeader("x-delay", expiration);
+			}
+			return message;
+		});
+	}
+
+
+	/**
+	 * 给queue发送消息
+	 *
+	 * @param queueName 队列名
+	 */
+	public String receiveFromQueue(String queueName) {
+		return receiveFromQueue(DirectExchange.DEFAULT, queueName);
+	}
+
+	/**
+	 * 给direct交换机指定queue发送消息
+	 *
+	 * @param directExchange 直接模式交换机
+	 * @param queueName      队列名
+	 */
+	public String receiveFromQueue(DirectExchange directExchange, String queueName) {
+		Queue queue = new Queue(queueName);
+		addQueue(queue);
+		Binding binding = BindingBuilder.bind(queue).to(directExchange).withQueueName();
+		rabbitAdmin.declareBinding(binding);
+		String messages = (String) rabbitTemplate.receiveAndConvert(queueName);
+		log.info("接收到的信息:{}", messages);
+		return messages;
+	}
+
+	/**
+	 * 创建Exchange
+	 *
+	 * @param exchange 交换机
+	 */
+	public void addExchange(AbstractExchange exchange) {
+		rabbitAdmin.declareExchange(exchange);
+	}
+
+	/**
+	 * 删除一个Exchange
+	 *
+	 * @param exchangeName 交换机名称
+	 */
+	public boolean deleteExchange(String exchangeName) {
+		return rabbitAdmin.deleteExchange(exchangeName);
+	}
+
+
+	/**
+	 * 声明其名称自动命名的队列。它是用exclusive=true、autoDelete=true和 durable = false
+	 *
+	 * @return Queue
+	 */
+	public Queue addQueue() {
+		return rabbitAdmin.declareQueue();
+	}
+
+	/**
+	 * 创建一个指定的Queue
+	 *
+	 * @param queue 队列
+	 * @return queueName
+	 */
+	public String addQueue(Queue queue) {
+		return rabbitAdmin.declareQueue(queue);
+	}
+
+	/**
+	 * 删除一个队列
+	 *
+	 * @param queueName the name of the queue.
+	 * @param unused    true if the queue should be deleted only if not in use.
+	 * @param empty     true if the queue should be deleted only if empty.
+	 */
+	public void deleteQueue(String queueName, boolean unused, boolean empty) {
+		rabbitAdmin.deleteQueue(queueName, unused, empty);
+	}
+
+	/**
+	 * 删除一个队列
+	 *
+	 * @param queueName 队列名
+	 * @return true if the queue existed and was deleted.
+	 */
+	public boolean deleteQueue(String queueName) {
+		return rabbitAdmin.deleteQueue(queueName);
+	}
+
+	/**
+	 * 绑定一个队列到一个匹配型交换器使用一个routingKey
+	 *
+	 * @param queue      队列
+	 * @param exchange   交换机
+	 * @param routingKey 路由key
+	 */
+	public void addBinding(Queue queue, TopicExchange exchange, String routingKey) {
+		Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey);
+		rabbitAdmin.declareBinding(binding);
+	}
+
+	/**
+	 * 绑定一个Exchange到一个匹配型Exchange 使用一个routingKey
+	 *
+	 * @param exchange      交换机
+	 * @param topicExchange topic交换机
+	 * @param routingKey    路由key
+	 */
+	public void addBinding(Exchange exchange, TopicExchange topicExchange, String routingKey) {
+		Binding binding = BindingBuilder.bind(exchange).to(topicExchange).with(routingKey);
+		rabbitAdmin.declareBinding(binding);
+	}
+
+	/**
+	 * 去掉一个binding
+	 *
+	 * @param binding 绑定
+	 */
+	public void removeBinding(Binding binding) {
+		rabbitAdmin.removeBinding(binding);
+	}
+
+	/**
+	 * 创建交换器
+	 *
+	 * @param exchangeName 交换机名称
+	 * @return 直接模式交换机
+	 */
+	public DirectExchange createExchange(String exchangeName) {
+		return new DirectExchange(exchangeName, true, false);
+	}
+}

+ 54 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/config/RabbitMqConfig.java

@@ -0,0 +1,54 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.config;
+
+import com.qunzhixinxi.hnqz.common.rabbitmq.event.HnqzRemoteApplicationEvent;
+import org.springframework.amqp.core.AcknowledgeMode;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
+import org.springframework.amqp.support.ConsumerTagStrategy;
+import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.UUID;
+
+/**
+ * 消息队列配置类
+ *
+ * @author zyf
+ */
+@Configuration
+@RemoteApplicationEventScan(basePackageClasses = HnqzRemoteApplicationEvent.class)
+public class RabbitMqConfig {
+
+    @Bean
+    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
+        RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
+        //设置忽略声明异常
+        rabbitAdmin.setIgnoreDeclarationExceptions(true);
+        return rabbitAdmin;
+    }
+
+    @Bean
+    public SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory) {
+        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
+        container.setConnectionFactory(connectionFactory);
+        //手动确认
+        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
+        //当前的消费者数量
+        container.setConcurrentConsumers(1);
+        //最大的消费者数量
+        container.setMaxConcurrentConsumers(1);
+        //是否重回队列
+        container.setDefaultRequeueRejected(true);
+        //消费端的标签策略
+        container.setConsumerTagStrategy(new ConsumerTagStrategy() {
+            @Override
+            public String createConsumerTag(String queue) {
+                return queue + "_" + UUID.randomUUID().toString();
+            }
+        });
+        return container;
+    }
+
+}

+ 31 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/core/BaseRabbiMqHandler.java

@@ -0,0 +1,31 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.core;
+
+import com.qunzhixinxi.hnqz.common.rabbitmq.listenter.MqListener;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+
+@Slf4j
+public class BaseRabbiMqHandler<T> {
+
+    public void onMessage(T t, Long deliveryTag, Channel channel, MqListener mqListener) {
+        try {
+            mqListener.handler(t, channel);
+            channel.basicAck(deliveryTag, false);
+        } catch (Exception e) {
+            log.info("接收消息失败,重新放回队列");
+            try {
+                /**
+                 * deliveryTag:该消息的index
+                 * multiple:是否批量.true:将一次性拒绝所有小于deliveryTag的消息。
+                 * requeue:被拒绝的是否重新入队列
+                 */
+                channel.basicNack(deliveryTag, false, true);
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+
+    }
+}

+ 39 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/core/MapMessageConverter.java

@@ -0,0 +1,39 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.core;
+
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.core.MessageProperties;
+import org.springframework.amqp.support.converter.MessageConversionException;
+import org.springframework.amqp.support.converter.MessageConverter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MapMessageConverter implements MessageConverter {
+    @Override
+    public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
+        return new Message(object.toString().getBytes(), messageProperties);
+    }
+
+    @Override
+    public Object fromMessage(Message message) throws MessageConversionException {
+        String contentType = message.getMessageProperties().getContentType();
+        if (null != contentType && contentType.contains("text")) {
+            return new String(message.getBody());
+        } else {
+            ObjectInputStream objInt = null;
+            try {
+                ByteArrayInputStream byteInt = new ByteArrayInputStream(message.getBody());
+                objInt = new ObjectInputStream(byteInt);
+                //byte[]转map
+                Map map = (HashMap) objInt.readObject();
+                return map;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+
+    }
+}

+ 27 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/BaseApplicationEvent.java

@@ -0,0 +1,27 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.event;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.qunzhixinxi.hnqz.common.core.util.SpringContextHolder;
+import org.springframework.context.ApplicationListener;
+import org.springframework.stereotype.Component;
+
+/**
+ * 监听远程事件,并分发消息到业务模块消息处理器
+ */
+@Component
+public class BaseApplicationEvent implements ApplicationListener<HnqzRemoteApplicationEvent> {
+
+    @Override
+    public void onApplicationEvent(HnqzRemoteApplicationEvent hnqzRemoteApplicationEvent) {
+        EventObj eventObj = hnqzRemoteApplicationEvent.getEventObj();
+        if (ObjectUtil.isNotEmpty(eventObj)) {
+            //获取业务模块消息处理器
+            BusEventHandler busEventHandler = SpringContextHolder.getHandler(eventObj.getHandlerName(), BusEventHandler.class);
+            if (ObjectUtil.isNotEmpty(busEventHandler)) {
+                //通知业务模块
+                busEventHandler.onMessage(eventObj);
+            }
+        }
+    }
+
+}

+ 8 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/BusEventHandler.java

@@ -0,0 +1,8 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.event;
+
+/**
+ * 业务模块消息处理器接口
+ */
+public interface BusEventHandler {
+    void onMessage(EventObj map);
+}

+ 21 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/EventObj.java

@@ -0,0 +1,21 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.event;
+
+import com.qunzhixinxi.hnqz.common.core.entity.BaseMap;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 远程事件数据对象
+ */
+@Data
+public class EventObj implements Serializable {
+    /**
+     * 数据对象
+     */
+    private BaseMap baseMap;
+    /**
+     * 自定义业务模块消息处理器beanName
+     */
+    private String handlerName;
+}

+ 29 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/event/HnqzRemoteApplicationEvent.java

@@ -0,0 +1,29 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.event;
+
+import lombok.Data;
+import org.springframework.cloud.bus.event.RemoteApplicationEvent;
+
+/**
+ * 自定义网关刷新远程事件
+ *
+ * @author : zyf
+ * @date :2020-11-10
+ */
+@Data
+public class HnqzRemoteApplicationEvent extends RemoteApplicationEvent {
+
+    private EventObj eventObj;
+
+    private HnqzRemoteApplicationEvent() {
+    }
+
+    public HnqzRemoteApplicationEvent(EventObj source, String originService, String destinationService) {
+        super(source, originService, destinationService);
+        this.eventObj = source;
+    }
+
+    public HnqzRemoteApplicationEvent(EventObj source, String originService) {
+        super(source, originService, null);
+        this.eventObj = source;
+    }
+}

+ 30 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/exchange/DelayExchangeBuilder.java

@@ -0,0 +1,30 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.exchange;
+
+import org.springframework.amqp.core.CustomExchange;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 延迟交换器构造器
+ */
+public class DelayExchangeBuilder {
+    /**
+     * 默认延迟消息交换器
+     */
+    public final static  String DEFAULT_DELAY_EXCHANGE = "default.delayed.exchange";
+    /**
+     * 普通交换器
+     */
+    public final static  String DEFAULT_DIRECT_EXCHANGE = "default.direct.exchange";
+
+    /**
+     * 构建延迟消息交换器
+     * @return
+     */
+    public static CustomExchange buildExchange() {
+        Map<String, Object> args = new HashMap<String, Object>();
+        args.put("x-delayed-type", "direct");
+        return new CustomExchange(DEFAULT_DELAY_EXCHANGE, "x-delayed-message", true, false, args);
+    }
+}

+ 10 - 0
hnqz-common/hnqz-common-mq/src/main/java/com/qunzhixinxi/hnqz/common/rabbitmq/listenter/MqListener.java

@@ -0,0 +1,10 @@
+package com.qunzhixinxi.hnqz.common.rabbitmq.listenter;
+
+import com.rabbitmq.client.Channel;
+
+public interface MqListener<T> {
+
+    default void handler(T map, Channel channel) {
+    }
+
+}

+ 3 - 0
hnqz-common/hnqz-common-mq/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,3 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+  com.qunzhixinxi.hnqz.common.rabbitmq.config.RabbitMqConfig,\
+  com.qunzhixinxi.hnqz.common.rabbitmq.client.RabbitMqClient

+ 1 - 0
hnqz-common/pom.xml

@@ -51,5 +51,6 @@
 		<module>hnqz-common-ding</module>
 		<module>hnqz-common-taxhelper</module>
 		<module>hnqz-common-qcc</module>
+		<module>hnqz-common-mq</module>
 	</modules>
 </project>

+ 11 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/CacheConstants.java

@@ -74,4 +74,15 @@ public interface CacheConstants {
 	 */
 	String MONITORING_INDICATOR = "monitoring_indicator";
 
+	/**
+	 * zb报告导出缓存
+	 */
+	String EXPORT_ZB_REPORT_CACHE = "export:zb_report:%s";
+	String EXPORT_NBA_REPORT_CACHE = "export:nba_report:%s";
+	String EXPORT_NBA_HISTORY_REPORT_CACHE = "export:nba_history_report:%s";
+	String EXPORT_NB_REPORT_CACHE = "export:nb_report:%s";
+
+
+	Long DEF_REPORT_CREATING_TTL = 24L * 60 * 60 * 1000;
+
 }

+ 21 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/constant/MqConstants.java

@@ -0,0 +1,21 @@
+package com.qunzhixinxi.hnqz.admin.api.constant;
+
+/**
+ * {@code MqConstants}
+ * <p>
+ * 消息队列常量
+ *
+ * @author Hengchen.Sun
+ * @version 1.0.0
+ * @date 2021/11/17 11:21
+ */
+public interface MqConstants {
+
+	/**
+	 * 众包队列
+	 */
+	String DIRECT_MODE_REPORT_EXPORT_ZB_QUEUE = "direct_mode_report_export_zb_queue";
+	String DIRECT_MODE_REPORT_EXPORT_NBA_QUEUE = "direct_mode_report_export_nba_queue";
+	String DIRECT_MODE_REPORT_EXPORT_NBA_HISTORY_QUEUE = "direct_mode_report_export_nba_history_queue";
+	String DIRECT_MODE_REPORT_EXPORT_NB_QUEUE = "direct_mode_report_export_nb_queue";
+}

+ 57 - 0
hnqz-upms/hnqz-upms-api/src/main/java/com/qunzhixinxi/hnqz/admin/api/entity/WmReportOpt.java

@@ -0,0 +1,57 @@
+package com.qunzhixinxi.hnqz.admin.api.entity;
+
+import cn.hutool.core.date.DatePattern;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * {@code WmReportOpt}
+ * <p>
+ * 报告导出
+ *
+ * @author Hengchen.Sun
+ * @version 1.0.0
+ * @date 2021/11/17 11:37
+ */
+@Data
+public class WmReportOpt {
+
+	/**
+	 * 生成状态
+	 */
+	private WmReportOptStatus status;
+
+	/**
+	 * 最近可用
+	 */
+	@JsonInclude(JsonInclude.Include.NON_NULL)
+	private String latestUrl;
+
+	/**
+	 * 当前报告最后可用下载时间
+	 */
+	@JsonInclude(JsonInclude.Include.NON_NULL)
+	@JsonFormat(pattern = DatePattern.CHINESE_DATE_TIME_PATTERN)
+	private LocalDateTime ttl;
+
+	/**
+	 * 失败信息
+	 */
+	@JsonInclude(JsonInclude.Include.NON_NULL)
+	private String errorMsg;
+
+
+	public enum WmReportOptStatus {
+		// 未生成
+		NOT_GENERATE,
+		// 生成中
+		GENERATING,
+		// 已生成
+		GENERATED,
+		// 生成失败
+		ERROR;
+	}
+}

+ 4 - 0
hnqz-upms/hnqz-upms-biz/pom.xml

@@ -33,6 +33,10 @@
 	<description>hnqz 通用用户权限管理系统业务处理模块</description>
 
 	<dependencies>
+		<dependency>
+			<groupId>com.qunzhixinxi</groupId>
+			<artifactId>hnqz-common-mq</artifactId>
+		</dependency>
 		<!--upms api、model 模块-->
 		<dependency>
 			<groupId>com.qunzhixinxi</groupId>

+ 218 - 82
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/ReportExportController.java

@@ -19,23 +19,35 @@
 
 package com.qunzhixinxi.hnqz.admin.controller;
 
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.csp.sentinel.util.StringUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
+import com.qunzhixinxi.hnqz.admin.api.constant.MqConstants;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.config.UpmsConfig;
 import com.qunzhixinxi.hnqz.admin.entity.WmReport;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
 import com.qunzhixinxi.hnqz.admin.entity.WmTask;
 import com.qunzhixinxi.hnqz.admin.entity.input.WmPackageExportApiInput;
+import com.qunzhixinxi.hnqz.admin.enums.ChannelEnum;
 import com.qunzhixinxi.hnqz.admin.enums.ReportEnum;
 import com.qunzhixinxi.hnqz.admin.service.*;
+import com.qunzhixinxi.hnqz.common.core.entity.BaseMap;
 import com.qunzhixinxi.hnqz.common.core.util.R;
+import com.qunzhixinxi.hnqz.common.rabbitmq.client.RabbitMqClient;
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.mail.javamail.JavaMailSender;
 import org.springframework.mail.javamail.MimeMessageHelper;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -49,6 +61,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -77,6 +90,8 @@ public class ReportExportController {
 	private final JavaMailSender sender;
 
 	private final UpmsConfig upmsConfig;
+	private final RedisTemplate<String,String> redisTemplate;
+	private final RabbitMqClient rabbitMqClient;
 
 
 
@@ -112,6 +127,56 @@ public class ReportExportController {
 
 
 
+	// /**
+	//  * 结算报告管理--导出汇总或详情
+	//  * @param wmReport
+	//  * @return
+	//  * @throws IOException
+	//  */
+	// @GetMapping("/exportNbReport")
+	// public R exportNbReport(WmReport wmReport ) throws IOException {
+	// 	wmReport=wmReportService.getById(wmReport.getId());
+	// 	List<WmTask> taskList=new ArrayList<>();//该报告关联的所有未提交的任务
+	// 	//更新任务表审批意见
+	// 	WmScorePackage scorePackage=wmScorePackageService.getById(wmReport.getScoreId());
+	// 	WmTask wmTask=new WmTask();
+	// 	wmTask.setDelFlag("0");
+	// 	wmTask.setEnableFlag("0");
+	// 	wmTask.setRealFlag("0");
+	//
+	// 	SysDept sysDept = sysDeptService.getById(scorePackage.getSendPackageDeptId());
+	//
+	//
+	// 	if("0".equals(scorePackage.getTypeid())){//药企
+	// 		wmTask.setReportDrugId(wmReport.getId());
+	// 		wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
+	// 		taskList=wmTaskService.list(Wrappers.query(wmTask));
+	// 	}else if("1".equals(scorePackage.getTypeid())){//一级代理商类型
+	// 		wmTask.setReportOneId(wmReport.getId());
+	// 		if(sysDept.getLevel() == 2){
+	// 			wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
+	// 		}else {
+	// 			wmTask.setReportOneApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
+	// 		}
+	//
+	// 		taskList=wmTaskService.list(Wrappers.query(wmTask));
+	// 	}else if("2".equals(scorePackage.getTypeid())){//二级代理商类型
+	// 		wmTask.setReportSecondId(wmReport.getId());
+	// 		wmTask.setReportSecondApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
+	// 		taskList=wmTaskService.list(Wrappers.query(wmTask));
+	// 	}
+	// 	if(null==taskList||taskList.size()<=0){
+	// 		return R.failed("未查询到该报告关联的审批通过的任务");
+	// 	}
+	// 	String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
+	// 	wmTask.setScorePackageId(wmReport.getScoreId().toString());
+	// 	wmTask.setId(ids);
+	//
+	// 		return reportExportService.exportNb(wmTask,wmReport);//报告汇总
+	//
+	//
+	// }
+
 	/**
 	 * 结算报告管理--导出汇总或详情
 	 * @param wmReport
@@ -120,50 +185,70 @@ public class ReportExportController {
 	 */
 	@GetMapping("/exportNbReport")
 	public R exportNbReport(WmReport wmReport ) throws IOException {
-		wmReport=wmReportService.getById(wmReport.getId());
-		List<WmTask> taskList=new ArrayList<>();//该报告关联的所有未提交的任务
-		//更新任务表审批意见
-		WmScorePackage scorePackage=wmScorePackageService.getById(wmReport.getScoreId());
-		WmTask wmTask=new WmTask();
-		wmTask.setDelFlag("0");
-		wmTask.setEnableFlag("0");
-		wmTask.setRealFlag("0");
-
-		SysDept sysDept = sysDeptService.getById(scorePackage.getSendPackageDeptId());
-
-
-		if("0".equals(scorePackage.getTypeid())){//药企
-			wmTask.setReportDrugId(wmReport.getId());
-			wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
-			taskList=wmTaskService.list(Wrappers.query(wmTask));
-		}else if("1".equals(scorePackage.getTypeid())){//一级代理商类型
-			wmTask.setReportOneId(wmReport.getId());
-			if(sysDept.getLevel() == 2){
-				wmTask.setReportDrugApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
-			}else {
-				wmTask.setReportOneApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
-			}
 
-			taskList=wmTaskService.list(Wrappers.query(wmTask));
-		}else if("2".equals(scorePackage.getTypeid())){//二级代理商类型
-			wmTask.setReportSecondId(wmReport.getId());
-			wmTask.setReportSecondApprovalOpinion(ReportEnum.APPROVAL_OPINION_YES.getType());//审核通过的状态
-			taskList=wmTaskService.list(Wrappers.query(wmTask));
-		}
-		if(null==taskList||taskList.size()<=0){
-			return R.failed("未查询到该报告关联的审批通过的任务");
+
+		String key = String.format(CacheConstants.EXPORT_NB_REPORT_CACHE, wmReport.getId());
+
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StringUtils.isNotEmpty(o) && WmReportOpt.WmReportOptStatus.GENERATING.name().equals(o)){
+
+			return R.failed("已有在途生成记录,能耐心等待");
+
 		}
-		String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
-		wmTask.setScorePackageId(wmReport.getScoreId().toString());
-		wmTask.setId(ids);
 
-			return reportExportService.exportNb(wmTask,wmReport);//报告汇总
+
+		HnqzUser user = SecurityUtils.getUser();
+		BaseMap map = new BaseMap();
+		map.put("requestBody", JSONUtil.toJsonStr(wmReport));
+		map.put("username",user.getUsername());
+		map.put("deptId",user.getDeptId());
+
+		rabbitMqClient.sendMessage(MqConstants.DIRECT_MODE_REPORT_EXPORT_NB_QUEUE,map);
+
+		redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
+				CacheConstants.DEF_REPORT_CREATING_TTL, TimeUnit.MILLISECONDS);
+
+		return R.ok("开始导出,请耐心等待");
 
 
 	}
 
 
 
+	// /**
+	//  * 个人报告导出--导出汇总或详情  汇总和详情合为一个模版
+	//  * @param wmTask
+	//  * @return
+	//  * @throws IOException
+	//  */
+	// @GetMapping("/exportZbReport")
+	// public R exportZbReport(WmTask wmTask) throws IOException {
+	// 	String packageId=wmTask.getScorePackageDrugId();
+	// 	if (null == packageId) {
+	// 		return R.failed("积分包ID不能为空");
+	// 	}
+	// 	LambdaQueryWrapper<WmTask> queryWrapper=new LambdaQueryWrapper();
+	// 	queryWrapper.in(WmTask::getScorePackageId, Arrays.asList(packageId.split(",")));
+	// 	queryWrapper.eq(WmTask::getTaskStatus,"3");
+	// 	queryWrapper.eq(WmTask::getDelFlag,"0");
+	// 	queryWrapper.eq(WmTask::getEnableFlag,"0");
+	// 	queryWrapper.eq(WmTask::getRealFlag,"0");
+	// 	List<WmTask> taskList=wmTaskService.list(queryWrapper);
+	// 	if(taskList.isEmpty()){
+	// 		return R.failed("未查询到审核通过的任务");
+	// 	}
+	// 	String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
+	// 	wmTask.setScorePackageId(packageId);
+	// 	wmTask.setId(ids);
+	//
+	// 	return reportExportService.exportZb(wmTask);//报告汇总
+	//
+	//
+	// }
+
+
+
 	/**
 	 * 个人报告导出--导出汇总或详情  汇总和详情合为一个模版
 	 * @param wmTask
@@ -172,26 +257,40 @@ public class ReportExportController {
 	 */
 	@GetMapping("/exportZbReport")
 	public R exportZbReport(WmTask wmTask) throws IOException {
-		String packageId=wmTask.getScorePackageDrugId();
-		if (null == packageId) {
-			return R.failed("积分包ID不能为空");
+
+		String scorePackageDrugId = wmTask.getScorePackageDrugId();
+
+		// 判断是否是合并导出
+		if (scorePackageDrugId.contains(StrUtil.COMMA)){
+			String[] idArr = scorePackageDrugId.split(StrUtil.COMMA);
+			scorePackageDrugId = Arrays.stream(idArr).sorted().collect(Collectors.joining(StrUtil.COMMA));
+			wmTask.setScorePackageDrugId(scorePackageDrugId);
+
 		}
-		LambdaQueryWrapper<WmTask> queryWrapper=new LambdaQueryWrapper();
-		queryWrapper.in(WmTask::getScorePackageId, Arrays.asList(packageId.split(",")));
-		queryWrapper.eq(WmTask::getTaskStatus,"3");
-		queryWrapper.eq(WmTask::getDelFlag,"0");
-		queryWrapper.eq(WmTask::getEnableFlag,"0");
-		queryWrapper.eq(WmTask::getRealFlag,"0");
-		List<WmTask> taskList=wmTaskService.list(queryWrapper);
-		if(taskList.isEmpty()){
-			return R.failed("未查询到审核通过的任务");
+
+		String key = String.format(CacheConstants.EXPORT_ZB_REPORT_CACHE, wmTask.getScorePackageDrugId());
+
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StringUtils.isNotEmpty(o) && WmReportOpt.WmReportOptStatus.GENERATING.name().equals(o)){
+
+			return R.failed("已有在途生成记录,能耐心等待");
+
 		}
-		String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
-		wmTask.setScorePackageId(packageId);
-		wmTask.setId(ids);
 
-		return reportExportService.exportZb(wmTask);//报告汇总
 
+		HnqzUser user = SecurityUtils.getUser();
+		BaseMap map = new BaseMap();
+		map.put("requestBody", JSONUtil.toJsonStr(wmTask));
+		map.put("username",user.getUsername());
+		map.put("deptId",user.getDeptId());
+
+		rabbitMqClient.sendMessage(MqConstants.DIRECT_MODE_REPORT_EXPORT_ZB_QUEUE,map);
+
+		redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
+				CacheConstants.DEF_REPORT_CREATING_TTL, TimeUnit.MILLISECONDS);
+
+		return R.ok("开始导出,请耐心等待");
 
 	}
 
@@ -286,13 +385,13 @@ public class ReportExportController {
 
 
 
-	/**
-	 * 个人报告导出--导出汇总或详情
-	 * @param wmTask
-	 *@param exportType  1 导出汇总  2导出详情
-	 * @return
-	 * @throws IOException
-	 */
+	// /**
+	//  * 个人报告导出--导出汇总或详情
+	//  * @param wmTask
+	//  *@param exportType  1 导出汇总  2导出详情
+	//  * @return
+	//  * @throws IOException
+	//  */
 //	@GetMapping("/exportZbReport")
 //	public R exportZbReport(WmTask wmTask, String exportType) throws IOException {
 //		String packageId=wmTask.getScorePackageDrugId();
@@ -361,6 +460,45 @@ public class ReportExportController {
 	}
 
 
+	// /**
+	//  * 历史数据导出报告
+	//  * @param wmScorePackage
+	//  * @return
+	//  * @throws IOException
+	//  */
+	// @GetMapping("/exportNbaHistory")
+	// public R exportNbaHistory(WmScorePackage wmScorePackage) throws IOException {
+	// 	wmScorePackage=wmScorePackageService.getById(wmScorePackage.getId());
+	// 	if(wmScorePackage==null){
+	// 		return R.failed("未查询到积分包信息");
+	// 	}
+	// 	LambdaQueryWrapper<WmTask> queryWrapper=new LambdaQueryWrapper();
+	// 	queryWrapper.eq(WmTask::getScorePackageDrugId, wmScorePackage.getId());
+	// 	queryWrapper.eq(WmTask::getTaskStatus,"3");
+	// 	queryWrapper.eq(WmTask::getDelFlag,"0");
+	// 	queryWrapper.eq(WmTask::getEnableFlag,"0");
+	// 	queryWrapper.eq(WmTask::getRealFlag,"0");
+	// 	List<WmTask> taskList=wmTaskService.list(queryWrapper);
+	// 	//List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
+	// 	//更新任务表审批意见
+	// 	WmTask wmTask=new WmTask();
+	// 	wmTask.setDelFlag("0");
+	// 	wmTask.setEnableFlag("0");
+	//
+	// 	if(null==taskList||taskList.size()<=0){
+	// 		return R.failed("未查询到该报告关联的审批通过的任务");
+	// 	}
+	// 	String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
+	// 	wmTask.setScorePackageId(wmScorePackage.getId());
+	// 	//wmTask.setId(ids);
+	// 	wmTask.setId("(select id from wm_task where del_flag=0 and real_flag=0 and enable_flag=0 and task_status=3  and score_package_drug_id="+wmScorePackage.getId()+")");
+	//
+	// 	return reportExportService.exportNba(wmTask,wmScorePackage);//报告汇总
+	//
+	//
+	// }
+
+
 	/**
 	 * 历史数据导出报告
 	 * @param wmScorePackage
@@ -369,33 +507,31 @@ public class ReportExportController {
 	 */
 	@GetMapping("/exportNbaHistory")
 	public R exportNbaHistory(WmScorePackage wmScorePackage) throws IOException {
-		wmScorePackage=wmScorePackageService.getById(wmScorePackage.getId());
-		if(wmScorePackage==null){
-			return R.failed("未查询到积分包信息");
-		}
-		LambdaQueryWrapper<WmTask> queryWrapper=new LambdaQueryWrapper();
-		queryWrapper.eq(WmTask::getScorePackageDrugId, wmScorePackage.getId());
-		queryWrapper.eq(WmTask::getTaskStatus,"3");
-		queryWrapper.eq(WmTask::getDelFlag,"0");
-		queryWrapper.eq(WmTask::getEnableFlag,"0");
-		queryWrapper.eq(WmTask::getRealFlag,"0");
-		List<WmTask> taskList=wmTaskService.list(queryWrapper);
-		//List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
-		//更新任务表审批意见
-		WmTask wmTask=new WmTask();
-		wmTask.setDelFlag("0");
-		wmTask.setEnableFlag("0");
-
-		if(null==taskList||taskList.size()<=0){
-			return R.failed("未查询到该报告关联的审批通过的任务");
+
+
+		String key = String.format(CacheConstants.EXPORT_NBA_HISTORY_REPORT_CACHE,wmScorePackage.getId());
+
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StringUtils.isNotEmpty(o) && WmReportOpt.WmReportOptStatus.GENERATING.name().equals(o)){
+
+			return R.failed("已有在途生成记录,能耐心等待");
+
 		}
-		String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining("," ));
-		wmTask.setScorePackageId(wmScorePackage.getId());
-		//wmTask.setId(ids);
-		wmTask.setId("(select id from wm_task where del_flag=0 and real_flag=0 and enable_flag=0 and task_status=3  and score_package_drug_id="+wmScorePackage.getId()+")");
 
-		return reportExportService.exportNba(wmTask,wmScorePackage);//报告汇总
 
+		HnqzUser user = SecurityUtils.getUser();
+		BaseMap map = new BaseMap();
+		map.put("requestBody",JSONUtil.toJsonStr(wmScorePackage));
+		map.put("username",user.getUsername());
+		map.put("deptId",user.getDeptId());
+
+		rabbitMqClient.sendMessage(MqConstants.DIRECT_MODE_REPORT_EXPORT_NBA_HISTORY_QUEUE,map);
+
+		redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
+				CacheConstants.DEF_REPORT_CREATING_TTL,TimeUnit.MILLISECONDS);
+
+		return R.ok("开始导出,请耐心等待");
 
 	}
 

+ 14 - 2
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmScorePackageController.java

@@ -27,9 +27,11 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.ImmutableMap;
+import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.dto.UserDTO;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.api.vo.ErrorInfoVo;
 import com.qunzhixinxi.hnqz.admin.api.vo.UserVO;
 import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
@@ -56,6 +58,8 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -70,6 +74,7 @@ import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 
@@ -103,7 +108,7 @@ public class WmScorePackageController {
 	private final WmDaDrugEntMapper wmDaDrugEntMapper;
 	private final WmDaAgentMapper wmDaAgentMapper;
 	private final SysUserMapper sysUserMapper;
-	private final WmReportMapper wmReportMapper;
+	private final StringRedisTemplate redisTemplate;
 
 
 	/**
@@ -318,6 +323,10 @@ public class WmScorePackageController {
 				}
 			}
 
+			// 封装报告记录
+			wmS.setReportMqName(CacheConstants.EXPORT_NBA_HISTORY_REPORT_CACHE);
+			wmScorePackageService.getReportOpt(wmS);
+
 		}
 		pageAnswer.setRecords(list);
 		return R.ok(pageAnswer);
@@ -642,6 +651,10 @@ public class WmScorePackageController {
 			if (ext.getPayRate().equals("100.00")) {
 				ext.setPackageFinishStatus("1");
 			}
+
+			// 封装导出结果
+			ext.setReportMqName(CacheConstants.EXPORT_NBA_REPORT_CACHE);
+			wmScorePackageService.getReportOpt(ext);
 		}
 		return R.ok(page1);
 	}
@@ -1404,7 +1417,6 @@ public class WmScorePackageController {
 		return R.ok(pageAnswer);
 	}
 
-
 	/**
 	 * 获取关联积分包名称 二期  业务平台
 	 *

+ 61 - 13
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/WmTaskController.java

@@ -29,9 +29,12 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.plugin.excel.annotation.RequestExcel;
+import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
+import com.qunzhixinxi.hnqz.admin.api.constant.MqConstants;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysFile;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.entity.AuditEntity;
 import com.qunzhixinxi.hnqz.admin.entity.WmDaAgent;
 import com.qunzhixinxi.hnqz.admin.entity.WmDaDistribution;
@@ -61,9 +64,12 @@ import com.qunzhixinxi.hnqz.admin.service.WmTaskContentService;
 import com.qunzhixinxi.hnqz.admin.service.WmTaskRuleService;
 import com.qunzhixinxi.hnqz.admin.service.WmTaskService;
 import com.qunzhixinxi.hnqz.admin.service.WmTaskTypeService;
+import com.qunzhixinxi.hnqz.common.core.entity.BaseMap;
 import com.qunzhixinxi.hnqz.common.core.util.R;
 import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
+import com.qunzhixinxi.hnqz.common.rabbitmq.client.RabbitMqClient;
 import com.qunzhixinxi.hnqz.common.security.annotation.Inner;
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -71,6 +77,7 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -102,6 +109,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 
@@ -146,6 +154,9 @@ public class WmTaskController {
 
 	private final SysFileService sysFileService;
 
+	private final RabbitMqClient rabbitMqClient;
+	private final RedisTemplate<String,String> redisTemplate;
+
 	/**
 	 * 分页查询
 	 *
@@ -1203,6 +1214,34 @@ public class WmTaskController {
 		return R.ok(wmTaskService.selectSettleTask(page, wmTask));
 	}
 
+	// /**
+	//  * 任务中心--导出汇总或详情
+	//  *
+	//  * @param wmScorePackage
+	//  * @return
+	//  * @throws IOException
+	//  */
+	// @GetMapping("/exportNba")
+	// public R exportNba(WmScorePackage wmScorePackage) throws IOException {
+	// 	wmScorePackage = wmScorePackageService.getById(wmScorePackage.getId());
+	// 	List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
+	// 	//更新任务表审批意见
+	// 	WmTask wmTask = new WmTask();
+	// 	wmTask.setDelFlag("0");
+	// 	wmTask.setEnableFlag("0");
+	//
+	// 	if (null == taskList || taskList.size() <= 0) {
+	// 		return R.failed("未查询到该报告关联的审批通过的任务");
+	// 	}
+	// 	String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining(","));
+	// 	wmTask.setScorePackageId(wmScorePackage.getId());
+	// 	wmTask.setId(ids);
+	//
+	// 	return reportExportService.exportNba(wmTask, wmScorePackage);//报告汇总
+	//
+	//dddd
+	// }
+
 	/**
 	 * 任务中心--导出汇总或详情
 	 *
@@ -1211,26 +1250,35 @@ public class WmTaskController {
 	 * @throws IOException
 	 */
 	@GetMapping("/exportNba")
-	public R exportNba(WmScorePackage wmScorePackage) throws IOException {
-		wmScorePackage = wmScorePackageService.getById(wmScorePackage.getId());
-		List<WmTask> taskList = wmTaskMapper.selectListByWmTask(wmScorePackage);
-		//更新任务表审批意见
-		WmTask wmTask = new WmTask();
-		wmTask.setDelFlag("0");
-		wmTask.setEnableFlag("0");
+	public R<?> exportNba(WmScorePackage wmScorePackage) throws IOException {
+
+		String key = String.format(CacheConstants.EXPORT_NBA_REPORT_CACHE,wmScorePackage.getId());
+
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StringUtils.isNotEmpty(o) && WmReportOpt.WmReportOptStatus.GENERATING.name().equals(o)){
+
+			return R.failed("已有在途生成记录,能耐心等待");
 
-		if (null == taskList || taskList.size() <= 0) {
-			return R.failed("未查询到该报告关联的审批通过的任务");
 		}
-		String ids = taskList.stream().map(WmTask::getId).collect(Collectors.joining(","));
-		wmTask.setScorePackageId(wmScorePackage.getId());
-		wmTask.setId(ids);
 
-		return reportExportService.exportNba(wmTask, wmScorePackage);//报告汇总
 
+		HnqzUser user = SecurityUtils.getUser();
+		BaseMap map = new BaseMap();
+		map.put("requestBody",JSONUtil.toJsonStr(wmScorePackage));
+		map.put("username",user.getUsername());
+		map.put("deptId",user.getDeptId());
+
+		rabbitMqClient.sendMessage(MqConstants.DIRECT_MODE_REPORT_EXPORT_NBA_QUEUE,map);
 
+		redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
+				CacheConstants.DEF_REPORT_CREATING_TTL , TimeUnit.MILLISECONDS);
+
+		return R.ok("开始导出,请耐心等待");
 	}
 
+
+
 	/**
 	 * 结算包--获取任务详情
 	 *

+ 7 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmReport.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -146,4 +147,10 @@ public class WmReport extends Model<WmReport> {
 	 */
 	@TableField(exist = false)
 	private String scorePackageName;
+
+	/**
+	 * 报告状态
+	 */
+	@TableField(exist = false)
+	private WmReportOpt reportOpt;
 }

+ 13 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/entity/WmScorePackage.java

@@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -479,6 +480,18 @@ public class WmScorePackage extends Model<WmScorePackage> {
 	@TableField(exist = false)
 	private PackageStopStatus stopStatus;
 
+	/**
+	 * 报告操作状态
+	 */
+	@TableField(exist = false)
+	private WmReportOpt reportOpt;
+
+	/**
+	 * 报告队列名
+	 */
+	@TableField(exist = false)
+	private String reportMqName;
+
 	/**
 	 * 关联药品的生产厂商列表
 	 */

+ 7 - 7
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/ReportExportService.java

@@ -21,19 +21,19 @@ import java.util.Map;
  */
 public interface ReportExportService {
 
-	public R getExportPackageZbTotalList(Page page, WmScorePackage wmScorePackage);
+	R getExportPackageZbTotalList(Page page, WmScorePackage wmScorePackage);
 
-	public R getExportPackageZbTaskList(Page page, WmTask wmTask);
+	R getExportPackageZbTaskList(Page page, WmTask wmTask);
 
-	public R exportNb(WmTask wmTask, WmReport wmReport) throws IOException;
+	R exportNb(WmTask wmTask, WmReport wmReport) throws IOException;
 
-	public R exportNba(WmTask wmTask,WmScorePackage wmScorePackage) throws IOException;
+	R exportNba(WmTask wmTask, WmScorePackage wmScorePackage) throws IOException;
 
-	public List<Map<String, Object>> exportNbInfo(WmTask wmTask) throws IOException;
+	List<Map<String, Object>> exportNbInfo(WmTask wmTask) throws IOException;
 
-	public R exportZb(WmTask wmTask) throws IOException;
+	R exportZb(WmTask wmTask) throws IOException;
 
-	public List<Map<String, Object>> exportZbInfo(WmTask wmTask) throws IOException;
+	List<Map<String, Object>> exportZbInfo(WmTask wmTask) throws IOException;
 
 	R exportZbJs(WmTask wmTask) throws IOException;
 

+ 3 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/WmScorePackageService.java

@@ -72,7 +72,7 @@ public interface WmScorePackageService extends IService<WmScorePackage> {
 
 	public IPage<WmScorePackage> getExportPackageTotalList(Page page, WmScorePackage wmScorePackage);
 
-	public IPage<WmScorePackage> getExportPackageTotalList1(Page page, WmScorePackage wmScorePackage);
+	IPage<WmScorePackage> getExportPackageTotalList1(Page page, WmScorePackage wmScorePackage);
 
 	public IPage<Map<String, Object>> getPlatTotalData(Page page, WmScorePackage wmScorePackage);
 
@@ -170,4 +170,6 @@ public interface WmScorePackageService extends IService<WmScorePackage> {
 
 
 	Future<WmScorePackage> buildScorePackage(WmScorePackage wmScorePackage, Integer packageType1, Integer packageType2);
+
+	void getReportOpt(WmScorePackage wmScorePackage);
 }

+ 0 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/ReportExportServiceImpl.java

@@ -105,7 +105,6 @@ public class ReportExportServiceImpl implements ReportExportService {
 	 * @return
 	 */
 	public R getExportPackageZbTotalList(Page page, WmScorePackage wmScorePackage) {
-		//SysDept sysDept = sysDeptService.getById(SecurityUtils.getUser().getDeptId());
 
 		wmScorePackage.setSendPackageDeptId(SecurityUtils.getUser().getDeptId()+"");
 		wmScorePackage.setTypeid("4");

+ 47 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmReportServiceImpl.java

@@ -18,6 +18,7 @@ package com.qunzhixinxi.hnqz.admin.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -26,7 +27,9 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.entity.WmReport;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
 import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageStatus;
@@ -48,6 +51,7 @@ import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -55,6 +59,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -75,10 +80,51 @@ public class WmReportServiceImpl extends ServiceImpl<WmReportMapper, WmReport> i
 	private final WmDaDistributionService wmDaDistributionService;
 	private final WmDaPharmacyService wmDaPharmacyService;
 	private final WmDaHospitalService wmDaHospitalService;
+	private final RedisTemplate<String,String> redisTemplate;
 
 	@Override
 	public IPage<WmReport> getReportListPage(Page page, WmReport wmReport, String scoreId, String name){
-		return wmReportMapper.getReportListPage(page,wmReport,scoreId,name);
+		IPage<WmReport> reportListPage = wmReportMapper.getReportListPage(page, wmReport, scoreId, name);
+
+		List<WmReport> records = reportListPage.getRecords();
+
+		for (WmReport report : records){
+
+			WmReportOpt opt = new WmReportOpt();
+
+			// 获取生成记录
+			String key = String.format(CacheConstants.EXPORT_NB_REPORT_CACHE, report.getId());
+			String o = redisTemplate.opsForValue().get(key);
+
+			if (StrUtil.isNotEmpty(o)) {
+
+				// 生成中的
+				if ("GENERATING".equals(o)) {
+					opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATING);
+				}
+				// 生成失败的
+				else if (o.startsWith("ERROR")) {
+					opt.setStatus(WmReportOpt.WmReportOptStatus.ERROR);
+					opt.setErrorMsg(o.split(StrUtil.UNDERLINE)[1]);
+				}
+				// 成功的
+				else {
+					Long expire = redisTemplate.opsForValue().getOperations().getExpire(key, TimeUnit.SECONDS);
+					opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATED);
+					opt.setTtl(LocalDateTime.now().plusSeconds(expire));
+					// o = "https://pre.yaoyi.net/admin/sys-file/wmkj/兼职学术信息沟通专员业绩报告(2249)-20211116191527.doc";
+					opt.setLatestUrl(o);
+				}
+
+
+			} else {
+				opt.setStatus(WmReportOpt.WmReportOptStatus.NOT_GENERATE);
+			}
+			report.setReportOpt(opt);
+
+		}
+
+		return reportListPage;
 	}
 
 

+ 67 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmScorePackageServiceImpl.java

@@ -29,10 +29,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.ImmutableMap;
+import com.qunzhixinxi.hnqz.admin.api.constant.CacheConstants;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDept;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysDictItem;
 import com.qunzhixinxi.hnqz.admin.api.entity.SysUser;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.admin.api.vo.UserVO;
 import com.qunzhixinxi.hnqz.admin.api.vo.WmScorePackageVO;
 import com.qunzhixinxi.hnqz.admin.entity.*;
@@ -51,6 +53,7 @@ import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
 import org.springframework.stereotype.Service;
@@ -62,6 +65,7 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import static com.qunzhixinxi.hnqz.admin.enums.ReportEnum.REPORT_STATUS_END;
@@ -91,6 +95,7 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
 	private final WmDaDrugEntDrugtableService wmDaDrugEntDrugtableService;
 	private final WmReportMapper wmReportMapper;
 	private final SysDictItemService sysDictItemService;
+	private final RedisTemplate<String, String> redisTemplate;
 
 	@Override
 	public List<WmScorePackage> listWmScorePackageAndTask(WmScorePackage wmScorePackage) {
@@ -264,7 +269,17 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
 		orderItem.setColumn("create_time");
 		orderItem.setAsc(false);
 		page.addOrder(orderItem);
-		return wmScorePackageMapper.getExportPackageTotalList1(page, wmScorePackage);
+		IPage<WmScorePackage> list1 = wmScorePackageMapper.getExportPackageTotalList1(page, wmScorePackage);
+		List<WmScorePackage> records = list1.getRecords();
+
+		for (WmScorePackage scorePackage : records) {
+
+			scorePackage.setReportMqName(CacheConstants.EXPORT_ZB_REPORT_CACHE);
+			this.getReportOpt(scorePackage);
+		}
+
+
+		return list1;
 	}
 
 	public IPage<WmScorePackage> getExportPackageTotalList(Page page, WmScorePackage wmScorePackage) {
@@ -2074,6 +2089,10 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
 
 		scorePackage.setStopStatus(stopStatus);
 
+		// 封装报告记录
+		scorePackage.setReportMqName(CacheConstants.EXPORT_ZB_REPORT_CACHE);
+		getReportOpt(scorePackage);
+
 		return new AsyncResult<>(scorePackage);
 	}
 
@@ -2226,6 +2245,53 @@ public class WmScorePackageServiceImpl extends ServiceImpl<WmScorePackageMapper,
 		wmScorePackage.setPayScore(payScoreAndYsh.get("payScore"));
 		wmScorePackage.setYsh(payScoreAndYsh.get("ysh"));
 
+		// 封装报告状态
+		wmScorePackage.setReportMqName(CacheConstants.EXPORT_NBA_REPORT_CACHE);
+		getReportOpt(wmScorePackage);
 		return wmScorePackage;
 	}
+
+
+	/**
+	 * 查询报告导出状态
+	 *
+	 * @param wmScorePackage 列表
+	 */
+	@Override
+	public void getReportOpt(WmScorePackage wmScorePackage) {
+
+		WmReportOpt opt = new WmReportOpt();
+
+		// 获取生成记录
+		String key = String.format(wmScorePackage.getReportMqName(), wmScorePackage.getId());
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StrUtil.isNotEmpty(o)) {
+
+			// 生成中的
+			if ("GENERATING".equals(o)) {
+				opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATING);
+			}
+			// 生成失败的
+			else if (o.startsWith("ERROR")) {
+				opt.setStatus(WmReportOpt.WmReportOptStatus.ERROR);
+				opt.setErrorMsg(o.split(StrUtil.UNDERLINE)[1]);
+			}
+			// 成功的
+			else {
+				Long expire = redisTemplate.opsForValue().getOperations().getExpire(key, TimeUnit.SECONDS);
+				opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATED);
+				opt.setTtl(LocalDateTime.now().plusSeconds(expire));
+				// o = "https://pre.yaoyi.net/admin/sys-file/wmkj/兼职学术信息沟通专员业绩报告(2249)-20211116191527.doc";
+				opt.setLatestUrl(o);
+			}
+
+		} else {
+			opt.setStatus(WmReportOpt.WmReportOptStatus.NOT_GENERATE);
+		}
+
+
+		wmScorePackage.setReportOpt(opt);
+
+	}
 }