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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatPointLocationInfo;
import com.yuchen.saas.park.service.service.PmgBatPointLocationInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.web.bind.annotation.*;

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

/**
 * (PmgBatPointLocationInfo)表控制层 点位信息
 *
 * @author 任业政
 * @since 2021-09-13 11:45:09
 */
@Api(tags = "点位信息")
@RestController
@RequestMapping("/pointLocation")
public class PmgBatPointLocationInfoController {

    /**
     * 点位信息服务对象
     */
    @Resource
    private PmgBatPointLocationInfoService pmgBatPointLocationInfoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "通过主键查询单条数据")
    @GetMapping("/selectOne")
    public R selectOne(Long id) {
        return R.data(this.pmgBatPointLocationInfoService.getById(id));
    }


    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页查询", notes = "传入条件对象")
    @GetMapping("/selectByList")
    public R<IPage<PmgBatPointLocationInfo>> selectByList(PmgBatPointLocationInfo pointLocationInfo, Query query) {
        return R.data(pmgBatPointLocationInfoService.page(Condition.getPage(query)
                , new LambdaQueryWrapper<PmgBatPointLocationInfo>()
                        .like(Func.isNotEmpty(pointLocationInfo.getName()),PmgBatPointLocationInfo::getName,pointLocationInfo.getName())
                        .eq(Func.isNotEmpty(pointLocationInfo.getParkId()), PmgBatPointLocationInfo::getParkId, pointLocationInfo.getParkId())
                        .eq(Func.isNotEmpty(pointLocationInfo.getType()), PmgBatPointLocationInfo::getType, pointLocationInfo.getType())));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页查询", notes = "传入条件对象")
    @GetMapping("/listAll")
    public R<List<PmgBatPointLocationInfo>> listAll() {
        return R.data(pmgBatPointLocationInfoService.list());
    }



    /**
     * 新增 点位信息
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增 点位信息", notes = "新增 点位信息")
    public R save(@Valid @RequestBody PmgBatPointLocationInfo pointLocationInfo) {
        return R.status(pmgBatPointLocationInfoService.save(pointLocationInfo));
    }

    /**
     * 修改 点位信息
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改 点位信息", notes = "修改 点位信息")
    public R update(@Valid @RequestBody PmgBatPointLocationInfo pointLocationInfo) {
        return R.status(pmgBatPointLocationInfoService.updateById(pointLocationInfo));
    }


    /**
     * 删除 点位信息
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除 点位信息", notes = "删除 点位信息")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(pmgBatPointLocationInfoService.deleteLogic(Func.toLongList(ids)));
    }

    /**
     * 根据场景id查询出所有和点位关联的设备点位信息
     *
     * @param parkId
     * @param buildingId
     * @param floorId
     * @param roomId
     * @return
     */
    @GetMapping("/findByLocationEq")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "设备点位信息", tags = "返回对象信息")
    public R findByLocationEq(Long parkId, Long buildingId, Long floorId, Long roomId) {
        return R.data(pmgBatPointLocationInfoService.selectByAllEquipmentPoint(parkId, buildingId, floorId, roomId));
    }

    /**
     * 查询出所有和点位关联的设备点位信息
     *
     * @param parkId
     * @param buildingId
     * @param floorId
     * @param roomId
     * @return
     */
    @GetMapping("/findByIds")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "设备点位信息", tags = "返回对象信息")
    public R findByIds(Long parkId, Long buildingId, Long floorId, Long roomId) {
        return R.data(pmgBatPointLocationInfoService.selectAllLocationPoint(parkId, buildingId, floorId, roomId));
    }


}