调整日志配置总量查询,整页配置只查询一次,减小资源浪费

This commit is contained in:
wangxin
2018-08-26 10:43:03 +08:00
parent 6b79b5f7ef
commit 9678a4a10f
3 changed files with 89 additions and 55 deletions

View File

@@ -25,21 +25,14 @@ public class NtcPzReport extends BaseReport<NtcPzReport>{
*/ */
private static final long serialVersionUID = 7079305499220977782L; private static final long serialVersionUID = 7079305499220977782L;
private Long configId; private Long cfgId;
private Date statTime; private Date statTime;
/**
* configId
* @return configId
*/
public Long getConfigId() { public Long getCfgId() {
return configId; return cfgId;
} }
/** public void setCfgId(Long cfgId) {
* @param configId the configId to set this.cfgId = cfgId;
*/
public void setConfigId(Long configId) {
this.configId = configId;
} }
/** /**
* statTime * statTime

View File

@@ -50,30 +50,46 @@ import net.sf.json.JsonConfig;
public class NtcPzReportController extends BaseController{ public class NtcPzReportController extends BaseController{
@RequestMapping(value="ajaxGetLogTotal",method=RequestMethod.POST) @RequestMapping(value="ajaxGetLogTotal",method=RequestMethod.POST)
@ResponseBody @ResponseBody
public Map<String, Object> ajaxGetLogTotal(Model model,long endTime,int action,Integer functionId,Integer compileId){ public List<Map<String, Object>> ajaxGetLogTotal(Model model,long endTime,String actions,Integer functionId,String compileIds){
Map<String, Object> data=new HashMap<String, Object>(); List<Map<String, Object>> dataList=new ArrayList<>();
SimpleDateFormat sdf=new SimpleDateFormat(Constants.SEARCH_DATEFORMAT); SimpleDateFormat sdf=new SimpleDateFormat(Constants.SEARCH_DATEFORMAT);
int interval=Constants.LOG_TIME_RANGE; int interval=Constants.LOG_TIME_RANGE;
Date endDate=new Date(endTime); Date endDate=new Date(endTime);
Date startDate=new Date(endTime-interval); Date startDate=new Date(endTime-interval);
int serviceId=0; String serviceIdsStr="";
StringBuffer serviceIds=new StringBuffer();
List<FunctionServiceDict> serviceList=DictUtils.getFunctionServiceDictList(functionId.intValue()); List<FunctionServiceDict> serviceList=DictUtils.getFunctionServiceDictList(functionId.intValue());
for(FunctionServiceDict service:serviceList){ for(String action:actions.split(",")) {
if(service.getAction().intValue()==action){ for(FunctionServiceDict service:serviceList){
serviceId=service.getServiceId().intValue(); if(service.getAction().intValue()==Integer.parseInt(action)){
break; serviceIds.append(service.getServiceId().intValue());
serviceIds.append(",");
}
} }
} }
data.put("compileId", compileId.intValue()); if(serviceIds.toString().endsWith(",")) {
String json=ConfigServiceUtil.getReport(Constants.BUSINESSTYPE_CONFIG, String.valueOf(compileId), String.valueOf(serviceId), sdf.format(startDate), sdf.format(endDate)); serviceIdsStr=serviceIds.toString().substring(0,serviceIds.toString().lastIndexOf(","));
}
String json=ConfigServiceUtil.getReport(Constants.BUSINESSTYPE_CONFIG, compileIds, serviceIdsStr, sdf.format(startDate), sdf.format(endDate));
List<NtcPzReport> list=getList(json); List<NtcPzReport> list=getList(json);
if(list!=null&&list.size()>0){ String[] idArr=compileIds.split(",");
data.put("sum",list.get(0).getSum().longValue()); if(list!=null&&(list.size()>0)){
for(NtcPzReport report:list) {
Map<String, Object> data=new HashMap<String, Object>();
data.put("compileId", report.getCfgId().longValue());
data.put("sum",report.getSum().longValue());
dataList.add(data);
}
}else { }else {
data.put("sum", 0); for(String id:idArr) {
Map<String, Object> data=new HashMap<String, Object>();
data.put("compileId", id);
data.put("sum",0);
dataList.add(data);
}
} }
return data; return dataList;
} }
@RequestMapping("/ntcPzReport") @RequestMapping("/ntcPzReport")
public String list(@ModelAttribute("bean") SearchReport bean,Model model, HttpServletRequest request, HttpServletResponse response) { public String list(@ModelAttribute("bean") SearchReport bean,Model model, HttpServletRequest request, HttpServletResponse response) {

View File

@@ -336,28 +336,8 @@ $(function(){
$("input[name$='exprType']:checked").each(function(){ $("input[name$='exprType']:checked").each(function(){
setDefaultMatchMethod(this); setDefaultMatchMethod(this);
}); });
/* //获取配置日志总数
*配置展示日志总数,审核通过才会调用接口查询日志总量 getTotalLog();
必须放在是否审核一列之后
并且是否审核一列的span标签需配置data-audit="xxxx"属性
xxxx可用值为createdapprovedunapprovedcancel
td需要配置属性有functionIdcompileIdaction
*/
$("td[compileId]").each(function(){
var audit=$(this).attr("audit");
if(audit == 1){
var data={};
data.date=new Date();
data.compileId=$(this).attr("compileId");
data.action=$(this).attr("action");
data.functionId=$(this).attr("functionId");
data.audit=$(this).attr("audit");
data.obj=$(this)
GetLogTotal(data);
}else{
$(this).html("0");
}
});
$(".action").on("change", function() { $(".action").on("change", function() {
$("#serviceId").val($(this).attr("serviceId")); $("#serviceId").val($(this).attr("serviceId"));
$("#protocolId").val($(this).attr("protocolId")); $("#protocolId").val($(this).attr("protocolId"));
@@ -1116,32 +1096,77 @@ var viewAreaInfo=function(path,areaEffectiveIds,compileId){
}); });
} }
var getTotalLog=function(){
var GetLogTotal=function(data){ /*
td需要配置属性有audit,functionIdcompileIdaction
*/
var data={};
data.date=new Date();
data.compileIds=[];
data.actions=[];
data.objs=[];
$("td[compileId]").each(function(){
var audit=$(this).attr("audit");
var compileId=$(this).attr("compileId");
var action=$(this).attr("action");
var functionId=$(this).attr("functionId");
if(audit&&compileId&&action&&functionId){
if(audit == 1){
var has=false;
for(var i=0;i<data.actions.length;i++){
if(data.actions[i]==$(this).attr("action")){
has=true;
}
}
if(!has){
data.actions.push($(this).attr("action"));
}
data.compileIds.push($(this).attr("compileId"));
data.functionId=$(this).attr("functionId");
data.objs.push($(this));
}else{
$(this).html("0");
}
}
});
if(data.compileIds.length>0){
GetLogTotal(data);
}
}
var GetLogTotal=function(_data){
var pathName=window.document.location.pathname.substring(0,window.document.location.pathname.indexOf("/nis")+4); var pathName=window.document.location.pathname.substring(0,window.document.location.pathname.indexOf("/nis")+4);
var timeStamp=0; var timeStamp=0;
if(data.date){ if(_data.date){
timeStamp=data.date.valueOf(); timeStamp=_data.date.valueOf();
}else{ }else{
timeStamp=(new Date()).valueOf(); timeStamp=(new Date()).valueOf();
} }
var totalTr=$(data.obj); var totalTrs=$(_data.objs);
var timeout=$.validator.messages.timeout; var timeout=$.validator.messages.timeout;
var request=$.ajax({ var request=$.ajax({
type:'post', type:'post',
timeout:10000,//超时时间设置,查询接口时间过长超时 timeout:10000,//超时时间设置,查询接口时间过长超时
url:pathName+'/report/ajaxGetLogTotal', url:pathName+'/report/ajaxGetLogTotal',
data:{"endTime":timeStamp,"action":data.action,"functionId":data.functionId,"compileId":data.compileId}, data:{"endTime":timeStamp,"actions":_data.actions.join(','),"functionId":_data.functionId,"compileIds":_data.compileIds.join(',')},
dataType:'json', dataType:'json',
async:true, async:true,
success:function(data,textStatus){//处理返回结果 success:function(data,textStatus){//处理返回结果
if(textStatus=="success"){ if(textStatus=="success"){
totalTr.html(data.sum); totalTrs.each(function(){
for(var i=0;i<data.length;i++){
if($(this).attr("compileId")==data[i].compileId){
$(this).html(data[i].sum);
}
}
})
} }
}, },
complete:function(XMLHttpRequest,status){//超时设置 complete:function(XMLHttpRequest,status){//超时设置
if(status=="timeout"){ if(status=="timeout"){
totalTr.html(timeout); totalTrs.each(function(){
$(this).html(timeout);
})
} }
} }
}); });