package com.ruoyi.powerdistribution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.powerdistribution.domain.PdmMaintenanceCompletionStatistics;
import com.ruoyi.powerdistribution.service.IPdmMaintenanceCompletionStatisticsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线路检修完成情况Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/powerdistribution/maintenance/statistics")
public class PdmMaintenanceCompletionStatisticsController extends BaseController
{
    @Autowired
    private IPdmMaintenanceCompletionStatisticsService pdmMaintenanceCompletionStatisticsService;

    /**
     * 查询线路检修完成情况列表
     */
    //@PreAuthorize("@ss.hasPermi('powerdistribution:maintenance/statistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmMaintenanceCompletionStatistics pdmMaintenanceCompletionStatistics)
    {
        if(StringUtils.isNotEmpty(pdmMaintenanceCompletionStatistics.getMaintenanceOverdue())){
            pdmMaintenanceCompletionStatistics.setMaintenanceOverdueUnit(pdmMaintenanceCompletionStatistics.getMaintenanceOverdue().split("\\|")[1]);
            pdmMaintenanceCompletionStatistics.setMaintenanceOverdueVal(pdmMaintenanceCompletionStatistics.getMaintenanceOverdue().split("\\|")[0]);
        }
        if(StringUtils.isNotEmpty(pdmMaintenanceCompletionStatistics.getRepeatPowerCut())){
            pdmMaintenanceCompletionStatistics.setRepeatPowerCutUnit(pdmMaintenanceCompletionStatistics.getRepeatPowerCut().split("\\|")[1]);
            pdmMaintenanceCompletionStatistics.setRepeatPowerCutVal(pdmMaintenanceCompletionStatistics.getRepeatPowerCut().split("\\|")[0]);
        }
        startPage();
        List<PdmMaintenanceCompletionStatistics> list = pdmMaintenanceCompletionStatisticsService.selectPdmMaintenanceCompletionStatisticsList(pdmMaintenanceCompletionStatistics);
        return getDataTable(list);
    }

    /**
     * 导出线路检修完成情况列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:maintenance:statistics:export')")
    @Log(title = "线路检修完成情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmMaintenanceCompletionStatistics pdmMaintenanceCompletionStatistics)
    {
        List<PdmMaintenanceCompletionStatistics> list = pdmMaintenanceCompletionStatisticsService.selectPdmMaintenanceCompletionStatisticsList(pdmMaintenanceCompletionStatistics);
        ExcelUtil<PdmMaintenanceCompletionStatistics> util = new ExcelUtil<PdmMaintenanceCompletionStatistics>(PdmMaintenanceCompletionStatistics.class);
        util.exportExcel(response, list, "线路检修完成情况数据");
    }

    /**
     * 获取线路检修完成情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:maintenance:statistics:query')")
    @GetMapping(value = "/{eventNo}")
    public AjaxResult getInfo(@PathVariable("eventNo") String eventNo)
    {
        return success(pdmMaintenanceCompletionStatisticsService.selectPdmMaintenanceCompletionStatisticsByEventNo(eventNo));
    }

    /**
     * 新增线路检修完成情况
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:maintenance:statistics:add')")
    @Log(title = "线路检修完成情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmMaintenanceCompletionStatistics pdmMaintenanceCompletionStatistics)
    {
        return toAjax(pdmMaintenanceCompletionStatisticsService.insertPdmMaintenanceCompletionStatistics(pdmMaintenanceCompletionStatistics));
    }

    /**
     * 修改线路检修完成情况
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:maintenance:statistics:edit')")
    @Log(title = "线路检修完成情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmMaintenanceCompletionStatistics pdmMaintenanceCompletionStatistics)
    {
        return toAjax(pdmMaintenanceCompletionStatisticsService.updatePdmMaintenanceCompletionStatistics(pdmMaintenanceCompletionStatistics));
    }

    /**
     * 删除线路检修完成情况
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:maintenance:statistics:remove')")
    @Log(title = "线路检修完成情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventNos}")
    public AjaxResult remove(@PathVariable String[] eventNos)
    {
        return toAjax(pdmMaintenanceCompletionStatisticsService.deletePdmMaintenanceCompletionStatisticsByEventNos(eventNos));
    }
}
