mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 15:45:04 +08:00
6
pom.xml
6
pom.xml
@@ -66,12 +66,6 @@
|
||||
<version>3.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -42,15 +41,19 @@ public class Cortana {
|
||||
String[] replies;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Rule {
|
||||
String[] regexp;
|
||||
String[] replies;
|
||||
|
||||
public Rule() {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RawConfig {
|
||||
Map<String, Rule> rules;
|
||||
|
||||
public RawConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,40 +17,48 @@
|
||||
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import lombok.ToString;
|
||||
import love.sola.netsupport.sql.TableConfig;
|
||||
|
||||
/**
|
||||
* @author Sola {@literal <dev@sola.love>}
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
public String Wechat_AppId;
|
||||
public String Wechat_Secret;
|
||||
public String Wechat_Token;
|
||||
public String Wechat_AesKey;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONFIGURATIONS
|
||||
// -------------------------------------------- //
|
||||
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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> T fromXml(Class<T> 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> T fromXml(Class<T> clazz, InputStream is) {
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.alias("wechat-config", clazz);
|
||||
xstream.processAnnotations(clazz);
|
||||
return (T) xstream.fromXML(is);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <dev@sola.love>}
|
||||
*/
|
||||
@EqualsAndHashCode(of = "id")
|
||||
public final class MapSession implements WxSession, Serializable {
|
||||
|
||||
@Getter
|
||||
private final String id;
|
||||
private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
|
||||
@Getter
|
||||
private long creationTime = System.currentTimeMillis();
|
||||
@Getter
|
||||
@Setter
|
||||
private long lastAccessedTime = creationTime;
|
||||
@Getter
|
||||
private boolean invalidated = false;
|
||||
private final String id;
|
||||
private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
|
||||
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> T getAttribute(String attributeName) {
|
||||
return (T) sessionAttrs.get(attributeName);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getAttribute(String attributeName) {
|
||||
return (T) sessionAttrs.get(attributeName);
|
||||
}
|
||||
|
||||
public Set<String> getAttributeNames() {
|
||||
return sessionAttrs.keySet();
|
||||
}
|
||||
public Set<String> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user