Skip to content

Commit

Permalink
Merge branch 'cherry-pick-958fa0a7' into 'release'
Browse files Browse the repository at this point in the history
修复index在H2数据时间毫秒保存的错误.

See merge request o2oa/o2oa!1357
  • Loading branch information
huqi1980 committed Jan 5, 2023
2 parents 1b71e25 + 9d6345b commit ac0faec
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ protected Response getOpenApi(HttpHeaders headers, ServletConfig config, Applica
.resourcePackages(resourcePackages).configLocation(configLocation)
.openApiConfiguration(openApiConfiguration).ctxId(ctxId).buildContext(true);
OpenAPI oas = ctx.read();
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println(XGsonBuilder.toJson(oas));
System.out.println(ctx.getOpenApiConfiguration().getReaderClass());
System.out.println(ctx.getOpenApiConfiguration().getScannerClass());
System.out.println(ctx.getOpenApiConfiguration().getUserDefinedOptions());
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// boolean pretty = false;
// if (ctx.getOpenApiConfiguration() != null
// && Boolean.TRUE.equals(ctx.getOpenApiConfiguration().isPrettyPrint())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ActionPublishAPK2Local extends BaseAction {

private static Logger logger = LoggerFactory.getLogger(ActionPublishAPK2Local.class);

ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
ActionResult<Wo> result = new ActionResult<>();

Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Expand Down Expand Up @@ -71,7 +71,7 @@ ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElemen
appPackApkFile.setAppVersionName(wi.getAppVersionName());
appPackApkFile.setIsPackAppIdOuter(wi.getIsPackAppIdOuter());
emc.check(appPackApkFile, CheckPersistType.all);
appPackApkFile.saveContent(mapping, new byte[]{}, fileName);
appPackApkFile.saveContent(mapping, new byte[] {}, fileName);
emc.beginTransaction(AppPackApkFile.class);
emc.persist(appPackApkFile);
emc.commit();
Expand All @@ -90,7 +90,6 @@ ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElemen
return result;
}


public class DownloadJob extends Thread {
private Wi wi;
private String id;
Expand All @@ -109,7 +108,7 @@ public void run() {
throw new ExceptionAllocateStorageMapping();
}
String url = Config.collect().appPackServerUrl() + wi.getApkPath() + "?token=" + wi.getToken();
logger.info("下载apk的url: "+url);
logger.info("下载apk的url: " + url);
byte[] bytes = ConnectionAction.getBinary(url, null);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
AppPackApkFile file = emc.find(this.id, AppPackApkFile.class);
Expand All @@ -120,19 +119,20 @@ public void run() {
file.setLastUpdateTime(new Date());
emc.commit();
// 发布成功了,需要修改jpush配置文件,把outer包的key配置上去
if (StringUtils.isNotBlank(file.getIsPackAppIdOuter()) && "2".equals(file.getIsPackAppIdOuter())) {
if (StringUtils.isNotBlank(file.getIsPackAppIdOuter())
&& "2".equals(file.getIsPackAppIdOuter())) {
updateJpushConfig();
}
updateAppUrl(wi.getWebUrl());
logger.info("下载发布apk成功。。。。。。");
} else {
logger.error(new Exception("错误,没有找到对应的文件对象,id:"+id));
logger.error(new Exception("错误,没有找到对应的文件对象,id:" + id));
}
}

} catch (Exception e) {
logger.error(e);
logger.info("下载失败,更新错误状态!!!!");
logger.info("下载失败,更新错误状态.");
try {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
AppPackApkFile file = emc.find(this.id, AppPackApkFile.class);
Expand All @@ -142,10 +142,10 @@ public void run() {
file.setLastUpdateTime(new Date());
emc.commit();
} else {
logger.error(new Exception("错误,没有找到对应的文件对象,id:"+id));
logger.error(new IllegalStateException("错误,没有找到对应的文件对象,id:" + id + "."));
}
}
}catch (Exception e1) {
} catch (Exception e1) {
logger.error(e1);
}
}
Expand All @@ -156,18 +156,17 @@ private void updateJpushConfig() {
logger.info("开始修改jpush文件.......");
JpushConfig newConfig = JpushConfig.defaultInstance().getOuterApplicationJpushConfig();
updateConfigFileOnLine(Config.NAME_CONFIG_JPUSH, newConfig.toString());
}catch (Exception e) {
} catch (Exception e) {
logger.error(e);
}
}


