From 42c3358006a7ac74e5cf7c2fe4cfca053c1e1321 Mon Sep 17 00:00:00 2001 From: wangrenkang <1173308176@qq.com> Date: Mon, 15 Jan 2024 14:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=8B=E9=A1=B9=E5=89=94?= =?UTF-8?q?=E9=99=A4=E5=92=8C=E4=BA=8B=E9=A1=B9=E5=88=B7=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../helper/basic/AbstractMatterCacheHelper.java | 18 ++++- .../kqapi/scheduler/controller/TaskController.java | 15 ++++ .../ningdatech/kqapi/scheduler/task/SynTask.java | 92 +++++++++++++++++++++- .../entity/ComponentsMatterEliminateEntity.java | 44 +++++++++++ .../mapper/ComponentsMatterEliminateMapper.java | 11 +++ .../mapper/ComponentsMatterEliminateMapper.xml | 5 ++ .../service/ComponentsMatterEliminateService.java | 8 ++ .../impl/ComponentsMatterEliminateServiceImpl.java | 16 ++++ 8 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/entity/entity/ComponentsMatterEliminateEntity.java create mode 100644 kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.java create mode 100644 kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.xml create mode 100644 kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/ComponentsMatterEliminateService.java create mode 100644 kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/impl/ComponentsMatterEliminateServiceImpl.java diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/common/helper/basic/AbstractMatterCacheHelper.java b/kqapi/src/main/java/com/ningdatech/kqapi/common/helper/basic/AbstractMatterCacheHelper.java index 7e016b4..6d6b054 100644 --- a/kqapi/src/main/java/com/ningdatech/kqapi/common/helper/basic/AbstractMatterCacheHelper.java +++ b/kqapi/src/main/java/com/ningdatech/kqapi/common/helper/basic/AbstractMatterCacheHelper.java @@ -5,6 +5,8 @@ import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.collect.Lists; import com.ningdatech.kqapi.common.constant.BizConst; +import com.ningdatech.kqapi.zzsfw.entity.entity.ComponentsMatterEliminateEntity; +import com.ningdatech.kqapi.zzsfw.service.ComponentsMatterEliminateService; import com.ningdatech.kqapi.zzsfw.entity.entity.DscSxAdsShareItemQltQlsxCommonIDVKq; import com.ningdatech.kqapi.zzsfw.entity.entity.MatterKey; import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMattersDeduplicate; @@ -18,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** *

