package com.bwie.es.sync; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.bwie.common.domain.response.VolumeCodeListRes; import com.bwie.common.result.Result; import com.bwie.es.feign.EsVolumeCodeFeign; import com.bwie.es.service.EsVolumeCodeService; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; import java.util.List; /** * @Author:蓬叁 * @Package:com.bwie.es.sync * @Project:maven-month * @name:EsSyncVolumeCode * @Date:2024/8/12 下午1:17 */ @Log4j2 @Component public class EsSyncVolumeCode implements ApplicationRunner { @Autowired private EsVolumeCodeFeign esVolumeCodeFeign; @Autowired private EsVolumeCodeService esVolumeCodeService; @Override public void run(ApplicationArguments args) throws Exception { log.info("--------Es模块启动--------"); log.info("启动任务:mysql同步Es正在执行,正在查询数据库......"); Result> all = esVolumeCodeFeign.all(); List volumeCodeListResList = all.getData(); log.info("启动任务:mysql同步Es正在执行,查询数据:[{}]", JSON.toJSONString(volumeCodeListResList)); try { esVolumeCodeService.syncAdd(volumeCodeListResList); log.info("启动任务:mysql同步Es正在执行,同步成功"); } catch (Exception exception){ exception.printStackTrace(); log.info("启动任务:mysql同步Es正在执行,同步失败"); } } }