// Path: src/main/java/love/sola/netsupport/sql/TableUser.java
// @SuppressWarnings("Duplicates")
// public class TableUser extends SQLCore {
// 
//     public static final String COLUMN_ID = "id";
//     public static final String COLUMN_NAME = "name";
//     public static final String COLUMN_ISP = "isp";
//     public static final String COLUMN_NET_ACCOUNT = "netaccount";
//     public static final String COLUMN_WECHAT = "wechat";
//     public static final String COLUMN_BLOCK = "block";
//     public static final String COLUMN_ROOM = "room";
//     public static final String COLUMN_PHONE = "phone";
// 
//     public static User getById(long id) {
//         try (Session s = sf.openSession()) {
//             return s.get(User.class, id);
//         }
//     }
// 
//     public static User getByName(String name) {
//         try (Session s = sf.openSession()) {
//             return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
//         }
//     }
// 
//     public static User getByWechat(String wechat) {
//         try {
//             User u = cache.get(wechat);
//             return u == NULL_USER ? null : u;
//         } catch (ExecutionException e) {
//             e.printStackTrace();
//             return null;
//         }
//     }
// 
//     public static int update(User user) {
//         try (Session s = sf.openSession()) {
//             s.beginTransaction();
//             s.update(user);
//             s.getTransaction().commit();
//             cache.put(user.getWechatId(), user);
//             return 1;
//         }
//     }
// 
//     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);
//         }
//     }
// 
//     private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
//             .concurrencyLevel(4)
//             .maximumSize(4096)
//             .expireAfterAccess(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
//             .build(new ValueLoader());
// 
//     private static class ValueLoader extends CacheLoader<String, User> {
//         @Override
//         public User load(String key) throws Exception {
//             User u = TableUser.getByWechat0(key);
//             return u == null ? NULL_USER : u;
//         }
//     }
// 
//     private static final User NULL_USER = new User();
// 
//     public static void flushCache() {
//         cache.invalidateAll();
//     }
// 
//     private static User getByWechat0(String wechat) {
//         try (Session s = sf.openSession()) {
//             return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
//         }
//     }
// 
// }


import love.sola.netsupport.sql.TableUser;
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
/*
 * This file is part of WechatTicketSystem.
 *
 * WechatTicketSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WechatTicketSystem is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with WechatTicketSystem.  If not, see <http://www.gnu.org/licenses/>.
 */

package love.sola.netsupport.wechat.matcher;


/**
 * @author Sola {@literal <dev@sola.love>}
 */
public class RegisterMatcher implements WxMpMessageMatcher {

    @Override
    public boolean match(WxMpXmlMessage message) {
// Path: src/main/java/love/sola/netsupport/sql/TableUser.java
// @SuppressWarnings("Duplicates")
// public class TableUser extends SQLCore {
// 
//     public static final String COLUMN_ID = "id";
//     public static final String COLUMN_NAME = "name";
//     public static final String COLUMN_ISP = "isp";
//     public static final String COLUMN_NET_ACCOUNT = "netaccount";
//     public static final String COLUMN_WECHAT = "wechat";
//     public static final String COLUMN_BLOCK = "block";
//     public static final String COLUMN_ROOM = "room";
//     public static final String COLUMN_PHONE = "phone";
// 
//     public static User getById(long id) {
//         try (Session s = sf.openSession()) {
//             return s.get(User.class, id);
//         }
//     }
// 
//     public static User getByName(String name) {
//         try (Session s = sf.openSession()) {
//             return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_NAME, name)).uniqueResult();
//         }
//     }
// 
//     public static User getByWechat(String wechat) {
//         try {
//             User u = cache.get(wechat);
//             return u == NULL_USER ? null : u;
//         } catch (ExecutionException e) {
//             e.printStackTrace();
//             return null;
//         }
//     }
// 
//     public static int update(User user) {
//         try (Session s = sf.openSession()) {
//             s.beginTransaction();
//             s.update(user);
//             s.getTransaction().commit();
//             cache.put(user.getWechatId(), user);
//             return 1;
//         }
//     }
// 
//     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);
//         }
//     }
// 
//     private static LoadingCache<String, User> cache = CacheBuilder.newBuilder()
//             .concurrencyLevel(4)
//             .maximumSize(4096)
//             .expireAfterAccess(Settings.I.User_Wechat_Cache_Expire_Time, TimeUnit.SECONDS)
//             .build(new ValueLoader());
// 
//     private static class ValueLoader extends CacheLoader<String, User> {
//         @Override
//         public User load(String key) throws Exception {
//             User u = TableUser.getByWechat0(key);
//             return u == null ? NULL_USER : u;
//         }
//     }
// 
//     private static final User NULL_USER = new User();
// 
//     public static void flushCache() {
//         cache.invalidateAll();
//     }
// 
//     private static User getByWechat0(String wechat) {
//         try (Session s = sf.openSession()) {
//             return (User) s.createCriteria(User.class).add(Restrictions.eq(User.PROPERTY_WECHAT, wechat)).uniqueResult();
//         }
//     }
// 
// }


// Path: src/main/java/love/sola/netsupport/wechat/matcher/RegisterMatcher.java
import love.sola.netsupport.sql.TableUser;
import me.chanjar.weixin.mp.api.WxMpMessageMatcher;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;

/*
 * This file is part of WechatTicketSystem.
 *
 * WechatTicketSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WechatTicketSystem is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with WechatTicketSystem.  If not, see <http://www.gnu.org/licenses/>.
 */

package love.sola.netsupport.wechat.matcher;


/**
 * @author Sola {@literal <dev@sola.love>}
 */
public class RegisterMatcher implements WxMpMessageMatcher {

    @Override
    public boolean match(WxMpXmlMessage message) {
        return TableUser.getByWechat(message.getFromUserName()) == null;