package com.qmth.paper.library.api;


import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.paper.library.business.bean.result.EditResult;
import com.qmth.paper.library.common.bean.dto.syssetting.SettingObject;
import com.qmth.paper.library.common.contant.ApiPrefixConstant;
import com.qmth.paper.library.common.service.SysSettingService;
import com.qmth.paper.library.common.util.Result;
import com.qmth.paper.library.common.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
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 javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统设置 前端控制器
 * </p>
 */
@Api(tags = "系统设置controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + ApiPrefixConstant.PREFIX_SYS + "/setting")
@Validated
public class SysSettingController {

    @Resource
    private SysSettingService sysSettingService;

    @ApiOperation(value = "查询")
    @PostMapping("/get")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
    public Result getData() {
        return ResultUtil.ok(sysSettingService.getData());
    }


    @ApiOperation(value = "保存")
    @PostMapping("/save")
    @ApiResponses({@ApiResponse(code = 200, message = "保存/更新成功", response = EditResult.class)})
    public Result save(@RequestBody List<SettingObject> simpleObjectList) {
        return ResultUtil.ok(sysSettingService.saveData(simpleObjectList));
    }
}
