|
|
package net.educoder.controller;
|
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.educoder.common.DingTalk;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Author: youys
|
|
|
* @Date: 2022/4/2
|
|
|
* @Description: 回调接口
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/callback")
|
|
|
public class CallbackController {
|
|
|
|
|
|
@Autowired
|
|
|
private DingTalk dingTalk;
|
|
|
|
|
|
private static final String RESULT = "success";
|
|
|
|
|
|
|
|
|
private final List<String> ERROR_MSG_LIST = Arrays.asList("系统繁忙,请稍后重试",
|
|
|
"程序执行失败导致评测提前终止,请稍后重试或联系系统管理员",
|
|
|
"本次评测网络延迟较高,资源无法正常加载,请10s后重试。",
|
|
|
"实验环境存在问题或已被回收,请保存数据再重置实训重新评测。",
|
|
|
"当前实验环境正在更新中,请稍后重试或联系系统管理员!",
|
|
|
"当前网络较差,代码下载超时,请稍后重试!",
|
|
|
"评测脚本设置异常,建议您在实训的配置页面重新选择或修改评测脚本"
|
|
|
);
|
|
|
|
|
|
@PostMapping("/evaluation")
|
|
|
public String evaluation(@RequestBody Map<String, Object> params) {
|
|
|
log.info("回调请求参数:{}", params);
|
|
|
|
|
|
if (params == null) {
|
|
|
return RESULT;
|
|
|
}
|
|
|
|
|
|
JSONObject jsonTestDetails = JSONObject.parseObject(params.get("jsonTestDetails").toString());
|
|
|
String outPut = jsonTestDetails.getString("outPut");
|
|
|
String tpiID = jsonTestDetails.getString("tpiID");
|
|
|
|
|
|
String decodeOutPut = Base64.decodeStr(outPut);
|
|
|
log.info("tpiID:{}, decodeOutPut:{}", tpiID, decodeOutPut);
|
|
|
if (match(decodeOutPut)) {
|
|
|
log.info("tpiID:{},需要发送钉钉通知", tpiID);
|
|
|
// 钉钉通知
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("【自动化评测】tpiID:").append(tpiID).append(" 错误:消息").append(decodeOutPut);
|
|
|
String result = dingTalk.sendMessage(sb.toString());
|
|
|
log.info("发送钉钉通知结果:{}", result);
|
|
|
}
|
|
|
|
|
|
return RESULT;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 匹配输出包含了错误.
|
|
|
*
|
|
|
* @param output
|
|
|
* @return
|
|
|
*/
|
|
|
private boolean match(String output) {
|
|
|
for (String s : ERROR_MSG_LIST) {
|
|
|
if (output.contains(s)) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
}
|