package com.sundot.airport.web.controller.ledger;

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

import com.sundot.airport.ledger.domain.vo.EmployeeAdditionalScoreVO;
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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.ledger.domain.ScoreEmployeeAdditional;
import com.sundot.airport.ledger.service.IScoreEmployeeAdditionalService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;

/**
 * 员工附加分Controller
 *
 * @author ruoyi
 * @date 2026-05-18
 */
@RestController
@RequestMapping("/ledger/scoreEmployeeAdditional")
public class ScoreEmployeeAdditionalController extends BaseController {
    @Autowired
    private IScoreEmployeeAdditionalService scoreEmployeeAdditionalService;

    /**
     * 查询员工附加分列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreEmployeeAdditional scoreEmployeeAdditional) {
        startPage();
        List<ScoreEmployeeAdditional> list = scoreEmployeeAdditionalService.selectScoreEmployeeAdditionalList(scoreEmployeeAdditional);
        return getDataTable(list);
    }

    /**
     * 导出员工附加分列表
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:export')")
    @Log(title = "员工附加分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreEmployeeAdditional scoreEmployeeAdditional) {
        List<ScoreEmployeeAdditional> list = scoreEmployeeAdditionalService.selectScoreEmployeeAdditionalList(scoreEmployeeAdditional);
        ExcelUtil<ScoreEmployeeAdditional> util = new ExcelUtil<ScoreEmployeeAdditional>(ScoreEmployeeAdditional.class);
        util.exportExcel(response, list, "员工附加分数据");
    }

    /**
     * 获取员工附加分详细信息
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scoreEmployeeAdditionalService.getById(id));
    }

    /**
     * 新增员工附加分
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:add')")
    @Log(title = "员工附加分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreEmployeeAdditional scoreEmployeeAdditional) {
        scoreEmployeeAdditional.setCreateBy(getUsername());
        return toAjax(scoreEmployeeAdditionalService.insertScoreEmployeeAdditional(scoreEmployeeAdditional));
    }

    /**
     * 修改员工附加分
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:edit')")
    @Log(title = "员工附加分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreEmployeeAdditional scoreEmployeeAdditional) {
        scoreEmployeeAdditional.setUpdateBy(getUsername());
        return toAjax(scoreEmployeeAdditionalService.updateScoreEmployeeAdditional(scoreEmployeeAdditional));
    }

    /**
     * 删除员工附加分
     */
    @PreAuthorize("@ss.hasPermi('ledger:scoreEmployeeAdditional:remove')")
    @Log(title = "员工附加分", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scoreEmployeeAdditionalService.deleteScoreEmployeeAdditionalByIds(ids));
    }

    /**
     * 获取员工附加分列表
     */
    @GetMapping("/listByEmployeeInfo")
    public AjaxResult listByEmployeeInfo(ScoreEmployeeAdditional scoreEmployeeAdditional) {
        List<ScoreEmployeeAdditional> list = scoreEmployeeAdditionalService.selectScoreEmployeeAdditionalList(scoreEmployeeAdditional);
        return success(list);
    }

    /**
     * 按员工分组获取每个员工下的附加总分
     */
    @GetMapping("/getTotalScoreByEmployee")
    public AjaxResult getTotalScoreByEmployee(ScoreEmployeeAdditional scoreEmployeeAdditional) {
        List<EmployeeAdditionalScoreVO> result = scoreEmployeeAdditionalService.selectTotalScoreByEmployee(scoreEmployeeAdditional);
        return success(result);
    }
}