提交 c86d8e4f 编写于 作者: O o2sword

新版应用市场开发3

上级 1705a242
......@@ -4,6 +4,7 @@ import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.enums.CommonStatus;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
......@@ -56,6 +57,7 @@ class ActionInstallOffline extends BaseAction {
emc.persist(installLog);
}
emc.commit();
CacheManager.notify(InstallLog.class);
}
result.setData(wo);
......
......@@ -5,6 +5,7 @@ import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.enums.CommonStatus;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Collect;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
......@@ -82,6 +83,7 @@ class ActionInstallOrUpdate extends BaseAction {
emc.persist(installLog);
}
emc.commit();
CacheManager.notify(InstallLog.class);
}
result.setData(wo);
......
package com.x.program.center.jaxrs.market;
import com.google.gson.JsonObject;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.enums.CommonStatus;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Collect;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.program.center.Business;
import com.x.program.center.core.entity.InstallLog;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
class ActionListByCategoryPaging extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionListByCategoryPaging.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size, String category)
throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Cache.CacheKey cacheKey = new Cache.CacheKey(ActionListByCategoryPaging.class, page, size, category);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
wos = (List<Wo>) optional.get();
} else {
String token = Business.loginCollect();
if (StringUtils.isNotEmpty(token)) {
try {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("orderBy", "createTime");
jsonObject.addProperty("isAsc", Boolean.FALSE);
if(!EMPTY_SYMBOL.equals(category)){
jsonObject.addProperty("category", category);
}
jsonObject.addProperty("status", "publish");
String url = StringUtils.replaceEach(COLLECT_MARKET_LIST_INFO, new String[]{"{page}", "{size}"},
new String[]{String.valueOf(page), String.valueOf(size)});
ActionResponse response = ConnectionAction.post(
Config.collect().url(url),
ListTools.toList(new NameValuePair(Collect.COLLECT_TOKEN, token)), jsonObject);
wos = response.getDataAsList(Wo.class);
result.setCount(response.getCount());
} catch (Exception e) {
logger.warn("list market form o2cloud error: {}.", e.getMessage());
}
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
for (Wo wo : wos) {
InstallLog installLog = emc.find(wo.getId(), InstallLog.class);
if (installLog != null && CommonStatus.VALID.getValue().equals(installLog.getStatus())) {
wo.setInstalledVersion(installLog.getVersion());
} else {
wo.setInstalledVersion("");
}
}
}
if(ListTools.isNotEmpty(wos)){
CacheManager.put(cacheCategory, cacheKey, wos);
}
}
result.setData(wos);
return result;
}
public static class Wo extends Application2 {
@FieldDescribe("已安装的版本,空表示未安装")
private String installedVersion;
public String getInstalledVersion() {
return installedVersion;
}
public void setInstalledVersion(String installedVersion) {
this.installedVersion = installedVersion;
}
}
}
package com.x.program.center.jaxrs.market;
import com.google.gson.JsonObject;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.enums.CommonStatus;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.bean.NameValuePair;
import com.x.base.core.project.cache.Cache;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Collect;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.connection.ActionResponse;
import com.x.base.core.project.connection.ConnectionAction;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.program.center.Business;
import com.x.program.center.core.entity.InstallLog;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
class ActionTopThree extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionTopThree.class);
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
ActionResult<List<Wo>> result = new ActionResult<>();
List<Wo> wos = new ArrayList<>();
Cache.CacheKey cacheKey = new Cache.CacheKey(ActionTopThree.class);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
wos = (List<Wo>) optional.get();
} else {
String token = Business.loginCollect();
if (StringUtils.isNotEmpty(token)) {
try {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("orderBy", "recommend");
jsonObject.addProperty("isAsc", Boolean.TRUE);
jsonObject.addProperty("status", "publish");
String url = StringUtils.replaceEach(COLLECT_MARKET_LIST_INFO, new String[]{"{page}", "{size}"},
new String[]{"1", "3"});
ActionResponse response = ConnectionAction.post(
Config.collect().url(url),
ListTools.toList(new NameValuePair(Collect.COLLECT_TOKEN, token)), jsonObject);
wos = response.getDataAsList(Wo.class);
result.setCount(response.getCount());
} catch (Exception e) {
logger.warn("list market form o2cloud error: {}.", e.getMessage());
}
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
for (Wo wo : wos) {
InstallLog installLog = emc.find(wo.getId(), InstallLog.class);
if (installLog != null && CommonStatus.VALID.getValue().equals(installLog.getStatus())) {
wo.setInstalledVersion(installLog.getVersion());
} else {
wo.setInstalledVersion("");
}
}
}
if(ListTools.isNotEmpty(wos)){
CacheManager.put(cacheCategory, cacheKey, wos);
}
}
result.setData(wos);
return result;
}
public static class Wo extends Application2 {
@FieldDescribe("已安装的版本,空表示未安装")
private String installedVersion;
public String getInstalledVersion() {
return installedVersion;
}
public void setInstalledVersion(String installedVersion) {
this.installedVersion = installedVersion;
}
}
}
......@@ -47,6 +47,26 @@ public class MarketAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result, jsonElement));
}
@JaxrsMethodDescribe(value = "根据分类查找应用应用.", action = ActionListByCategoryPaging.class)
@GET
@Path("list/paging/{page}/size/{size}/category/{category}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listByCategoryPaging(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("分页") @PathParam("page") Integer page,
@JaxrsParameterDescribe("每页数量") @PathParam("size") Integer size,
@JaxrsParameterDescribe("分类((0)表示全部分类)") @PathParam("category") String category) {
ActionResult<List<ActionListByCategoryPaging.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListByCategoryPaging().execute(effectivePerson, page, size, category);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取对象.", action = ActionGet.class)
@GET
@Path("{flag}")
......@@ -137,6 +157,23 @@ public class MarketAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "列示推荐的3个应用.", action = ActionTopThree.class)
@GET
@Path("list/top/three")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listTopThree(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
ActionResult<List<ActionTopThree.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionTopThree().execute(effectivePerson);
} catch (Exception e) {
logger.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取指定应用安装记录.", action = ActionGetInstallLog.class)
@GET
@Path("{flag}/install/log")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册