package com.prolog.rdc.tms.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.product.core.tools.util.JsonMapper;
import com.prolog.rdc.tms.model.dto.SySParameterDTO;
import com.prolog.rdc.tms.model.vo.SySParameterVO;
import com.prolog.rdc.tms.service.SySParameterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.validation.Valid;

@RestController
@Api(tags = "系统参数")
@RequestMapping("/SySParameter")
public class SySParameterController {

    private final Logger logger = LoggerFactory.getLogger(SySParameterController.class);

    @Autowired
    private SySParameterService sySParameterService;

    @UserLog("系统参数查询")
    @ApiOperation(value = "系统参数查询", notes = "系统参数查询")
    @PostMapping("/queryParameter/v1.0")
    public RestMessage<SySParameterDTO> queryParameter() {
        SySParameterDTO sySParameter = sySParameterService.queryParameter();
        logger.info("- > queryParameter result={}", JsonMapper.toJsonString(sySParameter));
        return RestMessage.newInstance(true, "查询成功", sySParameter);
    }

    @UserLog("系统参数新增")
    @ApiOperation(value = "系统参数新增", notes = "系统参数新增")
    @PostMapping("/saveOrUpdate/v1.0")
    public RestMessage<Object> saveOrUpdate(@RequestBody @Valid SySParameterVO vo) {
        logger.info("- > saveOrUpdate vo={}", JsonMapper.toJsonString(vo));
        sySParameterService.saveOrUpdate(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }


}