package com.ruoyi.cms.controller.cms;

import com.ruoyi.cms.domain.CommunityUser;
import com.ruoyi.cms.service.ICommunityUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cms/communityUser")
@Api(tags = "后台：工作人员管理")
public class CommunityUserController extends BaseController {

    @Autowired
    private ICommunityUserService communityUserService;


    @ApiOperation("查询工作人员列表")
    @PreAuthorize("@ss.hasPermi('application:mgmt:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityUser communityUser) {
        startPage();
        List<CommunityUser> list = communityUserService.selectCommunityUserList(communityUser);
        return getDataTable(list);
    }

    @ApiOperation("新增工作人员")
    @PreAuthorize("@ss.hasPermi('application:mgmt:add')")
    @PostMapping
    public AjaxResult add(@RequestBody CommunityUser communityUser) {
        return toAjax(communityUserService.save(communityUser));
    }

    @ApiOperation("修改工作人员")
    @PreAuthorize("@ss.hasPermi('application:mgmt:edit')")
    @PutMapping
    public AjaxResult update(@RequestBody CommunityUser communityUser) {
        return toAjax(communityUserService.updateById(communityUser));
    }

    @ApiOperation("删除工作人员")
    @PreAuthorize("@ss.hasPermi('application:mgmt:del')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids) {
        return toAjax(communityUserService.delCommunityUser(ids));
    }
}
