package com.ruoyi.powerdistribution.controller;

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

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

/**
 * 队伍积分排名Controller
 *
 * @author ruoyi
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/power/teamRank")
public class PdmScoreRankTeamController extends BaseController
{
    @Autowired
    private IPdmScoreRankTeamService pdmScoreRankTeamService;

    /**
     * 查询队伍积分排名列表
     */
    @ApiOperation(value = "查询队伍积分排名列表")
    @PreAuthorize("@ss.hasPermi('system:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmScoreRankTeam pdmScoreRankTeam)
    {
        startPage();
        List<PdmScoreRankTeam> list = pdmScoreRankTeamService.selectPdmScoreRankTeamList(pdmScoreRankTeam);
        PageInfo pageInfo =  new PageInfo(list);
        int pageNum = pageInfo.getPageNum();
        int i = 1;
        for(PdmScoreRankTeam manager:list){
            int rankNum = pageNum!=1?(pageNum-1)*pageInfo.getPageSize()*i:i;
            manager.setRankNum(rankNum);
            i++;
        }
        return getDataTable(list);
    }

    /**
     * 导出队伍积分排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:team:export')")
    @Log(title = "队伍积分排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmScoreRankTeam pdmScoreRankTeam)
    {
        List<PdmScoreRankTeam> list = pdmScoreRankTeamService.selectPdmScoreRankTeamList(pdmScoreRankTeam);
        ExcelUtil<PdmScoreRankTeam> util = new ExcelUtil<PdmScoreRankTeam>(PdmScoreRankTeam.class);
        util.exportExcel(response, list, "队伍积分排名数据");
    }

    /**
     * 获取队伍积分排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:team:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmScoreRankTeamService.selectPdmScoreRankTeamById(id));
    }

    /**
     * 新增队伍积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:team:add')")
    @Log(title = "队伍积分排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmScoreRankTeam pdmScoreRankTeam)
    {
        return toAjax(pdmScoreRankTeamService.insertPdmScoreRankTeam(pdmScoreRankTeam));
    }

    /**
     * 修改队伍积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:team:edit')")
    @Log(title = "队伍积分排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmScoreRankTeam pdmScoreRankTeam)
    {
        return toAjax(pdmScoreRankTeamService.updatePdmScoreRankTeam(pdmScoreRankTeam));
    }

    /**
     * 删除队伍积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:team:remove')")
    @Log(title = "队伍积分排名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmScoreRankTeamService.deletePdmScoreRankTeamByIds(ids));
    }
}
