/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.nh.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.modules.nh.pojo.dto.InverterUapDTO;
import org.springblade.modules.nh.pojo.entity.InverterUapEntity;
import org.springblade.modules.nh.pojo.vo.InverterUapVO;
import org.springblade.modules.nh.excel.InverterUapExcel;
import org.springblade.modules.nh.mapper.InverterUapMapper;
import org.springblade.modules.nh.service.IInverterUapService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;

/**
 * 逆变器电流电压功率数据 服务实现类
 *
 * @author AlexWang
 * @since 2024-11-21
 */
@Service
public class InverterUapServiceImpl extends ServiceImpl<InverterUapMapper, InverterUapEntity> implements IInverterUapService {

	@Override
	public IPage<InverterUapVO> selectInverterUapPage(IPage<InverterUapVO> page, InverterUapVO inverterUap) {
		return page.setRecords(baseMapper.selectInverterUapPage(page, inverterUap));
	}


	@Override
	public List<InverterUapExcel> exportInverterUap(Wrapper<InverterUapEntity> queryWrapper) {
		List<InverterUapExcel> inverterUapList = baseMapper.exportInverterUap(queryWrapper);
		//inverterUapList.forEach(inverterUap -> {
		//	inverterUap.setTypeName(DictCache.getValue(DictEnum.YES_NO, InverterUap.getType()));
		//});
		return inverterUapList;
	}

	@Override
	public Map<String, Object> inverterMap(String outStationId, String stateTime,String ivType) {
		List<InverterUapDTO> list = baseMapper.findInverterUapList(outStationId,stateTime);
		Map<String,Object> maps = Maps.newHashMap();
		List<String> XStr= Lists.newArrayList();  //X轴
		List<Object> Yxjsjd= Lists.newArrayList();
		if("voltage".equals(ivType)){//电压
			List<Object> fdlY1= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY2= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY3= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY4= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY5= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY6= Lists.newArrayList();  //直流电压的Y轴
			for(InverterUapDTO dto :list){
				XStr.add(DateUtil.format(dto.getStateTime(),"HH:mm"));
				fdlY1.add(dto.getUv1());
				fdlY2.add(dto.getUv2());
				fdlY3.add(dto.getUv3());
				fdlY4.add(dto.getUv4());
				fdlY5.add(dto.getUv5());
				fdlY6.add(dto.getUv6());
			}
			Yxjsjd.add(fdlY1);
			Yxjsjd.add(fdlY2);
			Yxjsjd.add(fdlY3);
			Yxjsjd.add(fdlY4);
			Yxjsjd.add(fdlY5);
			Yxjsjd.add(fdlY6);

		}else if("electricCurrent".equals(ivType)){//电流
			List<Object> fdlY1= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY2= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY3= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY4= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY5= Lists.newArrayList();  //直流电压的Y轴
			List<Object> fdlY6= Lists.newArrayList();  //直流电压的Y轴
			for(InverterUapDTO dto :list){
				XStr.add(DateUtil.format(dto.getStateTime(),"HH:mm"));
				fdlY1.add(dto.getIa1());
				fdlY2.add(dto.getIa2());
				fdlY3.add(dto.getIa3());
				fdlY4.add(dto.getIa4());
				fdlY5.add(dto.getIa5());
				fdlY6.add(dto.getIa6());
			}
			Yxjsjd.add(fdlY1);
			Yxjsjd.add(fdlY2);
			Yxjsjd.add(fdlY3);
			Yxjsjd.add(fdlY4);
			Yxjsjd.add(fdlY5);
			Yxjsjd.add(fdlY6);

		}else if("power".equals(ivType)){//功率
			List<Object> fdlY= Lists.newArrayList();  //直流电压的Y轴
			for(InverterUapDTO dto :list){
				XStr.add(DateUtil.format(dto.getStateTime(),"HH:mm"));
				fdlY.add(dto.getTotalPower());
			}
			Yxjsjd.add(fdlY);
		}
		maps.put("Yxjsjd",Yxjsjd);
		maps.put("XStr",XStr);
		return maps;
	}


}
