mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-11-01 02:46:19 +08:00 
			
		
		
		
	ticket push
This commit is contained in:
		| @@ -36,14 +36,12 @@ public class Response { | ||||
| 		PARAMETER_REQUIRED(-1), | ||||
| 		ILLEGAL_PARAMETER(-2), | ||||
| 		REQUEST_FAILED(-3), | ||||
| 		AUTHORIZE_FAILED(-9), | ||||
| 		LENGTH_LIMIT_EXCEEDED(-4), | ||||
| 		USER_NOT_FOUND(-11), | ||||
| 		TICKET_NOT_FOUND(-12), | ||||
| 		OPERATOR_NOT_FOUND(-13), | ||||
| 		UNAUTHORIZED(-20), | ||||
| 		REQUEST_EXPIRED(-21), | ||||
| 		WRONG_PASSWORD(-22), | ||||
| 		INCORRECT_WECHAT(-23), | ||||
| 		PERMISSION_DENIED(-24), | ||||
| 		INTERNAL_ERROR(-90), | ||||
| 		DATABASE_ERROR(-91), | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package love.sola.netsupport.api; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import love.sola.netsupport.config.Settings; | ||||
| import love.sola.netsupport.enums.Attribute; | ||||
| import love.sola.netsupport.pojo.Ticket; | ||||
| import love.sola.netsupport.pojo.User; | ||||
| @@ -51,6 +52,9 @@ public class TicketSubmit extends HttpServlet { | ||||
| 		if (desc == null || desc.isEmpty()) { | ||||
| 			return new Response(Response.ResponseCode.PARAMETER_REQUIRED); | ||||
| 		} | ||||
| 		if (desc.length() > Settings.MAX_DESC_LENGTH) { | ||||
| 			return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED); | ||||
| 		} | ||||
|  | ||||
| 		try (Session s = SQLCore.sf.openSession()) { | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,93 @@ | ||||
| package love.sola.netsupport.api.admin.root; | ||||
|  | ||||
| import com.google.gson.Gson; | ||||
| import love.sola.netsupport.api.Response; | ||||
| import love.sola.netsupport.config.Settings; | ||||
| import love.sola.netsupport.enums.Access; | ||||
| import love.sola.netsupport.enums.Attribute; | ||||
| import love.sola.netsupport.enums.Status; | ||||
| import love.sola.netsupport.pojo.Operator; | ||||
| import love.sola.netsupport.pojo.Ticket; | ||||
| import love.sola.netsupport.pojo.User; | ||||
| import love.sola.netsupport.sql.SQLCore; | ||||
| import love.sola.netsupport.util.Checker; | ||||
| import love.sola.netsupport.util.ParseUtil; | ||||
| import love.sola.netsupport.wechat.Command; | ||||
| import me.chanjar.weixin.common.session.WxSession; | ||||
| import org.hibernate.HibernateException; | ||||
| import org.hibernate.Session; | ||||
|  | ||||
| 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/22. | ||||
|  * Don't modify this source without my agreement | ||||
|  * *********************************************** | ||||
|  */ | ||||
| @WebServlet(name = "TicketPush",urlPatterns = "/api/admin/ticketpush",loadOnStartup = 44) | ||||
| public class TicketPush extends HttpServlet{ | ||||
|  | ||||
| 	private Gson gson = SQLCore.gson; | ||||
|  | ||||
| 	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"); | ||||
| 		PrintWriter out = response.getWriter(); | ||||
| 		String json = gson.toJson(push(request)); | ||||
| 		out.println(ParseUtil.parseJsonP(request, json)); | ||||
| 		out.close(); | ||||
| 	} | ||||
|  | ||||
| 	private Response push(HttpServletRequest request) { | ||||
| 		String uid = request.getParameter("uid"); | ||||
| 		String desc = request.getParameter("desc"); | ||||
| 		if (Checker.hasNull(uid, desc)) { | ||||
| 			return new Response(Response.ResponseCode.PARAMETER_REQUIRED); | ||||
| 		} | ||||
| 		if (desc.length() > Settings.MAX_DESC_LENGTH) { | ||||
| 			return new Response(Response.ResponseCode.LENGTH_LIMIT_EXCEEDED); | ||||
| 		} | ||||
|  | ||||
| 		WxSession session = Checker.isAuthorized(request, Command.LOGIN); | ||||
| 		if (session == null) { | ||||
| 			return new Response(Response.ResponseCode.UNAUTHORIZED); | ||||
| 		} | ||||
| 		Operator op = (Operator) session.getAttribute(Attribute.OPERATOR); | ||||
| 		if (op.getAccess() > Access.LEADER) { | ||||
| 			return new Response(Response.ResponseCode.PERMISSION_DENIED); | ||||
| 		} | ||||
|  | ||||
| 		try (Session s = SQLCore.sf.openSession()) { | ||||
| 			s.beginTransaction(); | ||||
| 			User u = s.get(User.class, Long.parseLong(uid)); | ||||
| 			if (u == null) { | ||||
| 				return new Response(Response.ResponseCode.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 new Response(Response.ResponseCode.OK, t); | ||||
| 		} catch (NumberFormatException e) { | ||||
| 			return new Response(Response.ResponseCode.ILLEGAL_PARAMETER); | ||||
| 		} catch (HibernateException e) { | ||||
| 			e.printStackTrace(); | ||||
| 			return new Response(Response.ResponseCode.DATABASE_ERROR, e.getMessage()); | ||||
| 		} catch (Exception e) { | ||||
| 			e.printStackTrace(); | ||||
| 			return new Response(Response.ResponseCode.INTERNAL_ERROR, e.getMessage()); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola