瀏覽代碼

feat: 新版报告导出-查询报告状态接口

lixuesong 1 年之前
父節點
當前提交
89919e7c19

+ 70 - 0
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/ReportExportController.java

@@ -36,6 +36,7 @@ import org.springframework.mail.javamail.MimeMessageHelper;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.mail.MessagingException;
@@ -724,4 +725,73 @@ public class ReportExportController {
 		return R.ok("开始导出,请耐心等待");
 	}
 
+	/**
+	 * 获取新版报告导出状态
+	 *
+	 * @param reportType 报告类型
+	 * @param packageId 积分包id
+	 * @return {@link WmReportOpt} 结果
+	 */
+	@GetMapping("/new-report-status")
+	public WmReportOpt getNewReportStatus(@RequestParam("reportType") ReportTypeEnum reportType,
+										  @RequestParam("id") String packageId) {
+		WmReportOpt opt = new WmReportOpt();
+
+		String reportCacheKey = null;
+		switch (reportType) {
+			case NEW_DRUG_ENT:
+				reportCacheKey = CacheConstants.NEW_DRUG_ENT_REPORT_CACHE;
+				break;
+			case NEW_PERSONAL:
+				reportCacheKey = CacheConstants.NEW_PERSONAL_REPORT_CACHE;
+				break;
+			case NEW_EXCEL_COMMON:
+				reportCacheKey = CacheConstants.NEW_EXCEL_COMMON_REPORT_CACHE;
+				break;
+			default:
+				reportCacheKey = CacheConstants.NEW_PERSONAL_REPORT_CACHE;
+		}
+
+		// 获取生成记录
+		String key = String.format(reportCacheKey, packageId);
+		String o = redisTemplate.opsForValue().get(key);
+
+		if (StrUtil.isNotEmpty(o)) {
+
+			if (StrUtil.contains(o, "https")) {
+				// 临时解决url 前出现的字符~
+				Long expire = redisTemplate.opsForValue().getOperations().getExpire(key, TimeUnit.SECONDS);
+				opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATED);
+				opt.setTtl(LocalDateTime.now().plusSeconds(expire));
+				opt.setLatestUrl(o.substring(o.indexOf("https")));
+			}
+			// 生成中的
+			else 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]);
+			}
+			// 生成失败的2
+			else if (!o.startsWith("http")) {
+				opt.setStatus(WmReportOpt.WmReportOptStatus.ERROR);
+				opt.setErrorMsg(o);
+			}
+			// 成功的
+			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);
+		}
+
+		return opt;
+	}
 }