mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
ticket submit api
This commit is contained in:
@@ -65,6 +65,7 @@ public class Authorize extends HttpServlet {
|
||||
case REGISTER:
|
||||
break;
|
||||
case QUERY:
|
||||
case SUBMIT:
|
||||
User u = TableUser.getUserByWechat(wechat);
|
||||
if (u == null) return new Response(Response.ResponseCode.AUTHORIZE_FAILED);
|
||||
request.getSession(true).setAttribute("user", u);
|
||||
|
||||
@@ -35,6 +35,7 @@ public class GetUser extends HttpServlet {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
|
||||
@@ -4,6 +4,7 @@ import love.sola.netsupport.enums.Block;
|
||||
import love.sola.netsupport.enums.ISP;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.TableUser;
|
||||
import love.sola.netsupport.util.Redirect;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
@@ -12,8 +13,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
import static love.sola.netsupport.config.Lang.lang;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/11/29.
|
||||
@@ -26,7 +25,6 @@ public class Register extends HttpServlet {
|
||||
public static final String STUDENT_ID_REGEX = "^(2010|2012|2013|2014|2015)[0-9]{9}$";
|
||||
public static final String PHONE_NUMBER_REGEX = "^1[34578][0-9]{9}$";
|
||||
|
||||
public static final String REDIRECT_PAGE = "http://topaz.sinaapp.com/nm/result.html";
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
@@ -35,7 +33,7 @@ public class Register extends HttpServlet {
|
||||
|
||||
String wechat = checkWechat(request.getParameter("wechatid"), request);
|
||||
if (wechat == null) {
|
||||
response.sendRedirect(response.encodeRedirectURL(REDIRECT_PAGE + "?msg=Illegal_Request&type=1"));
|
||||
Redirect.message(response, 0, "Illegal_Request");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,12 +49,7 @@ public class Register extends HttpServlet {
|
||||
checkPhoneNumber(request.getParameter("phone")),
|
||||
wechat
|
||||
);
|
||||
response.sendRedirect(
|
||||
response.encodeRedirectURL(REDIRECT_PAGE +
|
||||
"?msg=" + result + "" +
|
||||
"&type=" + (result.equals("Register_Success") ? 1 : 0)
|
||||
)
|
||||
);
|
||||
Redirect.message(response, result.equals("Register_Success") ? 1 : 0, result);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@@ -64,12 +57,7 @@ public class Register extends HttpServlet {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||
response.sendRedirect(
|
||||
response.encodeRedirectURL(REDIRECT_PAGE +
|
||||
"?msg=" + lang("Illegal_Request") +
|
||||
"&type=-1"
|
||||
)
|
||||
);
|
||||
Redirect.message(response, -1, "Illegal_Request");
|
||||
}
|
||||
|
||||
private String register(long sid, String name, ISP isp, String netAccount, Block block, int room, long phone, String wechat) {
|
||||
|
||||
@@ -33,6 +33,7 @@ public class Response {
|
||||
|
||||
public enum ResponseCode {
|
||||
|
||||
ALREADY_SUBMITTED(1),
|
||||
OK(0),
|
||||
PARAMETER_REQUIRED(-1),
|
||||
ILLEGAL_PARAMETER(-2),
|
||||
|
||||
@@ -25,8 +25,8 @@ import java.io.PrintWriter;
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "QueryTicket", urlPatterns = "/api/querytickets", loadOnStartup = 23)
|
||||
public class QueryTicket extends HttpServlet {
|
||||
@WebServlet(name = "QueryTicket", urlPatterns = "/api/ticketquery", loadOnStartup = 23)
|
||||
public class TicketQuery extends HttpServlet {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
@@ -34,6 +34,7 @@ public class QueryTicket extends HttpServlet {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
@@ -63,11 +64,11 @@ public class QueryTicket extends HttpServlet {
|
||||
int limit = request.getParameter("limit") == null ? 5 : Integer.parseInt(request.getParameter("limit"));
|
||||
c.setFirstResult(first);
|
||||
c.setMaxResults(limit);
|
||||
c.add(Restrictions.eq("sid", u.getId()));
|
||||
c.add(Restrictions.eq(Ticket.PROPERTY_USER, u));
|
||||
if (request.getParameter("status") != null) {
|
||||
c.add(Restrictions.eq("status", Integer.parseInt(request.getParameter("status"))));
|
||||
c.add(Restrictions.eq(Ticket.PROPERTY_STATUS, Integer.parseInt(request.getParameter("status"))));
|
||||
} else if (request.getParameter("statusl") != null && request.getParameter("statush") != null) {
|
||||
c.add(Restrictions.between("status",
|
||||
c.add(Restrictions.between(Ticket.PROPERTY_STATUS,
|
||||
Integer.parseInt(request.getParameter("statusl")),
|
||||
Integer.parseInt(request.getParameter("statush"))
|
||||
));
|
||||
88
src/main/java/love/sola/netsupport/api/TicketSubmit.java
Normal file
88
src/main/java/love/sola/netsupport/api/TicketSubmit.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package love.sola.netsupport.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import love.sola.netsupport.pojo.Ticket;
|
||||
import love.sola.netsupport.pojo.User;
|
||||
import love.sola.netsupport.sql.SQLCore;
|
||||
import love.sola.netsupport.util.JsonP;
|
||||
import love.sola.netsupport.util.Redirect;
|
||||
import love.sola.netsupport.wechat.Command;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.criterion.Projections;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/6.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
@WebServlet(name = "TicketSubmit", urlPatterns = "/api/ticketsubmit", loadOnStartup = 23)
|
||||
public class TicketSubmit extends HttpServlet {
|
||||
|
||||
private Gson gson = SQLCore.gson;
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/json;charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String json = gson.toJson(submit(request));
|
||||
out.println(JsonP.parse(request, json));
|
||||
out.close();
|
||||
}
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.addHeader("Content-type", "text/plain;charset=utf-8");
|
||||
Redirect.message(response, -1, "Illegal_Request");
|
||||
}
|
||||
|
||||
private Response submit(HttpServletRequest request) {
|
||||
try (Session s = SQLCore.sf.openSession()) {
|
||||
if (request.getSession() == null || request.getSession().getAttribute("authorized") != Command.SUBMIT) {
|
||||
return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
}
|
||||
User u = (User) request.getSession().getAttribute("user");
|
||||
if (u == null) return new Response(Response.ResponseCode.UNAUTHORIZED);
|
||||
int n = (int) s.createCriteria(Ticket.class)
|
||||
.add(Restrictions.eq(Ticket.PROPERTY_USER, u))
|
||||
.add(Restrictions.eq(Ticket.PROPERTY_STATUS, 0))
|
||||
.setProjection(Projections.rowCount())
|
||||
.uniqueResult();
|
||||
if (n > 0) {
|
||||
return new Response(Response.ResponseCode.ALREADY_SUBMITTED);
|
||||
}
|
||||
String desc = request.getParameter("desc");
|
||||
if (desc == null) {
|
||||
return new Response(Response.ResponseCode.PARAMETER_REQUIRED);
|
||||
}
|
||||
Ticket t = new Ticket();
|
||||
t.setUser(u);
|
||||
t.setDescription(desc);
|
||||
t.setStatus(0);
|
||||
s.beginTransaction();
|
||||
s.save(t);
|
||||
s.getTransaction().commit();
|
||||
return new Response(Response.ResponseCode.OK, t);
|
||||
} catch (NumberFormatException e) {
|
||||
return new Response(Response.ResponseCode.ILLEGAL_PARAMETER);
|
||||
} catch (HibernateException e) {
|
||||
return new Response(Response.ResponseCode.DATABASE_ERROR);
|
||||
} catch (Exception e) {
|
||||
return new Response(Response.ResponseCode.INTERNAL_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package love.sola.netsupport.pojo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import love.sola.netsupport.sql.TableTicket;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
@@ -20,19 +21,23 @@ import java.util.Date;
|
||||
@Table(name = "tickets")
|
||||
public class Ticket {
|
||||
|
||||
public static final String PROPERTY_USER = "user";
|
||||
public static final String PROPERTY_STATUS = "status";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
private Integer id;
|
||||
@ManyToOne(optional = false)
|
||||
@JoinColumn(name = "sid")
|
||||
@JoinColumn(name = TableTicket.COLUMN_SID)
|
||||
private User user;
|
||||
private String description;
|
||||
@Column(name = TableTicket.COLUMN_SUBMIT_TIME, insertable = false)
|
||||
private Date submitTime;
|
||||
private String remark;
|
||||
private Date updateTime;
|
||||
@ManyToOne(optional = true)
|
||||
@JoinColumn(name = "opsid")
|
||||
@JoinColumn(name = TableTicket.COLUMN_OPSID)
|
||||
private User operator;
|
||||
private int status;
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class User {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", updatable = false, nullable = false)
|
||||
private long id;
|
||||
private Long id;
|
||||
@Column(name = "name", updatable = false, nullable = false)
|
||||
private String name;
|
||||
@Convert(converter = ISPConverter.class)
|
||||
|
||||
20
src/main/java/love/sola/netsupport/sql/TableTicket.java
Normal file
20
src/main/java/love/sola/netsupport/sql/TableTicket.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package love.sola.netsupport.sql;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/6.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
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";
|
||||
|
||||
}
|
||||
25
src/main/java/love/sola/netsupport/util/Redirect.java
Normal file
25
src/main/java/love/sola/netsupport/util/Redirect.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package love.sola.netsupport.util;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* Created by Sola on 2015/12/6.
|
||||
* Don't modify this source without my agreement
|
||||
* ***********************************************
|
||||
*/
|
||||
public class Redirect {
|
||||
|
||||
public static final String REDIRECT_PAGE = "http://topaz.sinaapp.com/nm/result.html";
|
||||
|
||||
public static void message(HttpServletResponse response, int type, String message) throws IOException {
|
||||
response.sendRedirect(
|
||||
response.encodeRedirectURL(REDIRECT_PAGE +
|
||||
"?msg=" + message +
|
||||
"&type=" + type
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public enum Command {
|
||||
|
||||
REGISTER(0, ".*"),
|
||||
QUERY(1, "Query"),
|
||||
SUBMIT(1, "Submit"),
|
||||
;
|
||||
|
||||
private static final Map<Integer, Command> ID_MAP = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user