2018-03-17 17:09:19 +08:00
|
|
|
|
package com.nis.web.controller.specific;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
import java.util.Properties;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import com.google.gson.JsonArray;
|
|
|
|
|
|
import com.nis.domain.ImportErrorInfo;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import com.nis.domain.Page;
|
2018-03-22 18:22:09 +08:00
|
|
|
|
import com.nis.domain.specific.SpecificServiceCfg;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import com.nis.domain.specific.SpecificServiceHostCfg;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import com.nis.util.Configurations;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
2018-06-11 10:58:06 +08:00
|
|
|
|
import com.nis.util.excel.ExportExcel;
|
|
|
|
|
|
import com.nis.util.excel.ImportExcel;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
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)){
|
|
|
|
|
|
return specificServiceHostCfgService.getDictByHostId(hostId);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return new SpecificServiceHostCfg();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 分页查询
|
|
|
|
|
|
* @param specificServiceHostCfg
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @param model
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-28 08:42:32 +08:00
|
|
|
|
@RequiresPermissions("specific:serviceIp:view")
|
2018-03-17 17:09:19 +08:00
|
|
|
|
@RequestMapping(value = "list")
|
|
|
|
|
|
public String list(SpecificServiceHostCfg specificServiceHostCfg, HttpServletRequest request, HttpServletResponse response,
|
|
|
|
|
|
Model model) {
|
|
|
|
|
|
|
|
|
|
|
|
//查出分页数据
|
|
|
|
|
|
Page<SpecificServiceHostCfg> page = specificServiceHostCfgService.findSpecHostList(new Page<SpecificServiceHostCfg>(request, response), specificServiceHostCfg);
|
|
|
|
|
|
model.addAttribute("page", page);
|
2018-03-22 18:22:09 +08:00
|
|
|
|
//查询特定服务管理(specific_service_cfg)协议id供下拉选择
|
|
|
|
|
|
List<SpecificServiceCfg> listSpecService = specificServiceCfgService.findAllSpecificServiceCfg(new SpecificServiceCfg(), "spec_service_id DESC");
|
|
|
|
|
|
model.addAttribute("listSpecService", listSpecService);
|
2018-03-17 17:09:19 +08:00
|
|
|
|
return "/specific/specificServiceHostCfgList";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 进入查看、修改或新增页面
|
|
|
|
|
|
* @param specificServiceHostCfg
|
|
|
|
|
|
* @param request
|
|
|
|
|
|
* @param response
|
|
|
|
|
|
* @param model
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-06-11 10:58:06 +08:00
|
|
|
|
@RequiresPermissions("specific:serviceIp:edit")
|
2018-03-17 17:09:19 +08:00
|
|
|
|
@RequestMapping(value = "form")
|
|
|
|
|
|
public String form(SpecificServiceHostCfg specificServiceHostCfg, HttpServletRequest request, HttpServletResponse response, Model model) {
|
2018-03-22 18:22:09 +08:00
|
|
|
|
//查询协议id供下拉选择
|
|
|
|
|
|
List<SpecificServiceCfg> listSpecService = specificServiceCfgService.findAllSpecificServiceCfg(new SpecificServiceCfg(), "spec_service_id DESC");
|
|
|
|
|
|
model.addAttribute("listSpecService", listSpecService);
|
2018-03-17 17:09:19 +08:00
|
|
|
|
return "/specific/specificServiceHostCfgForm";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 新增或修改
|
|
|
|
|
|
* @param specificServiceHostCfg
|
|
|
|
|
|
* @param model
|
|
|
|
|
|
* @param redirectAttributes
|
|
|
|
|
|
* @param mulitId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-06-11 10:58:06 +08:00
|
|
|
|
@RequiresPermissions("specific:serviceIp:edit")
|
2018-03-17 17:09:19 +08:00
|
|
|
|
@RequestMapping(value = "saveOrUpdate")
|
|
|
|
|
|
public String saveOrUpdate(SpecificServiceHostCfg specificServiceHostCfg,Model model,RedirectAttributes redirectAttributes){
|
|
|
|
|
|
try {
|
|
|
|
|
|
specificServiceHostCfgService.saveOrUpdate(specificServiceHostCfg);
|
2018-03-29 18:45:37 +08:00
|
|
|
|
addMessage(redirectAttributes, "save_success");
|
2018-03-17 17:09:19 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
2018-03-29 18:45:37 +08:00
|
|
|
|
addMessage(redirectAttributes, "save_failed");
|
2018-03-17 17:09:19 +08:00
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
2018-03-17 17:09:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除
|
|
|
|
|
|
* @param specificServiceHostCfg
|
|
|
|
|
|
* @param redirectAttributes
|
|
|
|
|
|
* @param mulitId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-06-11 10:58:06 +08:00
|
|
|
|
@RequiresPermissions("specific:serviceIp:edit")
|
2018-03-17 17:09:19 +08:00
|
|
|
|
@RequestMapping(value="delete")
|
|
|
|
|
|
public String delete(SpecificServiceHostCfg specificServiceHostCfg, RedirectAttributes redirectAttributes, String mulitId){
|
|
|
|
|
|
try{
|
|
|
|
|
|
specificServiceHostCfgService.delete(mulitId);
|
2018-03-29 18:45:37 +08:00
|
|
|
|
addMessage(redirectAttributes,"delete_success");
|
2018-03-17 17:09:19 +08:00
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
e.printStackTrace();
|
2018-03-29 18:45:37 +08:00
|
|
|
|
addMessage(redirectAttributes,"delete_failed");
|
2018-03-17 17:09:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
|
|
|
|
|
}
|
2018-06-11 10:58:06 +08:00
|
|
|
|
@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());
|
2018-06-15 09:33:53 +08:00
|
|
|
|
new ExportExcel(msgProp,msgProp.getProperty("agreement_ip_configuration"), SpecificServiceHostCfg.class, 2).setDataList(msgProp,list,null).
|
2018-06-11 10:58:06 +08:00
|
|
|
|
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{
|
2018-06-11 17:47:44 +08:00
|
|
|
|
addMessage(redirectAttributes, "import_success");
|
2018-06-11 10:58:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
return "redirect:"+adminPath+"/specific/specificServiceHostCfg/list";
|
|
|
|
|
|
// return renderString(response,errorInfos);
|
|
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 校验spec_service_id重复
|
|
|
|
|
|
* @param newId
|
|
|
|
|
|
* @param oldId
|
|
|
|
|
|
*/
|
2018-03-22 18:22:09 +08:00
|
|
|
|
/* @ResponseBody
|
2018-03-21 13:43:43 +08:00
|
|
|
|
@RequestMapping(value = "isSpecServiceIdRepeat")
|
|
|
|
|
|
public boolean isSpecServiceIdRepeat(String newId,String oldId){
|
|
|
|
|
|
if(oldId!=null){
|
|
|
|
|
|
oldId.trim().equals(newId);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
SpecificServiceHostCfg sshc = specificServiceHostCfgService.getBySpecServiceId(Integer.valueOf(newId));
|
|
|
|
|
|
if(sshc==null){
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
2018-03-22 18:22:09 +08:00
|
|
|
|
}*/
|
2018-03-17 17:09:19 +08:00
|
|
|
|
}
|