Commit 8d92466c by chenweisong

更新

parent f505809d
......@@ -2,7 +2,7 @@ package com.keymobile.rest.common.conf;
import com.keymobile.rest.common.bean.ApiResponse;
import com.keymobile.rest.common.constant.ApiConstant;
import com.keymobile.rest.common.exception.TwinkleException;
import com.keymobile.rest.common.exception.CommonException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
......@@ -27,7 +27,7 @@ public class ExceptionHandlerConfig {
*/
@ExceptionHandler(Exception.class)
public ApiResponse globalException(Throwable ex) {
if (ex instanceof TwinkleException) {
if (ex instanceof CommonException) {
logger.warn("访问出错:" + ex.getMessage());
return ApiResponse.fail(ApiConstant.FAILED_CODE, ex.getMessage());
}
......
......@@ -9,10 +9,10 @@ import lombok.Data;
* @date :2019/1/12 23:28
*/
@Data
public class TwinkleException extends RuntimeException {
public class CommonException extends RuntimeException {
private static final long serialVersionUID = 3455708526465670030L;
public TwinkleException(String msg) {
public CommonException(String msg) {
super(msg);
}
}
package com.keymobile.rest.common.validator;
import com.keymobile.rest.common.exception.TwinkleException;
import com.keymobile.rest.common.exception.CommonException;
import java.util.Collection;
import java.util.Map;
......@@ -12,37 +12,37 @@ import java.util.regex.Pattern;
* @author :chenws
* @date :2019/1/12 23:28
*/
public final class TwinkleValidator extends AbstractValidator {
public final class CommonValidator extends AbstractValidator {
public static void isTrue(boolean flag, String message) {
if (!flag) {
throw new TwinkleException(message);
throw new CommonException(message);
}
}
public static void isFalse(boolean flag, String message) {
if (flag) {
throw new TwinkleException(message);
throw new CommonException(message);
}
}
public static void notLessThan(int value, int flag, String message) {
if (value < flag) {
throw new TwinkleException(message);
throw new CommonException(message);
}
}
public static void notMessThan(int value, int flag, String message) {
if (value > flag) {
throw new TwinkleException(message);
throw new CommonException(message);
}
}
public static <T> boolean notNull(T value, String message) {
boolean isValid = notNull(value);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -53,7 +53,7 @@ public final class TwinkleValidator extends AbstractValidator {
}
boolean isValid = Pattern.matches("^\\d+$", input);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -61,7 +61,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static <T extends CharSequence> boolean notEmpty(T value, String message) {
boolean isValid = notEmpty(value);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -69,7 +69,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static <T> boolean notEmpty(T[] value, String message) {
boolean isValid = notEmpty(value);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -77,7 +77,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static <T extends Collection<?>> boolean notEmpty(T value, String message) {
boolean isValid = notEmpty(value);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -85,7 +85,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static <T extends Map<?, ?>> boolean notEmpty(T value, String message) {
boolean isValid = notEmpty(value);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -93,7 +93,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static boolean maxLength(String value, int maxLength, String message) {
boolean isValid = maxLength(value, maxLength);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -101,7 +101,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static boolean range(String value, int minLength, int maxLength, String message) {
boolean isValid = range(value, minLength, maxLength);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......@@ -109,7 +109,7 @@ public final class TwinkleValidator extends AbstractValidator {
public static boolean range(Integer value, int min, int max, String message) {
boolean isValid = range(value, min, max);
if (!isValid) {
throw new TwinkleException(message);
throw new CommonException(message);
}
return isValid;
}
......
......@@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap;
import com.keymobile.rest.common.bean.ApiResponse;
import com.keymobile.rest.common.utils.BeanUtils;
import com.keymobile.rest.common.utils.DateUtil;
import com.keymobile.rest.common.validator.TwinkleValidator;
import com.keymobile.rest.common.validator.CommonValidator;
import com.keymobile.rest.model.*;
import com.keymobile.rest.model.Process;
import com.keymobile.rest.service.*;
......@@ -84,7 +84,7 @@ public class TaskController {
@PostMapping(value = "/get")
public ApiResponse get(long taskId) {
Activity activity = activityService.get(taskId);
TwinkleValidator.notNull(activity, "活动不存在");
CommonValidator.notNull(activity, "活动不存在");
return ApiResponse.ok(activity);
}
......@@ -134,10 +134,10 @@ public class TaskController {
@ApiOperation(value = "新建活动")
@PostMapping(value = "/create")
public ApiResponse createTask(@RequestBody TaskForm form) {
TwinkleValidator.notEmpty(form.getName(), "名称不能为空");
TwinkleValidator.notNull(form.getType(), "类型不能为空");
CommonValidator.notEmpty(form.getName(), "名称不能为空");
CommonValidator.notNull(form.getType(), "类型不能为空");
TwinkleValidator.isTrue(form.getExcels() != null && form.getExcels().size() != 0, "补录模板不能为空");
CommonValidator.isTrue(form.getExcels() != null && form.getExcels().size() != 0, "补录模板不能为空");
// 创建人 为 manager
User admin = getAdmin();
form.setUser(admin);
......@@ -151,15 +151,15 @@ public class TaskController {
// 新建excel实例
List<ExcelForm> excelFormList = form.getExcels();
excelFormList.forEach(excelForm -> {
TwinkleValidator.isTrue(excelForm.getName() != null, "模板名称不能为空");
TwinkleValidator.isTrue(excelForm.getConfig() != null, "模板配置config不能为空");
TwinkleValidator.isTrue(excelForm.getScopeId() != null && excelForm.getScopeId() != 0, "模板scopeId不能为空");
TwinkleValidator.isTrue(excelForm.getNeedAudit() != null && excelForm.getNeedAudit() != 0, "模板needAudit不能为空");
TwinkleValidator.isTrue(excelForm.getNeedConfirm() != null && excelForm.getNeedConfirm() != 0, "模板needConfirm不能为空");
CommonValidator.isTrue(excelForm.getName() != null, "模板名称不能为空");
CommonValidator.isTrue(excelForm.getConfig() != null, "模板配置config不能为空");
CommonValidator.isTrue(excelForm.getScopeId() != null && excelForm.getScopeId() != 0, "模板scopeId不能为空");
CommonValidator.isTrue(excelForm.getNeedAudit() != null && excelForm.getNeedAudit() != 0, "模板needAudit不能为空");
CommonValidator.isTrue(excelForm.getNeedConfirm() != null && excelForm.getNeedConfirm() != 0, "模板needConfirm不能为空");
RecordScope scope = recordScopeService.findById(excelForm.getScopeId());
TwinkleValidator.isTrue(scope != null, "补录范围不能为空");
TwinkleValidator.isFalse((StringUtils.isEmpty(excelForm.getUpStreamAddr()) && StringUtils.isNotEmpty(excelForm.getBackStreamAddr())
CommonValidator.isTrue(scope != null, "补录范围不能为空");
CommonValidator.isFalse((StringUtils.isEmpty(excelForm.getUpStreamAddr()) && StringUtils.isNotEmpty(excelForm.getBackStreamAddr())
|| (StringUtils.isNotEmpty(excelForm.getUpStreamAddr()) && StringUtils.isEmpty(excelForm.getBackStreamAddr()))), "上游地址和回流地址需同时填写或者同时为空");
excelForm.setActivity(finalActivity);
......@@ -169,7 +169,7 @@ public class TaskController {
// 查找当前补录范围所有的用户
List<User> userList = scope.getUserList();
TwinkleValidator.notLessThan(userList.size(), 1, "补录人员不存在,所选补录范围需要先绑定用户");
CommonValidator.notLessThan(userList.size(), 1, "补录人员不存在,所选补录范围需要先绑定用户");
userList.forEach(user -> {
// 创建了一些空白任务
......@@ -192,10 +192,10 @@ public class TaskController {
@PostMapping(value = "/start")
public ApiResponse startTask(long taskId) {
Activity activity = activityService.get(taskId);
TwinkleValidator.notNull(activity, "活动不存在");
CommonValidator.notNull(activity, "活动不存在");
// 根据活动查找需要填写的人 目前只支持一人
List<Template> templateList = activity.getExcelList();
TwinkleValidator.notLessThan(templateList.size(), 1, "补录模板不存在");
CommonValidator.notLessThan(templateList.size(), 1, "补录模板不存在");
// 部署补录流程
Deployment deploy = repositoryService
......
package com.keymobile.rest.controller;
import com.keymobile.rest.common.bean.ApiResponse;
import com.keymobile.rest.common.validator.TwinkleValidator;
import com.keymobile.rest.common.validator.CommonValidator;
import com.keymobile.rest.model.*;
import com.keymobile.rest.service.*;
import io.swagger.annotations.Api;
......@@ -73,10 +73,10 @@ public class UserController {
@PostMapping(value = "/scope/bindUser")
public ApiResponse bindUser(long scopeId, long userId) {
RecordScope scope = recordScopeService.findById(scopeId);
TwinkleValidator.notNull(scope, "所选范围不存在");
CommonValidator.notNull(scope, "所选范围不存在");
User user = userService.findById(userId);
TwinkleValidator.notNull(user, "所选用户不存在");
TwinkleValidator.isTrue(scope.getGroup().getId() == user.getGroup().getId(), "所选用户与所选范围不属于同一机构");
CommonValidator.notNull(user, "所选用户不存在");
CommonValidator.isTrue(scope.getGroup().getId() == user.getGroup().getId(), "所选用户与所选范围不属于同一机构");
List<User> userList = scope.getUserList();
if (!userList.contains(user)) {
userList.add(user);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment