|
@@ -1,6 +1,8 @@
|
|
|
package com.persagy.dmp.rwd.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import cn.hutool.core.util.EnumUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
@@ -15,17 +17,23 @@ import com.persagy.common.json.JacksonMapper;
|
|
|
import com.persagy.common.web.ListResponse;
|
|
|
import com.persagy.common.web.PagedResponse;
|
|
|
import com.persagy.dmp.rwd.constants.CommonConstant;
|
|
|
+import com.persagy.dmp.rwd.constants.ErrorEnum;
|
|
|
import com.persagy.dmp.rwd.entity.FuncidDef;
|
|
|
import com.persagy.dmp.rwd.entity.QFuncidDef;
|
|
|
import com.persagy.dmp.rwd.enums.ObjType;
|
|
|
import com.persagy.dmp.rwd.feign.DicClient;
|
|
|
import com.persagy.dmp.rwd.handler.BusinessException;
|
|
|
import com.persagy.dmp.rwd.handler.ResponseCode;
|
|
|
+import com.persagy.dmp.rwd.handler.SpringHelper;
|
|
|
import com.persagy.dmp.rwd.model.ClassDefModel;
|
|
|
import com.persagy.dmp.rwd.model.FuncidDefModel;
|
|
|
import com.persagy.dmp.rwd.repository.FuncidDefRepository;
|
|
|
import com.persagy.dmp.rwd.service.*;
|
|
|
import com.persagy.dmp.rwd.util.FileUtil;
|
|
|
+import com.persagy.dmp.rwd.validators.service.FileCheckService;
|
|
|
+import com.persagy.dmp.rwd.validators.service.impl.CommonFileCheckServiceImpl;
|
|
|
+import com.persagy.dmp.rwd.validators.service.impl.EquipFileCheckServiceImpl;
|
|
|
+import com.persagy.dmp.rwd.validators.service.impl.SystemFileCheckServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.poi.ss.usermodel.Name;
|
|
@@ -69,16 +77,18 @@ public class BatchHandleObjectServiceImpl extends BaseService implements BatchHa
|
|
|
private static final String SPACE_ZONES_SHEET_NAME="spaceZones";
|
|
|
/**空间功能类型sheet*/
|
|
|
private static final String SPACE_FUNC_TYPES_SHEET_NAME="roomFuncTypes";
|
|
|
- /**专业系统类sheet*/
|
|
|
+ /**做系统类级联选择的sheet*/
|
|
|
private static final String SYSTEM_OBJECT_CLAZZ_SHEET_NAME="systemObjectClazz";
|
|
|
- /**专业系统设备类sheet*/
|
|
|
+ /**做设备类级联选择的sheet*/
|
|
|
private static final String EQUIPMENT_OBJECT_CLAZZ_SHEET_NAME="equipmentObjectClazz";
|
|
|
- /**对象信息点sheet*/
|
|
|
+ /**系统对象信息点sheet*/
|
|
|
private static final String SYSTEM_OBJECT_INFOS_SHEET_NAME="systemObjectInfos";
|
|
|
- /**对象信息点sheet*/
|
|
|
+ /**设备对象信息点sheet*/
|
|
|
private static final String EQUIPMENT_OBJECT_INFOS_SHEET_NAME="equipmentObjectInfos";
|
|
|
- /**对象信息点sheet*/
|
|
|
+ /**专业系统设备类sheet*/
|
|
|
private static final String OBJECT_CLAZZ_SHEET_NAME="objectClazz";
|
|
|
+ /**楼层定义sheet*/
|
|
|
+ private static final String FLOOR_IDENTITIES_SHEET_NAME="floorIdentities";
|
|
|
|
|
|
|
|
|
/***
|
|
@@ -124,48 +134,127 @@ public class BatchHandleObjectServiceImpl extends BaseService implements BatchHa
|
|
|
@Override
|
|
|
public void uploadObjectTemplateFile(MultipartFile file, HttpServletRequest request,
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
+ Workbook workbook = WorkbookUtil.createBook(file.getInputStream());
|
|
|
+ // 1.获得各个sheet的列表数据
|
|
|
ExcelReader commonObjectSheet = ExcelUtil.getReader(file.getInputStream(),0);
|
|
|
ExcelReader equipObjectSheet = ExcelUtil.getReader(file.getInputStream(),1);
|
|
|
ExcelReader systemObjectSheet = ExcelUtil.getReader(file.getInputStream(),2);
|
|
|
ExcelReader systemObjectInfosSheet = ExcelUtil.getReader(file.getInputStream(), SYSTEM_OBJECT_INFOS_SHEET_NAME);
|
|
|
ExcelReader equipObjectInfosSheet = ExcelUtil.getReader(file.getInputStream(), EQUIPMENT_OBJECT_INFOS_SHEET_NAME);
|
|
|
- ExcelReader deptSheet = ExcelUtil.getReader(file.getInputStream(),1);
|
|
|
- ExcelReader positionSheet = ExcelUtil.getReader(file.getInputStream(),2);
|
|
|
- ExcelReader domainSheet = ExcelUtil.getReader(file.getInputStream(),3);
|
|
|
- ExcelReader sexSheet = ExcelUtil.getReader(file.getInputStream(),4);
|
|
|
- ExcelReader prjectSheet = ExcelUtil.getReader(file.getInputStream(),5);
|
|
|
-// List<List<Object>> uploadData = firstSheet.read();
|
|
|
-// List<List<Object>> deptListList = deptSheet.read();
|
|
|
-// List<List<Object>> positionListList = positionSheet.read();
|
|
|
-// List<List<Object>> domainListList = domainSheet.read();
|
|
|
-// List<List<Object>> sexListList = sexSheet.read();
|
|
|
-// List<List<Object>> prjectListList = prjectSheet.read();
|
|
|
-// List<String> checkFileErrList = checkFileIsValid(uploadData);
|
|
|
-// if (CollUtil.isNotEmpty(checkFileErrList)){
|
|
|
-// FileUtil.writeErrorContentToResponse(checkFileErrList,response,request, WorkConstant.UPLOAD_PERSON_ERR_FILE_NAME);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// // 1.{部门名称:部门id}映射
|
|
|
-// Map<String,String> deptMap = createDataMap(deptListList,0,1);
|
|
|
-// Map<String,String> deptTypeMap = createDataMap(deptListList,1,2);
|
|
|
-// // 2.{岗位名称:岗位id}映射
|
|
|
-// Map<String,String> positionMap = createDataMap(positionListList,0,1);
|
|
|
-// Map<String,String> positionAuthoMap = createDataMap(positionListList,1,2);
|
|
|
-// // 3.{专业名称:专业id}映射
|
|
|
-// Map<String,String> domainMap = createDataMap(domainListList,0,1);
|
|
|
-// // 4.{性别名称:性别id}映射
|
|
|
-// Map<String,String> sexMap = createDataMap(sexListList,0,1);
|
|
|
-// // 5.{项目名称:项目id}映射
|
|
|
-// Map<String,String> projectMap = createDataMap(prjectListList,0,1);
|
|
|
-// // 4.检验数据合法性
|
|
|
-// List<String> checkDataErrList = checkDataIsValid(uploadData, deptMap, positionMap, domainMap,sexMap,projectMap,firstSheet);
|
|
|
-// if (CollUtil.isNotEmpty(checkDataErrList)){
|
|
|
-// FileUtil.writeErrorContentToResponse(checkDataErrList,response,request, WorkConstant.UPLOAD_PERSON_ERR_FILE_NAME);
|
|
|
+ ExcelReader buildingFuncTypesSheet = ExcelUtil.getReader(file.getInputStream(), BUILDING_FUNC_TYPE_SHEET_NAME);
|
|
|
+ ExcelReader floorIdentitiesSheet = ExcelUtil.getReader(file.getInputStream(), FLOOR_IDENTITIES_SHEET_NAME);
|
|
|
+ ExcelReader spaceZonesSheet = ExcelUtil.getReader(file.getInputStream(), SPACE_ZONES_SHEET_NAME);
|
|
|
+ ExcelReader spaceFuncTypesSheet = ExcelUtil.getReader(file.getInputStream(), SPACE_FUNC_TYPES_SHEET_NAME);
|
|
|
+ // 1.1 基础对象录入列表
|
|
|
+ List<List<Object>> commonObjectUploadData = commonObjectSheet.read();
|
|
|
+ // 1.2 设备对象录入列表
|
|
|
+ List<List<Object>> equipObjectUploadData = equipObjectSheet.read();
|
|
|
+ // 1.3 系统对象录入列表
|
|
|
+ List<List<Object>> systemObjectUploadData = systemObjectSheet.read();
|
|
|
+ // 1.4 系统对象信息点列表
|
|
|
+ List<List<Object>> systemObjectInfosListList = systemObjectInfosSheet.read();
|
|
|
+ // 1.5 设备对象信息点列表
|
|
|
+ List<List<Object>> equipObjectInfosListList = equipObjectInfosSheet.read();
|
|
|
+ // 1.6 建筑功能类型列表
|
|
|
+ List<List<Object>> buildingFuncTypesListList = buildingFuncTypesSheet.read();
|
|
|
+ // 1.7 楼层编码列表
|
|
|
+ List<List<Object>> floorIdentitiesListList = floorIdentitiesSheet.read();
|
|
|
+ // 1.8 空间分区列表
|
|
|
+ List<List<Object>> spaceZonesListList = spaceZonesSheet.read();
|
|
|
+ // 1.9 空间功能类型列表
|
|
|
+ List<List<Object>> spaceFuncTypesListList = spaceFuncTypesSheet.read();
|
|
|
+ // 2.获得名称与信息点的映射
|
|
|
+ // 2.1 {系统信息点名称:系统信息点code}映射
|
|
|
+ Map<String,String> systemObjectInfosMap = createDataMap(systemObjectInfosListList,0,1);
|
|
|
+ // 2.2 {设备信息点名称:设备信息点code}映射
|
|
|
+ Map<String,String> equipObjectInfosMap = createDataMap(equipObjectInfosListList,0,1);
|
|
|
+ // 2.3 {建筑功能类型名称:建筑功能类型code}映射
|
|
|
+ Map<String,String> buildingFuncTypesMap = createDataMap(buildingFuncTypesListList,0,1);
|
|
|
+ // 2.4 {楼层编码名称:楼层编码code}映射
|
|
|
+ Map<String,String> floorIdentitiesMap = createDataMap(floorIdentitiesListList,0,1);
|
|
|
+ // 2.5 {空间分区名称:空间分区code}映射
|
|
|
+ Map<String,String> spaceZonesMap = createDataMap(spaceZonesListList,0,1);
|
|
|
+ // 2.6 {空间功能类型名称:空间功能类型code}映射
|
|
|
+ Map<String,String> spaceFuncTypesMap = createDataMap(spaceFuncTypesListList,0,1);
|
|
|
+ List<String> errorList = new ArrayList<>();
|
|
|
+ // 3.文件及文件表头校验
|
|
|
+ // 3.1 校验基础对象录入
|
|
|
+ FileCheckService commonFileCheckService = SpringHelper.getBean(CommonFileCheckServiceImpl.class);
|
|
|
+ commonFileCheckService.checkFileIsValid(errorList,commonObjectUploadData,new HashMap<>());
|
|
|
+ // 3.2 校验设备对象录入
|
|
|
+ FileCheckService equipFileCheckService = SpringHelper.getBean(EquipFileCheckServiceImpl.class);
|
|
|
+ equipFileCheckService.checkFileIsValid(errorList,equipObjectUploadData,equipObjectInfosMap);
|
|
|
+ // 3.3 校验系统对象录入
|
|
|
+ FileCheckService systemFileCheckService = SpringHelper.getBean(SystemFileCheckServiceImpl.class);
|
|
|
+ systemFileCheckService.checkFileIsValid(errorList,systemObjectUploadData,systemObjectInfosMap);
|
|
|
+ if (CollUtil.isNotEmpty(errorList)){
|
|
|
+ FileUtil.writeErrorContentToResponse(errorList,response,request, CommonConstant.UPLOAD_ERR_FILE_NAME);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 4.检验数据合法性
|
|
|
+ // 4.1 校验基础对象录入
|
|
|
+ checkCommonDataIsValid(errorList,commonObjectUploadData,buildingFuncTypesMap,floorIdentitiesMap,spaceZonesMap,spaceFuncTypesMap);
|
|
|
+// // 4.2 校验设备对象录入
|
|
|
+// checkEquipDataIsValid(errorList,equipObjectUploadData,equipObjectInfosMap);
|
|
|
+// // 4.3 校验系统对象录入
|
|
|
+// checkSystemDataIsValid(errorList,systemObjectUploadData,systemObjectInfosMap);
|
|
|
+// if (CollUtil.isNotEmpty(errorList)){
|
|
|
+// FileUtil.writeErrorContentToResponse(errorList,response,request, CommonConstant.UPLOAD_ERR_FILE_NAME);
|
|
|
// return;
|
|
|
// }
|
|
|
// batchHandleUploadDatas(userId, uploadData,firstSheet, deptMap, positionMap, domainMap,
|
|
|
// sexMap,projectMap,deptTypeMap,positionAuthoMap);
|
|
|
-// response.addHeader(CommonConstant.UPLOAD_FLAG,MagicNumEnum.SUCCESS_FLAG_ONE.getValue());
|
|
|
+// response.addHeader(CommonConstant.UPLOAD_FLAG,CommonConstant.SUCCESS_FLAG_ONE);
|
|
|
+ }
|
|
|
+ /***
|
|
|
+ * Description: 校验基础对象录入的数据
|
|
|
+ * @param errorList : 错误提示列表
|
|
|
+ * @param commonObjectUploadData : 基础对象录入数据
|
|
|
+ * @param buildingFuncTypesMap : 建筑功能类型名称和建筑功能类型code的映射
|
|
|
+ * @param floorIdentitiesMap : 楼层编码名称和楼层编码code的映射
|
|
|
+ * @param spaceZonesMap : 空间分区名称和空间分区code的映射
|
|
|
+ * @param spaceFuncTypesMap : 空间功能类型名称和空间功能类型code的映射
|
|
|
+ * @return : void
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/9/24 17:30
|
|
|
+ * Update By lijie 2021/9/24 17:30
|
|
|
+ */
|
|
|
+ private void checkCommonDataIsValid(List<String> errorList, List<List<Object>> commonObjectUploadData,
|
|
|
+ Map<String, String> buildingFuncTypesMap, Map<String, String> floorIdentitiesMap,
|
|
|
+ Map<String, String> spaceZonesMap, Map<String, String> spaceFuncTypesMap) {
|
|
|
+ int startRowIndex=2;
|
|
|
+ if (commonObjectUploadData.size()<3){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int objSize = commonObjectUploadData.size();
|
|
|
+ for (int i = startRowIndex; i < objSize; i++) {
|
|
|
+ List<Object> datas = commonObjectUploadData.get(i);
|
|
|
+ // 1.项目id
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /***
|
|
|
+ * Description: 创建映射关系
|
|
|
+ * @param dataListList : 数据列表
|
|
|
+ * @return : java.util.Map<java.lang.String,java.lang.String>
|
|
|
+ * @author : lijie
|
|
|
+ * @date :2021/8/5 20:12
|
|
|
+ * Update By lijie 2021/8/5 20:12
|
|
|
+ */
|
|
|
+ private Map<String, String> createDataMap(List<List<Object>> dataListList,Integer keyIndex,Integer valIndex) {
|
|
|
+ Map<String,String> dataMap = new HashMap<>();
|
|
|
+ for (List<Object> objects : dataListList) {
|
|
|
+ String key = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(keyIndex)));
|
|
|
+ String value = CharSequenceUtil.trimToEmpty(StrUtil.utf8Str(objects.get(valIndex)));
|
|
|
+ dataMap.put(key, value);
|
|
|
+ }
|
|
|
+ return dataMap;
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -268,8 +357,8 @@ public class BatchHandleObjectServiceImpl extends BaseService implements BatchHa
|
|
|
int n=1;
|
|
|
for (Map.Entry<String, String> clazzEntry : systemClazzEntries) {
|
|
|
CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(equipObjectClazzSheet,n),m),clazzEntry.getValue()+StrUtil.UNDERLINE,null);
|
|
|
- CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),0),entry.getValue(),null);
|
|
|
- CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),1),entry.getKey(),null);
|
|
|
+ CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),0),clazzEntry.getValue(),null);
|
|
|
+ CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),1),clazzEntry.getKey(),null);
|
|
|
n++;
|
|
|
clazzIndex++;
|
|
|
}
|
|
@@ -293,8 +382,8 @@ public class BatchHandleObjectServiceImpl extends BaseService implements BatchHa
|
|
|
for (Map.Entry<String, String> equipEntry : equipClazzList) {
|
|
|
String modelName = equipEntry.getValue();
|
|
|
CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(equipObjectClazzSheet,n),m),modelName,null);
|
|
|
- CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),0),entry.getValue(),null);
|
|
|
- CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),1),entry.getKey(),null);
|
|
|
+ CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),0),equipEntry.getValue(),null);
|
|
|
+ CellUtil.setCellValue(CellUtil.getOrCreateCell(RowUtil.getOrCreateRow(objectClazzSheet,clazzIndex),1),equipEntry.getKey(),null);
|
|
|
n++;
|
|
|
clazzIndex++;
|
|
|
}
|