package com.xueyi.system.meeting.controller;

import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.common.security.annotation.Logical;
import com.xueyi.common.security.annotation.RequiresPermissions;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.system.api.meeting.domain.dto.DmMeetingRoomsDto;
import com.xueyi.system.meeting.domain.model.DmMeetingRoomsConverter;
import com.xueyi.system.meeting.domain.query.DmMeetingRoomsQuery;
import com.xueyi.system.meeting.mapper.DmMeetingRoomsMapper;
import com.xueyi.system.meeting.service.IDmMeetingRoomsService;
import org.springframework.beans.factory.annotation.Autowired;
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 java.io.Serializable;
import java.util.List;

/**
 * 会议室管理 业务处理
 *
 * @author xueyi
 */
@RestController
@RequestMapping("/meeting/rooms")
public class DmMeetingRoomsController extends BaseController<DmMeetingRoomsQuery, DmMeetingRoomsDto, IDmMeetingRoomsService> {

    @Autowired
    IDmMeetingRoomsService iDmMeetingRoomsService;

    /**
     * 定义节点名称
     */
    @Override
    protected String getNodeName() {
        return "会议室";
    }


    @Autowired
    private DmMeetingRoomsMapper dmMeetingRoomsMapper;

    @Autowired
    DmMeetingRoomsConverter dmMeetingRoomsConverter;


    /**
     * 查询会议室列表
     */
    @Override
    @GetMapping("/list")
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_LIST)
    public AjaxResult list(DmMeetingRoomsQuery dmMeetingRooms) {


        startPage();
        List<DmMeetingRoomsDto> list = baseService.selectListScope(dmMeetingRooms);
        list.forEach(item -> iDmMeetingRoomsService.addImgUrl(item));
        return getDataTable(list);
    }


    @GetMapping("/lists")
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_LIST)
    public AjaxResult lists(DmMeetingRoomsQuery dmMeetingRooms) {
        startPage();
        List<DmMeetingRoomsDto> list = baseService.selectListScope(dmMeetingRooms);
        list.forEach(item -> iDmMeetingRoomsService.addImgUrl(item));
        return getDataTable(list);
    }

    /**
     * 查询会议室详细
     */
    @Override
    @GetMapping(value = "/{id}")
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_SINGLE)
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    /**
     * 会议室新增
     */
    @Override
    @PostMapping
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_ADD)
    @Log(title = "会议室管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated({V_A.class}) @RequestBody DmMeetingRoomsDto dmMeetingRooms) {
        return super.add(dmMeetingRooms);
    }

    /**
     * 会议室修改
     */
    @Override
    @PutMapping
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_EDIT)
    @Log(title = "会议室管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody DmMeetingRoomsDto dmMeetingRooms) {
        return super.edit(dmMeetingRooms);
    }

    /**
     * 会议室修改状态
     */
    @Override
    @PutMapping("/status")
    @RequiresPermissions(value = {Auth.DM_MEETING_ROOMS_EDIT, Auth.DM_MEETING_ROOMS_ES}, logical = Logical.OR)
    @Log(title = "会议室管理", businessType = BusinessType.UPDATE_STATUS)
    public AjaxResult editStatus(@RequestBody DmMeetingRoomsDto dmMeetingRooms) {
        return super.editStatus(dmMeetingRooms);
    }

    /**
     * 会议室批量删除
     */
    @Override
    @DeleteMapping("/batch/{idList}")
    @RequiresPermissions(Auth.DM_MEETING_ROOMS_DEL)
    @Log(title = "会议室管理", businessType = BusinessType.DELETE)
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }

    /**
     * 获取会议室选择框列表
     */
    @Override
    @GetMapping("/option")
    public AjaxResult option() {
        return super.option();
    }

    interface Auth {
        /**
         * 系统 - 会议室管理 - 列表
         */
        String DM_MEETING_ROOMS_LIST = "meeting:rooms:meeting/rooms:list";
        /**
         * 系统 - 会议室管理 - 详情
         */
        String DM_MEETING_ROOMS_SINGLE = "meeting:rooms:meeting/rooms:single";
        /**
         * 系统 - 会议室管理 - 新增
         */
        String DM_MEETING_ROOMS_ADD = "meeting:rooms:meeting/rooms:add";
        /**
         * 系统 - 会议室管理 - 修改
         */
        String DM_MEETING_ROOMS_EDIT = "meeting:rooms:meeting/rooms:edit";
        /**
         * 系统 - 会议室管理 - 修改状态
         */
        String DM_MEETING_ROOMS_ES = "meeting:rooms:meeting/rooms:es";
        /**
         * 系统 - 会议室管理 - 删除
         */
        String DM_MEETING_ROOMS_DEL = "meeting:rooms:meeting/rooms:delete";
    }
}
