package cn.cecep.talroad.service.impl;

import cn.cecep.talroad.domain.SMainDynamicControlParam;
import cn.cecep.talroad.mapper.SMainDynamicControlParamMapper;
import cn.cecep.talroad.service.ISMainDynamicControlParamService;
import cn.cecep.talroad.vo.SMainDynamicControlParamVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;




/**
 * 基本信息-废气、废水排口档案-动态管控信息调整 -参数Service业务层处理
 *
 * @author szhpt
 * @date 2023-02-02*/
@Service
public class SMainDynamicControlParamServiceImpl extends ServiceImpl<SMainDynamicControlParamMapper,SMainDynamicControlParam> implements ISMainDynamicControlParamService
{
    @Autowired
    private SMainDynamicControlParamMapper sMainDynamicControlParamMapper;

    /**
     * 查询基本信息-废气、废水排口档案-动态管控信息调整 -参数列表
     *
     * @param sMainDynamicControlParam 基本信息-废气、废水排口档案-动态管控信息调整 -参数
     * @return 基本信息-废气、废水排口档案-动态管控信息调整 -参数
     */
    @Override
    public List<SMainDynamicControlParam> selectSMainDynamicControlParamList(SMainDynamicControlParam sMainDynamicControlParam)
    {
        return sMainDynamicControlParamMapper.selectSMainDynamicControlParamList(sMainDynamicControlParam);
    }

    @Override
    public SMainDynamicControlParamVo.Table getParamTableData(String factoryId, String outletId, String controlTypeCode) {
        List<Map<String, Object>> data = sMainDynamicControlParamMapper.selectParamTableData(factoryId, outletId, controlTypeCode);

        // >> 将查询出来的纵向数据转为横向数据
        // 表头，即所有的参数
        List<Map<String, Object>> paramHeaders = new ArrayList<>();
        // 第一行数据，即所有参数的实测值
        Map<String, Object> row1 = new HashMap<>();
        // 第二行数据，即所有参数的验收标准值
        Map<String, Object> row2 = new HashMap<>();

        for (int i = 0; i < data.size(); i++) {
            String prop = "prop" + i;

            Map<String, Object> column = new HashMap<>();
            column.put("prop", prop);
            column.put("label", data.get(i).get("argumentsName"));
            paramHeaders.add(column);

            row1.put(prop, data.get(i).get("measuredValue"));
            row2.put(prop, data.get(i).get("standardValue"));
        }

        String prop = "valueType";
        Map<String, Object> column = new HashMap<>();
        column.put("prop", prop);
        column.put("label", "参数名称");

        paramHeaders.add(0, column);
        row1.put(prop, "实测值");
        row2.put(prop, "验收标准值");

        List<Map<String, Object>> paramData = new ArrayList<>();
        paramData.add(row1);
        paramData.add(row2);

        SMainDynamicControlParamVo.Table table = new SMainDynamicControlParamVo.Table();
        table.setParamHeaders(paramHeaders);
        table.setParamData(paramData);
        return table;
    }

}
