@@ -16,7 +16,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; | |||||
* @Version 1.0 | * @Version 1.0 | ||||
**/ | **/ | ||||
@RestControllerAdvice(basePackages = { | @RestControllerAdvice(basePackages = { | ||||
"com.ningdatech.kqapi.zzsfw.controller" | |||||
"com.ningdatech.kqapi.zzsfw.controller", | |||||
"com.ningdatech.kqapi.scheduler.controller" | |||||
}) | }) | ||||
public class GlobalResponseHandler implements ResponseBodyAdvice<Object> { | public class GlobalResponseHandler implements ResponseBodyAdvice<Object> { | ||||
@@ -3,6 +3,7 @@ package com.ningdatech.kqapi.scheduler.controller; | |||||
import com.ningdatech.kqapi.scheduler.manage.SynManage; | import com.ningdatech.kqapi.scheduler.manage.SynManage; | ||||
import com.ningdatech.kqapi.scheduler.task.RemoveMattersTask; | import com.ningdatech.kqapi.scheduler.task.RemoveMattersTask; | ||||
import com.ningdatech.kqapi.scheduler.task.SynTask; | |||||
import com.ningdatech.kqapi.zzsfw.entity.vo.MatterTopVO; | import com.ningdatech.kqapi.zzsfw.entity.vo.MatterTopVO; | ||||
import com.ningdatech.kqapi.zzsfw.entity.vo.TreeVO; | import com.ningdatech.kqapi.zzsfw.entity.vo.TreeVO; | ||||
import com.ningdatech.kqapi.zzsfw.manage.MatterManage; | import com.ningdatech.kqapi.zzsfw.manage.MatterManage; | ||||
@@ -35,6 +36,8 @@ import java.util.List; | |||||
public class TaskController { | public class TaskController { | ||||
private final RemoveMattersTask removeMattersTask; | private final RemoveMattersTask removeMattersTask; | ||||
private final SynTask synTask; | |||||
private final SynManage synManage; | private final SynManage synManage; | ||||
@ApiOperation(value = "主动调删除数据", notes = "主动调删除数据") | @ApiOperation(value = "主动调删除数据", notes = "主动调删除数据") | ||||
@@ -48,4 +51,11 @@ public class TaskController { | |||||
public void synData() throws UnknownHostException { | public void synData() throws UnknownHostException { | ||||
synManage.synData(); | synManage.synData(); | ||||
} | } | ||||
@ApiOperation(value = "同步菜单链接数据", notes = "同步菜单链接数据") | |||||
@GetMapping("/syn") | |||||
public String synMenu() throws UnknownHostException { | |||||
synTask.synData(); | |||||
return "同步成功"; | |||||
} | |||||
} | } |
@@ -0,0 +1,100 @@ | |||||
package com.ningdatech.kqapi.scheduler.task; | |||||
import cn.hutool.core.date.StopWatch; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||||
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.NdKqZzsfwMattersDeduplicate; | |||||
import com.ningdatech.kqapi.zzsfw.entity.entity.NdKqZzsfwMenu; | |||||
import com.ningdatech.kqapi.zzsfw.manage.MatterManage; | |||||
import com.ningdatech.kqapi.zzsfw.service.IDscSxAdsShareItemQltQlsxCommonIDVKqService; | |||||
import com.ningdatech.kqapi.zzsfw.service.INdKqZzsfwMatterDeduplicateService; | |||||
import com.ningdatech.kqapi.zzsfw.service.INdKqZzsfwMenuService; | |||||
import lombok.RequiredArgsConstructor; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.apache.commons.lang3.StringUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
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.List; | |||||
/** | |||||
* @Classname SynTask | |||||
* @Description | |||||
* @Date 2024/1/4 9:04 | |||||
* @Author PoffyZhang | |||||
*/ | |||||
@Component | |||||
@Slf4j | |||||
@RequiredArgsConstructor | |||||
public class SynTask { | |||||
@Value("${hostname}") | |||||
public String HOST; | |||||
@Value("${spring.profiles.active}") | |||||
public String active; | |||||
@Autowired | |||||
private MatterCacheHelper matterCacheHelper; | |||||
@Autowired | |||||
private MatterManage matterManage; | |||||
@Autowired | |||||
private INdKqZzsfwMatterDeduplicateService matterDeduplicateService; | |||||
@Autowired | |||||
private INdKqZzsfwMenuService menuService; | |||||
/** | |||||
* 每天 | |||||
*/ | |||||
@Scheduled(cron = "0 30 8 * * ?") | |||||
public void synData() throws UnknownHostException { | |||||
// if (!HOST.equals(InetAddress.getLocalHost().getHostName())) { | |||||
// log.info("定时器没开启或者host不对! {}:{}", | |||||
// HOST,InetAddress.getLocalHost().getHostName()); | |||||
// return; | |||||
// } | |||||
// if(!TaskContant.PROD.equals(active)){ | |||||
// log.info("非正式环境不用运行同步任务!"); | |||||
// return; | |||||
// } | |||||
log.info("政务数据 ===================== 同步开始"); | |||||
StopWatch stopWatch = new StopWatch(); | |||||
stopWatch.start(); | |||||
//1.处理 去重数据 | |||||
if(matterCacheHelper.refreshAll()){ | |||||
matterManage.removeAllDup(); | |||||
List<NdKqZzsfwMattersDeduplicate> allDup = matterCacheHelper.all(); | |||||
matterDeduplicateService.saveBatch(allDup); | |||||
//2. 事项 | |||||
List<NdKqZzsfwMenu> menus = menuService.list(); | |||||
for(NdKqZzsfwMenu menu : menus){ | |||||
String url = matterCacheHelper.getUrl(menu.getItemName()); | |||||
if(StringUtils.isBlank(url)){ | |||||
menuService.update(Wrappers.lambdaUpdate(NdKqZzsfwMenu.class) | |||||
.eq(NdKqZzsfwMenu::getId,menu.getId()) | |||||
.set(NdKqZzsfwMenu::getWebapplyurl,null) | |||||
.set(NdKqZzsfwMenu::getHasUrl, CommonEnum.NO.getCode())); | |||||
}else{ | |||||
menuService.update(Wrappers.lambdaUpdate(NdKqZzsfwMenu.class) | |||||
.eq(NdKqZzsfwMenu::getId,menu.getId()) | |||||
.set(NdKqZzsfwMenu::getWebapplyurl,url) | |||||
.set(NdKqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); | |||||
} | |||||
} | |||||
} | |||||
stopWatch.stop(); | |||||
log.info("政务数据 ===================== 同步总共耗时 :{} s",stopWatch.getTotalTimeSeconds()); | |||||
} | |||||
} |
@@ -69,10 +69,4 @@ public class NdKqZzsfwMenuController { | |||||
public String removeAllDup() { | public String removeAllDup() { | ||||
return matterManage.removeAllDup(); | return matterManage.removeAllDup(); | ||||
} | } | ||||
@ApiOperation(value = "同步数据", notes = "同步数据") | |||||
@GetMapping("/syn") | |||||
public String synData() { | |||||
return matterManage.synData(); | |||||
} | |||||
} | } |
@@ -38,8 +38,6 @@ public class MatterManage { | |||||
private final INdKqZzsfwMatterDeduplicateService matterDeduplicateService; | private final INdKqZzsfwMatterDeduplicateService matterDeduplicateService; | ||||
private final MatterCacheHelper matterCacheHelper; | |||||
public List<TreeVO> getMatters() { | public List<TreeVO> getMatters() { | ||||
List<NdKqZzsfwMenu> matters = menuService.list(Wrappers.lambdaQuery(NdKqZzsfwMenu.class) | List<NdKqZzsfwMenu> matters = menuService.list(Wrappers.lambdaQuery(NdKqZzsfwMenu.class) | ||||
.isNotNull(NdKqZzsfwMenu::getWebapplyurl) | .isNotNull(NdKqZzsfwMenu::getWebapplyurl) | ||||
@@ -149,38 +147,4 @@ public class MatterManage { | |||||
matterDeduplicateService.remove(Wrappers.lambdaQuery(NdKqZzsfwMattersDeduplicate.class)); | matterDeduplicateService.remove(Wrappers.lambdaQuery(NdKqZzsfwMattersDeduplicate.class)); | ||||
return "删除成功"; | return "删除成功"; | ||||
} | } | ||||
public String synData() { | |||||
log.info("政务数据 ===================== 同步开始"); | |||||
StopWatch stopWatch = new StopWatch(); | |||||
stopWatch.start(); | |||||
//1.处理 去重数据 | |||||
if(matterCacheHelper.refreshAll()){ | |||||
removeAllDup(); | |||||
List<NdKqZzsfwMattersDeduplicate> allDup = matterCacheHelper.all(); | |||||
matterDeduplicateService.saveBatch(allDup); | |||||
//2. 事项 | |||||
List<NdKqZzsfwMenu> menus = menuService.list(); | |||||
for(NdKqZzsfwMenu menu : menus){ | |||||
String url = matterCacheHelper.getUrl(menu.getItemName()); | |||||
if(StringUtils.isBlank(url)){ | |||||
menuService.update(Wrappers.lambdaUpdate(NdKqZzsfwMenu.class) | |||||
.eq(NdKqZzsfwMenu::getId,menu.getId()) | |||||
.set(NdKqZzsfwMenu::getWebapplyurl,null) | |||||
.set(NdKqZzsfwMenu::getHasUrl,CommonEnum.NO.getCode())); | |||||
}else{ | |||||
menuService.update(Wrappers.lambdaUpdate(NdKqZzsfwMenu.class) | |||||
.eq(NdKqZzsfwMenu::getId,menu.getId()) | |||||
.set(NdKqZzsfwMenu::getWebapplyurl,url) | |||||
.set(NdKqZzsfwMenu::getHasUrl,CommonEnum.YES.getCode())); | |||||
} | |||||
} | |||||
} | |||||
stopWatch.stop(); | |||||
log.info("政务数据 ===================== 同步总共耗时 :{} s",stopWatch.getTotalTimeSeconds()); | |||||
return "同步成功 耗时 :" + stopWatch.getTotalTimeSeconds() + "s"; | |||||
} | |||||
} | } |