页面跳转:
//正版化统计列表
public String listUI() {
List<Software> softwares = softwareService.queryAll();//注意我要获取的是software表的数据
List<Software> softwareList = new ArrayList<Software>();
if(softwares != null){
for(Software gsnm : softwares){
Software gm = new Software();
gm.setSoftName(gsnm.getSoftName());
gm.setSoftId(gsnm.getSoftId());
softwareList.add(gm);//获取software表的数据存储到softwareList中,然后传给前台
}
}
getRequest().setAttribute("softwareList", softwareList);
return "listUI";
}
后台逻辑处理:
public void list() {
try {
HQLBuilderUtil hql = new HQLBuilderUtil(Software.class);//注意要是获取到Software的page数据,此处需是Software.class
if(software!=null && software.getSoftId()!=null && !"".equals(software.getSoftId())){
Integer softId = software.getSoftId();
hql.addWhereClause(" this.softId=? ", softId);
}
Integer pcCount = pcInfoService.queryAll().size();//PC总数
GridData<Software> reportlogs = softwareService.getPageView(hql, getPageNum(), getPageSize());//获取到Software的page数据
List<Software> list = reportlogs.getRows();
for (int i = 0; i < list.size(); i++) {
//取安装数
Integer installCount = genuineManagementStaticService.queryInstallNum(list.get(i).getSoftId());
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String result = numberFormat.format((float) installCount / (float) pcCount * 100) + "%";
list.get(i).setInstallNum(installCount);
list.get(i).setInstallPersent(result);
//取正版数
Integer genuine = 1;
Integer genuineCount = genuineManagementStaticService.queryGenuineNum(genuine, list.get(i).getSoftId());
Integer softCount = genuineManagementStaticService.querySoftNum(list.get(i).getSoftId());
NumberFormat numberFormatGenuine = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String genuineResult = numberFormatGenuine.format((float) genuineCount / (float) softCount * 100) + "%";
list.get(i).setGenuineNum(genuineCount);
list.get(i).setGenuinePersent(genuineResult);
//取最新版本
GenuineManagementStatic gms = genuineManagementStaticService.queryNewVersion(list.get(i).getSoftId());
list.get(i).setVersion(gms.getVersion());
}
print(ActionUtil.jsonObj(reportlogs));
} catch (Exception e) {
e.printStackTrace();
GridData<Software> soft = new GridData<Software>();
soft.setRows(null);
soft.setTotal(0);
print(ActionUtil.jsonObj(soft));
}
}
我们再看一下几个dao层的查询方法:
@Override
public Integer queryInstallNum(Integer softId) {
return Integer.parseInt(getSession().createSQLQuery(" select count(1) from vrv_paw_genuineManagementStatic a,vrv_paw_pcinfo b where a.pcInfoId=b.id and softId=:softId")
.setParameter("softId", softId)
.list().get(0).toString());
};
@Override
public Integer queryGenuineNum(Integer matchResult, Integer softId) {
return Integer.parseInt(getSession().createSQLQuery(" select count(1) from vrv_paw_genuineManagementStatic where matchResult=:matchResult and softId=:softId ")
.setParameter("matchResult", matchResult)
.setParameter("softId", softId)
.list().get(0).toString());
}
@Override
public Integer querySoftNum(Integer softId) {
return Integer.parseInt(getSession().createSQLQuery(" select count(1) from vrv_paw_genuineManagementStatic where softId=:softId ")
.setParameter("softId", softId)
.list().get(0).toString());
}
//获取softId为某个的软件的总数
@SuppressWarnings("unchecked")
@Override
public GenuineManagementStatic queryNewVersion(Integer softId) {
List<GenuineManagementStatic> list = getSession().createQuery(" from " + this.clazz.getName() + " this WHERE this.softId=:softId order by version desc LIMIT 0,1")
.setParameter("softId", softId)
.list();
if (list.size() > 0) {
return list.get(0);
}
return null;
}
上面这个方法,就需要查看下此篇博客深入学习下:unexpected token: * 和 java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to 解决办法