package com.gyee.runeconomy.controller.threerate;


import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.dto.response.FwjslDTO;
import com.gyee.runeconomy.dto.response.QxjslDTO;
import com.gyee.runeconomy.service.threerate.ThreeRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 三率 前端控制器
 * </p>
 *
 * @author wang
 * @since 2022-11-22
 */
@RestController
@RequestMapping("//threerate")
public class ThreeRateController {


    @Autowired
    private ThreeRateService threeRateService;


    /**
     * 复位及时率
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/reset-timely-rate")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public R getResetTimelyRateInfo(
            @RequestParam(value = "companyId", required = false) String companyId,
            @RequestParam(value = "windpowerstationId", required = false) String windpowerstationId,
            @RequestParam(value = "beginDate", required = true) String beginDate,
            @RequestParam(value = "endDate", required = true) String endDate
    ) {

        List<FwjslDTO> resultlist = threeRateService.getResetTimelyRateInfo(companyId, windpowerstationId, beginDate, endDate);
        if (StringUtils.isNotNull(resultlist)) {
            return R.data(ResultMsg.ok(resultlist));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    /**
     * 状态转换率
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/state-conversion-rate")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public R getStateConversionRateInfo(
            @RequestParam(value = "companyId", required = false) String companyId,
            @RequestParam(value = "windpowerstationId", required = false) String windpowerstationId,
            @RequestParam(value = "beginDate", required = true) String beginDate,
            @RequestParam(value = "endDate", required = true) String endDate
    ) {
        Map<String, List<FwjslDTO>> resultlist = threeRateService.getStateConversionRateInfo(companyId, windpowerstationId, beginDate, endDate);
        if (StringUtils.isNotNull(resultlist)) {
            return R.data(ResultMsg.ok(resultlist));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    /**
     * 消缺及时率
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/defects-eliminat-rate")
    @ResponseBody
    @CrossOrigin(origins = "*", maxAge = 3600)
    public R getDefectsEliminatRateList(
            @RequestParam(value = "companyId", required = false) String companyId,
            @RequestParam(value = "windpowerstationId", required = false) String windpowerstationId,
            @RequestParam(value = "beginDate", required = true) String beginDate,
            @RequestParam(value = "endDate", required = true) String endDate
    ) {
        List<QxjslDTO> resultlist = threeRateService.getDefectsEliminatRateList(companyId, windpowerstationId, beginDate, endDate);
        if (StringUtils.isNotNull(resultlist)) {
            return R.data(ResultMsg.ok(resultlist));
        } else {
            return R.error(ResultMsg.error());
        }
    }

}
