mirror of
				https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
				synced 2025-10-31 10:26: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()); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -12,6 +12,8 @@ import love.sola.netsupport.sql.TableConfig; | ||||
| @ToString | ||||
| public class Settings { | ||||
|  | ||||
| 	public static final int MAX_DESC_LENGTH = 255; | ||||
|  | ||||
| 	public static Settings I; | ||||
|  | ||||
| 	static { | ||||
| @@ -29,8 +31,6 @@ public class Settings { | ||||
| 	public int Check_Spam_Cache_Expire_Time; | ||||
| 	public int Check_Spam_Interval; | ||||
|  | ||||
| 	public int User_Caching_Time; | ||||
|  | ||||
| 	public int User_Session_Max_Inactive; | ||||
|  | ||||
| 	//No arg constructor for Yaml.loadAs | ||||
|   | ||||
| @@ -15,6 +15,14 @@ import static love.sola.netsupport.config.Lang.lang; | ||||
| public class Access { | ||||
|  | ||||
| 	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 NOLOGIN = 9; | ||||
|  | ||||
| 	public static final Map<Integer, String> inverseMap = new HashMap<>(); | ||||
|   | ||||
| @@ -42,4 +42,10 @@ public class User { | ||||
| 	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; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -76,6 +76,7 @@ public class SQLCore { | ||||
| 			sr = new StandardServiceRegistryBuilder().configure().build(); | ||||
| 			sf = new MetadataSources(sr).buildMetadata().buildSessionFactory(); | ||||
|  | ||||
| 			TableUser.init(); | ||||
| 			TableOperator.init(); | ||||
| 		} catch (Exception e) { | ||||
| 			e.printStackTrace(); | ||||
|   | ||||
| @@ -50,4 +50,12 @@ public class TableUser extends SQLCore { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	protected static void init() { | ||||
| 		try (Session s = SQLCore.sf.openSession()) { | ||||
| 			User.OFFICIAL_CHINA_UNICOM_XH = s.get(User.class, 100104L); | ||||
| 			User.OFFICIAL_CHINA_MOBILE_XH = s.get(User.class, 100864L); | ||||
| 			User.OFFICIAL_CHINA_MOBILE_FX = s.get(User.class, 100865L); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sola
					Sola