mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 23:55:04 +08:00
improve operator converting
This commit is contained in:
@@ -109,7 +109,7 @@ public class Register extends HttpServlet {
|
|||||||
return "Duplicated_" + dupKey.toUpperCase(); // PHONE ACCOUNT WECHAT
|
return "Duplicated_" + dupKey.toUpperCase(); // PHONE ACCOUNT WECHAT
|
||||||
}
|
}
|
||||||
// FIXME: 2015/12/30 Temporary converter
|
// FIXME: 2015/12/30 Temporary converter
|
||||||
converter(user);
|
converterWithRetry(user);
|
||||||
return "Register_Success";
|
return "Register_Success";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,27 +119,17 @@ public class Register extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void converter(User u) {
|
public static void converterWithRetry(User u) {
|
||||||
try (Connection conn = SQLCore.ds.getConnection()) {
|
Throwable last = null;
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM `convert` WHERE id=?");
|
for (int i = 0; i < 3; i++) {
|
||||||
ps.setLong(1, u.getId());
|
try {
|
||||||
ResultSet rs = ps.executeQuery();
|
converter(u);
|
||||||
if (rs.next()) {
|
|
||||||
String old = rs.getString(1);
|
|
||||||
ps = conn.prepareStatement("UPDATE `operators` SET wechat=? WHERE wechat=?");
|
|
||||||
ps.setString(1, u.getWechatId());
|
|
||||||
ps.setString(2, old);
|
|
||||||
ps.executeUpdate();
|
|
||||||
WxMpServlet.instance.wxMpService
|
|
||||||
.userUpdateGroup(u.getWechatId(), 100L);
|
|
||||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换成功").build());
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
|
} catch (WxErrorException | SQLException e) {
|
||||||
|
last = e;
|
||||||
}
|
}
|
||||||
} catch (SQLException | WxErrorException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
last.printStackTrace();
|
||||||
try {
|
try {
|
||||||
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换失败").build());
|
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换失败").build());
|
||||||
} catch (WxErrorException e) {
|
} catch (WxErrorException e) {
|
||||||
@@ -147,4 +137,27 @@ public class Register extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void converter(User u) throws WxErrorException, SQLException {
|
||||||
|
try (Connection conn = SQLCore.ds.getConnection()) {
|
||||||
|
PreparedStatement ps = conn.prepareStatement("SELECT wechat FROM `convert` WHERE id=?");
|
||||||
|
ps.setLong(1, u.getId());
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
WxMpServlet.instance.wxMpService
|
||||||
|
.userUpdateGroup(u.getWechatId(), 100L);
|
||||||
|
String old = rs.getString(1);
|
||||||
|
ps = conn.prepareStatement("UPDATE `operators` SET wechat=? WHERE wechat=?");
|
||||||
|
ps.setString(1, u.getWechatId());
|
||||||
|
ps.setString(2, old);
|
||||||
|
if (ps.executeUpdate() == 1) {
|
||||||
|
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("数据转换成功").build());
|
||||||
|
} else {
|
||||||
|
WxMpServlet.instance.wxMpService.customMessageSend(WxMpCustomMessage.TEXT().toUser(u.getWechatId()).content("已进行过数据转换").build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException | WxErrorException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class WxMpServlet extends HttpServlet {
|
|||||||
.msgType(WxConsts.XML_MSG_EVENT)
|
.msgType(WxConsts.XML_MSG_EVENT)
|
||||||
.event(WxConsts.EVT_SUBSCRIBE)
|
.event(WxConsts.EVT_SUBSCRIBE)
|
||||||
.handler(new SubscribeHandler())
|
.handler(new SubscribeHandler())
|
||||||
.next();
|
.end();
|
||||||
wxMpMessageRouter.rule()
|
wxMpMessageRouter.rule()
|
||||||
.async(false)
|
.async(false)
|
||||||
.matcher(new CheckSpamMatcher())
|
.matcher(new CheckSpamMatcher())
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package love.sola.netsupport.wechat.handler;
|
package love.sola.netsupport.wechat.handler;
|
||||||
|
|
||||||
|
import love.sola.netsupport.api.user.Register;
|
||||||
import love.sola.netsupport.enums.Attribute;
|
import love.sola.netsupport.enums.Attribute;
|
||||||
import love.sola.netsupport.pojo.User;
|
import love.sola.netsupport.pojo.User;
|
||||||
import love.sola.netsupport.sql.TableUser;
|
import love.sola.netsupport.sql.TableUser;
|
||||||
@@ -38,6 +39,7 @@ public class SubscribeHandler implements WxMpMessageHandler {
|
|||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
session.setAttribute(Attribute.USER, u);
|
session.setAttribute(Attribute.USER, u);
|
||||||
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
out.content(format("Event_Subscribe", format("Already_Registered", format("User_Profile_Link", id, u.getName(), u.getIsp().id, u.getNetAccount(), u.getBlock(), u.getRoom(), u.getPhone()))));
|
||||||
|
Register.converterWithRetry(u);
|
||||||
} else {
|
} else {
|
||||||
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
session.setAttribute(Attribute.AUTHORIZED, Command.REGISTER);
|
||||||
session.setAttribute(Attribute.WECHAT, fromUser);
|
session.setAttribute(Attribute.WECHAT, fromUser);
|
||||||
@@ -45,4 +47,5 @@ public class SubscribeHandler implements WxMpMessageHandler {
|
|||||||
}
|
}
|
||||||
return out.build();
|
return out.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user