package com.ruoyi.adapter.api;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.predict.domain.WtgType;
import com.ruoyi.predict.domain.WtgTypeTemperatureDef;
import com.ruoyi.predict.service.IWtgTypeService;
import com.ruoyi.predict.service.IWtgTypeTemperatureDefService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hlf
 * @date 2022/11/11 15:28
 * 文件说明：图迹运行参数数据
 */
@Api(value = "图迹运行参数数据Controller", tags = {"图迹运行参数数据操作接口"})
@Controller
@RequestMapping("/adapter/api/tjpodc")
public class TuJiParameterOperationDataController extends BaseController {

    @Autowired
    private IWtgTypeService wtgTypeService;

    @Autowired
    private IWtgTypeTemperatureDefService wtgTypeTemperatureDefService;

    @ApiOperation("运行参数")
    @GetMapping("/parameterOperation")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "unitType", value = "风机类型", required = true),
            @ApiImplicitParam(name = "powerRating", value = "额定功率"),
            @ApiImplicitParam(name = "cutInWspeed", value = "切入风速"),
            @ApiImplicitParam(name = "cutOutWspeed", value = "切出风速"),
            @ApiImplicitParam(name = "ratedWspeed", value = "额定风速"),
            @ApiImplicitParam(name = "lTemperature", value = "低温切出"),
            @ApiImplicitParam(name = "hTemperature", value = "高温切出"),
    })
    public AjaxResult parameterOperation(@RequestParam(value = "unitType") String unitType) {
        JSONObject json = new JSONObject();
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        TjDataFormat tjDataFormat = new TjDataFormat();
        WtgType wtgType = wtgTypeService.selectWtgTypeById(Convert.toLong(unitType));
        if (ObjectUtil.isNotNull(wtgType)) {
            tjDataFormat.setTypeName(wtgType.getTypeName());
            tjDataFormat.setPowerRating(wtgType.getPowerRating());
            tjDataFormat.setCutInWspeed(wtgType.getCutInWspeed());
            tjDataFormat.setCutOutWspeed(wtgType.getCutOutWspeed());
            tjDataFormat.setRatedWspeed(wtgType.getRatedWspeed());
            WtgTypeTemperatureDef wtgTypeTemperatureDef = wtgTypeTemperatureDefService.selectWtgTypeTemperatureDefById(wtgType.getTypeNo());
            if (ObjectUtil.isNotNull(wtgTypeTemperatureDef)) {
                tjDataFormat.setlTemperature(wtgTypeTemperatureDef.getlTemperature());
                tjDataFormat.sethTemperature(wtgTypeTemperatureDef.gethTemperature());
            }
        }
        tjDataFormatList.add(tjDataFormat);
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    public static class TjDataFormat {

        //风机类型
        private String typeName;

        //额定功率
        private Long powerRating;

        //切入风速
        private Double cutInWspeed;

        //切出风速
        private Double cutOutWspeed;

        //额定风速
        private Double ratedWspeed;

        //低温切出
        private Double lTemperature;

        //高温切出
        private Double hTemperature;

        public String getTypeName() {
            return typeName;
        }

        public void setTypeName(String typeName) {
            this.typeName = typeName;
        }

        public Long getPowerRating() {
            return powerRating;
        }

        public void setPowerRating(Long powerRating) {
            this.powerRating = powerRating;
        }

        public Double getCutInWspeed() {
            return cutInWspeed;
        }

        public void setCutInWspeed(Double cutInWspeed) {
            this.cutInWspeed = cutInWspeed;
        }

        public Double getCutOutWspeed() {
            return cutOutWspeed;
        }

        public void setCutOutWspeed(Double cutOutWspeed) {
            this.cutOutWspeed = cutOutWspeed;
        }

        public Double getRatedWspeed() {
            return ratedWspeed;
        }

        public void setRatedWspeed(Double ratedWspeed) {
            this.ratedWspeed = ratedWspeed;
        }

        public Double getlTemperature() {
            return lTemperature;
        }

        public void setlTemperature(Double lTemperature) {
            this.lTemperature = lTemperature;
        }

        public Double gethTemperature() {
            return hTemperature;
        }

        public void sethTemperature(Double hTemperature) {
            this.hTemperature = hTemperature;
        }
    }
}
