Commit 1db53a35 by liuyu

2024/07/09 老乡鸡ai标注接入。ai统计添加项目信息。标签命中添加前提条件。

parent 1bbabd3d
...@@ -18,6 +18,11 @@ public class AIMark implements Serializable { ...@@ -18,6 +18,11 @@ public class AIMark implements Serializable {
* 分层id * 分层id
*/ */
private Integer monitorLevelId; private Integer monitorLevelId;
private List<Integer> monitorLevelIds;
private String type;
/** /**
* 接口信息 * 接口信息
*/ */
...@@ -83,6 +88,22 @@ public class AIMark implements Serializable { ...@@ -83,6 +88,22 @@ public class AIMark implements Serializable {
this.projectId = projectId; this.projectId = projectId;
} }
public List<Integer> getMonitorLevelIds() {
return monitorLevelIds;
}
public void setMonitorLevelIds(List<Integer> monitorLevelIds) {
this.monitorLevelIds = monitorLevelIds;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public static class TagRelation implements Serializable { public static class TagRelation implements Serializable {
/**标签id*/ /**标签id*/
private Long id; private Long id;
...@@ -99,6 +120,27 @@ public class AIMark implements Serializable { ...@@ -99,6 +120,27 @@ public class AIMark implements Serializable {
/**标签关联value*/ /**标签关联value*/
private String relateValue; private String relateValue;
/***是否包含前提条件*/
private Boolean hasRequirements;
/**前提条件*/
private List<Requirement> requirements;
public Boolean getHasRequirements() {
return hasRequirements;
}
public void setHasRequirements(Boolean hasRequirements) {
this.hasRequirements = hasRequirements;
}
public List<Requirement> getRequirements() {
return requirements;
}
public void setRequirements(List<Requirement> requirements) {
this.requirements = requirements;
}
public Long getId() { public Long getId() {
return id; return id;
} }
...@@ -156,6 +198,28 @@ public class AIMark implements Serializable { ...@@ -156,6 +198,28 @@ public class AIMark implements Serializable {
} }
} }
public static class Requirement implements Serializable {
private String requirementKey;
private String requirementValue;
public String getRequirementKey() {
return requirementKey;
}
public void setRequirementKey(String requirementKey) {
this.requirementKey = requirementKey;
}
public String getRequirementValue() {
return requirementValue;
}
public void setRequirementValue(String requirementValue) {
this.requirementValue = requirementValue;
}
}
public static class InterfaceRelation implements Serializable { public static class InterfaceRelation implements Serializable {
/** 接口地址*/ /** 接口地址*/
private String url; private String url;
......
...@@ -16,10 +16,30 @@ public class AiApiResult { ...@@ -16,10 +16,30 @@ public class AiApiResult {
private String noise; private String noise;
private String negLabel;
private String project;
private String result; private String result;
private Long createAt; private Long createAt;
public String getNegLabel() {
return negLabel;
}
public void setNegLabel(String negLabel) {
this.negLabel = negLabel;
}
public String getProject() {
return project;
}
public void setProject(String project) {
this.project = project;
}
public String getId() { public String getId() {
return id; return id;
} }
......
package com.zhiwei.middleware.automatic.server.pojo.enums;
/**
* author:liu-yu
* date: 2024/7/9 10:03
**/
public enum AiInterfaceEnums {
FEI_HE("飞鹤", "62baa19f4d9a553ac3e7cd9b", "feihe-compet-tagger"),
LAO_XIANG_JI("老乡鸡", "665d8791b36dd11c5e453955", "laoxiangji-tagger");
final String project;
final String projectId;
final String waitFor;
AiInterfaceEnums(String project, String projectId, String waitFor) {
this.project = project;
this.projectId = projectId;
this.waitFor = waitFor;
}
public String getProject() {
return project;
}
public String getProjectId() {
return projectId;
}
public String getWaitFor() {
return waitFor;
}
public static AiInterfaceEnums create(String projectId) {
for (AiInterfaceEnums enums : AiInterfaceEnums.values()) {
if (enums.getProjectId().equals(projectId)) {
return enums;
}
}
throw new IllegalStateException("该项目不支持ai标注:" + projectId);
}
}
...@@ -3,6 +3,7 @@ package com.zhiwei.middleware.automatic.server.mission; ...@@ -3,6 +3,7 @@ package com.zhiwei.middleware.automatic.server.mission;
import com.zhiwei.middleware.automatic.server.common.GenericAttribute; import com.zhiwei.middleware.automatic.server.common.GenericAttribute;
import com.zhiwei.middleware.automatic.server.dao.AiMarkCountDao; import com.zhiwei.middleware.automatic.server.dao.AiMarkCountDao;
import com.zhiwei.middleware.automatic.server.pojo.AiMarkCount; import com.zhiwei.middleware.automatic.server.pojo.AiMarkCount;
import com.zhiwei.middleware.automatic.server.pojo.enums.AiInterfaceEnums;
import com.zhiwei.middleware.automatic.server.util.RedissonUtil; import com.zhiwei.middleware.automatic.server.util.RedissonUtil;
import com.zhiwei.middleware.automatic.server.util.TimeUtil; import com.zhiwei.middleware.automatic.server.util.TimeUtil;
import com.zhiwei.middleware.automatic.server.util.Tools; import com.zhiwei.middleware.automatic.server.util.Tools;
...@@ -59,13 +60,16 @@ public class AsyncTask { ...@@ -59,13 +60,16 @@ public class AsyncTask {
public void syncDayCount() { public void syncDayCount() {
String timeKey = TimeUtil.COMMON_TIME_FORMAT.format(System.currentTimeMillis() - GenericAttribute.DAY_TIME); String timeKey = TimeUtil.COMMON_TIME_FORMAT.format(System.currentTimeMillis() - GenericAttribute.DAY_TIME);
for (AiInterfaceEnums enums : AiInterfaceEnums.values()) {
AiMarkCount aiMarkCount = new AiMarkCount(); AiMarkCount aiMarkCount = new AiMarkCount();
aiMarkCount.setTime(timeKey); aiMarkCount.setTime(timeKey);
aiMarkCount.setTotal(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, GenericAttribute.KEY_TOTAL))); aiMarkCount.setTotal(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, enums.getProject(), GenericAttribute.KEY_TOTAL)));
aiMarkCount.setResError(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, GenericAttribute.KEY_RES_ERROR))); aiMarkCount.setResError(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, enums.getProject(), GenericAttribute.KEY_RES_ERROR)));
aiMarkCount.setResIncomplete(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, GenericAttribute.KEY_RES_INCOMPLETE))); aiMarkCount.setResIncomplete(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, enums.getProject(), GenericAttribute.KEY_RES_INCOMPLETE)));
aiMarkCount.setNotMarkRelation(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, GenericAttribute.KEY_NOT_MARK_RELATION))); aiMarkCount.setNotMarkRelation(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, enums.getProject(), GenericAttribute.KEY_NOT_MARK_RELATION)));
aiMarkCount.setSuccess(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, GenericAttribute.KEY_SUCCESS))); aiMarkCount.setSuccess(redissonUtil.getCount(Tools.assembleKey(GenericAttribute.KEY_AI, timeKey, enums.getProject(), GenericAttribute.KEY_SUCCESS)));
aiMarkCountDao.insert(aiMarkCount); aiMarkCountDao.insert(aiMarkCount);
} }
}
} }
package com.zhiwei.middleware.automatic.son.task.aiTask;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.base.entity.subclass.mark.MarkInfo;
import com.zhiwei.middleware.automatic.server.pojo.AiApiResult;
import com.zhiwei.middleware.automatic.server.pojo.AiInterfaceParam;
import com.zhiwei.middleware.automatic.server.pojo.enums.AiInterfaceEnums;
import java.util.Map;
/**
* author:liu-yu
* date: 2024/7/9 10:46
**/
public interface AiTaskService {
AiInterfaceEnums getType();
MarkInfo executor(AiInterfaceParam aiParam, String timeKey);
/**
* 构建请求参数 (metadata)
* @param aiParam aiParam
* @return 请求参数
*/
JSONObject httpParamByMetadata(AiInterfaceParam aiParam);
/**
* 接口请求
* @param httpType 请求类型
* @param url url
* @param header header
* @return 接口返回值
*/
String httpResult(String httpType, String url, String paramInfo, Map<String, Object> header);
/**
* 接口返回值转换
* @param interfaceRes 接口返回值
* @return AiApiResult
*/
AiApiResult aiApiResultConversion(String interfaceRes);
void requestMarkTotalCount(String timeKey);
void requestErrorCount(String timeKey);
void requestResIncomplete(String timeKey);
void markNotRelation(String timeKey);
void markSuccess(String timeKey);
}
package com.zhiwei.middleware.automatic.son.task.aiTask;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.middleware.automatic.server.pojo.AiInterfaceParam;
import com.zhiwei.middleware.automatic.server.pojo.enums.AiInterfaceEnums;
import com.zhiwei.middleware.automatic.server.util.RedissonUtil;
import com.zhiwei.middleware.automatic.son.dao.AiApiResultDao;
import org.springframework.stereotype.Service;
/**
* author:liu-yu
* date: 2024/7/9 14:16
**/
@Service
public class AiTaskServiceFeiHe extends AbstractAiTaskService {
public AiTaskServiceFeiHe(RedissonUtil redissonUtil, AiApiResultDao aiApiResultDao) {
super(AiInterfaceEnums.FEI_HE, redissonUtil, aiApiResultDao);
}
@Override
public JSONObject httpParamByMetadata(AiInterfaceParam aiParam) {
JSONObject metadata = new JSONObject();
metadata.put("product", aiParam.getAiMark().getInterfaceRelation().getProduct());
metadata.put("platform", aiParam.getPt());
metadata.put("platform_category", aiParam.getPt());
return metadata;
}
}
package com.zhiwei.middleware.automatic.son.task.aiTask;
import com.zhiwei.base.entity.subclass.mark.MarkInfo;
import com.zhiwei.middleware.automatic.server.pojo.AiInterfaceParam;
import com.zhiwei.middleware.automatic.son.task.holder.ApplicationContextHolder;
import java.util.HashMap;
import java.util.Map;
/**
* author:liu-yu
* date: 2024/7/9 14:20
**/
public class AiTaskServiceHandler {
private static final Map<String, AiTaskService> SERVICE_MAP = new HashMap<>();
private AiTaskServiceHandler() {
Map<String, AiTaskService> beansOfType = ApplicationContextHolder.getInstance().getBeansOfType(AiTaskService.class);
beansOfType.forEach((k, v) -> SERVICE_MAP.put(v.getType().getProjectId(), v));
}
public static AiTaskServiceHandler getInstance() {
return AiTaskServiceHandlerHolder.HANDLER;
}
public MarkInfo sendAIRequest(AiInterfaceParam aiParam, String timeKey) {
return SERVICE_MAP.get(aiParam.getAiMark().getProjectId()).executor(aiParam, timeKey);
}
private static class AiTaskServiceHandlerHolder {
private static final AiTaskServiceHandler HANDLER = new AiTaskServiceHandler();
}
}
package com.zhiwei.middleware.automatic.son.task.aiTask;
import com.alibaba.fastjson.JSONObject;
import com.zhiwei.middleware.automatic.server.pojo.AiInterfaceParam;
import com.zhiwei.middleware.automatic.server.pojo.enums.AiInterfaceEnums;
import com.zhiwei.middleware.automatic.server.util.RedissonUtil;
import com.zhiwei.middleware.automatic.son.dao.AiApiResultDao;
import org.springframework.stereotype.Service;
/**
* author:liu-yu
* date: 2024/7/9 14:19
**/
@Service
public class AiTaskServiceLXJ extends AbstractAiTaskService {
public AiTaskServiceLXJ(RedissonUtil redissonUtil, AiApiResultDao aiApiResultDao) {
super(AiInterfaceEnums.LAO_XIANG_JI, redissonUtil, aiApiResultDao);
}
@Override
public JSONObject httpParamByMetadata(AiInterfaceParam aiParam) {
return null;
}
}
...@@ -18,9 +18,17 @@ public class OkHttpUtil { ...@@ -18,9 +18,17 @@ public class OkHttpUtil {
public static String httpPut(String url, String info, Map<String, Object> header) { public static String httpPut(String url, String info, Map<String, Object> header) {
Request.Builder builder = new Request.Builder().url(url).put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), info)); Request.Builder builder = new Request.Builder().url(url).put(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), info));
for (Map.Entry<String, Object> entry : header.entrySet()) { builderHeader(builder, header);
builder.addHeader(entry.getKey(), String.valueOf(entry.getValue())); try (Response response = okHttpClient.newCall(builder.build()).execute()) {
return response.body().string();
} catch (Exception e) {
return null;
}
} }
public static String httpPost(String url, String info, Map<String, Object> header) {
Request.Builder builder = new Request.Builder().url(url).post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), info));
builderHeader(builder, header);
try (Response response = okHttpClient.newCall(builder.build()).execute()) { try (Response response = okHttpClient.newCall(builder.build()).execute()) {
return response.body().string(); return response.body().string();
} catch (Exception e) { } catch (Exception e) {
...@@ -28,4 +36,10 @@ public class OkHttpUtil { ...@@ -28,4 +36,10 @@ public class OkHttpUtil {
} }
} }
private static void builderHeader(Request.Builder builder, Map<String, Object> header) {
for (Map.Entry<String, Object> entry : header.entrySet()) {
builder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment