main
黄海 1 year ago
parent ab9a73de5f
commit ab11267c42

@ -289,7 +289,7 @@ public class HuiYaController extends Controller {
@Before({POST.class})
@EmptyInterface({"token", "source_img_url"})
@IsNumericInterface({"model_id", "count"})
public void wxAddTask(String token, int model_id, String source_img_url, String images_md5, int prompt_id) throws Exception {
public void wxAddTask(String token, int model_id, String source_img_url, String images_md5, int prompt_id) {
if (prompt_id == 0) prompt_id = 1;
//验证token
Kv res = ym.checkToken(token);
@ -310,22 +310,25 @@ public class HuiYaController extends Controller {
}
//将上传的图片进行检测
/**
for (String s : source_img_url.split(",")) {
var ret = AliYunCheckImageUtil.Check(s);
if (ret.getConfidence() != null && ret.getConfidence() > 0) {
res.set("success", false);
res.set("message", "上传的图片中存在违反网络内容传播相关规定的内容,无法创建任务!");
renderJson(res);
return;
}
}*/
for (String s : source_img_url.split(",")) {
var ret = AliYunCheckImageUtil.Check(s);
if (ret.getConfidence() != null && ret.getConfidence() > 0) {
res.set("success", false);
res.set("message", "上传的图片中存在违反网络内容传播相关规定的内容,无法创建任务!");
renderJson(res);
return;
}
}*/
//记录到数据库中
var imgUrlList = source_img_url.split(",");
var md5List = images_md5.split(",");
for (int i = 0; i < imgUrlList.length; i++) {
ym.wxWriteImageMd5(md5List[i], imgUrlList[i]);
}
ym.wxAddTask(user_id, model_id, source_img_url, prompt_id);
int task_id = ym.wxAddTask(user_id, model_id, source_img_url, prompt_id);
//计算当前任务的可能完成时间
String finish_time = ym.wxGetCostTime(task_id);
res.put("finish_time", finish_time);
renderJson(res);
}

@ -15,6 +15,9 @@ import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.*;
public class HuiYaModel {
@ -99,7 +102,7 @@ public class HuiYaModel {
* @param prompt_id
* @param source_img_url
*/
public void wxAddTask(String user_id, int model_id, String source_img_url, int prompt_id) {
public int wxAddTask(String user_id, int model_id, String source_img_url, int prompt_id) {
if (prompt_id == 0) prompt_id = 1;
String sql = "select model_type_id from t_hy_model where model_id=?";
int model_type_id = Db.findFirst(sql, model_id).getInt("model_type_id");
@ -138,6 +141,8 @@ public class HuiYaModel {
//更新模型统计数据
sql = "update t_hy_model set img_count=img_count+1 where model_id=?";
Db.update(sql, model_id);
return task_id;
}
/**
@ -560,9 +565,70 @@ public class HuiYaModel {
/**
*
*
* @return
*/
public List<Record> wxGetCostTime() {
SqlPara sqlPara = Db.getSqlPara("HuiYa.wxGetCostTime");
public static List<Record> wxGetCostTimeList = new ArrayList<>();
public static DateTime wxGetCostTimeListBeginTime = DateTime.now();
public static Map<Integer, Integer> wxGetCostMap = new HashMap<>();
public Map<Integer, Integer> wxGetCostTimeMap() {
Duration duration = Duration.between((Temporal) DateTime.now(), (Temporal) wxGetCostTimeListBeginTime);
if (duration.getSeconds() > 60) {
wxGetCostTimeList.clear();
wxGetCostTimeListBeginTime = DateTime.now();
}
if (wxGetCostTimeList.size() == 0) {
SqlPara sqlPara = Db.getSqlPara("HuiYa.wxGetCostTime");
wxGetCostTimeList = Db.find(sqlPara);
wxGetCostTimeListBeginTime = DateTime.now();
wxGetCostTimeList.forEach(record -> {
int model_id = record.getInt("model_id");
int seconds_difference = record.getInt("seconds_difference");
wxGetCostMap.put(model_id, seconds_difference);
});
}
return wxGetCostMap;
}
public String wxGetCostTime(int task_id) {
//当前任务的model_id
Record r = Db.findById("t_hy_task", "task_id", task_id);
int model_id = r.getInt("model_id");
String sql = "select model_id from t_hy_task where task_id<? and finish_flag=0";
List<Record> list = Db.find(sql, task_id);
String res = "前面有" + list.size() + "个任务,预计完成时间:";
int secondsToAdd = 0;
for (int i = 0; i < list.size(); i++) {
Record record = list.get(i);
model_id = record.getInt("model_id");
int seconds_difference = 60;//如果前面的某个模型没有最后一次的执行耗时那么默认是1分钟
if (wxGetCostMap.containsKey(model_id)) {
seconds_difference = wxGetCostMap.get(model_id);
}
secondsToAdd += seconds_difference;
}
//再加上当前任务的生成时间
int current_task_seconds = 60;
if (wxGetCostMap.containsKey(model_id)) {
current_task_seconds = wxGetCostMap.get(model_id);
}
// 使用Duration来添加秒数
// 获取当前时间的Instant实例
Instant now = Instant.now();
Instant futureTime = now.plus(Duration.ofSeconds(secondsToAdd + current_task_seconds));
// 将Instant转换为特定时区的ZonedDateTime
ZonedDateTime zonedDateTime = futureTime.atZone(ZoneId.systemDefault());
// 转换为LocalDateTime
LocalDateTime localDateTime = zonedDateTime.toLocalDateTime();
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 格式化LocalDateTime
String formattedDateTime = localDateTime.format(formatter);
res = res + formattedDateTime;
return res;
}
}

Loading…
Cancel
Save