package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.SysConfig;
import com.ym.mec.biz.service.SysTenantConfigService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.tenant.TenantContextHolder;
import com.yonge.log.model.AuditLogAnnotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 
 * 系统配置控制层
 */
@RestController
@Api(tags = "系统参数设置")
@RequestMapping(value = "sysTenantConfig")
public class SysTenantConfigController extends BaseController {

	@Autowired
	private SysTenantConfigService sysTenantConfigService;
	@Autowired
	private SysUserFeignService sysUserFeignService;

	@ApiOperation(value = "参数列表")
	@GetMapping(value = "queryAll")
	public Object queryAll(String group) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		Map<String,Object> params = new HashMap<String, Object>(2);
		params.put("group", group);
		params.put("tenantId", sysUser.getTenantId());
		return succeed(sysTenantConfigService.queryAll(params));
	}

	@ApiOperation(value = "获取单个配置")
	@PostMapping(value = "findByName")
	public Object findByName(String configName) {
		return succeed(sysTenantConfigService.getTenantConfigValue(configName,TenantContextHolder.getTenantId()));
	}
}
