1.定时去统计界面和服务端的配置量入库,并新增系统管理-管理员用户预警界面列表的功能
2.实时扫描此表中界面和服务端的配置量是否一致,不一致,管理员用户告警提示
This commit is contained in:
92
src/main/java/com/nis/domain/SysUserWarn.java
Normal file
92
src/main/java/com/nis/domain/SysUserWarn.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.nis.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
public class SysUserWarn {
|
||||
|
||||
private String serviceId; //业务Id
|
||||
private String serviceDesc;//业务描述
|
||||
private Integer interfaceCfgTotal;//界面配置数量
|
||||
|
||||
private Integer systemCfgTotal;//服务端配置数量
|
||||
|
||||
private Date time;//时间
|
||||
private String remark;//备注
|
||||
|
||||
private Integer id;//serviceID
|
||||
private String tableName;//表名
|
||||
/**
|
||||
* 当前实体分页对象
|
||||
*/
|
||||
protected Page<SysUserWarn> page;
|
||||
|
||||
public String getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
public void setServiceId(String serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
public String getServiceDesc() {
|
||||
return serviceDesc;
|
||||
}
|
||||
public void setServiceDesc(String serviceDesc) {
|
||||
this.serviceDesc = serviceDesc;
|
||||
}
|
||||
public Integer getInterfaceCfgTotal() {
|
||||
return interfaceCfgTotal;
|
||||
}
|
||||
public void setInterfaceCfgTotal(Integer interfaceCfgTotal) {
|
||||
this.interfaceCfgTotal = interfaceCfgTotal;
|
||||
}
|
||||
public Integer getSystemCfgTotal() {
|
||||
return systemCfgTotal;
|
||||
}
|
||||
public void setSystemCfgTotal(Integer systemCfgTotal) {
|
||||
this.systemCfgTotal = systemCfgTotal;
|
||||
}
|
||||
public Date getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(Date time) {
|
||||
this.time = time;
|
||||
}
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
@JsonIgnore
|
||||
@XmlTransient
|
||||
public Page<SysUserWarn> getPage() {
|
||||
if (page == null){
|
||||
page = new Page<SysUserWarn>();
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public Page<SysUserWarn> setPage(Page<SysUserWarn> page) {
|
||||
this.page = page;
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
46
src/main/java/com/nis/domain/SysUserWarnData.java
Normal file
46
src/main/java/com/nis/domain/SysUserWarnData.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.nis.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SysUserWarnData {
|
||||
|
||||
private Map<String,List<String>> effective;
|
||||
private Integer effectiveCount;
|
||||
private Map<String,List<String>> obsolete;
|
||||
private Integer obsoleteCount;
|
||||
|
||||
|
||||
public Map<String, List<String>> getEffective() {
|
||||
return effective;
|
||||
}
|
||||
public void setEffective(Map<String, List<String>> effective) {
|
||||
this.effective = effective;
|
||||
}
|
||||
public Integer getEffectiveCount() {
|
||||
return effectiveCount;
|
||||
}
|
||||
public void setEffectiveCount(Integer effectiveCount) {
|
||||
this.effectiveCount = effectiveCount;
|
||||
}
|
||||
public Map<String, List<String>> getObsolete() {
|
||||
return obsolete;
|
||||
}
|
||||
public void setObsolete(Map<String, List<String>> obsolete) {
|
||||
this.obsolete = obsolete;
|
||||
}
|
||||
public Integer getObsoleteCount() {
|
||||
return obsoleteCount;
|
||||
}
|
||||
public void setObsoleteCount(Integer obsoleteCount) {
|
||||
this.obsoleteCount = obsoleteCount;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserWarnData [effective=" + effective + ", effectiveCount=" + effectiveCount + ", obsolete="
|
||||
+ obsolete + ", obsoleteCount=" + obsoleteCount + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
67
src/main/java/com/nis/domain/SysUserWarnRecvData.java
Normal file
67
src/main/java/com/nis/domain/SysUserWarnRecvData.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.nis.domain;
|
||||
|
||||
public class SysUserWarnRecvData {
|
||||
private Integer status;
|
||||
private Integer businessCode;
|
||||
private String reason;
|
||||
private String msg;
|
||||
private String fromuri;
|
||||
private String logSource;
|
||||
private String traceCode;
|
||||
private SysUserWarnData data;
|
||||
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
public Integer getBusinessCode() {
|
||||
return businessCode;
|
||||
}
|
||||
public void setBusinessCode(Integer businessCode) {
|
||||
this.businessCode = businessCode;
|
||||
}
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
public String getFromuri() {
|
||||
return fromuri;
|
||||
}
|
||||
public void setFromuri(String fromuri) {
|
||||
this.fromuri = fromuri;
|
||||
}
|
||||
public String getLogSource() {
|
||||
return logSource;
|
||||
}
|
||||
public void setLogSource(String logSource) {
|
||||
this.logSource = logSource;
|
||||
}
|
||||
public String getTraceCode() {
|
||||
return traceCode;
|
||||
}
|
||||
public void setTraceCode(String traceCode) {
|
||||
this.traceCode = traceCode;
|
||||
}
|
||||
public SysUserWarnData getData() {
|
||||
return data;
|
||||
}
|
||||
public void setData(SysUserWarnData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -834,4 +834,8 @@ public final class Constants {
|
||||
* 配置保护名单字典key
|
||||
*/
|
||||
public static final String CACHE_PROTECTION_LIST_DICT = "protetionListDict";
|
||||
/**
|
||||
* 管理员用户预警查询服务配置总量接口
|
||||
*/
|
||||
public static final String CONFIG_BY_SERVICE = Configurations.getStringProperty("getConfigByService","");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.nis.domain.SysUserWarn;
|
||||
import com.nis.domain.SysUserWarnData;
|
||||
import com.nis.domain.SysUserWarnRecvData;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.ServiceConfigTemplateUtil;
|
||||
import com.nis.util.httpclient.HttpClientUtil;
|
||||
import com.nis.web.service.SysUserWarnService;
|
||||
/**
|
||||
* 定时查询 界面配置总量和 服务配置总量 并添加到 sys_user_warn表中
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class StatisticSysUserWarnNumber {
|
||||
|
||||
private Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
|
||||
@Autowired
|
||||
protected SysUserWarnService sysUserWarnService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
|
||||
public void insertTotalInfo() {
|
||||
logger.info("定时统计业务号的界面配置总量和服务配置总量-开始。。。。。。。。。。。。。。");
|
||||
long start=System.currentTimeMillis();
|
||||
//获取界面配置的所有业务信息
|
||||
List<Map<String, Object>> serviceList = ServiceConfigTemplateUtil.getServiceList();
|
||||
getSysData(serviceList);
|
||||
long end=System.currentTimeMillis();
|
||||
logger.info("定时统计业务号的界面配置总量和服务配置总量-结束:"+(end-start)+"。。。。。。。。。。。。。。");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void getSysData(List<Map<String, Object>> serviceList){
|
||||
//调用服务端接口,查询所有业务服务端的配置总量
|
||||
try{
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("service", -1);
|
||||
String url = Constants.SERVICE_URL + Constants.CONFIG_BY_SERVICE;
|
||||
String recv = HttpClientUtil.getMsg(url, params, request);
|
||||
if (StringUtils.isNotBlank(recv)) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
SysUserWarnRecvData fromJson = gson.fromJson(recv, new TypeToken<SysUserWarnRecvData>() {
|
||||
}.getType());
|
||||
if (fromJson.getStatus().intValue() == 200) {
|
||||
SysUserWarnData data = fromJson.getData();
|
||||
Map<String, List<String>> effective = data.getEffective();
|
||||
List<SysUserWarn> listTotal =new ArrayList<SysUserWarn>();
|
||||
for (Map<String, Object> map1 : serviceList) {
|
||||
SysUserWarn entity=new SysUserWarn();
|
||||
entity.setId(Integer.parseInt(map1.get("id").toString()));
|
||||
entity.setTableName(map1.get("tableName").toString());
|
||||
//根据serviceID和表名查询界面各个业务的配置数量
|
||||
Integer cfgCount = sysUserWarnService.getCfgCount(entity);
|
||||
//查询服务端的各个业务的配置数量
|
||||
List<String> list = effective.get(map1.get("id"));
|
||||
SysUserWarn sysUserWarn=new SysUserWarn();
|
||||
sysUserWarn.setServiceId(map1.get("id").toString());
|
||||
sysUserWarn.setServiceDesc(map1.get("desc").toString());
|
||||
if(cfgCount>0){
|
||||
sysUserWarn.setInterfaceCfgTotal(cfgCount);
|
||||
}else{
|
||||
sysUserWarn.setInterfaceCfgTotal(0);
|
||||
}
|
||||
if(list !=null && list.size()>0){
|
||||
sysUserWarn.setSystemCfgTotal(list.size());
|
||||
}else {
|
||||
sysUserWarn.setSystemCfgTotal(0);
|
||||
}
|
||||
sysUserWarn.setTime(new Date());
|
||||
listTotal.add(sysUserWarn);
|
||||
}
|
||||
//判断表中是否有数据
|
||||
Integer total = sysUserWarnService.getAllInfoCount();
|
||||
if(total !=null && total>0){//说明有数据 先删除 后添加
|
||||
sysUserWarnService.deleteAllData();
|
||||
sysUserWarnService.insert(listTotal);
|
||||
}else{// 没有 直接 添加
|
||||
sysUserWarnService.insert(listTotal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch(Exception e) {
|
||||
logger.error("更新所有业务的配置数量失败", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.nis.web.controller.sys;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.SysUserWarn;
|
||||
import com.nis.util.ServiceConfigTemplateUtil;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.service.SysUserWarnService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/sys/warn")
|
||||
public class SysUserWarnController extends BaseController{
|
||||
|
||||
@Autowired
|
||||
protected SysUserWarnService sysUserWarnService;
|
||||
|
||||
|
||||
|
||||
@RequiresPermissions("sys:warnList:view")
|
||||
@RequestMapping(value = {"userWarnList", ""})
|
||||
public String list(@ModelAttribute("warn") SysUserWarn warn, Model model,HttpServletRequest request
|
||||
,HttpServletResponse response) {
|
||||
Page<SysUserWarn> pageCondition = new Page<SysUserWarn>(request, response,"r");
|
||||
Properties msgProp = getMsgProp();
|
||||
Page<SysUserWarn> page = sysUserWarnService.getAllList(pageCondition,warn,msgProp);
|
||||
model.addAttribute("warn", warn);
|
||||
model.addAttribute("page", page);
|
||||
return "/sys/sysUserWarnList";
|
||||
}
|
||||
|
||||
@RequiresPermissions("sys:warnList:view")
|
||||
@ResponseBody
|
||||
@RequestMapping(value = {"serviceSum", ""})
|
||||
public SysUserWarn findServiceSum() {
|
||||
SysUserWarn findServiceSum = sysUserWarnService.findServiceSum();
|
||||
return findServiceSum;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
List<Map<String, Object>> serviceList = ServiceConfigTemplateUtil.getServiceList();
|
||||
System.out.println(serviceList);
|
||||
for (Map<String, Object> map : serviceList) {
|
||||
System.out.println(map.get("id"));
|
||||
System.out.println(map.get("tableName"));
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/main/java/com/nis/web/dao/SysUserWarnDao.java
Normal file
22
src/main/java/com/nis/web/dao/SysUserWarnDao.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.nis.web.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.nis.domain.SysUserWarn;
|
||||
|
||||
@MyBatisDao
|
||||
public interface SysUserWarnDao extends CrudDao<SysUserWarn>{
|
||||
|
||||
//查询所有的数据
|
||||
public List<SysUserWarn> getAllList(SysUserWarn entity);
|
||||
//查询总的记录数
|
||||
public Integer getAllInfoCount();
|
||||
//查询 所有数据中界面总量 和 服务总量
|
||||
public SysUserWarn getAllSum(SysUserWarn entity);
|
||||
//根据serviceID和表名查询业务配置的数量
|
||||
public Integer getCfgCount(SysUserWarn entity);
|
||||
//新增
|
||||
public int insert(List<SysUserWarn> list);
|
||||
//删除所有的数据
|
||||
public int deleteAllData();
|
||||
}
|
||||
91
src/main/java/com/nis/web/dao/SysUserWarnDao.xml
Normal file
91
src/main/java/com/nis/web/dao/SysUserWarnDao.xml
Normal file
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.nis.web.dao.SysUserWarnDao" >
|
||||
<resultMap id="SysUserWarnMap" type="com.nis.domain.SysUserWarn" >
|
||||
<result column="service_id" property="serviceId" jdbcType="VARCHAR" />
|
||||
<result column="service_desc" property="serviceDesc" jdbcType="VARCHAR" />
|
||||
<result column="interface_cfg_total" property="interfaceCfgTotal" jdbcType="INTEGER" />
|
||||
<result column="system_cfg_total" property="systemCfgTotal" jdbcType="INTEGER" />
|
||||
<result column="time" property="time" jdbcType="TIMESTAMP" />
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR" />
|
||||
</resultMap>
|
||||
|
||||
<select id="getAllList" parameterType="com.nis.domain.SysUserWarn" resultMap="SysUserWarnMap">
|
||||
|
||||
SELECT
|
||||
service_id,
|
||||
service_desc,
|
||||
interface_cfg_total,
|
||||
system_cfg_total,
|
||||
time,
|
||||
remark
|
||||
FROM
|
||||
sys_user_warn
|
||||
<where>
|
||||
<if test="serviceId != null and serviceId !=''" >
|
||||
and service_id = #{serviceId}
|
||||
</if>
|
||||
</where>
|
||||
order by service_id
|
||||
</select>
|
||||
|
||||
<select id="getAllSum" parameterType="com.nis.domain.SysUserWarn" resultType="com.nis.domain.SysUserWarn">
|
||||
|
||||
SELECT
|
||||
SUM(interface_cfg_total) interface_cfg_total,
|
||||
SUM(system_cfg_total) system_cfg_total
|
||||
FROM
|
||||
sys_user_warn
|
||||
<where>
|
||||
<if test="serviceId != null and serviceId !=''" >
|
||||
and service_id = #{serviceId}
|
||||
</if>
|
||||
</where>
|
||||
order by service_id
|
||||
</select>
|
||||
|
||||
<select id="getAllInfoCount" resultType="java.lang.Integer">
|
||||
|
||||
select count(service_id) total from sys_user_warn
|
||||
</select>
|
||||
|
||||
<select id="getCfgCount" parameterType="com.nis.domain.SysUserWarn" resultType="java.lang.Integer">
|
||||
|
||||
select count(cfg_id) cfgTotal from ${tableName}
|
||||
|
||||
<where>
|
||||
service_id = #{id}
|
||||
and is_valid=1
|
||||
</where>
|
||||
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="java.util.List" >
|
||||
insert into sys_user_warn (
|
||||
service_id,
|
||||
service_desc,
|
||||
interface_cfg_total,
|
||||
system_cfg_total,
|
||||
time,
|
||||
remark
|
||||
)values
|
||||
<foreach collection="list" item="item" index= "index" separator =",">
|
||||
(
|
||||
#{item.serviceId,jdbcType=VARCHAR},
|
||||
#{item.serviceDesc,jdbcType=VARCHAR},
|
||||
#{item.interfaceCfgTotal,jdbcType=INTEGER},
|
||||
#{item.systemCfgTotal,jdbcType=INTEGER},
|
||||
#{item.time,jdbcType=TIMESTAMP},
|
||||
#{item.remark,jdbcType=VARCHAR}
|
||||
)
|
||||
</foreach>
|
||||
|
||||
|
||||
</insert>
|
||||
|
||||
<delete id="deleteAllData">
|
||||
|
||||
delete from sys_user_warn
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
72
src/main/java/com/nis/web/service/SysUserWarnService.java
Normal file
72
src/main/java/com/nis/web/service/SysUserWarnService.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.nis.web.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.SysUserWarn;
|
||||
import com.nis.web.dao.SysUserWarnDao;
|
||||
|
||||
@Service
|
||||
public class SysUserWarnService extends BaseService{
|
||||
|
||||
@Autowired
|
||||
private SysUserWarnDao sysUserWarnDao;
|
||||
|
||||
//查询所有的数据
|
||||
public Page<SysUserWarn> getAllList(Page<SysUserWarn> page,SysUserWarn entity,Properties msgProp){
|
||||
|
||||
entity.setPage(page);
|
||||
List<SysUserWarn> allList = sysUserWarnDao.getAllList(entity);
|
||||
if(allList !=null && allList.size()>0){
|
||||
SysUserWarn obj=new SysUserWarn();
|
||||
obj.setServiceId(entity.getServiceId());
|
||||
SysUserWarn allSum = sysUserWarnDao.getAllSum(obj);
|
||||
SysUserWarn sysWarn=new SysUserWarn();
|
||||
String report_total = msgProp.getProperty("report_total");
|
||||
sysWarn.setServiceId(report_total);
|
||||
sysWarn.setServiceDesc("--");
|
||||
sysWarn.setInterfaceCfgTotal(allSum.getInterfaceCfgTotal());
|
||||
sysWarn.setSystemCfgTotal(allSum.getSystemCfgTotal());
|
||||
sysWarn.setTime(allList.get(0).getTime());
|
||||
allList.add(0, sysWarn);
|
||||
}
|
||||
|
||||
page.setList(allList);
|
||||
return page;
|
||||
}
|
||||
//根据serviceID和表名查询业务配置的数量
|
||||
public Integer getAllInfoCount(){
|
||||
|
||||
return sysUserWarnDao.getAllInfoCount();
|
||||
}
|
||||
|
||||
//根据serviceID和表名查询业务配置的数量
|
||||
public Integer getCfgCount(SysUserWarn entity){
|
||||
|
||||
return sysUserWarnDao.getCfgCount(entity);
|
||||
}
|
||||
//新增
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public int insert(List<SysUserWarn> list){
|
||||
return sysUserWarnDao.insert(list);
|
||||
|
||||
}
|
||||
//删除所有的数据
|
||||
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
||||
public int deleteAllData(){
|
||||
return sysUserWarnDao.deleteAllData();
|
||||
|
||||
}
|
||||
//查询 所有业务 界面总量和服务总量的和
|
||||
public SysUserWarn findServiceSum(){
|
||||
SysUserWarn obj=new SysUserWarn();
|
||||
SysUserWarn allSum = sysUserWarnDao.getAllSum(obj);
|
||||
return allSum;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user