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

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

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.core.page.TableDataInfo;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.common.utils.DateUtils;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.ledger.domain.LedgerLeaveSpecial;
import com.sundot.airport.ledger.service.ILedgerLeaveSpecialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 请休假记录（特殊）Controller（页面录入，支持增删改查）
 */
@RestController
@RequestMapping("/ledger/leaveSpecial")
public class LedgerLeaveSpecialController extends BaseController {

    @Autowired
    private ILedgerLeaveSpecialService service;

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:list')")
    @GetMapping("/list")
    public TableDataInfo list(LedgerLeaveSpecial query) {
        startPage();
        List<LedgerLeaveSpecial> list = service.selectList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:export')")
    @Log(title = "请休假记录（特殊）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LedgerLeaveSpecial query) {
        List<LedgerLeaveSpecial> list = service.selectList(query);
        ExcelUtil<LedgerLeaveSpecial> util = new ExcelUtil<>(LedgerLeaveSpecial.class);
        util.exportExcel(response, list, "请休假记录（特殊）");
    }

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(service.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:add')")
    @Log(title = "请休假记录（特殊）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody LedgerLeaveSpecial entity) {
        entity.setCreateBy(getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        return toAjax(service.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:edit')")
    @Log(title = "请休假记录（特殊）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody LedgerLeaveSpecial entity) {
        entity.setUpdateBy(getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return toAjax(service.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('ledger:leaveSpecial:remove')")
    @Log(title = "请休假记录（特殊）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        for (Long id : ids) {
            service.removeById(id);
        }
        return AjaxResult.success();
    }
}
