|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|