package com.gyee.frame.controller.contrast;

import com.gyee.frame.common.conf.AjaxStatus;
import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.custom.BenchMarkVo;
import com.gyee.frame.model.custom.ConditionVo;
import com.gyee.frame.model.custom.DataVo;
import com.gyee.frame.model.custom.Tablepar;
import com.gyee.frame.service.contrast.*;
import com.gyee.frame.util.BenchmarkUtil;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

@Controller
@RequestMapping("/contrast")
@Api(value = "对标管理管理",tags =  "对标管理管理")
public class ContrastController {

    @Resource
    private ContrastWpService contrastWpService;
    @Resource
    private ContrastPjService contrastPjService;
    @Resource
    private ContrastWtService contrastWtService;
    @Resource
    private ContrastZjService contrastZjService;
    @Resource
    private ContrastLnService contrastLnService;

    /**
     * 查询性能对标列表
     **/
    @PostMapping("/benchmarkLossList")
    @ResponseBody
    @ApiOperation(value = "查询性能对标列表", notes = "查询性能对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkLossList(Tablepar tablepar, String wpId, String beginDate, String endDate) {

        List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastWpService.benchmarkLossList(wpId, beginDate,  endDate);


            if (vos != null && !vos.isEmpty()) {
                BenchmarkUtil bu = new BenchmarkUtil();
                vos = bu.getBenchMarkOrder(vos);
                //默认综合排序，不需要从新排序，除非指定字段排序
                if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
                {
                    vos = bu.getBenchMarkOrder(vos,tablepar);
                }
                return AjaxResult.successData(AjaxStatus.success.code, vos);
            } else {
                return AjaxResult.successData(AjaxStatus.success.code, vos);
            }

    }

