This commit is contained in:
xiangwbs
2018-06-26 20:50:24 +08:00
parent 929d46a0a7
commit ba27ad5baf
3 changed files with 67 additions and 64 deletions
@@ -1,5 +1,6 @@
package com.xwbing.domain.entity.model;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.Date;
@@ -1,10 +1,17 @@
package com.xwbing.service.rest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.constant.CommonConstant;
import com.xwbing.domain.entity.model.EmailModel;
import com.xwbing.domain.entity.rest.FilesUpload;
import com.xwbing.domain.entity.sys.SysConfig;
import com.xwbing.domain.mapper.rest.FilesUploadMapper;
import com.xwbing.exception.BusinessException;
import com.xwbing.service.sys.SysConfigService;
import com.xwbing.util.DigestsUtil;
import com.xwbing.util.RestMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -25,6 +32,8 @@ import java.util.Base64;
public class CommonService {
@Resource
private FilesUploadMapper uploadMapper;
@Resource
private SysConfigService sysConfigService;
/**
* 保存信息表单提交时获取校验签名
@@ -78,4 +87,45 @@ public class CommonService {
}
return result;
}
/**
* 添加邮箱配置
*
* @param emailModel
* @return
*/
public RestMessage saveOrUpdateEmail(EmailModel emailModel) {
SysConfig sysConfig = sysConfigService.getByCode(CommonConstant.EMAIL_KEY);
if (sysConfig == null) {
sysConfig = new SysConfig();
sysConfig.setName("邮箱配置");
sysConfig.setCode(CommonConstant.EMAIL_KEY);
sysConfig.setEnable(CommonConstant.IS_ENABLE);
sysConfig.setValue(JSON.toJSONString(emailModel));
return sysConfigService.save(sysConfig);
} else {
sysConfig.setValue(JSON.toJSONString(emailModel));
return sysConfigService.update(sysConfig);
}
}
/**
* 获取邮箱信息
*
* @return
*/
public EmailModel getEmail() {
SysConfig sysConfig = sysConfigService.getByCode(CommonConstant.EMAIL_KEY);
if (sysConfig == null) {
return new EmailModel();
} else {
String value = sysConfig.getValue();
if (StringUtils.isEmpty(value)) {
return new EmailModel();
} else {
return JSONObject.parseObject(value, EmailModel.class);
}
}
}
}
@@ -1,22 +1,18 @@
package com.xwbing.controller.sys;
import com.alibaba.fastjson.JSONObject;
import com.xwbing.domain.entity.sys.SysConfig;
import com.xwbing.domain.entity.vo.ListSysConfigVo;
import com.xwbing.annotation.LogInfo;
import com.xwbing.domain.entity.model.EmailModel;
import com.xwbing.domain.entity.vo.RestMessageVo;
import com.xwbing.domain.entity.vo.SysConfigVo;
import com.xwbing.service.sys.SysConfigService;
import com.xwbing.service.rest.CommonService;
import com.xwbing.util.JsonResult;
import com.xwbing.util.RestMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
/**
* 说明: 系统配置控制层
@@ -30,65 +26,21 @@ import java.util.List;
@RequestMapping("/config/")
public class SysConfigControl {
@Resource
private SysConfigService sysConfigService;
private CommonService commonService;
@ApiOperation(value = "新增", notes = "新增系统配置信息", response = RestMessageVo.class)
@PostMapping("save")
public JSONObject save(@RequestBody @Valid SysConfig sysConfig) {
String logMsg = "新增系统配置信息";
log.info(logMsg);
RestMessage result = sysConfigService.save(sysConfig);
return JsonResult.toJSONObj(result);
@LogInfo("获取邮箱配置信息")
@ApiOperation(value = "获取邮箱配置信息", response = RestMessageVo.class)
@GetMapping("getEmail")
public JSONObject getEmail() {
EmailModel email = commonService.getEmail();
return JsonResult.toJSONObj(email, "");
}
@ApiOperation(value = "删除", notes = "根据code删除系统配置信息", response = RestMessageVo.class)
@DeleteMapping("removeByCode/{code}")
public JSONObject removeByCode(@PathVariable String code) {
String logMsg = "根据code删除系统配置信息";
log.info(logMsg + " code:{}", code);
if (StringUtils.isEmpty(code)) {
return JsonResult.toJSONObj("code不能为空");
}
RestMessage result = sysConfigService.removeByCode(code);
return JsonResult.toJSONObj(result);
}
@ApiOperation(value = "修改", notes = "修改系统配置信息", response = RestMessageVo.class)
@PutMapping("update")
public JSONObject update(@RequestBody @Valid SysConfig sysConfig) {
String logMsg = "修改系统配置信息";
log.info(logMsg);
if (StringUtils.isEmpty(sysConfig.getCode())) {
return JsonResult.toJSONObj("配置项的code不能为空");
}
RestMessage result = sysConfigService.update(sysConfig);
return JsonResult.toJSONObj(result);
}
@ApiOperation(value = "查找", notes = "根据key查找系统配置信息", response = SysConfigVo.class)
@GetMapping("getByCode")
public JSONObject getByCode(@RequestParam String code) {
String logMsg = "根据code查找系统配置信息";
log.info(logMsg + " code:{}", code);
if (StringUtils.isEmpty(code)) {
return JsonResult.toJSONObj("code不能为空");
}
SysConfig one = sysConfigService.getByCode(code);
if (one == null) {
return JsonResult.toJSONObj("该配置不存在");
}
return JsonResult.toJSONObj(one, "");
}
@ApiOperation(value = "查找列表", notes = "根据是否启用查找配置列表", response = ListSysConfigVo.class)
@GetMapping("listByEnable")
public JSONObject listByEnable(@RequestParam String enable) {
String logMsg = "根据是否启用查找配置列表";
log.info(logMsg + " enable:{}", enable);
if (StringUtils.isEmpty(enable)) {
return JsonResult.toJSONObj("是否启用不能为空");
}
List<SysConfig> byEnable = sysConfigService.listByEnable(enable);
return JsonResult.toJSONObj(byEnable, "");
@LogInfo("添加/修改邮箱配置信息")
@ApiOperation(value = "添加/修改邮箱配置信息", response = RestMessageVo.class)
@PostMapping("saveOrUpdateEmail")
public JSONObject saveOrUpdateEmail(@RequestBody EmailModel emailModel) {
RestMessage restMessage = commonService.saveOrUpdateEmail(emailModel);
return JsonResult.toJSONObj(restMessage);
}
}