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.PdmScoreRankCompany;
import com.ruoyi.powerdistribution.service.IPdmScoreRankCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单位积分排名Controller
 *
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("power/companyRank")
public class PdmScoreRankCompanyController extends BaseController
{
    @Autowired
    private IPdmScoreRankCompanyService pdmScoreRankCompanyService;

    /**
     * 查询单位积分排名列表
     */
    @ApiOperation(value = "查询单位积分排名列表")
    @PreAuthorize("@ss.hasPermi('system:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmScoreRankCompany pdmScoreRankCompany)
    {
        startPage();
        List<PdmScoreRankCompany> list = pdmScoreRankCompanyService.selectPdmScoreRankCompanyList(pdmScoreRankCompany);
        PageInfo pageInfo =  new PageInfo(list);
        int pageNum = pageInfo.getPageNum();
        int i = 1;
        for(PdmScoreRankCompany manager:list){
            int rankNum = pageNum!=1?(pageNum-1)*pageInfo.getPageSize()*i:i;
            manager.setRankNum(rankNum);
            i++;
        }
        return getDataTable(list);
    }

    /**
     * 导出单位积分排名列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:export')")
    @Log(title = "单位积分排名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmScoreRankCompany pdmScoreRankCompany)
    {
        List<PdmScoreRankCompany> list = pdmScoreRankCompanyService.selectPdmScoreRankCompanyList(pdmScoreRankCompany);
        ExcelUtil<PdmScoreRankCompany> util = new ExcelUtil<PdmScoreRankCompany>(PdmScoreRankCompany.class);
        util.exportExcel(response, list, "单位积分排名数据");
    }

    /**
     * 获取单位积分排名详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmScoreRankCompanyService.selectPdmScoreRankCompanyById(id));
    }

    /**
     * 新增单位积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "单位积分排名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmScoreRankCompany pdmScoreRankCompany)
    {
        return toAjax(pdmScoreRankCompanyService.insertPdmScoreRankCompany(pdmScoreRankCompany));
    }

    /**
     * 修改单位积分排名
     */
    @PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "单位积分排名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmScoreRankCompany pdmScoreRankCompany)
    {
        return toAjax(pdmScoreRankCompanyService.updatePdmScoreRankCompany(pdmScoreRankCompany));
    }

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