package com.youchain.dropdown;

import com.youchain.annotation.AnonymousAccess;
import com.youchain.annotation.Log;
import com.youchain.basicdata.domain.Item;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.repository.ItemRepository;
import com.youchain.basicdata.repository.PointRepository;
import com.youchain.exception.handler.ApiResult;
import com.youchain.jamod.domain.ModbusInfo;
import com.youchain.jamod.repository.ModbusInfoRepository;
import com.youchain.jamod.service.ModbusInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
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;

@RestController
@RequiredArgsConstructor
@Api(tags = "下拉框加载")
@RequestMapping("/api/dropdown")
public class DropdownController {
    private final PointRepository pointRepository;
    private final ModbusInfoRepository modbusInfoRepository;
    private final ItemRepository itemRepository;
    @PostMapping("/pointData")
    @ApiOperation("全部点位")
    @AnonymousAccess
    public ResponseEntity<Object> pointData(){
        List<Point> pointList=pointRepository.findAll();
        ApiResult apiResult=ApiResult.fail(200,"成功",pointList);
        return new ResponseEntity<>(apiResult,apiResult.getStatus());
    }
    @PostMapping("/itemData")
    @ApiOperation("全部物料")
    @AnonymousAccess
    public ResponseEntity<Object> itemData(){
        List<Item> itemList=itemRepository.findAll();
        ApiResult apiResult=ApiResult.fail(200,"成功",itemList);
        return new ResponseEntity<>(apiResult,apiResult.getStatus());
    }
    @PostMapping("/modbusInfoData")
    @ApiOperation("全部modbusInfo")
    @AnonymousAccess
    public ResponseEntity<Object> modbusInfoData(){
        List<ModbusInfo> modbusInfoList=modbusInfoRepository.findAll();
        ApiResult apiResult=ApiResult.fail(200,"成功",modbusInfoList);
        return new ResponseEntity<>(apiResult,apiResult.getStatus());
    }
}
