package com.srs.web.controller.staff;

import com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.page.TableDataInfo;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.staff.domain.StaffOneStopRoom;
import com.srs.staff.service.IStaffOneStopRoomService;
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 javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 一站式社区-功能房Controller
 *
 * @author chc
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/staff/room")
@Api(value = "一站式社区-功能房管理", tags = "一站式社区-功能房管理")
public class StaffOneStopRoomController extends BaseController {
    @Autowired
    private IStaffOneStopRoomService staffOneStopRoomService;

    /**
     * 查询一站式社区-功能房列表
     */
    @PreAuthorize("@ss.hasPermi('staff:room:list')")
    @GetMapping("/list")
    @ApiOperation("查询一站式社区-功能房列表")
    public TableDataInfo list(StaffOneStopRoom staffOneStopRoom) {
        startPage();
        List<StaffOneStopRoom> list = staffOneStopRoomService.selectStaffOneStopRoomList(staffOneStopRoom);
        return getDataTable(list);
    }

    /**
     * 查询一站式社区-功能房列表
     */
    @PreAuthorize("@ss.hasPermi('staff:room:list')")
    @GetMapping("/listAll")
    @ApiOperation("查询一站式社区-功能房列表（未分页）")
    public AjaxResult listAll(StaffOneStopRoom staffOneStopRoom) {
        List<StaffOneStopRoom> list = staffOneStopRoomService.selectStaffOneStopRoomList(staffOneStopRoom);
        return success(list);
    }

    /**
     * 导出一站式社区-功能房列表
     */
    @PreAuthorize("@ss.hasPermi('staff:room:export')")
    @Log(title = "一站式社区-功能房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出一站式社区-功能房列表")
    public void export(HttpServletResponse response, StaffOneStopRoom staffOneStopRoom) {
        List<StaffOneStopRoom> list = staffOneStopRoomService.selectStaffOneStopRoomList(staffOneStopRoom);
        ExcelUtil<StaffOneStopRoom> util = new ExcelUtil<StaffOneStopRoom>(StaffOneStopRoom.class);
        util.exportExcel(response, list, "一站式社区-功能房数据");
    }

    /**
     * 获取一站式社区-功能房详细信息
     */
    @PreAuthorize("@ss.hasPermi('staff:room:query')")
    @GetMapping(value = "/{roomId}")
    @ApiOperation("获取一站式社区-功能房详细信息")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId) {
        return success(staffOneStopRoomService.selectStaffOneStopRoomByRoomId(roomId));
    }

    /**
     * 新增一站式社区-功能房
     */
    @PreAuthorize("@ss.hasPermi('staff:room:add')")
    @Log(title = "一站式社区-功能房", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增一站式社区-功能房")
    public AjaxResult add(@RequestBody StaffOneStopRoom staffOneStopRoom) {
        int i = staffOneStopRoomService.insertStaffOneStopRoom(staffOneStopRoom);
        StaffOneStopRoom stopRoom = null;
        if (i > 0) {
            // 新增成功，查询新增的数据
            stopRoom = staffOneStopRoomService.selectStaffOneStopRoomByRoomId(staffOneStopRoom.getRoomId());
            if (stopRoom != null) {
                return success(stopRoom);
            }
        }
        return success(stopRoom);
    }

    /**
     * 修改一站式社区-功能房
     */
    @PreAuthorize("@ss.hasPermi('staff:room:edit')")
    @Log(title = "一站式社区-功能房", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改一站式社区-功能房")
    public AjaxResult edit(@RequestBody StaffOneStopRoom staffOneStopRoom) {
        return toAjax(staffOneStopRoomService.updateStaffOneStopRoom(staffOneStopRoom));
    }

    /**
     * 删除一站式社区-功能房
     */
    @PreAuthorize("@ss.hasPermi('staff:room:remove')")
    @Log(title = "一站式社区-功能房", businessType = BusinessType.DELETE)
    @PostMapping("/{roomIds}")
    @ApiOperation("删除一站式社区-功能房")
    public AjaxResult remove(@PathVariable Long[] roomIds) {
        return toAjax(staffOneStopRoomService.deleteStaffOneStopRoomByRoomIds(roomIds));
    }
}
