package com.ruoyi.powerdistribution.controller;

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

import com.github.pagehelper.PageInfo;
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.PdmScoreRankManager;
import com.ruoyi.powerdistribution.service.IPdmScoreRankManagerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 负责人积分排名Controller
 *
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/power/managerRank")
public class PdmScoreRankManagerController extends BaseController
{
    @Autowired
    private IPdmScoreRankManagerService pdmScoreRankManagerService;

    /**
     * 查询负责人积分排名列表
     */
    @ApiOperation(value = "查询负责人积分排名列表")
    @PreAuthorize("@ss.hasPermi('system:manager:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmScoreRankManager pdmScoreRankManager)
    {
        startPage();
        List<PdmScoreRankManager> list = pdmScoreRankManagerService.selectPdmScoreRankManagerList(pdmScoreRankManager);
        PageInfo pageInfo =  new PageInfo(list);
        int pageNum = pageInfo.getPageNum();
        int i = 1;
        for(PdmScoreRankManager manager:list){
            int rankNum = pageNum!=1?(pageNum-1)*pageInfo.getPageSize()*i:i;
            manager.setRankNum(rankNum);
            i++;
        }
        return getDataTable(list);
    }

    /**
     * 导出负责人积分排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:manager:export')")
    @Log(title = "负责人积分排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmScoreRankManager pdmScoreRankManager)
    {
        List<PdmScoreRankManager> list = pdmScoreRankManagerService.selectPdmScoreRankManagerList(pdmScoreRankManager);
        ExcelUtil<PdmScoreRankManager> util = new ExcelUtil<PdmScoreRankManager>(PdmScoreRankManager.class);
        util.exportExcel(response, list, "负责人积分排名数据");
    }

    /**
     * 获取负责人积分排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:manager:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmScoreRankManagerService.selectPdmScoreRankManagerById(id));
    }

    /**
     * 新增负责人积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:manager:add')")
    @Log(title = "负责人积分排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmScoreRankManager pdmScoreRankManager)
    {
        return toAjax(pdmScoreRankManagerService.insertPdmScoreRankManager(pdmScoreRankManager));
    }

    /**
     * 修改负责人积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:manager:edit')")
    @Log(title = "负责人积分排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmScoreRankManager pdmScoreRankManager)
    {
        return toAjax(pdmScoreRankManagerService.updatePdmScoreRankManager(pdmScoreRankManager));
    }

    /**
     * 删除负责人积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:manager:remove')")
    @Log(title = "负责人积分排名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmScoreRankManagerService.deletePdmScoreRankManagerByIds(ids));
    }
}
