package com.iailab.module.data.ind.collection;
|
|
import com.iailab.module.data.common.enums.ItemTypeEnum;
|
import com.iailab.module.data.ind.collection.handler.AtomItemHandler;
|
import com.iailab.module.data.ind.collection.handler.CalItemHandler;
|
import com.iailab.module.data.ind.collection.handler.DerItemHandler;
|
import com.iailab.module.data.ind.item.entity.IndItemEntity;
|
import com.iailab.module.data.ind.item.service.IndItemService;
|
import com.iailab.module.data.ind.item.vo.IndItemValueVO;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年10月04日
|
*/
|
@Slf4j
|
@Component
|
public class IndItemCollector {
|
|
@Autowired
|
private IndItemService indItemService;
|
|
@Autowired
|
private AtomItemHandler atomItemHandler;
|
|
@Autowired
|
private DerItemHandler derItemHandler;
|
|
@Autowired
|
private CalItemHandler calItemHandler;
|
|
public List<IndItemValueVO> queryValue(String itemNo) {
|
List<IndItemValueVO> result = new ArrayList<IndItemValueVO>();
|
IndItemEntity indItem = indItemService.getInfoByNo(itemNo);
|
if (indItem == null) {
|
return result;
|
}
|
ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(indItem.getItemType());
|
switch (itemType) {
|
case ATOM:
|
result = atomItemHandler.queryValue(indItem.getId());
|
break;
|
case DER:
|
result = derItemHandler.queryValue(indItem.getId());
|
break;
|
case CAL:
|
result = calItemHandler.queryValue(indItem.getId());
|
break;
|
default:
|
break;
|
}
|
// 考虑指标精度和转换系数
|
handleResult(result,indItem);
|
return result;
|
}
|
|
public List<IndItemValueVO> queryValue(String itemNo, Date startTime, Date endTime) {
|
List<IndItemValueVO> result = new ArrayList<IndItemValueVO>();
|
IndItemEntity indItem = indItemService.getInfoByNo(itemNo);
|
if (indItem == null) {
|
return result;
|
}
|
ItemTypeEnum itemType = ItemTypeEnum.getEumByCode(indItem.getItemType());
|
switch (itemType) {
|
case ATOM:
|
result = atomItemHandler.queryValue(indItem.getId());
|
break;
|
case DER:
|
result = derItemHandler.queryValue(indItem.getId(), startTime, endTime);
|
break;
|
case CAL:
|
result = calItemHandler.queryValue(indItem.getId(), startTime, endTime);
|
break;
|
default:
|
break;
|
}
|
// 考虑指标精度和转换系数
|
handleResult(result,indItem);
|
return result;
|
}
|
|
private void handleResult(List<IndItemValueVO> result, IndItemEntity indItem) {
|
if (!CollectionUtils.isEmpty(result)) {
|
result.forEach(e -> {
|
if (e != null) {
|
Object dataValue = e.getDataValue();
|
if (dataValue != null && dataValue instanceof Number) {
|
BigDecimal value = new BigDecimal(dataValue.toString());
|
if (StringUtils.isNotBlank(indItem.getCoefficient())) {
|
value = value.multiply(new BigDecimal(indItem.getCoefficient()));
|
}
|
if (indItem.getPrecision() != null) {
|
value = value.setScale(indItem.getPrecision(), BigDecimal.ROUND_HALF_UP);
|
}
|
e.setDataValue(value.doubleValue());
|
}
|
}
|
|
});
|
}
|
}
|
}
|