package org.springblade.device.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.device.entity.Gb28181Device;
import org.springblade.device.vo.Gb28181DeviceVO;
import org.springblade.device.wrapper.GbDeviceWrapper;
import org.springblade.device.service.IGbDeviceService;

import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-12-06
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/gbdevice")

public class GbDeviceClient implements IGbDeviceClient {

    private final IGbDeviceService gbDeviceService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public Gb28181DeviceVO detail(Gb28181Device gb28181Device) {
        Gb28181Device detail = gbDeviceService.getOne(Condition.getQueryWrapper(gb28181Device));
        return GbDeviceWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<Gb28181DeviceVO> list(Gb28181Device gb28181Device) {
        return GbDeviceWrapper.build().listVO(gbDeviceService.list(Condition.getQueryWrapper(gb28181Device)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Gb28181Device gb28181Device) {
        return gbDeviceService.save(gb28181Device);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Gb28181Device gb28181Device) {
        return gbDeviceService.updateById(gb28181Device);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Gb28181Device gb28181Device) {
        return gbDeviceService.saveOrUpdate(gb28181Device);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return gbDeviceService.deleteLogic(Func.toLongList(ids));
        }

	/**
	 * 设备绑定
	 */
	@Override
	@PostMapping("/bind")
	public R bind(@RequestBody Gb28181Device gb28181Device) {
		return this.gbDeviceService.bind(gb28181Device);
	}


}
