package com.nis.web.controller.configuration; import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.taglibs.standard.functions.Functions; import org.springframework.beans.BeanUtils; 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.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.nis.domain.Page; import com.nis.domain.SysDataDictionaryItem; import com.nis.domain.configuration.AppBuiltInFeatureFile; import com.nis.domain.configuration.AppByteCfg; import com.nis.domain.configuration.AppDomainCfg; import com.nis.domain.configuration.AppHeaderCfg; import com.nis.domain.configuration.AppHttpCfg; import com.nis.domain.configuration.AppIpCfg; import com.nis.domain.configuration.AppPolicyCfg; import com.nis.domain.configuration.AppSslCertCfg; import com.nis.domain.configuration.AppTcpCfg; import com.nis.domain.configuration.AppTopicDomainCfg; import com.nis.domain.configuration.BaseStringCfg; import com.nis.domain.configuration.CfgIndexInfo; import com.nis.domain.configuration.IpPortCfg; import com.nis.domain.configuration.NtcSubscribeIdCfg; import com.nis.domain.configuration.WebsiteDomainTopic; import com.nis.domain.maat.ToMaatResult; import com.nis.domain.maat.ToMaatResult.ResponseData; import com.nis.domain.specific.SpecificServiceCfg; import com.nis.exceptions.CallExternalProceduresException; import com.nis.exceptions.MaatConvertException; import com.nis.util.ConfigServiceUtil; import com.nis.util.Constants; import com.nis.util.DictUtils; import com.nis.util.FileUtils; import com.nis.util.JsonMapper; import com.nis.util.LogUtils; import com.nis.util.StringUtil; import com.nis.web.controller.BaseController; import com.nis.web.security.UserUtils; /** * 特定协议相关配置控制类 * * @author zhangwei * */ @Controller @RequestMapping("${adminPath}/app") public class AppCfgController extends BaseController { /** * app策略列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "policyCfgList" }) public String policyCfgList(Model model, @ModelAttribute("cfg") AppPolicyCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppPolicyList(searchPage, cfg); // for(AppPolicyCfg entity:page.getList()){ // SpecificServiceCfg app = // specificServiceCfgService.getBySpecServiceId(entity.getSpecServiceId()); // if(app!=null) { // entity.setAppName(app.getSpecServiceName()); // } // } // 查找社交应用的所有有效二级特定服务 // SpecificServiceCfg second=new SpecificServiceCfg(); // second.setCfgType(1); // second.setIsValid(Constants.VALID_YES); // second.setIsLeaf(1); // List // secondList=specificServiceCfgService.findAllSpecificServiceCfg(second, // null); // 遍历,找到匹配项后将行为设置进去 // for(AppPolicyCfg entity:page.getList()){ // if(entity.getBehavCode()==null) continue; // for(SpecificServiceCfg secondCfg:secondList) { // if(secondCfg.getSpecServiceCode()==null) continue; // if(secondCfg.getSpecServiceCode().intValue()==entity.getBehavCode().intValue()) // { // entity.setBehavName(secondCfg.getSpecServiceName()); // break; // } // } // } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appPolicyCfgList"; } /** * ajax设置Name * * @param model * @param ids * @return */ @RequestMapping(value = "ajaxAppName", method = RequestMethod.POST) @ResponseBody public List> ajaxAppName(Model model, String ids,Integer cfgType) { List> dataList = new ArrayList<>(); List serviceList = specificServiceCfgService.getBySpecServiceCodes(ids,cfgType); Map appMap = new HashMap<>(); Map behavMap = new HashMap<>(); for (SpecificServiceCfg cfg : serviceList) { if (cfg.getIsLeaf().intValue() == 0) { appMap.put(cfg.getSpecServiceCode().toString(), cfg.getSpecServiceName()); } else { behavMap.put(cfg.getSpecServiceCode().toString(), cfg.getSpecServiceName()); } } dataList.add(appMap); dataList.add(behavMap); return dataList; } /** * 查询APP策略IP子配置 * * @param model * @param cfgId * @param index * @return */ @RequestMapping(value = { "ajaxAppPolicyIpList" }) public String ajaxSslSubList(Model model, Long cfgId, Integer index, Integer compileId) { AppPolicyCfg cfg = appCfgService.getAppPolicyCfg(cfgId, compileId); List tabList = new ArrayList(); if (CollectionUtils.isNotEmpty(cfg.getIpPortList())) { String cfgType = null; for (IpPortCfg ip : cfg.getIpPortList()) { if (!ip.getCfgType().equals(cfgType)) { tabList.add(new String[] { "1", ip.getCfgType() }); cfgType = ip.getCfgType(); } } } if (CollectionUtils.isNotEmpty(cfg.getNtcSubscribeIdCfgList())) { String cfgType = null; for (NtcSubscribeIdCfg ntc : cfg.getNtcSubscribeIdCfgList()) { if (!ntc.getCfgType().equals(cfgType)) { tabList.add(new String[] { "2", ntc.getCfgType() }); cfgType = ntc.getCfgType(); } } } model.addAttribute("_cfg", cfg); model.addAttribute("index", index); model.addAttribute("tabList", tabList); return "/cfg/app/appPolicySubList"; } /** * 策略配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "policyCfgForm" }) @RequiresPermissions(value = { "app:policy:config" }) public String policyCfgForm(Model model, String ids, AppPolicyCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppPolicyCfg(Long.parseLong(ids), null); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appPolicyCfgForm"; } /** * 策略配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppPolicyCfg" }) @RequiresPermissions(value = { "app:policy:config" }) public String saveAppPolicyCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppPolicyCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppPolicyCfg(entity); //配置仅保存 if(StringUtil.isEmpty(entity.getIsValid()) || entity.getIsValid()!=1) { addMessage(redirectAttributes, "success", "save_success"); }else { //配置直接生效 addMessage(redirectAttributes, "success", "audit_success"); } } catch (MaatConvertException e) { logger.error("app 协议配置下发失败:",e); addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } catch (Exception e) { logger.error("app 协议配置保存失败:",e); addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } return "redirect:" + adminPath + "/app/policyCfgList?functionId=" + entity.getFunctionId(); } /** * 策略配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppPolicyCfg" }) @RequiresPermissions(value = { "app:policy:confirm" }) public String auditAppPolicyCfg(Model model, @ModelAttribute("cfg") AppPolicyCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppPolicyCfg entity = new AppPolicyCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppPolicyCfg(Long.parseLong(id), null); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setFunctionId(functionId); entity.setConfigType(Constants.SPECIFIC_SERVICE_CFG_TYPE_APP); try { appCfgService.auditAppPolicyCfg(entity, isAudit,Constants.INSERT_ACTION); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app策略配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); BeanUtils.copyProperties(searchPage, auditPage); try { auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return policyCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/policyCfgList?functionId=" + functionId; } /** * 策略配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppPolicyCfgValid" }) @RequiresPermissions(value = { "app:policy:config" }) public String updateAppPolicyCfgValid(Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg")AppPolicyCfg cfg) { try { if (!StringUtil.isEmpty(ids)) { appCfgService.updateAppPolicyCfgValid(isValid, ids, functionId); addMessage(redirectAttributes, "success", "delete_success"); }else { // 批量删除 Page searchPage = new Page(request, response, "a"); deleteAll(searchPage, functionId, cfg); } } catch (Exception e) { logger.error("配置删除失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "delete_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/policyCfgList?functionId=" + functionId; } /** * app协议IP配置列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "ipCfgList" }) public String ipCfgList(Model model, @ModelAttribute("cfg") AppIpCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppIpList(searchPage, cfg); for (AppIpCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appIpCfgList"; } /** * 协议IP配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "ipCfgForm" }) @RequiresPermissions(value = { "app:ip:config" }) public String ipCfgForm(Model model, String ids, AppIpCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppIpCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appIpCfgForm"; } /** * 协议IP配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppIpCfg" }) @RequiresPermissions(value = { "app:ip:config" }) public String saveAppIpCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppIpCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppIpCfg(entity); //配置仅保存 if(StringUtil.isEmpty(entity.getIsValid()) || entity.getIsValid()!=1) { addMessage(redirectAttributes, "success", "save_success"); }else { //配置直接生效 addMessage(redirectAttributes, "success", "audit_success"); } }catch (MaatConvertException e) { logger.error("APP IP配置下发失败:",e); addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } catch (Exception e) { logger.error("APP IP配置保存失败:",e); addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } return "redirect:" + adminPath + "/app/ipCfgList?functionId=" + entity.getFunctionId(); } /** * 协议IP配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppIpCfg" }) @RequiresPermissions(value = { "app:ip:confirm" }) public String auditAppIpCfg(Model model, @ModelAttribute("cfg") AppIpCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppIpCfg entity = new AppIpCfg(); String[] idArray = ids.split(","); // 同一编译IP的分组 Map> dataMap = new HashMap<>(); for (String id : idArray) { entity = appCfgService.getAppIpCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setFunctionId(functionId); if (dataMap.containsKey(entity.getCompileId())) { dataMap.get(entity.getCompileId()).add(entity); } else { List ipList = new ArrayList<>(); ipList.add(entity); dataMap.put(entity.getCompileId(), ipList); } } for (List entitys : dataMap.values()) { try { appCfgService.auditAppIpCfg(entitys, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app协议IP配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); BeanUtils.copyProperties(searchPage, auditPage); try { auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return ipCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/ipCfgList?functionId=" + functionId; } /** * IP配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppIpCfgValid" }) @RequiresPermissions(value = { "app:ip:config" }) public String updateAppIpCfgValid(Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg")AppIpCfg cfg) { try { if (!StringUtil.isEmpty(ids)) { appCfgService.updateAppIpCfgValid(isValid, ids, functionId); addMessage(redirectAttributes, "success", "delete_success"); }else { // 批量删除 Page searchPage = new Page(request, response, "a"); deleteAll(searchPage, functionId, cfg); } } catch (Exception e) { logger.error("配置删除失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "delete_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/ipCfgList?functionId=" + functionId; } /** * app协议http配置列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "httpCfgList" }) public String httpCfgList(Model model, @ModelAttribute("cfg") AppHttpCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppHttpList(searchPage, cfg); for (AppHttpCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } // entity.setCfgKeywords(entity.getCfgKeywords().replace(Constants.KEYWORD_EXPR, // "&")); } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appHttpCfgList"; } /** * 协议http配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "httpCfgForm" }) @RequiresPermissions(value = { "app:http:config" }) public String httpCfgForm(Model model, String ids, AppHttpCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppHttpCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appHttpCfgForm"; } /** * http配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppHttpCfg" }) @RequiresPermissions(value = { "app:http:config" }) public String saveAppHttpCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppHttpCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppHttpCfg(entity); addMessage(redirectAttributes, "success", "save_success"); } catch (Exception e) { e.printStackTrace(); logger.error("saveAppHttpCfg failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/httpCfgList?functionId=" + entity.getFunctionId(); } /** * http配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppHttpCfg" }) // @RequiresPermissions(value={"app:http:confirm"}) public String auditAppHttpCfg(Model model, @ModelAttribute("cfg") AppHttpCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppHttpCfg entity = new AppHttpCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppHttpCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); entity.setFunctionId(functionId); try { appCfgService.auditAppHttpCfg(entity, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app http配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); try { BeanUtils.copyProperties(searchPage, auditPage); auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return httpCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/httpCfgList?functionId=" + functionId; } /** * http配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppHttpCfgValid" }) @RequiresPermissions(value = { "app:http:config" }) public String updateAppHttpCfgValid(Integer isValid, String ids, Integer functionId) { appCfgService.updateAppHttpCfgValid(isValid, ids, functionId); return "redirect:" + adminPath + "/app/httpCfgList?functionId=" + functionId; } /** * app协议domain配置列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "domainCfgList" }) public String domainCfgList(Model model, @ModelAttribute("cfg") AppDomainCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppDomainList(searchPage, cfg); for (AppDomainCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appDomainCfgList"; } /** * 协议domain配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "domainCfgForm" }) @RequiresPermissions(value = { "app:domain:config" }) public String domainCfgForm(Model model, String ids, AppDomainCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppDomainCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appDomainCfgForm"; } /** * domain配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppDomainCfg" }) @RequiresPermissions(value = { "app:domain:config" }) public String saveAppDomainCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppDomainCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppDomainCfg(entity); //配置仅保存 if(StringUtil.isEmpty(entity.getIsValid()) || entity.getIsValid()!=1) { addMessage(redirectAttributes, "success", "save_success"); }else { //配置直接生效 addMessage(redirectAttributes, "success", "audit_success"); } } catch (MaatConvertException e) { logger.error("APP域名配置下发失败:",e); addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } catch (Exception e) { logger.error("APP域名配置保存失败:",e); addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } return "redirect:" + adminPath + "/app/domainCfgList?functionId=" + entity.getFunctionId(); } /** * domain配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppDomainCfg" }) // @RequiresPermissions(value={"app:domain:confirm"}) public String auditAppDomainCfg(Model model, @ModelAttribute("cfg") AppDomainCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppDomainCfg entity = new AppDomainCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppDomainCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setFunctionId(functionId); try { appCfgService.auditAppDomainCfg(entity, isAudit,Constants.INSERT_ACTION); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app协议domain配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); try { BeanUtils.copyProperties(searchPage, auditPage); auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return domainCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/domainCfgList?functionId=" + functionId; } /** * domain配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppDomainCfgValid" }) @RequiresPermissions(value = { "app:domain:config" }) public String updateAppDomainCfgValid(Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg")AppDomainCfg cfg) { try { if (!StringUtil.isEmpty(ids)) { appCfgService.updateAppDomainCfgValid(isValid, ids, functionId); addMessage(redirectAttributes, "success", "delete_success"); }else { // 批量删除 Page searchPage = new Page(request, response, "a"); deleteAll(searchPage, functionId, cfg); } } catch (Exception e) { logger.error("配置删除失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "delete_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/domainCfgList?functionId=" + functionId; } /** * app协议byte配置列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "byteCfgList" }) public String byteCfgList(Model model, @ModelAttribute("cfg") AppByteCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppByteList(searchPage, cfg); for (AppByteCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appByteCfgList"; } /** * 协议byte配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "byteCfgForm" }) @RequiresPermissions(value = { "app:byte:config" }) public String byteCfgForm(Model model, String ids, AppByteCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppByteCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appByteCfgForm"; } /** * byte配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppByteCfg" }) @RequiresPermissions(value = { "app:byte:config" }) public String saveAppByteCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppByteCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppByteCfg(entity); addMessage(redirectAttributes, "success", "save_success"); } catch (Exception e) { e.printStackTrace(); logger.error("saveAppByteCfg failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/byteCfgList?functionId=" + entity.getFunctionId(); } /** * byte配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppByteCfg" }) // @RequiresPermissions(value={"app:byte:confirm"}) public String auditAppByteCfg(Integer isAudit, Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes,HttpServletRequest request) { AppByteCfg entity = new AppByteCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppByteCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); entity.setFunctionId(functionId); try { appCfgService.auditAppByteCfg(entity, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app协议byte配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } return "redirect:" + adminPath + "/app/byteCfgList?functionId=" + functionId; } /** * byte配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppByteCfgValid" }) @RequiresPermissions(value = { "app:byte:config" }) public String updateAppByteCfgValid(Integer isValid, String ids, Integer functionId) { appCfgService.updateAppByteCfgValid(isValid, ids, functionId); return "redirect:" + adminPath + "/app/byteCfgList?functionId=" + functionId; } /** * APP ssl证书特征配置 列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "sslCfgList" }) public String sslCfgList(Model model, @ModelAttribute("cfg") AppSslCertCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppSslList(searchPage, cfg); for (AppSslCertCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appSslCfgList"; } /** * APP ssl证书特征配置表单(新增/修改) * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "sslCfgForm" }) @RequiresPermissions(value = { "app:ssl:config" }) public String sslCfgForm(Model model, String ids, AppSslCertCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppSslCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appSslCfgForm"; } /** * APP ssl证书特征配置(新增/修改)提交 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppSslCfg" }) @RequiresPermissions(value = { "app:ssl:config" }) public String saveAppSslCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppSslCertCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppSslCfg(entity); //配置仅保存 if(StringUtil.isEmpty(entity.getIsValid()) || entity.getIsValid()!=1) { addMessage(redirectAttributes, "success", "save_success"); }else { //配置直接生效 addMessage(redirectAttributes, "success", "audit_success"); } } catch (Exception e) { e.printStackTrace(); logger.error("saveAppSslCfg failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/sslCfgList?functionId=" + entity.getFunctionId(); } /** * APP ssl证书特征配置 审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppSslCfg" }) @RequiresPermissions(value = { "app:ssl:confirm" }) public String auditAppSslCfg(Model model, @ModelAttribute("cfg") AppSslCertCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppSslCertCfg entity = new AppSslCertCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppSslCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); entity.setFunctionId(functionId); try { appCfgService.auditAppSslCfg(entity, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("app SSL配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); try { BeanUtils.copyProperties(searchPage, auditPage); auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return sslCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/sslCfgList?functionId=" + functionId; } /** * APP ssl证书特征配置 删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppSslCfgValid" }) @RequiresPermissions(value = { "app:ssl:config" }) public String updateAppSslCfgValid(Integer isValid, String ids, Integer functionId) { appCfgService.updateAppSslCfgValid(isValid, ids, functionId); return "redirect:" + adminPath + "/app/sslCfgList?functionId=" + functionId; } /** * APP TCP会话字节数特征 列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "tcpCfgList" }) public String tcpCfgList(Model model, @ModelAttribute("cfg") AppTcpCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppTcpList(searchPage, cfg); for (AppTcpCfg entity : page.getList()) { SpecificServiceCfg app = specificServiceCfgService.getBySpecServiceId(entity.getSpecServiceId()); if(app!=null){ entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appTcpCfgList"; } /** * APP TCP会话字节数特征表单(新增/修改) * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "tcpCfgForm" }) @RequiresPermissions(value = { "app:tcp:config" }) public String tcpCfgForm(Model model, String ids, AppTcpCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppTcpCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appTcpCfgForm"; } /** * APP TCP会话字节数特征配置(新增/修改)提交 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppTcpCfg" }) @RequiresPermissions(value = { "app:tcp:config" }) public String saveAppTcpCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppTcpCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppTcpeCfg(entity); addMessage(redirectAttributes, "success", "save_success"); } catch (Exception e) { e.printStackTrace(); logger.error("saveAppTcpCfg failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/tcpCfgList?functionId=" + entity.getFunctionId(); } /** * APP TCP会话字节数特征配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppTcpCfgValid" }) @RequiresPermissions(value = { "app:tcp:config" }) public String updateAppTcpCfgValid(Integer isValid, String ids, Integer functionId) { appCfgService.updateAppTcpCfgValid(isValid, ids, functionId); return "redirect:" + adminPath + "/app/tcpCfgList?functionId=" + functionId; } /** * APP TCP会话字节数特征配置 审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppTcpCfg" }) @RequiresPermissions(value = { "app:tcp:confirm" }) public String auditAppTcpCfg(Integer isAudit, Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes,HttpServletRequest request) { AppTcpCfg entity = new AppTcpCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppTcpCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); entity.setFunctionId(functionId); try { appCfgService.auditAppTcpCfg(entity, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("app SSL配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } return "redirect:" + adminPath + "/app/tcpCfgList?functionId=" + functionId; } /** * APP header特征配置 列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "headerCfgList" }) public String headerCfgList(Model model, @ModelAttribute("cfg") AppHeaderCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppHeaderList(searchPage, cfg); for (AppHeaderCfg entity : page.getList()) { // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setAppName(app.getSpecServiceName()); } } model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appHeaderCfgList"; } /** * APP header特征配置表单 (修改/新增) * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "headerCfgForm" }) @RequiresPermissions(value = { "app:header:config" }) public String headerCfgForm(Model model, String ids, AppHeaderCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppHeaderCfg(Long.parseLong(ids)); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(entity.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); entity.setSpecServiceId(app.getSpecServiceId()); } initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appHeaderCfgForm"; } /** * APP header特征配置 (新增/修改)表单提交 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppHeaderCfg" }) @RequiresPermissions(value = { "app:header:config" }) public String saveAppHeaderCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppHeaderCfg entity, RedirectAttributes redirectAttributes) { try { SpecificServiceCfg specificService = specificServiceCfgService .getBySpecServiceId(entity.getSpecServiceId()); if (specificService != null) { entity.setAppCode(specificService.getSpecServiceCode()); } appCfgService.saveOrUpdateAppHeaderCfg(entity); addMessage(redirectAttributes, "success", "save_success"); } catch (Exception e) { e.printStackTrace(); logger.error("saveAppHeaderCfg failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/headerCfgList?functionId=" + entity.getFunctionId(); } /** * APP header特征配置 审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppHeaderCfg" }) @RequiresPermissions(value = { "app:header:confirm" }) public String auditAppHeaderCfg(Integer isAudit, Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes,HttpServletRequest request) { AppHeaderCfg entity = new AppHeaderCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppHeaderCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); entity.setFunctionId(functionId); try { appCfgService.auditAppHeaderCfg(entity, isAudit); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("app Header配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } return "redirect:" + adminPath + "/app/headerCfgList?functionId=" + functionId; } /** * APP header特征配置 删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppHeaderCfgValid" }) @RequiresPermissions(value = { "app:header:config" }) public String updateAppHeaderCfgValid(Integer isValid, String ids, Integer functionId) { appCfgService.updateAppHeaderCfgValid(isValid, ids, functionId); return "redirect:" + adminPath + "/app/headerCfgList?functionId=" + functionId; } /** * 主题网站配置列表 * * @param model * @param cfg * @param request * @param response * @return */ @RequestMapping(value = { "topicDomainCfgList" }) public String TopicDomainCfgList(Model model, @ModelAttribute("cfg") AppTopicDomainCfg cfg, HttpServletRequest request, HttpServletResponse response) { Page searchPage = new Page(request, response, "r"); Page page = appCfgService.findAppTopicDomainList(searchPage, cfg); model.addAttribute("page", page); initPageCondition(model, cfg); return "/cfg/app/appTopicDomainCfgList"; } /** * * 获取服务与主题关系表中的域名 * * @param websiteDomainTopic * @param response * @return */ @ResponseBody @RequestMapping(value = "WebsiteDomainTopicList", method = RequestMethod.GET) public List> WebsiteDomainTopicList( @ModelAttribute("websiteDomainTopic") WebsiteDomainTopic websiteDomainTopic, @RequestParam("websiteServiceId") Long websiteServiceId, @RequestParam("topicId") Long topicId, HttpServletResponse response) { List> mapList = Lists.newArrayList(); if (websiteServiceId != null && topicId != null) { List list = appCfgService.getDomainDict(websiteDomainTopic); if (list != null && list.size() > 0) { for (WebsiteDomainTopic domain : list) { Map map = Maps.newHashMap(); map.put("domain", domain.getDomain()); map.put("domainId", domain.getId()); mapList.add(map); } } } return mapList; } /** * app主题网站配置表单 * * @param model * @param ids * @param entity * @return */ @RequestMapping(value = { "topicDomainCfgForm" }) @RequiresPermissions(value = { "app:topic:config" }) public String topicDomainCfgForm(Model model, String ids, @ModelAttribute("_cfg") AppTopicDomainCfg entity) { if (StringUtils.isNotBlank(ids)) { entity = appCfgService.getAppTopicDomainCfg(Long.parseLong(ids)); initUpdateFormCondition(model, entity); } else { initFormCondition(model, entity); } model.addAttribute("_cfg", entity); return "/cfg/app/appTopicDomainCfgForm"; } /** * app主题网站配置新增修改 * * @param model * @param request * @param response * @param entity * @param redirectAttributes * @return */ @RequestMapping(value = { "saveAppTopicDomainCfg" }) @RequiresPermissions(value = { "app:topic:config" }) public String saveAppTopicDomainCfg(Model model, HttpServletRequest request, HttpServletResponse response, AppTopicDomainCfg entity, RedirectAttributes redirectAttributes) { try { // 验证域名的重复行 if (!StringUtil.isBlank(entity.getCfgKeywords())) { WebsiteDomainTopic websiteDomainTopic = new WebsiteDomainTopic(); websiteDomainTopic.setDomain(entity.getCfgKeywords()); List domainDict = appCfgService.getDomainDict(websiteDomainTopic); if ((domainDict == null || domainDict.size() == 0)) { // 保存到域名关联表中 if (entity != null && entity.getWebsiteServiceId() != null && entity.getTopicId() != null) { websiteDomainTopic.setWebsiteServiceId(entity.getWebsiteServiceId()); websiteDomainTopic.setTopicId(entity.getTopicId()); websiteDomainTopic.setCreateTime(new Date()); websiteDomainTopic.setCreatorId(Integer.valueOf(UserUtils.getUser().getId().toString())); websiteDomainTopic.setIsValid(Constants.VALID_YES); appCfgService.saveDomainDict(websiteDomainTopic); } else { addMessage(redirectAttributes, "error", "save_failed"); return "redirect:" + adminPath + "/app/topicDomainCfgList?functionId=" + entity.getFunctionId(); } } } if (entity != null && StringUtil.isBlank(entity.getCfgKeywords()) && !StringUtil.isBlank(entity.getCfgKeywords())) { entity.setCfgKeywords(entity.getCfgKeywords()); } appCfgService.saveOrUpdateAppTopicDomainCfg(entity); //配置仅保存 if(StringUtil.isEmpty(entity.getIsValid()) || entity.getIsValid()!=1) { addMessage(redirectAttributes, "success", "save_success"); }else { //配置直接生效 addMessage(redirectAttributes, "success", "audit_success"); } } catch (MaatConvertException e) { logger.error("APP主题网站配置下发失败:",e); addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } catch (Exception e) { logger.error("APP主题网站配置保存失败:",e); addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } return "redirect:" + adminPath + "/app/topicDomainCfgList?functionId=" + entity.getFunctionId(); } /** * domain配置审核 * * @param isAudit * @param isValid * @param ids * @param functionId * @param redirectAttributes * @return */ @RequestMapping(value = { "auditAppTopicDomainCfg" }) // @RequiresPermissions(value={"app:domain:confirm"}) public String auditAppTopicDomainCfg(Model model, @ModelAttribute("cfg") AppTopicDomainCfg cfg, Integer isValid, Integer isAudit, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletResponse response, HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { AppTopicDomainCfg entity = new AppTopicDomainCfg(); String[] idArray = ids.split(","); for (String id : idArray) { entity = appCfgService.getAppTopicDomainCfg(Long.parseLong(id)); entity.setIsAudit(isAudit); entity.setIsValid(isValid); entity.setFunctionId(functionId); try { appCfgService.auditAppTopicDomainCfg(entity, isAudit,Constants.INSERT_ACTION); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("app主题网站配置下发失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } else { Page searchPage = new Page(request, response, "r"); Page auditPage = new Page(request, response, "r"); try { BeanUtils.copyProperties(searchPage, auditPage); auditAll(auditPage, isValid, cfg); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { logger.error("配置下发失败:", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } return TopicDomainCfgList(model, cfg, request, response); } return "redirect:" + adminPath + "/app/topicDomainCfgList?functionId=" + functionId; } /** * 网站主题配置删除 * * @param isValid * @param ids * @param functionId * @return */ @RequestMapping(value = { "updateAppTopicDomainCfgValid" }) @RequiresPermissions(value = { "app:topic:config" }) public String updateAppTopicDomainCfgValid(Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg")AppTopicDomainCfg cfg) { try { if (!StringUtil.isEmpty(ids)) { appCfgService.updateAppTopicDomainCfgValid(isValid, ids, functionId); addMessage(redirectAttributes, "success", "delete_success"); }else { // 批量删除 Page searchPage = new Page(request, response, "a"); deleteAll(searchPage, functionId, cfg); } } catch (Exception e) { logger.error("app主题网站删除失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else if (e instanceof CallExternalProceduresException) { addMessage(redirectAttributes, "error", "call_external_procedures_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "delete_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/topicDomainCfgList?functionId=" + functionId; } /********************** 内置APP特征文件上传 *******************************/ @RequestMapping(value = { "/appBuiltinFeatureFileForm" }) @RequiresPermissions(value = { "app:built_in_file:config" }) public String from(Model model, HttpServletRequest request, HttpServletResponse response, String ids, @ModelAttribute("cfg") AppBuiltInFeatureFile cfg, RedirectAttributes redirectAttributes) { if (cfg == null) { cfg = new AppBuiltInFeatureFile(); } if (!StringUtil.isEmpty(ids)) { cfg = appBuiltInFeatureService.getAppBuiltInFeatureFile(Long.valueOf(ids), -1); initFormCondition(model, cfg); model.addAttribute("isAdd", false); } else { initFormCondition(model, cfg); model.addAttribute("isAdd", true); } model.addAttribute("_cfg", cfg); return "/cfg/app/appBuiltinFeatureFileForm"; } @RequestMapping(value = { "/appBuiltinFeatureFileSaveOrUpdate" }) @RequiresPermissions(value = { "app:built_in_file:config" }) public String saveOrUpdate(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppBuiltInFeatureFile cfg, MultipartFile file, RedirectAttributes redirectAttributes) { File fileD = null; try { if (file != null) { String filename = file.getOriginalFilename(); String prefix = FileUtils.getPrefix(filename, false); String suffix = FileUtils.getSuffix(filename, false); fileD = File.createTempFile("file_" + prefix, suffix); file.transferTo(fileD);// 复制文件 String md5 = FileUtils.getFileMD5(fileD); Map srcMap = Maps.newHashMap(); srcMap.put("filetype", suffix); srcMap.put("datatype", "dbSystem");// 源文件存入数据中心 srcMap.put("createTime", new Date()); srcMap.put("key", prefix); srcMap.put("fileName", filename); srcMap.put("checksum", md5); ToMaatResult result = ConfigServiceUtil.postFileCfg(null, fileD, JsonMapper.toJsonString(srcMap)); logger.info("APP 内置特征 文件上传响应信息:" + JsonMapper.toJsonString(result)); String accessUrl = null; if (!StringUtil.isEmpty(result)) { ResponseData data = result.getData(); accessUrl = data.getAccessUrl(); cfg.setFilePath(accessUrl); ; } } appBuiltInFeatureService.saveOrUpdate(cfg); addMessage(redirectAttributes, "success", "save_success"); } catch (Exception e) { e.printStackTrace(); logger.error("appBuiltinFeatureFileSaveOrUpdate failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "save_failed"); LogUtils.saveLog(request, null, e, null); } } return "redirect:" + adminPath + "/app/appBuiltinFeatureFileList?functionId=" + cfg.getFunctionId(); } @RequestMapping(value = { "/appBuiltinFeatureFileList" }) public String list(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppBuiltInFeatureFile entity, RedirectAttributes redirectAttributes) { Page page = appBuiltInFeatureService .findPage(new Page(request, response, "r"), entity); model.addAttribute("page", page); initPageCondition(model); return "/cfg/app/appBuiltinFeatureFileList"; } @RequestMapping(value = { "/appBuiltinFeatureFileDelete" }) @RequiresPermissions(value = { "app:built_in_file:config" }) public String delete(Integer isAudit, Integer isValid, String ids, Integer functionId, Model model, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) { if (!StringUtil.isEmpty(ids)) { appBuiltInFeatureService.delete(isAudit, isValid, ids, functionId); } return "redirect:" + adminPath + "/app/appBuiltinFeatureFileList?functionId=" + functionId; } @RequestMapping(value = { "/audit" }) @RequiresPermissions(value = { "app:built_in_file:confirm" }) public String audit(Integer isAudit, Integer isValid, String ids, Integer functionId, RedirectAttributes redirectAttributes,HttpServletRequest request) { if (!StringUtil.isEmpty(ids)) { String[] idArray = ids.split(","); Date auditTime = new Date(); for (String id : idArray) { try { appBuiltInFeatureService.audit(isAudit, isValid, functionId, id, auditTime); addMessage(redirectAttributes, "success", "audit_success"); } catch (Exception e) { e.printStackTrace(); logger.error("appBuiltinFeature audit failed", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); LogUtils.saveLog(request, null, e, null); } else { addMessage(redirectAttributes, "error", "audit_failed"); LogUtils.saveLog(request, null, e, null); } } } } return "redirect:" + adminPath + "/app/appBuiltinFeatureFileList?functionId=" + functionId; } @ResponseBody @RequestMapping(value = "/validCfgId") public boolean validCfgId(Long cfgId) { AppBuiltInFeatureFile dns = appBuiltInFeatureService.getAppBuiltInFeatureFile(cfgId, null); if (dns == null) { return false; } else { return true; } } // ip配置导出 @RequestMapping(value = "exportIpAddr") public void exportIpAddr(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppPolicyCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); // 导出选中记录 if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppByPolicyList(ids); } else { entity.setTableName(IpPortCfg.getTablename()); Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppPolicyList(pageInfo, entity); ipLists = page.getList(); } List> logTotals=new ArrayList>(); StringBuilder compileIds=new StringBuilder(","); Set set=new HashSet(); for (AppPolicyCfg policy : ipLists) { if(policy.getIsAudit()!=0){ set.add(policy.getServiceId()); compileIds.append(policy.getCompileId()+","); }else{ Map logTotal=new HashMap(); logTotal.put("compileId", policy.getCompileId()+""); logTotal.put("sum",0L); logTotals.add(logTotal); } // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(policy.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); policy.setSocialName(app.getSpecServiceName()); } } StringBuilder serviceIds=new StringBuilder(","); for (Integer id : set) { serviceIds.append(id+","); } if(serviceIds.length()>1&&compileIds.length()>1){ String serviceIdsStr=serviceIds.toString().substring(1, serviceIds.length()-1); String compileIdsStr=compileIds.toString().substring(1, compileIds.length()-1); //获取日志总量 if(!StringUtils.isBlank(serviceIdsStr)&&!StringUtils.isBlank(compileIdsStr)){ List> logs = getLogTotal( null,serviceIdsStr,compileIdsStr); logTotals.addAll(logs); } } // 查找社交应用的所有有效二级特定服务 SpecificServiceCfg second = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { second.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } second.setIsValid(Constants.VALID_YES); second.setIsLeaf(1); List secondList = specificServiceCfgService.findAllSpecificServiceCfg(second, null); // 遍历,找到匹配项后将行为设置进去 for (AppPolicyCfg policy : ipLists) { for (Map logTotal : logTotals) { if(policy.getCompileId().equals(Integer.parseInt((String) logTotal.get("compileId")))){ policy.setTotalLogs((Long)logTotal.get("sum")); break; } } if (policy.getBehavCode() == null) continue; for (SpecificServiceCfg secondCfg : secondList) { if (secondCfg.getSpecServiceCode() == null) continue; if (secondCfg.getSpecServiceCode().intValue() == policy.getBehavCode().intValue()) { policy.setBehavName(secondCfg.getSpecServiceName()); break; } } } titleList.add(entity.getMenuNameCode()); titleList.add("NTC_IP"); titleList.add("NTC_SUBSCRIBE_ID"); classMap.put(entity.getMenuNameCode(), AppPolicyCfg.class); classMap.put("NTC_IP", IpPortCfg.class); classMap.put("NTC_SUBSCRIBE_ID", NtcSubscribeIdCfg.class); String cfgIndexInfoNoExport = ",do_blacklist,encrypted_tunnel_behavior,basic_protocol,expression_type,match_method,whether_hexbinary,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; String ipPortInfoNoExport = ",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + ",config_time,editor,edit_time,auditor,audit_time" + ",letter,whether_area_block,classification,attribute,label" + ",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,"; String subscribeInfoNoExport = ",do_log,action,config_describe,valid_identifier,is_audit,creator,creator" + ",config_time,editor,edit_time,auditor,audit_time" + ",letter,whether_area_block,classification,attribute,label" + ",userregion1,userregion2,userregion3,userregion4,userregion5,ir_type,group_name,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); noExportMap.put("NTC_IP", ipPortInfoNoExport); noExportMap.put("NTC_SUBSCRIBE_ID", subscribeInfoNoExport); List ipList = new ArrayList(); List subscribeInfoList = new ArrayList(); for (AppPolicyCfg cfg : ipLists) { AppPolicyCfg cfgIndexInfo = appCfgService.exportIpInfo(cfg); ipList.addAll(cfgIndexInfo.getIpPortList()); subscribeInfoList.addAll(cfgIndexInfo.getNtcSubscribeIdCfgList()); } subscribeInfoList = BaseStringCfg.baseHexList(subscribeInfoList); dataMap.put(entity.getMenuNameCode(), ipLists); dataMap.put("NTC_IP", ipList); dataMap.put("NTC_SUBSCRIBE_ID", subscribeInfoList); /* } */ 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("ip addr export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } // top @RequestMapping(value = "exportTop") public void exportTop(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppTopicDomainCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); // 导出选中记录 if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppByTopicDomainList(ids); } else { Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppTopicDomainList(pageInfo, entity); ipLists = page.getList(); } for (int i = 0; i < ipLists.size(); i++) { AppTopicDomainCfg appTop = ipLists.get(i); appTop.setIsHex(appTop.getIsHexbin()); // '默认为0:大小写不敏感,且非HEX;1:HEX格式二进制;2:大小写敏感,且非HEX', if(appTop.getIsHexbin()==2){ appTop.setIsCaseInsenstive(1); }else{ appTop.setIsCaseInsenstive(0); } } titleList.add(entity.getMenuNameCode()); classMap.put(entity.getMenuNameCode(), AppTopicDomainCfg.class); String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); dataMap.put(entity.getMenuNameCode(), ipLists); /* } */ 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("top export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } // appIp配置导出 @RequestMapping(value = "exportAppIp") public void exportAppIp(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppIpCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); // 导出选中记录 if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppByIpList(ids); } else { Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppIpList(pageInfo, entity); ipLists = page.getList(); } for (AppIpCfg appIp : ipLists) { SpecificServiceCfg app = specificServiceCfgService.getBySpecServiceId(appIp.getSpecServiceId()); if(app!=null){ appIp.setAppName(app.getSpecServiceName()); } } titleList.add(entity.getMenuNameCode()); classMap.put(entity.getMenuNameCode(), AppIpCfg.class); String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,client_port,ir_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); dataMap.put(entity.getMenuNameCode(), ipLists); /* } */ 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("appIp export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } // appHttp配置导出 @RequestMapping(value = "exportAppHttp") public void exportAppHttp(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppHttpCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); // 导出选中记录 if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppByHttpList(ids); } else { Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppHttpList(pageInfo, entity); ipLists = page.getList(); } for (AppHttpCfg http : ipLists) { http.setIsHex(http.getIsHexbin()); // '默认为0:大小写不敏感,且非HEX;1:HEX格式二进制;2:大小写敏感,且非HEX', if(http.getIsHexbin()==2){ http.setIsCaseInsenstive(1); }else{ http.setIsCaseInsenstive(0); } http.setCfgKeywords(Functions.replace(http.getCfgKeywords(), "***and***", " ")); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(http.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); http.setAppName(app.getSpecServiceName()); } } titleList.add(entity.getMenuNameCode()); classMap.put(entity.getMenuNameCode(), AppHttpCfg.class); String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,client_port,ir_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); dataMap.put(entity.getMenuNameCode(), ipLists); /* } */ 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("http export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } // appdomain配置导出 @RequestMapping(value = "exportDomain") public void exportDomain(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppDomainCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppByDomainList(ids); } else { Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppDomainList(pageInfo, entity); ipLists = page.getList(); } for (AppDomainCfg domain : ipLists) { domain.setIsHex(domain.getIsHexbin()); // '默认为0:大小写不敏感,且非HEX;1:HEX格式二进制;2:大小写敏感,且非HEX', if(domain.getIsHexbin()==2){ domain.setIsCaseInsenstive(1); }else{ domain.setIsCaseInsenstive(0); } // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(domain.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); domain.setAppName(app.getSpecServiceName()); } } titleList.add(entity.getMenuNameCode()); classMap.put(entity.getMenuNameCode(), AppDomainCfg.class); String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,client_port,ir_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); dataMap.put(entity.getMenuNameCode(), ipLists); /* } */ 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("Domain export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } // appssl配置导出 @RequestMapping(value = "exportAppSsl") public void exportAppSsl(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute("cfg") AppSslCertCfg entity, String ids, RedirectAttributes redirectAttributes) { try { // export data info List titleList = new ArrayList(); Map> classMap = new HashMap>(); Map dataMap = new HashMap(); Map noExportMap = new HashMap(); List ipLists = new ArrayList(); if (!StringUtil.isEmpty(ids)) { ipLists = appCfgService.findAppBySslList(ids); } else { Page pageInfo = new Page(request, response, "r"); pageInfo.setPageNo(1); pageInfo.setPageSize(Constants.MAX_EXPORT_SIZE); Page page = appCfgService.findAppSslList(pageInfo, entity); ipLists = page.getList(); } for (AppSslCertCfg ssl : ipLists) { ssl.setIsHex(ssl.getIsHexbin()); // '默认为0:大小写不敏感,且非HEX;1:HEX格式二进制;2:大小写敏感,且非HEX', if(ssl.getIsHexbin()==2){ ssl.setIsCaseInsenstive(1); }else{ ssl.setIsCaseInsenstive(0); } ssl.setCfgKeywords(Functions.replace(ssl.getCfgKeywords(), "***and***", " ")); // 查找社交应用的所有有效一级特定服务 SpecificServiceCfg appSpec = new SpecificServiceCfg(); for (SysDataDictionaryItem dict : DictUtils.getDictList("SPECIFIC_SERVICE_CFG_TYPE")) { if (Constants.SPECIFIC_SERVICE_CFG_TYPE_APP.equals(dict.getItemValue())) { appSpec.setCfgType(Integer.parseInt(dict.getItemCode())); break; } } appSpec.setIsValid(Constants.VALID_YES); appSpec.setIsLeaf(0); appSpec.setSpecServiceCode(ssl.getAppCode()); List appList = specificServiceCfgService.findAllSpecificServiceCfg(appSpec, null); if (!StringUtil.isEmpty(appList)) { SpecificServiceCfg app = appList.get(0); ssl.setAppName(app.getSpecServiceName()); } } titleList.add(entity.getMenuNameCode()); classMap.put(entity.getMenuNameCode(), AppSslCertCfg.class); String cfgIndexInfoNoExport = ",letter,whether_area_block,classification,attribute,label,do_log,block_type,client_port,ir_type,group_name,userregion1,userregion2,userregion3,userregion4,userregion5,"; // 时间过滤 if (entity.getSearch_create_time_start() == null && entity.getSearch_create_time_end() == null) { cfgIndexInfoNoExport = ",config_time" + cfgIndexInfoNoExport; } if (entity.getSearch_edit_time_start() == null && entity.getSearch_edit_time_end() == null) { cfgIndexInfoNoExport = ",edit_time" + cfgIndexInfoNoExport; } if (entity.getSearch_audit_time_start() == null && entity.getSearch_audit_time_end() == null) { cfgIndexInfoNoExport = ",audit_time" + cfgIndexInfoNoExport; } if (!StringUtil.isEmpty(entity.gethColumns())) { cfgIndexInfoNoExport = "," + entity.gethColumns() + "," + cfgIndexInfoNoExport; } noExportMap.put(entity.getMenuNameCode(), cfgIndexInfoNoExport); dataMap.put(entity.getMenuNameCode(), ipLists); /* } */ 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("App ssl export failed", e); addMessage(redirectAttributes, "error", "export_failed"); LogUtils.saveLog(request, null, e, null); } // return "redirect:" + adminPath // +"/ntc/iplist/list?functionId="+entity.getFunctionId(); } }