delombok phase 2

Signed-off-by: Sola <dev@sola.love>
This commit is contained in:
Sola
2017-12-15 08:52:49 +08:00
parent c97faf5994
commit 4737957043
7 changed files with 202 additions and 180 deletions

View File

@@ -66,12 +66,6 @@
<version>3.1.0</version> <version>3.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@@ -39,34 +39,34 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public class TicketPush extends API { public class TicketPush extends API {
public TicketPush() { public TicketPush() {
url = "/admin/ticketpush"; url = "/admin/ticketpush";
access = Access.LEADER; access = Access.LEADER;
authorize = Command.LOGIN; authorize = Command.LOGIN;
} }
@Override @Override
protected Object process(HttpServletRequest req, WxSession session) throws Exception { protected Object process(HttpServletRequest req, WxSession session) throws Exception {
String uid = req.getParameter("uid"); String uid = req.getParameter("uid");
String desc = req.getParameter("desc"); String desc = req.getParameter("desc");
if (Checker.hasNull(uid, desc)) { if (Checker.hasNull(uid, desc)) {
return Error.PARAMETER_REQUIRED; return Error.PARAMETER_REQUIRED;
} }
if (desc.length() > Settings.MAX_DESC_LENGTH) { if (desc.length() > Settings.MAX_DESC_LENGTH) {
return Error.LENGTH_LIMIT_EXCEEDED; return Error.LENGTH_LIMIT_EXCEEDED;
} }
Operator op = session.getAttribute(Attribute.OPERATOR); Operator op = session.getAttribute(Attribute.OPERATOR);
try (Session s = SQLCore.sf.openSession()) { try (Session s = SQLCore.sf.openSession()) {
s.beginTransaction(); s.beginTransaction();
User u = s.get(User.class, Long.parseLong(uid)); User u = s.get(User.class, Long.parseLong(uid));
if (u == null) { if (u == null) {
return Error.USER_NOT_FOUND; return Error.USER_NOT_FOUND;
} }
Ticket t = new Ticket(null, u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED); Ticket t = new Ticket(u, desc, null, "Pushed By Admin", null, op, Status.UNCHECKED);
s.save(t); s.save(t);
s.getTransaction().commit(); s.getTransaction().commit();
return t; return t;
} }
} }
} }

View File

@@ -41,64 +41,62 @@ import java.util.Date;
*/ */
public class ToolsCheck extends API { public class ToolsCheck extends API {
public ToolsCheck() { public ToolsCheck() {
url = "/admin/toolscheck"; url = "/admin/toolscheck";
access = Access.MEMBER; access = Access.MEMBER;
authorize = Command.LOGIN; authorize = Command.LOGIN;
} }
@Override @Override
protected Object process(HttpServletRequest req, WxSession session) throws Exception { protected Object process(HttpServletRequest req, WxSession session) throws Exception {
if (req.getMethod().equals("GET")) { if (req.getMethod().equals("GET")) {
return query(req, session); return query(req, session);
} else if (req.getMethod().equals("POST")) { } else if (req.getMethod().equals("POST")) {
return submit(req, session); return submit(req, session);
} }
return null; return null;
} }
private Object submit(HttpServletRequest req, WxSession session) { private Object submit(HttpServletRequest req, WxSession session) {
Operator op = session.getAttribute(Attribute.OPERATOR); Operator op = session.getAttribute(Attribute.OPERATOR);
int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0")); int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
String remark = req.getParameter("remark"); String remark = req.getParameter("remark");
if (status != 0 && StringUtils.isBlank(remark)) { if (status != 0 && StringUtils.isBlank(remark)) {
return Error.PARAMETER_REQUIRED; return Error.PARAMETER_REQUIRED;
} }
try (Session s = SQLCore.sf.openSession()) { try (Session s = SQLCore.sf.openSession()) {
s.beginTransaction(); s.beginTransaction();
s.save(new love.sola.netsupport.pojo.ToolsCheck( s.save(new love.sola.netsupport.pojo.ToolsCheck(
null, op,
op, op.getBlock(),
op.getBlock(), new Date(),
new Date(), status,
status, remark
remark ));
) s.getTransaction().commit();
); return Error.OK;
s.getTransaction().commit(); }
return Error.OK; }
}
}
private Object query(HttpServletRequest req, WxSession session) { private Object query(HttpServletRequest req, WxSession session) {
int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0")); int status = Integer.valueOf(getParameterWithDefault(req.getParameter("status"), "0"));
Date after = getDay(getParameterAsDate(req.getParameter("after"), getToday())); Date after = getDay(getParameterAsDate(req.getParameter("after"), getToday()));
Date before = getDay(getParameterAsDate(req.getParameter("before"), getToday())); Date before = getDay(getParameterAsDate(req.getParameter("before"), getToday()));
before = DateUtils.addDays(before, 1); before = DateUtils.addDays(before, 1);
int block = Integer.valueOf(getParameterWithDefault(req.getParameter("block"), "0")); int block = Integer.valueOf(getParameterWithDefault(req.getParameter("block"), "0"));
try (Session s = SQLCore.sf.openSession()) { try (Session s = SQLCore.sf.openSession()) {
Criteria query = s.createCriteria(love.sola.netsupport.pojo.ToolsCheck.class); Criteria query = s.createCriteria(love.sola.netsupport.pojo.ToolsCheck.class);
query.add( query.add(
Restrictions.sqlRestriction( Restrictions.sqlRestriction(
"{alias}.status & ? = ?", "{alias}.status & ? = ?",
new Object[]{status, status}, new Object[]{status, status},
new Type[]{IntegerType.INSTANCE, IntegerType.INSTANCE} new Type[]{IntegerType.INSTANCE, IntegerType.INSTANCE}
) )
); );
query.add(Restrictions.between("checkTime", after, before)); query.add(Restrictions.between("checkTime", after, before));
if (block != 0) query.add(Restrictions.eq("block", block)); if (block != 0) query.add(Restrictions.eq("block", block));
return query.list(); return query.list();
} }
} }
} }

