统一返回结果

This commit is contained in:
shuzheng 2017-02-18 23:54:27 +08:00
parent 3eb2d9f1ac
commit bba0216787
5 changed files with 164 additions and 56 deletions

View File

@ -1,6 +1,12 @@
package com.zheng.upms.server.controller.manage;
import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
import com.zheng.common.base.BaseController;
import com.zheng.common.validator.LengthValidator;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.UpmsOrganization;
import com.zheng.upms.dao.model.UpmsOrganizationExample;
import com.zheng.upms.dao.model.UpmsSystem;
@ -43,7 +49,7 @@ public class UpmsOrganizationController extends BaseController {
@ApiOperation(value = "组织列表")
@RequiresPermissions("upms:organization:read")
@RequestMapping("/list")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@ -73,22 +79,29 @@ public class UpmsOrganizationController extends BaseController {
@ApiOperation(value = "新增组织")
@RequiresPermissions("upms:organization:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(UpmsOrganization upmsOrganization, ModelMap modelMap) {
public Object create(UpmsOrganization upmsOrganization) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsOrganization.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
long time = System.currentTimeMillis();
upmsOrganization.setCtime(time);
int count = upmsOrganizationService.insertSelective(upmsOrganization);
modelMap.put("count", count);
return "redirect:/manage/organization/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "删除组织")
@RequiresPermissions("upms:organization:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = upmsOrganizationService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/organization/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "修改组织")
@ -103,11 +116,18 @@ public class UpmsOrganizationController extends BaseController {
@ApiOperation(value = "修改组织")
@RequiresPermissions("upms:organization:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, UpmsOrganization upmsOrganization, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, UpmsOrganization upmsOrganization) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsOrganization.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
upmsOrganization.setOrganizationId(id);
int count = upmsOrganizationService.updateByPrimaryKeySelective(upmsOrganization);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/organization/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,6 +1,12 @@
package com.zheng.upms.server.controller.manage;
import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
import com.zheng.common.base.BaseController;
import com.zheng.common.validator.LengthValidator;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.UpmsPermission;
import com.zheng.upms.dao.model.UpmsPermissionExample;
import com.zheng.upms.rpc.api.UpmsPermissionService;
@ -56,7 +62,7 @@ public class UpmsPermissionController extends BaseController {
@ApiOperation(value = "权限列表")
@RequiresPermissions("upms:permission:read")
@RequestMapping("/list")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@ -91,23 +97,30 @@ public class UpmsPermissionController extends BaseController {
@ApiOperation(value = "新增权限")
@RequiresPermissions("upms:permission:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(UpmsPermission upmsPermission, ModelMap modelMap) {
public Object create(UpmsPermission upmsPermission) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsPermission.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
long time = System.currentTimeMillis();
upmsPermission.setCtime(time);
upmsPermission.setOrders(time);
int count = upmsPermissionService.insertSelective(upmsPermission);
modelMap.put("count", count);
return "redirect:/manage/permission/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "删除权限")
@RequiresPermissions("upms:permission:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = upmsPermissionService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/permission/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "修改权限")
@ -122,11 +135,18 @@ public class UpmsPermissionController extends BaseController {
@ApiOperation(value = "修改权限")
@RequiresPermissions("upms:permission:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, UpmsPermission upmsPermission, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, UpmsPermission upmsPermission) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsPermission.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
upmsPermission.setPermissionId(id);
int count = upmsPermissionService.updateByPrimaryKeySelective(upmsPermission);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/permission/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,6 +1,12 @@
package com.zheng.upms.server.controller.manage;
import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
import com.zheng.common.base.BaseController;
import com.zheng.common.validator.LengthValidator;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.UpmsRole;
import com.zheng.upms.dao.model.UpmsRoleExample;
import com.zheng.upms.rpc.api.UpmsRoleService;
@ -42,7 +48,7 @@ public class UpmsRoleController extends BaseController {
@ApiOperation(value = "角色列表")
@RequiresPermissions("upms:role:read")
@RequestMapping("/list")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@ -72,23 +78,30 @@ public class UpmsRoleController extends BaseController {
@ApiOperation(value = "新增角色")
@RequiresPermissions("upms:role:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(UpmsRole upmsRole, ModelMap modelMap) {
public Object create(UpmsRole upmsRole) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsRole.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
long time = System.currentTimeMillis();
upmsRole.setCtime(time);
upmsRole.setOrders(time);
int count = upmsRoleService.insertSelective(upmsRole);
modelMap.put("count", count);
return "redirect:/manage/role/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "删除角色")
@RequiresPermissions("upms:role:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = upmsRoleService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/role/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "修改角色")
@ -103,11 +116,18 @@ public class UpmsRoleController extends BaseController {
@ApiOperation(value = "修改角色")
@RequiresPermissions("upms:role:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, UpmsRole upmsRole, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, UpmsRole upmsRole) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsRole.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
upmsRole.setRoleId(id);
int count = upmsRoleService.updateByPrimaryKeySelective(upmsRole);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/role/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,6 +1,12 @@
package com.zheng.upms.server.controller.manage;
import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
import com.zheng.common.base.BaseController;
import com.zheng.common.validator.LengthValidator;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.UpmsSystem;
import com.zheng.upms.dao.model.UpmsSystemExample;
import com.zheng.upms.rpc.api.UpmsSystemService;
@ -42,7 +48,7 @@ public class UpmsSystemController extends BaseController {
@ApiOperation(value = "系统列表")
@RequiresPermissions("upms:system:read")
@RequestMapping("/list")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@ -66,29 +72,37 @@ public class UpmsSystemController extends BaseController {
@ApiOperation(value = "新增系统")
@RequiresPermissions("upms:system:create")
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String add() {
public String create() {
return "/manage/system/create";
}
@ApiOperation(value = "新增系统")
@RequiresPermissions("upms:system:create")
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String add(UpmsSystem upmsSystem, ModelMap modelMap) {
@ResponseBody
public Object create(UpmsSystem upmsSystem) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsSystem.getTitle(), new LengthValidator(1, 20, "标题"))
.on(upmsSystem.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
long time = System.currentTimeMillis();
upmsSystem.setCtime(time);
upmsSystem.setOrders(time);
int count = upmsSystemService.insertSelective(upmsSystem);
modelMap.put("count", count);
return "redirect:/manage/system/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "删除系统")
@RequiresPermissions("upms:system:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = upmsSystemService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/system/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "修改系统")
@ -103,11 +117,19 @@ public class UpmsSystemController extends BaseController {
@ApiOperation(value = "修改系统")
@RequiresPermissions("upms:system:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, UpmsSystem upmsSystem, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, UpmsSystem upmsSystem) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsSystem.getTitle(), new LengthValidator(1, 20, "标题"))
.on(upmsSystem.getName(), new LengthValidator(1, 20, "名称"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
upmsSystem.setSystemId(id);
int count = upmsSystemService.updateByPrimaryKeySelective(upmsSystem);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/system/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
}

View File

@ -1,6 +1,14 @@
package com.zheng.upms.server.controller.manage;
import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.FluentValidator;
import com.baidu.unbiz.fluentvalidator.ResultCollectors;
import com.zheng.common.base.BaseController;
import com.zheng.common.validator.LengthValidator;
import com.zheng.common.validator.NotNullValidator;
import com.zheng.common.validator.SizeValidator;
import com.zheng.upms.common.constant.UpmsResult;
import com.zheng.upms.common.constant.UpmsResultConstant;
import com.zheng.upms.dao.model.UpmsUser;
import com.zheng.upms.dao.model.UpmsUserExample;
import com.zheng.upms.rpc.api.UpmsUserService;
@ -42,7 +50,7 @@ public class UpmsUserController extends BaseController {
@ApiOperation(value = "用户列表")
@RequiresPermissions("upms:user:read")
@RequestMapping("/list")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ResponseBody
public Object list(
@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
@ -72,22 +80,31 @@ public class UpmsUserController extends BaseController {
@ApiOperation(value = "新增用户")
@RequiresPermissions("upms:user:create")
@ResponseBody
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(UpmsUser upmsUser, ModelMap modelMap) {
public Object create(UpmsUser upmsUser) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsUser.getUsername(), new LengthValidator(1, 20, "帐号"))
.on(upmsUser.getPassword(), new LengthValidator(5, 32, "密码"))
.on(upmsUser.getRealname(), new NotNullValidator("姓名"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
long time = System.currentTimeMillis();
upmsUser.setCtime(time);
int count = upmsUserService.insertSelective(upmsUser);
modelMap.put("count", count);
return "redirect:/manage/user/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "删除用户")
@RequiresPermissions("upms:user:delete")
@RequestMapping(value = "/delete/{ids}",method = RequestMethod.GET)
public String delete(@PathVariable("ids") String ids, ModelMap modelMap) {
@ResponseBody
public Object delete(@PathVariable("ids") String ids) {
int count = upmsUserService.deleteByPrimaryKeys(ids);
modelMap.put("count", count);
return "redirect:/manage/user/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
@ApiOperation(value = "修改用户")
@ -102,11 +119,20 @@ public class UpmsUserController extends BaseController {
@ApiOperation(value = "修改用户")
@RequiresPermissions("upms:user:update")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String update(@PathVariable("id") int id, UpmsUser upmsUser, ModelMap modelMap) {
@ResponseBody
public Object update(@PathVariable("id") int id, UpmsUser upmsUser) {
ComplexResult result = FluentValidator.checkAll()
.on(upmsUser.getUsername(), new LengthValidator(1, 20, "帐号"))
.on(upmsUser.getPassword(), new LengthValidator(5, 32, "密码"))
.on(upmsUser.getRealname(), new NotNullValidator("姓名"))
.doValidate()
.result(ResultCollectors.toComplex());
if (!result.isSuccess()) {
return new UpmsResult(UpmsResultConstant.INVALID_LENGTH, result.getErrors());
}
upmsUser.setUserId(id);
int count = upmsUserService.updateByPrimaryKeySelective(upmsUser);
modelMap.put("count", count);
modelMap.put("id", id);
return "redirect:/manage/user/list";
return new UpmsResult(UpmsResultConstant.SUCCESS, count);
}
}