This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
k18-ntcs-web-ntc/src/main/java/com/nis/web/controller/basics/UrlCommGroupController.java
2019-02-20 19:09:17 +08:00

235 lines
9.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
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.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;
import com.nis.domain.basics.AsnIpCfg;
import com.nis.domain.basics.UrlCommGroupCfg;
import com.nis.domain.configuration.CfgIndexInfo;
import com.nis.domain.configuration.HttpUrlCfg;
import com.nis.exceptions.MaatConvertException;
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{
@Autowired
private UrlCommGroupService urlCommGroupService;
@RequestMapping(value = {"/list"})
public String list(Model model,HttpServletRequest request
,HttpServletResponse response,@ModelAttribute("cfg")UrlCommGroupCfg entity
){
Page<UrlCommGroupCfg> page = urlCommGroupService.findPage(new Page<UrlCommGroupCfg>(request, response,"r"), entity);
model.addAttribute("page", page);
List<FunctionRegionDict> regionList = DictUtils.getFunctionRegionDictList(entity.getFunctionId());
model.addAttribute("regionList", regionList);
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(entity.getFunctionId());
model.addAttribute("serviceList", serviceList);
return "/basics/urlCommGroupList";
}
@RequestMapping(value = {"/addForm"})
public String addForm(Model model,HttpServletRequest request
,HttpServletResponse response,@ModelAttribute("cfg")CfgIndexInfo cfg
,RedirectAttributes redirectAttributes){
// UrlCommGroupCfg urlCfg = new UrlCommGroupCfg();
// urlCfg.setCfgType("NTC_URL_REGION");
// cfg.setUrlCommGroupCfg(urlCfg);
// List<UrlCommGroupCfg> urlList = new ArrayList<UrlCommGroupCfg>();
// urlList.add(urlCfg);
// cfg.setUrlCommGroupList(urlList);
// initFormCondition(model, entity);
cfg.setGroupType(11);
initFormCondition(model,cfg);
//List<ConfigGroupInfo> groupInfos=configGroupInfoService.findAllList(4);
//model.addAttribute("policyGroups", groupInfos);
model.addAttribute("_cfg", cfg);
return "/basics/urlCommGroupFormAdd";
}
@RequestMapping(value = {"/save"})
@RequiresPermissions(value={"http:url:config"})
public String save(Model model,HttpServletRequest request,HttpServletResponse response,@ModelAttribute("cfg")CfgIndexInfo cfg,RedirectAttributes redirectAttributes){
// System.out.println("URL分组");
try{
urlCommGroupService.saveUrlCommGroupCfg(cfg);
}catch(Exception e){
logger.error("信息保存失败",e);
e.printStackTrace();
if(e instanceof MaatConvertException) {
addMessage(redirectAttributes,"error",e.getMessage());
}else {
addMessage(redirectAttributes,"error","save_failed");
}
}
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,
@ModelAttribute("cfg")UrlCommGroupCfg entity,String ids,RedirectAttributes redirectAttributes){
try {
//export data info
List<String> titleList=new ArrayList<String>();
Map<String, Class<?>> classMap=new HashMap<String, Class<?>>();
Map<String, List> dataMap=new HashMap<String, List>();
Map<String, String> noExportMap=new HashMap<String, String>();
List<UrlCommGroupCfg> list = new ArrayList<UrlCommGroupCfg>();
if (!StringUtil.isEmpty(ids)) {
list = urlCommGroupService.findByPage(ids);
} else {
Page<UrlCommGroupCfg> pageInfo=new Page<UrlCommGroupCfg>(request, response,"r");
pageInfo.setPageNo(1);
pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE);
Page<UrlCommGroupCfg> page = urlCommGroupService.findPage(pageInfo, entity);
list=page.getList();
}
//
titleList.add(entity.getMenuNameCode());
classMap.put(entity.getMenuNameCode(), UrlCommGroupCfg.class);
String cfgIndexInfoNoExport=",block_type,do_log,action"
+ ",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 ) {
cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_edit_time_start() == null) {
cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport;
}
if (entity.getSearch_audit_time_start() == null) {
cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport;
}
if (!StringUtil.isEmpty(entity.gethColumns())) {
cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport;
}
noExportMap.put(entity.getMenuNameCode(),cfgIndexInfoNoExport);
dataMap.put(entity.getMenuNameCode(), list);
String timeRange = initTimeMap(entity);
noExportMap.put("timeRange", timeRange);
if ("csv".equals(entity.getExType())) {
this._exportCsv(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
} else {
this._export(model, request, response, redirectAttributes, entity.getMenuNameCode(), titleList,
classMap, dataMap, noExportMap);
}
} catch (Exception e) {
logger.error("urlGroupConfig export failed",e);
addMessage(redirectAttributes,"error","export_failed");
}
//return "redirect:" + adminPath +"/ntc/iplist/list?functionId="+entity.getFunctionId();
}
}