exam-month/yuan-es/src/main/java/com/bwie/es/sync/EsSyncVolumeCode.java

47 lines
1.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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蓬叁
* @Packagecom.bwie.es.sync
* @Projectmaven-month
* @nameEsSyncVolumeCode
* @Date2024/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<List<VolumeCodeListRes>> all = esVolumeCodeFeign.all();
List<VolumeCodeListRes> 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正在执行,同步失败");
}
}
}