Commit b5d9866f authored by 钱坤's avatar 钱坤

基金净值缓存刷新触发job

parent fe9f3516
package com.tanpu.fund.feign.hangjia;
import com.tanpu.common.model.tanpuroom.Type;
import com.tanpu.common.resp.CommonResp;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
//@FeignClient(value = "service-product", url = "http://127.0.0.1:8194/product")
@FeignClient(value = "service-hangjia-back", url = "${tanpu.hangjia-back.svc:}", path = "/py/jijinhangjia")
public interface FeignForHangjia {
@GetMapping("/api/tamp/cache/fund/nav/reload")
CommonResp reloadFundNav4Ifa(@RequestParam("sign") String sign, @RequestParam("ifa_id") String ifaId);
@GetMapping("/api/tamp/cache/fund/nav/reload")
CommonResp reloadMostUsedFundNav(@RequestParam("sign") String sign, @RequestParam("limit") int limit);
}
package com.tanpu.fund.feign.hangjia;
import com.alibaba.fastjson.JSON;
import com.tanpu.common.model.tanpuroom.Type;
import com.tanpu.common.resp.CommonResp;
import com.tanpu.fund.feign.product.FeignForProduct;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
@Slf4j
@Component
public class FeignbackForHangjiaBack implements FallbackFactory<FeignForHangjia> {
@Override
public FeignForHangjia create(Throwable throwable) {
return new FeignForHangjia() {
@Override
public CommonResp reloadFundNav4Ifa(String sign, String ifaId) {
log.error("FeignForHangjia.reloadFundNav4Ifa 发生异常, sign: {}, ifaId: {}", sign, ifaId, throwable);
return CommonResp.error("基金净值缓存刷新发生异常");
}
@Override
public CommonResp reloadMostUsedFundNav(String sign, int limit) {
log.error("FeignForHangjia.reloadMostUsedFundNav 发生异常, sign: {}, limit: {}", sign, limit, throwable);
return CommonResp.error("基金净值缓存刷新发生异常");
}
};
}
}
package com.tanpu.fund.job;
import com.tanpu.common.resp.CommonResp;
import com.tanpu.common.utils.DateUtils;
import com.tanpu.common.utils.RedisUtils;
import com.tanpu.fund.feign.hangjia.FeignForHangjia;
import com.tanpu.fund.service.impl.FundLatestNavService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author: zyh
* <p>
*/
@Slf4j
@Component
public class FundNavCacheJob {
@Resource
private FeignForHangjia feignForHangjia;
@Value("${tanpu.fund.nav.cache.ifa:}")
private String ifaIdList;
@Value("${tanpu.most.used.fund.nav.cache.limit:200}")
private int limit;
@Scheduled(cron = "10 1 * * * ?")
public void execute() {
long start = System.currentTimeMillis();
String sign = DateUtils.format(DateUtils.nowDate()).replace(" ", "");
try {
if (StringUtils.isNotBlank(ifaIdList)) {
log.info("刷新指定ifa的基金净值缓存job开始");
String[] ss = ifaIdList.split(",");
for (String id : ss) {
log.info("开始刷新ifa=" + id + "的基金净值缓存");
CommonResp resp = feignForHangjia.reloadFundNav4Ifa(sign, id);
log.info("ifa=" + id + "的基金净值缓存刷新结果: " + resp);
Thread.sleep(1000);
}
}
} catch (Exception e) {
log.error("", e);
} finally {
log.info("私募基金最新净值更新job结束, 耗时: {}ms", System.currentTimeMillis() - start);
}
try {
log.info("开始刷新使用最多基金净值缓存, limit: " + limit);
sign = DateUtils.format(DateUtils.nowDate()).replace(" ", "");
CommonResp resp = feignForHangjia.reloadMostUsedFundNav(sign, limit);
log.info("使用最多基金净值缓存刷新结果: " + resp);
} catch (Exception e) {
log.error("", e);
} finally {
log.info("基金净值缓存刷新触发job结束, 耗时: {}ms", System.currentTimeMillis() - start);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment