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

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.ledger.domain.ScorePushConfig;
import com.sundot.airport.ledger.service.IScorePushConfigService;
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.*;

/**
 * 推送配置管理
 */
@RestController
@RequestMapping("/score/pushConfig")
public class ScorePushConfigController extends BaseController {

    @Autowired
    private IScorePushConfigService service;

    @PreAuthorize("@ss.hasPermi('score:pushConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScorePushConfig query) {
        startPage();
        return getDataTable(service.selectList(query));
    }

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

    @PreAuthorize("@ss.hasPermi('score:pushConfig:add')")
    @Log(title = "推送配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ScorePushConfig entity) {
        entity.setCreateBy(getUsername());
        entity.setCreateTime(DateUtils.getNowDate());
        return toAjax(service.save(entity));
    }

    @PreAuthorize("@ss.hasPermi('score:pushConfig:edit')")
    @Log(title = "推送配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ScorePushConfig entity) {
        entity.setUpdateBy(getUsername());
        entity.setUpdateTime(DateUtils.getNowDate());
        return toAjax(service.updateById(entity));
    }

    @PreAuthorize("@ss.hasPermi('score:pushConfig:remove')")
    @Log(title = "推送配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        for (Long id : ids) service.removeById(id);
        return AjaxResult.success();
    }
}