    /**
     * 查询场内对标列表信息
     **/
    @PostMapping("/benchmarkWpList")
    @ResponseBody
    @ApiOperation(value = "查询场内对标列表", notes = "查询场内对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkWpList(Tablepar tablepar, String wpId, String beginDate, String endDate) {

        List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastWpService.benchmarkWpList(wpId, beginDate,  endDate);


        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }
    /**
     * 查询场内风机列表信息
     **/
    @PostMapping("/benchmarkWpInWtList")
    @ResponseBody
    @ApiOperation(value = "查询场内对标风机对标列表", notes = "查询场内对标风机对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkWpInWtList(Tablepar tablepar, String wpId,String wtId, String beginDate, String endDate) {

        List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastWtService.benchmarkWpInWtList(wpId,wtId,beginDate, endDate);

        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    /**
     * 查询场际对标列表信息
     **/
    @PostMapping("/benchmarkWpOutList")
    @ResponseBody
    @ApiOperation(value = "查询场际对标列表", notes = "查询场际对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkWpOutList(Tablepar tablepar, String wpId, String beginDate, String endDate) {


        List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastWpService.benchmarkWpOutList(wpId, beginDate,  endDate);



        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    /**
     * 查询场际对标图表
     **/
    @GetMapping("/findWpPowerOutChat")
    @ResponseBody
    @ApiOperation(value = "查询场际对标图表", notes = "查询场际对标图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findWpPowerOutChat(String wpId, String beginDate, String endDate) throws Exception {
        List<String> wpids = new ArrayList<String>();
        if (StringUtils.notEmp(wpId)) {
            if (wpId.indexOf(",") != -1) {
                String[] strs = wpId.split(",");
                if (strs.length > 0) {
                    for (int i = 0; i < strs.length; i++) {
                        wpids.add(strs[i]);
                    }
                }
            } else {
                wpids.add(wpId);
            }

        }

        Date begin = DateUtils.parseDate(beginDate);
        Date end = DateUtils.parseDate(endDate);

        List<DataVo> vos =new ArrayList<>();

            vos = contrastWpService.findWpPowerChat(wpids, begin, end);


        if (vos != null && !vos.isEmpty()) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }


    /**
     * 查询项目对标列表信息
     **/
    @PostMapping("/benchmarkPjList")
    @ResponseBody
    @ApiOperation(value = "查询项目对标列表", notes = "查询项目对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pjId", value = "项目编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkPjList(Tablepar tablepar, String wpId,String pjId, String beginDate, String endDate) {

          List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastPjService.benchmarkPjList(wpId,pjId, beginDate,  endDate);



        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    /**
     * 查询项目对标图表
     **/
    @GetMapping("/findPjPowerChat")
    @ResponseBody
    @ApiOperation(value = "查询项目对标图表", notes = "查询项目对标图表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pjId", value = "项目编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findPjPowerChat(String wpId,String pjId, String beginDate, String endDate) throws Exception {

        List<DataVo> vos =new ArrayList<>();

            vos = contrastPjService.findPjPowerChat(wpId,pjId, beginDate, endDate);



        if (vos != null && !vos.isEmpty()) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }

    /**
     * 查询线路对标列表信息
     **/
    @PostMapping("/benchmarkLnList")
    @ResponseBody
    @ApiOperation(value = "查询线路对标列表", notes = "查询线路对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "lnId", value = "线路编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkLnList(Tablepar tablepar, String wpId,String lnId, String beginDate, String endDate) {


        List<BenchMarkVo> vos =new ArrayList<>();


            vos =contrastLnService.benchmarkLnList(wpId,lnId, beginDate,  endDate);



        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    /**
     * 查询线路对标图表
     **/
    @GetMapping("/findLnPowerChat")
    @ResponseBody
    @ApiOperation(value = "查询线路对标列表", notes = "查询线路对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "lnId", value = "线路编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult findLnPowerChat(String wpId,String lnId, String beginDate, String endDate) throws Exception {

        List<DataVo> vos =new ArrayList<>();


        vos = contrastLnService.findLnPowerChat(wpId,lnId, beginDate, endDate);

        if (vos != null && !vos.isEmpty()) {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }
    }
    /**
     * 查询风机列表信息
     **/
    @PostMapping("/benchmarkWtList")
    @ResponseBody
    @ApiOperation(value = "查询风机对标列表", notes = "查询风机对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkWtList(Tablepar tablepar, String wpId,String wtId, String beginDate, String endDate) {

        List<BenchMarkVo> vos =contrastWtService.benchmarkWtList(wpId,wtId, beginDate,  endDate);

        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }




    /**
     * 新增值际对标
     **/
    @PostMapping("/addBenchmarkZj")
    @ResponseBody
    @ApiOperation(value = "新增值际对标", notes = "新增值际对标")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "风场编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "month", value = "月份", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "zjs", value = "值际类型 1:上旬,2:中旬,3:下旬", required = true, dataType = "string", paramType = "query")})

    public AjaxResult addBenchmarkZj(HttpServletRequest request,Tablepar tablepar, String wpId, String year, String month, String zjs) {

        List<BenchMarkVo> vos=null;
        // List<BenchMarkVo> vos =contrastWtService.benchmarkWtList(wpId,wtId,beginDate, endDate);

        contrastZjService.addBenchmarkZj(request, wpId, year, month, zjs);


        if (null != request.getSession().getAttribute("bmvos")) {
            vos = (List<BenchMarkVo>) request.getSession().getAttribute("bmvos");
        } else {
            vos =new ArrayList<>();

        }

        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }

    /**
     * 值际对标列表
     **/
    @PostMapping("/benchmarkZjList")
    @ResponseBody
    @ApiOperation(value = "查询值际对标列表", notes = "查询值际对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query")})

    public AjaxResult benchmarkZjList(HttpServletRequest request,Tablepar tablepar) {

        List<BenchMarkVo> vos=null;

        if (null != request.getSession().getAttribute("bmvos")) {
            vos = (List<BenchMarkVo>) request.getSession().getAttribute("bmvos");
        } else {
            vos =new ArrayList<>();

        }

        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }


    /**
     * 查询值际风机列表信息
     **/
    @PostMapping("/benchmarkZjWtList")
    @ResponseBody
    @ApiOperation(value = "查询风机对标列表", notes = "查询风机对标列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tablepar", value = "分页对象", required = true, dataType = "tablepar", paramType = "query"),
            @ApiImplicitParam(name = "cid", value = "值际对标编号", required = true, dataType = "string", paramType = "query")})

    public AjaxResult benchmarkZjWtList(HttpServletRequest request,Tablepar tablepar, String cid) {
        List<BenchMarkVo> vos=new ArrayList<>();
        Map<String, List<ConditionVo>> ctmap = null;
        if (null != request.getSession().getAttribute("bmwtvos")) {
            ctmap = (Map<String, List<ConditionVo>>) request.getSession().getAttribute("bmwtvos");
        } else {
            ctmap = new HashMap<String, List<ConditionVo>>();
        }

        if (StringUtils.notEmp(cid) && ctmap.containsKey(cid)) {
            List<ConditionVo> ctvos = ctmap.get(cid);
            Map<String, BenchMarkVo> bmmap = new HashMap<String, BenchMarkVo>();
            for (ConditionVo ct : ctvos) {

                String wpId = ct.getWpId();
                String beginDate = ct.getBeginDate();
                String endDate =ct.getEndDate();

                bmmap=contrastWtService.benchmarkZjInWtList(wpId,null,beginDate,endDate);
            }

            Set<Map.Entry<String, BenchMarkVo>> set = bmmap.entrySet();
            for (Iterator<Map.Entry<String, BenchMarkVo>> it = set.iterator(); it.hasNext();) {
                Map.Entry<String, BenchMarkVo> entry = (Map.Entry<String, BenchMarkVo>) it.next();
                // System.out.println(entry.getKey() + "--->" +
                // entry.getValue());
                BenchMarkVo bm = entry.getValue();
                totalBenchmarkInfo(bm);
                vos.add(bm);
            }
        }

        if (vos != null && !vos.isEmpty()) {
            BenchmarkUtil bu = new BenchmarkUtil();
            vos = bu.getBenchMarkOrder(vos);
            //默认综合排序，不需要从新排序，除非指定字段排序
            if(StringUtils.notEmp(tablepar) && StringUtils.isNotEmpty(tablepar.getOrderByColumn()) )
            {
                vos = bu.getBenchMarkOrder(vos,tablepar);
            }
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        } else {
            return AjaxResult.successData(AjaxStatus.success.code, vos);
        }

    }


    private void totalBenchmarkInfo(BenchMarkVo bm) {
        double scadafdl = bm.getScadafdl(); // scada发电量
        double qfss = bm.getQfss();// 欠发损失发电量
        double gzss = bm.getGzss();// 故障损失发电量
        double whss = bm.getWhss();// 维护损失发电量
        double xdss = bm.getXdss();// 限电损失发电量
        double llfdl = scadafdl + qfss + gzss + whss + xdss;// 理论发电量

        if (llfdl != 0) {
            double temp = xdss;

            BigDecimal b1 = new BigDecimal(temp);
            BigDecimal b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 弃风率
            bm.setQfl(temp);
            temp = qfss;

            b1 = new BigDecimal(temp);
            b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 性能损失率
            bm.setXnssl(temp);

            temp = gzss;

            b1 = new BigDecimal(temp);
            b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 故障损失率
            bm.setGzssl(temp);

            temp = whss;

            b1 = new BigDecimal(temp);
            b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 检修损失率
            bm.setJxssl(temp);
            temp = 0;

            b1 = new BigDecimal(temp);
            b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 受累损失率
            bm.setSlssl(temp);
            temp = scadafdl;

            b1 = new BigDecimal(temp);
            b2 = new BigDecimal(llfdl);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 风能利用率
            bm.setFnlyl(temp);
            // 受累损失电量
            bm.setSlssl(0.0);
        } else {
            // temp 风能利用率
            bm.setFnlyl(0.0);
            // temp 故障损失率
            bm.setGzssl(0.0);
            // temp 检修损失率
            bm.setJxssl(0.0);
            // temp 弃风率
            bm.setQfl(0.0);
            // temp 受累损失率
            bm.setSlssl(0.0);
            // 受累损失电量
            bm.setSlssl(0.0);
            // temp 性能损失率
            bm.setXnssl(0.0);
        }

        if (bm.getFwzcs() != 0) {

            double temp1 = bm.getFwcs();// 5分钟复位及时次数
            double temp2 = bm.getFwzcs();// 总复位次数

            double temp = 0;

            BigDecimal b1 = new BigDecimal(temp1);
            BigDecimal b2 = new BigDecimal(temp2);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();
            // temp 复位及时率
            bm.setFwjsl(temp);
        } else {
            bm.setFwjsl(100.0);
        }

        if (bm.getZtzcs() != 0) {

            double temp1 = bm.getZtcs();// 小于3米5分钟转换及时次数
            double temp2 = bm.getZtzcs();// 小于3米状态转换总次数

            double temp = 0;

            BigDecimal b1 = new BigDecimal(temp1);
            BigDecimal b2 = new BigDecimal(temp2);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();

            // temp 状态转换及时率
            bm.setZtzhjsl(temp);
        } else {
            bm.setZtzhjsl(100.0);
        }

        if (bm.getXqzcs() != 0) {

            double temp1 = bm.getXqcs();// 消缺及时次数
            double temp2 = bm.getXqzcs();// 故障总次数

            double temp = 0;

            BigDecimal b1 = new BigDecimal(temp1);
            BigDecimal b2 = new BigDecimal(temp2);

            temp = b1.divide(b2, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue();

            // temp 消缺及时率
            bm.setXqjsl(temp);
        } else {
            bm.setXqjsl(100.0);
        }
    }
}

