|
@@ -0,0 +1,116 @@
|
|
|
+package com.simuwang.manage.task;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.simuwang.base.common.conts.NavParseStatusConst;
|
|
|
+import com.simuwang.base.common.util.DateUtils;
|
|
|
+import com.simuwang.base.mapper.daq.NavMapper;
|
|
|
+import com.simuwang.base.pojo.dos.EmailFundNavDO;
|
|
|
+import com.simuwang.base.pojo.dos.NavDO;
|
|
|
+import com.simuwang.manage.service.EmailFundNavService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * FileName: NavAmplitudeTask
|
|
|
+ * Author: chenjianhua
|
|
|
+ * Date: 2024/12/9 15:46
|
|
|
+ * Description: ${DESCRIPTION}
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class NavAmplitudeTask {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(NavAmplitudeTask.class);
|
|
|
+ @Autowired
|
|
|
+ private EmailFundNavService emailFundNavService;
|
|
|
+ @Autowired
|
|
|
+ private NavMapper navMapper;
|
|
|
+ private static final Integer maxNum = 100000;
|
|
|
+ public void navAmplitude(){
|
|
|
+ //获取净值振幅错误的数据总量
|
|
|
+ Integer total = emailFundNavService.getNavAmplitudeErrorCount();
|
|
|
+ if(total==0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //不超过10W数据,就一次查询处理,超过就分批次处理
|
|
|
+ if(total <= maxNum){
|
|
|
+ List<EmailFundNavDO> emailFundNavDOList = emailFundNavService.getNavAmplitudeErrorList();
|
|
|
+ emailFundNavDOList.stream().forEach(e -> emailNavAmplitude(e));
|
|
|
+ }else{
|
|
|
+ //如果大于10W,分批次处理
|
|
|
+ Map<String,Long> idMap = emailFundNavService.selectNavAmplitudeErrorMaxMinId();
|
|
|
+ Long minId = idMap.get("minId");
|
|
|
+ Long maxId = idMap.get("maxId");
|
|
|
+ long times = (maxId-minId)%maxNum==0?(maxId-minId)/maxNum:(maxId-minId)/maxNum+1;
|
|
|
+ long startIdx = minId;
|
|
|
+ for(int idx=1;idx <= times;idx++){
|
|
|
+ long endIdx = startIdx+idx*maxNum;
|
|
|
+ if(endIdx >= maxId){
|
|
|
+ endIdx = maxId;
|
|
|
+ }
|
|
|
+ List<EmailFundNavDO> emailFundNavDOList = emailFundNavService.getNavAmplitudeErrorListById(startIdx,endIdx);
|
|
|
+ emailFundNavDOList.stream().forEach(e -> emailNavAmplitude(e));
|
|
|
+ startIdx = endIdx;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void emailNavAmplitude(EmailFundNavDO emailFundNavDO) {
|
|
|
+ try{
|
|
|
+ String fundId = emailFundNavDO.getFundId();
|
|
|
+ String priceDate = DateUtils.format(emailFundNavDO.getPriceDate(), DateUtils.YYYY_MM_DD);
|
|
|
+ //上一期单位净值
|
|
|
+ NavDO preNavDO = navMapper.queryLastNavByFundIdDate(fundId,priceDate);
|
|
|
+ if(preNavDO == null){
|
|
|
+ saveEmailFundNav(emailFundNavDO,NavParseStatusConst.SUCCESS,1);
|
|
|
+ saveEmailFundNavToNav(emailFundNavDO);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //|(当期-上期)/ 上期 |
|
|
|
+ BigDecimal amplitudeRate = emailFundNavDO.getNav().subtract(preNavDO.getNav()).divide(preNavDO.getNav(),4, BigDecimal.ROUND_HALF_UP).abs();
|
|
|
+ if(amplitudeRate.compareTo(BigDecimal.valueOf(1)) >= 0){
|
|
|
+ //振幅超过100%不可以入库
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ //振幅超过20%可以入库,但要给出提示信息
|
|
|
+ if(amplitudeRate.compareTo(BigDecimal.valueOf(0.2)) >= 0){
|
|
|
+ saveEmailFundNav(emailFundNavDO,NavParseStatusConst.AMPLITUDE_EXCEPTION,1);
|
|
|
+ }else{
|
|
|
+ saveEmailFundNav(emailFundNavDO,NavParseStatusConst.SUCCESS,1);
|
|
|
+ }
|
|
|
+ saveEmailFundNavToNav(emailFundNavDO);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage(),e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveEmailFundNavToNav(EmailFundNavDO emailFundNavDO) {
|
|
|
+ String fundId = emailFundNavDO.getFundId();
|
|
|
+ String priceDate = DateUtils.format(emailFundNavDO.getPriceDate(), DateUtils.YYYY_MM_DD);
|
|
|
+ NavDO oldNavDO = navMapper.queryNavByFundIdDate(fundId,priceDate);
|
|
|
+ if(oldNavDO != null){
|
|
|
+ oldNavDO.setNav(emailFundNavDO.getNav());
|
|
|
+ oldNavDO.setCumulativeNavWithdrawal(emailFundNavDO.getCumulativeNavWithdrawal());
|
|
|
+ oldNavDO.setUpdateTime(new Date());
|
|
|
+ navMapper.updateNav(oldNavDO);
|
|
|
+ }else{
|
|
|
+ NavDO insertDO = BeanUtil.copyProperties(emailFundNavDO, NavDO.class);
|
|
|
+ insertDO.setCreateTime(new Date());
|
|
|
+ insertDO.setUpdateTime(new Date());
|
|
|
+ navMapper.saveNav(insertDO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveEmailFundNav(EmailFundNavDO insertDO,Integer exceptionStatus,Integer isStored) {
|
|
|
+ insertDO.setExceptionStatus(exceptionStatus);
|
|
|
+ insertDO.setIsStored(isStored);
|
|
|
+ insertDO.setUpdateTime(new Date());
|
|
|
+ emailFundNavService.update(insertDO);
|
|
|
+ }
|
|
|
+}
|