直接上代码:
package com.fh.util;
import org.apache.http.client.CookieStore;
import java.util.TimerTask;
/**
* Created by CP_xiawei on 2019/9/18.
*/
/**
* 定义自己的TimerTask
*/
public abstract class MyTimerTask extends TimerTask {
public String jid;
public CookieStore cookieStore;
public FlagStatusListener flagListener;
public boolean flag = false;
//定义构造方法
public MyTimerTask(String jid, CookieStore cookieStore,FlagStatusListener flagListener) {
super();
this.jid = jid;
this.cookieStore = cookieStore;
this.flagListener = flagListener;
}
}
================================================================
package com.fh.util;
/**
* Created by CP_xiawei on 2019/9/19.
*/
/**
* 定义监听器
*/
public interface FlagStatusListener {
public void flagValueChanged(boolean newFlag);
}
================================================================
package com.fh.service.AIModel.AIModel.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.service.AIModel.AIModel.AIModelManager;
import com.fh.service.aiparticiple.aiparticiple.AiParticipleManager;
import com.fh.util.*;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.nio.charset.Charset;
import java.util.*;
import static com.fh.controller.base.BaseController.logBefore;
/**
* 会话启动(调用接口api/exec/ensure)
* @return
* @throws Exception
*/
private String sessionStar(CookieStore cookieStore) throws Exception{
//获取定义的HttpClient对象
CloseableHttpClient client = null;
String url = Config.getConfig().getTagBatchUpdateSessionStarUrl();
if(null != cookieStore) {
try {
//获取定义的HttpClient对象
client = ByPassSSLUtils.getByPassSSLHttpClient(cookieStore);
HttpPost post = new HttpPost(url);
//构建Body
JSONObject jsonObject = new JSONObject();
jsonObject.put("groupId","default");
jsonObject.put("isGroup",true);
//构建消息实体
StringEntity entityStr = new StringEntity(jsonObject.toString(), Charset.forName("UTF-8"));
entityStr.setContentEncoding("UTF-8");
//发送Json格式的数据请求
entityStr.setContentType("application/json");
post.setEntity(entityStr);
//获取Response
CloseableHttpResponse response = client.execute(post);
try {
//获取请求实体
HttpEntity entity = response.getEntity();
if (entity != null) {
int code = response.getStatusLine().getStatusCode();
logger.info("返回状态码:" + code);
if (code == 200) {
//获取响应结果
String result = EntityUtils.toString(entity, Charset.forName("UTF-8"));
logger.info("获取返回结果:" + result);
return result;
} else {
return "fail";
}
} else {
return "fail";
}
} catch (Exception e) {
e.printStackTrace();
return "fail";
} finally {
response.close();
}
}catch(Exception e){
e.printStackTrace();
return "fail";
}finally {
client.close();
}
}else{
return "fail";
}
}
/**
* 启动运行实验
* @param jsonObject
* @param sessionId
* @param projectId
* @return
*/
private String submitTest(JSONObject jsonObject,String sessionId,String projectId,CookieStore cookieStore) throws Exception{
//定义必传参数
//CookieStore cookieStore = null;
//获取定义的HttpClient对象
CloseableHttpClient client = null;
String url = Config.getConfig().getSubmitTestUrl();
try {
//获取定义的HttpClient对象
client = ByPassSSLUtils.getByPassSSLHttpClient(cookieStore);
if(StringUtils.isNotBlank(sessionId) && StringUtils.isNotBlank(projectId)){
url = url+"?sessionId="+sessionId+"&pid="+projectId;
}
HttpPost post = new HttpPost(url);
//构建消息实体
StringEntity entityStr = new StringEntity(jsonObject.toString(), Charset.forName("UTF-8"));
entityStr.setContentEncoding("UTF-8");
//发送Json格式的数据请求
entityStr.setContentType("application/json");
post.setEntity(entityStr);
//获取Response
CloseableHttpResponse response = client.execute(post);
try {
//获取请求实体
HttpEntity entity = response.getEntity();
if (entity != null) {
int code = response.getStatusLine().getStatusCode();
logger.info("返回状态码:" + code);
if (code == 200) {
//获取响应结果
String result = EntityUtils.toString(entity, Charset.forName("UTF-8"));
logger.info("获取返回结果:" + result);
return result;
} else {
return "fail";
}
} else {
return "fail";
}
} catch (Exception e) {
e.printStackTrace();
return "fail";
} finally {
response.close();
}
}catch(Exception e){
e.printStackTrace();
return "fail";
}finally {
client.close();
}
}
/**
* 获取实验结果状态
* @param jid
* @param cookieStore
* @return
* @throws Exception
*/
@Override
public String getTestStatus(String jid,CookieStore cookieStore) throws Exception{
//获取定义的HttpClient对象
CloseableHttpClient client = ByPassSSLUtils.getByPassSSLHttpClient(cookieStore);
//URL
String url = Config.getConfig().getGetTestStatusUrl();
if(StringUtils.isNotBlank(url)){
url = url+"/"+jid;
}
try{
//GET请求
HttpGet get = new HttpGet(url);
CloseableHttpResponse response = client.execute(get);
try{
//获取请求实体
HttpEntity entity = response.getEntity();
if (entity != null) {
int code = response.getStatusLine().getStatusCode();
logger.info("返回状态码:" + code);
if (code == 200) {
nums++;
//获取响应结果
String result = EntityUtils.toString(entity, Charset.forName("UTF-8"));
//转换为对象
JSONObject reusltObject = JSONObject.parseObject(result);
reusltObject.put("nums",nums);
String resultStr = reusltObject.toJSONString();
return resultStr;
} else {
return "fail";
}
} else {
return "fail";
}
}catch (Exception e){
e.printStackTrace();
return "fail";
}finally {
response.close();
}
}catch (Exception e){
return "fail";
}finally {
client.close();
}
}
================================================================
/**
* 获取更新标签后的结果信息
* @return
* @throws Exception
*/
@Override
public String tagMsgUpdate() throws Exception {
String msg = "";
//查询分词表信息
List<PageData> lp = aiParticipleService.findAllList();
logger.info("lp的长度:"+lp.size());
//查询实验结果列表全部信息
List<PageData> labelResult = AIModelService.findAILabelAll();
logger.info("labelResult的长度:"+labelResult.size());
/**获取表AI_LABEL_BATCH_RESULT的标签信息,表头为标签名称,行记录为标签属性*/
if(labelResult.size() > 0) {
try {
//存第一行列字段信息
JSONArray reColumns = new JSONArray();
//存全部行记录
JSONArray reRows = new JSONArray();
//遍历实验结果列表
int n = 0;
for (PageData pdResult : labelResult) {
n++;
//存每一行记录
JSONArray rows = new JSONArray();
//对结果信息进行迭代
Iterator iter = pdResult.keySet().iterator();
while (iter.hasNext()) {
//获取键
String key = (String) iter.next();
if (n == 1) {
//保存标签(列字段key)
reColumns.add(key);
}
//获取值
Long value = (Long) pdResult.get(key);
//添加一个key对应的值
rows.add(value);
}
//添加一行记录
reRows.add(rows);
}
//测管(手工)平台非回归用例关系信息列表
List<PageData> relationCsglList = new ArrayList<PageData>();
//测管(手工)平台非回归用例ID信息列表
List<String> casesIdCsglList = new ArrayList<String>();
//测管(自动化)平台关系信息列表
List<PageData> relationZdhList = new ArrayList<PageData>();
//测管(自动化)平台用例ID信息列表
List<String> casesIdZdhList = new ArrayList<String>();
//测管(手工)平台关系信息列表
List<PageData> relationRegressList = new ArrayList<PageData>();
//测管(手工)平台用例ID信息列表
List<String> regressCasesIdRegressList = new ArrayList<String>();
//存实验所得标签全部标签信息
List<PageData> tagInfoList = new ArrayList <PageData>();
//存实验所得全部标签名称
List<String> countList = new ArrayList <String>();
for (int i = 0; i < lp.size(); i++) {
if(i == 0){
//1.获取实验所得标签的信息
List<PageData> contentList = new ArrayList<PageData>();
for (int j = 0; j < reColumns.size(); j++) {
PageData pdContent = new PageData();
pdContent.put("CONTENT", reColumns.getString(j));
contentList.add(pdContent);
}
//存为数组,批量查询
String[] contentArr = new String[contentList.size()];
for(int k =0; k < contentList.size(); k++){
contentArr[k] = contentList.get(k).getString("CONTENT");
}
//查询contentList中的标签
PageData contentPd = new PageData();
contentPd.put("array",contentArr);
contentPd.put("PROPERTY", "1");;
tagInfoList = (List<PageData>)dao.findForList("AIModelMapper.selectTagInfo", contentPd);
if (tagInfoList.size() > 0) {
try {
//获取contentList和tagInfoList中全部的不同元素
List <String> diffList = new ArrayList <String>();
if(contentList.size() != tagInfoList.size()){
diffList = CompareListUtil.getDiffrent(contentList, tagInfoList);
}
if (diffList.size() > 0) {
//保存这些不同的
List <PageData> tagList = new ArrayList <PageData>();
for (String difftag : diffList) {
PageData pdtag = new PageData();
pdtag.put("CONTENT", difftag);
pdtag.put("PROPERTY", "1");
pdtag.put("ISEFFECTIVE", "1");
tagList.add(pdtag);
}
//批量保存标签
AIModelService.batchSaveAITag(tagList);
}
}catch (Exception e){
e.printStackTrace();
msg = "error";
logger.info("标签保存异常:>>>>>>>>"+e);
}
}else{
//保存这些不同的
List <PageData> tagList = new ArrayList <PageData>();
for(int contSize = 0; contSize < contentArr.length; contSize++){
PageData pdtag = new PageData();
pdtag.put("CONTENT", contentArr[contSize]);
pdtag.put("PROPERTY", "1");
pdtag.put("ISEFFECTIVE", "1");
tagList.add(pdtag);
}
//批量保存标签
AIModelService.batchSaveAITag(tagList);
}
//获取实验所得标签全部标签信息
tagInfoList= (List<PageData>)dao.findForList("AIModelMapper.selectTagInfo", contentPd);
for(PageData tagInfo : tagInfoList){
countList.add(tagInfo.getString("CONTENT"));
}
}
//程序前面没有出现异常时执行
if(StringUtils.isEmpty(msg)) {
//区分是否是回归库用例
if (lp.get(i).containsKey("REGRESS_TAG") && "N".equals(lp.get(i).get("REGRESS_TAG") + "")) {
//区分是来自自动化的用例还是手工平台(测管平台)的用例
if ("FHADMINM".equals(lp.get(i).get("DATA_SOURCE"))) {
//保存要删除的AI标签用例关系信息
casesIdCsglList.add(lp.get(i).getString("CASES_ID"));
//获取并保存用例标签关系数据
for (int j = 0; j < reColumns.size(); j++) {
if (reRows.getJSONArray(i).getLong(j) != 0) {
PageData rp = new PageData();
rp.put("CASES_ID", lp.get(i).getString("CASES_ID"));
rp.put("PROJECT_ID",lp.get(i).getString("PROJECT_ID"));
//获取标签ID
if (countList.contains(reColumns.getString(j))) {
rp.put("ATTRIBUTE_ID", tagInfoList.get(j).get("ATTRIBUTE_ID"));
}
//添加到测管AI标签用例关系信息列表
relationCsglList.add(rp);
//达到4000条批量操作一次数据库
if (relationCsglList.size() == 4000) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
//将外层List拆成长度为1000的小List
for(int k =0; k < casesIdCsglList.size(); k++){
casesIdList.add(casesIdCsglList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelation(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelation(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
casesIdCsglList.clear();
//批量保存FHADMINM的标签关系信息
AIModelService.batchSaveRelation(relationCsglList);
//清空List
relationCsglList.clear();
}
}
}
} else if ("fyauto".equals(lp.get(i).get("DATA_SOURCE"))) {
//保存要删除的AI标签用例关系信息
casesIdZdhList.add(lp.get(i).getString("CASES_ID"));
//获取并保存用例标签关系数据
for (int j = 0; j < reColumns.size(); j++) {
if (reRows.getJSONArray(i).getLong(j) != 0) {
PageData rp = new PageData();
Integer casesId = Integer.parseInt(lp.get(i).getString("CASES_ID"));
rp.put("CASES_ID", casesId);
rp.put("SYSTEM_ID", lp.get(i).getString("SYSTEM_ID"));
//获取标签ID
if (countList.contains(reColumns.getString(j))) {
rp.put("ATTRIBUTE_ID", tagInfoList.get(j).get("ATTRIBUTE_ID"));
}
//添加到自动化AI标签用例关系信息列表
relationZdhList.add(rp);
//达到4000条批量操作一次数据库
if (relationZdhList.size() == 4000) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
//将外层List拆成长度为1000的小List
for(int k =0; k < casesIdZdhList.size(); k++){
casesIdList.add(casesIdZdhList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationZdh(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationZdh(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
casesIdZdhList.clear();
//批量保存fyauto的标签关系信息
AIModelService.batchSaveRelationZdh(relationZdhList);
//清空List
relationZdhList.clear();
}
}
}
}
} else if (lp.get(i).containsKey("REGRESS_TAG") && "Y".equals(lp.get(i).get("REGRESS_TAG") + "")) {
//保存要删除的AI标签用例关系信息
regressCasesIdRegressList.add(lp.get(i).getString("CASES_ID"));
//获取并保存用例标签关系数据
for (int j = 0; j < reColumns.size(); j++) {
if (reRows.getJSONArray(i).getLong(j) != 0) {
PageData rp = new PageData();
rp.put("REGRESS_CASES_ID", lp.get(i).getString("CASES_ID"));
rp.put("PROJECT_ID", lp.get(i).getString("PROJECT_ID"));
//获取标签ID
if (countList.contains(reColumns.getString(j))) {
rp.put("ATTRIBUTE_ID", tagInfoList.get(j).get("ATTRIBUTE_ID"));
}
//添加到测管回归库AI标签用例关系信息列表
relationRegressList.add(rp);
//达到4000条批量操作一次数据库
if (relationRegressList.size() == 4000) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
//将外层List拆成长度为1000的小List
for(int k =0; k < regressCasesIdRegressList.size(); k++){
casesIdList.add(regressCasesIdRegressList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationRegress(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationRegress(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
regressCasesIdRegressList.clear();
//批量保存fyauto的标签关系信息
AIModelService.batchSaveRelationRegress(relationRegressList);
//清空List
relationRegressList.clear();
}
}
}
}
}else{
break;
}
}
//程序前面没有出现异常时执行
if(StringUtils.isEmpty(msg)) {
/**全部循环完后,校验各用例信息List对象是否为空,如果不是,根据List的信息继续删除*/
if (casesIdCsglList.size() > 0) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
for(int k =0; k < casesIdCsglList.size(); k++){
casesIdList.add(casesIdCsglList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelation(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelation(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
casesIdCsglList.clear();
}
if (casesIdZdhList.size() > 0) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
//将外层List拆成长度为1000的小List
for(int k =0; k < casesIdZdhList.size(); k++){
casesIdList.add(casesIdZdhList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationZdh(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationZdh(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
casesIdZdhList.clear();
}
if (regressCasesIdRegressList.size() > 0) {
//存casesId
List<String> casesIdList = new ArrayList <String>();
//将外层List拆成长度为1000的小List
for(int k =0; k < regressCasesIdRegressList.size(); k++){
casesIdList.add(regressCasesIdRegressList.get(k));
if(casesIdList.size() == 1000) {
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationRegress(casesIdList);
//清空List
casesIdList.clear();
}
}
//继续删除
if(casesIdList.size() > 0){
//批量删除用例标签关系信息
AIModelService.batchDeleteRelationRegress(casesIdList);
//清空List
casesIdList.clear();
}
//清空List
regressCasesIdRegressList.clear();
}
/**全部循环完后,校验各用例标签关系List对象是否为空,如果不是,根据List的信息继续保存*/
if (relationCsglList.size() > 0) {
//批量保存FHADMINM的标签关系信息
AIModelService.batchSaveRelation(relationCsglList);
//清空List
relationCsglList.clear();
}
if (relationZdhList.size() > 0) {
//批量保存fyauto的标签关系信息
AIModelService.batchSaveRelationZdh(relationZdhList);
//清空List
relationZdhList.clear();
}
if (relationRegressList.size() > 0) {
//批量保存fyauto的标签关系信息
AIModelService.batchSaveRelationRegress(relationRegressList);
//清空List
relationRegressList.clear();
}
msg = "success";
}
}catch (Exception e){
e.printStackTrace();
msg = "error";
}
}else{
msg = "error";
}
return msg;
}
================================================================
/**
* 标签批处理启动
* @return
* @throws Exception
*/
private String tagUpdateStar() throws Exception{
/**1.调用接口启动批处理实验(对用例标签进行批量更新处理,并将处理后的数据存入表AI_LABEL_BATCH_RESULT)中。*/
//定义必传参数
CookieStore cookieStore = null;
String flag = "";
String jid = "";
try {
String username = Config.getConfig().getLineUserName();
String password = Config.getConfig().getLinePassword();
/**1)获取TGT(getTGT)*/
String TGT = getTGT(username, password);
logger.info("TGT: " + TGT);
if (StringUtils.isNotBlank(TGT)) {
/**2)获取ST(getST)*/
String ST = getST(TGT);
logger.info("ST: " + ST);
if (StringUtils.isNotBlank(ST)) {
/**3)获取cookie(getCookie)*/
cookieStore = getCookie(ST);
logger.info("cookieStore: " + cookieStore);
} else {
flag = "fail";
}
} else {
flag = "fail";
}
//初始化数据
PageData sypd = new PageData();
sypd.put("IS_SYNC", "INIT");
AIModelService.saveStatusResult(sypd);
/**4)会话启动(sessionStar)*/
String result = "";
JSONObject reusltObject = null;
String state = "";
//反复请求此接口,直到state变为idle或running
do{
//获取会话结果
result = sessionStar(cookieStore);
logger.info("sessionStar result:>>>>>>>>"+result);
reusltObject = JSONObject.parseObject(result);
//获取会话状态
state = reusltObject.getString("state");
}while(!"idle".equals(state) && !"running".equals(state));
/**5)启动运行实验(submitTest)*/
String submitResult = "";
//获取flow值
JSONObject flowJsonObject = batchFlowJsonObject;
//封装为JSON对象
JSONObject jsonObject = new JSONObject();
jsonObject.put("pid","a497e618-a809-4387-8143-6f1e9e2166a9");
jsonObject.put("flowName","AI_LABEL_BATCH_PREDICT");
jsonObject.put("username","");
//封装context
JSONObject job = new JSONObject();
job.put("projectId","a497e618-a809-4387-8143-6f1e9e2166a9");
job.put("path","AI_LABEL_BATCH_PREDICT/AI_LABEL_BATCH_PREDICT|LAB|AI_LABEL_BATCH_PREDICT");
jsonObject.put("context",job);
jsonObject.put("flow",flowJsonObject);
String id = reusltObject.getString("id");
if (!"fail".equals(id)) {
String sessionId = id;
String projectId = "a497e618-a809-4387-8143-6f1e9e2166a9";
//运行实验
submitResult = submitTest(jsonObject, sessionId, projectId, cookieStore);
logger.info("submitResult:>>>>>>>>" + submitResult);
//获取实验结果状态
JSONObject smtRstjsonObj = null;
if(StringUtils.isNotBlank(submitResult)){
smtRstjsonObj = JSONObject.parseObject(submitResult);
/**6)获取实验运行结果状态*/
jid = smtRstjsonObj.getString("id");
if(StringUtils.isNotBlank(jid)) {
try {
//创建定时器
final Timer timer = new Timer();
//获取监听器,并实现监听方法
FlagStatusListener flagListener = new FlagStatusListener() {
@Override
public void flagValueChanged(boolean newFlag) {
if (true == newFlag) {
//清除TimerTask中的任务
timer.purge();
//关闭Timer
timer.cancel();
}
}
};
//匿名内部类加载定时任务,并重写run方法
timer.schedule(new MyTimerTask(jid, cookieStore, flagListener) {
//异常信息
String exceptionInfo = "";
@Override
public void run() {
//定义状态结果
String statusResult = "";
try {
//获取状态结果
statusResult = AIModelService.getTestStatus(jid, cookieStore);
logger.info("测试状态结果:>>>>>>>>>"+statusResult);
} catch (Exception e) {
e.printStackTrace();
logger.info("轮训接口获取实验结果状态异常:",e);
//保存失败标记
exceptionInfo = "N";
//关闭任务
this.cancel();
//关闭定时器
flagListener.flagValueChanged(true);
} finally {
if(StringUtils.isEmpty(exceptionInfo)) {
try {
JSONObject stusResultObj = JSONObject.parseObject(statusResult);
String stateStr = stusResultObj.getString("state");
String metaStr = stusResultObj.getString("meta");
Integer nums = (Integer) stusResultObj.get("nums");
if (StringUtils.isNotBlank(stateStr) && StringUtils.isNotBlank(metaStr)) {
//第一遍保存一条记录
if (nums == 1) {
PageData staPd = new PageData();
staPd.put("IS_SYNC", "INIT");
//获取记录条数
Integer count = AIModelService.findByIsSyncCount();
if (count > 0) {
//全部删除
AIModelService.deleteByIsSync(staPd);
}
//每次同步只保存一次
AIModelService.saveStatusResult(staPd);
}
JSONObject stateObj = JSONObject.parseObject(stateStr);
JSONObject metaObj = JSONObject.parseObject(metaStr);
//获取状态值
String runState = stateObj.getString("state");
logger.info("状态码:>>>>>>>>" + runState);
//runState=SUCCEEDED表示:实验运行成功结束;
if ("SUCCEEDED".equals(runState)) {
//获取FLOW_NAME
String flowName = metaObj.getString("flowName");
//将上一次的记录设置为删除状态
PageData pdId = AIModelService.findNotInitMaxId();
PageData pid = new PageData();
Integer id;
if (null != pdId && !"INIT".equals(pdId.getString("IS_SYNC"))) {
id = (Integer) pdId.get("ID");
pid.put("ID", id);
pid.put("IS_DELETE", "1");
//标记为删除
AIModelService.updateIsDelete(pid);
}
//保存结果状态数据的对象
PageData pd = new PageData();
pd.put("FLOW_NAME", flowName);
pd.put("JID", jid);
pd.put("STATUS_RESULT", runState);
pd.put("IS_SYNC", "R");
try {
PageData pgId = AIModelService.findMaxId();
Integer maxid;
if (null != pgId) {
maxid = (Integer) pgId.get("ID");
pd.put("ID", maxid);
//保存实验状态结果
AIModelService.updateStatusResult(pd);
}
/**2.根据表中保存的状态信息更新或标记用例标签。(页面按钮的状态根据IS_SYNC字段变化)*/
PageData jidPd = new PageData();
jidPd.put("JID", jid);
PageData resultInfo = AIModelService.findByJID(jidPd);
if (null != resultInfo) {
String status = resultInfo.getString("STATUS_RESULT");
if ("SUCCEEDED".equals(status)) {
//开始更新标签信息
String flags = AIModelService.tagMsgUpdate();
if ("success".equals(flags)) {
Integer dbId = (Integer)resultInfo.get("ID");
try {
jidPd.put("ID",dbId);
jidPd.put("IS_SYNC", "Y");
AIModelService.updateIsSync(jidPd);
} catch (Exception e) {
e.printStackTrace();
logger.info("修改实验结果表信息时异常:", e);
//保存失败标记
exceptionInfo = "N";
}
} else {
//保存失败标记
exceptionInfo = "N";
//关闭任务
this.cancel();
//关闭定时器
flagListener.flagValueChanged(true);
}
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存实验状态结果异常:" + e);
//保存失败标记
exceptionInfo = "N";
} finally {
//关闭任务
this.cancel();
//关闭定时器
flagListener.flagValueChanged(true);
}
}
} else {
//保存失败标记
exceptionInfo = "N";
//关闭任务
this.cancel();
//关闭定时器
flagListener.flagValueChanged(true);
}
} catch (Exception e) {
e.printStackTrace();
logger.info("获取状态结果失败!" + e);
//保存失败标记
exceptionInfo = "N";
//关闭任务
this.cancel();
//关闭定时器
flagListener.flagValueChanged(true);
}
}
//如果异常信息不为空则保存
if(StringUtils.isNotBlank(exceptionInfo)){
try {
PageData pgMxId = AIModelService.findMaxId();
PageData synpd = new PageData();
if(null != pgMxId) {
Integer mId = (int)pgMxId.get("ID");
synpd.put("ID", mId);
synpd.put("IS_SYNC", "N");
AIModelService.updateIsSync(synpd);
}else{
synpd.put("IS_SYNC", "N");
AIModelService.saveStatusResult(synpd);
}
} catch (Exception e) {
e.printStackTrace();
logger.info("保存异常状态异常:" + e);
}
}
}
}
}, 1000, 5*60*1000);
}catch (Exception e){
e.printStackTrace();
logger.info("实现的定时器执行异常:",e);
flag = "fail";
}
}else{
flag = "fail";
}
}else{
flag = "fail";
}
}
}catch(Exception e){
logger.error("标签批处理启动失败!");
e.printStackTrace();
flag = "fail";
}finally {
if("fail".equals(flag)){
return "N";
}else{
//标签正在批量更新中
return "R";
}
}
}