mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-31 02:16:18 +08:00
xml config support & multi-step command matcher
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.enums.ResponseCode;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
|
||||
@@ -43,23 +42,23 @@ public class GetUser extends HttpServlet {
|
||||
String id = request.getParameter("id");
|
||||
String name = request.getParameter("name");
|
||||
if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
|
||||
out.println(gson.toJson(new Response(ResponseCode.PARAMETER_REQUIRED)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.PARAMETER_REQUIRED)));
|
||||
} else if (id != null) {
|
||||
try {
|
||||
User u = TableUser.getUserById(Integer.parseInt(id));
|
||||
if (u == null)
|
||||
out.println(gson.toJson(new Response(ResponseCode.USER_NOT_FOUND)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.USER_NOT_FOUND)));
|
||||
else
|
||||
out.println(gson.toJson(new Response(ResponseCode.OK, u)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.OK, u)));
|
||||
} catch (NumberFormatException e) {
|
||||
out.println(gson.toJson(new Response(ResponseCode.ILLEGAL_PARAMETER)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.ILLEGAL_PARAMETER)));
|
||||
}
|
||||
} else {
|
||||
User u = TableUser.getUserByName(name);
|
||||
if (u == null)
|
||||
out.println(gson.toJson(new Response(ResponseCode.USER_NOT_FOUND)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.USER_NOT_FOUND)));
|
||||
else
|
||||
out.println(gson.toJson(new Response(ResponseCode.OK, u)));
|
||||
out.println(gson.toJson(new Response(Response.ResponseCode.OK, u)));
|
||||
}
|
||||
out.close();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import love.sola.netsupport.enums.ResponseCode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
@@ -26,4 +28,42 @@ public class Response {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ResponseCode {
|
||||
|
||||
OK(0, "OK"),
|
||||
PARAMETER_REQUIRED(-1, "Parameter Required"),
|
||||
ILLEGAL_PARAMETER(-2, "Illegal parameter"),
|
||||
USER_NOT_FOUND(-11, "User not found"),
|
||||
;
|
||||
|
||||
private static final Map<Integer, ResponseCode> ID_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (ResponseCode type : values()) {
|
||||
if (type.id > 0) {
|
||||
ID_MAP.put(type.id, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final String info;
|
||||
public final int id;
|
||||
|
||||
ResponseCode(int id, String info) {
|
||||
this.info = info;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static ResponseCode fromId(int id) {
|
||||
return ID_MAP.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user