@@ -40,11 +43,22 @@ public abstract class AbstractMatterCacheHelper implements InitializingBean { protected LoadingCache mattersUrlCache; + @Autowired + private ComponentsMatterEliminateService componentsMatterEliminateService; + private final String KQ_ZZS_BASE_URL = "https://www.zjzwfw.gov.cn/zjservice-fe/#/workguide?localInnerCode=&siteCode=330000000000"; private Boolean initMatterCache() { + // 首先,查询ComponentsMatterEliminateEntity中isDelete不为1的qlName列表, 未被剔除 + List eliminatedQlNames = componentsMatterEliminateService.list( + Wrappers.lambdaQuery() + .select(ComponentsMatterEliminateEntity::getQlName) + .ne(ComponentsMatterEliminateEntity::getIsDelete, 1) + ).stream().map(ComponentsMatterEliminateEntity::getQlName).collect(Collectors.toList()); + + // 然后,使用eliminatedQlNames来过滤DscSxAdsShareItemQltQlsxCommonIDVKq查询 List allMatters = kqService - .list(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class) + .list(Wrappers.lambdaQuery() .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getRowguid, DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, DscSxAdsShareItemQltQlsxCommonIDVKq::getQlState, @@ -52,9 +66,9 @@ public abstract class AbstractMatterCacheHelper implements InitializingBean { DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl) .eq(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlState, "1") .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl) - // 确保getQlInnerCodeItem字段不为null且不为"" .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlInnerCodeItem) .ne(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlInnerCodeItem, "") + .notIn(!eliminatedQlNames.isEmpty(), DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, eliminatedQlNames) // 过滤掉那些在eliminatedQlNames中的记录 .orderByDesc(DscSxAdsShareItemQltQlsxCommonIDVKq::getUpdateDate)); if (allMatters.isEmpty()) { log.warn("事项数据未初始化"); diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java b/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java index 40d0137..baf2c52 100644 --- a/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java +++ b/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/controller/TaskController.java @@ -13,10 +13,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.net.UnknownHostException; +import java.util.Arrays; import java.util.List; /** @@ -59,6 +61,19 @@ public class TaskController { return "同步成功"; } + @ApiOperation(value = "剔除某个菜单组件名称数据", notes = "英文逗号','分割") + @GetMapping("/synEliminate") + public String synEliminate(String keys){ + return synTask.synEliminate(Arrays.asList(keys.split(","))); + } + + @ApiOperation(value = "同步单个菜单组件名称", notes = "同步菜单链接数据") + @GetMapping("/synSingle") + public String synSingle(String key){ + synTask.synSingle(key); + return "同步成功"; + } + @ApiOperation(value = "同步菜单链接数据", notes = "同步菜单链接数据") @GetMapping("/syn-menu") public String synMenuData() throws UnknownHostException { diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java b/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java index 9d8d277..b45eac3 100644 --- a/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java +++ b/kqapi/src/main/java/com/ningdatech/kqapi/scheduler/task/SynTask.java @@ -1,10 +1,16 @@ package com.ningdatech.kqapi.scheduler.task; import cn.hutool.core.date.StopWatch; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.github.benmanes.caffeine.cache.LoadingCache; +import com.ningdatech.kqapi.common.constant.BizConst; import com.ningdatech.kqapi.common.enumeration.CommonEnum; import com.ningdatech.kqapi.common.helper.MatterCacheHelper; -import com.ningdatech.kqapi.scheduler.contants.TaskContant; +import com.ningdatech.kqapi.zzsfw.entity.entity.ComponentsMatterEliminateEntity; +import com.ningdatech.kqapi.zzsfw.service.ComponentsMatterEliminateService; +import com.ningdatech.kqapi.zzsfw.entity.entity.DscSxAdsShareItemQltQlsxCommonIDVKq; +import com.ningdatech.kqapi.zzsfw.entity.entity.MatterKey; import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMattersDeduplicate; import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMenu; import com.ningdatech.kqapi.zzsfw.manage.MatterManage; @@ -19,9 +25,10 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * @Classname SynTask @@ -51,6 +58,16 @@ public class SynTask { @Autowired private INdKqZzsfwMenuService menuService; + @Autowired + private IDscSxAdsShareItemQltQlsxCommonIDVKqService kqService; + + @Autowired + private ComponentsMatterEliminateService componentsMatterEliminateService; + + protected LoadingCache mattersDupCache; + + private final String KQ_ZZS_BASE_URL = "https://www.zjzwfw.gov.cn/zjservice-fe/#/workguide?localInnerCode=&siteCode=330000000000"; + /** * 每天 */ @@ -117,4 +134,75 @@ public class SynTask { } } } + + public String synEliminate(List keys){ +// kqService.remove(new LambdaQueryWrapper() +// .in(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, keys)); + // 添加剔除信息 + List entityList = new ArrayList<>(); + keys.forEach(key ->{ + ComponentsMatterEliminateEntity one = componentsMatterEliminateService.getOne(Wrappers.lambdaQuery(ComponentsMatterEliminateEntity.class) + .eq(ComponentsMatterEliminateEntity::getQlName, key)); + if (Objects.isNull(one)){ + entityList.add(new ComponentsMatterEliminateEntity(key,"1")); + } + // 删除缓存 + DscSxAdsShareItemQltQlsxCommonIDVKq matter = getSynUrl(key); + String url = KQ_ZZS_BASE_URL.replace("localInnerCode=", "localInnerCode=" + matter.getQlInnerCodeItem()); + MatterKey matterKey = MatterKey.of(matter.getQlName(),url); + try { + mattersDupCache.invalidate(matterKey); + }catch (Exception e){ + log.error("mattersDupCache is null", e.getMessage()); + } + }); + componentsMatterEliminateService.saveBatch(entityList); + + // 删除menu表 + menuService.remove(new LambdaQueryWrapper() + .in(NdKqZzsfwMenu::getItemName, keys)); + + // 删除deduplicate表 + matterDeduplicateService.remove(new LambdaQueryWrapper() + .in(NdKqZzsfwMattersDeduplicate::getQlName, keys)); + + return "剔除成功"; + } + + public DscSxAdsShareItemQltQlsxCommonIDVKq getSynUrl(String key){ + DscSxAdsShareItemQltQlsxCommonIDVKq matter = kqService + .getOne(Wrappers.lambdaQuery(DscSxAdsShareItemQltQlsxCommonIDVKq.class) + .select(DscSxAdsShareItemQltQlsxCommonIDVKq::getRowguid, + DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, + DscSxAdsShareItemQltQlsxCommonIDVKq::getQlState, + DscSxAdsShareItemQltQlsxCommonIDVKq::getQlInnerCodeItem, + DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl) + .eq(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlName, key) + .eq(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlState, "1") + .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getWebapplyurl) + // 确保getQlInnerCodeItem字段不为null且不为"" + .isNotNull(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlInnerCodeItem) + .ne(DscSxAdsShareItemQltQlsxCommonIDVKq::getQlInnerCodeItem, "") + .orderByDesc(DscSxAdsShareItemQltQlsxCommonIDVKq::getUpdateDate) + .last(BizConst.LIMIT_1)); + return matter; + } + + public String synSingle(String key){ + DscSxAdsShareItemQltQlsxCommonIDVKq matter = getSynUrl(key); + String url = KQ_ZZS_BASE_URL.replace("localInnerCode=", "localInnerCode=" + matter.getQlInnerCodeItem()); + List menus = menuService.list(Wrappers.lambdaQuery(NdKqZzsfwMenu.class) + .eq(NdKqZzsfwMenu::getItemName, key)); + menus.forEach(menu->{ + menuService.update(Wrappers.lambdaUpdate(NdKqZzsfwMenu.class) + .eq(NdKqZzsfwMenu::getId,menu.getId()) + .set(NdKqZzsfwMenu::getWebapplyurl,url) + .set(NdKqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); + }); + // 更新缓存 + MatterKey matterKey = MatterKey.of(matter.getQlName(),url); + mattersDupCache.invalidate(matterKey); + mattersDupCache.put(matterKey,NdKqZzsfwMattersDeduplicate.of(matter.getQlName(),url)); + return "更新成功,rul:" + url; + } } diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/entity/entity/ComponentsMatterEliminateEntity.java b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/entity/entity/ComponentsMatterEliminateEntity.java new file mode 100644 index 0000000..bfe883b --- /dev/null +++ b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/entity/entity/ComponentsMatterEliminateEntity.java @@ -0,0 +1,44 @@ +package com.ningdatech.kqapi.zzsfw.entity.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.security.Timestamp; + +// ComponentsMatterEliminateEntity.java +@Data +@TableName("components_matter_eliminate") +public class ComponentsMatterEliminateEntity { + + /** + * 事项名称剔除表,主要剔除事项url报错404链接 + */ + + @ApiModelProperty("id主键") + @TableId(type = IdType.AUTO) + private Long id; + /** + * 组件名称 + */ + private String qlName; + + /** + * 剔除时间 + */ + private Timestamp eliminateTime; + + /** + * 剔除标识,0未剔除,1已剔除 + */ + private String isDelete; + + public ComponentsMatterEliminateEntity(String qlName,String isDelete) { + this.qlName = qlName; + this.isDelete = isDelete; + } +} + diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.java b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.java new file mode 100644 index 0000000..33867b0 --- /dev/null +++ b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.java @@ -0,0 +1,11 @@ +package com.ningdatech.kqapi.zzsfw.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ningdatech.kqapi.zzsfw.entity.entity.ComponentsMatterEliminateEntity; + +/** + * @author wangrenkang + * @date 2024-01-15 10:53:17 + */ +public interface ComponentsMatterEliminateMapper extends BaseMapper { +} \ No newline at end of file diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.xml b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.xml new file mode 100644 index 0000000..fec934c --- /dev/null +++ b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/mapper/ComponentsMatterEliminateMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/ComponentsMatterEliminateService.java b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/ComponentsMatterEliminateService.java new file mode 100644 index 0000000..b12b063 --- /dev/null +++ b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/ComponentsMatterEliminateService.java @@ -0,0 +1,8 @@ +package com.ningdatech.kqapi.zzsfw.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ningdatech.kqapi.zzsfw.entity.entity.ComponentsMatterEliminateEntity; + +// ComponentsMatterEliminateService.java +public interface ComponentsMatterEliminateService extends IService { +} diff --git a/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/impl/ComponentsMatterEliminateServiceImpl.java b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/impl/ComponentsMatterEliminateServiceImpl.java new file mode 100644 index 0000000..0e4871c --- /dev/null +++ b/kqapi/src/main/java/com/ningdatech/kqapi/zzsfw/service/impl/ComponentsMatterEliminateServiceImpl.java @@ -0,0 +1,16 @@ +package com.ningdatech.kqapi.zzsfw.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ningdatech.kqapi.zzsfw.entity.entity.ComponentsMatterEliminateEntity; +import com.ningdatech.kqapi.zzsfw.mapper.ComponentsMatterEliminateMapper; +import com.ningdatech.kqapi.zzsfw.service.ComponentsMatterEliminateService; +import org.springframework.stereotype.Service; + +/** + * @author wangrenkang + * @date 2024-01-15 10:54:49 + */ +@Service +public class ComponentsMatterEliminateServiceImpl extends ServiceImpl implements ComponentsMatterEliminateService { + +} \ No newline at end of file