This commit is contained in:
xiangwb
2018-02-27 16:37:49 +08:00
parent bdda8df5fc
commit 5746ebfc1d
21 changed files with 212 additions and 113 deletions
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSONObject;
import com.xwbing.annotation.LogInfo;
import com.xwbing.domain.entity.ExpressInfo;
import com.xwbing.domain.entity.vo.ExpressInfoVo;
import com.xwbing.exception.BusinessException;
import com.xwbing.redis.RedisService;
import com.xwbing.service.other.CookieSessionService;
import com.xwbing.service.other.ExpressDeliveryService;
@@ -71,8 +70,9 @@ public class TestControl {
@LogInfo("快递查询")
@PostMapping("expressInfo")
public JSONObject getExpressInfo(@RequestBody ExpressInfo info) {
if (StringUtils.isEmpty(info.getLogisticCode()) || StringUtils.isEmpty(info.getShipperCode()))
if (StringUtils.isEmpty(info.getLogisticCode()) || StringUtils.isEmpty(info.getShipperCode())) {
return JSONObjResult.toJSONObj("快递公司或物流单号不能为空");
}
ExpressInfoVo infoVo = expressDeliveryService.queryOrderTraces(info);
return JSONObjResult.toJSONObj(infoVo, "查询快递信息成功");
}
@@ -87,8 +87,9 @@ public class TestControl {
@LogInfo("解析二维码")
@GetMapping("decode")
public JSONObject decode(@RequestParam String path) {
if (StringUtils.isEmpty(path))
if (StringUtils.isEmpty(path)) {
return JSONObjResult.toJSONObj("二维码图片路径不能为空");
}
File file = new File(path);
RestMessage decode = qrCodeZipService.decode(file);
return JSONObjResult.toJSONObj(decode);
@@ -97,8 +98,9 @@ public class TestControl {
@LogInfo("导出zip")
@GetMapping("batchGetImage")
public JSONObject batchGetImage(HttpServletResponse response, @RequestParam String[] names, @RequestParam String fileName) {
if (StringUtils.isEmpty(fileName))
if (StringUtils.isEmpty(fileName)) {
return JSONObjResult.toJSONObj("zip名称不能为空");
}
RestMessage restMessage = qrCodeZipService.batchGetImage(response, names, fileName);
return JSONObjResult.toJSONObj(restMessage);
}
@@ -153,8 +155,9 @@ public class TestControl {
e.printStackTrace();
}
//出现异常,异常会被限制在执行任务的线程范围内
if (1 == 1)
if (1 == 1) {
throw new RuntimeException("545456");
}
return "world";
}), (s1, s2) -> {
JSONObject object = new JSONObject();
@@ -45,8 +45,9 @@ public class DataDictionaryControl {
@PostMapping("update")
@ApiOperation(value = "修改字典", response = RestMessageVo.class)
public JSONObject update(@RequestBody DataDictionary dictionary) {
if (StringUtils.isEmpty(dictionary.getId()))
if (StringUtils.isEmpty(dictionary.getId())) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = dataDictionaryService.update(dictionary);
return JSONObjResult.toJSONObj(result);
}
@@ -55,11 +56,13 @@ public class DataDictionaryControl {
@ApiOperation(value = "获取字典详情", response = DataDictionaryVo.class)
@GetMapping("getById")
public JSONObject getById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
DataDictionary dataDictionary = dataDictionaryService.getById(id);
if (dataDictionary == null)
if (dataDictionary == null) {
return JSONObjResult.toJSONObj("该字典不存在");
}
return JSONObjResult.toJSONObj(dataDictionary, "");
}
@@ -70,8 +73,9 @@ public class DataDictionaryControl {
public JSONObject uniqueCode(@RequestParam String code, String id) {
boolean b = dataDictionaryService.uniqueCode(code, id);
RestMessage result = new RestMessage();
if (b)
if (b) {
result.setSuccess(true);
}
return JSONObjResult.toJSONObj(result);
}
@@ -83,8 +87,9 @@ public class DataDictionaryControl {
})
@PostMapping("findListByParent")
public JSONObject findListByParent(String enable, String parentId) {
if (StringUtils.isEmpty(parentId))
if (StringUtils.isEmpty(parentId)) {
parentId = CommonConstant.ROOT;
}
List<DataDictionary> listByParent = dataDictionaryService.findListByParent(parentId, enable);
return JSONObjResult.toJSONObj(listByParent, "");
}
@@ -94,8 +99,9 @@ public class DataDictionaryControl {
@ApiImplicitParam(name = "enable", value = "是否启用,格式为Y|N", paramType = "query", dataType = "string")
@PostMapping("findListByCode")
public JSONObject findListByCode(@RequestParam String code, String enable) {
if (StringUtils.isEmpty(code))
if (StringUtils.isEmpty(code)) {
return JSONObjResult.toJSONObj("编码不能为空");
}
List<DataDictionary> listByParent = dataDictionaryService.findListByCode(code, enable);
return JSONObjResult.toJSONObj(listByParent, "");
}
@@ -43,8 +43,9 @@ public class SysAuthorityControl {
public JSONObject save(@RequestBody SysAuthority sysAuthority) {
RestMessage save = sysAuthorityService.save(sysAuthority);
//删除缓存
if (save.isSuccess())
if (save.isSuccess()) {
redisService.del(CommonConstant.AUTHORITY_THREE);
}
return JSONObjResult.toJSONObj(save);
}
@@ -52,12 +53,14 @@ public class SysAuthorityControl {
@ApiOperation(value = "删除权限", response = RestMessageVo.class)
@GetMapping("removeById")
public JSONObject removeById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = sysAuthorityService.removeById(id);
//删除缓存
if (result.isSuccess())
if (result.isSuccess()) {
redisService.del(CommonConstant.AUTHORITY_THREE);
}
return JSONObjResult.toJSONObj(result);
}
@@ -65,8 +68,9 @@ public class SysAuthorityControl {
@ApiOperation(value = "修改权限", response = RestMessageVo.class)
@PostMapping("update")
public JSONObject update(@RequestBody SysAuthority sysAuthority) {
if (StringUtils.isEmpty(sysAuthority.getId()))
if (StringUtils.isEmpty(sysAuthority.getId())) {
return JSONObjResult.toJSONObj("主键不能为空");
}
String enable = sysAuthority.getEnable();
// 如果禁用,查询是否有子节点,如果有,子节点也要被禁用
if (CommonConstant.IS_NOT_ENABLE.equals(enable)) {
@@ -78,14 +82,16 @@ public class SysAuthorityControl {
// 如果是启用,看父节点是否被禁用,一级的不需要判断
if (!CommonConstant.ROOT.equals(sysAuthority.getParentId())) {
SysAuthority parent = sysAuthorityService.getById(sysAuthority.getParentId());
if (parent != null && CommonEnum.YesOrNoEnum.NO.getCode().equals(parent.getEnable()))
if (parent != null && CommonEnum.YesOrNoEnum.NO.getCode().equals(parent.getEnable())) {
return JSONObjResult.toJSONObj("父节点已被禁用,请先启用父节点");
}
}
}
RestMessage result = sysAuthorityService.update(sysAuthority);
//删除缓存
if (result.isSuccess())
if (result.isSuccess()) {
redisService.del(CommonConstant.AUTHORITY_THREE);
}
return JSONObjResult.toJSONObj(result);
}
@@ -103,10 +109,12 @@ public class SysAuthorityControl {
@ApiOperation(value = "根据父节点查询子节点", response = ListSysAuthorityVo.class)
@ApiImplicitParam(name = "parentId", value = "父id,可为空", paramType = "query", dataType = "string")
public JSONObject listByParentId(String parentId) {
if (StringUtils.isEmpty(parentId))
if (StringUtils.isEmpty(parentId)) {
parentId = CommonConstant.ROOT;
if (!CommonConstant.ROOT.equals(parentId) && sysAuthorityService.getById(parentId) == null)
}
if (!CommonConstant.ROOT.equals(parentId) && sysAuthorityService.getById(parentId) == null) {
return JSONObjResult.toJSONObj("父节点不存在");
}
List<SysAuthority> queryByParentId = sysAuthorityService.listByParentEnable(parentId, null);
return JSONObjResult.toJSONObj(queryByParentId, "");
}
@@ -77,8 +77,9 @@ public class SysConfigControl {
public JSONObject update(SysConfig sysConfig) {
String logMsg = "修改系统配置信息";
logger.info(logMsg);
if (StringUtils.isEmpty(sysConfig.getCode()))
if (StringUtils.isEmpty(sysConfig.getCode())) {
return JSONObjResult.toJSONObj("配置项的code不能为空");
}
RestMessage result = sysConfigService.update(sysConfig);
return JSONObjResult.toJSONObj(result);
}
@@ -52,8 +52,9 @@ public class SysRoleControl {
@ApiOperation(value = "删除角色", response = RestMessageVo.class)
@GetMapping("removeById")
public JSONObject removeById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = sysRoleService.removeById(id);
return JSONObjResult.toJSONObj(result);
}
@@ -62,8 +63,9 @@ public class SysRoleControl {
@ApiOperation(value = "修改角色", response = RestMessageVo.class)
@PostMapping("update")
public JSONObject update(@RequestBody SysRole sysRole) {
if (StringUtils.isEmpty(sysRole.getId()))
if (StringUtils.isEmpty(sysRole.getId())) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = sysRoleService.update(sysRole);
return JSONObjResult.toJSONObj(result);
}
@@ -72,11 +74,13 @@ public class SysRoleControl {
@ApiOperation(value = "获取角色详情", response = SysRoleVo.class)
@GetMapping("getById")
public JSONObject getById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
SysRole sysRole = sysRoleService.getById(id);
if (sysRole == null)
if (sysRole == null) {
return JSONObjResult.toJSONObj("该角色不存在");
}
return JSONObjResult.toJSONObj(sysRole, "");
}
@@ -94,11 +98,13 @@ public class SysRoleControl {
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
@PostMapping("listAuthorityByRoleId")
public JSONObject listAuthorityByRoleId(@RequestParam String roleId, String enable) {
if (StringUtils.isEmpty(roleId))
if (StringUtils.isEmpty(roleId)) {
return JSONObjResult.toJSONObj("角色主键不能为空");
}
SysRole sysRole = sysRoleService.getById(roleId);
if (sysRole == null)
if (sysRole == null) {
return JSONObjResult.toJSONObj("该角色不存在");
}
List<SysAuthority> authoritys = sysAuthorityService.listByRoleIdEnable(roleId, enable);
return JSONObjResult.toJSONObj(authoritys, "");
}
@@ -107,13 +113,16 @@ public class SysRoleControl {
@ApiOperation(value = "保存角色权限", response = RestMessageVo.class)
@PostMapping("saveAuthority")
public JSONObject saveAuthority(@RequestParam String authorityIds, @RequestParam String roleId) {
if (StringUtils.isEmpty(authorityIds))
if (StringUtils.isEmpty(authorityIds)) {
return JSONObjResult.toJSONObj("权限主键集合不能为空");
if (StringUtils.isEmpty(roleId))
}
if (StringUtils.isEmpty(roleId)) {
return JSONObjResult.toJSONObj("角色主键不能为空");
}
SysRole sysRole = sysRoleService.getById(roleId);
if (sysRole == null)
if (sysRole == null) {
return JSONObjResult.toJSONObj("该角色不存在");
}
String ids[] = authorityIds.split(",");
List<SysRoleAuthority> list = new ArrayList<>();
SysRoleAuthority roleAuthority;
@@ -61,8 +61,9 @@ public class SysUserControl {
@ApiOperation(value = "删除用户", response = RestMessageVo.class)
@GetMapping("removeById")
public JSONObject removeById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = sysUserService.removeById(id);
return JSONObjResult.toJSONObj(result);
}
@@ -71,8 +72,9 @@ public class SysUserControl {
@ApiOperation(value = "修改用户信息", response = RestMessageVo.class)
@PostMapping("update")
public JSONObject update(@RequestBody @Valid SysUser sysUser) {
if (StringUtils.isEmpty(sysUser.getId()))
if (StringUtils.isEmpty(sysUser.getId())) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage result = sysUserService.update(sysUser);
return JSONObjResult.toJSONObj(result);
}
@@ -81,11 +83,13 @@ public class SysUserControl {
@ApiOperation(value = "获取用户详情", response = SysUserVo.class)
@GetMapping("getById")
public JSONObject getById(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
SysUser sysUser = sysUserService.getById(id);
if (sysUser == null)
if (sysUser == null) {
return JSONObjResult.toJSONObj("未查到该对象");
}
return JSONObjResult.toJSONObj(sysUser, "");
}
@@ -101,10 +105,12 @@ public class SysUserControl {
@ApiOperation(value = "登录", response = RestMessageVo.class)
@PostMapping("login")
public JSONObject login(HttpServletRequest request, @RequestParam String userName, @RequestParam String passWord, @RequestParam String checkCode) {
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(passWord))
if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(passWord)) {
return JSONObjResult.toJSONObj("用户名或密码不能为空");
if (StringUtils.isEmpty(checkCode))
}
if (StringUtils.isEmpty(checkCode)) {
return JSONObjResult.toJSONObj("请输入验证码");
}
RestMessage login = sysUserService.login(request, userName, passWord, checkCode);
return JSONObjResult.toJSONObj(login);
}
@@ -121,10 +127,12 @@ public class SysUserControl {
@ApiOperation(value = "修改密码", response = RestMessageVo.class)
@PostMapping("updatePassWord")
public JSONObject updatePassWord(@RequestParam String newPassWord, @RequestParam String oldPassWord, @RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(oldPassWord))
}
if (StringUtils.isEmpty(newPassWord) || StringUtils.isEmpty(oldPassWord)) {
return JSONObjResult.toJSONObj("原密码或新密码不能为空");
}
RestMessage restMessage = sysUserService.updatePassWord(newPassWord, oldPassWord, id);
return JSONObjResult.toJSONObj(restMessage);
}
@@ -133,8 +141,9 @@ public class SysUserControl {
@ApiOperation(value = "重置密码", response = RestMessageVo.class)
@GetMapping("resetPassWord")
public JSONObject resetPassWord(@RequestParam String id) {
if (StringUtils.isEmpty(id))
if (StringUtils.isEmpty(id)) {
return JSONObjResult.toJSONObj("主键不能为空");
}
RestMessage restMessage = sysUserService.resetPassWord(id);
return JSONObjResult.toJSONObj(restMessage);
}
@@ -144,21 +153,24 @@ public class SysUserControl {
@GetMapping("getLoginUserInfo")
public JSONObject getLoginUserInfo() {
SysUser sysUser = sysUserService.getById((String) CommonDataUtil.getToken(CommonConstant.CURRENT_USER_ID));
if (sysUser == null)
if (sysUser == null) {
return JSONObjResult.toJSONObj("未获取到当前登录用户信息");
}
List<SysAuthority> button = new ArrayList<>();
List<SysAuthority> menu = new ArrayList<>();
List<SysAuthority> list;
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(sysUser.getAdmin()))
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(sysUser.getAdmin())) {
list = sysAuthorityService.listByEnable(CommonEnum.YesOrNoEnum.YES.getCode());
else
} else {
list = sysUserService.listAuthorityByIdAndEnable(sysUser.getId(), CommonEnum.YesOrNoEnum.YES.getCode());
}
if (CollectionUtils.isNotEmpty(list)) {
for (SysAuthority sysAuthority : list) {
if (sysAuthority.getType() == CommonEnum.MenuOrButtonEnum.MENU.getCode())
if (sysAuthority.getType() == CommonEnum.MenuOrButtonEnum.MENU.getCode()) {
menu.add(sysAuthority);
else
} else {
button.add(sysAuthority);
}
}
}
sysUser.setMenus(menu);
@@ -170,15 +182,19 @@ public class SysUserControl {
@ApiOperation(value = "保存用户角色", response = RestMessageVo.class)
@PostMapping("saveRole")
public JSONObject saveRole(@RequestParam String roleIds, @RequestParam String userId) {
if (StringUtils.isEmpty(roleIds))
if (StringUtils.isEmpty(roleIds)) {
return JSONObjResult.toJSONObj("角色主键不能为空");
if (StringUtils.isEmpty(userId))
}
if (StringUtils.isEmpty(userId)) {
return JSONObjResult.toJSONObj("用户主键不能为空");
}
SysUser old = sysUserService.getById(userId);
if (old == null)
if (old == null) {
return JSONObjResult.toJSONObj("该用户不存在");
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(old.getAdmin()))
}
if (CommonEnum.YesOrNoEnum.YES.getCode().equalsIgnoreCase(old.getAdmin())) {
return JSONObjResult.toJSONObj("不能对管理员进行操作");
}
String ids[] = roleIds.split(",");
List<SysUserRole> list = new ArrayList<>();
SysUserRole userRole;
@@ -197,8 +213,9 @@ public class SysUserControl {
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
@PostMapping("listRoleByUserId")
public JSONObject listRoleByUserId(@RequestParam String userId, String enable) {
if (StringUtils.isEmpty(userId))
if (StringUtils.isEmpty(userId)) {
return JSONObjResult.toJSONObj("用户主键不能为空");
}
List<SysRole> list = sysRoleService.listByUserIdEnable(userId, enable);
return JSONObjResult.toJSONObj(list, "");
}
@@ -208,8 +225,9 @@ public class SysUserControl {
@ApiImplicitParam(name = "enable", value = "是否启用,格式Y|N", paramType = "query", dataType = "string")
@PostMapping("listAuthorityByUserId")
public JSONObject listAuthorityByUserId(@RequestParam String userId, String enable) {
if (StringUtils.isEmpty(userId))
if (StringUtils.isEmpty(userId)) {
return JSONObjResult.toJSONObj("用户主键不能为空");
}
List<SysAuthority> list = sysUserService.listAuthorityByIdAndEnable(userId, enable);
return JSONObjResult.toJSONObj(list, "");
}
@@ -63,8 +63,9 @@ public class GlobalExceptionHandler {
String errorMessages = cause.getMessage();
logger.error(errorMessages);
String detail = cause.toString();
if (!detail.contains("BusinessException"))
if (!detail.contains("BusinessException")) {
errorMessages = "异步获取数据出错";
}
return JSONObjResult.toJSONObj(errorMessages);
}