| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.enums.DataPointFreq; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.data.enums.TimeGranularityEnum; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.factory.ItemEntityFactory; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | |
| | | |
| | | @Autowired |
| | | private ItemEntityFactory itemEntityFactory; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | /** |
| | | * prepareSampleInfo |
| | |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (columnItem.getParamType()) { |
| | | case "DATAPOINT": |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue()); |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue()); |
| | | break; |
| | | case "PREDICTITEM": |
| | | case PREDICTITEM: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case "IND-HIS": |
| | | case IND: |
| | | dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60); |
| | | break; |
| | | case "IND-PLAN": |
| | | case PLAN: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | default: |
| | |
| | | Date dateTime = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(originalTime); |
| | | switch (columnItem.getParamType()) { |
| | | case "DATAPOINT": |
| | | switch (ModelParamType.getEumByCode(columnItem.getParamType())) { |
| | | case DATAPOINT: |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | if (dataPoint == null) { |
| | | return null; |
| | | } |
| | | calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue() * -1); |
| | | break; |
| | | case "PREDICTITEM": |
| | | dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); |
| | | break; |
| | | case "IND-HIS": |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case "IND-PLAN": |
| | | dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60); |
| | | case PREDICTITEM: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case IND: |
| | | dateTime = calendar.getTime(); |
| | | break; |
| | | case PLAN: |
| | | ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId()); |
| | | if (planItem == null) { |
| | | return null; |
| | | } |
| | | dateTime = calculateDate(originalTime, false, columnItem.getDataLength(), |
| | | TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue()); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | switch (columnItem.getParamType()) { |
| | | case "DATAPOINT": |
| | | ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId()); |
| | | granularity = DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue(); |
| | | break; |
| | | case "PREDICTITEM": |
| | | granularity = itemEntityFactory.getItemById(columnItem.getParamId()).getGranularity(); |
| | |
| | | calendar.add(Calendar.SECOND, timeLength * granularity); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | public Date calculateDate(Date originalTime, Boolean backward, int dataLength, int field) { |
| | | int timeLength; |
| | | if (backward) { |
| | | timeLength = (-1) * dataLength; |
| | | } else { |
| | | timeLength = dataLength - 1; |
| | | } |
| | | Date desTime = originalTime; |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(desTime); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | // 数据长度 * 粒度 |
| | | calendar.add(Calendar.SECOND, timeLength); |
| | | return calendar.getTime(); |
| | | } |
| | | } |