基本配置增加csv和excel导出
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.nis.web.controller.specific;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -23,12 +25,19 @@ 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.SysUser;
|
||||
import com.nis.domain.basics.ServiceDictInfo;
|
||||
import com.nis.domain.specific.SpecificServiceCfg;
|
||||
import com.nis.exceptions.MaatConvertException;
|
||||
import com.nis.util.ConfigDictUtils;
|
||||
import com.nis.util.Configurations;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DateUtils;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.util.StringUtil;
|
||||
import com.nis.util.StringUtils;
|
||||
import com.nis.web.controller.BaseController;
|
||||
import com.nis.web.dao.dashboard.codedic.CodeResult;
|
||||
import com.nis.web.security.UserUtils;
|
||||
|
||||
@Controller
|
||||
@@ -490,4 +499,117 @@ public class SpecificServiceCfgController extends BaseController {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Specific配置导出
|
||||
@RequestMapping(value = "exportSpec")
|
||||
public void exportDict(String itType, SpecificServiceCfg specificServiceCfg, Model model, HttpServletRequest request,
|
||||
HttpServletResponse response, String ids, RedirectAttributes redirectAttributes, String exType,
|
||||
String hColumns) {
|
||||
try {
|
||||
// export data info
|
||||
List<String> titleList = new ArrayList<String>();
|
||||
Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
|
||||
Map<String, List> dataMap = new HashMap<String, List>();
|
||||
Map<String, String> noExportMap = new HashMap<String, String>();
|
||||
//--------------------------------------------
|
||||
List<SpecificServiceCfg> list = Lists.newArrayList();
|
||||
//处理数据
|
||||
if (!StringUtil.isEmpty(ids)) {
|
||||
list = specificServiceCfgService.findBySpecificServiceCfg(ids);
|
||||
} else {
|
||||
if(specificServiceCfg.getCfgType()==null){
|
||||
specificServiceCfg.setCfgType(1);
|
||||
}
|
||||
Page<SpecificServiceCfg> pageCondition = new Page<SpecificServiceCfg>(request, response);
|
||||
pageCondition.setPageNo(1);
|
||||
pageCondition.setPageSize(Constants.MAX_EXPORT_SIZE);
|
||||
List<SpecificServiceCfg> allList = specificServiceCfgService.findAllSpecificServiceCfg(specificServiceCfg,pageCondition.getOrderBy());
|
||||
Page<SpecificServiceCfg> page = specificServiceCfgService.findTopPage(pageCondition, specificServiceCfg);
|
||||
// 删除顶层数据、取出id
|
||||
List<Integer> intList = Lists.newArrayList();
|
||||
for (int i = allList.size() - 1; i >= 0; i--) {
|
||||
SpecificServiceCfg ss = allList.get(i);
|
||||
if ((ss != null && intList.contains(ss.getSpecServiceId())) || (ss != null && ss.getParent().getSpecServiceId() == 0)) {
|
||||
allList.remove(ss);
|
||||
}
|
||||
}
|
||||
allList.addAll(page.getList());
|
||||
SpecificServiceCfg.sortList(list, allList, 0, true);
|
||||
SpecificServiceCfg.addChildrenSeq(list, 0);
|
||||
}
|
||||
List<SysDataDictionaryItem> app=DictUtils.getDictList("APP_BUSINESS_TYPE");
|
||||
List<SysDataDictionaryItem> tunnel=DictUtils.getDictList("TUNNEL_BEHAV_BUSINESS_TYPE");
|
||||
List<SysDataDictionaryItem> basic=DictUtils.getDictList("BASIC_PROTOCOL_BUSINESS_TYPE");
|
||||
Properties msgProp = getMsgProp();
|
||||
for (SpecificServiceCfg spec : list) {
|
||||
if (!StringUtils.isEmpty(spec.getBusinessType())) {
|
||||
if (spec.getCfgType() == 1) {
|
||||
spec.setBusinessType(getName(spec.getBusinessType(),app,msgProp));
|
||||
} else if (spec.getCfgType() == 2) {
|
||||
spec.setBusinessType(getName(spec.getBusinessType(),tunnel,msgProp));
|
||||
} else if (spec.getCfgType() == 3) {
|
||||
spec.setBusinessType(getName(spec.getBusinessType(),basic,msgProp));
|
||||
}
|
||||
}
|
||||
}
|
||||
String dictName = "specific_service_cfg";
|
||||
titleList.add(dictName);
|
||||
classMap.put(dictName, SpecificServiceCfg.class);
|
||||
String cfgIndexInfoNoExport = "";
|
||||
if (specificServiceCfg.getCfgType() != null) {
|
||||
if (specificServiceCfg.getCfgType() == 2) {
|
||||
cfgIndexInfoNoExport = ",&app_code:tunnel_code-app_name:tunnel_name-app_desc:tunnel_desc-";
|
||||
} else if (specificServiceCfg.getCfgType() == 3) {
|
||||
cfgIndexInfoNoExport = ",&app_code:protocol_code-app_name:protocol_name-app_desc:protocol_desc-";
|
||||
}
|
||||
}
|
||||
if (specificServiceCfg.getBeginDate() == null) {
|
||||
cfgIndexInfoNoExport = ",operate_time," + cfgIndexInfoNoExport;
|
||||
}
|
||||
|
||||
if (!StringUtil.isEmpty(hColumns)) {
|
||||
cfgIndexInfoNoExport = "," + hColumns + "," + cfgIndexInfoNoExport;
|
||||
}
|
||||
noExportMap.put(dictName, cfgIndexInfoNoExport);
|
||||
dataMap.put(dictName, list);
|
||||
String timeRange = initDictMap(specificServiceCfg, dictName,msgProp);
|
||||
noExportMap.put("timeRange", timeRange);
|
||||
if ("csv".equals(exType)) {
|
||||
this._exportCsv(model, request, response, redirectAttributes, dictName, titleList, classMap, dataMap,
|
||||
noExportMap);
|
||||
} else {
|
||||
this._export(model, request, response, redirectAttributes, dictName, titleList, classMap, dataMap,
|
||||
noExportMap);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("dict white export failed", e);
|
||||
addMessage(redirectAttributes, "error", "export_failed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getName(String id,List<SysDataDictionaryItem> list,Properties msgProp){
|
||||
String name=id;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if(id.equals(list.get(i).getItemCode())){
|
||||
name=msgProp.getProperty(list.get(i).getItemValue(),list.get(i).getItemValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public String initDictMap(SpecificServiceCfg cfg, String dictName,Properties msgProp) {
|
||||
String titleTime =msgProp.getProperty(dictName,dictName) ;
|
||||
if (cfg.getBeginDate() != null) {
|
||||
titleTime += " " + msgProp.getProperty("operate_time") + ":" + DateUtils.formatDateTime(cfg.getBeginDate());
|
||||
if (cfg.getEndDate() != null) {
|
||||
titleTime += "—" + DateUtils.formatDateTime(cfg.getEndDate());
|
||||
} else {
|
||||
titleTime += "—" + DateUtils.getDateTime();
|
||||
}
|
||||
}
|
||||
return titleTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user