package com.aegis.web.controller.resource.team;

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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aegis.common.annotation.Log;
import com.aegis.common.core.controller.BaseController;
import com.aegis.common.core.domain.AjaxResult;
import com.aegis.common.core.page.TableDataInfo;
import com.aegis.common.enums.BusinessType;
import com.aegis.resource.team.domain.Team;
import com.aegis.resource.team.service.IResourceTeamService;

/**
 * 应急队伍Controller
 * 
 * @author aegis
 */
@RestController
@RequestMapping("/resources/teams")
public class ResourceTeamController extends BaseController {

    @Autowired
    private IResourceTeamService teamService;

    /**
     * 查询队伍列表
     */
    @PreAuthorize("@ss.hasPermi('resource:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(Team team) {
        startPage();
        return getDataTable(teamService.listByCondition(team));
    }

    /**
     * 根据ID获取队伍详情
     */
    @PreAuthorize("@ss.hasPermi('resource:team:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(teamService.getById(id));
    }

    /**
     * 新增队伍
     */
    @PreAuthorize("@ss.hasPermi('resource:team:add')")
    @Log(title = "应急队伍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Team team) {
        return toAjax(teamService.save(team));
    }

    /**
     * 修改队伍
     */
    @PreAuthorize("@ss.hasPermi('resource:team:edit')")
    @Log(title = "应急队伍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Team team) {
        return toAjax(teamService.updateById(team));
    }

    /**
     * 删除队伍
     */
    @PreAuthorize("@ss.hasPermi('resource:team:remove')")
    @Log(title = "应急队伍", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        boolean removed = teamService.removeByIds(java.util.Arrays.asList(ids));
        return removed ? success() : error("删除失败");
    }
}