|
@@ -0,0 +1,69 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysCommonExportService;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通用导出服务impl
|
|
|
+ *
|
|
|
+ * @author snows
|
|
|
+ * @date 2025/08/04
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class SysCommonExportServiceImpl implements SysCommonExportService {
|
|
|
+
|
|
|
+ private final RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出信息的结果
|
|
|
+ *
|
|
|
+ * @param user 用户
|
|
|
+ * @param redisKey Redis key
|
|
|
+ * @return {@link WmReportOpt } 状态和结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public WmReportOpt exportResult(HnqzUser user, String redisKey) {
|
|
|
+ String o = (String) redisTemplate.opsForValue().get(redisKey);
|
|
|
+ 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("/admin/sys-file")) {
|
|
|
+ opt.setStatus(WmReportOpt.WmReportOptStatus.ERROR);
|
|
|
+ opt.setErrorMsg(o);
|
|
|
+ }
|
|
|
+ // 成功的
|
|
|
+ else {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ Long expire = redisTemplate.opsForValue().getOperations().getExpire(redisKey, TimeUnit.SECONDS);
|
|
|
+ opt.setStatus(WmReportOpt.WmReportOptStatus.GENERATED);
|
|
|
+ opt.setTtl(expire != null ? now.plusSeconds(expire) : now);
|
|
|
+ opt.setLatestUrl(o);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ opt.setStatus(WmReportOpt.WmReportOptStatus.NOT_GENERATE);
|
|
|
+ }
|
|
|
+
|
|
|
+ return opt;
|
|
|
+ }
|
|
|
+}
|