|
@@ -1,14 +1,22 @@
|
|
|
package com.qmth.themis.admin.api;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.reflect.TypeToken;
|
|
|
+import com.qmth.themis.business.bean.admin.NotifyBean;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.entity.TSBlackList;
|
|
|
import com.qmth.themis.business.entity.TSNotify;
|
|
|
+import com.qmth.themis.business.enums.UploadFileEnum;
|
|
|
import com.qmth.themis.business.service.TSNotifyService;
|
|
|
+import com.qmth.themis.business.service.ThemisCacheService;
|
|
|
+import com.qmth.themis.business.util.OssUtil;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
+import com.qmth.themis.common.util.GsonUtil;
|
|
|
import com.qmth.themis.common.util.Result;
|
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -19,6 +27,12 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.constraints.Max;
|
|
|
import javax.validation.constraints.Min;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
@@ -39,6 +53,12 @@ public class TSNotifyController {
|
|
|
@Resource
|
|
|
TSNotifyService tsNotifyService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ OssUtil ossUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ThemisCacheService themisCacheService;
|
|
|
+
|
|
|
@ApiOperation(value = "系统通知信息查询接口")
|
|
|
@RequestMapping(value = "/select", method = RequestMethod.POST)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "系统通知信息", response = TSBlackList.class)})
|
|
@@ -56,6 +76,7 @@ public class TSNotifyController {
|
|
|
return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
|
|
}
|
|
|
tsNotifyService.saveOrUpdate(tsNotify);
|
|
|
+ updateTsNotifyCache();
|
|
|
return ResultUtil.ok(true);
|
|
|
}
|
|
|
|
|
@@ -73,6 +94,38 @@ public class TSNotifyController {
|
|
|
|
|
|
tsNotify.setEnable(enable);
|
|
|
tsNotifyService.saveOrUpdate(tsNotify);
|
|
|
+ updateTsNotifyCache();
|
|
|
return ResultUtil.ok(true);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新缓存信息并写入json文件
|
|
|
+ *
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void updateTsNotifyCache() {
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ file = SystemConstant.getFileTempVar(SystemConstant.JSON_PREFIX);
|
|
|
+ List<TSNotify> tsNotifyList = themisCacheService.updateSysNotifyCache();
|
|
|
+ List<NotifyBean> notifyBeanList = GsonUtil.fromJson(GsonUtil.toJson(tsNotifyList), new TypeToken<List<NotifyBean>>() {
|
|
|
+ }.getType());
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("notifyList", notifyBeanList);
|
|
|
+ file = ossUtil.download(true, UploadFileEnum.client.name() + "/notifyList.json", file.getPath());
|
|
|
+ IOUtils.write(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(file));
|
|
|
+ ossUtil.upload(true, UploadFileEnum.client.name() + "/notifyList.json", file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(file)) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|