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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatDeviceType;
import com.yuchen.saas.park.service.service.IDeviceType;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author 吕海泉
 * @create 2020/12/7 16:53
 */
@RestController
@AllArgsConstructor
@RequestMapping("/device/type")
@Api(value = "设备类型", tags = "设备类型接口")
public class ParkDeviceTypeController {


    @Autowired
    private IDeviceType iDeviceType;

    /**
     * 查询设备类型
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询设备类型", notes = "查询设备类型")
    public R<PmgBatDeviceType> detail(PmgBatDeviceType pmgBatDeviceType) {
        PmgBatDeviceType detail = iDeviceType.getOne(Condition.getQueryWrapper(pmgBatDeviceType));
        return R.data(detail);
    }


    /**
     * 分页 设备类型
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页 设备类型", notes = "分页 设备类型")
    public R<IPage<PmgBatDeviceType>> list(PmgBatDeviceType pmgBatDeviceType, Query query) {
        IPage<PmgBatDeviceType> pages = iDeviceType.page(Condition.getPage(query),Condition.getQueryWrapper(pmgBatDeviceType));
        return  R.data(pages);
    }


    /**
     * 新增 设备类型
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增 设备类型", notes = "新增 设备类型")
    public R save(@Valid @RequestBody PmgBatDeviceType pmgBatDeviceType) {
        return R.status(iDeviceType.save(pmgBatDeviceType));
    }
    /**
     * 修改 设备类型
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改 设备类型", notes = "修改 设备类型")
    public R update(@Valid @RequestBody PmgBatDeviceType pmgBatDeviceType) {
        return R.status(iDeviceType.updateById(pmgBatDeviceType));
    }


    /**
     * 删除 设备类型
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除 设备类型", notes = "删除 设备类型")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(iDeviceType.deleteLogic(Func.toLongList(ids)));
    }
}

