package com.ruoyi.predict.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.predict.domain.*;
import com.ruoyi.predict.service.*;
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.PostMapping;
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/1/17 10:37
 * 文件说明：场站管理
 */
@Api(value = "场站管理Controller", tags = {"场站管理操作接口"})
@Controller
@RequestMapping("/predict/api/smc")
public class StationManagementController extends BaseController {

    @Autowired
    private IWindplantService windplantService;

    @Autowired
    private IPvPowerStationService pvPowerStationService;

    @Autowired
    private IAreaConfigService areaConfigService;

    @Autowired
    private IRtuService rtuService;

    @Autowired
    private IWindplantprojectService windplantprojectService;

    @Autowired
    private ICollectorwireprojectService collectorwireprojectService;

    @Autowired
    private IAreaService areaService;

    @Autowired
    private IWturService wturService;

    @Autowired
    private IWfProjectCwWtgService wfProjectCwWtgService;

    @Autowired
    private IWtgTypeService wtgTypeService;

    @Autowired
    private IWtgTypeTemperatureDefService wtgTypeTemperatureDefService;

    @ApiOperation("获取场站信息列表")
    @PostMapping("/getStationsList")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaBelongs", value = "所属区域"),
            @ApiImplicitParam(name = "stationName", value = "场站名称"),
            @ApiImplicitParam(name = "stationCode", value = "场站代码"),
            @ApiImplicitParam(name = "stationType", value = "场站类型"),
            @ApiImplicitParam(name = "stationLongitude", value = "场站经度"),
            @ApiImplicitParam(name = "stationLatitude", value = "场站纬度"),
            @ApiImplicitParam(name = "numberUnits", value = "机组数量"),
            @ApiImplicitParam(name = "installedCapacity", value = "装机容量MW"),
            @ApiImplicitParam(name = "affiliatedCompany", value = "所属公司"),
    })
    public TableDataInfo getStationsList(StationInformation stationInformation) {
        startPage();
        List<StationInformation> list = new ArrayList<>();
        Windplant windplant = new Windplant();
        windplant.setAreaNo(stationInformation.getAreaNo());
        List<Windplant> windplantList = windplantService.selectWindplantList(windplant);
        for (Windplant wp : windplantList) {
            StationInformation si = new StationInformation();
            si.setAreaNo(wp.getAreaNo());
            si.setNo(wp.getWindplantNo());
            si.setAreaBelongs(wp.getAreaName());
            si.setStationName(wp.getName());
            si.setStationCode(wp.getPathname());
            si.setStationType(wp.getRtuTypeName());
            si.setStationLongitude(wp.getBsP());
            si.setStationLatitude(wp.getBsQ());
            si.setNumberUnits(wp.getInstallWtg());
            si.setInstalledCapacity(wp.getInstallPower());
            si.setAffiliatedCompany(wp.getCompanyNo());
            si.setItemVal(wp.getItemVal());
            list.add(si);
        }
        PvPowerStation pvPowerStation = new PvPowerStation();
        pvPowerStation.setAreaNo(stationInformation.getAreaNo());
        List<PvPowerStation> pvPowerStationList = pvPowerStationService.selectPvPowerStationList(pvPowerStation);
        for (PvPowerStation pps : pvPowerStationList) {
            StationInformation si = new StationInformation();
            si.setAreaNo(pps.getAreaNo());
            si.setNo(pps.getPvStationNo());
            si.setAreaBelongs(pps.getAreaName());
            si.setStationName(pps.getName());
            si.setStationCode(pps.getRef());
            si.setStationType(pps.getRtuTypeName());
            si.setStationLongitude(pps.getLongtitude());
            si.setStationLatitude(pps.getLatitude());
            si.setNumberUnits(pps.getPvCellCnt());
            si.setInstalledCapacity(pps.getRatingPower());
            si.setAffiliatedCompany(pps.getCompanyNo());
            si.setItemVal(pps.getItemVal());
            list.add(si);
        }
        return getDataTable(list);
    }

    @ApiOperation("添加场站信息")
    @PostMapping("/addStations")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaNo", value = "区域名称", required = true),
            @ApiImplicitParam(name = "stationName", value = "场站名称", required = true),
            @ApiImplicitParam(name = "stationCode", value = "场站代码", required = true),
            @ApiImplicitParam(name = "stationType", value = "场站类型", required = true),
            @ApiImplicitParam(name = "stationLongitude", value = "场站经度", required = true),
            @ApiImplicitParam(name = "stationLatitude", value = "场站纬度", required = true),
            @ApiImplicitParam(name = "affiliatedCompany", value = "所属公司", required = true),
    })
    public AjaxResult addStations(StationInformation stationInformation) {
        if (UserConstants.USER_NAME_NOT_UNIQUE.equals(windplantService.checkWindplantNameUnique(stationInformation.getStationName())) || UserConstants.USER_NAME_NOT_UNIQUE.equals(pvPowerStationService.checkPvStationNameUnique(stationInformation.getStationName()))) {
            return error("新增场站'" + stationInformation.getStationName() + "'失败，场站已存在");
        }
        if ("0".equals(stationInformation.getStationType())) {//风电场
            Windplant windplant = new Windplant();
            Long windplantNo;
            if (windplantService.selectNewData() == null) {
                windplantNo = Convert.toLong(1);
            } else {
                if (windplantService.selectNewData() > pvPowerStationService.selectNewData()) {
                    windplantNo = windplantService.selectNewData() + 1;
                } else {
                    windplantNo = pvPowerStationService.selectNewData() + 1;
                }
            }
            windplant.setWindplantNo(windplantNo);
            windplant.setName(stationInformation.getStationName());
            windplant.setPathname(stationInformation.getStationCode());
            windplant.setBsP(stationInformation.getStationLongitude());
            windplant.setBsQ(stationInformation.getStationLatitude());
            windplant.setCompanyNo(stationInformation.getAffiliatedCompany());
            windplantService.insertWindplant(windplant);
            AreaConfig areaConfig = new AreaConfig();
            areaConfig.setAreaNo(stationInformation.getAreaNo());
            areaConfig.setRtuNo(windplantNo);
            areaConfigService.insertAreaConfig(areaConfig);
            Rtu rtu = new Rtu();
            rtu.setRtuNo(windplantNo);
            rtu.setRtuType(Convert.toLong(stationInformation.getStationType()));
            rtuService.insertRtu(rtu);
        } else if ("4".equals(stationInformation.getStationType())) {//光伏电站
            PvPowerStation pvPowerStation = new PvPowerStation();
            Long pvStationNo;
            if (pvPowerStationService.selectNewData() == null) {
                pvStationNo = Convert.toLong(1);
            } else {
                if (pvPowerStationService.selectNewData() > windplantService.selectNewData()) {
                    pvStationNo = pvPowerStationService.selectNewData() + 1;
                } else {
                    pvStationNo = windplantService.selectNewData() + 1;
                }
            }
            pvPowerStation.setPvStationNo(pvStationNo);
            pvPowerStation.setName(stationInformation.getStationName());
            pvPowerStation.setRef(stationInformation.getStationCode());
            pvPowerStation.setLongtitude(stationInformation.getStationLongitude());
            pvPowerStation.setLatitude(stationInformation.getStationLatitude());
            pvPowerStation.setCompanyNo(stationInformation.getAffiliatedCompany());
            pvPowerStationService.insertPvPowerStation(pvPowerStation);
            AreaConfig areaConfig = new AreaConfig();
            areaConfig.setAreaNo(stationInformation.getAreaNo());
            areaConfig.setRtuNo(pvStationNo);
            areaConfigService.insertAreaConfig(areaConfig);
            Rtu rtu = new Rtu();
            rtu.setRtuNo(pvStationNo);
            rtu.setRtuType(Convert.toLong(stationInformation.getStationType()));
            rtuService.insertRtu(rtu);
        }
        return AjaxResult.success();
    }

    @ApiOperation("修改场站信息")
    @PostMapping("/updateStations")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "no", value = "场站编号", required = true),
            @ApiImplicitParam(name = "areaNo", value = "区域名称"),
            @ApiImplicitParam(name = "stationName", value = "场站名称"),
            @ApiImplicitParam(name = "stationCode", value = "场站代码"),
            @ApiImplicitParam(name = "stationType", value = "场站类型"),
            @ApiImplicitParam(name = "stationLongitude", value = "场站经度"),
            @ApiImplicitParam(name = "stationLatitude", value = "场站纬度"),
            @ApiImplicitParam(name = "affiliatedCompany", value = "所属公司"),
    })
    public AjaxResult updateStations(StationInformation stationInformation) {
        if (UserConstants.USER_NAME_NOT_UNIQUE.equals(windplantService.checkWindplantNameUnique(stationInformation.getStationName())) || UserConstants.USER_NAME_NOT_UNIQUE.equals(pvPowerStationService.checkPvStationNameUnique(stationInformation.getStationName()))) {
            return error("修改场站'" + stationInformation.getStationName() + "'失败，场站已存在");
        }
        if ("0".equals(stationInformation.getStationType())) {//风电场
            Windplant windplant = windplantService.selectWindplantById(stationInformation.getNo());
            windplant.setName(stationInformation.getStationName());
            windplant.setPathname(stationInformation.getStationCode());
            windplant.setBsP(stationInformation.getStationLongitude());
            windplant.setBsQ(stationInformation.getStationLatitude());
            windplant.setCompanyNo(stationInformation.getAffiliatedCompany());
            windplantService.insertWindplant(windplant);
            AreaConfig areaConfig = areaConfigService.selectAreaConfigByRtuNo(windplant.getWindplantNo());
            if (!stationInformation.getAreaNo().equals(areaConfig.getAreaNo())) {
                areaConfig.setAreaNo(stationInformation.getAreaNo());
                areaConfigService.updateAreaConfig(areaConfig);
            }
        } else if ("4".equals(stationInformation.getStationType())) {//光伏电站
            PvPowerStation pvPowerStation = pvPowerStationService.selectPvPowerStationById(stationInformation.getNo());
            pvPowerStation.setName(stationInformation.getStationName());
            pvPowerStation.setRef(stationInformation.getStationCode());
            pvPowerStation.setLongtitude(stationInformation.getStationLongitude());
            pvPowerStation.setLatitude(stationInformation.getStationLatitude());
            pvPowerStation.setCompanyNo(stationInformation.getAffiliatedCompany());
            pvPowerStationService.insertPvPowerStation(pvPowerStation);
            AreaConfig areaConfig = areaConfigService.selectAreaConfigByRtuNo(pvPowerStation.getPvStationNo());
            if (!stationInformation.getAreaNo().equals(areaConfig.getAreaNo())) {
                areaConfig.setAreaNo(stationInformation.getAreaNo());
                areaConfigService.updateAreaConfig(areaConfig);
            }
        }
        return AjaxResult.success();
    }

    @ApiOperation("删除场站信息")
    @PostMapping("/deleteStations")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "no", value = "场站编号", required = true),
            @ApiImplicitParam(name = "stationType", value = "场站类型", required = true),
    })
    public AjaxResult deleteStations(@RequestParam(value = "no") String no,
                                     @RequestParam(value = "stationType") String stationType) {
        if ("风电场".equals(stationType)) {//风电场
            //删除风场信息
            windplantService.deleteWindplantById(Convert.toLong(no));
        } else if ("光伏电站".equals(stationType)) {//光伏电站
            //删除光伏电站信息
            pvPowerStationService.deletePvPowerStationById(Convert.toLong(no));

        }
        //删除新能源场站配置信息
        rtuService.deleteRtuById(Convert.toLong(no));
        //删除区域场站关联表信息
        areaConfigService.deleteAreaConfigByRtuNo(Convert.toLong(no));
        //删除期次配置信息
        windplantprojectService.deleteWindplantprojectByWindplantNo(Convert.toLong(no));
        //删除集电线配置信息
        collectorwireprojectService.deleteCollectorwireprojectByWindplantNo(Convert.toLong(no));
        //风机装机容量
        double installedCapacity = 0;
        //删除风机配置信息
        List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByWindplantNo(Convert.toLong(no));
        for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList) {
            Wtur wtur = wturService.selectWturById(wfProjectCwWtg.getWtgNo());
            if (ObjectUtil.isNotNull(wtur)) {
                if (wtur.getRatedPower() != null){
                    installedCapacity += wtur.getRatedPower();
                }
                wtgTypeService.deleteWtgTypeById(wtur.getWtgType());
            }
            wtgTypeTemperatureDefService.deleteWtgTypeTemperatureDefById(wtur.getWtgType());
            wturService.deleteWturById(wfProjectCwWtg.getWtgNo());
        }
        wfProjectCwWtgService.deleteWfProjectCwWtgByWindplantNo(Convert.toLong(no));
        //减去当前数据下的风机的总装机容量
        AreaConfig areaConfig = areaConfigService.selectAreaConfigByRtuNo(Convert.toLong(no));
        if (ObjectUtil.isNotNull(areaConfig)) {
            Area area = areaService.selectAreaById(areaConfig.getAreaNo());
            if (ObjectUtil.isNotNull(area)) {
                if (area.getInstallPower() != null){
                    area.setInstallPower(area.getInstallPower() - installedCapacity);
                    areaService.updateArea(area);
                }
            }
        }
        return AjaxResult.success();
    }

    @ApiOperation("获取期次信息列表")
    @PostMapping("/getWindplantprojectList")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "windplantName或pvStationName", value = "所属场站"),
            @ApiImplicitParam(name = "projectName", value = "期次名称"),
            @ApiImplicitParam(name = "projectIssue", value = "期次代码"),
            @ApiImplicitParam(name = "unitsNumber", value = "机组数量"),
            @ApiImplicitParam(name = "projectCapacity", value = "装机容量MW"),
    })
    public TableDataInfo getWindplantprojectList(Windplantproject windplantproject) {
        startPage();
        List<Windplantproject> list = windplantprojectService.selectWindplantprojectList(windplantproject);
        return getDataTable(list);
    }

    @ApiOperation("添加期次信息")
    @PostMapping("/addWindplantproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpNo", value = "场站名称", required = true),
            @ApiImplicitParam(name = "projectName", value = "期次名称", required = true),
            @ApiImplicitParam(name = "projectIssue", value = "期次代码", required = true),
    })
    public AjaxResult addWindplantproject(Windplantproject windplantproject) {
        Long projectNo;
        if (windplantprojectService.selectNewData() == null) {
            projectNo = Convert.toLong(1);
        } else {
            projectNo = windplantprojectService.selectNewData() + 1;
        }
        windplantproject.setProjectNo(projectNo);
        windplantprojectService.insertWindplantproject(windplantproject);
        return AjaxResult.success();
    }

    @ApiOperation("修改期次信息")
    @PostMapping("/updateWindplantproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "wpNo", value = "场站名称"),
            @ApiImplicitParam(name = "projectName", value = "期次名称"),
            @ApiImplicitParam(name = "projectIssue", value = "期次代码"),
    })
    public AjaxResult updateWindplantproject(Windplantproject windplantproject) {
        windplantprojectService.updateWindplantproject(windplantproject);
        return AjaxResult.success();
    }

    @ApiOperation("删除期次信息")
    @PostMapping("/deleteWindplantproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpNo", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
    })
    public AjaxResult deleteWindplantproject(@RequestParam(value = "wpNo") String wpNo,
                                             @RequestParam(value = "projectNo") String projectNo) {
        windplantprojectService.deleteWindplantprojectById(Convert.toLong(projectNo));
        //删除集电线配置信息
        collectorwireprojectService.deleteCollectorwireprojectByProjectNo(Convert.toLong(projectNo));
        //风机装机容量
        double installedCapacity = 0;
        //删除风机配置信息
        List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByPojectNo(Convert.toLong(wpNo), Convert.toLong(projectNo));
        for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList) {
            Wtur wtur = wturService.selectWturById(wfProjectCwWtg.getWtgNo());
            if (ObjectUtil.isNotNull(wtur)) {
                if (wtur.getRatedPower() != null){
                    installedCapacity += wtur.getRatedPower();
                }
                wtgTypeService.deleteWtgTypeById(wtur.getWtgType());
            }
            wtgTypeTemperatureDefService.deleteWtgTypeTemperatureDefById(wtur.getWtgType());
            wturService.deleteWturById(wfProjectCwWtg.getWtgNo());
        }
        wfProjectCwWtgService.deleteWfProjectCwWtgByProjectNo(Convert.toLong(wpNo), Convert.toLong(projectNo));
        //减去当前数据下的风机的总装机容量
        Windplant windplant = windplantService.selectWindplantById(Convert.toLong(wpNo));
        if (ObjectUtil.isNotNull(windplant)) {
            if (windplant.getInstallPower() != null){
                windplant.setInstallPower(windplant.getInstallPower() - installedCapacity);
                windplantService.updateWindplant(windplant);
            }
        }
        AreaConfig areaConfig = areaConfigService.selectAreaConfigByRtuNo(Convert.toLong(wpNo));
        if (ObjectUtil.isNotNull(areaConfig)) {
            Area area = areaService.selectAreaById(areaConfig.getAreaNo());
            if (ObjectUtil.isNotNull(area)) {
                if (area.getInstallPower() != null){
                    area.setInstallPower(area.getInstallPower() - installedCapacity);
                    areaService.updateArea(area);
                }
            }
        }
        return AjaxResult.success();
    }

    @ApiOperation("获取集电线信息列表")
    @PostMapping("/getCollectorwireprojectList")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "windplantName或pvStationName", value = "所属场站"),
            @ApiImplicitParam(name = "projectName", value = "所属期次"),
            @ApiImplicitParam(name = "wireName", value = "集电线名称"),
            @ApiImplicitParam(name = "wireIssue", value = "集电线代码"),
            @ApiImplicitParam(name = "unitsNumber", value = "机组数量"),
            @ApiImplicitParam(name = "wireCapacity", value = "装机容量MW"),
    })
    public TableDataInfo getCollectorwireprojectList(Collectorwireproject collectorwireproject) {
        startPage();
        List<Collectorwireproject> list = collectorwireprojectService.selectCollectorwireprojectList(collectorwireproject);
        return getDataTable(list);
    }

    @ApiOperation("添加集电线信息")
    @PostMapping("/addCollectorwireproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpNo", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "wireName", value = "集电线名称", required = true),
            @ApiImplicitParam(name = "wireIssue", value = "集电线代码", required = true),
    })
    public AjaxResult addCollectorwireproject(Collectorwireproject collectorwireproject) {
        Long collectorwireNo;
        if (collectorwireprojectService.selectNewData() == null) {
            collectorwireNo = Convert.toLong(1);
        } else {
            collectorwireNo = collectorwireprojectService.selectNewData() + 1;
        }
        collectorwireproject.setCollectorwireNo(collectorwireNo);
        collectorwireprojectService.insertCollectorwireproject(collectorwireproject);
        return AjaxResult.success();
    }

    @ApiOperation("修改集电线信息")
    @PostMapping("/updateCollectorwireproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collectorwireNo", value = "集电线编号", required = true),
            @ApiImplicitParam(name = "wpNo", value = "场站编号"),
            @ApiImplicitParam(name = "projectNo", value = "期次编号"),
            @ApiImplicitParam(name = "wireName", value = "集电线名称"),
            @ApiImplicitParam(name = "wireIssue", value = "集电线代码"),
    })
    public AjaxResult updateCollectorwireproject(Collectorwireproject collectorwireproject) {
        collectorwireprojectService.updateCollectorwireproject(collectorwireproject);
        return AjaxResult.success();
    }

    @ApiOperation("删除集电线信息")
    @PostMapping("/deleteCollectorwireproject")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpNo", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "collectorwireNo", value = "集电线编号", required = true),
    })
    public AjaxResult deleteCollectorwireproject(@RequestParam(value = "wpNo") String wpNo,
                                                 @RequestParam(value = "projectNo") String projectNo,
                                                 @RequestParam(value = "collectorwireNo") String collectorwireNo) {
        collectorwireprojectService.deleteCollectorwireprojectById(Convert.toLong(collectorwireNo));
        //风机装机容量
        double installedCapacity = 0;
        //删除风机配置信息
        List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByCollectorwireNo(Convert.toLong(wpNo), Convert.toLong(projectNo), Convert.toLong(collectorwireNo));
        for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList) {
            Wtur wtur = wturService.selectWturById(wfProjectCwWtg.getWtgNo());
            if (ObjectUtil.isNotNull(wtur)) {
                if (wtur.getRatedPower() != null){
                    installedCapacity += wtur.getRatedPower();
                }
                wtgTypeService.deleteWtgTypeById(wtur.getWtgType());
            }
            wtgTypeTemperatureDefService.deleteWtgTypeTemperatureDefById(wtur.getWtgType());
            wturService.deleteWturById(wfProjectCwWtg.getWtgNo());
        }
        wfProjectCwWtgService.deleteWfProjectCwWtgByCollectorwireNo(Convert.toLong(wpNo), Convert.toLong(projectNo), Convert.toLong(collectorwireNo));
        //减去当前数据下的风机的总装机容量
        Windplantproject windplantproject = windplantprojectService.selectWindplantprojectByWpNoProjectNo(Convert.toLong(wpNo), Convert.toLong(projectNo));
        if (ObjectUtil.isNotNull(windplantproject)) {
            if (windplantproject.getProjectCapacity() != null){
                windplantproject.setProjectCapacity(windplantproject.getProjectCapacity() - installedCapacity);
                windplantprojectService.updateWindplantproject(windplantproject);
            }
        }
        Windplant windplant = windplantService.selectWindplantById(Convert.toLong(wpNo));
        if (ObjectUtil.isNotNull(windplant)) {
            if (windplant.getInstallPower() != null){
                windplant.setInstallPower(windplant.getInstallPower() - installedCapacity);
                windplantService.updateWindplant(windplant);
            }
        }
        AreaConfig areaConfig = areaConfigService.selectAreaConfigByRtuNo(Convert.toLong(wpNo));
        if (ObjectUtil.isNotNull(areaConfig)) {
            Area area = areaService.selectAreaById(areaConfig.getAreaNo());
            if (ObjectUtil.isNotNull(area)) {
                if (area.getInstallPower() != null){
                    area.setInstallPower(area.getInstallPower() - installedCapacity);
                    areaService.updateArea(area);
                }
            }
        }
        return AjaxResult.success();
    }
}
