package org.springblade.modules.nh.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import jakarta.validation.Valid;

import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.wrapper.InverterUapWrapper;
import org.springblade.modules.nh.service.IInverterUapService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.constant.RoleConstant;
import java.util.Map;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

/**
 * 逆变器电流电压功率数据 控制器
 *
 * @author AlexWang
 * @since 2024-11-21
 */
@RestController
@AllArgsConstructor
@RequestMapping("nh/inverterUap")
@Tag(name = "逆变器电流电压功率数据", description = "逆变器电流电压功率数据接口")
public class InverterUapController extends BladeController {

	private final IInverterUapService inverterUapService;

	/**
	 * 逆变器电流电压功率数据 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description  = "传入inverterUap")
	public R<InverterUapVO> detail(InverterUapEntity inverterUap) {
		InverterUapEntity detail = inverterUapService.getOne(Condition.getQueryWrapper(inverterUap));
		return R.data(InverterUapWrapper.build().entityVO(detail));
	}
	/**
	 * 逆变器电流电压功率数据 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "分页", description  = "传入inverterUap")
	public R<IPage<InverterUapVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> inverterUap, Query query) {
		IPage<InverterUapEntity> pages = inverterUapService.page(Condition.getPage(query), Condition.getQueryWrapper(inverterUap, InverterUapEntity.class));
		return R.data(InverterUapWrapper.build().pageVO(pages));
	}

	/**
	 * 逆变器电流电压功率数据 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "分页", description  = "传入inverterUap")
	public R<IPage<InverterUapVO>> page(InverterUapVO inverterUap, Query query) {
		IPage<InverterUapVO> pages = inverterUapService.selectInverterUapPage(Condition.getPage(query), inverterUap);
		return R.data(pages);
	}

	/**
	 * 逆变器电流电压功率数据 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入inverterUap")
	public R save(@Valid @RequestBody InverterUapEntity inverterUap) {
		return R.status(inverterUapService.save(inverterUap));
	}

	/**
	 * 逆变器电流电压功率数据 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改", description  = "传入inverterUap")
	public R update(@Valid @RequestBody InverterUapEntity inverterUap) {
		return R.status(inverterUapService.updateById(inverterUap));
	}

	/**
	 * 逆变器电流电压功率数据 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "新增或修改", description  = "传入inverterUap")
	public R submit(@Valid @RequestBody InverterUapEntity inverterUap) {
		return R.status(inverterUapService.saveOrUpdate(inverterUap));
	}

	/**
	 * 逆变器电流电压功率数据 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "删除", description  = "传入ids")
	public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
		return R.status(inverterUapService.removeByIds(Func.toLongList(ids)));
	}

	@GetMapping(value = "inverterMap")
	@Operation(summary = "设备电流电压趋势")
	public Map<String, Object> inverterMap(@Parameter(name = "outStationId", required = true,description = "电站外部id")String outStationId,
										   @Parameter(name = "stateTime", required = true,description = "当前日期")String stateTime,
										   @Parameter(name = "ivType", required = true,description = "参数类型，voltage：电压，electricCurrent：电流 ，power：功率")String ivType) {
		return inverterUapService.inverterMap(outStationId, stateTime, ivType);
	}


//	/**
//	 * 导出数据
//	 */
//	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
//	@GetMapping("/export-inverterUap")
//	@ApiOperationSupport(order = 9)
//	@Operation(summary = "导出数据", description  = "传入inverterUap")
//	public void exportInverterUap(@Parameter(hidden = true) @RequestParam Map<String, Object> inverterUap, BladeUser bladeUser, HttpServletResponse response) {
//		QueryWrapper<InverterUapEntity> queryWrapper = Condition.getQueryWrapper(inverterUap, InverterUapEntity.class);
//		//if (!AuthUtil.isAdministrator()) {
//		//	queryWrapper.lambda().eq(InverterUap::getTenantId, bladeUser.getTenantId());
//		//}
//		queryWrapper.lambda().eq(InverterUapEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
//		List<InverterUapExcel> list = inverterUapService.exportInverterUap(queryWrapper);
//		ExcelUtil.export(response, "逆变器电流电压功率数据数据" + DateUtil.time(), "逆变器电流电压功率数据数据表", list, InverterUapExcel.class);
//	}

}
