Url分组配置修改、删除和审核服务端

This commit is contained in:
shangguanyanfei
2019-02-20 19:09:17 +08:00
parent 9b36df1a00
commit efbb596bd5
7 changed files with 707 additions and 36 deletions

View File

@@ -1,6 +1,7 @@
package com.nis.web.controller.basics;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.google.common.collect.Maps;
import com.nis.domain.FunctionRegionDict;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
@@ -28,8 +30,11 @@ import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.util.StringUtil;
import com.nis.web.controller.BaseController;
import com.nis.web.security.UserUtils;
import com.nis.web.service.basics.UrlCommGroupService;
import jersey.repackaged.com.google.common.collect.Lists;
@Controller
@RequestMapping(value = "${adminPath}/basics/url")
public class UrlCommGroupController extends BaseController{
@@ -77,7 +82,7 @@ public class UrlCommGroupController extends BaseController{
@RequiresPermissions(value={"http:url:config"})
public String save(Model model,HttpServletRequest request,HttpServletResponse response,@ModelAttribute("cfg")CfgIndexInfo cfg,RedirectAttributes redirectAttributes){
System.out.println("URL分组");
// System.out.println("URL分组");
try{
urlCommGroupService.saveUrlCommGroupCfg(cfg);
}catch(Exception e){
@@ -93,7 +98,81 @@ public class UrlCommGroupController extends BaseController{
return "redirect:" + adminPath +"/basics/url/list?functionId="+cfg.getFunctionId();
}
@RequestMapping(value = {"/updateForm"})
public String updateForm(Model model,HttpServletRequest request
,HttpServletResponse response,String ids,@ModelAttribute("cfg")UrlCommGroupCfg cfg
,RedirectAttributes redirectAttributes){
cfg = urlCommGroupService.get(Long.parseLong(ids));
// initUpdateFormCondition(model, cfg);
cfg.setGroupType(11);
initUpdateFormCondition(model,cfg);
//List<ConfigGroupInfo> groupInfos=configGroupInfoService.findAllList(4);
//model.addAttribute("policyGroups", groupInfos);
model.addAttribute("_cfg", cfg);
return "/basics/urlCommGroupFormUpdate";
}
@RequestMapping(value = {"/update"})
@RequiresPermissions(value={"http:url:config"})
public String update(Model model,HttpServletRequest request,HttpServletResponse response,@ModelAttribute("cfg")UrlCommGroupCfg cfg,RedirectAttributes redirectAttributes){
try{
urlCommGroupService.update(cfg);
addMessage(redirectAttributes,"success","save_success");
}catch(Exception e){
logger.error("信息保存失败",e);
e.printStackTrace();
addMessage(redirectAttributes,"error","save_failed");
}
return "redirect:" + adminPath +"/basics/url/list?functionId="+cfg.getFunctionId();
}
@RequestMapping(value = {"/audit"})
@RequiresPermissions(value={"http:url:config"})
public String audit(Model model,@ModelAttribute("cfg")UrlCommGroupCfg cfg
,Integer isAudit
,Integer isValid
,String ids
,Integer functionId
, HttpServletRequest request
,HttpServletResponse response
,RedirectAttributes redirectAttributes) {
//选中配置审核
if(!StringUtil.isEmpty(ids)) {
List<UrlCommGroupCfg> urlGroupCfgs=urlCommGroupService.getByIds(ids);
/********************每次下发一个组的region保证事物********************/
for (UrlCommGroupCfg urlCommGroup : urlGroupCfgs) {
try {
urlCommGroupService.audit(urlCommGroup,isAudit,isValid);
} catch (Exception e) {
logger.error("审核失败",e);
e.printStackTrace();
addMessage(redirectAttributes,"error","audit_failed");
}
}
}
return "redirect:" + adminPath +"/basics/url/list?functionId="+cfg.getFunctionId();
}
@RequestMapping(value = {"/delete"})
@RequiresPermissions(value={"http:url:config"})
public String delete(Integer isValid
,String ids,Integer functionId
,RedirectAttributes redirectAttributes){
try{
urlCommGroupService.delete(ids);
addMessage(redirectAttributes,"success","delete_success");
}catch(Exception e){
logger.error("Delete failed",e);
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error",e.getMessage());
}else {
addMessage(redirectAttributes,"error","delete_failed");
}
}
return "redirect:" + adminPath +"/basics/url/list?functionId="+functionId;
}
//urlComm配置导出
@RequestMapping(value = "/exportUrlComm")
public void exportAsnIp(Model model,HttpServletRequest request,HttpServletResponse response,
@@ -118,7 +197,7 @@ public class UrlCommGroupController extends BaseController{
titleList.add(entity.getMenuNameCode());
classMap.put(entity.getMenuNameCode(), UrlCommGroupCfg.class);
String cfgIndexInfoNoExport=",block_type,do_log,action"
+ ",letter,whether_area_block,classification,attribute,label"
+ ",letter,whether_area_block,classification,attribute,label,expression_type,match_method"
+",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,asn_no,is_hex,is_case_insenstive,";
// 时间过滤
if (entity.getSearch_create_time_start() == null ) {

View File

@@ -9,14 +9,30 @@ import com.nis.web.dao.CrudDao;
import com.nis.web.dao.MyBatisDao;
@MyBatisDao
public interface UrlCommGroupDao extends CrudDao<UrlCommGroupDao>{
public interface UrlCommGroupDao extends CrudDao<UrlCommGroupCfg>{
// 查询列表
public List<UrlCommGroupCfg> findAllPageList(UrlCommGroupCfg entity);
public List<UrlCommGroupCfg> findByPage(@Param("ids")String ids);
public List<UrlCommGroupCfg> findInfoByCfgId(@Param("cfgId")String cfgId);
public List<UrlCommGroupCfg> findInfoByCfgId(@Param("cfgId")Long cfgId);
//新增
public int insertUrlCommGroupCfg(UrlCommGroupCfg entity);
public Integer findUrlUdFlag(@Param("groupId")Integer groupId);
public int updateUrlUdFlag(@Param("groupId")Integer groupId,@Param("udFlag")Integer udFlag);
//修改
public int update(UrlCommGroupCfg entity);
//删除
public int delete(@Param("ids")String ids);
public List<UrlCommGroupCfg> getByIds(@Param("ids")String ids);
public Integer getGroupIdCount(@Param("groupId")String groupId);
}

View File

@@ -165,17 +165,24 @@
r.request_id,r.compile_id,r.is_area_effective,r.classify,r.attribute,r.lable,
r.expr_type,r.match_method,r.is_hexbin,r.area_effective_ids,r.function_id,
r.cfg_region_code,r.cfg_type,r.ratelimit,r.user_region1,r.user_region2,
r.user_region3,r.user_region4,r.user_region5,
s.name AS creator_name,e.name AS editor_name,u.name AS auditor_name
r.user_region3,r.user_region4,r.user_region5
FROM
http_url_cfg r
LEFT JOIN sys_user s ON r.creator_id = s.id
LEFT JOIN sys_user e ON r.editor_id = e.id
LEFT JOIN sys_user u ON r.auditor_id = u.id
where r.CFG_ID =#{cfgId}
</select>
<select id="get" resultMap="urlCommGroupCfgMap">
SELECT
r.cfg_id,r.cfg_desc,r.cfg_keywords,r.action,r.is_valid,r.is_audit,r.creator_id,
r.create_time,r.editor_id,r.edit_time,r.auditor_id,r.audit_time,r.service_id,
r.request_id,r.compile_id,r.is_area_effective,r.classify,r.attribute,r.lable,
r.expr_type,r.match_method,r.is_hexbin,r.area_effective_ids,r.function_id,
r.cfg_region_code,r.cfg_type,r.ratelimit,r.user_region1,r.user_region2,
r.user_region3,r.user_region4,r.user_region5
from http_url_cfg r
where r.cfg_id=#{cfgId}
</select>
<insert id="insertUrlCommGroupCfg" parameterType="com.nis.domain.basics.UrlCommGroupCfg">
insert into http_url_cfg (
@@ -245,4 +252,135 @@
)
</insert>
<select id="findUrlUdFlag" parameterType="java.lang.Integer" resultType="java.lang.Integer">
SELECT ud_flag from policy_group_info
where group_id=#{groupId}
and group_type=11
</select>
<update id="updateUrlUdFlag" parameterType="java.lang.Integer">
UPDATE policy_group_info SET ud_flag =#{udFlag}
WHERE group_id=#{groupId}
and group_type=11
</update>
<update id="update" parameterType="com.nis.domain.basics.UrlCommGroupCfg" >
update http_url_cfg
<set >
<trim suffixOverrides=",">
<if test="cfgDesc != null and cfgDesc != ''" >
cfg_desc = #{cfgDesc,jdbcType=VARCHAR},
</if>
<if test="cfgKeywords != null and cfgKeywords != ''" >
cfg_keywords = #{cfgKeywords,jdbcType=VARCHAR},
</if>
<if test="action != null" >
action = #{action,jdbcType=INTEGER},
</if>
<if test="isValid != null" >
is_valid = #{isValid,jdbcType=INTEGER},
</if>
<if test="isAudit != null" >
is_audit = #{isAudit,jdbcType=INTEGER},
</if>
<if test="editorId != null" >
editor_id = #{editorId,jdbcType=INTEGER},
</if>
<if test="editTime != null and editTime != ''" >
edit_time = #{editTime,jdbcType=TIMESTAMP},
</if>
<if test="auditorId != null" >
AUDITOR_ID = #{auditorId,jdbcType=INTEGER},
</if>
<if test="auditTime != null and auditTime != ''" >
AUDIT_TIME = #{auditTime,jdbcType=TIMESTAMP},
</if>
<if test="serviceId != null" >
service_id = #{serviceId,jdbcType=INTEGER},
</if>
<if test="requestId != null" >
request_id = #{requestId,jdbcType=INTEGER},
</if>
<if test="compileId != null and compileId != ''" >
compile_id = #{compileId,jdbcType=INTEGER},
</if>
<if test="isAreaEffective != null" >
is_area_effective = #{isAreaEffective,jdbcType=INTEGER},
</if>
<if test="classify != null and classify != ''" >
classify = #{classify,jdbcType=VARCHAR},
</if>
<if test="attribute != null and attribute != ''" >
attribute = #{attribute,jdbcType=VARCHAR},
</if>
<if test="lable != null and lable != ''" >
lable = #{lable,jdbcType=VARCHAR},
</if>
<if test="exprType != null" >
expr_type = #{exprType,jdbcType=INTEGER},
</if>
<if test="matchMethod != null" >
match_method = #{matchMethod,jdbcType=INTEGER},
</if>
<if test="isHexbin != null" >
is_hexbin = #{isHexbin,jdbcType=INTEGER},
</if>
<if test="areaEffectiveIds != null" >
area_effective_ids = #{areaEffectiveIds,jdbcType=VARCHAR},
</if>
<if test="functionId != null" >
function_id = #{functionId,jdbcType=INTEGER},
</if>
<if test="cfgType != null and cfgType != ''" >
cfg_type = #{cfgType,jdbcType=VARCHAR},
</if>
<if test="cfgRegionCode != null " >
cfg_region_code = #{cfgRegionCode,jdbcType=INTEGER},
</if>
<if test="ratelimit != null and ratelimit != ''" >
ratelimit = #{ratelimit,jdbcType=VARCHAR},
</if>
<if test="userRegion1 != null and userRegion1 != ''" >
user_region1 = #{userRegion1,jdbcType=VARCHAR},
</if>
<if test="userRegion2 != null and userRegion2 != ''" >
user_region2 = #{userRegion2,jdbcType=VARCHAR},
</if>
<if test="userRegion3 != null and userRegion3 != ''" >
user_region3 = #{userRegion3,jdbcType=VARCHAR},
</if>
<if test="userRegion4 != null and userRegion4 != ''" >
user_region4 = #{userRegion4,jdbcType=VARCHAR},
</if>
<if test="userRegion5 != null and userRegion5 != ''" >
user_region5 = #{userRegion5,jdbcType=VARCHAR},
</if>
</trim>
</set>
<where>
and cfg_id = #{cfgId,jdbcType=INTEGER}
</where>
</update>
<delete id="delete" parameterType="java.lang.String" >
delete from http_url_cfg where cfg_id in (${ids})
</delete>
<select id="getByIds" resultMap="urlCommGroupCfgMap">
select
r.cfg_id,r.cfg_desc,r.cfg_keywords,r.action,r.is_valid,r.is_audit,r.creator_id,
r.create_time,r.editor_id,r.edit_time,r.auditor_id,r.audit_time,r.service_id,
r.request_id,r.compile_id,r.is_area_effective,r.classify,r.attribute,r.lable,
r.expr_type,r.match_method,r.is_hexbin,r.area_effective_ids,r.function_id,
r.cfg_region_code,r.cfg_type,r.ratelimit,r.user_region1,r.user_region2,
r.user_region3,r.user_region4,r.user_region5
from http_url_cfg r
where r.cfg_id in (${ids}) and is_valid !=-1
</select>
<select id="getGroupIdCount" parameterType="java.lang.String" resultType="java.lang.Integer">
SELECT COUNT(cfg_id) groupCount from http_url_cfg
WHERE user_region3= #{groupId}
and is_valid=1
</select>
</mapper>

View File

@@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -13,13 +16,27 @@ import com.nis.domain.Page;
import com.nis.domain.basics.AsnGroupInfo;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.UrlCommGroupCfg;
import com.nis.domain.configuration.BaseIpCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.specific.ConfigGroupInfo;
import com.nis.domain.maat.GroupReuseAddBean;
import com.nis.domain.maat.GroupReuseCfg;
import com.nis.domain.maat.MaatCfg;
import com.nis.domain.maat.ToMaatBean;
import com.nis.domain.maat.ToMaatResult;
import com.nis.domain.maat.MaatCfg.DigestCfg;
import com.nis.domain.maat.MaatCfg.GroupCfg;
import com.nis.domain.maat.MaatCfg.IpCfg;
import com.nis.domain.maat.MaatCfg.NumBoundaryCfg;
import com.nis.domain.maat.MaatCfg.StringCfg;
import com.nis.util.ConfigServiceUtil;
import com.nis.util.Constants;
import com.nis.util.StringUtil;
import com.nis.web.dao.CrudDao;
import com.nis.web.dao.basics.UrlCommGroupDao;
import com.nis.web.dao.configuration.IpCfgDao;
import com.nis.web.security.UserUtils;
import com.nis.web.service.CrudService;
import com.nis.web.service.SpringContextHolder;
@Service
public class UrlCommGroupService extends CrudService<CrudDao<UrlCommGroupCfg>, UrlCommGroupCfg>{
@@ -32,6 +49,10 @@ public class UrlCommGroupService extends CrudService<CrudDao<UrlCommGroupCfg>, U
entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"r"));
entity.setPage(page);
List<UrlCommGroupCfg> list=urlCommGroupDao.findAllPageList(entity);
for (int i = 0; i < list.size(); i++) {
String key=list.get(i).getCfgKeywords().replace("***and***", " ");
list.get(i).setCfgKeywords(key);
}
page.setList(list);
return page;
}
@@ -42,33 +63,91 @@ public class UrlCommGroupService extends CrudService<CrudDao<UrlCommGroupCfg>, U
return list;
}
public UrlCommGroupCfg get(Long id ) {
return urlCommGroupDao.get(id);
}
//新增 insertUrlCommGroupCfg
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void saveUrlCommGroupCfg(CfgIndexInfo entity) {
Date createTime=new Date();
if(entity.getUrlCommGroupList()!=null) {
for(UrlCommGroupCfg cfg:entity.getUrlCommGroupList()) {
BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"});
cfg.setRequestId(0);
cfg.setClassify("0");
cfg.setAttribute("0");
cfg.setLable("0");
cfg.setIsHexbin(0);
cfg.setCreateTime(createTime);
cfg.setCreatorId(entity.getCurrentUser().getId());
cfg.setIsValid(Constants.VALID_NO);
cfg.setIsAudit(Constants.AUDIT_NOT_YET);
if(cfg.getCfgKeywords().contains("and")){
cfg.setExprType(1);
for (int i = 0; i < entity.getUrlCommGroupList().size(); i++) {
BeanUtils.copyProperties(entity, entity.getUrlCommGroupList().get(i), new String[]{"cfgId"});
entity.getUrlCommGroupList().get(i).setRequestId(0);
entity.getUrlCommGroupList().get(i).setClassify("0");
entity.getUrlCommGroupList().get(i).setAttribute("0");
entity.getUrlCommGroupList().get(i).setLable("0");
entity.getUrlCommGroupList().get(i).setIsHexbin(0);
entity.getUrlCommGroupList().get(i).setCreateTime(createTime);
entity.getUrlCommGroupList().get(i).setCreatorId(entity.getCurrentUser().getId());
entity.getUrlCommGroupList().get(i).setIsValid(Constants.VALID_NO);
entity.getUrlCommGroupList().get(i).setIsAudit(Constants.AUDIT_NOT_YET);
if(entity.getUrlCommGroupList().get(i).getCfgKeywords().contains("***and***")){
entity.getUrlCommGroupList().get(i).setExprType(1);
}else{
cfg.setExprType(0);
entity.getUrlCommGroupList().get(i).setExprType(0);
}
urlCommGroupDao.insertUrlCommGroupCfg(cfg);
urlCommGroupDao.insertUrlCommGroupCfg(entity.getUrlCommGroupList().get(i));
}
// //修改公共组的标识
// Integer udFlag=urlCommGroupDao.findUrlUdFlag(Integer.parseInt(entity.getUserRegion3()));
// if(udFlag == 0){
// urlCommGroupDao.updateUrlUdFlag(Integer.parseInt(entity.getUserRegion3()), 1);
// }
}
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void update(UrlCommGroupCfg entity){
Date editTime=new Date();
entity.setIsValid(0);
entity.setIsAudit(0);
entity.setEditTime(editTime);
entity.setEditorId(entity.getCurrentUser().getId());
if(entity.getCfgKeywords().contains("***and***")){
entity.setExprType(1);
}else{
entity.setExprType(0);
}
urlCommGroupDao.update(entity);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void delete(String ids) {
urlCommGroupDao.delete(ids);
}
public List<UrlCommGroupCfg> getByIds(String ids) {
if(ids==null) {
throw new RuntimeException("ids is null!");
}
return urlCommGroupDao.getByIds(ids);
}
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
public void audit(UrlCommGroupCfg urlGroupCfg,Integer isAudit,Integer isValid) {
if(!StringUtil.isEmpty(urlGroupCfg)){
urlGroupCfg.setIsValid(isValid);
urlGroupCfg.setIsAudit(isAudit);
urlGroupCfg.setAuditorId(UserUtils.getUser().getId());
urlGroupCfg.setAuditTime(new Date());
urlCommGroupDao.update(urlGroupCfg);
}
//下发配置时改变公共组udFlag标识
//查询有效的url配置个数
Integer groupCount=urlCommGroupDao.getGroupIdCount(urlGroupCfg.getUserRegion3());
if(groupCount>0){//udFlag 设置为1
urlCommGroupDao.updateUrlUdFlag(Integer.parseInt(urlGroupCfg.getUserRegion3()), 1);
}else{//udFlag 设置为0
urlCommGroupDao.updateUrlUdFlag(Integer.parseInt(urlGroupCfg.getUserRegion3()), 0);
}
}
}