|
@@ -0,0 +1,279 @@
|
|
|
+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.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.service.ReportExportService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysDeptService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmReportService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmScorePackageService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmTaskService;
|
|
|
+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;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.mail.MessagingException;
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * excel报告导出
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/report/excel/export")
|
|
|
+@Api(value = "excelReportExport", tags = "导出管理模块")
|
|
|
+public class ExcelReportExportController {
|
|
|
+
|
|
|
+ private final RedisTemplate<String,String> redisTemplate;
|
|
|
+ private final RabbitMqClient rabbitMqClient;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算报告管理--导出汇总或详情
|
|
|
+ * @param wmReport
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/exportNbReport")
|
|
|
+ public R exportNbReport(WmReport wmReport ) throws IOException {
|
|
|
+
|
|
|
+
|
|
|
+ String key = String.format(CacheConstants.EXCEL_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("已有在途生成记录,能耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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/status")
|
|
|
+ public R exportZbReportStatus(WmTask wmTask) throws IOException {
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = String.format(CacheConstants.EXCEL_EXPORT_ZB_REPORT_CACHE, wmTask.getScorePackageDrugId());
|
|
|
+
|
|
|
+ String o = redisTemplate.opsForValue().get(key);
|
|
|
+ WmReportOpt opt = new WmReportOpt();
|
|
|
+
|
|
|
+ if (StringUtils.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]);
|
|
|
+ }
|
|
|
+ // 生成失败的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));
|
|
|
+ opt.setLatestUrl(o);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ opt.setStatus(WmReportOpt.WmReportOptStatus.NOT_GENERATE);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok(opt);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 个人报告导出--导出汇总或详情 汇总和详情合为一个模版
|
|
|
+ * @param wmTask
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/exportZbReport")
|
|
|
+ public R exportZbReport(WmTask wmTask) throws IOException {
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ String key = String.format(CacheConstants.EXCEL_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("已有在途生成记录,能耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HnqzUser user = SecurityUtils.getUser();
|
|
|
+ BaseMap map = new BaseMap();
|
|
|
+ map.put("requestBody", JSONUtil.toJsonStr(wmTask));
|
|
|
+ map.put("username",user.getUsername());
|
|
|
+ map.put("deptId",user.getDeptId());
|
|
|
+
|
|
|
+// SysDept dept = sysDeptService.getById(user.getDeptId());
|
|
|
+// map.put("isGuangshengtang", "913500007297027606".equals(dept.getTaxCode()));
|
|
|
+
|
|
|
+ rabbitMqClient.sendMessage(MqConstants.DIRECT_MODE_EXCEL_REPORT_EXPORT_ZB_QUEUE,map);
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
|
|
|
+ CacheConstants.DEF_REPORT_CREATING_TTL, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ return R.ok("开始导出,请耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 任务中心--导出汇总或详情
|
|
|
+ *
|
|
|
+ * @param wmScorePackage
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/exportNba")
|
|
|
+ public R<?> exportNba(WmScorePackage wmScorePackage) throws IOException {
|
|
|
+
|
|
|
+ String key = String.format(CacheConstants.EXCEL_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("已有在途生成记录,能耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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_EXCEL_REPORT_EXPORT_NBA_QUEUE,map);
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
|
|
|
+ CacheConstants.DEF_REPORT_CREATING_TTL , TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ return R.ok("开始导出,请耐心等待");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 历史数据导出报告
|
|
|
+ *
|
|
|
+ * @param wmScorePackage
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("/exportNbaHistory")
|
|
|
+ public R exportNbaHistory(WmScorePackage wmScorePackage) throws IOException {
|
|
|
+
|
|
|
+
|
|
|
+ String key = String.format(CacheConstants.EXCEL_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("已有在途生成记录,能耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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_EXCEL_REPORT_EXPORT_NBA_HISTORY_QUEUE,map);
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().set(key, WmReportOpt.WmReportOptStatus.GENERATING.name(),
|
|
|
+ CacheConstants.DEF_REPORT_CREATING_TTL,TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ return R.ok("开始导出,请耐心等待");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|