Commit e21cad8a by zhangkb

系统导出接口代码提交

parent bf1fa4c7
package com.keymobile.tagmanager.api;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -88,6 +92,19 @@ public class TagFileCtrl {
tagExportService.undoImportExcel(importlogId);
}
@ApiOperation(value = "系统导出(系统id传参样式:4,9,10,23)", notes = "系统导出(系统id传参样式:4,9,10,23)")
@GetMapping(value = "/exportSystem")
public void exportSystem(@RequestParam String systemIdString,HttpServletRequest request,
HttpServletResponse response) throws Exception{
if(StringUtils.isNotBlank(systemIdString)) {
List<Long> systemIds = new ArrayList<>();
String[] systemId = systemIdString.split(",");
for(String sid : systemId) {
systemIds.add(Long.valueOf(sid));
}
tagExportService.exportSystem(systemIds, request, response);
}
}
//----------------------以下为导入系统的时候
......@@ -96,6 +113,4 @@ public class TagFileCtrl {
String userName = UserInfoUtils.getUserName();
return tagExportService.importSystem(userName, file);
}
}
package com.keymobile.tagmanager.remote;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -14,4 +17,11 @@ public interface AuthServiceClient {
@GetMapping(value = "/orgs/findByFullName")
public Org findByFullName(@RequestParam("orgFullName") String orgFullName);
@GetMapping(value = "/domains/{domainId}/catalogs")
public List<Map<String,Object>> catalogs(@PathVariable("domainId") Long domainId);
@GetMapping(value = "/domains/{domainId}/scopes/{scopeId}")
public Map<String,Object> getScopes(@PathVariable("domainId") Long domainId,
@PathVariable("scopeId") Long scopeId);
}
package com.keymobile.tagmanager.service;
import java.io.BufferedOutputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
......@@ -11,9 +14,20 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -63,6 +77,9 @@ public class TagFileService {
@Autowired
private RepoServiceClient repoService;
@Autowired
private AuthServiceClient authService;
/**
* author:zhangkb time:2020-1-17 desc:标签分析excel导出
*/
......@@ -574,4 +591,270 @@ public class TagFileService {
public void undoImportExcel(String importlogId) {
mongoOperations.remove(Query.query(Criteria.where("importId").is(importlogId)), Tag.class);
}
//author:zhangkb time:2020-3-16 desc:系统导出
@SuppressWarnings("unchecked")
public void exportSystem(List<Long> systemIds,HttpServletRequest request,
HttpServletResponse response) throws Exception{
List<SysTag> sysTagList = new ArrayList<>();
//循环根据系统id获取系统详细信息
for(Long systemId : systemIds) {
Map<String,Object> sysMap = authService.getScopes(0L, systemId);
//获取系统属性map
Map<String,Object> optionMap = (Map<String, Object>) sysMap.get("options");
SysTag sysTag = (SysTag) this.map2JavaBean(SysTag.class, optionMap);
sysTagList.add(sysTag);
}
//填充excel
Row row;
int rowIndex = 0;
Workbook workbook = new XSSFWorkbook();//创建HSSFWorkbook对象
Sheet sheet = workbook.createSheet("1.系统");
row = sheet.createRow(rowIndex++);
List<String> titleList = new ArrayList<>();
List<Integer> requiredCell = new ArrayList<>();
this.setTitleListAndRequiredCell(titleList,requiredCell);
//生成excel的title
this.excelTitleStyle(workbook, titleList, requiredCell, row, sheet);
//填充数据
this.fillSystemData(sysTagList, row, sheet, rowIndex);
//返回前台
this.responseWorkbook(workbook, request, response);
}
private void responseWorkbook(Workbook workbook,HttpServletRequest request,
HttpServletResponse response) throws Exception{
String msie = "msie";
String chrome = "chrome";
String windows = "windows";
String firefox = "firefox";
String fileName = "CGNSystem_"+System.currentTimeMillis()+".xlsx";
String browserType = request.getHeader("User-Agent").toLowerCase();
if (browserType.contains(firefox) || browserType.contains(chrome)) {
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
} else if (browserType.contains(msie) || browserType.contains(windows)) {
fileName = URLEncoder.encode(fileName, "UTF-8");
} else {
fileName = new String(fileName.getBytes());
}
response.setHeader("Content-Disposition",
"attachment;filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
BufferedOutputStream bufferedOutPut = new BufferedOutputStream(response.getOutputStream());
workbook.write(bufferedOutPut);
bufferedOutPut.flush();
bufferedOutPut.close();
}
private void fillSystemData(List<SysTag> sysTagList,Row row,Sheet sheet,int rowIndex) {
for(SysTag sysTag : sysTagList) {
int contentCellIndex = 0;
row = sheet.createRow(rowIndex++);
row.createCell(contentCellIndex).setCellValue(sysTag.getSerialNumber());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemCode());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemType());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getCnName());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getName());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getAlias());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getDevNo());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getIntangibleNo());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getItemNo());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getBusinessDomain());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getBusinessFlow());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getCatalog());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getDept());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemIntroduction());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getURL());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getIp());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getContact());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getBusinessSystemNo());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getDocuments());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemPersonInCharge());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getPersonnelList());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getUserList());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemFunction());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getModuleDescription());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getCallRelationship());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getCapabilityBlock());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getMasterData());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getFunctionClassification());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getImportantSystem());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getOrgan());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getServiceObject());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getBusinessDepartment());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getConstructionDepartment());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getOperationDepartment());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getServiceWindow());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemOnlineTime());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemOfflineTime());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getMainVersion());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSecurityProtectionLevel());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getMaintenanceClassification());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getNodeName());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getHardware());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSoftwareAndVersionNo());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getLocationOfDeployment());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getDisasterPreparedness());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getThirdPartyConnection());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemAssociation());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getOtherInstructions());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getInformationApplicationDepartment());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getFillingPerson());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getUpgradingTime());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getMainContentsOfUpgrading());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getDateOfChange());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getCounterpartSector());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getPersonInCharge());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getRecordCreationDate());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getRecordUpdateDate());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getOnLineDate());
contentCellIndex++;
row.createCell(contentCellIndex).setCellValue(sysTag.getSystemState());
}
}
private void setTitleListAndRequiredCell(List<String> titleList,List<Integer> requiredCell) {
titleList.add("序号");titleList.add("系统代码");titleList.add("系统类型");titleList.add("中文名称");
titleList.add("英文名称");titleList.add("曾用名/别名");titleList.add("开发支出资产主数据号");titleList.add("无形资产主数据号");
titleList.add("立项号");titleList.add("业务域");titleList.add("业务流");titleList.add("所属板块");
titleList.add("所属部门");titleList.add("系统简介");titleList.add("网址");titleList.add("IP地址");
titleList.add("系统当前联系人");titleList.add("业务系统编号");titleList.add("项目过程文档");titleList.add("系统创建负责人");
titleList.add("研发人员名单");titleList.add("系统授权用户清单");titleList.add("系统功能点");titleList.add("系统功能模块描述");
titleList.add("系统调用关系");titleList.add("对应的能力块");titleList.add("主要数据");titleList.add("系统功能分类");
titleList.add("是否重要信息系统");titleList.add("使用机构");titleList.add("服务对象");titleList.add("业务负责部门");
titleList.add("系统建设部门");titleList.add("系统运维部门");titleList.add("运行服务窗口");titleList.add("系统上线时间");
titleList.add("系统下线时间");titleList.add("应用系统主版本");titleList.add("系统安全保护等级");titleList.add("系统维护分类");
titleList.add("节点名称");titleList.add("硬件");titleList.add("系统软件及版本号");titleList.add("部署地点");
titleList.add("灾备情况");titleList.add("第三方连接");titleList.add("系统关联关系");titleList.add("其他说明项");
titleList.add("信息申报部门");titleList.add("填表人");titleList.add("升级改造时间");titleList.add("升级改造主要内容");
titleList.add("变更日期");titleList.add("对口部门");titleList.add("负责人");titleList.add("记录创建日期");
titleList.add("记录更新日期");titleList.add("上线日期");titleList.add("系统状态");
requiredCell.add(0);requiredCell.add(1);requiredCell.add(11);requiredCell.add(12);
requiredCell.add(17);requiredCell.add(25);requiredCell.add(28);requiredCell.add(53);
requiredCell.add(54);requiredCell.add(55);requiredCell.add(56);requiredCell.add(58);
}
private void excelTitleStyle(Workbook workbook,List<String> titleList,List<Integer> requiredCell,
Row row,Sheet sheet) {
//蓝色背景列
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setFillForegroundColor((short) 4);// 设置背景色
//cellStyle.setAlignment(HorizontalAlignment.CENTER); // 居中
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
//红色背景列
CellStyle cellStyle1 = workbook.createCellStyle();
cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle1.setFillForegroundColor((short) 2);// 设置背景色
//cellStyle1.setAlignment(HorizontalAlignment.CENTER); // 居中
cellStyle1.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中
Font font = workbook.createFont();
font.setFontName("微软雅黑");
font.setFontHeightInPoints((short) 12);//设置字体大小
//font.setColor((short) 1);
cellStyle.setFont(font);
cellStyle1.setFont(font);
int cellIndex = 0;
row.setHeight((short)450);
for (String title : titleList) {
sheet.setColumnWidth(cellIndex, 3500);//设置列宽
if(requiredCell.contains(cellIndex)) {
Cell cell = row.createCell(cellIndex++);
cell.setCellStyle(cellStyle1);
cell.setCellValue(title == null ? "" : title);
}else {
Cell cell = row.createCell(cellIndex++);
cell.setCellStyle(cellStyle);
cell.setCellValue(title == null ? "" : title);
}
}
}
//map转对象
private Object map2JavaBean(Class<?> clazz, Map<String, Object> map) throws Exception {
Object javabean = clazz.newInstance(); // 构建对象
Method[] methods = clazz.getMethods(); // 获取所有方法
for (Method method : methods) {
if (method.getName().startsWith("set")) {
String field = method.getName(); // 截取属性名
field = field.substring(field.indexOf("set") + 3);
field = field.toLowerCase().charAt(0) + field.substring(1);
if (map.containsKey(field)) {
method.invoke(javabean, map.get(field));
}
}
}
return javabean;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment