This commit is contained in:
xiangwb
2017-11-09 14:25:25 +08:00
parent 03974da97a
commit 4cb41dfc51
8 changed files with 53 additions and 50 deletions
@@ -1,5 +1,7 @@
package com.xwbing.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
@@ -16,15 +18,21 @@ import java.util.Date;
*/
@Data
@MappedSuperclass
@ApiModel
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 8901948362657956187L;
@Id
@Column(length = 50)
@ApiModelProperty(value = "主键")
private String id;
@ApiModelProperty(value = "创建者")
private String creator;
@ApiModelProperty(value = "修改者")
private String modifier;
@ApiModelProperty(value = "创建时间")
@Column(name = "create_time")
private Date createTime;
@ApiModelProperty(value = "修改时间")
@Column(name = "modified_time")
private Date modifiedTime;
}
@@ -1,5 +1,7 @@
package com.xwbing.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
@@ -17,30 +19,23 @@ import javax.validation.constraints.Pattern;
@EqualsAndHashCode(callSuper = true)
@Data
@Entity(name = "system_config")
@ApiModel//swagger
public class SysConfig extends BaseEntity {
private static final long serialVersionUID = -7587016038432881980L;
public static String table = "system_config";
/**
* 配置项的code
*/
@ApiModelProperty(value = "配置项的code",example = "email_config")
@NotBlank(message = "配置项的code不能为空")
@Length(min = 1, max = 50, message = "code长度为1-50")
private String code;
/**
* 配置项的值
*/
@ApiModelProperty(value = "配置项的值",example = "{}")
@NotBlank(message = "配置项的value不能为空")
private String value;
/**
* 配置项的描述(名称)
*/
@ApiModelProperty(value = "配置项的描述(名称)",example = "邮箱配置")
@NotBlank(message = "配置项的name不能为空")
@Length(min = 1, max = 20, message = "value长度为1-20")
private String name;
/**
* 是否启用
*/
@ApiModelProperty(value = "是否启用",example = "Y")
@NotBlank(message = "是否启用不能为空")
@Pattern(regexp = "[Y|N]",message = "是否启用格式为Y|N")
@Pattern(regexp = "[Y|N]", message = "是否启用格式为Y|N")
private String enable;
}
@@ -12,7 +12,7 @@ import java.util.List;
* 作者: xiangwb
*/
public interface SysConfigRepository extends JpaRepository<SysConfig, String> {
SysConfig findByCode(String code);
SysConfig getByCode(String code);
List<SysConfig> findByEnable(String enable);
List<SysConfig> getByEnable(String enable);
}
@@ -9,5 +9,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* 作者: xiangwb
*/
public interface SysUserRepository extends JpaRepository<SysUser, String> {
SysUser findByUserName(String name);
SysUser getByUserName(String name);
}
@@ -31,7 +31,7 @@ public class SysConfigService {
if (sysConfig == null) {
throw new BusinessException("配置数据不能为空");
}
SysConfig old = findByCode(sysConfig.getCode());
SysConfig old = getByCode(sysConfig.getCode());
if (old != null) {
throw new BusinessException(sysConfig.getCode() + "已存在");
}
@@ -50,7 +50,7 @@ public class SysConfigService {
public RestMessage removeByCode(String code) {
logger.info("删除配置信息");
RestMessage result = new RestMessage();
SysConfig old = findByCode(code);
SysConfig old = getByCode(code);
if (old == null) {
throw new BusinessException("该配置项不存在");
}
@@ -62,7 +62,7 @@ public class SysConfigService {
public RestMessage update(SysConfig sysConfig) {
RestMessage result = new RestMessage();
SysConfig old = findByCode(sysConfig.getCode());
SysConfig old = getByCode(sysConfig.getCode());
if (old == null) {
throw new BusinessException("该配置项不存在");
}
@@ -79,11 +79,11 @@ public class SysConfigService {
return result;
}
public SysConfig findByCode(String code) {
return sysConfigRepository.findByCode(code);
public SysConfig getByCode(String code) {
return sysConfigRepository.getByCode(code);
}
public List<SysConfig> findByEnable(String enable) {
return sysConfigRepository.findByEnable(enable);
public List<SysConfig> listByEnable(String enable) {
return sysConfigRepository.getByEnable(enable);
}
}
@@ -42,7 +42,7 @@ public class SysUserService {
*/
public RestMessage save(SysUser sysUser) {
RestMessage result = new RestMessage();
SysUser old = findByUserName(sysUser.getUserName());
SysUser old = getByUserName(sysUser.getUserName());
if (old != null) {
throw new BusinessException("已经存在此用户名");
}
@@ -76,7 +76,7 @@ public class SysUserService {
*/
public RestMessage removeById(String id) {
RestMessage result = new RestMessage();
SysUser old = findOne(id);
SysUser old = getOne(id);
if (old == null) {
throw new BusinessException("该对象不存在");
}
@@ -101,7 +101,7 @@ public class SysUserService {
*/
public RestMessage update(SysUser sysUser) {
RestMessage result = new RestMessage();
SysUser old = findOne(sysUser.getId());
SysUser old = getOne(sysUser.getId());
if (old == null) {
throw new BusinessException("该对象不存在");
}
@@ -133,7 +133,7 @@ public class SysUserService {
* @param id
* @return
*/
public SysUser findOne(String id) {
public SysUser getOne(String id) {
return sysUserRepository.findOne(id);
}
@@ -165,7 +165,7 @@ public class SysUserService {
*/
public RestMessage resetPassWord(String id) {
RestMessage result = new RestMessage();
SysUser old = findOne(id);
SysUser old = getOne(id);
if (old == null)
throw new BusinessException("未查询到用户信息");
if (CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID).equals(id))
@@ -197,7 +197,7 @@ public class SysUserService {
*/
public RestMessage updatePassWord(String newPassWord, String oldPassWord, String id) {
RestMessage result = new RestMessage();
SysUser sysUser = findOne(id);
SysUser sysUser = getOne(id);
if (sysUser == null)
throw new BusinessException("该用户不存在");
boolean flag = checkPassWord(oldPassWord, sysUser.getPassword(), sysUser.getSalt());
@@ -233,7 +233,7 @@ public class SysUserService {
throw new BusinessException("验证码错误");
}
//验证账号,密码
SysUser user = findByUserName(userName);
SysUser user = getByUserName(userName);
if (user == null)
throw new BusinessException("账号错误");
boolean flag = checkPassWord(passWord, user.getPassword(), user.getSalt());
@@ -264,7 +264,7 @@ public class SysUserService {
public RestMessage logout(HttpServletRequest request) {
RestMessage restMessage = new RestMessage();
String userId = (String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID);
SysUser user = findOne(userId);
SysUser user = getOne(userId);
if (user != null) {
CommonDataUtil.clearMap();
SysUserLoginInOut loginInOut = new SysUserLoginInOut();
@@ -290,8 +290,8 @@ public class SysUserService {
* @param userName
* @return
*/
private SysUser findByUserName(String userName) {
return sysUserRepository.findByUserName(userName);
private SysUser getByUserName(String userName) {
return sysUserRepository.getByUserName(userName);
}
/**
@@ -321,7 +321,7 @@ public class SysUserService {
* @return
*/
private boolean sendEmail(SysUser sysUser, String passWord) {
SysConfig sysConfig = sysConfigService.findByCode(CommonConstant.EMAIL_KEY);
SysConfig sysConfig = sysConfigService.getByCode(CommonConstant.EMAIL_KEY);
if (sysConfig == null) {
throw new BusinessException("没有查找到邮件配置项");
}
@@ -33,12 +33,12 @@ public class SysConfigControl {
private SysConfigService sysConfigService;
@ApiOperation(value = "新增", notes = "新增系统配置信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "code", value = "配置项的key,长度为1-50", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "value", value = "配置项的值", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "enable", value = "是否启用,格式为Y|N", paramType = "query", required = true, dataType = "string"),
@ApiImplicitParam(name = "name", value = "配置名称,长度为1-10", paramType = "query", required = true, dataType = "string")
})
// @ApiImplicitParams({
// @ApiImplicitParam(name = "code", value = "配置项的key,长度为1-50", paramType = "query", required = true, dataType = "string"),
// @ApiImplicitParam(name = "value", value = "配置项的值", paramType = "query", required = true, dataType = "string"),
// @ApiImplicitParam(name = "enable", value = "是否启用,格式为Y|N", paramType = "query", required = true, dataType = "string"),
// @ApiImplicitParam(name = "name", value = "配置名称,长度为1-10", paramType = "query", required = true, dataType = "string")
// })
@PostMapping("save")
public JSONObject save(@RequestBody @Valid SysConfig sysConfig) {
String logMsg = "新增系统配置信息";
@@ -78,14 +78,14 @@ public class SysConfigControl {
@ApiOperation(value = "查找", notes = "根据key查找系统配置信息")
@ApiImplicitParam(name = "code", value = "配置项的code", paramType = "query", required = true, dataType = "string")
@GetMapping("findByCode")
public JSONObject findByCode(@RequestParam String code) {
@GetMapping("getByCode")
public JSONObject getByCode(@RequestParam String code) {
String logMsg = "根据code查找系统配置信息";
logger.info(logMsg + " code:{}", code);
if (StringUtils.isEmpty(code)) {
return JSONObjResult.toJSONObj("code不能为空");
}
SysConfig one = sysConfigService.findByCode(code);
SysConfig one = sysConfigService.getByCode(code);
if (one == null) {
return JSONObjResult.toJSONObj("该配置不存在");
}
@@ -95,13 +95,13 @@ public class SysConfigControl {
@ApiOperation(value = "查找列表", notes = "根据是否启用查找配置列表")
@ApiImplicitParam(name = "enable", value = "是否启用,格式为Y|N", paramType = "query", required = true, dataType = "string")
@GetMapping("listByEnable")
public JSONObject findByEnable(@RequestParam String enable) {
public JSONObject listByEnable(@RequestParam String enable) {
String logMsg = "根据是否启用查找配置列表";
logger.info(logMsg + " enable:{}", enable);
if (StringUtils.isEmpty(enable)) {
return JSONObjResult.toJSONObj("是否启用不能为空");
}
List<SysConfig> byEnable = sysConfigService.findByEnable(enable);
List<SysConfig> byEnable = sysConfigService.listByEnable(enable);
return JSONObjResult.toJSONObj(byEnable, true, "");
}
}
@@ -57,12 +57,12 @@ public class SysUserControl {
}
@LogInfo("获取用户详情")
@GetMapping("findById")
public JSONObject findById(@RequestParam String id) {
@GetMapping("getById")
public JSONObject getById(@RequestParam String id) {
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
SysUser sysUser = sysUserService.findOne(id);
SysUser sysUser = sysUserService.getOne(id);
if (sysUser == null) {
return JSONObjResult.toJSONObj("未查到该对象");
}
@@ -70,8 +70,8 @@ public class SysUserControl {
}
@LogInfo("列表查询所有用户")
@GetMapping("findList")
public JSONObject findList() {
@GetMapping("listAll")
public JSONObject listAll() {
List<SysUser> list = sysUserService.listAll();
return JSONObjResult.toJSONObj(list, true, "");
}