package org.nl.acs.device.device_driver;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.service.DeviceExtraService;
import org.nl.common.logging.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ldjun
 * @date 2021-03-16
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "设备驱动配置")
@RequestMapping("/api/device/driver/config")
@Slf4j
public class DeviceDriverConfigController {

    private final DeviceExtraService deviceExtraService;


    @PostMapping()
    @Log("设备驱动配置保存")
    @ApiOperation("设备驱动配置保存")
    public ResponseEntity<Object> save(@RequestBody Map map) throws Exception {
        final JSONObject model = new JSONObject();
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(map);
        //得到扩展属性表字段记录
        JSONObject form = jsonObject.getJSONObject("form");
        //设备标识
        String device_id = form.getString("device_id");
        form.put("device_id", device_id);
        deviceExtraService.createByDeviceConfig(form, "01");
        return new ResponseEntity(model, HttpStatus.OK);
    }

    @GetMapping
    @Log("查询设备")
    @ApiOperation("查询设备")
    //@PreAuthorize("@el.check('device:list')")
    public ResponseEntity<Object> query(@RequestParam Map whereJson) {
        return null;
    }
}
