运维页面
This commit is contained in:
@@ -0,0 +1,86 @@
|
|||||||
|
package com.yunhai.bschclassmanage.controller.api;
|
||||||
|
|
||||||
|
import com.yunhai.bschclassmanage.config.Config;
|
||||||
|
import com.yunhai.bschclassmanage.controller.BaseController;
|
||||||
|
import com.yunhai.bschclassmanage.entity.SyncLog;
|
||||||
|
import com.yunhai.bschclassmanage.enums.UserType;
|
||||||
|
import com.yunhai.bschclassmanage.model.vo.PageVO;
|
||||||
|
import com.yunhai.bschclassmanage.service.ISyncLogService;
|
||||||
|
import com.yunhai.bschclassmanage.utils.UserContext;
|
||||||
|
import com.yunhai.platform.utils.exception.DException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Config.API_PATH + "/synclog/")
|
||||||
|
@CrossOrigin(originPatterns = {"*"}, allowCredentials = "true")
|
||||||
|
public class SyncLogController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISyncLogService syncLogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 超管校验:非超级管理员直接抛异常阻断(运维工作台仅超级管理员可访问)
|
||||||
|
*/
|
||||||
|
private void denyIfNotSuperAdmin() {
|
||||||
|
boolean isSuperAdmin = UserType.SUPER_ADMINISTRATOR.getId().equals(UserContext.getType());
|
||||||
|
if (!isSuperAdmin) {
|
||||||
|
throw new DException("无权限:仅超级管理员可访问同步日志");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 同步调用日志分页查询;schId 为"所选学校"筛选条件(非登录用户隔离),不传则查全部学校 */
|
||||||
|
@GetMapping("list")
|
||||||
|
public PageVO<SyncLog> list(
|
||||||
|
@RequestParam(required = false) Integer schId,
|
||||||
|
@RequestParam(required = false) String syncType,
|
||||||
|
@RequestParam(required = false) String syncTypeName,
|
||||||
|
@RequestParam(required = false) String classMethod,
|
||||||
|
@RequestParam(required = false) Integer status,
|
||||||
|
@RequestParam(required = false) String userName,
|
||||||
|
Pageable pageable) {
|
||||||
|
denyIfNotSuperAdmin();
|
||||||
|
return syncLogService.pageQuery(schId, syncType, syncTypeName,
|
||||||
|
classMethod, status, userName, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 下载某条同步日志原文(优先 jsonData,回退 errorMsg) */
|
||||||
|
@GetMapping("download/{id}")
|
||||||
|
public ResponseEntity<InputStreamResource> download(@PathVariable Long id) {
|
||||||
|
denyIfNotSuperAdmin();
|
||||||
|
String data = syncLogService.getDownloadData(id);
|
||||||
|
ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||||
|
try {
|
||||||
|
headers.add(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
|
"attachment; filename=" + new String(("sync-" + id + ".txt").getBytes("gbk"), "iso8859-1"));
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok().headers(headers)
|
||||||
|
.contentType(MediaType.parseMediaType("application/octet-stream"))
|
||||||
|
.body(new InputStreamResource(bis));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 重试某条同步/推送调用:按记录中的 classMethod + jsonData 反射重放原始操作 */
|
||||||
|
@PostMapping("retry/{id}")
|
||||||
|
public Map<String, Object> retry(@PathVariable Long id) {
|
||||||
|
denyIfNotSuperAdmin();
|
||||||
|
Object result = syncLogService.retry(id);
|
||||||
|
Map<String, Object> m = new LinkedHashMap<>();
|
||||||
|
m.put("success", true);
|
||||||
|
m.put("message", "重试已提交,执行结果见新增的同步日志");
|
||||||
|
if (result != null) m.put("data", result);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user