package com.sptg.estate.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.DeviceTestDto;
import com.sptg.estate.api.entity.DeviceTest;
import com.sptg.estate.api.feigns.DeviceTestFeign;
import com.sptg.estate.biz.service.DeviceTestServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * title: DeviceInstallationController
 * package: com.sptg.estate.biz.service
 * description: 设备检测 - 控制器
 *
 *               
 *                      
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/implement/device/test")
public class DeviceTestController implements DeviceTestFeign {

    private final DeviceTestServiceInterface deviceTestServiceInterface;

    @Override
    @PostMapping("/showList")
    public ResultBean<Page<DeviceTest>> showList(@RequestBody DeviceTestDto dto){
        Page<DeviceTest> deviceInstallationPage = this.deviceTestServiceInterface.showList(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,deviceInstallationPage);
    }

    @Override
    @PostMapping("/findById")
    public ResultBean<DeviceTest> findById(@RequestBody Long id) {
        DeviceTest deviceTest =null;
        if(id!=null&&id>0){
            deviceTest = this.deviceTestServiceInterface.findById(id);
        }
        return new ResultBean<>(ResultEnum.SUCCESS,deviceTest);
    }

    @Override
    @PostMapping("/checkState")
    public ResultBean<Boolean> checkState(@RequestBody DeviceTestDto dto) {
        boolean result = this.deviceTestServiceInterface.checkState(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }

    @Override
    @PostMapping("/countByOrgPosition")
    public ResultBean<Integer> countByOrgPosition(@RequestBody String orgPosition) {
        return this.deviceTestServiceInterface.countByOrgPosition(orgPosition);
    }

    @Override
    @PostMapping("/findListByPosition")
    public ResultBean<DeviceTest> findListByPosition(@RequestBody DeviceTestDto dto) {
        return this.deviceTestServiceInterface.findListByPosition(dto);
    }

    @Override
    @PostMapping("/findBySerialNumber")
    public ResultBean<DeviceTest> findBySerialNumber(@RequestBody String serialNumber) {
        return this.deviceTestServiceInterface.findBySerialNumber(serialNumber);
    }

    @Override
    @PostMapping("/insertEntity")
    public ResultBean<Boolean> insertEntity(@RequestBody DeviceTest deviceTest) {
        return new ResultBean<>(ResultEnum.SUCCESS,this.deviceTestServiceInterface.insert(deviceTest));
    }

    @Override
    @PostMapping("/findByDeviceInstallationIds")
    public ResultBean<DeviceTest> findByDeviceInstallationIds(@RequestBody List<Long> deviceInstallationIds) {
        return this.deviceTestServiceInterface.findByDeviceInstallationIds(deviceInstallationIds);
    }
}
