| | |
| | | import com.ycl.platform.base.CheckIndex; |
| | | import constant.ApiConstants; |
| | | import constant.CheckConstants; |
| | | import enumeration.general.PublishType; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | @Slf4j |
| | | public class IndexCalculationUtils { |
| | | //检查是否存在当日数据 |
| | | public <I extends CheckIndex> I getCheckIndex(String key, List<I> checkIndexList, Class<I> clazz) { |
| | | I checkIndex; |
| | | public <T extends CheckIndex> T getCheckIndex(String key, List<T> checkIndexList, Class<T> clazz) { |
| | | T checkIndex; |
| | | |
| | | // 检查是否已存在今日数据 |
| | | Optional<I> existingIndex = checkIndexList.stream() |
| | | Optional<T> existingIndex = checkIndexList.stream() |
| | | .filter(index -> key.startsWith(ApiConstants.Province) ? |
| | | CheckConstants.Examine_Tag_Province.equals(index.getExamineTag()) && key.split("_")[1].equals(index.getDeptId().toString()) |
| | | : key.startsWith(ApiConstants.Dept) ? CheckConstants.Examine_Tag_Dept.equals(index.getExamineTag()) && key.split("_")[1].equals(index.getDeptId().toString()) |
| | | : CheckConstants.Examine_Tag_County.equals(index.getExamineTag()) && key.equals(index.getDeptId().toString())) |
| | | .findFirst(); |
| | | |
| | |
| | | } else { |
| | | try { |
| | | checkIndex = clazz.getDeclaredConstructor().newInstance(); |
| | | checkIndex.setDeptId(key.startsWith(ApiConstants.Province) ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); |
| | | checkIndex.setExamineTag(key.startsWith(ApiConstants.Province) ? CheckConstants.Examine_Tag_Province : CheckConstants.Examine_Tag_County); |
| | | checkIndex.setDeptId(key.startsWith(ApiConstants.Province) || key.startsWith(ApiConstants.Dept) ? Long.parseLong(key.split("_")[1]) : Long.parseLong(key)); |
| | | checkIndex.setExamineTag(key.startsWith(ApiConstants.Province) ? CheckConstants.Examine_Tag_Province : key.startsWith(ApiConstants.Dept) ? CheckConstants.Examine_Tag_Dept : CheckConstants.Examine_Tag_County); |
| | | checkIndex.setCreateTime(new Date()); |
| | | //默认发布 |
| | | checkIndex.setPublish(PublishType.PUBLISHED.getCode()); |
| | | } catch (Exception e) { |
| | | checkIndex = null; |
| | | log.error("无法创建 checkIndex 实例", e); |