|
|
@@ -0,0 +1,509 @@
|
|
|
+package org.dromara.mall.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson2.JSONPath;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.mall.domain.param.DiyPageInitParam;
|
|
|
+import org.dromara.mall.domain.param.DiyPageSearchParam;
|
|
|
+import org.dromara.mall.domain.param.DiyRouteSearchParam;
|
|
|
+import org.dromara.mall.domain.param.TemplateParam;
|
|
|
+import org.dromara.mall.domain.vo.NsDiyRouteVo;
|
|
|
+import org.dromara.mall.domain.vo.SceneDomainVo;
|
|
|
+import org.dromara.mall.domain.vo.StartUpPageConfigVo;
|
|
|
+import org.dromara.mall.service.INsDiyRouteService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.mall.domain.bo.NsDiyPageBo;
|
|
|
+import org.dromara.mall.domain.vo.NsDiyPageVo;
|
|
|
+import org.dromara.mall.domain.NsDiyPage;
|
|
|
+import org.dromara.mall.mapper.NsDiyPageMapper;
|
|
|
+import org.dromara.mall.service.INsDiyPageService;
|
|
|
+
|
|
|
+import java.net.URL;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 自定义页面Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2026-01-20
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class NsDiyPageServiceImpl extends ServiceImpl<NsDiyPageMapper, NsDiyPage> implements INsDiyPageService {
|
|
|
+
|
|
|
+ private final NsDiyPageMapper baseMapper;
|
|
|
+
|
|
|
+ private final INsDiyRouteService nsDiyRouteService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询自定义页面
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 自定义页面
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public NsDiyPageVo queryById(Long id){
|
|
|
+ return baseMapper.selectVoById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询自定义页面列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 自定义页面分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<NsDiyPageVo> queryPageList(NsDiyPageBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<NsDiyPage> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<NsDiyPageVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的自定义页面列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 自定义页面列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<NsDiyPageVo> queryList(NsDiyPageBo bo) {
|
|
|
+ LambdaQueryWrapper<NsDiyPage> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<NsDiyPage> buildQueryWrapper(NsDiyPageBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<NsDiyPage> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(NsDiyPage::getId);
|
|
|
+ lqw.eq(bo.getSiteId() != null, NsDiyPage::getSiteId, bo.getSiteId());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPageTitle()), NsDiyPage::getPageTitle, bo.getPageTitle());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getTitle()), NsDiyPage::getTitle, bo.getTitle());
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getName()), NsDiyPage::getName, bo.getName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getType()), NsDiyPage::getType, bo.getType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getTemplate()), NsDiyPage::getTemplate, bo.getTemplate());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getMode()), NsDiyPage::getMode, bo.getMode());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getValue()), NsDiyPage::getValue, bo.getValue());
|
|
|
+ lqw.eq(bo.getIsDefault() != null, NsDiyPage::getIsDefault, bo.getIsDefault());
|
|
|
+ lqw.eq(bo.getIsChange() != null, NsDiyPage::getIsChange, bo.getIsChange());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getShare()), NsDiyPage::getShare, bo.getShare());
|
|
|
+ lqw.eq(bo.getVisitCount() != null, NsDiyPage::getVisitCount, bo.getVisitCount());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增自定义页面
|
|
|
+ *
|
|
|
+ * @param bo 自定义页面
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(NsDiyPageBo bo) {
|
|
|
+ NsDiyPage add = MapstructUtils.convert(bo, NsDiyPage.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改自定义页面
|
|
|
+ *
|
|
|
+ * @param bo 自定义页面
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(NsDiyPageBo bo) {
|
|
|
+ NsDiyPage update = MapstructUtils.convert(bo, NsDiyPage.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(NsDiyPage entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除自定义页面信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自定义页面详情
|
|
|
+ *
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public NsDiyPageVo infoByName(String name) {
|
|
|
+ NsDiyPageVo nsDiyPageVo = baseMapper.selectVoOne(Wrappers.lambdaQuery(NsDiyPage.class)
|
|
|
+ .eq(NsDiyPage::getName, name)
|
|
|
+ .eq(NsDiyPage::getIsDefault, 1)
|
|
|
+ .eq(NsDiyPage::getSiteId, 0)
|
|
|
+ );
|
|
|
+ return nsDiyPageVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取页面列表
|
|
|
+ *
|
|
|
+ * @param searchParam
|
|
|
+ * @param pageQuery
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<NsDiyPageVo> getDiyPage(DiyPageSearchParam searchParam, PageQuery pageQuery) {
|
|
|
+ QueryWrapper<NsDiyPage> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("site_id", 0);
|
|
|
+ queryWrapper.orderByDesc("id");
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotEmpty(searchParam.getTitle())) queryWrapper.like("title", searchParam.getTitle());
|
|
|
+ if (ObjectUtil.isNotEmpty(searchParam.getMode())) queryWrapper.eq("mode", searchParam.getMode());
|
|
|
+ if (ObjectUtil.isNotEmpty(searchParam.getType())) queryWrapper.eq("type", searchParam.getType());
|
|
|
+
|
|
|
+ //获取resource/json/loader/diy/template.json
|
|
|
+ String templateJsonStr = ResourceUtil.readUtf8Str("json/loader/diy/template.json");
|
|
|
+ JSONObject template = JSONUtil.parseObj(templateJsonStr);
|
|
|
+
|
|
|
+ IPage<NsDiyPageVo> iPage = baseMapper.selectVoPage(pageQuery.build(), queryWrapper);
|
|
|
+ for (NsDiyPageVo item : iPage.getRecords()) {
|
|
|
+ item.setTypeName(ObjectUtil.defaultIfNull(template.getByPath(item.getType() + ".title", String.class), ""));
|
|
|
+ item.setTypePage(ObjectUtil.defaultIfNull(template.getByPath(item.getType() + ".page", String.class), ""));
|
|
|
+ }
|
|
|
+ return TableDataInfo.build(iPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取页面模板
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getTemplate(TemplateParam param) {
|
|
|
+
|
|
|
+ if (true) {
|
|
|
+ param.setAppType("admin");
|
|
|
+ } else {
|
|
|
+ param.setAppType("site");
|
|
|
+ }
|
|
|
+ //获取resource/json/loader/diy/template.json
|
|
|
+ String templateJsonStr = ResourceUtil.readUtf8Str("json/loader/diy/template.json");
|
|
|
+ JSONObject template = JSONUtil.parseObj(templateJsonStr);
|
|
|
+
|
|
|
+ for (String key : template.keySet()) {
|
|
|
+ JSONObject pages = ObjectUtil.defaultIfNull(getPages(key, param.getMode()), new JSONObject());
|
|
|
+ template.putByPath(key + ".template", pages);
|
|
|
+ }
|
|
|
+
|
|
|
+ return template;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject getPages(String type, String mode){
|
|
|
+ //获取resource/json/loader/diy/template.json
|
|
|
+ String pageJsonStr = ResourceUtil.readUtf8Str("json/loader/diy/pages.json");
|
|
|
+ JSONObject pages = JSONUtil.parseObj(pageJsonStr);
|
|
|
+
|
|
|
+ if (!type.isEmpty() && pages != null) {
|
|
|
+ pages = pages.getJSONObject(type);
|
|
|
+ }
|
|
|
+ if (!mode.isEmpty() && pages != null) {
|
|
|
+ JSONObject modePages = new JSONObject();
|
|
|
+ for (String key : pages.keySet()) {
|
|
|
+ if (!pages.getStr(key + ".mode", "").equals(mode)) {
|
|
|
+ modePages.put(key, pages.getJSONObject(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return modePages;
|
|
|
+ }
|
|
|
+
|
|
|
+ return pages;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static JSONObject getPagesByAddon(String type, String addon){
|
|
|
+ //获取resource/json/loader/diy/template.json
|
|
|
+ String pageJsonStr = ResourceUtil.readUtf8Str("json/loader/diy/pages.json");
|
|
|
+ JSONObject pages = JSONUtil.parseObj(pageJsonStr);
|
|
|
+
|
|
|
+ if (type != null && !type.isEmpty() && pages != null) {
|
|
|
+ pages = pages.getJSONObject(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ return pages;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取默认页面数据
|
|
|
+ *
|
|
|
+ * @param type
|
|
|
+ * @param addon
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getFirstPageData(String type, String addon) {
|
|
|
+ JSONObject pages = getPagesByAddon(type, addon);
|
|
|
+ if (pages == null || pages.keySet().size() == 0) return null;
|
|
|
+
|
|
|
+ String template = pages.keySet().iterator().next();
|
|
|
+ JSONObject data = pages.getJSONObject(template);
|
|
|
+ data.set("type", type);
|
|
|
+ data.set("template", template);
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //获取resource/json/loader/diy/template.json
|
|
|
+ String jsonStr = ResourceUtil.readUtf8Str("json/loader/diy/template.json");
|
|
|
+ //jan
|
|
|
+ JSONObject template = JSONUtil.parseObj(jsonStr);
|
|
|
+ System.out.println(template.toStringPretty());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取页面装修列表
|
|
|
+ *
|
|
|
+ * @param searchParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject getDecoratePage(DiyPageSearchParam searchParam) {
|
|
|
+
|
|
|
+ TemplateParam templateParam = new TemplateParam();
|
|
|
+ String[] key = {searchParam.getType()};
|
|
|
+ templateParam.setKey(key);
|
|
|
+ JSONObject template = this.getTemplate(templateParam).getJSONObject(searchParam.getType());
|
|
|
+ if (template == null) throw new RuntimeException("模板不存在");
|
|
|
+
|
|
|
+ JSONObject defaultPage = getFirstPageData(searchParam.getType(), "");
|
|
|
+
|
|
|
+ JSONObject useTemplate = new JSONObject();
|
|
|
+ useTemplate.put("type", searchParam.getType());
|
|
|
+ useTemplate.put("title", defaultPage == null ? "" : defaultPage.getStr("title", ""));
|
|
|
+ useTemplate.put("name", "");
|
|
|
+ useTemplate.put("cover", defaultPage == null ? "" : defaultPage.getStr("cover", ""));
|
|
|
+ useTemplate.put("page", template.getStr("page"));
|
|
|
+ useTemplate.put("action", template.getStr("action"));
|
|
|
+ useTemplate.put("url", "");
|
|
|
+ useTemplate.put("parent", "");
|
|
|
+
|
|
|
+ NsDiyPageVo info = infoByName(searchParam.getType());
|
|
|
+ useTemplate.set("id", info.getId());
|
|
|
+ useTemplate.set("title", info.getTitle());
|
|
|
+ if (useTemplate.getStr("cover").isEmpty() && useTemplate.getStr("url").isEmpty()) {
|
|
|
+ useTemplate.set("url", template.getStr("page"));
|
|
|
+ } else if (useTemplate.getStr("url").isEmpty()) {
|
|
|
+ useTemplate.set("url", template.getStr("page"));
|
|
|
+ }
|
|
|
+
|
|
|
+ DiyRouteSearchParam diyRouteSearchParam = new DiyRouteSearchParam();
|
|
|
+ diyRouteSearchParam.setUrl(useTemplate.getStr("page"));
|
|
|
+ List<NsDiyRouteVo> otherPage = nsDiyRouteService.list(diyRouteSearchParam);
|
|
|
+ if (otherPage.size() > 0) {
|
|
|
+ NsDiyRouteVo route = otherPage.get(0);
|
|
|
+ useTemplate.set("title", route.getTitle());
|
|
|
+ useTemplate.set("name", route.getName());
|
|
|
+ useTemplate.set("parent", route.getParent());
|
|
|
+ useTemplate.set("action", route.getAction());
|
|
|
+ }
|
|
|
+
|
|
|
+ template.put("use_template", useTemplate);
|
|
|
+ String wapDomain = "http://127.0.0.1:8080";
|
|
|
+ SceneDomainVo sceneDomainVo = new SceneDomainVo();
|
|
|
+ sceneDomainVo.setWapDomain(wapDomain);
|
|
|
+ sceneDomainVo.setWapUrl(wapDomain + "/wap");
|
|
|
+ sceneDomainVo.setWebUrl(wapDomain + "/web");
|
|
|
+ JSONObject domainUrl = new JSONObject();
|
|
|
+ domainUrl.put("wap_domain", sceneDomainVo.getWapDomain());
|
|
|
+ domainUrl.put("wap_url", sceneDomainVo.getWapUrl());
|
|
|
+ domainUrl.put("web_url", sceneDomainVo.getWebUrl());
|
|
|
+ template.put("domain_url", domainUrl);
|
|
|
+
|
|
|
+ return template;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面初始化数据
|
|
|
+ *
|
|
|
+ * @param param@return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public NsDiyPageVo getPageInit(DiyPageInitParam param) {
|
|
|
+ JSONObject template = getTemplate(new TemplateParam());
|
|
|
+
|
|
|
+ NsDiyPageVo info = null;
|
|
|
+ if (param.getId() > 0) {
|
|
|
+ info = this.queryById(Long.valueOf(param.getId()));
|
|
|
+ } else if (!param.getName().isEmpty()) {
|
|
|
+ info = this.infoByName(param.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!param.getName().isEmpty()) {
|
|
|
+ StartUpPageConfigVo startConfig = null;
|
|
|
+ for (String key : template.keySet()) {
|
|
|
+ if (ObjectUtil.defaultIfNull(template.getByPath(key + ".page", String.class), "").equals(startConfig.getPage())) {
|
|
|
+ info = this.infoByName(key);
|
|
|
+ if (info != null) {
|
|
|
+ param.setType(key);
|
|
|
+ param.setName(key);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (info != null) {
|
|
|
+ if (template.getJSONObject(info.getType()) != null) {
|
|
|
+ JSONObject page = template.getJSONObject(info.getType());
|
|
|
+ info.setTypeName(page.getStr("title"));
|
|
|
+ info.setPage(page.getStr("page"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Long time = System.currentTimeMillis() / 1000;
|
|
|
+ String pageTitle = ObjectUtil.defaultIfBlank(param.getTitle(), "页面" + time);
|
|
|
+ String type = ObjectUtil.defaultIfBlank(param.getType(), "DIY_PAGE");
|
|
|
+ String name = type.equals("DIY_PAGE") ? "DIY_PAGE_RANDOM_" + time : type;
|
|
|
+ String typeName = "";
|
|
|
+ String templateName = "";
|
|
|
+ String pageRoute = "";
|
|
|
+ String mode = "diy";
|
|
|
+ Integer isDefault = 0;
|
|
|
+ String value = "";
|
|
|
+
|
|
|
+ JSONObject page = null;
|
|
|
+ if (template.getJSONObject(param.getName()) != null) {
|
|
|
+ page = template.getJSONObject(param.getName());
|
|
|
+ type = name = param.getName();
|
|
|
+ pageTitle = typeName = page.getStr("title");
|
|
|
+ pageRoute = page.getStr("page");
|
|
|
+ JSONObject pageData = this.getFirstPageData(type, "");
|
|
|
+// if (pageData != null) {
|
|
|
+// mode = pageData.getByPath("template.mode", String.class);
|
|
|
+// value = pageData.getJSONObject("template").toString();
|
|
|
+// isDefault = 1;
|
|
|
+// }
|
|
|
+
|
|
|
+ if (pageData != null) {
|
|
|
+ mode = JSONPath.eval(pageData, "$.mode") + "";
|
|
|
+ value = JSONPath.eval(pageData, "$.data") + "";
|
|
|
+ isDefault = 1;
|
|
|
+ }
|
|
|
+ } else if (template.getJSONObject(param.getType()) != null) {
|
|
|
+ page = template.getJSONObject(param.getType());
|
|
|
+ typeName = page.getStr("title");
|
|
|
+ pageRoute = page.getStr("page");
|
|
|
+ }
|
|
|
+
|
|
|
+ info = new NsDiyPageVo();
|
|
|
+ info.setName(name);
|
|
|
+ info.setPageTitle(pageTitle);
|
|
|
+ info.setTitle(pageTitle);
|
|
|
+ info.setType(type);
|
|
|
+ info.setTypeName(typeName);
|
|
|
+ info.setTemplate(templateName);
|
|
|
+ info.setPage(pageRoute);
|
|
|
+ info.setMode(mode);
|
|
|
+ info.setValue(value);
|
|
|
+ info.setIsDefault(Long.valueOf(isDefault));
|
|
|
+ }
|
|
|
+
|
|
|
+ info.setComponent(getComponentList(info.getType()));
|
|
|
+
|
|
|
+ String wapDomain = "http://127.0.0.1:8080";
|
|
|
+
|
|
|
+ SceneDomainVo sceneDomainVo = new SceneDomainVo();
|
|
|
+ sceneDomainVo.setWapDomain(wapDomain);
|
|
|
+ sceneDomainVo.setWapUrl(wapDomain + "/wap");
|
|
|
+ sceneDomainVo.setWebUrl(wapDomain + "/web");
|
|
|
+ info.setDomainUrl(sceneDomainVo);
|
|
|
+
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject getComponentList(String type) {
|
|
|
+ String templateJsonStr = ResourceUtil.readUtf8Str("json/loader/diy/components.json");
|
|
|
+ JSONObject ComponentList = JSONUtil.parseObj(templateJsonStr);
|
|
|
+ JSONObject res = new JSONObject();
|
|
|
+ for (String formComponentObj : ComponentList.keySet()) {
|
|
|
+ JSONObject formComponent = ComponentList.getJSONObject(formComponentObj);
|
|
|
+ JSONObject list = formComponent.getJSONObject("list");
|
|
|
+ Iterator<Map.Entry<String, Object>> iterator = list.entrySet().iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ JSONObject cv = JSONUtil.parseObj(iterator.next().getValue());
|
|
|
+ if (cv.containsKey("support_page")) {
|
|
|
+ JSONArray support = cv.getJSONArray("support_page");
|
|
|
+ if (ObjectUtil.isNotEmpty(type)) {
|
|
|
+ if (support != null && support.size() > 0 && !support.contains(type)) {
|
|
|
+ iterator.remove();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cv.remove("sort");
|
|
|
+ cv.remove("support_page");
|
|
|
+ }
|
|
|
+ // 根据 sort 排序
|
|
|
+ iterator = list.entrySet().iterator();
|
|
|
+ if(iterator.hasNext())
|
|
|
+ {
|
|
|
+ formComponent.put("list", sortJSONObjectBySortField(list));
|
|
|
+ res.put(formComponentObj, formComponent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject sortJSONObjectBySortField(JSONObject originalJsonObject) {
|
|
|
+ // 提取所有内部 JSONObject 到一个 List 中
|
|
|
+ List<Map.Entry<String, Object>> entryList = new ArrayList<>(originalJsonObject.entrySet());
|
|
|
+
|
|
|
+ // 对 List 进行排序
|
|
|
+ Collections.sort(entryList, new Comparator<Map.Entry<String, Object>>() {
|
|
|
+ public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
|
|
|
+ JSONObject jsonObj1 = (JSONObject) o1.getValue();
|
|
|
+ JSONObject jsonObj2 = (JSONObject) o2.getValue();
|
|
|
+ int sort1 = jsonObj1.getInt("sort");
|
|
|
+ int sort2 = jsonObj2.getInt("sort");
|
|
|
+ return Integer.compare(sort1, sort2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建一个新的 JSONObject 来存放排序后的结果
|
|
|
+ JSONObject sortedJsonObject = new JSONObject();
|
|
|
+ for (Map.Entry<String, Object> entry : entryList) {
|
|
|
+ sortedJsonObject.put(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ return sortedJsonObject;
|
|
|
+ }
|
|
|
+}
|