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.
133 lines
4.5 KiB
133 lines
4.5 KiB
/**
|
|
* Copyright (c) 2018 人人开源 All rights reserved.
|
|
*
|
|
* https://www.renren.io
|
|
*
|
|
* 版权所有,侵权必究!
|
|
*/
|
|
|
|
package com.epmet.controller;
|
|
|
|
import com.epmet.dto.SysParamsDTO;
|
|
import com.epmet.service.SysParamsService;
|
|
import com.epmet.commons.tools.constant.Constant;
|
|
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.excel.SysParamsExcel;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import springfox.documentation.annotations.ApiIgnore;
|
|
|
|
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")
|
|
@Api(tags="参数管理")
|
|
public class SysParamsController {
|
|
@Autowired
|
|
private SysParamsService sysParamsService;
|
|
|
|
@GetMapping("page")
|
|
@ApiOperation("分页")
|
|
@ApiImplicitParams({
|
|
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
|
|
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
|
|
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
|
|
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String") ,
|
|
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
|
|
})
|
|
public Result<PageData<SysParamsDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
|
PageData<SysParamsDTO> page = sysParamsService.page(params);
|
|
|
|
return new Result<PageData<SysParamsDTO>>().ok(page);
|
|
}
|
|
|
|
@GetMapping("{id}")
|
|
@ApiOperation("信息")
|
|
public Result<SysParamsDTO> get(@PathVariable("id") Long id){
|
|
SysParamsDTO data = sysParamsService.get(id);
|
|
|
|
return new Result<SysParamsDTO>().ok(data);
|
|
}
|
|
|
|
@PostMapping
|
|
@ApiOperation("保存")
|
|
public Result save(@RequestBody SysParamsDTO dto){
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
|
|
|
sysParamsService.save(dto);
|
|
|
|
return new Result();
|
|
}
|
|
|
|
@PutMapping
|
|
@ApiOperation("修改")
|
|
public Result update(@RequestBody SysParamsDTO dto){
|
|
//效验数据
|
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
|
|
|
sysParamsService.update(dto);
|
|
|
|
return new Result();
|
|
}
|
|
|
|
@DeleteMapping
|
|
@ApiOperation("删除")
|
|
public Result delete(@RequestBody Long[] ids){
|
|
//效验数据
|
|
AssertUtils.isArrayEmpty(ids, "id");
|
|
|
|
sysParamsService.delete(ids);
|
|
|
|
return new Result();
|
|
}
|
|
|
|
@GetMapping("export")
|
|
@ApiOperation("导出")
|
|
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
|
|
public void export(@ApiIgnore @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);
|
|
}
|
|
}
|
|
|