View File

@@ -17,7 +17,6 @@
package love.sola.netsupport.config; package love.sola.netsupport.config;
import lombok.Data;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.InputStream; import java.io.InputStream;
@@ -42,15 +41,19 @@ public class Cortana {
String[] replies; String[] replies;
} }
@Data
public static class Rule { public static class Rule {
String[] regexp; String[] regexp;
String[] replies; String[] replies;
public Rule() {
}
} }
@Data
public static class RawConfig { public static class RawConfig {
Map<String, Rule> rules; Map<String, Rule> rules;
public RawConfig() {
}
} }
} }

View File

@@ -17,40 +17,48 @@
package love.sola.netsupport.config; package love.sola.netsupport.config;
import lombok.ToString;
import love.sola.netsupport.sql.TableConfig; import love.sola.netsupport.sql.TableConfig;
/** /**
* @author Sola {@literal <dev@sola.love>} * @author Sola {@literal <dev@sola.love>}
*/ */
@ToString
public class Settings { 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 { static {
I = TableConfig.getSettings(); I = TableConfig.getSettings();
} }
// -------------------------------------------- // public String Wechat_AppId;
// CONFIGURATIONS public String Wechat_Secret;
// -------------------------------------------- // public String Wechat_Token;
public String Wechat_AppId; public String Wechat_AesKey;
public String Wechat_Secret;
public String Wechat_Token;
public String Wechat_AesKey;
public int Check_Spam_Cache_Expire_Time; public int Check_Spam_Cache_Expire_Time;
public int Check_Spam_Interval; public int Check_Spam_Interval;
public int User_Session_Max_Inactive; public int User_Session_Max_Inactive;
public int User_Wechat_Cache_Expire_Time; public int User_Wechat_Cache_Expire_Time;
//No arg constructor for Yaml.loadAs //No arg constructor for Yaml.loadAs
public Settings() { public Settings() {
I = this; 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 +
'}';
}
} }

View File

@@ -19,7 +19,6 @@ package love.sola.netsupport.config;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.ToString;
import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
@@ -29,15 +28,14 @@ import java.io.InputStream;
* @author chanjarster * @author chanjarster
*/ */
@XStreamAlias("wechat-config") @XStreamAlias("wechat-config")
@ToString
public class WxMpXmlInMemoryConfigStorage extends WxMpInMemoryConfigStorage { public class WxMpXmlInMemoryConfigStorage extends WxMpInMemoryConfigStorage {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T fromXml(Class<T> clazz, InputStream is) { public static <T> T fromXml(Class<T> clazz, InputStream is) {
XStream xstream = XStreamInitializer.getInstance(); XStream xstream = XStreamInitializer.getInstance();
xstream.alias("wechat-config", clazz); xstream.alias("wechat-config", clazz);
xstream.processAnnotations(clazz); xstream.processAnnotations(clazz);
return (T) xstream.fromXML(is); return (T) xstream.fromXML(is);
} }
} }

View File

@@ -32,74 +32,95 @@
*/ */
package love.sola.netsupport.session; package love.sola.netsupport.session;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
/** /**
* @author Sola {@literal <dev@sola.love>} * @author Sola {@literal <dev@sola.love>}
*/ */
@EqualsAndHashCode(of = "id")
public final class MapSession implements WxSession, Serializable { public final class MapSession implements WxSession, Serializable {
@Getter private final String id;
private final String id; private Map<String, Object> sessionAttrs = new HashMap<String, Object>();
private Map<String, Object> sessionAttrs = new HashMap<String, Object>(); private long creationTime = System.currentTimeMillis();
@Getter private long lastAccessedTime = creationTime;
private long creationTime = System.currentTimeMillis(); private boolean invalidated = false;
@Getter
@Setter
private long lastAccessedTime = creationTime;
@Getter
private boolean invalidated = false;
/** /**
* Creates a new instance with a secure randomly generated identifier. * Creates a new instance with a secure randomly generated identifier.
*/ */
public MapSession() { public MapSession() {
this(UUID.randomUUID().toString()); this(UUID.randomUUID().toString());
} }
/** /**
* Creates a new instance with the specified id. This is preferred to the * 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 * default constructor when the id is known to prevent unnecessary consumption on
* entropy which can be slow. * entropy which can be slow.
* *
* @param id the identifier to use * @param id the identifier to use
*/ */
public MapSession(String id) { public MapSession(String id) {
this.id = id; this.id = id;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getAttribute(String attributeName) { public <T> T getAttribute(String attributeName) {
return (T) sessionAttrs.get(attributeName); return (T) sessionAttrs.get(attributeName);
} }
public Set<String> getAttributeNames() { public Set<String> getAttributeNames() {
return sessionAttrs.keySet(); return sessionAttrs.keySet();
} }
public void setAttribute(String attributeName, Object attributeValue) { public void setAttribute(String attributeName, Object attributeValue) {
if (attributeValue == null) { if (attributeValue == null) {
removeAttribute(attributeName); removeAttribute(attributeName);
} else { } else {
sessionAttrs.put(attributeName, attributeValue); sessionAttrs.put(attributeName, attributeValue);
} }
} }
public void removeAttribute(String attributeName) { public void removeAttribute(String attributeName) {
sessionAttrs.remove(attributeName); sessionAttrs.remove(attributeName);
} }
public void invalidate() { public void invalidate() {
invalidated = true; 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);
}
} }