public Page queryTerminalForPage(String subMerid,String terminalBeginNo,String terminalEndNo, int start, int pageSize)
throws BusiException, Exception {
if (StringUtil.isNullorEmpty(subMerid)) {
throw new BusiException("获取工单的终端的时,分店id不能为空!");
}
Criteria criteria = taskDao.createCriteria(TM03Terminal.class);
CriteriaUtil.add(criteria, terminalBeginNo, "terminalNo", Operation.GE);
CriteriaUtil.add(criteria, terminalEndNo, "terminalNo", Operation.LE);
criteria.add(Restrictions.eq("submerId", subMerid));
Page page = taskDao.queryCriteriaForPage(criteria, start, pageSize);
if (page != null) {
String getDevice = "select twt121.model ||','||twt121.SERIAL_NO||'&;'||twt122.model ||'," +
"'||twt122.SERIAL_NO||'&;'||twt123.model ||','||twt123.SERIAL_NO" +
"||'&;'||twt124.model ||','||twt124.SERIAL_NO||'&;'||twt125.model ||','||twt125.SERIAL_NO " +
"from t_m03_terminal tm03 " +
"left join t_wt10_device twt121 on twt121.terminal_id = tm03.id and twt121.device_type = 0 " + //--主机
"left join t_wt10_device twt122 on twt122.terminal_id = tm03.id and twt122.device_type = 1 " + //-- 密码键盘
"left join t_wt10_device twt123 on twt123.terminal_id = tm03.id and twt123.device_type = 2 " + //--手写板
"left join t_wt10_device twt124 on twt124.terminal_id = tm03.id and twt124.device_type = 3 " +//--SIM卡
"left join t_wt10_device twt125 on twt125.terminal_id = tm03.id and twt125.device_type = 4 " +//--读卡器
"where tm03.id = '%s'";
List<TM03Terminal> termList = (List<TM03Terminal>) page.getResult();
if (termList != null && termList.size() > 0) {
for (TM03Terminal m03 : termList) {
String deviceString = StringUtil.getString(taskDao.findBySql(String.format(getDevice,m03.getId())));
String [] resultDevice = deviceString.split("&;");
m03.setViDevice0(resultDevice[0]);
m03.setViDevice1(resultDevice[1]);
m03.setViDevice2(resultDevice[2]);
m03.setViDevice3(resultDevice[3]);
m03.setViDevice4(resultDevice[4]);
virtualField.setViTM03Terminal(m03);
}
}
}
return page;
}
然后:在数据库里执行的语句:
select
*
from
( select
twt121.model ||','||twt121.SERIAL_NO||'&;'||twt122.model ||','||twt122.SERIAL_NO||'&;'||twt123.model ||','||twt123.SERIAL_NO||'&;'||twt124.model ||','||twt124.SERIAL_NO||'&;'||twt125.model ||','||twt125.SERIAL_NO
from
t_m03_terminal tm03
left join
t_wt10_device twt121
on twt121.terminal_id = tm03.id
and twt121.device_type = 0
left join
t_wt10_device twt122
on twt122.terminal_id = tm03.id
and twt122.device_type = 1
left join
t_wt10_device twt123
on twt123.terminal_id = tm03.id
and twt123.device_type = 2
left join
t_wt10_device twt124
on twt124.terminal_id = tm03.id
and twt124.device_type = 3
left join
t_wt10_device twt125
on twt125.terminal_id = tm03.id
and twt125.device_type = 4
where
tm03.id = '4028b2d251c239830151c351bf1000c4')