package cn.com.energy.service.impl;

import cn.com.energy.mapper.DvMachineryDataMapper;
import cn.com.energy.model.DvMachineryData;
import cn.com.energy.service.IDvMachineryDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 操作日志 服务层处理
 * 
 * @author ruoyi
 */
@Service
public class DvMachineryDataServiceImpl extends ServiceImpl<DvMachineryDataMapper, DvMachineryData> implements IDvMachineryDataService
{
    @Autowired
    private DvMachineryDataMapper dvMachineryDataMapper;

    @Override
    public List<Map<String, Object>> selectElectric(DvMachineryData dvMachineryData) {
        return dvMachineryDataMapper.selectElectric(dvMachineryData);
    }

    @Override
    public List<Map<String, Object>> selectElectricByWeek() {
        List<Map<String, Object>> dvMachineryWeekDataList = dvMachineryDataMapper.selectElectricByWeek();
        List<Map<String,Object>> resultList=new ArrayList<>();
        double sum = 0;
        String value="0";
        for (Map<String, Object> data : dvMachineryWeekDataList) {
            Map map= new HashMap();
            double d=Double.parseDouble(data.get("parser_data").toString())*20;
            value = String.valueOf(d);
            BigDecimal valBig = new BigDecimal(value).setScale(2, RoundingMode.UP);
            sum += valBig.doubleValue();
            sum= Double.parseDouble(String.format("%.2f", sum));//保留两位小数
            map.put("day", data.get("day").toString());
            map.put("value", valBig);
            map.put("sum", sum);
            resultList.add(map);
        }
        return resultList;
    }
}
