package com.ics.admin.controller.meeting;

import com.ics.system.service.ICurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ics.common.core.domain.R;
import com.ics.common.core.controller.BaseController;
import com.ics.admin.domain.meeting.RoomServe;
import com.ics.admin.service.meeting.IRoomServeService;
import org.wf.jwtp.annotation.RequiresPermissions;
import org.wf.jwtp.util.SubjectUtil;

/**
 * 服务 提供者
 *
 * @author chen
 * @date 2024-02-25
 */
@RestController
@RequestMapping("/meeting/roomServe")
public class RoomServeController extends BaseController {

    @Autowired
    private IRoomServeService roomServeService;

    @Autowired
    private ICurrentUserService currentUserService;

    /**
     * 查询服务
     */
    @GetMapping("get/{id}")
    public RoomServe get(@PathVariable("id") Long id) {
        return roomServeService.selectRoomServeById(id);
    }

    /**
     * 查询服务列表
     */
    @RequiresPermissions("meeting:roomServe:list")
    @GetMapping("list")
    public R list(RoomServe roomServe) {
        startPage();
        boolean isAdmin = SubjectUtil.hasRole(getRequest(),"manager");
        if (isAdmin){
            Long parkId = currentUserService.getParkId();
            Long tenantId = currentUserService.getTenantId();
            roomServe.setParkId(parkId);
//            roomServe.setTenantId(tenantId);
        }

        return result(roomServeService.selectRoomServeList(roomServe));
    }


    /**
     * 新增保存服务
     */
    @RequiresPermissions("meeting:roomServe:add")
    @PostMapping("save")
    public R addSave(@RequestBody RoomServe roomServe) {
        return toAjax(roomServeService.insertRoomServe(roomServe));
    }

    /**
     * 修改保存服务
     */
    @RequiresPermissions("meeting:roomServe:edit")
    @PostMapping("update")
    public R editSave(@RequestBody RoomServe roomServe) {
        return toAjax(roomServeService.updateRoomServe(roomServe));
    }

    /**
     * 删除服务
     */
    @RequiresPermissions("meeting:roomServe:remove")
    @PostMapping("remove")
    public R remove(String ids) {
        return toAjax(roomServeService.deleteRoomServeByIds(ids));
    }

}
