diff --git a/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java b/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java index eb408bc7..aaacb4cb 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java +++ b/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java @@ -18,6 +18,7 @@ import com.adc.da.util.http.ResponseMessage; import com.adc.da.util.http.Result; import com.adc.da.utils.util.DateUtil; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.gson.JsonObject; import org.apache.commons.lang3.StringUtils; import org.elasticsearch.client.transport.TransportClient; @@ -91,6 +92,49 @@ public class ResetSearchCenterService { return Result.success(res); } + @Async + public ResponseMessage syncResetALLSearchCenter(SearchCenter searchCenter) throws Exception{ + Boolean getFulltextserchIndex = elasticsearchService.isIndexExist("fulltextserch"); + SearchCenter standSearch = new SearchCenter(); + QueryWrapper qw = new QueryWrapper(); + qw.eq("VALID_FLAG","0"); + int count = iSarStandardsInfoService.count(qw); + standSearch.setExecType(searchCenter.getExecType()); + standSearch.setCountStand(count); + ResponseMessage stand = resetStandSearchCenter(new SarStandardsInfoEOPage(),standSearch); + List r = new ArrayList<>(); + if(stand.isOk() && StringUtils.isNotBlank(stand.getData().toString())){ + r.add(stand.getData().toString()); + } + + SearchCenter lawsSearch = new SearchCenter(); + QueryWrapper qw2 = new QueryWrapper(); + qw2.eq("VALID_FLAG","0"); + int count2 = iSarLawsStandInfoService.count(qw2); + lawsSearch.setExecType(searchCenter.getExecType()); + lawsSearch.setCountStand(count2); + ResponseMessage laws = resetLawsSearchCenter(new SarLawsStandInfoPage(),lawsSearch); + if(laws.isOk() && StringUtils.isNotBlank(laws.getData().toString())){ + r.add(laws.getData().toString()); + } + + SearchCenter bussSearch = new SearchCenter(); + QueryWrapper qw3 = new QueryWrapper(); + qw3.eq("VALID_FLAG","0"); + int count3 = iSarBussionessStandService.count(qw3); + bussSearch.setExecType(searchCenter.getExecType()); + bussSearch.setCountStand(count3); + ResponseMessage buss = resetBussStandSearchCenter(new SarBussionessStandEOPage(),bussSearch); + if(buss.isOk() && StringUtils.isNotBlank(buss.getData().toString())){ + r.add(buss.getData().toString()); + } + + String res = String.join(", ", r); + logger.info(res); + + return Result.success(res); + } + //重建国内外标准 @Async public ResponseMessage resetStandSearchCenter(SarStandardsInfoEOPage page,SearchCenter searchCenter) throws Exception{ diff --git a/adc-da-slrs/src/main/java/com/adc/da/search/sync/restSearchSync.java b/adc-da-slrs/src/main/java/com/adc/da/search/sync/restSearchSync.java new file mode 100644 index 00000000..beeef499 --- /dev/null +++ b/adc-da-slrs/src/main/java/com/adc/da/search/sync/restSearchSync.java @@ -0,0 +1,71 @@ +package com.adc.da.search.sync; + +import com.adc.da.search.bean.SearchCenter; +import com.adc.da.search.server.ResetSearchCenterService; +import com.adc.da.slrs.sarBussionessStand.dao.SarBussionessStandDao; +import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand; +import com.adc.da.slrs.sarBussionessStandState.entity.SarBussionessStandState; +import com.adc.da.slrs.sarBussionessStandState.service.ISarBussionessStandStateService; +import com.adc.da.utils.util.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Description: TODO + * @author: super_liu + * @date: 2022年01月25日 3:34 + */ +@EnableScheduling +@Component +@Slf4j +public class restSearchSync { + Logger logger = LoggerFactory.getLogger(restSearchSync.class); + + @Autowired + private ResetSearchCenterService resetSearchCenterService; + + /** + * 根据配置文件设置是否开启定时器 + */ + + @Value("${isNotScheduled}") + private boolean isNotScheduled; //是否开启定时器 + + + // 每天0点1分执行 重置ES 自动更新、新增、删除 +// @Scheduled(cron="0 0 1 1 * ?") + @Scheduled(cron = "0 1 0 * * ?") + @Async + public void StandScheduledJobMonthBegin(){ + if(isNotScheduled){ + try{ + Thread.sleep(2000); + logger.info("每天0点1分执行 重置ES 自动更新、新增、删除:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---START-01"); + + SearchCenter searchCenter = new SearchCenter(); + // ALL 执行全部 + searchCenter.setExecType("ALL"); + resetSearchCenterService.syncResetALLSearchCenter(searchCenter); + + logger.info("每天0点1分执行 重置ES 自动更新、新增、删除:"+Thread.currentThread().getName() + " cron=0 1 0 * * ? --- " + new Date()+"---End-01"); + }catch(Exception e){ + logger.info(e.getMessage()); + } + } + } + +}