/**
* 更新appUrl collect.json配置文件 登录界面扫码可以下载
*/
private void updateAppUrl(String webUrl) {
try {
logger.info("updateAppUrl : "+webUrl);
logger.info("updateAppUrl : " + webUrl);
if (StringUtils.isNotEmpty(webUrl)) {
String myUrl = webUrl;
String protocol = Config.nodes().centerServers().first().getValue().getHttpProtocol();
Expand All @@ -183,26 +182,26 @@ private void updateAppUrl(String webUrl) {
}
}
if (StringUtils.isNotEmpty(webProxyHost)) {
String url = protocol + ":https://" +webProxyHost + ":" +webProxyPort;
String url = protocol + ":https://" + webProxyHost + ":" + webProxyPort;
if (!url.equals(webUrl)) {
myUrl = url;
}
}
logger.info("最后的URL :" + myUrl);
Config.collect().setAppUrl(myUrl+ "/x_desktop/appDownload.html");
updateConfigFileOnLine(Config.NAME_CONFIG_COLLECT, Config.collect().toString());
Config.collect().setAppUrl(myUrl + "/x_desktop/appDownload.html");
updateConfigFileOnLine(Config.NAME_CONFIG_COLLECT, Config.collect().toString());
}

}catch (Exception e) {
} catch (Exception e) {
logger.error(e);
}
}


/**
* 更新配置文件
*
* @param fileName 配置文件名称 如 jpushConfig.json
* @param content 配置文件内容 json
* @param content 配置文件内容 json
* @throws Exception
*/
private void updateConfigFileOnLine(String fileName, String content) throws Exception {
Expand All @@ -212,14 +211,15 @@ private void updateConfigFileOnLine(String fileName, String content) throws Exce
JPushConfigSaveWi wi = new JPushConfigSaveWi();
wi.setFileName(fileName);
wi.setFileContent(content);
ActionResponse response = CipherConnectionAction.post(false, Config.url_x_program_center_jaxrs("config", "save") ,wi);
ActionResponse response = CipherConnectionAction.post(false,
Config.url_x_program_center_jaxrs("config", "save"), wi);
if (response != null) {
ActionSave.Wo wo = response.getData(ActionSave.Wo.class);
if (wo != null && wo.getStatus() != null) {
logger.info("修改保存["+fileName+"]配置文件成功!");
logger.info("修改保存[" + fileName + "]配置文件成功!");
}
} else {
logger.info("保存["+fileName+"]配置文件 返回为空!!");
logger.info("保存[" + fileName + "]配置文件 返回为空!!");
}
}
}
Expand Down Expand Up @@ -264,7 +264,6 @@ public static class Wi extends GsonPropertyObject {
@FieldDescribe("前端web地址,如 https://dd.o2oa.net")
private String webUrl;


public String getWebUrl() {
return webUrl;
}
Expand Down Expand Up @@ -322,7 +321,6 @@ public void setIsPackAppIdOuter(String isPackAppIdOuter) {
}
}


