Search in sources :

Example 1 with PanoramicProductOfflineMeasurement

use of com.monitor.model.productofflinemeasurement.PanoramicProductOfflineMeasurement in project new-cloud by xie-summer.

the class PanoramicProductOfflineMeasurementServiceImpl method productOfflineSummaryTask.

/**
 * 产品消耗数据实时汇总
 * @param name
 * @param code
 * @param date
 */
private void productOfflineSummaryTask(String name, String code, String date) {
    // 
    Condition condition = new Condition(PanoramicProductOfflineMeasurement.class, false);
    condition.createCriteria().andCondition("	code = '" + code + "' " + "AND f_id=2 AND delete_flag=1 " + "AND date_format(utime,'%Y%m%d%H') = date_format('" + date + "','%Y%m%d%H')");
    List<PanoramicProductOfflineMeasurement> offlineMeasurementList = panoramicProductOfflineMeasurementMapper.selectByCondition(condition);
    PanoramicProductOfflineMeasurement record = new PanoramicProductOfflineMeasurement();
    record.setCode(code);
    record.setName(name);
    record.setValue(String.valueOf("0.0"));
    record.setCtime(DateUtil.getCurFullTimestamp());
    record.setId(null);
    record.setOperator("auto_task");
    record.setfId("2");
    record.setUnit("吨");
    record.setDeleteFlag(1);
    final double[] sumValue = { 0.0 };
    if (null != offlineMeasurementList && offlineMeasurementList.size() > 0) {
        offlineMeasurementList.forEach(e -> {
            sumValue[0] += Double.valueOf(e.getValue()).doubleValue();
            record.setUtime(e.getUtime());
            record.setDtime(null);
            record.setOperator(e.getOperator());
            record.setfId(e.getfId());
            record.setName(e.getName());
            record.setDeleteFlag(e.getDeleteFlag());
            record.setCtime(e.getCtime());
            record.setId(null);
        });
    }
    PanoramicRealTimeConsumptionGather selectOne = realTimeConsumptionGatherMapper.selectByGatherTime(code, date);
    Optional<PanoramicRealTimeConsumptionGather> one = Optional.ofNullable(selectOne);
    if (one.isPresent()) {
        selectOne.setValue(sumValue[0]);
        selectOne.setUtime(DateUtil.getCurFullTimestamp());
        selectOne.setCtime(selectOne.getUtime());
        selectOne.setOperator("auto_task_update");
        selectOne.setGatherTime(date);
        realTimeConsumptionGatherMapper.updateByPrimaryKeySelective(selectOne);
    } else {
        PanoramicRealTimeConsumptionGather gather = new PanoramicRealTimeConsumptionGather();
        gather.setCode(code);
        gather.setName(name);
        gather.setDeleteFlag(record.getDeleteFlag());
        gather.setfId(record.getfId());
        gather.setGatherTime(date);
        gather.setId(null);
        gather.setCtime(DateUtil.getCurFullTimestamp());
        gather.setName(record.getName());
        gather.setOperator(record.getOperator());
        gather.setUnit(record.getUnit());
        gather.setDtime(record.getDtime());
        gather.setUtime(gather.getCtime());
        gather.setValue(sumValue[0]);
        realTimeConsumptionGatherMapper.insert(gather);
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PanoramicRealTimeConsumptionGather(com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather) PanoramicProductOfflineMeasurement(com.monitor.model.productofflinemeasurement.PanoramicProductOfflineMeasurement)

Aggregations

PanoramicProductOfflineMeasurement (com.monitor.model.productofflinemeasurement.PanoramicProductOfflineMeasurement)1 PanoramicRealTimeConsumptionGather (com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather)1 Condition (tk.mybatis.mapper.entity.Condition)1