package com.yuchen.saas.park.service.controller.pldoor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.pldoor.PlDoorPointGroupDTO;
import com.yuchen.saas.park.api.vo.pldoor.PlDoorPointGroupLtVO;
import com.yuchen.saas.park.api.vo.pldoor.PlDoorPointGroupVO;
import com.yuchen.saas.park.api.vo.request.PlDoorPointGroupListReq;
import com.yuchen.saas.park.api.vo.request.PlDoorPointGroupReq;
import com.yuchen.saas.park.service.service.pldoor.PlDoorPointGroupService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 保利门禁组 前端控制器
 * </p>
 *
 * @author miaoqs
 * @since 2024-04-03
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/plDoorPointGroup")
public class PlDoorPointGroupController {

    private final PlDoorPointGroupService plDoorPointGroupService;

    /**
     * 门禁分组 新增/修改
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "门禁分组 新增/修改", notes = "门禁分组 新增/修改")
    public R saveOrUpdate(@Valid @RequestBody PlDoorPointGroupDTO plDoorPointGroupDTO) {
        if(Func.isEmpty(plDoorPointGroupDTO)) {
            return R.error("门禁分组不能为空");
        }
        return R.data(plDoorPointGroupService.saveOrUpdateByParam(plDoorPointGroupDTO));
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "门禁分组详情", notes = "门禁分组详情")
    public R detail(Long id) {
        return R.data(plDoorPointGroupService.detailById(id));
    }

    /**
     * 根据主表id删除门禁分组
     * @param plDoorPointGroupDTO
     * @return
     */
    @PostMapping("/removeId")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主表id门禁分组删除", notes = "根据主表id门禁分组删除")
    public R removeId(@RequestBody PlDoorPointGroupDTO plDoorPointGroupDTO) throws Exception {
        return R.data(plDoorPointGroupService.deleteById(plDoorPointGroupDTO.getId()));
    }

    /**
     * 分页 门禁分组
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "分页 门禁分组", notes = "分页 门禁分组")
    public R<NestPage<PlDoorPointGroupVO>> page(PlDoorPointGroupReq req) {
        Page<PlDoorPointGroupReq> page = new Page<>();
        page.setCurrent(req.getCurrent());
        page.setSize(req.getSize());
        IPage<PlDoorPointGroupVO> pages = plDoorPointGroupService.pageByParam(page, req);
        return  R.data(NestPage.of(pages));
    }

    /**
     * 按条件查询门禁分组列表
     */
    @GetMapping("/listByParam")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "按条件查询门禁分组列表", notes = "按条件查询门禁分组列表")
    public R<List<PlDoorPointGroupLtVO>> listByParam(PlDoorPointGroupListReq req) {
        return R.data(plDoorPointGroupService.listByParam(req));
    }

}
