diff --git a/.gitignore b/.gitignore
index 0730807..67f58ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,12 @@
-/buildNumber.properties
-/docs
-.idea/
-out/
-/.metadata/
-/web/META-INF/context.xml
-*.iml
-~*
-.DS_Store
-.classpath
-/target
+/buildNumber.properties
+/docs
+.idea/
+out/
+/.metadata/
+/web/META-INF/context.xml
+*.iml
+~*
+.DS_Store
+.classpath
+/target
.project
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index b14ca0a..65c5ca8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,165 +1,165 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-
- This version of the GNU Lesser General Public License incorporates
-the terms and conditions of version 3 of the GNU General Public
-License, supplemented by the additional permissions listed below.
-
- 0. Additional Definitions.
-
- As used herein, "this License" refers to version 3 of the GNU Lesser
-General Public License, and the "GNU GPL" refers to version 3 of the GNU
-General Public License.
-
- "The Library" refers to a covered work governed by this License,
-other than an Application or a Combined Work as defined below.
-
- An "Application" is any work that makes use of an interface provided
-by the Library, but which is not otherwise based on the Library.
-Defining a subclass of a class defined by the Library is deemed a mode
-of using an interface provided by the Library.
-
- A "Combined Work" is a work produced by combining or linking an
-Application with the Library. The particular version of the Library
-with which the Combined Work was made is also called the "Linked
-Version".
-
- The "Minimal Corresponding Source" for a Combined Work means the
-Corresponding Source for the Combined Work, excluding any source code
-for portions of the Combined Work that, considered in isolation, are
-based on the Application, and not on the Linked Version.
-
- The "Corresponding Application Code" for a Combined Work means the
-object code and/or source code for the Application, including any data
-and utility programs needed for reproducing the Combined Work from the
-Application, but excluding the System Libraries of the Combined Work.
-
- 1. Exception to Section 3 of the GNU GPL.
-
- You may convey a covered work under sections 3 and 4 of this License
-without being bound by section 3 of the GNU GPL.
-
- 2. Conveying Modified Versions.
-
- If you modify a copy of the Library, and, in your modifications, a
-facility refers to a function or data to be supplied by an Application
-that uses the facility (other than as an argument passed when the
-facility is invoked), then you may convey a copy of the modified
-version:
-
- a) under this License, provided that you make a good faith effort to
- ensure that, in the event an Application does not supply the
- function or data, the facility still operates, and performs
- whatever part of its purpose remains meaningful, or
-
- b) under the GNU GPL, with none of the additional permissions of
- this License applicable to that copy.
-
- 3. Object Code Incorporating Material from Library Header Files.
-
- The object code form of an Application may incorporate material from
-a header file that is part of the Library. You may convey such object
-code under terms of your choice, provided that, if the incorporated
-material is not limited to numerical parameters, data structure
-layouts and accessors, or small macros, inline functions and templates
-(ten or fewer lines in length), you do both of the following:
-
- a) Give prominent notice with each copy of the object code that the
- Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the object code with a copy of the GNU GPL and this license
- document.
-
- 4. Combined Works.
-
- You may convey a Combined Work under terms of your choice that,
-taken together, effectively do not restrict modification of the
-portions of the Library contained in the Combined Work and reverse
-engineering for debugging such modifications, if you also do each of
-the following:
-
- a) Give prominent notice with each copy of the Combined Work that
- the Library is used in it and that the Library and its use are
- covered by this License.
-
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
- document.
-
- c) For a Combined Work that displays copyright notices during
- execution, include the copyright notice for the Library among
- these notices, as well as a reference directing the user to the
- copies of the GNU GPL and this license document.
-
- d) Do one of the following:
-
- 0) Convey the Minimal Corresponding Source under the terms of this
- License, and the Corresponding Application Code in a form
- suitable for, and under terms that permit, the user to
- recombine or relink the Application with a modified version of
- the Linked Version to produce a modified Combined Work, in the
- manner specified by section 6 of the GNU GPL for conveying
- Corresponding Source.
-
- 1) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (a) uses at run time
- a copy of the Library already present on the user's computer
- system, and (b) will operate properly with a modified version
- of the Library that is interface-compatible with the Linked
- Version.
-
- e) Provide Installation Information, but only if you would otherwise
- be required to provide such information under section 6 of the
- GNU GPL, and only to the extent that such information is
- necessary to install and execute a modified version of the
- Combined Work produced by recombining or relinking the
- Application with a modified version of the Linked Version. (If
- you use option 4d0, the Installation Information must accompany
- the Minimal Corresponding Source and Corresponding Application
- Code. If you use option 4d1, you must provide the Installation
- Information in the manner specified by section 6 of the GNU GPL
- for conveying Corresponding Source.)
-
- 5. Combined Libraries.
-
- You may place library facilities that are a work based on the
-Library side by side in a single library together with other library
-facilities that are not Applications and are not covered by this
-License, and convey such a combined library under terms of your
-choice, if you do both of the following:
-
- a) Accompany the combined library with a copy of the same work based
- on the Library, uncombined with any other library facilities,
- conveyed under the terms of this License.
-
- b) Give prominent notice with the combined library that part of it
- is a work based on the Library, and explaining where to find the
- accompanying uncombined form of the same work.
-
- 6. Revised Versions of the GNU Lesser General Public License.
-
- The Free Software Foundation may publish revised and/or new versions
-of the GNU Lesser General Public License from time to time. Such new
-versions will be similar in spirit to the present version, but may
-differ in detail to address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Library as you received it specifies that a certain numbered version
-of the GNU Lesser General Public License "or any later version"
-applies to it, you have the option of following the terms and
-conditions either of that published version or of any later version
-published by the Free Software Foundation. If the Library as you
-received it does not specify a version number of the GNU Lesser
-General Public License, you may choose any version of the GNU Lesser
-General Public License ever published by the Free Software Foundation.
-
- If the Library as you received it specifies that a proxy can decide
-whether future versions of the GNU Lesser General Public License shall
-apply, that proxy's public statement of acceptance of any version is
-permanent authorization for you to choose that version for the
-Library.
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/pom.xml b/pom.xml
index 25bea55..04c0a70 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,168 +1,162 @@
-
-
- 4.0.0
- WechatTicketSystem
- love.sola.netsupport
- WechatTicketSystem
- 2.1-SNAPSHOT
- war
-
-
- UTF-8
- 1.8
- 1.8
- 1.8
-
-
-
- scm:svn:http://127.0.0.1/dummy
- scm:svn:https://127.0.0.1/dummy
- HEAD
- http://127.0.0.1/dummy
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.3
-
- 1.8
- 1.8
-
-
-
- org.codehaus.mojo
- buildnumber-maven-plugin
- 1.4
-
- {0,number,0000}
-
- - buildNumber0
-
- false
- false
- unknown
-
-
-
- validate
-
- create
-
-
-
-
-
- ${project.artifactId}##${buildNumber}
-
-
-
-
- javax.servlet
- javax.servlet-api
- 3.1.0
- provided
-
-
- org.projectlombok
- lombok
- 1.16.6
- provided
-
-
- junit
- junit
- 4.12
- test
-
-
- org.slf4j
- slf4j-simple
- 1.7.12
-
-
- com.google.guava
- guava
- 19.0-rc2
-
-
- com.google.code.gson
- gson
- 2.4
-
-
- org.apache.commons
- commons-io
- 1.3.2
-
-
- org.apache.commons
- commons-lang3
- 3.4
-
-
- commons-net
- commons-net
- 3.3
-
-
- me.chanjar
- weixin-java-mp
- 1.3.3
-
-
- com.mchange
- c3p0
- 0.9.5.1
-
-
- mysql
- mysql-connector-java
- 5.1.37
-
-
- org.hibernate
- hibernate-core
- 5.0.3.Final
-
-
- org.hibernate
- hibernate-entitymanager
- 5.0.3.Final
-
-
- org.hibernate
- hibernate-c3p0
- 5.0.3.Final
-
-
- org.hibernate.javax.persistence
- hibernate-jpa-2.1-api
- 1.0.0.Final
-
-
- org.hibernate
- hibernate-envers
- 5.0.3.Final
-
-
- de.svenkubiak
- jBCrypt
- 0.4
-
-
- org.yaml
- snakeyaml
- 1.16
-
-
- org.reflections
- reflections
- 0.9.10
-
-
-
+
+
+ 4.0.0
+ WechatTicketSystem
+ love.sola.netsupport
+ WechatTicketSystem
+ 2.1-SNAPSHOT
+ war
+
+
+ UTF-8
+ 1.8
+ 1.8
+ 1.8
+
+
+
+ scm:svn:http://127.0.0.1/dummy
+ scm:svn:https://127.0.0.1/dummy
+ HEAD
+ http://127.0.0.1/dummy
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+ 1.8
+ 1.8
+
+
+
+ org.codehaus.mojo
+ buildnumber-maven-plugin
+ 1.4
+
+ {0,number,0000}
+
+ - buildNumber0
+
+ false
+ false
+ unknown
+
+
+
+ validate
+
+ create
+
+
+
+
+
+ ${project.artifactId}##${buildNumber}
+
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ provided
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ org.slf4j
+ slf4j-simple
+ 1.7.12
+
+
+ com.google.guava
+ guava
+ 19.0-rc2
+
+
+ com.google.code.gson
+ gson
+ 2.4
+
+
+ org.apache.commons
+ commons-io
+ 1.3.2
+
+
+ org.apache.commons
+ commons-lang3
+ 3.4
+
+
+ commons-net
+ commons-net
+ 3.3
+
+
+ me.chanjar
+ weixin-java-mp
+ 1.3.3
+
+
+ com.mchange
+ c3p0
+ 0.9.5.1
+
+
+ mysql
+ mysql-connector-java
+ 5.1.37
+
+
+ org.hibernate
+ hibernate-core
+ 5.0.3.Final
+
+
+ org.hibernate
+ hibernate-entitymanager
+ 5.0.3.Final
+
+
+ org.hibernate
+ hibernate-c3p0
+ 5.0.3.Final
+
+
+ org.hibernate.javax.persistence
+ hibernate-jpa-2.1-api
+ 1.0.0.Final
+
+
+ org.hibernate
+ hibernate-envers
+ 5.0.3.Final
+
+
+ de.svenkubiak
+ jBCrypt
+ 0.4
+
+
+ org.yaml
+ snakeyaml
+ 1.16
+
+
+ org.reflections
+ reflections
+ 0.9.10
+
+
+
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/Index.java b/src/main/java/love/sola/netsupport/Index.java
index 765d280..017f314 100644
--- a/src/main/java/love/sola/netsupport/Index.java
+++ b/src/main/java/love/sola/netsupport/Index.java
@@ -31,21 +31,21 @@ import java.io.PrintWriter;
@WebServlet(name = "Index", urlPatterns = "/index", loadOnStartup = 1)
public class Index extends HttpServlet {
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doGet(request, response);
- }
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doGet(request, response);
+ }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- request.setCharacterEncoding("utf-8");
- response.addHeader("Content-type", "text/plain;charset=utf-8");
- response.setCharacterEncoding("utf-8");
- PrintWriter out = response.getWriter();
- out.println("Wechat Ticket System (WTS) 0.1 Copyright 2015-2016 Sola & LiuYue all rights reserved. | Commercial license for ZSC Network Support Department (ZSCNSD).");
- out.println("For any problem, Please contact loli@sola.love.");
- if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
- out.println("\nError 404: Page not found.");
- }
- out.close();
- }
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ request.setCharacterEncoding("utf-8");
+ response.addHeader("Content-type", "text/plain;charset=utf-8");
+ response.setCharacterEncoding("utf-8");
+ PrintWriter out = response.getWriter();
+ out.println("Wechat Ticket System (WTS) 0.1 Copyright 2015-2016 Sola & LiuYue all rights reserved. | Commercial license for ZSC Network Support Department (ZSCNSD).");
+ out.println("For any problem, Please contact loli@sola.love.");
+ if (response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
+ out.println("\nError 404: Page not found.");
+ }
+ out.close();
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/API.java b/src/main/java/love/sola/netsupport/api/API.java
index 91acea3..8929c6c 100644
--- a/src/main/java/love/sola/netsupport/api/API.java
+++ b/src/main/java/love/sola/netsupport/api/API.java
@@ -31,35 +31,35 @@ import java.util.Date;
*/
public abstract class API {
- public String url = null; //url
- public int access = Access.GOD_MODE; //operator's permission
- public Command authorize = null; //session check
+ public String url = null; //url
+ public int access = Access.GOD_MODE; //operator's permission
+ public Command authorize = null; //session check
- protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
+ protected abstract Object process(HttpServletRequest req, WxSession session) throws Exception;
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- "url='" + url + '\'' +
- ", access=" + Access.inverseMap.get(access) +
- ", authorize=" + authorize +
- '}';
- }
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "{" +
+ "url='" + url + '\'' +
+ ", access=" + Access.inverseMap.get(access) +
+ ", authorize=" + authorize +
+ '}';
+ }
- public static String getParameterWithDefault(String obj, String def) {
- return obj == null ? def : obj;
- }
+ public static String getParameterWithDefault(String obj, String def) {
+ return obj == null ? def : obj;
+ }
- public static Date getParameterAsDate(String obj, Date def) {
- return obj == null ? def : new Date(Long.valueOf(obj));
- }
+ public static Date getParameterAsDate(String obj, Date def) {
+ return obj == null ? def : new Date(Long.valueOf(obj));
+ }
- public static Date getToday() {
- return DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
- }
+ public static Date getToday() {
+ return DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH);
+ }
- public static Date getDay(Date date) {
- return DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
- }
+ public static Date getDay(Date date) {
+ return DateUtils.truncate(date, Calendar.DAY_OF_MONTH);
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/APIRouter.java b/src/main/java/love/sola/netsupport/api/APIRouter.java
index cf1eee5..f23bed2 100644
--- a/src/main/java/love/sola/netsupport/api/APIRouter.java
+++ b/src/main/java/love/sola/netsupport/api/APIRouter.java
@@ -46,107 +46,107 @@ import java.util.Set;
@WebServlet(name = "APIRouter", urlPatterns = "/api/*", loadOnStartup = 11)
public class APIRouter extends HttpServlet {
- protected static Gson gson = SQLCore.gson;
- private Map nodes = new HashMap<>();
+ protected static Gson gson = SQLCore.gson;
+ private Map nodes = new HashMap<>();
- @Override
- public void init() throws ServletException {
- super.init();
- try {
- Reflections reflections = new Reflections(getClass().getPackage().getName());
- Set> set = reflections.getSubTypesOf(API.class);
- for (Class extends API> clz : set) {
- try {
- System.out.println("Loading API: " + clz.getName());
- API obj = clz.newInstance();
- System.out.println("Registered API: " + obj);
- nodes.put(obj.url, obj);
- } catch (InstantiationException | IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("Total " + nodes.size() + " API(s) loaded.");
- }
+ @Override
+ public void init() throws ServletException {
+ super.init();
+ try {
+ Reflections reflections = new Reflections(getClass().getPackage().getName());
+ Set> set = reflections.getSubTypesOf(API.class);
+ for (Class extends API> clz : set) {
+ try {
+ System.out.println("Loading API: " + clz.getName());
+ API obj = clz.newInstance();
+ System.out.println("Registered API: " + obj);
+ nodes.put(obj.url, obj);
+ } catch (InstantiationException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("Total " + nodes.size() + " API(s) loaded.");
+ }
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- req.setCharacterEncoding("utf-8");
- resp.setCharacterEncoding("utf-8");
- resp.addHeader("Content-type", "application/json;charset=utf-8");
- resp.addHeader("Access-Control-Allow-Origin", "*");
- Object obj = null;
- try {
- API api = nodes.get(req.getPathInfo());
- if (api == null) {
- resp.sendError(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
- WxSession session = getSession(req);
- if (session == null) {
- obj = Error.UNAUTHORIZED;
- return;
- }
- if (api.authorize != null) {
- if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
- obj = Error.UNAUTHORIZED;
- return;
- }
- if (api.access == Access.USER) {
- User u = session.getAttribute(Attribute.USER);
- if (u == null) {
- obj = Error.UNAUTHORIZED;
- return;
- }
- }
- if (api.access < Access.USER) {
- Operator op = session.getAttribute(Attribute.OPERATOR);
- if (op == null) {
- obj = Error.UNAUTHORIZED;
- return;
- }
- if (op.getAccess() > api.access) {
- obj = Error.PERMISSION_DENIED;
- return;
- }
- }
- }
- obj = api.process(req, session);
- } catch (ParseException | NumberFormatException e) {
- obj = Error.ILLEGAL_PARAMETER;
- } catch (HibernateException e) {
- e.printStackTrace();
- obj = Error.DATABASE_ERROR;
- } catch (Exception e) {
- e.printStackTrace();
- obj = Error.INTERNAL_ERROR;
- } finally {
- if (!resp.isCommitted()) {
- try (PrintWriter out = resp.getWriter()) {
- out.println(gson.toJson(obj));
- }
- }
- }
- }
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ req.setCharacterEncoding("utf-8");
+ resp.setCharacterEncoding("utf-8");
+ resp.addHeader("Content-type", "application/json;charset=utf-8");
+ resp.addHeader("Access-Control-Allow-Origin", "*");
+ Object obj = null;
+ try {
+ API api = nodes.get(req.getPathInfo());
+ if (api == null) {
+ resp.sendError(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+ WxSession session = getSession(req);
+ if (session == null) {
+ obj = Error.UNAUTHORIZED;
+ return;
+ }
+ if (api.authorize != null) {
+ if (session.getAttribute(Attribute.AUTHORIZED) != api.authorize) {
+ obj = Error.UNAUTHORIZED;
+ return;
+ }
+ if (api.access == Access.USER) {
+ User u = session.getAttribute(Attribute.USER);
+ if (u == null) {
+ obj = Error.UNAUTHORIZED;
+ return;
+ }
+ }
+ if (api.access < Access.USER) {
+ Operator op = session.getAttribute(Attribute.OPERATOR);
+ if (op == null) {
+ obj = Error.UNAUTHORIZED;
+ return;
+ }
+ if (op.getAccess() > api.access) {
+ obj = Error.PERMISSION_DENIED;
+ return;
+ }
+ }
+ }
+ obj = api.process(req, session);
+ } catch (ParseException | NumberFormatException e) {
+ obj = Error.ILLEGAL_PARAMETER;
+ } catch (HibernateException e) {
+ e.printStackTrace();
+ obj = Error.DATABASE_ERROR;
+ } catch (Exception e) {
+ e.printStackTrace();
+ obj = Error.INTERNAL_ERROR;
+ } finally {
+ if (!resp.isCommitted()) {
+ try (PrintWriter out = resp.getWriter()) {
+ out.println(gson.toJson(obj));
+ }
+ }
+ }
+ }
- @Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- doGet(req, resp);
- }
+ @Override
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ doGet(req, resp);
+ }
- @Override
- protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- resp.addHeader("Access-Control-Allow-Method", "POST, GET, OPTIONS");
- resp.addHeader("Access-Control-Allow-Origin", "*");
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- }
+ @Override
+ protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ resp.addHeader("Access-Control-Allow-Method", "POST, GET, OPTIONS");
+ resp.addHeader("Access-Control-Allow-Origin", "*");
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ }
- private static WxSession getSession(HttpServletRequest req) {
- String t = req.getParameter("token");
- if (t == null || t.isEmpty()) return null;
- return WechatSession.get(t);
- }
+ private static WxSession getSession(HttpServletRequest req) {
+ String t = req.getParameter("token");
+ if (t == null || t.isEmpty()) return null;
+ return WechatSession.get(t);
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/CheckSession.java b/src/main/java/love/sola/netsupport/api/CheckSession.java
index 36bf235..8dc6f23 100644
--- a/src/main/java/love/sola/netsupport/api/CheckSession.java
+++ b/src/main/java/love/sola/netsupport/api/CheckSession.java
@@ -30,26 +30,26 @@ import java.util.Map;
*/
public class CheckSession extends API {
- public CheckSession() {
- url = "/checksession";
- access = Access.GUEST;
- authorize = null;
- }
+ public CheckSession() {
+ url = "/checksession";
+ access = Access.GUEST;
+ authorize = null;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String more = req.getParameter("more");
- Map result = new HashMap<>();
- result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
- if (more != null) {
- switch (more) {
- case "1":
- result.put(Attribute.USER, session.getAttribute(Attribute.USER));
- result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
- break;
- }
- }
- return result;
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String more = req.getParameter("more");
+ Map result = new HashMap<>();
+ result.put(Attribute.AUTHORIZED, session.getAttribute(Attribute.AUTHORIZED));
+ if (more != null) {
+ switch (more) {
+ case "1":
+ result.put(Attribute.USER, session.getAttribute(Attribute.USER));
+ result.put(Attribute.OPERATOR, session.getAttribute(Attribute.OPERATOR));
+ break;
+ }
+ }
+ return result;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/Error.java b/src/main/java/love/sola/netsupport/api/Error.java
index d381481..2fbbfd1 100644
--- a/src/main/java/love/sola/netsupport/api/Error.java
+++ b/src/main/java/love/sola/netsupport/api/Error.java
@@ -24,36 +24,36 @@ import static love.sola.netsupport.config.Lang.lang;
*/
public class Error {
- public static final Error ALREADY_SUBMITTED = new Error(1);
- public static final Object OK = new Object();
- public static final Error PARAMETER_REQUIRED = new Error(-1);
- public static final Error ILLEGAL_PARAMETER = new Error(-2);
-// public static final Error REQUEST_FAILED = new Error(-3); REMOVED
- public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
- public static final Error INVALID_PARAMETER = new Error(-5);
- public static final Error USER_NOT_FOUND = new Error(-11);
- public static final Error TICKET_NOT_FOUND = new Error(-12);
- public static final Error OPERATOR_NOT_FOUND = new Error(-13);
- public static final Error UNAUTHORIZED = new Error(-20);
- public static final Error WRONG_PASSWORD = new Error(-22);
- public static final Error PERMISSION_DENIED = new Error(-24);
- public static final Error INTERNAL_ERROR = new Error(-90);
- public static final Error DATABASE_ERROR = new Error(-91);
+ public static final Error ALREADY_SUBMITTED = new Error(1);
+ public static final Object OK = new Object();
+ public static final Error PARAMETER_REQUIRED = new Error(-1);
+ public static final Error ILLEGAL_PARAMETER = new Error(-2);
+ // public static final Error REQUEST_FAILED = new Error(-3); REMOVED
+ public static final Error LENGTH_LIMIT_EXCEEDED = new Error(-4);
+ public static final Error INVALID_PARAMETER = new Error(-5);
+ public static final Error USER_NOT_FOUND = new Error(-11);
+ public static final Error TICKET_NOT_FOUND = new Error(-12);
+ public static final Error OPERATOR_NOT_FOUND = new Error(-13);
+ public static final Error UNAUTHORIZED = new Error(-20);
+ public static final Error WRONG_PASSWORD = new Error(-22);
+ public static final Error PERMISSION_DENIED = new Error(-24);
+ public static final Error INTERNAL_ERROR = new Error(-90);
+ public static final Error DATABASE_ERROR = new Error(-91);
- public int errCode;
- public String errMsg;
+ public int errCode;
+ public String errMsg;
- private Error(int code) {
- this(code, lang("ERR_" + code));
- }
+ private Error(int code) {
+ this(code, lang("ERR_" + code));
+ }
- public Error(int errCode, String errMsg) {
- this.errCode = errCode;
- this.errMsg = errMsg;
- }
+ public Error(int errCode, String errMsg) {
+ this.errCode = errCode;
+ this.errMsg = errMsg;
+ }
- public Error withMsg(String msg) {
- return new Error(errCode, msg);
- }
+ public Error withMsg(String msg) {
+ return new Error(errCode, msg);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/api/Login.java b/src/main/java/love/sola/netsupport/api/Login.java
index 1b1ca12..96afe93 100644
--- a/src/main/java/love/sola/netsupport/api/Login.java
+++ b/src/main/java/love/sola/netsupport/api/Login.java
@@ -46,59 +46,59 @@ import java.io.PrintWriter;
@WebServlet(name = "Login", urlPatterns = "/api/admin/login", loadOnStartup = 12)
public class Login extends HttpServlet {
- private Gson gson = SQLCore.gson;
+ private Gson gson = SQLCore.gson;
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doGet(request, response);
- }
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ doGet(request, response);
+ }
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- request.setCharacterEncoding("utf-8");
- response.setCharacterEncoding("utf-8");
- response.addHeader("Content-type", "application/json;charset=utf-8");
- response.addHeader("Access-Control-Allow-Origin", "*");
- PrintWriter out = response.getWriter();
- out.println(gson.toJson(login(request)));
- out.close();
- }
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ request.setCharacterEncoding("utf-8");
+ response.setCharacterEncoding("utf-8");
+ response.addHeader("Content-type", "application/json;charset=utf-8");
+ response.addHeader("Access-Control-Allow-Origin", "*");
+ PrintWriter out = response.getWriter();
+ out.println(gson.toJson(login(request)));
+ out.close();
+ }
- private Object login(HttpServletRequest request) {
- try {
- int oid = Integer.parseInt(request.getParameter("id"));
- String password = request.getParameter("pass");
- boolean bypass = request.getParameter("bypass") != null;
- Operator op = TableOperator.get(oid);
- if (op == null)
- return Error.OPERATOR_NOT_FOUND;
- else if (op.getAccess() >= Access.NO_LOGIN)
- return Error.PERMISSION_DENIED;
+ private Object login(HttpServletRequest request) {
+ try {
+ int oid = Integer.parseInt(request.getParameter("id"));
+ String password = request.getParameter("pass");
+ boolean bypass = request.getParameter("bypass") != null;
+ Operator op = TableOperator.get(oid);
+ if (op == null)
+ return Error.OPERATOR_NOT_FOUND;
+ else if (op.getAccess() >= Access.NO_LOGIN)
+ return Error.PERMISSION_DENIED;
- if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) {
- return Error.WRONG_PASSWORD;
- }
+ if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) {
+ return Error.WRONG_PASSWORD;
+ }
- WxSession session = WechatSession.create();
- if (bypass) {
- session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
- } else {
- session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
- }
+ WxSession session = WechatSession.create();
+ if (bypass) {
+ session.setAttribute(Attribute.AUTHORIZED, Command.fromId(Integer.parseInt(request.getParameter("bypass"))));
+ } else {
+ session.setAttribute(Attribute.AUTHORIZED, Command.LOGIN);
+ }
- session.setAttribute(Attribute.WECHAT, op.getWechat());
- session.setAttribute(Attribute.OPERATOR, op);
+ session.setAttribute(Attribute.WECHAT, op.getWechat());
+ session.setAttribute(Attribute.OPERATOR, op);
- if (request.getParameter("bypassuser") != null) {
- User u = TableUser.getById(Long.parseLong(request.getParameter("bypassuser")));
- session.setAttribute(Attribute.USER, u);
- session.setAttribute(Attribute.WECHAT, u.getWechatId());
- }
- if (request.getParameter("bypasswechat") != null) {
- session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
- }
- return session.getId();
- } catch (Exception e) {
- e.printStackTrace();
- return Error.INTERNAL_ERROR;
- }
- }
+ if (request.getParameter("bypassuser") != null) {
+ User u = TableUser.getById(Long.parseLong(request.getParameter("bypassuser")));
+ session.setAttribute(Attribute.USER, u);
+ session.setAttribute(Attribute.WECHAT, u.getWechatId());
+ }
+ if (request.getParameter("bypasswechat") != null) {
+ session.setAttribute(Attribute.WECHAT, request.getParameter("bypasswechat"));
+ }
+ return session.getId();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return Error.INTERNAL_ERROR;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/api/manager/GetUser.java b/src/main/java/love/sola/netsupport/api/manager/GetUser.java
index 983fc03..3a1b411 100644
--- a/src/main/java/love/sola/netsupport/api/manager/GetUser.java
+++ b/src/main/java/love/sola/netsupport/api/manager/GetUser.java
@@ -32,36 +32,36 @@ import javax.servlet.http.HttpServletRequest;
*/
public class GetUser extends API {
- public GetUser() {
- url = "/admin/getuser";
- access = Access.LEADER;
- authorize = Command.LOGIN;
- }
+ public GetUser() {
+ url = "/admin/getuser";
+ access = Access.LEADER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String id = req.getParameter("id");
- String name = req.getParameter("name");
- if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
- return Error.PARAMETER_REQUIRED;
- }
- if (id != null) {
- try {
- User u = TableUser.getById(Long.parseLong(id));
- if (u == null)
- return Error.USER_NOT_FOUND;
- else
- return u;
- } catch (NumberFormatException e) {
- return Error.ILLEGAL_PARAMETER;
- }
- } else {
- User u = TableUser.getByName(name);
- if (u == null)
- return Error.USER_NOT_FOUND;
- else
- return u;
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String id = req.getParameter("id");
+ String name = req.getParameter("name");
+ if ((id == null || id.isEmpty()) && (name == null || name.isEmpty())) {
+ return Error.PARAMETER_REQUIRED;
+ }
+ if (id != null) {
+ try {
+ User u = TableUser.getById(Long.parseLong(id));
+ if (u == null)
+ return Error.USER_NOT_FOUND;
+ else
+ return u;
+ } catch (NumberFormatException e) {
+ return Error.ILLEGAL_PARAMETER;
+ }
+ } else {
+ User u = TableUser.getByName(name);
+ if (u == null)
+ return Error.USER_NOT_FOUND;
+ else
+ return u;
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/manager/TicketPush.java b/src/main/java/love/sola/netsupport/api/manager/TicketPush.java
index f19f9f1..c55eb5c 100644
--- a/src/main/java/love/sola/netsupport/api/manager/TicketPush.java
+++ b/src/main/java/love/sola/netsupport/api/manager/TicketPush.java
@@ -39,34 +39,34 @@ import javax.servlet.http.HttpServletRequest;
*/
public class TicketPush extends API {
- public TicketPush() {
- url = "/admin/ticketpush";
- access = Access.LEADER;
- authorize = Command.LOGIN;
- }
+ public TicketPush() {
+ url = "/admin/ticketpush";
+ access = Access.LEADER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String uid = req.getParameter("uid");
- String desc = req.getParameter("desc");
- if (Checker.hasNull(uid, desc)) {
- return Error.PARAMETER_REQUIRED;
- }
- if (desc.length() > Settings.MAX_DESC_LENGTH) {
- return Error.LENGTH_LIMIT_EXCEEDED;
- }
- Operator op = session.getAttribute(Attribute.OPERATOR);
- try (Session s = SQLCore.sf.openSession()) {
- s.beginTransaction();
- User u = s.get(User.class, Long.parseLong(uid));
- if (u == null) {
- return Error.USER_NOT_FOUND;
- }
- Ticket t = new Ticket(null, u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
- s.save(t);
- s.getTransaction().commit();
- return t;
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String uid = req.getParameter("uid");
+ String desc = req.getParameter("desc");
+ if (Checker.hasNull(uid, desc)) {
+ return Error.PARAMETER_REQUIRED;
+ }
+ if (desc.length() > Settings.MAX_DESC_LENGTH) {
+ return Error.LENGTH_LIMIT_EXCEEDED;
+ }
+ Operator op = session.getAttribute(Attribute.OPERATOR);
+ try (Session s = SQLCore.sf.openSession()) {
+ s.beginTransaction();
+ User u = s.get(User.class, Long.parseLong(uid));
+ if (u == null) {
+ return Error.USER_NOT_FOUND;
+ }
+ Ticket t = new Ticket(u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
+ s.save(t);
+ s.getTransaction().commit();
+ return t;
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/root/DashBoard.java b/src/main/java/love/sola/netsupport/api/root/DashBoard.java
index b95a096..3f94db6 100644
--- a/src/main/java/love/sola/netsupport/api/root/DashBoard.java
+++ b/src/main/java/love/sola/netsupport/api/root/DashBoard.java
@@ -31,23 +31,23 @@ import java.util.Set;
*/
public class DashBoard extends API {
- public DashBoard() {
- url = "/root/dashboard";
- access = Access.ROOT;
- authorize = Command.LOGIN;
- }
+ public DashBoard() {
+ url = "/root/dashboard";
+ access = Access.ROOT;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- StringBuilder sb = new StringBuilder();
- for (love.sola.netsupport.session.WxSession ws : WechatSession.list()) {
- sb.append("=====").append(ws.getId()).append("=====\n");
- Set e = ws.getAttributeNames();
- for (String key : e) {
- sb.append(key).append(": ").append(ws.getAttribute(key).toString()).append("\n");
- }
- }
- return sb.toString();
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ StringBuilder sb = new StringBuilder();
+ for (love.sola.netsupport.session.WxSession ws : WechatSession.list()) {
+ sb.append("=====").append(ws.getId()).append("=====\n");
+ Set e = ws.getAttributeNames();
+ for (String key : e) {
+ sb.append(key).append(": ").append(ws.getAttribute(key).toString()).append("\n");
+ }
+ }
+ return sb.toString();
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/root/FlushCache.java b/src/main/java/love/sola/netsupport/api/root/FlushCache.java
index 2e03ffb..c83eb17 100644
--- a/src/main/java/love/sola/netsupport/api/root/FlushCache.java
+++ b/src/main/java/love/sola/netsupport/api/root/FlushCache.java
@@ -31,16 +31,16 @@ import javax.servlet.http.HttpServletRequest;
*/
public class FlushCache extends API {
- public FlushCache() {
- url = "/root/flushcache";
- access = Access.ROOT;
- authorize = Command.LOGIN;
- }
+ public FlushCache() {
+ url = "/root/flushcache";
+ access = Access.ROOT;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- TableUser.flushCache();
- return Error.OK;
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ TableUser.flushCache();
+ return Error.OK;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/root/SetPassword.java b/src/main/java/love/sola/netsupport/api/root/SetPassword.java
index 657cd64..5094fab 100644
--- a/src/main/java/love/sola/netsupport/api/root/SetPassword.java
+++ b/src/main/java/love/sola/netsupport/api/root/SetPassword.java
@@ -34,30 +34,30 @@ import javax.servlet.http.HttpServletRequest;
*/
public class SetPassword extends API {
- public SetPassword() {
- url = "/root/setpass";
- access = Access.ROOT;
- authorize = Command.LOGIN;
- }
+ public SetPassword() {
+ url = "/root/setpass";
+ access = Access.ROOT;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String id = req.getParameter("id");
- String pass = req.getParameter("pass");
- if (pass == null || pass.length() < 8) {
- return Error.INVALID_PARAMETER;
- }
- try (Session s = SQLCore.sf.openSession()) {
- s.beginTransaction();
- Operator op = s.get(Operator.class, Integer.parseInt(id));
- if (op == null) {
- return Error.OPERATOR_NOT_FOUND;
- }
- op.setPassword(Crypto.hash(pass));
- s.update(op);
- s.getTransaction().commit();
- return Error.OK;
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String id = req.getParameter("id");
+ String pass = req.getParameter("pass");
+ if (pass == null || pass.length() < 8) {
+ return Error.INVALID_PARAMETER;
+ }
+ try (Session s = SQLCore.sf.openSession()) {
+ s.beginTransaction();
+ Operator op = s.get(Operator.class, Integer.parseInt(id));
+ if (op == null) {
+ return Error.OPERATOR_NOT_FOUND;
+ }
+ op.setPassword(Crypto.hash(pass));
+ s.update(op);
+ s.getTransaction().commit();
+ return Error.OK;
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/stuff/TicketLog.java b/src/main/java/love/sola/netsupport/api/stuff/TicketLog.java
index fe8b3db..21361a9 100644
--- a/src/main/java/love/sola/netsupport/api/stuff/TicketLog.java
+++ b/src/main/java/love/sola/netsupport/api/stuff/TicketLog.java
@@ -38,35 +38,35 @@ import java.util.Date;
*/
public class TicketLog extends API {
- public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
+ public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
- public TicketLog() {
- url = "/admin/ticketlog";
- access = Access.MEMBER;
- authorize = Command.LOGIN;
- }
+ public TicketLog() {
+ url = "/admin/ticketlog";
+ access = Access.MEMBER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- int first;
- int limit;
- Date start;
- Date end;
- first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
- limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
- start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
- end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
- end = DateUtils.addDays(end, 1);
- try (Session s = SQLCore.sf.openSession()) {
- AuditReader reader = TableTicket.getAuditReader(s);
- return reader.createQuery()
- .forRevisionsOfEntity(Ticket.class, false, true)
- .addOrder(AuditEntity.revisionNumber().desc())
- .add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
- .setFirstResult(first)
- .setMaxResults(limit)
- .getResultList();
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ int first;
+ int limit;
+ Date start;
+ Date end;
+ first = req.getParameter("first") == null ? 0 : Integer.parseInt(req.getParameter("first"));
+ limit = req.getParameter("limit") == null ? 20 : Integer.parseInt(req.getParameter("limit"));
+ start = req.getParameter("start") == null ? getToday() : dateFormat.parse(req.getParameter("start"));
+ end = req.getParameter("end") == null ? getToday() : dateFormat.parse(req.getParameter("end"));
+ end = DateUtils.addDays(end, 1);
+ try (Session s = SQLCore.sf.openSession()) {
+ AuditReader reader = TableTicket.getAuditReader(s);
+ return reader.createQuery()
+ .forRevisionsOfEntity(Ticket.class, false, true)
+ .addOrder(AuditEntity.revisionNumber().desc())
+ .add(AuditEntity.revisionProperty("timestamp").between(start.getTime(), end.getTime()))
+ .setFirstResult(first)
+ .setMaxResults(limit)
+ .getResultList();
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/stuff/TicketLookup.java b/src/main/java/love/sola/netsupport/api/stuff/TicketLookup.java
index a0984ad..07a764c 100644
--- a/src/main/java/love/sola/netsupport/api/stuff/TicketLookup.java
+++ b/src/main/java/love/sola/netsupport/api/stuff/TicketLookup.java
@@ -32,22 +32,22 @@ import javax.servlet.http.HttpServletRequest;
*/
public class TicketLookup extends API {
- public TicketLookup() {
- url = "/admin/ticketlookup";
- access = Access.MEMBER;
- authorize = Command.LOGIN;
- }
+ public TicketLookup() {
+ url = "/admin/ticketlookup";
+ access = Access.MEMBER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- Operator op = session.getAttribute(Attribute.OPERATOR);
- int block;
- if (req.getParameter("block") != null) {
- block = Integer.parseInt(req.getParameter("block"));
- } else {
- block = op.getBlock();
- }
- return TableTicket.unsolvedByBlock(block);
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ Operator op = session.getAttribute(Attribute.OPERATOR);
+ int block;
+ if (req.getParameter("block") != null) {
+ block = Integer.parseInt(req.getParameter("block"));
+ } else {
+ block = op.getBlock();
+ }
+ return TableTicket.unsolvedByBlock(block);
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/stuff/TicketTrack.java b/src/main/java/love/sola/netsupport/api/stuff/TicketTrack.java
index c763f5c..d086b48 100644
--- a/src/main/java/love/sola/netsupport/api/stuff/TicketTrack.java
+++ b/src/main/java/love/sola/netsupport/api/stuff/TicketTrack.java
@@ -31,19 +31,19 @@ import javax.servlet.http.HttpServletRequest;
*/
public class TicketTrack extends API {
- public TicketTrack() {
- url = "/admin/tickettrack";
- access = Access.MEMBER;
- authorize = Command.LOGIN;
- }
+ public TicketTrack() {
+ url = "/admin/tickettrack";
+ access = Access.MEMBER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String tid = req.getParameter("id");
- if (tid == null) {
- return Error.PARAMETER_REQUIRED;
- }
- return TableTicket.track(Integer.parseInt(tid));
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String tid = req.getParameter("id");
+ if (tid == null) {
+ return Error.PARAMETER_REQUIRED;
+ }
+ return TableTicket.track(Integer.parseInt(tid));
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/stuff/TicketUpdate.java b/src/main/java/love/sola/netsupport/api/stuff/TicketUpdate.java
index b005fa9..00be7b9 100644
--- a/src/main/java/love/sola/netsupport/api/stuff/TicketUpdate.java
+++ b/src/main/java/love/sola/netsupport/api/stuff/TicketUpdate.java
@@ -37,32 +37,32 @@ import java.util.Date;
*/
public class TicketUpdate extends API {
- public TicketUpdate() {
- url = "/admin/ticketupdate";
- access = Access.MEMBER;
- authorize = Command.LOGIN;
- }
+ public TicketUpdate() {
+ url = "/admin/ticketupdate";
+ access = Access.MEMBER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String ticket = req.getParameter("ticket");
- String remark = req.getParameter("remark");
- String status = req.getParameter("status");
- if (Checker.hasNull(ticket, remark, status)) return Error.PARAMETER_REQUIRED;
- try (Session s = SQLCore.sf.openSession()) {
- Operator op = session.getAttribute(Attribute.OPERATOR);
- Ticket t = s.get(Ticket.class, Integer.parseInt(ticket));
- if (t == null) {
- return Error.TICKET_NOT_FOUND;
- }
- t.setOperator(op);
- t.setRemark(remark);
- t.setStatus(Integer.parseInt(status));
- t.setUpdateTime(new Date());
- s.beginTransaction();
- s.update(t);
- s.getTransaction().commit();
- return t;
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String ticket = req.getParameter("ticket");
+ String remark = req.getParameter("remark");
+ String status = req.getParameter("status");
+ if (Checker.hasNull(ticket, remark, status)) return Error.PARAMETER_REQUIRED;
+ try (Session s = SQLCore.sf.openSession()) {
+ Operator op = session.getAttribute(Attribute.OPERATOR);
+ Ticket t = s.get(Ticket.class, Integer.parseInt(ticket));
+ if (t == null) {
+ return Error.TICKET_NOT_FOUND;
+ }
+ t.setOperator(op);
+ t.setRemark(remark);
+ t.setStatus(Integer.parseInt(status));
+ t.setUpdateTime(new Date());
+ s.beginTransaction();
+ s.update(t);
+ s.getTransaction().commit();
+ return t;
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java b/src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java
index b51513b..64dfd91 100644
--- a/src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java
+++ b/src/main/java/love/sola/netsupport/api/stuff/ToolsCheck.java
@@ -41,64 +41,62 @@ import java.util.Date;
*/
public class ToolsCheck extends API {
- public ToolsCheck() {
- url = "/admin/toolscheck";
- access = Access.MEMBER;
- authorize = Command.LOGIN;
- }
+ public ToolsCheck() {
+ url = "/admin/toolscheck";
+ access = Access.MEMBER;
+ authorize = Command.LOGIN;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- if (req.getMethod().equals("GET")) {
- return query(req, session);
- } else if (req.getMethod().equals("POST")) {
- return submit(req, session);
- }
- return null;
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ if (req.getMethod().equals("GET")) {
+ return query(req, session);
+ } else if (req.getMethod().equals("POST")) {
+ return submit(req, session);
+ }
+ return null;
+ }
- private Object submit(HttpServletRequest req, WxSession session) {
- Operator op = session.getAttribute(Attribute.OPERATOR);
- int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
- String remark = req.getParameter("remark");
- if (status != 0 && StringUtils.isBlank(remark)) {
- return Error.PARAMETER_REQUIRED;
- }
- try (Session s = SQLCore.sf.openSession()) {
- s.beginTransaction();
- s.save(new love.sola.netsupport.pojo.ToolsCheck(
- null,
- op,
- op.getBlock(),
- new Date(),
- status,
- remark
- )
- );
- s.getTransaction().commit();
- return Error.OK;
- }
- }
+ private Object submit(HttpServletRequest req, WxSession session) {
+ Operator op = session.getAttribute(Attribute.OPERATOR);
+ int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
+ String remark = req.getParameter("remark");
+ if (status != 0 && StringUtils.isBlank(remark)) {
+ return Error.PARAMETER_REQUIRED;
+ }
+ try (Session s = SQLCore.sf.openSession()) {
+ s.beginTransaction();
+ s.save(new love.sola.netsupport.pojo.ToolsCheck(
+ op,
+ op.getBlock(),
+ new Date(),
+ status,
+ remark
+ ));
+ s.getTransaction().commit();
+ return Error.OK;
+ }
+ }
- private Object query(HttpServletRequest req, WxSession session) {
- int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
- Date after = getDay(getParameterAsDate(req.getParameter("after"), getToday()));
- Date before = getDay(getParameterAsDate(req.getParameter("before"), getToday()));
- before = DateUtils.addDays(before, 1);
- int block = Integer.valueOf(getParameterWithDefault(req.getParameter("block"), "0"));
- try (Session s = SQLCore.sf.openSession()) {
- Criteria query = s.createCriteria(love.sola.netsupport.pojo.ToolsCheck.class);
- query.add(
- Restrictions.sqlRestriction(
- "{alias}.status & ? = ?",
- new Object[]{status, status},
- new Type[]{IntegerType.INSTANCE, IntegerType.INSTANCE}
- )
- );
- query.add(Restrictions.between("checkTime", after, before));
- if (block != 0) query.add(Restrictions.eq("block", block));
- return query.list();
- }
- }
+ private Object query(HttpServletRequest req, WxSession session) {
+ int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
+ Date after = getDay(getParameterAsDate(req.getParameter("after"), getToday()));
+ Date before = getDay(getParameterAsDate(req.getParameter("before"), getToday()));
+ before = DateUtils.addDays(before, 1);
+ int block = Integer.valueOf(getParameterWithDefault(req.getParameter("block"), "0"));
+ try (Session s = SQLCore.sf.openSession()) {
+ Criteria query = s.createCriteria(love.sola.netsupport.pojo.ToolsCheck.class);
+ query.add(
+ Restrictions.sqlRestriction(
+ "{alias}.status & ? = ?",
+ new Object[]{status, status},
+ new Type[]{IntegerType.INSTANCE, IntegerType.INSTANCE}
+ )
+ );
+ query.add(Restrictions.between("checkTime", after, before));
+ if (block != 0) query.add(Restrictions.eq("block", block));
+ return query.list();
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/user/ProfileModify.java b/src/main/java/love/sola/netsupport/api/user/ProfileModify.java
index 07e339c..14963a5 100644
--- a/src/main/java/love/sola/netsupport/api/user/ProfileModify.java
+++ b/src/main/java/love/sola/netsupport/api/user/ProfileModify.java
@@ -37,39 +37,39 @@ import static love.sola.netsupport.util.Checker.*;
*/
public class ProfileModify extends API {
- public ProfileModify() {
- url = "/profilemodify";
- access = Access.USER;
- authorize = Command.PROFILE;
- }
+ public ProfileModify() {
+ url = "/profilemodify";
+ access = Access.USER;
+ authorize = Command.PROFILE;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- User u = session.getAttribute(Attribute.USER);
- ISP isp = checkISP(req.getParameter("isp"));
- String netAccount = checkNetAccount(req.getParameter("username"), isp);
- int block = checkBlock(req.getParameter("block"));
- int room = checkRoom(req.getParameter("room"), block);
- long phone = checkPhoneNumber(req.getParameter("phone"));
- if (room == -1)
- return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
- if (phone == -1)
- return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
- if (netAccount == null)
- return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ User u = session.getAttribute(Attribute.USER);
+ ISP isp = checkISP(req.getParameter("isp"));
+ String netAccount = checkNetAccount(req.getParameter("username"), isp);
+ int block = checkBlock(req.getParameter("block"));
+ int room = checkRoom(req.getParameter("room"), block);
+ long phone = checkPhoneNumber(req.getParameter("phone"));
+ if (room == -1)
+ return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
+ if (phone == -1)
+ return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
+ if (netAccount == null)
+ return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
- u.setIsp(isp);
- u.setNetAccount(netAccount);
- u.setBlock(block);
- u.setRoom(room);
- u.setPhone(phone);
- try {
- TableUser.update(u);
- } catch (ConstraintViolationException e) {
- String dupKey = e.getConstraintName();
- return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase());
- }
- session.invalidate();
- return Error.OK;
- }
+ u.setIsp(isp);
+ u.setNetAccount(netAccount);
+ u.setBlock(block);
+ u.setRoom(room);
+ u.setPhone(phone);
+ try {
+ TableUser.update(u);
+ } catch (ConstraintViolationException e) {
+ String dupKey = e.getConstraintName();
+ return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase());
+ }
+ session.invalidate();
+ return Error.OK;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/user/Register.java b/src/main/java/love/sola/netsupport/api/user/Register.java
index b78db3c..f2d6450 100644
--- a/src/main/java/love/sola/netsupport/api/user/Register.java
+++ b/src/main/java/love/sola/netsupport/api/user/Register.java
@@ -37,56 +37,56 @@ import static love.sola.netsupport.util.Checker.*;
*/
public class Register extends API {
- public Register() {
- url = "/register";
- access = Access.GUEST;
- authorize = Command.REGISTER;
- }
+ public Register() {
+ url = "/register";
+ access = Access.GUEST;
+ authorize = Command.REGISTER;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String wechat = session.getAttribute(Attribute.WECHAT);
- if (wechat == null) {
- return Error.UNAUTHORIZED;
- }
- ISP isp = checkISP(req.getParameter("isp"));
- int block = checkBlock(req.getParameter("block"));
- return register(
- checkStudentId(req.getParameter("sid")),
- req.getParameter("name"),
- isp,
- checkNetAccount(req.getParameter("username"), isp),
- block,
- checkRoom(req.getParameter("room"), block),
- checkPhoneNumber(req.getParameter("phone")),
- wechat);
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String wechat = session.getAttribute(Attribute.WECHAT);
+ if (wechat == null) {
+ return Error.UNAUTHORIZED;
+ }
+ ISP isp = checkISP(req.getParameter("isp"));
+ int block = checkBlock(req.getParameter("block"));
+ return register(
+ checkStudentId(req.getParameter("sid")),
+ req.getParameter("name"),
+ isp,
+ checkNetAccount(req.getParameter("username"), isp),
+ block,
+ checkRoom(req.getParameter("room"), block),
+ checkPhoneNumber(req.getParameter("phone")),
+ wechat);
+ }
- private Object register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
- if (sid == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
- if (name == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
- if (isp == null) return Error.INVALID_PARAMETER.withMsg("Invalid_ISP");
- if (netAccount == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
- if (block == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Block");
- if (room == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
- if (phone == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
- User user = TableUser.getById(sid);
- if (user == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
- if (!user.getName().equals(name)) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
- if (user.getWechatId() != null) return Error.INVALID_PARAMETER.withMsg("User_Already_Registered");
- user.setIsp(isp);
- user.setNetAccount(netAccount);
- user.setBlock(block);
- user.setRoom(room);
- user.setPhone(phone);
- user.setWechatId(wechat);
- try {
- TableUser.update(user);
- } catch (ConstraintViolationException e) {
- String dupKey = e.getConstraintName();
- return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase()); // PHONE ACCOUNT WECHAT
- }
- return Error.OK;
- }
+ private Object register(long sid, String name, ISP isp, String netAccount, int block, int room, long phone, String wechat) {
+ if (sid == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
+ if (name == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
+ if (isp == null) return Error.INVALID_PARAMETER.withMsg("Invalid_ISP");
+ if (netAccount == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Account");
+ if (block == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Block");
+ if (room == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Room");
+ if (phone == -1) return Error.INVALID_PARAMETER.withMsg("Invalid_Phone_Number");
+ User user = TableUser.getById(sid);
+ if (user == null) return Error.INVALID_PARAMETER.withMsg("Invalid_Student_Id");
+ if (!user.getName().equals(name)) return Error.INVALID_PARAMETER.withMsg("Invalid_Name");
+ if (user.getWechatId() != null) return Error.INVALID_PARAMETER.withMsg("User_Already_Registered");
+ user.setIsp(isp);
+ user.setNetAccount(netAccount);
+ user.setBlock(block);
+ user.setRoom(room);
+ user.setPhone(phone);
+ user.setWechatId(wechat);
+ try {
+ TableUser.update(user);
+ } catch (ConstraintViolationException e) {
+ String dupKey = e.getConstraintName();
+ return Error.INVALID_PARAMETER.withMsg("Duplicated_" + dupKey.toUpperCase()); // PHONE ACCOUNT WECHAT
+ }
+ return Error.OK;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/user/TicketQuery.java b/src/main/java/love/sola/netsupport/api/user/TicketQuery.java
index b536d90..249ddb2 100644
--- a/src/main/java/love/sola/netsupport/api/user/TicketQuery.java
+++ b/src/main/java/love/sola/netsupport/api/user/TicketQuery.java
@@ -37,33 +37,33 @@ import javax.servlet.http.HttpServletRequest;
*/
public class TicketQuery extends API {
- public TicketQuery() {
- url = "/ticketquery";
- access = Access.USER;
- authorize = Command.QUERY;
- }
+ public TicketQuery() {
+ url = "/ticketquery";
+ access = Access.USER;
+ authorize = Command.QUERY;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- try (Session s = SQLCore.sf.openSession()) {
- User u = session.getAttribute(Attribute.USER);
- Criteria c = s.createCriteria(Ticket.class);
- int first = req.getParameter("offset") == null ? 0 : Integer.parseInt(req.getParameter("offset"));
- int limit = req.getParameter("limit") == null ? 5 : Integer.parseInt(req.getParameter("limit"));
- c.setFirstResult(first);
- c.setMaxResults(limit);
- c.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME));
- c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
- if (req.getParameter("status") != null) {
- c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(req.getParameter("status"))));
- } else if (req.getParameter("statusl") != null && req.getParameter("statush") != null) {
- c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
- Integer.parseInt(req.getParameter("statusl")),
- Integer.parseInt(req.getParameter("statush"))
- ));
- }
- return c.list();
- }
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ try (Session s = SQLCore.sf.openSession()) {
+ User u = session.getAttribute(Attribute.USER);
+ Criteria c = s.createCriteria(Ticket.class);
+ int first = req.getParameter("offset") == null ? 0 : Integer.parseInt(req.getParameter("offset"));
+ int limit = req.getParameter("limit") == null ? 5 : Integer.parseInt(req.getParameter("limit"));
+ c.setFirstResult(first);
+ c.setMaxResults(limit);
+ c.addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME));
+ c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
+ if (req.getParameter("status") != null) {
+ c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(req.getParameter("status"))));
+ } else if (req.getParameter("statusl") != null && req.getParameter("statush") != null) {
+ c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
+ Integer.parseInt(req.getParameter("statusl")),
+ Integer.parseInt(req.getParameter("statush"))
+ ));
+ }
+ return c.list();
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/api/user/TicketSubmit.java b/src/main/java/love/sola/netsupport/api/user/TicketSubmit.java
index a3608d0..75b73ba 100644
--- a/src/main/java/love/sola/netsupport/api/user/TicketSubmit.java
+++ b/src/main/java/love/sola/netsupport/api/user/TicketSubmit.java
@@ -37,37 +37,37 @@ import javax.servlet.http.HttpServletRequest;
*/
public class TicketSubmit extends API {
- public TicketSubmit() {
- url = "/ticketsubmit";
- access = Access.USER;
- authorize = Command.SUBMIT;
- }
+ public TicketSubmit() {
+ url = "/ticketsubmit";
+ access = Access.USER;
+ authorize = Command.SUBMIT;
+ }
- @Override
- protected Object process(HttpServletRequest req, WxSession session) throws Exception {
- String desc = req.getParameter("desc");
- if (desc == null || desc.isEmpty()) {
- return Error.PARAMETER_REQUIRED;
- }
- if (desc.length() > Settings.MAX_DESC_LENGTH) {
- return Error.LENGTH_LIMIT_EXCEEDED;
- }
+ @Override
+ protected Object process(HttpServletRequest req, WxSession session) throws Exception {
+ String desc = req.getParameter("desc");
+ if (desc == null || desc.isEmpty()) {
+ return Error.PARAMETER_REQUIRED;
+ }
+ if (desc.length() > Settings.MAX_DESC_LENGTH) {
+ return Error.LENGTH_LIMIT_EXCEEDED;
+ }
- try (Session s = SQLCore.sf.openSession()) {
- User u = session.getAttribute(Attribute.USER);
- if (TableTicket.hasOpen(u)) {
- session.invalidate();
- return Error.ALREADY_SUBMITTED;
- }
- Ticket t = new Ticket();
- t.setUser(u);
- t.setDescription(desc);
- t.setStatus(0);
- s.beginTransaction();
- s.save(t);
- s.getTransaction().commit();
- session.invalidate();
- return Error.OK;
- }
- }
+ try (Session s = SQLCore.sf.openSession()) {
+ User u = session.getAttribute(Attribute.USER);
+ if (TableTicket.hasOpen(u)) {
+ session.invalidate();
+ return Error.ALREADY_SUBMITTED;
+ }
+ Ticket t = new Ticket();
+ t.setUser(u);
+ t.setDescription(desc);
+ t.setStatus(0);
+ s.beginTransaction();
+ s.save(t);
+ s.getTransaction().commit();
+ session.invalidate();
+ return Error.OK;
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/auth/OAuth2.java b/src/main/java/love/sola/netsupport/auth/OAuth2.java
index 44fee9c..ea3f3bd 100644
--- a/src/main/java/love/sola/netsupport/auth/OAuth2.java
+++ b/src/main/java/love/sola/netsupport/auth/OAuth2.java
@@ -40,45 +40,45 @@ import java.util.Map;
@WebServlet(name = "OAuth2", urlPatterns = "/oauth2/callback", loadOnStartup = 21, asyncSupported = true)
public class OAuth2 extends HttpServlet {
- private static Map oAuth2HandlerMap = new HashMap<>();
+ private static Map oAuth2HandlerMap = new HashMap<>();
- /**
- * for {@link love.sola.netsupport.wechat.WxMpServlet#registerCommands}
- *
- * @param state the state key from open platform callback.
- * @param handler handler
- */
- public static void registerOAuth2Handler(String state, OAuth2Handler handler) {
- oAuth2HandlerMap.put(state, handler);
- }
+ /**
+ * for {@link love.sola.netsupport.wechat.WxMpServlet#registerCommands}
+ *
+ * @param state the state key from open platform callback.
+ * @param handler handler
+ */
+ public static void registerOAuth2Handler(String state, OAuth2Handler handler) {
+ oAuth2HandlerMap.put(state, handler);
+ }
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
- AsyncContext actx = req.startAsync();
- String code = req.getParameter("code");
- String state = req.getParameter("state");
- if (Checker.hasNull(code, state)) {
- resp.sendError(HttpServletResponse.SC_FORBIDDEN);
- return;
- }
- OAuth2Handler handler = oAuth2HandlerMap.get(state);
- if (handler == null) {
- resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
- return;
- }
- actx.start(() -> {
- try {
- WxMpService wxMpService = WxMpServlet.instance.wxMpService;
- WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
- String wechat = token.getOpenId();
- WxSession session = WechatSession.create();
- handler.onOAuth2(actx, (HttpServletResponse) actx.getResponse(), wechat, session);
- actx.complete();
- } catch (Exception e) {
- e.printStackTrace();
- }
- });
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ AsyncContext actx = req.startAsync();
+ String code = req.getParameter("code");
+ String state = req.getParameter("state");
+ if (Checker.hasNull(code, state)) {
+ resp.sendError(HttpServletResponse.SC_FORBIDDEN);
+ return;
+ }
+ OAuth2Handler handler = oAuth2HandlerMap.get(state);
+ if (handler == null) {
+ resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
+ return;
+ }
+ actx.start(() -> {
+ try {
+ WxMpService wxMpService = WxMpServlet.instance.wxMpService;
+ WxMpOAuth2AccessToken token = wxMpService.oauth2getAccessToken(code);
+ String wechat = token.getOpenId();
+ WxSession session = WechatSession.create();
+ handler.onOAuth2(actx, (HttpServletResponse) actx.getResponse(), wechat, session);
+ actx.complete();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
- }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/auth/OAuth2Handler.java b/src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
index 1dce3c0..21d3752 100644
--- a/src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
+++ b/src/main/java/love/sola/netsupport/auth/OAuth2Handler.java
@@ -27,6 +27,6 @@ import javax.servlet.http.HttpServletResponse;
*/
public interface OAuth2Handler {
- void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session);
+ void onOAuth2(AsyncContext actx, HttpServletResponse resp, String user, WxSession session);
}
diff --git a/src/main/java/love/sola/netsupport/config/Cortana.java b/src/main/java/love/sola/netsupport/config/Cortana.java
index 4e3c4d8..2277a38 100644
--- a/src/main/java/love/sola/netsupport/config/Cortana.java
+++ b/src/main/java/love/sola/netsupport/config/Cortana.java
@@ -17,7 +17,6 @@
package love.sola.netsupport.config;
-import lombok.Data;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
@@ -30,27 +29,31 @@ import java.util.regex.Pattern;
*/
public class Cortana {
- public static List entries;
+ public static List entries;
- public static void load() {
- InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml");
- RawConfig root = new Yaml().loadAs(in, RawConfig.class);
- }
+ public static void load() {
+ InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml");
+ RawConfig root = new Yaml().loadAs(in, RawConfig.class);
+ }
- static class Compiled {
- Pattern[] patterns;
- String[] replies;
- }
+ static class Compiled {
+ Pattern[] patterns;
+ String[] replies;
+ }
- @Data
- public static class Rule {
- String[] regexp;
- String[] replies;
- }
+ public static class Rule {
+ String[] regexp;
+ String[] replies;
- @Data
- public static class RawConfig {
- Map rules;
- }
+ public Rule() {
+ }
+ }
+
+ public static class RawConfig {
+ Map rules;
+
+ public RawConfig() {
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/config/Lang.java b/src/main/java/love/sola/netsupport/config/Lang.java
index 09c9a07..878d44b 100644
--- a/src/main/java/love/sola/netsupport/config/Lang.java
+++ b/src/main/java/love/sola/netsupport/config/Lang.java
@@ -29,29 +29,29 @@ import java.util.Map;
*/
public class Lang {
- public static Map messages;
- public static Map format_cache = new HashMap<>(32);
+ public static Map messages;
+ public static Map format_cache = new HashMap<>(32);
- static {
- InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
- //noinspection unchecked
- messages = new Yaml().loadAs(in, Map.class);
- }
+ static {
+ InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
+ //noinspection unchecked
+ messages = new Yaml().loadAs(in, Map.class);
+ }
- public static String lang(String key) {
- String value = messages.get(key);
- return value == null ? "!!" + key + "!!" : value;
- }
+ public static String lang(String key) {
+ String value = messages.get(key);
+ return value == null ? "!!" + key + "!!" : value;
+ }
- public static String format(String key, Object... args) {
- MessageFormat cache = format_cache.get(key);
- if (cache != null) {
- return cache.format(args);
- } else {
- cache = new MessageFormat(lang(key));
- format_cache.put(key, cache);
- return cache.format(args);
- }
- }
+ public static String format(String key, Object... args) {
+ MessageFormat cache = format_cache.get(key);
+ if (cache != null) {
+ return cache.format(args);
+ } else {
+ cache = new MessageFormat(lang(key));
+ format_cache.put(key, cache);
+ return cache.format(args);
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/config/Settings.java b/src/main/java/love/sola/netsupport/config/Settings.java
index 21bd9d0..256c034 100644
--- a/src/main/java/love/sola/netsupport/config/Settings.java
+++ b/src/main/java/love/sola/netsupport/config/Settings.java
@@ -17,40 +17,48 @@
package love.sola.netsupport.config;
-import lombok.ToString;
import love.sola.netsupport.sql.TableConfig;
/**
* @author Sola {@literal }
*/
-@ToString
public class Settings {
- public static final int MAX_DESC_LENGTH = 255;
+ public static final int MAX_DESC_LENGTH = 255;
- public static Settings I;
+ public static Settings I;
- static {
- I = TableConfig.getSettings();
- }
+ static {
+ I = TableConfig.getSettings();
+ }
- // -------------------------------------------- //
- // CONFIGURATIONS
- // -------------------------------------------- //
- public String Wechat_AppId;
- public String Wechat_Secret;
- public String Wechat_Token;
- public String Wechat_AesKey;
+ public String Wechat_AppId;
+ public String Wechat_Secret;
+ public String Wechat_Token;
+ public String Wechat_AesKey;
- public int Check_Spam_Cache_Expire_Time;
- public int Check_Spam_Interval;
+ public int Check_Spam_Cache_Expire_Time;
+ public int Check_Spam_Interval;
- public int User_Session_Max_Inactive;
- public int User_Wechat_Cache_Expire_Time;
+ public int User_Session_Max_Inactive;
+ public int User_Wechat_Cache_Expire_Time;
- //No arg constructor for Yaml.loadAs
- public Settings() {
- I = this;
- }
+ //No arg constructor for Yaml.loadAs
+ public Settings() {
+ I = this;
+ }
+ @Override
+ public String toString() {
+ return "Settings{" +
+ "Wechat_AppId='" + Wechat_AppId + '\'' +
+ ", Wechat_Secret='" + Wechat_Secret + '\'' +
+ ", Wechat_Token='" + Wechat_Token + '\'' +
+ ", Wechat_AesKey='" + Wechat_AesKey + '\'' +
+ ", Check_Spam_Cache_Expire_Time=" + Check_Spam_Cache_Expire_Time +
+ ", Check_Spam_Interval=" + Check_Spam_Interval +
+ ", User_Session_Max_Inactive=" + User_Session_Max_Inactive +
+ ", User_Wechat_Cache_Expire_Time=" + User_Wechat_Cache_Expire_Time +
+ '}';
+ }
}
diff --git a/src/main/java/love/sola/netsupport/config/WxMpXmlInMemoryConfigStorage.java b/src/main/java/love/sola/netsupport/config/WxMpXmlInMemoryConfigStorage.java
index 576fcf8..d9a1c89 100644
--- a/src/main/java/love/sola/netsupport/config/WxMpXmlInMemoryConfigStorage.java
+++ b/src/main/java/love/sola/netsupport/config/WxMpXmlInMemoryConfigStorage.java
@@ -19,7 +19,6 @@ package love.sola.netsupport.config;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
-import lombok.ToString;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
@@ -29,15 +28,14 @@ import java.io.InputStream;
* @author chanjarster
*/
@XStreamAlias("wechat-config")
-@ToString
public class WxMpXmlInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
- @SuppressWarnings("unchecked")
- public static T fromXml(Class clazz, InputStream is) {
- XStream xstream = XStreamInitializer.getInstance();
- xstream.alias("wechat-config", clazz);
- xstream.processAnnotations(clazz);
- return (T) xstream.fromXML(is);
- }
+ @SuppressWarnings("unchecked")
+ public static T fromXml(Class clazz, InputStream is) {
+ XStream xstream = XStreamInitializer.getInstance();
+ xstream.alias("wechat-config", clazz);
+ xstream.processAnnotations(clazz);
+ return (T) xstream.fromXML(is);
+ }
}
diff --git a/src/main/java/love/sola/netsupport/enums/Access.java b/src/main/java/love/sola/netsupport/enums/Access.java
index 08bb6d6..31294a4 100644
--- a/src/main/java/love/sola/netsupport/enums/Access.java
+++ b/src/main/java/love/sola/netsupport/enums/Access.java
@@ -28,40 +28,40 @@ import static love.sola.netsupport.config.Lang.lang;
*/
public class Access {
- public static final int GOD_MODE = -1;
- public static final int ROOT = 0;
- public static final int MANAGER = 1;
- public static final int CO_MANAGER = 2;
- public static final int LEADER = 3;
- public static final int CO_LEADER = 4;
- public static final int ELITE = 5;
- public static final int ELDER = 6;
- public static final int MEMBER = 7;
- public static final int PRE_MEMBER = 8;
- public static final int NO_LOGIN = 9;
- public static final int USER = 10;
- public static final int GUEST = 11;
+ public static final int GOD_MODE = -1;
+ public static final int ROOT = 0;
+ public static final int MANAGER = 1;
+ public static final int CO_MANAGER = 2;
+ public static final int LEADER = 3;
+ public static final int CO_LEADER = 4;
+ public static final int ELITE = 5;
+ public static final int ELDER = 6;
+ public static final int MEMBER = 7;
+ public static final int PRE_MEMBER = 8;
+ public static final int NO_LOGIN = 9;
+ public static final int USER = 10;
+ public static final int GUEST = 11;
- public static final Map inverseMap = new HashMap<>();
+ public static final Map inverseMap = new HashMap<>();
- static {
- System.out.println("Loading Access...");
- for (Field field : Access.class.getDeclaredFields()) {
- if (field.getType().isAssignableFrom(Integer.TYPE)) {
- try {
- inverseMap.put((Integer) field.get(null), field.getName());
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- }
+ static {
+ System.out.println("Loading Access...");
+ for (Field field : Access.class.getDeclaredFields()) {
+ if (field.getType().isAssignableFrom(Integer.TYPE)) {
+ try {
+ inverseMap.put((Integer) field.get(null), field.getName());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
- public static String getLocalized(int access) {
- if (inverseMap.containsKey(access)) {
- return lang("ACCESS_" + inverseMap.get(access));
- }
- return null;
- }
+ public static String getLocalized(int access) {
+ if (inverseMap.containsKey(access)) {
+ return lang("ACCESS_" + inverseMap.get(access));
+ }
+ return null;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/enums/Attribute.java b/src/main/java/love/sola/netsupport/enums/Attribute.java
index 65eb842..b5b84bc 100644
--- a/src/main/java/love/sola/netsupport/enums/Attribute.java
+++ b/src/main/java/love/sola/netsupport/enums/Attribute.java
@@ -22,9 +22,9 @@ package love.sola.netsupport.enums;
*/
public class Attribute {
- public static final String AUTHORIZED = "authorized";
- public static final String WECHAT = "wechat";
- public static final String OPERATOR = "operator";
- public static final String USER = "user";
+ public static final String AUTHORIZED = "authorized";
+ public static final String WECHAT = "wechat";
+ public static final String OPERATOR = "operator";
+ public static final String USER = "user";
}
diff --git a/src/main/java/love/sola/netsupport/enums/Block.java b/src/main/java/love/sola/netsupport/enums/Block.java
index dd7cee9..952630a 100644
--- a/src/main/java/love/sola/netsupport/enums/Block.java
+++ b/src/main/java/love/sola/netsupport/enums/Block.java
@@ -26,61 +26,61 @@ import java.util.Map;
*/
public class Block {
- public static final int QT_18 = 10;
- public static final int QT_19 = 11;
- public static final int QT_16 = 12;
- public static final int QT_17 = 13;
- public static final int BM_7 = 20;
- public static final int BM_8 = 21;
- public static final int BM_9 = 22;
- public static final int BM_10 = 23;
- public static final int BM_11 = 24;
- public static final int DM_12 = 30;
- public static final int DM_13 = 31;
- public static final int DM_14 = 32;
- public static final int DM_15 = 33;
- public static final int DM_20 = 34;
- public static final int DM_21 = 35;
- public static final int XH_A = 40;
- public static final int XH_B = 41;
- public static final int XH_C = 42;
- public static final int XH_D = 43;
- public static final int FX_1 = 50;
- public static final int FX_2 = 51;
- public static final int FX_3 = 52;
- public static final int FX_4 = 53;
- public static final int FX_5 = 54;
- public static final int FX_6 = 55;
- public static final int BS_1 = 60;
- public static final int BS_2 = 61;
- public static final int BS_3 = 62;
- public static final int BS_4 = 63;
- public static final int BS_5 = 64;
- public static final int BS_6 = 65;
- public static final int BS_7 = 66;
- public static final int BS_8 = 67;
- public static final int BS_9 = 68;
- public static final int ZH = 80;
+ public static final int QT_18 = 10;
+ public static final int QT_19 = 11;
+ public static final int QT_16 = 12;
+ public static final int QT_17 = 13;
+ public static final int BM_7 = 20;
+ public static final int BM_8 = 21;
+ public static final int BM_9 = 22;
+ public static final int BM_10 = 23;
+ public static final int BM_11 = 24;
+ public static final int DM_12 = 30;
+ public static final int DM_13 = 31;
+ public static final int DM_14 = 32;
+ public static final int DM_15 = 33;
+ public static final int DM_20 = 34;
+ public static final int DM_21 = 35;
+ public static final int XH_A = 40;
+ public static final int XH_B = 41;
+ public static final int XH_C = 42;
+ public static final int XH_D = 43;
+ public static final int FX_1 = 50;
+ public static final int FX_2 = 51;
+ public static final int FX_3 = 52;
+ public static final int FX_4 = 53;
+ public static final int FX_5 = 54;
+ public static final int FX_6 = 55;
+ public static final int BS_1 = 60;
+ public static final int BS_2 = 61;
+ public static final int BS_3 = 62;
+ public static final int BS_4 = 63;
+ public static final int BS_5 = 64;
+ public static final int BS_6 = 65;
+ public static final int BS_7 = 66;
+ public static final int BS_8 = 67;
+ public static final int BS_9 = 68;
+ public static final int ZH = 80;
- public static final Map inverseMap = new HashMap<>();
+ public static final Map inverseMap = new HashMap<>();
- static {
- System.out.println("Loading Blocks...");
- for (Field field : Block.class.getDeclaredFields()) {
- if (field.getType().isAssignableFrom(Integer.TYPE)) {
- try {
- inverseMap.put((Integer) field.get(null), field.getName());
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- }
+ static {
+ System.out.println("Loading Blocks...");
+ for (Field field : Block.class.getDeclaredFields()) {
+ if (field.getType().isAssignableFrom(Integer.TYPE)) {
+ try {
+ inverseMap.put((Integer) field.get(null), field.getName());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
- private static final int[][] AVAILABLE = new int[100][0];
+ private static final int[][] AVAILABLE = new int[100][0];
- static {
- // @formatter:off
+ static {
+ // @formatter:off
// -------------------------------------------- //
// THANKS DATA PROVIDED BY Lai Juncheng
// -------------------------------------------- //
@@ -120,14 +120,14 @@ public class Block {
AVAILABLE[BS_9] = new int[]{103, 203, 302};
AVAILABLE[ZH] = new int[]{199, 299, 399, 499, 599, 699, 799, 899, 999, 1099, 1199, 1299, 1399};
// @formatter:on
- }
+ }
- public static boolean checkRoom(int block, int room) {
- int floor = room / 100;
- if (floor == 0 || room % 100 == 0) return false;
- if (block < 0 || block >= AVAILABLE.length) return false;
- if (AVAILABLE[block].length < floor) return false;
- return room <= AVAILABLE[block][floor - 1];
- }
+ public static boolean checkRoom(int block, int room) {
+ int floor = room / 100;
+ if (floor == 0 || room % 100 == 0) return false;
+ if (block < 0 || block >= AVAILABLE.length) return false;
+ if (AVAILABLE[block].length < floor) return false;
+ return room <= AVAILABLE[block][floor - 1];
+ }
}
diff --git a/src/main/java/love/sola/netsupport/enums/ISP.java b/src/main/java/love/sola/netsupport/enums/ISP.java
index cbb9c47..5e3e403 100644
--- a/src/main/java/love/sola/netsupport/enums/ISP.java
+++ b/src/main/java/love/sola/netsupport/enums/ISP.java
@@ -27,49 +27,49 @@ import static love.sola.netsupport.config.Lang.lang;
*/
public enum ISP {
- TELECOM(1, "^1[3|4|5|7|8][0-9]{9}$"),
- UNICOM(2, "ZSZJLAN[0-9]{10}@16900\\.gd"),
- CHINAMOBILE(3, "^1[3|4|5|7|8][0-9]{9}@139\\.gd$"),
- OTHER(4, ".*"),;
+ TELECOM(1, "^1[3|4|5|7|8][0-9]{9}$"),
+ UNICOM(2, "ZSZJLAN[0-9]{10}@16900\\.gd"),
+ CHINAMOBILE(3, "^1[3|4|5|7|8][0-9]{9}@139\\.gd$"),
+ OTHER(4, ".*"),;
- private static final Map NAME_MAP = new HashMap<>();
- private static final Map ID_MAP = new HashMap<>();
+ private static final Map NAME_MAP = new HashMap<>();
+ private static final Map ID_MAP = new HashMap<>();
- static {
- for (ISP type : values()) {
- if (type.name != null) {
- NAME_MAP.put(type.name.toLowerCase(), type);
- }
- if (type.id > 0) {
- ID_MAP.put(type.id, type);
- }
- }
- }
+ static {
+ for (ISP type : values()) {
+ if (type.name != null) {
+ NAME_MAP.put(type.name.toLowerCase(), type);
+ }
+ if (type.id > 0) {
+ ID_MAP.put(type.id, type);
+ }
+ }
+ }
- public final int id;
- public final String name;
- public final String accountRegex;
+ public final int id;
+ public final String name;
+ public final String accountRegex;
- ISP(int id, String accountRegex) {
- this.id = id;
- this.name = lang("ISP_" + name());
- this.accountRegex = accountRegex;
- }
+ ISP(int id, String accountRegex) {
+ this.id = id;
+ this.name = lang("ISP_" + name());
+ this.accountRegex = accountRegex;
+ }
- public static ISP fromName(String name) {
- if (name == null) {
- return null;
- }
- return NAME_MAP.get(name.toLowerCase());
- }
+ public static ISP fromName(String name) {
+ if (name == null) {
+ return null;
+ }
+ return NAME_MAP.get(name.toLowerCase());
+ }
- public static ISP fromId(int id) {
- return ID_MAP.get(id);
- }
+ public static ISP fromId(int id) {
+ return ID_MAP.get(id);
+ }
- @Override
- public String toString() {
- return name;
- }
+ @Override
+ public String toString() {
+ return name;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/enums/ISPConverter.java b/src/main/java/love/sola/netsupport/enums/ISPConverter.java
index 5cf41da..9a37946 100644
--- a/src/main/java/love/sola/netsupport/enums/ISPConverter.java
+++ b/src/main/java/love/sola/netsupport/enums/ISPConverter.java
@@ -26,20 +26,20 @@ import javax.persistence.Converter;
@Converter
public class ISPConverter implements AttributeConverter {
- @Override
- public Integer convertToDatabaseColumn(ISP attribute) {
- if (attribute == null) {
- return null;
- }
- return attribute.id;
- }
+ @Override
+ public Integer convertToDatabaseColumn(ISP attribute) {
+ if (attribute == null) {
+ return null;
+ }
+ return attribute.id;
+ }
- @Override
- public ISP convertToEntityAttribute(Integer dbData) {
- if (dbData == null) {
- return null;
- }
- return ISP.fromId(dbData);
- }
+ @Override
+ public ISP convertToEntityAttribute(Integer dbData) {
+ if (dbData == null) {
+ return null;
+ }
+ return ISP.fromId(dbData);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/enums/Status.java b/src/main/java/love/sola/netsupport/enums/Status.java
index 91dc725..05ed3bf 100644
--- a/src/main/java/love/sola/netsupport/enums/Status.java
+++ b/src/main/java/love/sola/netsupport/enums/Status.java
@@ -28,33 +28,33 @@ import static love.sola.netsupport.config.Lang.lang;
*/
public class Status {
- public static final int UNCHECKED = 0;
- public static final int ARRANGED = 1;
- public static final int PUTOFF = 2;
- public static final int REPORTED = 4;
- public static final int ISP_HANDLED = 7;
- public static final int SOLVED = 9;
+ public static final int UNCHECKED = 0;
+ public static final int ARRANGED = 1;
+ public static final int PUTOFF = 2;
+ public static final int REPORTED = 4;
+ public static final int ISP_HANDLED = 7;
+ public static final int SOLVED = 9;
- public static final Map inverseMap = new HashMap<>();
+ public static final Map inverseMap = new HashMap<>();
- static {
- System.out.println("Loading Status...");
- for (Field field : Status.class.getDeclaredFields()) {
- if (field.getType().isAssignableFrom(Integer.TYPE)) {
- try {
- inverseMap.put((Integer) field.get(null), field.getName());
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- }
- }
- }
- }
+ static {
+ System.out.println("Loading Status...");
+ for (Field field : Status.class.getDeclaredFields()) {
+ if (field.getType().isAssignableFrom(Integer.TYPE)) {
+ try {
+ inverseMap.put((Integer) field.get(null), field.getName());
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
- public static String getLocalized(int status) {
- if (inverseMap.containsKey(status)) {
- return lang("STATUS_" + inverseMap.get(status));
- }
- return null;
- }
+ public static String getLocalized(int status) {
+ if (inverseMap.containsKey(status)) {
+ return lang("STATUS_" + inverseMap.get(status));
+ }
+ return null;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/pojo/Operator.java b/src/main/java/love/sola/netsupport/pojo/Operator.java
index a431021..3b13a41 100644
--- a/src/main/java/love/sola/netsupport/pojo/Operator.java
+++ b/src/main/java/love/sola/netsupport/pojo/Operator.java
@@ -18,10 +18,6 @@
package love.sola.netsupport.pojo;
import com.google.gson.annotations.Expose;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.ToString;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -31,35 +27,109 @@ import javax.persistence.Table;
/**
* @author Sola {@literal }
*/
-
-@Data
-@ToString(exclude = "password")
-@AllArgsConstructor
-@NoArgsConstructor
@Entity
@Table(name = "operators")
public class Operator {
- public static final String PROPERTY_WECHAT = "wechat";
+ public static final String PROPERTY_WECHAT = "wechat";
- @Id
- @Column(name = "id", nullable = false, insertable = false, updatable = false)
- private Integer id;
- @Column(name = "name", nullable = false, insertable = false, updatable = false)
- private String name;
- @Column(name = "access", nullable = false, insertable = false, updatable = false)
- private Integer access;
- @Column(name = "wechat", insertable = false, updatable = false)
- @Expose(serialize = false)
- private String wechat;
- private Integer block;
- private Integer week;
- @Expose(serialize = false)
- private String password;
+ //System Accounts
+ public static Operator USER_SELF;
+ public static Operator ADMIN;
+ @Id
+ @Column(name = "id", nullable = false, insertable = false, updatable = false)
+ private Integer id;
+ @Column(name = "name", nullable = false, insertable = false, updatable = false)
+ private String name;
+ @Column(name = "access", nullable = false, insertable = false, updatable = false)
+ private Integer access;
+ @Column(name = "wechat", insertable = false, updatable = false)
+ @Expose(serialize = false)
+ private String wechat;
+ private Integer block;
+ private Integer week;
+ @Expose(serialize = false)
+ private String password;
- //System Accounts
- public static Operator USER_SELF;
- public static Operator ADMIN;
+ public Operator(Integer id, String name, Integer access, String wechat, Integer block, Integer week, String password) {
+ this.id = id;
+ this.name = name;
+ this.access = access;
+ this.wechat = wechat;
+ this.block = block;
+ this.week = week;
+ this.password = password;
+ }
+ public Operator() {
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Integer getAccess() {
+ return access;
+ }
+
+ public void setAccess(Integer access) {
+ this.access = access;
+ }
+
+ public String getWechat() {
+ return wechat;
+ }
+
+ public void setWechat(String wechat) {
+ this.wechat = wechat;
+ }
+
+ public Integer getBlock() {
+ return block;
+ }
+
+ public void setBlock(Integer block) {
+ this.block = block;
+ }
+
+ public Integer getWeek() {
+ return week;
+ }
+
+ public void setWeek(Integer week) {
+ this.week = week;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public String toString() {
+ return "Operator{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", access=" + access +
+ ", wechat='" + wechat + '\'' +
+ ", block=" + block +
+ ", week=" + week +
+ '}';
+ }
}
diff --git a/src/main/java/love/sola/netsupport/pojo/Ticket.java b/src/main/java/love/sola/netsupport/pojo/Ticket.java
index c505219..160d592 100644
--- a/src/main/java/love/sola/netsupport/pojo/Ticket.java
+++ b/src/main/java/love/sola/netsupport/pojo/Ticket.java
@@ -17,9 +17,6 @@
package love.sola.netsupport.pojo;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
import love.sola.netsupport.sql.TableTicket;
import org.hibernate.envers.Audited;
import org.hibernate.envers.RelationTargetAuditMode;
@@ -30,32 +27,119 @@ import java.util.Date;
/**
* @author Sola {@literal }
*/
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
@Entity
@Table(name = "tickets")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
public class Ticket {
- public static final String PROPERTY_USER = "user";
- public static final String PROPERTY_STATUS = "status";
- public static final String PROPERTY_SUBMIT_TIME = "submitTime";
+ public static final String PROPERTY_USER = "user";
+ public static final String PROPERTY_STATUS = "status";
+ public static final String PROPERTY_SUBMIT_TIME = "submitTime";
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
- @ManyToOne(optional = false)
- @JoinColumn(name = TableTicket.COLUMN_SID)
- private User user;
- private String description;
- @Column(name = TableTicket.COLUMN_SUBMIT_TIME, insertable = false, updatable = false)
- private Date submitTime;
- private String remark;
- private Date updateTime;
- @ManyToOne(optional = true)
- @JoinColumn(name = TableTicket.COLUMN_OPSID)
- private Operator operator;
- private Integer status;
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+ @ManyToOne(optional = false)
+ @JoinColumn(name = TableTicket.COLUMN_SID)
+ private User user;
+ private String description;
+ @Column(name = TableTicket.COLUMN_SUBMIT_TIME, insertable = false, updatable = false)
+ private Date submitTime;
+ private String remark;
+ private Date updateTime;
+ @ManyToOne(optional = true)
+ @JoinColumn(name = TableTicket.COLUMN_OPSID)
+ private Operator operator;
+ private Integer status;
+ public Ticket() {
+ }
+
+ public Ticket(User user, String description, Date submitTime, String remark, Date updateTime, Operator operator, Integer status) {
+ this.user = user;
+ this.description = description;
+ this.submitTime = submitTime;
+ this.remark = remark;
+ this.updateTime = updateTime;
+ this.operator = operator;
+ this.status = status;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Date getSubmitTime() {
+ return submitTime;
+ }
+
+ public void setSubmitTime(Date submitTime) {
+ this.submitTime = submitTime;
+ }
+
+ public String getRemark() {
+ return remark;
+ }
+
+ public void setRemark(String remark) {
+ this.remark = remark;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ @Override
+ public String toString() {
+ return "Ticket{" +
+ "id=" + id +
+ ", user=" + user +
+ ", description='" + description + '\'' +
+ ", submitTime=" + submitTime +
+ ", remark='" + remark + '\'' +
+ ", updateTime=" + updateTime +
+ ", operator=" + operator +
+ ", status=" + status +
+ '}';
+ }
}
diff --git a/src/main/java/love/sola/netsupport/pojo/ToolsCheck.java b/src/main/java/love/sola/netsupport/pojo/ToolsCheck.java
index aa1ffe4..97d1db3 100644
--- a/src/main/java/love/sola/netsupport/pojo/ToolsCheck.java
+++ b/src/main/java/love/sola/netsupport/pojo/ToolsCheck.java
@@ -1,8 +1,5 @@
package love.sola.netsupport.pojo;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
@@ -12,29 +9,97 @@ import java.util.Date;
/**
* @author Sola {@literal }
*/
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
@Entity
@Table(name = "toolschk", indexes = {
- @Index(columnList = "block,chktime,status"),
- @Index(columnList = "chktime,status")
+ @Index(columnList = "block,chktime,status"),
+ @Index(columnList = "chktime,status")
})
@DynamicInsert
public class ToolsCheck {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
- @ManyToOne(optional = false)
- @JoinColumn(name = "opsid", nullable = false)
- private Operator operator;
- @Column(nullable = false)
- private Integer block;
- @Column(name = "chktime", nullable = false)
- private Date checkTime = new Date();
- @ColumnDefault("0")
- private Integer status = 0;
- private String remark;
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer id;
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "opsid", nullable = false)
+ private Operator operator;
+ @Column(nullable = false)
+ private Integer block;
+ @Column(name = "chktime", nullable = false)
+ private Date checkTime = new Date();
+ @ColumnDefault("0")
+ private Integer status = 0;
+ private String remark;
+
+ public ToolsCheck() {
+ }
+
+ public ToolsCheck(Operator operator, Integer block, Date checkTime, Integer status, String remark) {
+ this.operator = operator;
+ this.block = block;
+ this.checkTime = checkTime;
+ this.status = status;
+ this.remark = remark;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ public void setOperator(Operator operator) {
+ this.operator = operator;
+ }
+
+ public Integer getBlock() {
+ return block;
+ }
+
+ public void setBlock(Integer block) {
+ this.block = block;
+ }
+
+ public Date getCheckTime() {
+ return checkTime;
+ }
+
+ public void setCheckTime(Date checkTime) {
+ this.checkTime = checkTime;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ public String getRemark() {
+ return remark;
+ }
+
+ public void setRemark(String remark) {
+ this.remark = remark;
+ }
+
+ @Override
+ public String toString() {
+ return "ToolsCheck{" +
+ "id=" + id +
+ ", operator=" + operator +
+ ", block=" + block +
+ ", checkTime=" + checkTime +
+ ", status=" + status +
+ ", remark='" + remark + '\'' +
+ '}';
+ }
}
diff --git a/src/main/java/love/sola/netsupport/pojo/User.java b/src/main/java/love/sola/netsupport/pojo/User.java
index 81d6e58..6898a41 100644
--- a/src/main/java/love/sola/netsupport/pojo/User.java
+++ b/src/main/java/love/sola/netsupport/pojo/User.java
@@ -18,9 +18,6 @@
package love.sola.netsupport.pojo;
import com.google.gson.annotations.Expose;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
import love.sola.netsupport.enums.ISP;
import love.sola.netsupport.enums.ISPConverter;
@@ -29,37 +26,124 @@ import javax.persistence.*;
/**
* @author Sola {@literal }
*/
-@Data
-@AllArgsConstructor
-@NoArgsConstructor
@Entity
@Table(name = "users")
public class User {
- public static final String PROPERTY_NAME = "name";
- public static final String PROPERTY_WECHAT = "wechatId";
- public static final String PROPERTY_BLOCK = "block";
+ //System Accounts
+ public static User OFFICIAL_CHINA_UNICOM_XH;
+ public static User OFFICIAL_CHINA_MOBILE_XH;
+ public static User OFFICIAL_CHINA_MOBILE_FX;
- @Id
- @Column(name = "id", updatable = false, nullable = false)
- private Long id;
- @Column(name = "name", updatable = false, nullable = false)
- private String name;
- @Convert(converter = ISPConverter.class)
- private ISP isp;
- @Column(name = "netaccount")
- private String netAccount;
- @Expose(serialize = false)
- @Column(name = "wechat")
- private String wechatId;
- private Integer block;
- private Integer room;
- private Long phone;
+ public static final String PROPERTY_NAME = "name";
+ public static final String PROPERTY_WECHAT = "wechatId";
+ public static final String PROPERTY_BLOCK = "block";
+ @Id
+ @Column(name = "id", updatable = false, nullable = false)
+ private Long id;
+ @Column(name = "name", updatable = false, nullable = false)
+ private String name;
+ @Convert(converter = ISPConverter.class)
+ private ISP isp;
+ @Column(name = "netaccount")
+ private String netAccount;
+ @Expose(serialize = false)
+ @Column(name = "wechat")
+ private String wechatId;
+ private Integer block;
+ private Integer room;
+ private Long phone;
- //System Accounts
- public static User OFFICIAL_CHINA_UNICOM_XH;
- public static User OFFICIAL_CHINA_MOBILE_XH;
- public static User OFFICIAL_CHINA_MOBILE_FX;
+ public User() {
+ }
+ public User(Long id, String name, ISP isp, String netAccount, String wechatId, Integer block, Integer room, Long phone) {
+ this.id = id;
+ this.name = name;
+ this.isp = isp;
+ this.netAccount = netAccount;
+ this.wechatId = wechatId;
+ this.block = block;
+ this.room = room;
+ this.phone = phone;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ISP getIsp() {
+ return isp;
+ }
+
+ public void setIsp(ISP isp) {
+ this.isp = isp;
+ }
+
+ public String getNetAccount() {
+ return netAccount;
+ }
+
+ public void setNetAccount(String netAccount) {
+ this.netAccount = netAccount;
+ }
+
+ public String getWechatId() {
+ return wechatId;
+ }
+
+ public void setWechatId(String wechatId) {
+ this.wechatId = wechatId;
+ }
+
+ public Integer getBlock() {
+ return block;
+ }
+
+ public void setBlock(Integer block) {
+ this.block = block;
+ }
+
+ public Integer getRoom() {
+ return room;
+ }
+
+ public void setRoom(Integer room) {
+ this.room = room;
+ }
+
+ public Long getPhone() {
+ return phone;
+ }
+
+ public void setPhone(Long phone) {
+ this.phone = phone;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", isp=" + isp +
+ ", netAccount='" + netAccount + '\'' +
+ ", wechatId='" + wechatId + '\'' +
+ ", block=" + block +
+ ", room=" + room +
+ ", phone=" + phone +
+ '}';
+ }
}
diff --git a/src/main/java/love/sola/netsupport/session/MapSession.java b/src/main/java/love/sola/netsupport/session/MapSession.java
index b8a4fb6..db385da 100644
--- a/src/main/java/love/sola/netsupport/session/MapSession.java
+++ b/src/main/java/love/sola/netsupport/session/MapSession.java
@@ -32,74 +32,95 @@
*/
package love.sola.netsupport.session;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
-import lombok.Setter;
-
import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
/**
* @author Sola {@literal }
*/
-@EqualsAndHashCode(of = "id")
public final class MapSession implements WxSession, Serializable {
- @Getter
- private final String id;
- private Map sessionAttrs = new HashMap();
- @Getter
- private long creationTime = System.currentTimeMillis();
- @Getter
- @Setter
- private long lastAccessedTime = creationTime;
- @Getter
- private boolean invalidated = false;
+ private final String id;
+ private Map sessionAttrs = new HashMap();
+ private long creationTime = System.currentTimeMillis();
+ private long lastAccessedTime = creationTime;
+ private boolean invalidated = false;
- /**
- * Creates a new instance with a secure randomly generated identifier.
- */
- public MapSession() {
- this(UUID.randomUUID().toString());
- }
+ /**
+ * Creates a new instance with a secure randomly generated identifier.
+ */
+ public MapSession() {
+ this(UUID.randomUUID().toString());
+ }
- /**
- * Creates a new instance with the specified id. This is preferred to the
- * default constructor when the id is known to prevent unnecessary consumption on
- * entropy which can be slow.
- *
- * @param id the identifier to use
- */
- public MapSession(String id) {
- this.id = id;
- }
+ /**
+ * Creates a new instance with the specified id. This is preferred to the
+ * default constructor when the id is known to prevent unnecessary consumption on
+ * entropy which can be slow.
+ *
+ * @param id the identifier to use
+ */
+ public MapSession(String id) {
+ this.id = id;
+ }
- @SuppressWarnings("unchecked")
- public T getAttribute(String attributeName) {
- return (T) sessionAttrs.get(attributeName);
- }
+ @SuppressWarnings("unchecked")
+ public T getAttribute(String attributeName) {
+ return (T) sessionAttrs.get(attributeName);
+ }
- public Set getAttributeNames() {
- return sessionAttrs.keySet();
- }
+ public Set getAttributeNames() {
+ return sessionAttrs.keySet();
+ }
- public void setAttribute(String attributeName, Object attributeValue) {
- if (attributeValue == null) {
- removeAttribute(attributeName);
- } else {
- sessionAttrs.put(attributeName, attributeValue);
- }
- }
+ public void setAttribute(String attributeName, Object attributeValue) {
+ if (attributeValue == null) {
+ removeAttribute(attributeName);
+ } else {
+ sessionAttrs.put(attributeName, attributeValue);
+ }
+ }
- public void removeAttribute(String attributeName) {
- sessionAttrs.remove(attributeName);
- }
+ public void removeAttribute(String attributeName) {
+ sessionAttrs.remove(attributeName);
+ }
- public void invalidate() {
- invalidated = true;
- }
+ public void invalidate() {
+ invalidated = true;
+ }
+ public long getLastAccessedTime() {
+ return lastAccessedTime;
+ }
+
+ public void setLastAccessedTime(long lastAccessedTime) {
+ this.lastAccessedTime = lastAccessedTime;
+ }
+
+ @Override
+ public String getId() {
+
+ return id;
+ }
+
+ public long getCreationTime() {
+ return creationTime;
+ }
+
+ public boolean isInvalidated() {
+ return invalidated;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MapSession)) return false;
+ MapSession that = (MapSession) o;
+ return Objects.equals(id, that.id);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/session/MapSessionRepository.java b/src/main/java/love/sola/netsupport/session/MapSessionRepository.java
index 31604ea..c40d990 100644
--- a/src/main/java/love/sola/netsupport/session/MapSessionRepository.java
+++ b/src/main/java/love/sola/netsupport/session/MapSessionRepository.java
@@ -47,56 +47,56 @@ import java.util.concurrent.TimeUnit;
*/
public class MapSessionRepository {
- private final LoadingCache sessions;
+ private final LoadingCache sessions;
- public MapSessionRepository() {
- this(CacheBuilder.newBuilder()
- .concurrencyLevel(4)
- .maximumSize(65535)
- .expireAfterAccess(Settings.I.User_Session_Max_Inactive, TimeUnit.SECONDS)
- .build(new CacheLoader() {
- @Override
- public MapSession load(@Nonnull String key) throws Exception {
- return new MapSession(key);
- }
- }
- )
- );
- }
+ public MapSessionRepository() {
+ this(CacheBuilder.newBuilder()
+ .concurrencyLevel(4)
+ .maximumSize(65535)
+ .expireAfterAccess(Settings.I.User_Session_Max_Inactive, TimeUnit.SECONDS)
+ .build(new CacheLoader() {
+ @Override
+ public MapSession load(@Nonnull String key) throws Exception {
+ return new MapSession(key);
+ }
+ }
+ )
+ );
+ }
- public MapSessionRepository(LoadingCache sessions) {
- Validate.notNull(sessions);
- this.sessions = sessions;
- }
+ public MapSessionRepository(LoadingCache sessions) {
+ Validate.notNull(sessions);
+ this.sessions = sessions;
+ }
- public void save(MapSession session) {
- sessions.put(session.getId(), session);
- }
+ public void save(MapSession session) {
+ sessions.put(session.getId(), session);
+ }
- public MapSession getSession(String id) {
- MapSession saved = sessions.getIfPresent(id);
- if (saved == null) {
- return null;
- }
- if (saved.isInvalidated()) {
- delete(saved.getId());
- return null;
- }
- return saved;
- }
+ public MapSession getSession(String id) {
+ MapSession saved = sessions.getIfPresent(id);
+ if (saved == null) {
+ return null;
+ }
+ if (saved.isInvalidated()) {
+ delete(saved.getId());
+ return null;
+ }
+ return saved;
+ }
- public void delete(String id) {
- sessions.invalidate(id);
- }
+ public void delete(String id) {
+ sessions.invalidate(id);
+ }
- public MapSession createSession() {
- MapSession session = new MapSession();
- save(session);
- return session;
- }
+ public MapSession createSession() {
+ MapSession session = new MapSession();
+ save(session);
+ return session;
+ }
- public Map asMap() {
- return sessions.asMap();
- }
+ public Map asMap() {
+ return sessions.asMap();
+ }
}
diff --git a/src/main/java/love/sola/netsupport/session/WechatSession.java b/src/main/java/love/sola/netsupport/session/WechatSession.java
index 3780bfe..c963f54 100644
--- a/src/main/java/love/sola/netsupport/session/WechatSession.java
+++ b/src/main/java/love/sola/netsupport/session/WechatSession.java
@@ -25,22 +25,22 @@ import java.util.Collection;
*/
public class WechatSession {
- private static MapSessionRepository repository;
+ private static MapSessionRepository repository;
- static {
- repository = new MapSessionRepository();
- }
+ static {
+ repository = new MapSessionRepository();
+ }
- public static WxSession get(String id) {
- return repository.getSession(id);
- }
+ public static WxSession get(String id) {
+ return repository.getSession(id);
+ }
- public static WxSession create() {
- return repository.createSession();
- }
+ public static WxSession create() {
+ return repository.createSession();
+ }
- public static Collection extends WxSession> list() {
- return repository.asMap().values();
- }
+ public static Collection extends WxSession> list() {
+ return repository.asMap().values();
+ }
}
diff --git a/src/main/java/love/sola/netsupport/session/WxSession.java b/src/main/java/love/sola/netsupport/session/WxSession.java
index ffbf82c..00c9edf 100644
--- a/src/main/java/love/sola/netsupport/session/WxSession.java
+++ b/src/main/java/love/sola/netsupport/session/WxSession.java
@@ -24,16 +24,16 @@ import java.util.Set;
*/
public interface WxSession {
- String getId();
+ String getId();
- T getAttribute(String name);
+ T getAttribute(String name);
- Set getAttributeNames();
+ Set getAttributeNames();
- void setAttribute(String name, Object value);
+ void setAttribute(String name, Object value);
- void removeAttribute(String name);
+ void removeAttribute(String name);
- void invalidate();
+ void invalidate();
}
\ No newline at end of file
diff --git a/src/main/java/love/sola/netsupport/sql/SQLCore.java b/src/main/java/love/sola/netsupport/sql/SQLCore.java
index 696c28d..ed4f05f 100644
--- a/src/main/java/love/sola/netsupport/sql/SQLCore.java
+++ b/src/main/java/love/sola/netsupport/sql/SQLCore.java
@@ -46,111 +46,111 @@ import java.util.Date;
*/
public class SQLCore {
- public static InitialContext ic;
- public static DataSource ds;
- public static SessionFactory sf;
- public static ServiceRegistry sr;
- public static Gson gson = new GsonBuilder()
- .addSerializationExclusionStrategy(new ExclusionStrategy() {
- @Override
- public boolean shouldSkipField(FieldAttributes fieldAttributes) {
- final Expose expose = fieldAttributes.getAnnotation(Expose.class);
- return expose != null && !expose.serialize();
- }
+ public static InitialContext ic;
+ public static DataSource ds;
+ public static SessionFactory sf;
+ public static ServiceRegistry sr;
+ public static Gson gson = new GsonBuilder()
+ .addSerializationExclusionStrategy(new ExclusionStrategy() {
+ @Override
+ public boolean shouldSkipField(FieldAttributes fieldAttributes) {
+ final Expose expose = fieldAttributes.getAnnotation(Expose.class);
+ return expose != null && !expose.serialize();
+ }
- @Override
- public boolean shouldSkipClass(Class> aClass) {
- return false;
- }
- })
- .addDeserializationExclusionStrategy(new ExclusionStrategy() {
- @Override
- public boolean shouldSkipField(FieldAttributes fieldAttributes) {
- final Expose expose = fieldAttributes.getAnnotation(Expose.class);
- return expose != null && !expose.deserialize();
- }
+ @Override
+ public boolean shouldSkipClass(Class> aClass) {
+ return false;
+ }
+ })
+ .addDeserializationExclusionStrategy(new ExclusionStrategy() {
+ @Override
+ public boolean shouldSkipField(FieldAttributes fieldAttributes) {
+ final Expose expose = fieldAttributes.getAnnotation(Expose.class);
+ return expose != null && !expose.deserialize();
+ }
- @Override
- public boolean shouldSkipClass(Class> aClass) {
- return false;
- }
- })
- .registerTypeAdapter(Date.class, (JsonDeserializer) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
- .registerTypeAdapter(Date.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
- .registerTypeAdapter(ISP.class, (JsonDeserializer) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
- .registerTypeAdapter(ISP.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
- .registerTypeAdapter(Command.class, (JsonDeserializer) (json, typeOfT, context) -> Command.fromId(json.getAsJsonPrimitive().getAsInt()))
- .registerTypeAdapter(Command.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
- .registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
- .create();
+ @Override
+ public boolean shouldSkipClass(Class> aClass) {
+ return false;
+ }
+ })
+ .registerTypeAdapter(Date.class, (JsonDeserializer) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong()))
+ .registerTypeAdapter(Date.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.getTime()))
+ .registerTypeAdapter(ISP.class, (JsonDeserializer) (json, typeOfT, context) -> ISP.fromId(json.getAsJsonPrimitive().getAsInt()))
+ .registerTypeAdapter(ISP.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
+ .registerTypeAdapter(Command.class, (JsonDeserializer) (json, typeOfT, context) -> Command.fromId(json.getAsJsonPrimitive().getAsInt()))
+ .registerTypeAdapter(Command.class, (JsonSerializer) (src, typeOfSrc, context) -> new JsonPrimitive(src.id))
+ .registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY)
+ .create();
- static {
- try {
- ic = new InitialContext();
- ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
- ds.setLoginTimeout(3);
+ static {
+ try {
+ ic = new InitialContext();
+ ds = (DataSource) ic.lookup("java:comp/env/jdbc/netsupport");
+ ds.setLoginTimeout(3);
- sr = new StandardServiceRegistryBuilder().configure().build();
- sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
+ sr = new StandardServiceRegistryBuilder().configure().build();
+ sf = new MetadataSources(sr).buildMetadata().buildSessionFactory();
- TableUser.init();
- TableOperator.init();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ TableUser.init();
+ TableOperator.init();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- public static void destroy() {
- try {
- SQLCore.sf.close();
- ((ComboPooledDataSource) SQLCore.ds).close();
- SQLCore.ic.close();
- } catch (NamingException e) {
- e.printStackTrace();
- }
- }
+ public static void destroy() {
+ try {
+ SQLCore.sf.close();
+ ((ComboPooledDataSource) SQLCore.ds).close();
+ SQLCore.ic.close();
+ } catch (NamingException e) {
+ e.printStackTrace();
+ }
+ }
- public static AuditReader getAuditReader(Session session) {
- return AuditReaderFactory.get(session);
- }
+ public static AuditReader getAuditReader(Session session) {
+ return AuditReaderFactory.get(session);
+ }
- public static class HibernateProxyTypeAdapter extends TypeAdapter {
+ public static class HibernateProxyTypeAdapter extends TypeAdapter {
- public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
- @Override
- @SuppressWarnings("unchecked")
- public TypeAdapter create(Gson gson, TypeToken type) {
- return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? (TypeAdapter) new HibernateProxyTypeAdapter(gson) : null);
- }
- };
- private final Gson context;
+ public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
+ @Override
+ @SuppressWarnings("unchecked")
+ public TypeAdapter create(Gson gson, TypeToken type) {
+ return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? (TypeAdapter) new HibernateProxyTypeAdapter(gson) : null);
+ }
+ };
+ private final Gson context;
- private HibernateProxyTypeAdapter(Gson context) {
- this.context = context;
- }
+ private HibernateProxyTypeAdapter(Gson context) {
+ this.context = context;
+ }
- @Override
- public HibernateProxy read(JsonReader in) throws IOException {
- throw new UnsupportedOperationException("Not supported");
- }
+ @Override
+ public HibernateProxy read(JsonReader in) throws IOException {
+ throw new UnsupportedOperationException("Not supported");
+ }
- @SuppressWarnings({"rawtypes", "unchecked"})
- @Override
- public void write(JsonWriter out, HibernateProxy value) throws IOException {
- if (value == null) {
- out.nullValue();
- return;
- }
- // Retrieve the original (not proxy) class
- Class> baseType = Hibernate.getClass(value);
- // Get the TypeAdapter of the original class, to delegate the serialization
- TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
- // Get a filled instance of the original class
- Object unproxiedValue = ((HibernateProxy) value).getHibernateLazyInitializer()
- .getImplementation();
- // Serialize the value
- delegate.write(out, unproxiedValue);
- }
- }
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ @Override
+ public void write(JsonWriter out, HibernateProxy value) throws IOException {
+ if (value == null) {
+ out.nullValue();
+ return;
+ }
+ // Retrieve the original (not proxy) class
+ Class> baseType = Hibernate.getClass(value);
+ // Get the TypeAdapter of the original class, to delegate the serialization
+ TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
+ // Get a filled instance of the original class
+ Object unproxiedValue = ((HibernateProxy) value).getHibernateLazyInitializer()
+ .getImplementation();
+ // Serialize the value
+ delegate.write(out, unproxiedValue);
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/sql/TableConfig.java b/src/main/java/love/sola/netsupport/sql/TableConfig.java
index 4994594..a008b5b 100644
--- a/src/main/java/love/sola/netsupport/sql/TableConfig.java
+++ b/src/main/java/love/sola/netsupport/sql/TableConfig.java
@@ -26,29 +26,29 @@ import java.sql.*;
*/
public class TableConfig extends SQLCore {
- public static final String KEY_SYS = "sys";
+ public static final String KEY_SYS = "sys";
- public static Settings getSettings() {
- try (Connection conn = ds.getConnection()) {
- Statement st = conn.createStatement();
- ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'");
- if (rs.next()) {
- return gson.fromJson(rs.getString("data"), Settings.class);
- }
- } catch (SQLException e) {
- }
- return null;
- }
+ public static Settings getSettings() {
+ try (Connection conn = ds.getConnection()) {
+ Statement st = conn.createStatement();
+ ResultSet rs = st.executeQuery("SELECT * FROM settings WHERE type='" + KEY_SYS + "'");
+ if (rs.next()) {
+ return gson.fromJson(rs.getString("data"), Settings.class);
+ }
+ } catch (SQLException e) {
+ }
+ return null;
+ }
- public static int saveSettings(Settings obj) {
- try (Connection conn = ds.getConnection()) {
- PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?");
- ps.setString(1, gson.toJson(obj));
- ps.setString(2, KEY_SYS);
- return ps.executeUpdate();
- } catch (SQLException e) {
- }
- return -1;
- }
+ public static int saveSettings(Settings obj) {
+ try (Connection conn = ds.getConnection()) {
+ PreparedStatement ps = conn.prepareStatement("UPDATE settings SET data=? WHERE type=?");
+ ps.setString(1, gson.toJson(obj));
+ ps.setString(2, KEY_SYS);
+ return ps.executeUpdate();
+ } catch (SQLException e) {
+ }
+ return -1;
+ }
}
diff --git a/src/main/java/love/sola/netsupport/sql/TableOperator.java b/src/main/java/love/sola/netsupport/sql/TableOperator.java
index 8c54f84..806ac65 100644
--- a/src/main/java/love/sola/netsupport/sql/TableOperator.java
+++ b/src/main/java/love/sola/netsupport/sql/TableOperator.java
@@ -27,35 +27,35 @@ import org.hibernate.criterion.Restrictions;
*/
public class TableOperator extends SQLCore {
- public static boolean has(String wechat) {
- try (Session s = SQLCore.sf.openSession()) {
- return (long) s.createCriteria(Operator.class)
- .add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
- .setProjection(Projections.rowCount())
- .uniqueResult() > 0;
- }
- }
+ public static boolean has(String wechat) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return (long) s.createCriteria(Operator.class)
+ .add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
+ .setProjection(Projections.rowCount())
+ .uniqueResult() > 0;
+ }
+ }
- public static Operator get(String wechat) {
- try (Session s = SQLCore.sf.openSession()) {
- return (Operator) s.createCriteria(Operator.class)
- .add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
- .uniqueResult();
- }
- }
+ public static Operator get(String wechat) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return (Operator) s.createCriteria(Operator.class)
+ .add(Restrictions.eq(Operator.PROPERTY_WECHAT, wechat))
+ .uniqueResult();
+ }
+ }
- public static Operator get(int id) {
- try (Session s = SQLCore.sf.openSession()) {
- return s.get(Operator.class, id);
- }
- }
+ public static Operator get(int id) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return s.get(Operator.class, id);
+ }
+ }
- protected static void init() {
- try (Session s = SQLCore.sf.openSession()) {
- Operator.USER_SELF = s.get(Operator.class, -1);
- Operator.ADMIN = s.get(Operator.class, 0);
- }
- }
+ protected static void init() {
+ try (Session s = SQLCore.sf.openSession()) {
+ Operator.USER_SELF = s.get(Operator.class, -1);
+ Operator.ADMIN = s.get(Operator.class, 0);
+ }
+ }
}
diff --git a/src/main/java/love/sola/netsupport/sql/TableTicket.java b/src/main/java/love/sola/netsupport/sql/TableTicket.java
index 6d4deef..60807f0 100644
--- a/src/main/java/love/sola/netsupport/sql/TableTicket.java
+++ b/src/main/java/love/sola/netsupport/sql/TableTicket.java
@@ -34,83 +34,83 @@ import java.util.List;
*/
public class TableTicket extends SQLCore {
- public static final String COLUMN_ID = "id";
- public static final String COLUMN_SID = "sid";
- public static final String COLUMN_DESC = "description";
- public static final String COLUMN_SUBMIT_TIME = "submittime";
- public static final String COLUMN_REMARK = "remark";
- public static final String COLUMN_UPDATE_TIME = "updatetime";
- public static final String COLUMN_OPSID = "opsid";
- public static final String COLUMN_STATUS = "status";
+ public static final String COLUMN_ID = "id";
+ public static final String COLUMN_SID = "sid";
+ public static final String COLUMN_DESC = "description";
+ public static final String COLUMN_SUBMIT_TIME = "submittime";
+ public static final String COLUMN_REMARK = "remark";
+ public static final String COLUMN_UPDATE_TIME = "updatetime";
+ public static final String COLUMN_OPSID = "opsid";
+ public static final String COLUMN_STATUS = "status";
- public static Ticket latestOpen(User u) {
- try (Session s = SQLCore.sf.openSession()) {
- return (Ticket) s.createCriteria(Ticket.class)
- .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
- .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
- .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
- .setMaxResults(1)
- .uniqueResult();
- }
- }
+ public static Ticket latestOpen(User u) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return (Ticket) s.createCriteria(Ticket.class)
+ .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
+ .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
+ .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
+ .setMaxResults(1)
+ .uniqueResult();
+ }
+ }
- public static Ticket latest(User u) {
- try (Session s = SQLCore.sf.openSession()) {
- return (Ticket) s.createCriteria(Ticket.class)
- .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
- .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
- .setMaxResults(1)
- .uniqueResult();
- }
- }
+ public static Ticket latest(User u) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return (Ticket) s.createCriteria(Ticket.class)
+ .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
+ .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
+ .setMaxResults(1)
+ .uniqueResult();
+ }
+ }
- public static boolean hasOpen(User u) {
- try (Session s = SQLCore.sf.openSession()) {
- return (long) s.createCriteria(Ticket.class)
- .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
- .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
- .setProjection(Projections.rowCount())
- .uniqueResult() > 0;
- }
- }
+ public static boolean hasOpen(User u) {
+ try (Session s = SQLCore.sf.openSession()) {
+ return (long) s.createCriteria(Ticket.class)
+ .add(Restrictions.eq(Ticket.PROPERTY_USER, u))
+ .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
+ .setProjection(Projections.rowCount())
+ .uniqueResult() > 0;
+ }
+ }
- @SuppressWarnings("unchecked")
- public static List unsolvedByBlock(int b) {
- if (b == 0) return unsolved();
- try (Session s = SQLCore.sf.openSession()) {
- return s.createCriteria(Ticket.class)
- .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
- .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
- .createCriteria(Ticket.PROPERTY_USER)
- .add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
- .list();
- }
- }
+ @SuppressWarnings("unchecked")
+ public static List unsolvedByBlock(int b) {
+ if (b == 0) return unsolved();
+ try (Session s = SQLCore.sf.openSession()) {
+ return s.createCriteria(Ticket.class)
+ .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
+ .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
+ .createCriteria(Ticket.PROPERTY_USER)
+ .add(Restrictions.between(User.PROPERTY_BLOCK, b * 10, (b + 1) * 10 - 1))
+ .list();
+ }
+ }
- @SuppressWarnings("unchecked")
- public static List unsolved() {
- try (Session s = SQLCore.sf.openSession()) {
- return s.createCriteria(Ticket.class)
- .createAlias(Ticket.PROPERTY_USER, "u")
- .addOrder(Order.asc("u." + User.PROPERTY_BLOCK))
- .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
- .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
- .list();
- }
- }
+ @SuppressWarnings("unchecked")
+ public static List unsolved() {
+ try (Session s = SQLCore.sf.openSession()) {
+ return s.createCriteria(Ticket.class)
+ .createAlias(Ticket.PROPERTY_USER, "u")
+ .addOrder(Order.asc("u." + User.PROPERTY_BLOCK))
+ .addOrder(Order.desc(Ticket.PROPERTY_SUBMIT_TIME))
+ .add(Restrictions.ne(Ticket.PROPERTY_STATUS, Status.SOLVED))
+ .list();
+ }
+ }
- @SuppressWarnings("unchecked")
- public static List