public static class Wo extends WrapBoolean {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.x.query.service.processing.schedulelocal.LowFreqDocumentLocal;
import com.x.query.service.processing.schedulelocal.LowFreqWorkCompletedLocal;
import com.x.query.service.processing.schedulelocal.LowFreqWorkLocal;
import com.x.query.service.processing.schedulelocal.OptimizeIndexLocal;

public class ThisApplication {

Expand Down Expand Up @@ -105,10 +106,10 @@ private static void scheduleLowFreqWork() throws Exception {
if (BooleanUtils.isTrue(Config.query().index().getLowFreqWorkEnable())) {
if (StringUtils.equals(Config.query().index().getMode(), Query.Index.MODE_LOCALDIRECTORY)) {
context.scheduleLocal(LowFreqWorkLocal.class,
Config.query().index().getLowFreqWorkCompletedCron());
Config.query().index().getLowFreqWorkCron());
} else {
context.schedule(LowFreqWork.class,
Config.query().index().getLowFreqWorkCompletedCron());
Config.query().index().getLowFreqWorkCron());
}
}
}
Expand Down Expand Up @@ -144,15 +145,15 @@ private static void scheduleHighFreqWork() throws Exception {
Config.query().index().getHighFreqWorkCron());
} else {
context.schedule(HighFreqWork.class,
Config.query().index().getHighFreqWorkCompletedCron());
Config.query().index().getHighFreqWorkCron());
}
}
}

private static void scheduleOptimizeIndex() throws Exception {
if (BooleanUtils.isTrue(Config.query().index().getOptimizeIndexEnable())) {
if (StringUtils.equals(Config.query().index().getMode(), Query.Index.MODE_LOCALDIRECTORY)) {
context.scheduleLocal(OptimizeIndex.class,
context.scheduleLocal(OptimizeIndexLocal.class,
Config.query().index().getOptimizeIndexCron());
} else {
context.schedule(OptimizeIndex.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ protected <T extends JpaObject> List<T> list(State state, Class<T> clazz, int si
if (!Objects.isNull(state.getLatestUpdateTime())) {
Date latestTime = DateUtils.truncate(state.getLatestUpdateTime(), Calendar.SECOND);
p = cb.greaterThanOrEqualTo(root.get(JpaObject_.createTime), latestTime);
p = cb.and(p, cb.not(cb.and(cb.equal(root.get(JpaObject_.createTime), latestTime),
root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList()))));
// p = cb.and(p, cb.not(cb.and(cb.equal(root.get(JpaObject_.createTime), latestTime),
// root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList()))));
p = cb.and(p, cb.not(root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList())));
}
cq.select(root).where(p).orderBy(cb.asc(root.get(JpaObject_.createTime)));
LOGGER.debug("freqWork qurey sql:{}.", cq.toString());
LOGGER.debug("freq list qurey sql:{}.", cq.toString());
return em.createQuery(cq).setMaxResults(size).getResultList();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ protected <T extends JpaObject> List<Pair<String, Date>> list(State state, Class
if (!Objects.isNull(state.getLatestUpdateTime())) {
Date latestTime = DateUtils.truncate(state.getLatestUpdateTime(), Calendar.SECOND);
p = cb.greaterThanOrEqualTo(root.get(JpaObject_.createTime), latestTime);
p = cb.and(p, cb.not(cb.and(cb.equal(root.get(JpaObject_.createTime), latestTime),
root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList()))));
// p = cb.and(p, cb.not(cb.and(cb.equal(root.get(JpaObject_.createTime), latestTime),
// root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList()))));
p = cb.and(p, cb.not(root.get(JpaObject.id_FIELDNAME).in(state.getLatestIdList())));
} else {
p = cb.conjunction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import org.apache.commons.lang3.time.DateUtils;
import org.quartz.JobExecutionContext;

import com.google.gson.Gson;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.bean.tuple.Pair;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.gson.XGsonBuilder;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DateTools;
Expand Down Expand Up @@ -55,7 +57,7 @@ public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
delete(list, deleteCount);
Optional<Map.Entry<Date, List<Pair<String, Date>>>> optional = list.stream()
.map(o -> Pair.of(o.getId(), DateUtils.truncate(o.getCreateTime(), Calendar.SECOND)))
.collect(Collectors.groupingBy(o -> DateUtils.truncate(o.second(), Calendar.SECOND)))
.collect(Collectors.groupingBy(Pair::second))
.entrySet().stream()
.max(Comparator.comparingLong(o -> o.getKey().getTime()));
if (optional.isPresent()) {
Expand Down

0 comments on commit ac0faec

Please sign in to comment.