Search in sources :

Example 6 with PanoramicRealTimeConsumptionGather

use of com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather in project new-cloud by xie-summer.

the class PanoramicProductMaterialsServiceImpl method productSummaryTask.

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void productSummaryTask(String name, String code, String date) {
    // 先查出来,再去更新
    Condition condition = new Condition(PanoramicProductMaterials.class, false);
    condition.createCriteria().andCondition("  substring(code, 1, 12) = '" + 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<PanoramicProductMaterials> consumptionList = productMaterialsMapper.selectByCondition(condition);
    PanoramicProductMaterials record = new PanoramicProductMaterials();
    record.setCode(code);
    record.setName(name);
    record.setValue("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 != consumptionList && consumptionList.size() > 0) {
        consumptionList.forEach(e -> {
            try {
                sumValue[0] += Double.parseDouble(e.getValue());
            } catch (NumberFormatException e1) {
                sumValue[0] = 0;
            }
            record.setUtime(e.getUtime());
            record.setDtime(null);
            record.setUnit(e.getUnit());
            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) PanoramicProductMaterials(com.monitor.model.productmaterials.PanoramicProductMaterials) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with PanoramicRealTimeConsumptionGather

use of com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather in project new-cloud by xie-summer.

the class PanoramicRealTimeConsumptionGatherServiceImpl method queryMonthlyStatisticsByDate.

@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED, rollbackFor = Exception.class)
public PanoramicRealTimeConsumptionGather queryMonthlyStatisticsByDate(String date, String code) {
    Condition condition = new Condition(PanoramicRealTimeConsumptionGather.class, false);
    condition.createCriteria().andCondition(" code ='" + code + "' AND f_id=2 AND delete_flag=1 " + " AND date_format(gather_time,'%Y%m') = date_format('" + date + "','%Y%m')");
    condition.setOrderByClause(" gather_time asc ");
    List<PanoramicRealTimeConsumptionGather> recordList = realTimeConsumptionGatherMapper.selectByCondition(condition);
    PanoramicRealTimeConsumptionGather gather = new PanoramicRealTimeConsumptionGather();
    gather.setCode(code);
    gather.setValue(0.0);
    gather.setCtime(DateUtil.parseTimestamp(date, "yyyy-MM-dd"));
    gather.setGatherTime(date);
    if (null != recordList && recordList.size() > 0) {
        recordList.forEach(e -> {
            gather.setValue(e.getValue() + gather.getValue());
            gather.setDeleteFlag(e.getDeleteFlag());
            gather.setfId(e.getfId());
            gather.setId(null);
            gather.setName(e.getName());
            gather.setOperator(e.getOperator());
            gather.setUnit(e.getUnit());
            gather.setDtime(null);
            gather.setUtime(e.getUtime());
        });
    }
    return gather;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) PanoramicRealTimeConsumptionGather(com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PanoramicRealTimeConsumptionGather (com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather)7 Transactional (org.springframework.transaction.annotation.Transactional)6 Condition (tk.mybatis.mapper.entity.Condition)6 PanoramicRealTimeConsumptionGatherDto (com.monitor.dto.realtimeconsumptiongather.PanoramicRealTimeConsumptionGatherDto)1 PanoramicDailyInventorySummary (com.monitor.model.dailyinventorysummary.PanoramicDailyInventorySummary)1 PanoramicProductMaterials (com.monitor.model.productmaterials.PanoramicProductMaterials)1 PanoramicProductOfflineMeasurement (com.monitor.model.productofflinemeasurement.PanoramicProductOfflineMeasurement)1 PanoramicRealTimeConsumption (com.monitor.model.realtimeconsumption.PanoramicRealTimeConsumption)1