后台搭建 统一消息返回
parent
0e8cf02581
commit
b6c920dc64
@ -0,0 +1,15 @@
|
||||
/weaver-hrm-organization.iml
|
||||
/out/
|
||||
/.idea/
|
||||
|
||||
HELP.md
|
||||
target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
|
||||
/src/test
|
||||
/src/META-INF
|
||||
|
||||
/log
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.api.organization.web;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
@Path("/bs/hrmorganization/demo")
|
||||
public class DemoController extends com.engine.organization.web.DemoController {
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.engine.organization.entity.po;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DemoUser {
|
||||
|
||||
private String username;
|
||||
|
||||
private Integer age;
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.engine.organization.exception;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
public class OrganizationRunTimeException extends RuntimeException{
|
||||
|
||||
public OrganizationRunTimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public OrganizationRunTimeException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package com.engine.organization.util;
|
||||
|
||||
import com.engine.organization.exception.OrganizationRunTimeException;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
public abstract class OrganizationAssert {
|
||||
/**
|
||||
* 判断入参不为null
|
||||
*
|
||||
* @param object 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void notNull(Object object, String message) {
|
||||
if (object == null) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断多个入参不为null
|
||||
*
|
||||
* @param message 检查失败返回的异常信息
|
||||
* @param objects 待检查参数
|
||||
*/
|
||||
public static void notNull(String message, Object... objects) {
|
||||
for (Object obj : objects) {
|
||||
if (obj == null) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断入参为null
|
||||
*
|
||||
* @param object 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void isNull(Object object, String message) {
|
||||
if (object != null) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断集合是否为空
|
||||
*
|
||||
* @param collection 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void isEmpty(Collection<?> collection, String message) {
|
||||
if (!CollectionUtils.isEmpty(collection)) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断集合不为空
|
||||
*
|
||||
* @param collection 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void notEmpty(Collection<?> collection, String message) {
|
||||
if (CollectionUtils.isEmpty(collection)) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数组是否为空
|
||||
*
|
||||
* @param arr 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void notEmpty(Object[] arr, String message) {
|
||||
if (ObjectUtils.isEmpty(arr)) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断map是否为空
|
||||
*
|
||||
* @param map 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void notEmpty(Map<?, ?> map, String message) {
|
||||
if (CollectionUtils.isEmpty(map)) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数组元素是否为空
|
||||
*
|
||||
* @param arr 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void notNullElement(Object[] arr, String message) {
|
||||
if (arr != null) {
|
||||
for (Object obj : arr) {
|
||||
if (obj == null) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断boolean
|
||||
*
|
||||
* @param expression 待检查参数
|
||||
* @param message 检查失败返回的异常信息
|
||||
*/
|
||||
public static void isTrue(boolean expression, String message) {
|
||||
if (!expression) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isFalse(boolean expression, String message) {
|
||||
if (expression) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isBlank(CharSequence cs, String message) {
|
||||
int strLen;
|
||||
if (cs != null && (strLen = cs.length()) != 0) {
|
||||
for (int i = 0; i < strLen; ++i) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void notBlank(CharSequence cs, String message) {
|
||||
int strLen;
|
||||
if (cs != null && (strLen = cs.length()) != 0) {
|
||||
for (int i = 0; i < strLen; ++i) {
|
||||
if (Character.isWhitespace(cs.charAt(i))) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cs == null || cs.length() == 0) {
|
||||
throw new OrganizationRunTimeException(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.engine.organization.util.response;
|
||||
|
||||
public enum ResultCode implements IErrorCode {
|
||||
SUCCESS(200,"操作成功"),
|
||||
FAILED(500,"操作失败"),
|
||||
VALIDATE_FAILED(404,"参数检验失败"),
|
||||
UNAUTHORIZED(401,"暂未登陆或相关token已经过期"),
|
||||
FORBIDDEN(403,"没有相关权限"),
|
||||
|
||||
|
||||
BODY_NOT_MATCH(400,"请求的数据格式不符!"),
|
||||
INTERNAL_SERVER_ERROR(500, "服务器内部错误!"),
|
||||
SERVER_BUSY(503,"服务器正忙,请稍后再试!");
|
||||
private long code;
|
||||
private String msg;
|
||||
|
||||
ResultCode(long code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
interface IErrorCode {
|
||||
long getCode();
|
||||
|
||||
String getMessage();
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.engine.organization.web;
|
||||
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.organization.util.response.ReturnResult;
|
||||
import com.engine.organization.wrapper.DemoWrapper;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
public class DemoController {
|
||||
|
||||
public DemoWrapper getDemoWrapper(User user){
|
||||
return ServiceUtil.getService(DemoWrapper.class,user);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/test")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult testDemo(@Context HttpServletRequest request, @Context HttpServletResponse response,
|
||||
@QueryParam("name") String name) {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return getDemoWrapper(user).testDemo(name);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.engine.organization.wrapper;
|
||||
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.po.DemoUser;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.response.ReturnResult;
|
||||
|
||||
/**
|
||||
* @Author weaver_cl
|
||||
* @Description: TODO
|
||||
* @Date 2022/4/26
|
||||
* @Version V1.0
|
||||
**/
|
||||
public class DemoWrapper extends Service {
|
||||
|
||||
|
||||
public ReturnResult testDemo(String name) {
|
||||
|
||||
OrganizationAssert.notNull(name,"参数不能为空");
|
||||
DemoUser demoUser = DemoUser.builder().username("张三").age(12).build();
|
||||
return ReturnResult.successed(demoUser);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue