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.LedgerBannerLetter;
import com.sundot.airport.ledger.service.ILedgerBannerLetterService;
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/bannerLetter")
public class LedgerBannerLetterController extends BaseController {

    @Autowired
    private ILedgerBannerLetterService service;

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

    @PreAuthorize("@ss.hasPermi('ledger:bannerLetter:export')")
    @Log(title = "锦旗及感谢信记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LedgerBannerLetter query) {
        List<LedgerBannerLetter> list = service.selectList(query);
        ExcelUtil<LedgerBannerLetter> util = new ExcelUtil<>(LedgerBannerLetter.class);
        util.exportExcel(response, list, "锦旗及感谢信记录");
    }

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

    @PreAuthorize("@ss.hasPermi('ledger:bannerLetter:add')")
    @Log(title = "锦旗及感谢信记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody LedgerBannerLetter entity) {
        entity.setCreateBy(getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        return toAjax(service.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('ledger:bannerLetter:edit')")
    @Log(title = "锦旗及感谢信记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody LedgerBannerLetter entity) {
        entity.setUpdateBy(getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return toAjax(service.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('ledger:bannerLetter:remove')")
    @Log(title = "锦旗及感谢信记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        for (Long id : ids) {
            service.removeById(id);
        }
        return AjaxResult.success();
    }
}
