协议IP配置增加导入功能
This commit is contained in:
@@ -1,34 +1,39 @@
|
||||
package com.nis.web.controller.specific;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
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.gson.JsonArray;
|
||||
import com.nis.domain.ImportErrorInfo;
|
||||
import com.nis.domain.Page;
|
||||
import com.nis.domain.specific.SpecificServiceCfg;
|
||||
import com.nis.domain.specific.SpecificServiceHostCfg;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.excel.ExportExcel;
|
||||
import com.nis.util.excel.ImportExcel;
|
||||
import com.nis.web.controller.BaseController;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/specific/specificServiceHostCfg")
|
||||
public class SpecificServiceHostCfgController extends BaseController {
|
||||
|
||||
|
||||
@ModelAttribute
|
||||
public SpecificServiceHostCfg get(@RequestParam(required=false) Integer hostId) {
|
||||
if (!StringUtil.isEmpty(hostId)){
|
||||
@@ -68,7 +73,7 @@ public class SpecificServiceHostCfgController extends BaseController {
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions(value= {"specific:serviceIp:add","specific:serviceIp:edit"},logical=Logical.OR)
|
||||
@RequiresPermissions("specific:serviceIp:edit")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(SpecificServiceHostCfg specificServiceHostCfg, HttpServletRequest request, HttpServletResponse response, Model model) {
|
||||
//查询协议id供下拉选择
|
||||
@@ -85,7 +90,7 @@ public class SpecificServiceHostCfgController extends BaseController {
|
||||
* @param mulitId
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions(value= {"specific:serviceIp:add","specific:serviceIp:edit"},logical=Logical.OR)
|
||||
@RequiresPermissions("specific:serviceIp:edit")
|
||||
@RequestMapping(value = "saveOrUpdate")
|
||||
public String saveOrUpdate(SpecificServiceHostCfg specificServiceHostCfg,Model model,RedirectAttributes redirectAttributes){
|
||||
try {
|
||||
@@ -104,7 +109,7 @@ public class SpecificServiceHostCfgController extends BaseController {
|
||||
* @param mulitId
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("specific:serviceIp:del")
|
||||
@RequiresPermissions("specific:serviceIp:edit")
|
||||
@RequestMapping(value="delete")
|
||||
public String delete(SpecificServiceHostCfg specificServiceHostCfg, RedirectAttributes redirectAttributes, String mulitId){
|
||||
try{
|
||||
@@ -117,6 +122,80 @@ public class SpecificServiceHostCfgController extends BaseController {
|
||||
|
||||
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
||||
}
|
||||
@RequiresPermissions("specific:serviceIp:edit")
|
||||
@RequestMapping(value = "import/template")
|
||||
public String importFileTemplate(HttpServletRequest request,HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
||||
Properties msgProp = new Properties();
|
||||
try {
|
||||
String language = LocaleContextHolder.getLocale().getLanguage();
|
||||
if(language.equals("zh_cn")||language.equals("zh")){
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_zh_CN.properties"));
|
||||
}else if(language.equals("ru")){
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_ru.properties"));
|
||||
}else{
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
msgProp = null;
|
||||
System.err.println("未知i18n消息配置文件,请确定文件是否存在!");
|
||||
}
|
||||
try {
|
||||
String fileName = msgProp.getProperty("agreement_ip_configuration").replaceAll(" ", "_")+".xlsx";
|
||||
List<SpecificServiceHostCfg> list = Lists.newArrayList();
|
||||
list.add(new SpecificServiceHostCfg());
|
||||
new ExportExcel(msgProp,msgProp.getProperty("agreement_ip_configuration"), SpecificServiceHostCfg.class, 2).setDataList(list).
|
||||
write(request,response, fileName).dispose();
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
addMessage(redirectAttributes, msgProp.getProperty("import_template_failed")+e.getMessage());
|
||||
}
|
||||
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
||||
}
|
||||
@RequiresPermissions("specific:serviceIp:edit")
|
||||
@RequestMapping(value = "import", method=RequestMethod.POST)
|
||||
public String importFile(HttpServletRequest request,Model model,HttpServletResponse response, RedirectAttributes redirectAttributes,
|
||||
@RequestParam("file") MultipartFile file) {
|
||||
Properties msgProp = new Properties();
|
||||
try {
|
||||
String language = LocaleContextHolder.getLocale().getLanguage();
|
||||
if(language.equals("zh_cn")||language.equals("zh")){
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_zh_CN.properties"));
|
||||
}else if(language.equals("ru")){
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_ru.properties"));
|
||||
}else{
|
||||
msgProp.load(Configurations.class.getResourceAsStream("/messages/message_en.properties"));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
msgProp = null;
|
||||
System.err.println("未知i18n消息配置文件,请确定文件是否存在!");
|
||||
}
|
||||
List<ImportErrorInfo> errorInfos = null;
|
||||
try {
|
||||
ImportExcel ei = new ImportExcel(file, 1, 0);
|
||||
List<SpecificServiceHostCfg> list = ei.getDataList(SpecificServiceHostCfg.class);
|
||||
//查询特定服务管理(specific_service_cfg)协议id供下拉选择
|
||||
List<SpecificServiceCfg> listSpecService = specificServiceCfgService.findAllSpecificServiceCfg(new SpecificServiceCfg(), "spec_service_id DESC");
|
||||
|
||||
errorInfos = specificServiceHostCfgService.importFile(list,listSpecService,msgProp);
|
||||
// if(result){
|
||||
// addMessage(redirectAttributes, msgProp.getProperty("import_success"));
|
||||
// }else{
|
||||
// addMessage(redirectAttributes, msgProp.getProperty("import_error"));
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
addMessage(redirectAttributes, msgProp.getProperty("import_failed")+errorInfos);
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(errorInfos!=null && errorInfos.size()>0){
|
||||
addMessage(redirectAttributes, msgProp.getProperty("import_failed")+errorInfos);
|
||||
}else{
|
||||
addMessage(redirectAttributes, "success");
|
||||
}
|
||||
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
||||
// return renderString(response,errorInfos);
|
||||
}
|
||||
/**
|
||||
* 校验spec_service_id重复
|
||||
* @param newId
|
||||
|
||||
Reference in New Issue
Block a user