Search in sources :

Example 1 with SqlSession

use of cn.cerc.jdb.mysql.SqlSession in project summer-mis by cn-cerc.

the class TaskTrackCurrentUser method execute.

@Override
public void execute() {
    // 清理在线用户记录表
    SqlSession conn = (SqlSession) handle.getProperty(SqlSession.sessionId);
    // 删除超过100天的登录记录
    StringBuffer sql1 = new StringBuffer();
    sql1.append(String.format("delete from %s where datediff(now(),LoginTime_)>100", SystemTable.getCurrentUser));
    conn.execute(sql1.toString());
    // 清除所有未正常登录的用户记录
    StringBuffer sql2 = new StringBuffer();
    sql2.append(String.format("update %s set Viability_=-1 ", SystemTable.getCurrentUser));
    // 在线达24小时以上的用户
    sql2.append("where (Viability_>0) and (");
    sql2.append("(hour(timediff(now(),LoginTime_)) > 24 and LogoutTime_ is null)");
    // 在早上5点以后,清除昨天的用户
    if (TDateTime.Now().getHours() > 5) {
        sql2.append(" or (datediff(now(),LoginTime_)=1)");
    }
    // 已登出超过4小时的用户
    sql2.append(" or (hour(timediff(now(),LogoutTime_)) > 4)");
    sql2.append(")");
    conn.execute(sql2.toString());
}
Also used : SqlSession(cn.cerc.jdb.mysql.SqlSession)

Example 2 with SqlSession

use of cn.cerc.jdb.mysql.SqlSession in project summer-bean by cn-cerc.

the class UserList method changeCorpNo.

/*
     * 切换帐号到指定的公司别
     */
public void changeCorpNo(IHandle handle, String corpNo, String userCode, String roleCode) throws UserNotFindException {
    String buffKey = String.format("%d.%s.%s.%d", BufferType.getObject.ordinal(), corpNo, this.getClass().getName(), Version);
    Application.getMemcache().delete(buffKey);
    SqlQuery ds = new SqlQuery(handle);
    ds.add("select ID_ from %s where Code_='%s'", SystemTable.get(SystemTable.getUserInfo), userCode);
    ds.open();
    if (ds.eof())
        throw new UserNotFindException(userCode);
    SqlSession conn = (SqlSession) handle.getProperty(SqlSession.sessionId);
    String sql = String.format("update %s set CorpNo_='%s',ShareAccount_=1 where Code_='%s'", SystemTable.get(SystemTable.getUserInfo), corpNo, userCode);
    conn.execute(sql);
    sql = String.format("update %s set Name_='%s' where UserCode_='%s' and Code_='GroupCode'", SystemTable.get(SystemTable.getUserOptions), roleCode, userCode);
    conn.execute(sql);
    log.info(String.format("%s 已被切换到 corpNo=%s, roleCode=%s", userCode, corpNo, roleCode));
}
Also used : SqlQuery(cn.cerc.jdb.mysql.SqlQuery) SqlSession(cn.cerc.jdb.mysql.SqlSession)

Aggregations

SqlSession (cn.cerc.jdb.mysql.SqlSession)2 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)1