summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nz-admin/db/2020-10-16.sql9
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java7
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/AssetService.java2
-rw-r--r--nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java62
4 files changed, 51 insertions, 29 deletions
diff --git a/nz-admin/db/2020-10-16.sql b/nz-admin/db/2020-10-16.sql
new file mode 100644
index 00000000..4d9185ef
--- /dev/null
+++ b/nz-admin/db/2020-10-16.sql
@@ -0,0 +1,9 @@
+/**
+ * 修改导入导出表头信息
+ */
+delete from sys_config where param_key = "asset_export_header";
+INSERT INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (NULL, 'asset_export_header', '{\"cn\":{\"*SN码\":\"资产序列号,唯一标识(必填) \\n示例: A0420200101\",\"*资产类型\":\"设备类型(必填) \\n示例: server\",\"*厂商\":\"厂商(必填) \\n示例: Cisco\",\"*型号\":\"型号(必填) \\n示例: CISCO-UCS-C220\",\"*数据中心\":\"数据中心(必填) \\n示例: 北京电信中心机房\",\"机柜\":\"机柜 \\n示例: cabinet-001\",\"开始U位\":\"机柜开始位置 此信息一般和机柜结束位置联合使用 \\n示例: 1\",\"结束U位\":\"机柜结束位置 此信息一般与机柜开始位置联合使用 \\n示例: 2\",\"*主机地址\":\"主机地址(必填),IP格式 \\n示例: 172.0.0.1\",\"状态\":\"资产状态,可选: 在库、出库 \\n示例: 在库\",\"购买日期\":\"购买日期 \\n示例: 2020/2/25\",\"SSH账号端口\":\"SSH连接端口 \\n示例: 22\",\"SSH账号登录名\":\"SSH账号登录名 \\n示例: root\",\"SSH登录认证方式\":\"SSH登录认证方式 密码登录:password,密钥登录:key \\n示例: password\",\"SSH登录密码\":\"SSH登录密码 认证方式为password时登录密码 \\n示例: xxxxx\",\"SSH登录密钥\":\"SSH登录密钥 \\n示例: ssh-rsa CFdv7Jez6K...\",\"SSH密钥密码\":\"SSH密钥密码 \\n示例: xxxxx\",\"TELNET账号端口\":\"TELNET账号端口 \\n示例: 23\",\"TELNET账号登录名\":\"TELNET账号登录名 \\n示例: root\",\"TELNET用户名提示\":\"TELNET用户名提示 \\n示例: user\",\"TELNET登录密码\":\"TELNET登录密码 \\n示例: xxxxx\",\"TELNET密码提示\":\"TELNET密码提示 \\n示例: pass\",\"TELNET重启密码提示\":\"TELNET重启密码提示 \\n示例: pass\",\"SNMP账号端口\":\"SNMP账号端口 \\n示例: 161\",\"SNMP团体名\":\"SNMP团体名 \\n示例: public\",\"SNMP上下文名称\":\"SNMP上下文名称 \\n示例: 80002b8046h\",\"SNMP协议版本\":\"SNMP协议版本 支持V2和V3 \\n示例: 2\",\"SNMP用户名\":\"SNMPV3版本时,登录用户名 \\n示例: root\",\"SNMP安全级别\":\"SNMP安全级别 noAuthNoPriv(不认证不加密) authNoPriv(认证不加密) authPriv(认证且加密) \\n示例: noAuthNoPriv\",\"SNMP用户密码\":\"SNMP用户密码, 根据安全级别选择填写 \\n示例: xxxxx\",\"SNMP认证协议\":\"SNMP用户认证协议 MD5、SHA \\n示例: MD5\",\"SNMP加密协议\":\"SNMP加密协议 AES、DES \\n示例: AES\",\"SNMP加密密码\":\"SNMP加密密码 \\n示例: xxxxx\",\"资产标签\":\"资产标签,tag信息,格式: key=value 如需填写多个请使用回车换行 \\n示例: isOpen=true \\n isHighPerformance=true\",\"Exporter\":\"是否安装内置node_exporter,1:安装,0:不安装 \\n示例:1\"},\"en\":{\"*Sn\":\"Asset serial number, unique identifier (required) \\nExample: A0420200101\",\"*Type\":\"Asset type (required) \\nExample: server\",\"*Vendor\":\"Vendor (required) \\nExample: Cisco\",\"*Model\":\"Model (required) \\nExample: CISCO-UCS-C220\",\"*IDC\":\"Data Center (Required) \\nExample: Beijing Telecom Center Computer Room\",\"Cabinet\":\"Cabinet \\nExample: cabinet-001\",\"Cabinet Start\":\"Cabinet start position This information is generally used in conjunction with the cabinet end position \\nExample: 1\",\"Cabinet End\":\"Cabinet end position This information is generally used in conjunction with the cabinet start position \\nExample: 2\",\"*Host\":\"Host address (required), IP format \\nExample: 172.0.0.1\",\"State\":\"Asset status, optional: In stock or Not in stock \\nExample: In stock\",\"PurchaseDate\":\"Purchase date \\nExample: 2020/2/25\",\"SSH Account Port\":\"SSH account connection port \\nExample: 22\",\"SSH UserName\":\"SSH account login name \\nExample: root\",\"Methed\":\"SSH login authentication method, Password login: password, key login: key \\nExample: password\",\"SSH Password\":\"SSH login password The login password when the authentication method is password \\nExample: xxxxx\",\"PrivateKey\":\"SSH login key file \\nExample: ssh-rsa CFdv7Jez6K...\",\"Key Password\":\"SSH key password \\nExample: xxxxx\",\"TELNET Port\":\"TELNET account port \\nExample: 23\",\"TELNET Username\":\"TELNET account login name \\nExample: root\",\"User Tip\":\"TELNET username prompt \\nExample: user\",\"TELNET Password\":\"TELNET login password \\nExample: xxxxx\",\"Password Tip\":\"TELNET password prompt \\nExample: pass\",\"Relogin Tip\":\"TELNET relogin password prompt \\nExample: pass\",\"SNMP port\":\"SNMP account port \\nExample: 161\",\"Community\":\"SNMP community name \\nExample: public\",\"Context Name\":\"SNMP context name \\nExample: 80002b8046h\",\"Version\":\"SNMP protocol version supports V2 and V3 \\nExample: 2\",\"SNMP User\":\"In SNMPV3 version, login user name\\nExample: root\",\"SecurityLevel\":\"SNMP security level noAuthNoPriv (no authentication and no encryption) authNoPriv (authentication and no encryption) authPriv (authentication and encryption) \\nExample: noAuthNoPriv\",\"SNMP Password\":\"SNMP user password, fill in according to the security level \\nExample: xxxxx\",\"Auth Protocol\":\"SNMP auth protocol MD5, SHA \\nExample: MD5\",\"Priv Protocol\":\"SNMP priv protocol AES, DES \\nExample: AES\",\"Priv Password\":\"SNMP priv password \\nExample: xxxxx\",\"Tags\":\"Asset tag information, format: key=value If you need to fill in more than one, please use carriage return and line feed \\nExample: isOpen=true \\n isHighPerformance=true\",\"Exporter\":\"Whether to install the built-in node_exporter, 1: install, 0: not install \\nExample: 1\"}}', 1, 'alert_message导出表头');
+
+
+delete from sys_config where param_key = "i18n_mapping";
+INSERT INTO `sys_config`(`id`, `param_key`, `param_value`, `status`, `remark`) VALUES (NULL, 'i18n_mapping', '{\"assetState\":{\"en\":{\"1\":\"In stock\",\"2\":\"Not in stock\"},\"cn\":{\"1\":\"在库\",\"2\":\"出库\"}},\"chartType\":{\"en\":{\"line\":\"Line Chart\",\"bar\":\"Histogram\",\"table\":\"Table\",\"stackArea\":\"Stack Area\",\"singleStat\":\"SingleStat\",\"url\":\"URL\",\"alertList\":\"Alert list\"},\"cn\":{\"line\":\"曲线图\",\"bar\":\"柱状图\",\"table\":\"表格\",\"stackArea\":\"堆叠区域图\",\"singleStat\":\"SingleStat\",\"url\":\"URL\",\"alertList\":\"告警列表\"}}}', 1, NULL);
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
index 3caa48c6..ecb71dc0 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/controller/AssetController.java
@@ -167,11 +167,12 @@ public class AssetController {
*/
@PostMapping("/import")
@SysLog(operation = OperationEnum.IMPORT,type = TypeEnum.ASSET)
- public R importAssetsFromExcel(MultipartFile excelFile) {
- ValidateUtils.is(excelFile).notNull(RCode.ASSET_IMPORT_FILE_ISNULL);
+ public R importAssetsFromExcel(MultipartFile excelFile,String language) {
+ ValidateUtils.is(excelFile).notNull(RCode.ASSET_IMPORT_FILE_ISNULL)
+ .and(language).notNull(RCode.ASSET_EXPORT_HEADER_LANGUAGE_ISNULL);
// 本次导入的 uuid
String seqUUID = UUID.randomUUID().toString();
- Map map = assetService.importAssetsFromExcel(excelFile, seqUUID);
+ Map map = assetService.importAssetsFromExcel(excelFile, seqUUID, language);
return R.ok(map);
}
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetService.java b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetService.java
index d5892fe4..ad0d4ece 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/AssetService.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/AssetService.java
@@ -35,7 +35,7 @@ public interface AssetService extends IService<Asset> {
MetricsDto queryAssetStatisticsByModelOffLine();
- Map importAssetsFromExcel(MultipartFile assetsExcelFile, String seqUUID);
+ Map importAssetsFromExcel(MultipartFile assetsExcelFile, String seqUUID, String language);
void cancelImport(String seq);
diff --git a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
index b58dfb76..2da5d5ba 100644
--- a/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
+++ b/nz-admin/src/main/java/com/nis/modules/asset/service/impl/AssetServiceImpl.java
@@ -681,7 +681,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
private TransactionDefinition transactionDefinition;
@Override
- public Map importAssetsFromExcel(MultipartFile assetsExcelFile, String seqUUID) {
+ public Map importAssetsFromExcel(MultipartFile assetsExcelFile, String seqUUID, String language) {
logger.info("asset 导入文件名是:" + assetsExcelFile.getOriginalFilename() + ",本次随机UUD:" + seqUUID);
String originalFilename = assetsExcelFile.getOriginalFilename();
@@ -707,6 +707,15 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
}
}
+ // asset state 语言对应表
+ SysConfigEntity i18nConfig = sysConfigService.getOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.I18N_MAPPING).eq(SysConfigEntity::getStatus, 1));
+ Map i18nConfigMap = JSONObject.parseObject(i18nConfig.getParamValue(), Map.class);
+ Map assetStateMap = (Map) i18nConfigMap.get(Constant.DICT_ASSET_STATE_TYPE);
+ Map assetStateMapByLanguage = (Map) assetStateMap.get(language);
+ if (ToolUtil.isEmpty(assetStateMapByLanguage)) {
+ throw new NZException(RCode.ASSET_EXPORT_HEADER_LANGUAGE_ERROR);
+ }
+
// 查询 asset 相关数据 用作导入时间校验 减少循环查表
Map<String, SysDictEntity> assetTypesMap = new HashMap();
Map<String, SysDictEntity> vendorsMap = new HashMap();
@@ -784,7 +793,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
int dataFromExcelRowNum;
String sn, type, vendor, model, dcName, cabinetName, cabinetStart, cabinetEnd, host, state, purchaseDate, exporter; //, ipmiHost, ipmiPort;
- Integer start, end, stateInt;
+ Integer start, end;
Map saveEntitys, ipmiMap;
Long userId = ShiroUtils.getUserId();
@@ -800,7 +809,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
dataFromExcelRowNum = i + 1;
// 保证一行数据在同一事务内,将所有入库数据统一入库
saveEntitys = new HashMap();
- start = end = stateInt = null;
+ start = end = null;
accountList = new ArrayList<>();
boolean saveFlag = true;
boolean modelFlag = true;
@@ -1009,20 +1018,12 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
state = ExcelUtils.getCellValue(row.getCell(9));
if (StringUtils.isEmpty(state)) {
state = "1";
- }
- try {
- stateInt = Integer.parseInt(state);
- } catch (NumberFormatException e) {
- saveFlag = false;
- this.addFailDetail(dataFromExcelRowNum, failDetails, RCode.ASSET_STATE_INVALIDE.getMsg());
- }
-
- // 校验asste state 是否存在
- if (!assetStateList.contains(stateInt)) {
- saveFlag = false;
- this.addFailDetail(dataFromExcelRowNum, failDetails, RCode.ASSET_STATE_NOTFOUND.getMsg());
} else {
- asset.setState(stateInt);
+ state = this.validateAssetStateForImport(state, assetStateMapByLanguage);
+ if (StringUtils.isEmpty(state)) {
+ saveFlag = false;
+ this.addFailDetail(dataFromExcelRowNum, failDetails, RCode.ASSET_STATE_NOTFOUND.getMsg());
+ }
}
// 购买日期
@@ -1108,6 +1109,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
}
// 前面没有报错
if (saveFlag) {
+ asset.setState(Integer.parseInt(state));
asset.setSeq(seqUUID);
asset.setCreateAt(DateUtil.getUTCTimeByConfigTimeZone());
asset.setCreateBy(userId);
@@ -1166,6 +1168,15 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
return resultInfo;
}
+ private String validateAssetStateForImport(String type, Map<String,String> assetStateMapByLanguage) {
+ for (Map.Entry<String, String> entry : assetStateMapByLanguage.entrySet()) {
+ if(type.equals(entry.getValue())){
+ return entry.getKey();
+ }
+ }
+ return null;
+ }
+
private void updateImportAssetRelatedInfo(Map updateMap, Map<String, SysDictEntity> assetTypesMap, Map<String, SysDictEntity> vendorsMap, List<Model> modelList, Map<String, Idc> idcMap, List<Cabinet> cabinetList, List<String> assetSnList, List<String> assetHostList) {
SysDictEntity updateType = (SysDictEntity) updateMap.get("type");
if (updateType != null) {
@@ -1665,8 +1676,13 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
workbook = ExcelUtils.createExcel07(exportHeader, sheetName, false);
SXSSFSheet sheet = workbook.getSheet(sheetName);
+ SysConfigEntity i18nConfig = sysConfigService.getOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.I18N_MAPPING).eq(SysConfigEntity::getStatus, 1));
+ Map i18nConfigMap = JSONObject.parseObject(i18nConfig.getParamValue(), Map.class);
+ Map assetStateMap = (Map) i18nConfigMap.get(Constant.DICT_ASSET_STATE_TYPE);
+ Map assetStateMapByLanguage = (Map) assetStateMap.get(language);
+
// 填充数据
- this.fillData(list, 1, sheet, workbook, language);
+ this.fillData(list, 1, sheet, workbook, assetStateMapByLanguage);
// 响应为流
String fileName = "AssetsExport.xlsx"; // 默认名称
@@ -1688,10 +1704,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
}
}
- private void fillData(List<Asset> list, int rowNum, Sheet sheet, SXSSFWorkbook workbook, String language) {
- SysConfigEntity i18nConfig = sysConfigService.getOne(new QueryWrapper<SysConfigEntity>().lambda().eq(SysConfigEntity::getParamKey, Constant.I18N_MAPPING).eq(SysConfigEntity::getStatus, 1));
- Map i18nConfigMap = JSONObject.parseObject(i18nConfig.getParamValue(), Map.class);
- Map assetStateMap = (Map) i18nConfigMap.get(Constant.DICT_ASSET_STATE_TYPE);
+ private void fillData(List<Asset> list, int rowNum, Sheet sheet, SXSSFWorkbook workbook, Map assetStateMapByLanguage) {
Row row;
Model model;
Integer start, end, ipmiPort;
@@ -1712,7 +1725,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
end = asset.getCabinetEnd();
row.createCell(7).setCellValue(end == null ? "" : end + "");
row.createCell(8).setCellValue(asset.getHost());
- row.createCell(9).setCellValue(this.getI18nAssetStateValue(assetStateMap, language, asset.getState()));
+ row.createCell(9).setCellValue(this.getI18nAssetStateValue(assetStateMapByLanguage, asset.getState()));
row.createCell(10).setCellValue(asset.getPurchaseDate());
if (CollectionUtils.isNotEmpty(asset.getAccounts())) {
@@ -1743,9 +1756,8 @@ public class AssetServiceImpl extends ServiceImpl<AssetDao, Asset> implements As
}
}
- private String getI18nAssetStateValue(Map assetStateMap, String language, Integer state) {
- Map map = (Map) assetStateMap.get(state);
- Object value = map.get(language);
+ private String getI18nAssetStateValue(Map assetStateMapByLanguage, Integer state) {
+ Object value = assetStateMapByLanguage.get(state);
return value == null ? "" : value.toString();
}