项目笔记:统计页面功能实现
2023-09-11 14:19:55 时间
页面跳转:
//正版化统计列表
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";
}
前台页面如此获取:
<select id="querys_softName" name="genuineManagementStatic.softName" style="width:208px;">
<s:if test="#request.softwareList != null">
<s:iterator value="#request.softwareList">
<option softId='<s:property value="#request.softId" />' value='<s:property value="#request.softName" />'><s:property value="#request.softName" /></option>
</s:iterator>
</s:if>
</select>
后台逻辑处理:
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 解决办法
正版数(需要涉及子查询)和最新版本查询修改(最新版本要类型转换cast(version as integer))
//新的正版数逻辑
@Override
public Integer queryGenuineNumNew(Integer matchResult, Integer genuine, Integer softId) {
return Integer.parseInt(getSession().createSQLQuery(" select count(distinct softId,version,pcInfoId) from vrv_paw_genuineManagementStatic "
+ "where (softId,version,pcInfoId) not in(select softId,version,pcInfoId from vrv_paw_genuineManagementStatic where matchResult=:matchResult and softId=:softId)"
+ "and matchResult=:genuine "
+ "and softId=:softId ")
.setParameter("matchResult", matchResult)
.setParameter("genuine", genuine)
.setParameter("softId", softId)
.list().get(0).toString());
}
@Override
public GenuineManagementStatic queryNewVersion(Integer softId) {
List<GenuineManagementStatic> list = getSession().createQuery(" from " + this.clazz.getName() + " this WHERE this.softId=:softId order by cast(version as integer) desc LIMIT 0,1")
.setParameter("softId", softId)
.list();
if (list.size() > 0) {
return list.get(0);
}
return null;
}
关于正版数新逻辑查询,请查看这篇文章,说明的比较清楚:从项目上一个子查询扩展学习开来:mysql的查询、子查询及连接查询
相关文章
- 使用R进行分组统计
- ≪统计学习精要(The Elements of Statistical Learning)≫课堂笔记(一)
- Android Studio 统计项目的代码总行数(转载)
- (纪录片)统计的乐趣 The Joy of Stats (2010)
- SAP CDS view源代码行数统计工具
- Atitit 项目分析与统计目录1. 静态分析+动态分析 。其中, 12. 模块分析,与模块位置idx 13. 编程语言类型与版本 13.1. 类库统记表 类型与版本 23.2. 中间
- Atitit.Gui按钮与面板---项目规模的评估----文件数统计,结构,代码行数,每类型文件行数.
- ZZNUOJ_用C语言编写程序实现1180:成绩统计(结构体专题)(附完整源码)
- Excel:Excel使用技巧经验总结之(利用Excel自带功能统计各个字段不同类别及其个数并进行图表可视化+非编程实现)图文教程之详细攻略
- 通过localStorage实现页面的访问量的统计
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- 习题 5.9 有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。
- 主要是解决,作为一个数据共享的数据库,存在的数据库统计,然后将计算的数据量输出到自己使用的数据库,进行主页面展示。
- mysql根据分组和条件查询以后如何统计记录的条数
- Elkeid 规则引擎——数据向后传递是亮点,支持单事件规则和统计类规则;如果向后传递支持的话,理论上AB先后事件的关联分析可以做;自定义plugin类似udf
- MATLAB教室数据统计项目