package com.prolog.rdc.tms.controller.basicConfigure;

import java.util.List;

import javax.validation.Valid;

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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.basicConfigure.ParamConfigQueryDTO;
import com.prolog.rdc.tms.model.entity.SysParamConfigModel;
import com.prolog.rdc.tms.model.vo.basicConfigure.ParamConfigSaveVO;
import com.prolog.rdc.tms.service.basicConfigure.SysParamConfigService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * 系统参数控制层
 *
 * @className :SysParamConfigController
 * @author :fanzw
 * @creationTime :2022/07/18
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/07/18
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "基础配置-系统参数")
@RestController
@RequestMapping("/sysParamConfig")
public class SysParamConfigController {

	@Autowired
	private SysParamConfigService sysParamConfigService;

	@UserLog("系统参数查询")
	@ApiOperation(value = "系统参数查询", notes = "系统参数查询")
	@PostMapping("/query")
	public RestMessage<List<ParamConfigQueryDTO>> listExecute() {
		List<ParamConfigQueryDTO> list = sysParamConfigService.list();
		return RestMessage.newInstance(true, "查询成功", list);
	}

	@UserLog("系统参数保存")
	@ApiOperation(value = "系统参数保存", notes = "系统参数保存")
	@PostMapping("/save")
	public RestMessage<Object> saveExecute(@RequestBody @Valid List<ParamConfigSaveVO> paramConfigSaveVOs) {
		sysParamConfigService.save(paramConfigSaveVOs);
		return RestMessage.newInstance(true, "保存成功", null);
	}

	@UserLog("通用方法通过参数编码查询单个系统参数配置")
	@ApiOperation(value = "通用方法通过参数编码查询单个系统参数配置", notes = "通用方法通过参数编码查询单个系统参数配置")
	@PostMapping("/getValue")
	public RestMessage<SysParamConfigModel> getValue(@RequestParam(value = "code") String code) throws Exception {
		SysParamConfigModel data = sysParamConfigService.getValue(code);
		return RestMessage.newInstance(true, "操作成功", data);
	}

}
