use of cn.cerc.jdb.mysql.SqlQuery in project summer-mis by cn-cerc.
the class SvrUserLoginTest method test_sendVerifyCode.
@Test
@Ignore(value = "此处用于测试在5分钟内不允许重复申请验证码,耗时很长")
public void test_sendVerifyCode() throws InterruptedException, DataValidateException {
String corpNo = "911001";
String userCode = "91100123";
String deviceId = "TEST";
try (StubHandle handle = new StubHandle(corpNo, userCode)) {
// 清空缓存
try (MemoryBuffer buff = new MemoryBuffer(BufferType.getObject, handle.getUserCode(), SvrUserLogin.class.getName(), "sendVerifyCode")) {
buff.clear();
}
// 检查验证码是否存在
SqlQuery ds = new SqlQuery(handle);
ds.add("select * from %s", SystemTable.get(SystemTable.getDeviceVerify));
ds.add("where CorpNo_='%s'", corpNo);
ds.add("and UserCode_='%s'", userCode);
ds.add("and MachineCode_='%s'", deviceId);
ds.open();
String msg = String.format("帐号 %s 验证码 %s 不存在,无法完成测试", userCode, deviceId);
assertThat(msg, ds.eof(), is(false));
SvrUserLogin app = new SvrUserLogin();
app.init(handle);
app.getDataIn().getHead().setField("deviceId", deviceId);
assertThat(app.sendVerifyCode(), is(true));
Thread.sleep(1000 * 30);
try {
app.sendVerifyCode();
assertThat("此处不应该执行到", false, is(true));
} catch (Exception e) {
e.printStackTrace();
assertThat(e.getMessage().indexOf("5 分钟") > 0, is(true));
}
Thread.sleep(1000 * 60 * SvrUserLogin.TimeOut);
assertThat(app.sendVerifyCode(), is(true));
}
}
use of cn.cerc.jdb.mysql.SqlQuery in project summer-mis by cn-cerc.
the class DirectoryTest method WriteLine.
private int WriteLine(String text) {
if (text.length() > 150) {
System.err.println(text);
return 0;
}
SqlQuery dsLang = new SqlQuery(handle);
dsLang.add("select * from %s", SystemTable.getLanguage);
dsLang.add("where key_='%s' and lang_='en'", text);
dsLang.open();
if (dsLang.eof()) {
System.out.println(text);
dsLang.append();
dsLang.setField("key_", Utils.safeString(text));
dsLang.setField("lang_", "en");
dsLang.setField("value_", "");
dsLang.setField("supportAndroid_", false);
dsLang.setField("supportIphone_", false);
dsLang.setField("enable_", true);
dsLang.setField("updateUser_", handle.getUserCode());
dsLang.setField("updateDate_", TDateTime.Now());
dsLang.setField("createUser_", handle.getUserCode());
dsLang.setField("createDate_", TDateTime.Now());
dsLang.post();
return 1;
}
return 0;
}
use of cn.cerc.jdb.mysql.SqlQuery in project summer-bean by cn-cerc.
the class BookOptions method getBookCreateDate.
// 从系统帐套中取开帐日期
private static TDate getBookCreateDate(IHandle handle) {
BuildQuery f = new BuildQuery(handle);
String corpNo = handle.getCorpNo();
f.byField("CorpNo_", corpNo);
f.add("select AppDate_ from %s", SystemTable.get(SystemTable.getBookInfo));
SqlQuery ds = f.open();
if (ds.size() == 0)
throw new RuntimeException(String.format("没有找到帐套:%s", corpNo));
return ds.getDate("AppDate_");
}
use of cn.cerc.jdb.mysql.SqlQuery 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));
}
use of cn.cerc.jdb.mysql.SqlQuery in project summer-bean by cn-cerc.
the class AppSessionRestore method byUserCode.
public boolean byUserCode() throws ServiceException, UserNotFindException {
Record headIn = getDataIn().getHead();
DataValidateException.stopRun("用户id不允许为空", !headIn.hasValue("userCode"));
String userCode = headIn.getString("userCode");
SqlQuery cdsUser = new SqlQuery(this);
cdsUser.add("select ID_,Code_,RoleCode_,DiyRole_,CorpNo_, Name_ as UserName_,ProxyUsers_");
cdsUser.add("from %s ", SystemTable.get(SystemTable.getUserInfo));
cdsUser.add("where Code_= '%s' ", userCode);
cdsUser.open();
if (cdsUser.eof()) {
throw new UserNotFindException(userCode);
}
Record headOut = getDataOut().getHead();
headOut.setField("LoginTime_", TDateTime.Now());
copyData(cdsUser, headOut);
return true;
}
Aggregations