package com.nasc.web.controller.custom;

import com.nasc.common.annotation.Log;
import com.nasc.common.core.controller.BaseController;
import com.nasc.common.core.domain.AjaxResult;
import com.nasc.common.core.page.TableDataInfo;
import com.nasc.common.core.text.Convert;
import com.nasc.common.enums.BusinessType;
import com.nasc.custom.domain.NascVncDesktop;
import com.nasc.custom.service.INascVncDesktopService;
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.*;

import java.util.List;

/**
 * @Author: Jianq Yu
 * @Date: 2024/6/4 16:23
 * @Description: 远程桌面数据
 */
@RestController
@RequestMapping("/nasc/vnc")
public class NascVncDesktopController extends BaseController {

    @Autowired
    private INascVncDesktopService vncDesktopService;

    /**
     * @Author: Yujianq
     * @Date: 2024/6/4 16:54
     * @Description: 根据条件分页查询远程桌面数据列表
     * @param vncDesktop
     * @return: com.nasc.common.core.page.TableDataInfo
     */
    @PreAuthorize("@ss.hasPermi('vnc:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(NascVncDesktop vncDesktop) {
        startPage();
        List<NascVncDesktop> list = vncDesktopService.selectVncDesktopList(vncDesktop);
        return getDataTable(list);
    }

    /**
     * @Author: Yujianq
     * @Date: 2024/6/4 16:54
     * @Description: 根据条件查询所有远程桌面数据列表
     * @param vncDesktop
     * @return: com.nasc.common.core.page.TableDataInfo
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(NascVncDesktop vncDesktop) {
        List<NascVncDesktop> list = vncDesktopService.selectVncDesktopList(vncDesktop);
        return AjaxResult.success(list);
    }

    /**
     * @Author: Yujianq
     * @Date: 2024/6/5 10:17
     * @Description: 保存远程桌面数据信息
     * @param vncDesktop
     * @return: com.nasc.common.core.domain.AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('vnc:item:add')")
    @Log(title = "远程桌面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody NascVncDesktop vncDesktop) {
        if (vncDesktopService.checkVncDesktopDuplicates(vncDesktop) > 0) {
            return error("添加远程桌面'" + vncDesktop.getDesktopName() + "'失败，该远程桌面已存在！");
        }
        vncDesktop.setCreateBy(Convert.toStr(getUserId()));
        return toAjax(vncDesktopService.insertVncDesktop(vncDesktop));
    }

    /**
     * @Author: Yujianq
     * @Date: 2024/6/5 14:22
     * @Description: 修改远程桌面数据信息
     * @param vncDesktop
     * @return: com.nasc.common.core.domain.AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('vnc:item:edit')")
    @Log(title = "远程桌面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody NascVncDesktop vncDesktop) {
        if (vncDesktopService.checkVncDesktopDuplicates(vncDesktop) > 0) {
            return error("远程桌面事项'" + vncDesktop.getDesktopName() + "'失败，该远程桌面已存在！");
        }
        vncDesktop.setUpdateBy(Convert.toStr(getUserId()));
        return toAjax(vncDesktopService.updateVncDesktop(vncDesktop));
    }

    /**
     * @Author: Yujianq
     * @Date: 2024/6/5 17:25
     * @Description: 批量根据ID进行删除远程桌面数据
     * @param ids
     * @return: com.nasc.common.core.domain.AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('vnc:item:remove')")
    @Log(title = "远程桌面", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(vncDesktopService.deleteVncDesktopByIds(ids));
    }

    /**
     * @Author: Yujianq
     * @Date: 2024/6/6 10:06
     * @Description: 根据ID查询远程桌面数据信息
     * @param id
     * @return: com.nasc.common.core.domain.AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('vnc:item:query')")
    @GetMapping(value = { "/", "/{id}" })
    public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id) {
        return AjaxResult.success(vncDesktopService.getVncDesktopInfo(id));
    }

}
