package com.ruoyi.powerdistribution.controller;

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

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

/**
 * 作业人员积分排名Controller
 *
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/power/workerRank")
public class PdmScoreRankWorkerController extends BaseController
{
    @Autowired
    private IPdmScoreRankWorkerService pdmScoreRankWorkerService;

    /**
     * 查询作业人员积分排名列表
     */
    @ApiOperation(value = "查询作业人员积分排名列表")
    @PreAuthorize("@ss.hasPermi('system:worker:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmScoreRankWorker pdmScoreRankWorker)
    {
        startPage();
        List<PdmScoreRankWorker> list = pdmScoreRankWorkerService.selectPdmScoreRankWorkerList(pdmScoreRankWorker);
        PageInfo pageInfo =  new PageInfo(list);
        int pageNum = pageInfo.getPageNum();
        int i = 1;
        for(PdmScoreRankWorker manager:list){
            int rankNum = pageNum!=1?(pageNum-1)*pageInfo.getPageSize()*i:i;
            manager.setRankNum(rankNum);
            i++;
        }
        return getDataTable(list);
    }

    /**
     * 导出作业人员积分排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:worker:export')")
    @Log(title = "作业人员积分排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmScoreRankWorker pdmScoreRankWorker)
    {
        List<PdmScoreRankWorker> list = pdmScoreRankWorkerService.selectPdmScoreRankWorkerList(pdmScoreRankWorker);
        ExcelUtil<PdmScoreRankWorker> util = new ExcelUtil<PdmScoreRankWorker>(PdmScoreRankWorker.class);
        util.exportExcel(response, list, "作业人员积分排名数据");
    }

    /**
     * 获取作业人员积分排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:worker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmScoreRankWorkerService.selectPdmScoreRankWorkerById(id));
    }

    /**
     * 新增作业人员积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:worker:add')")
    @Log(title = "作业人员积分排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmScoreRankWorker pdmScoreRankWorker)
    {
        return toAjax(pdmScoreRankWorkerService.insertPdmScoreRankWorker(pdmScoreRankWorker));
    }

    /**
     * 修改作业人员积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:worker:edit')")
    @Log(title = "作业人员积分排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmScoreRankWorker pdmScoreRankWorker)
    {
        return toAjax(pdmScoreRankWorkerService.updatePdmScoreRankWorker(pdmScoreRankWorker));
    }

    /**
     * 删除作业人员积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:worker:remove')")
    @Log(title = "作业人员积分排名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmScoreRankWorkerService.deletePdmScoreRankWorkerByIds(ids));
    }
}
