package com.ruoyi.powerdistribution.controller;

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

import com.ruoyi.powerdistribution.domain.dto.PdmWorkPlanDTO;
import com.ruoyi.powerdistribution.domain.vo.WorkNumByCompanyStatistics;
import com.ruoyi.powerdistribution.domain.vo.WorkRiskStatistics;
import io.swagger.annotations.ApiOperation;
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.PdmWorkPlan;
import com.ruoyi.powerdistribution.service.IPdmWorkPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作业计划Controller
 *
 * @author ruoyi
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/power/workPlan")
public class PdmWorkPlanController extends BaseController
{
    @Autowired
    private IPdmWorkPlanService pdmWorkPlanService;

    /**
     * 查询作业计划列表
     */
    @ApiOperation(value = "查询作业计划列表")
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmWorkPlanDTO pdmWorkPlan)
    {
        startPage();
        List<PdmWorkPlan> list = pdmWorkPlanService.selectPdmWorkPlanList(pdmWorkPlan);
        return getDataTable(list);
    }

    /**
     * 导出作业计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "作业计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmWorkPlanDTO pdmWorkPlan)
    {
        List<PdmWorkPlan> list = pdmWorkPlanService.selectPdmWorkPlanList(pdmWorkPlan);
        ExcelUtil<PdmWorkPlan> util = new ExcelUtil<PdmWorkPlan>(PdmWorkPlan.class);
        util.exportExcel(response, list, "作业计划数据");
    }

    /**
     * 获取作业计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmWorkPlanService.selectPdmWorkPlanById(id));
    }

    /**
     * 新增作业计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "作业计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PdmWorkPlan pdmWorkPlan)
    {
        return toAjax(pdmWorkPlanService.insertPdmWorkPlan(pdmWorkPlan));
    }

    /**
     * 修改作业计划
     */
    @ApiOperation(value = "修改作业计划")
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "作业计划", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PdmWorkPlan pdmWorkPlan)
    {
        return toAjax(pdmWorkPlanService.updatePdmWorkPlan(pdmWorkPlan));
    }

    /**
     * 删除作业计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "作业计划", businessType = BusinessType.DELETE)
	@GetMapping("delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmWorkPlanService.deletePdmWorkPlanByIds(ids));
    }

    /**
     * 查询风险汇总-日
     */
    @ApiOperation(value = "查询风险汇总-日")
    @GetMapping("/getWorkRiskStatistics")
    public List<WorkRiskStatistics> getWorkRiskStatistics(String date)
    {
        return pdmWorkPlanService.getWorkRiskStatistics(date);
    }

    /**
     * 根据作业单位分类查询作业数量汇总
     */
    @ApiOperation(value = "根据作业单位分类查询作业数量汇总")
    @GetMapping("/getWorkNumStatistics")
    public List<WorkNumByCompanyStatistics> getWorkRiskStatistics(WorkNumByCompanyStatistics workNumByCompany){
        return pdmWorkPlanService.getWorkNumByCompanyStatistics(workNumByCompany);
    }
}
