package com.iailab.module.data.ind.collection.handler;
|
|
import com.iailab.module.data.ind.service.IndItemService;
|
import com.iailab.module.data.ind.service.IndItemService;
|
import com.iailab.module.data.ind.collection.utils.IndSqlUtils;
|
import com.iailab.module.data.ind.dao.IndItemValueDao;
|
import com.iailab.module.data.ind.dto.IndItemDTO;
|
import com.iailab.module.data.ind.dto.IndItemValueDTO;
|
import com.iailab.module.data.ind.service.IndItemService;
|
import com.iailab.module.data.ind.service.IndItemService;
|
import lombok.extern.slf4j.Slf4j;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月25日
|
*/
|
@Slf4j
|
@Component
|
public class AtomItemHandle {
|
|
@Resource
|
private IndItemService indItemService;
|
|
@Resource
|
private IndItemValueDao indItemValueDao;
|
|
|
public List<IndItemValueDTO> getItemSourceValue(String itemNo) {
|
List<IndItemValueDTO> result = new ArrayList<>();
|
IndItemDTO indItemDTO = indItemService.getItemAtom(itemNo);
|
if (indItemDTO == null) {
|
return result;
|
}
|
try {
|
StringBuilder sqlSelect = new StringBuilder();
|
sqlSelect.append(" data_value, data_time ");
|
indItemDTO.setSqlSelect(sqlSelect.toString());
|
indItemDTO.setSqlWhere(IndSqlUtils.getSqlWhere(indItemDTO.getTimeRange(), indItemDTO.getTimeGranularity()));
|
result = indItemValueDao.getSourceValue(indItemDTO);
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
|
result.forEach(item -> {
|
if (indItemDTO.getCoefficient() != null) {
|
item.setDataValue(item.getDataValue().multiply(indItemDTO.getCoefficient()));
|
}
|
if (indItemDTO.getPrecision() != null) {
|
item.setDataValue(item.getDataValue().setScale(indItemDTO.getPrecision(), BigDecimal.ROUND_HALF_UP));
|
}
|
item.setItemNo(itemNo);
|
});
|
return result;
|
}
|
|
public List<IndItemValueDTO> getItemSourceValue(String itemNo, String start, String end) {
|
List<IndItemValueDTO> result = new ArrayList<>();
|
IndItemDTO indItemDTO = indItemService.getItemAtom(itemNo);
|
if (indItemDTO == null) {
|
return result;
|
}
|
try {
|
StringBuilder sqlSelect = new StringBuilder();
|
sqlSelect.append(" data_value, data_time ");
|
indItemDTO.setSqlSelect(sqlSelect.toString());
|
indItemDTO.setSqlWhere(IndSqlUtils.getSqlWhereByRange(start, end));
|
result = indItemValueDao.getSourceValue(indItemDTO);
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
|
result.forEach(item -> {
|
if (indItemDTO.getCoefficient() != null) {
|
item.setDataValue(item.getDataValue().multiply(indItemDTO.getCoefficient()));
|
}
|
if (indItemDTO.getPrecision() != null) {
|
item.setDataValue(item.getDataValue().setScale(indItemDTO.getPrecision(), BigDecimal.ROUND_HALF_UP));
|
}
|
item.setItemNo(itemNo);
|
});
|
return result;
|
}
|
}
|