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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgConfigParkSpaceInfo;
import com.yuchen.saas.park.service.service.PmgConfigParkSpaceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.nest.springwrap.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 刘通
 * @date 2020/12/11 14:27
 */
@RestController
@AllArgsConstructor
@RequestMapping("/parkSpaceClass")
@Api(value = "园区空间主题类型", tags = "园区空间主题类型信息表接口")
public class PmgConfigParkSpaceInfoController {

    @Autowired
    private PmgConfigParkSpaceInfoService pmgConfigParkSpaceInfoService;
    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "园区空间主题类型信息")
    public R<PmgConfigParkSpaceInfo> detail(PmgConfigParkSpaceInfo pmgConfigParkSpaceInfo) {
        PmgConfigParkSpaceInfo detail = pmgConfigParkSpaceInfoService.getOne(Condition.getQueryWrapper(pmgConfigParkSpaceInfo));
        return R.data(detail);
    }

    /**
     * 分页 园区空间主题类型信息
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "园区空间主题类型信息")
    public R<IPage<PmgConfigParkSpaceInfo>> list(PmgConfigParkSpaceInfo pmgConfigParkSpaceInfo, Query query) {
        LambdaQueryWrapper<PmgConfigParkSpaceInfo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(pmgConfigParkSpaceInfo.getParkId() != null, PmgConfigParkSpaceInfo::getParkId, pmgConfigParkSpaceInfo.getParkId());
        wrapper.like(StringUtil.isNotBlank(pmgConfigParkSpaceInfo.getName()), PmgConfigParkSpaceInfo::getName, pmgConfigParkSpaceInfo.getName());
        IPage<PmgConfigParkSpaceInfo> pages = pmgConfigParkSpaceInfoService.page(Condition.getPage(query), wrapper);
        return  R.data(pages);
    }

    /**
     * 新增 园区空间主题类型信息
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "传入园区空间主题类型信息")
    public R save(@Valid @RequestBody PmgConfigParkSpaceInfo pmgConfigParkSpaceInfo) {
        return R.status(pmgConfigParkSpaceInfoService.save(pmgConfigParkSpaceInfo));
    }
    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增或修改", notes = "传入园区空间主题类型信息")
    public R submit(@Valid @RequestBody PmgConfigParkSpaceInfo pmgConfigParkSpaceInfo) {
        return R.status(pmgConfigParkSpaceInfoService.submit(pmgConfigParkSpaceInfo));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入园区空间主题类型信息")
    public R update(@Valid @RequestBody PmgConfigParkSpaceInfo pmgConfigParkSpaceInfo) {
        return R.status(pmgConfigParkSpaceInfoService.updateById(pmgConfigParkSpaceInfo));
    }
    /**
     * 删除 园区空间主题类型信息
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(pmgConfigParkSpaceInfoService.deleteLogic(Func.toLongList(ids)));
    }

}
