You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

112 lines
3.2 KiB

/**
* Copyright (c) 2018 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.epmet.controller;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.SysParamsDTO;
import com.epmet.excel.SysParamsExcel;
import com.epmet.service.SysParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 参数管理
*
* @author Mark sunlightcs@gmail.com
* @since 1.0.0
*/
@RestController
@RequestMapping("params")
public class SysParamsController {
@Autowired
private SysParamsService sysParamsService;
@GetMapping("page")
public Result<PageData<SysParamsDTO>> page(@RequestParam Map<String, Object> params){
PageData<SysParamsDTO> page = sysParamsService.page(params);
return new Result<PageData<SysParamsDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<SysParamsDTO> get(@PathVariable("id") Long id){
SysParamsDTO data = sysParamsService.get(id);
return new Result<SysParamsDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody SysParamsDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
sysParamsService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody SysParamsDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
sysParamsService.update(dto);
return new Result();
}
@DeleteMapping
public Result delete(@RequestBody Long[] ids){
//效验数据
AssertUtils.isArrayEmpty(ids, "id");
sysParamsService.delete(ids);
return new Result();
}
@GetMapping("export")
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<SysParamsDTO> list = sysParamsService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, SysParamsExcel.class);
}
/**
* 根据参数编码,获取参数值
* @param paramCode 参数编码
* @return 返回参数值
*/
@GetMapping("code/{paramCode}")
public String getValue(@PathVariable("paramCode") String paramCode){
return sysParamsService.getValue(paramCode);
}
/**
* 根据参数编码,更新参数值
* @param paramCode 参数编码
* @param paramValue 参数值
*/
@PutMapping("code/{paramCode}")
public void updateValueByCode(@PathVariable("paramCode") String paramCode, @RequestParam("paramValue") String paramValue){
sysParamsService.updateValueByCode(paramCode, paramValue);
}
}