package com.bonus.canteen.core.device.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.db.handler.StringHandler;
import com.bonus.canteen.core.device.service.ParamSettingService;
import com.bonus.canteen.core.device.vo.ParamSettingVO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.codehaus.groovy.tools.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "后台-参数设置")
@RestController
@RequestMapping("/paramSetting")
public class ParamSettingController extends BaseController {

    @Autowired
    private ParamSettingService service;

    @ApiOperation("更新参数设置")
    @PostMapping({"/update"})
    public AjaxResult updateDevice(@RequestBody @Valid ParamSettingVO dto) {
        if (ObjectUtil.isNull(dto.getId()) || ObjectUtil.isEmpty(dto.getId())){
            throw new ServiceException("参数id不能为空");
        }
        this.service.update(dto);
        return AjaxResult.success();
    }

    @ApiOperation(value = "获取参数")
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo() {
        return success(service.getInfo());
    }

}
