diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/controller/JclUpLoadFileController.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/controller/JclUpLoadFileController.java index acde447..6fc6b93 100644 --- a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/controller/JclUpLoadFileController.java +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/controller/JclUpLoadFileController.java @@ -41,18 +41,6 @@ import java.util.stream.Collectors; @RequestMapping("/api/secondev/jcl/upload") public class JclUpLoadFileController extends BaseCommonController { - @RpcReference - private RemoteUploadService remoteUploadService; - - @RpcReference - private DocClientService docClientService; - @Autowired - private FreeFormAssistService freeFormAssistService; - @RpcReference - private FileClientService fileClientService; - - @Autowired - private FileDownloadService fileDownloadService; @Autowired private DatabaseUtils databaseUtils; @Autowired @@ -68,74 +56,15 @@ public class JclUpLoadFileController extends BaseCommonController { * @return */ @WeaPermission(publicPermission = true) - @GetMapping("/uploadTest") + @GetMapping("/jcluploadFile") @ResponseBody public WeaResult> uploadTest(@RequestParam("fileId") String fileId,@RequestParam("tableName") String tableName){ Map returnMap = Maps.newHashMap(); try { String sql = "select * from fileobj where id in ("+fileId+")"; List> list = databaseUtils.getSqlList(sql); - sql = "select a.* from form_field a left join form_table b on a.form_id=b.form_id where b.table_name=? and a.delete_type='0'"; - List> fieldList = databaseUtils.getSqlList(sql,CommonUtils.getParamList(tableName)); - Map>> fieldGroupByTitle = fieldList.stream().collect(Collectors.groupingBy(e->e.get("title").toString())); + returnMap = uploadService.jcluploadFile(list,tableName,getCurrentUser()); - Map resultMap = list.get(0); - FileData fileData = new FileData(); - fileData.setLoadUrl(fileDownloadService.getDownloadUrl(CommonUtils.null2String(resultMap.get("url")),CommonUtils.null2String(resultMap.get("tenant_key")),CommonUtils.null2String(resultMap.get("name")))); - - - InputStream fileInputStream = fileData.getInputStream(); - - Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX); - //标题 - List titles = ExcelSupport.getSheetHeader(sheet, 0); - returnMap.put("titles",titles); - log.error("title长度:{}",titles.get(0).length()); - String title = titles.get(0).replace(" ", ""); - log.error("处理前年月信息:{}",title); - - - // 处理数值 - List> data = ExcelParseHelper.parse2Map(sheet, 1, 0); - log.error("excel导入数据数量:[{}]", data.size()); - // 表头 - List headers = ExcelSupport.getSheetHeader(sheet, 0); - List> dataList = Lists.newArrayList(); - List> fileList = ExcelUtil.processEmbeddedObjects((XSSFSheet)sheet); - Map map = Maps.newHashMap(); - for (int i = 0; i < data.size(); i++) { - map = data.get(i); - Map singleCheck = new HashMap<>(); - for (int j = 0; j < headers.size(); j++) { - //组装单条数据基础数据 - String key = headers.get(j); - if (key == null) { - continue; - } - singleCheck.put(key.replace(" ", ""), Optional.ofNullable(map.get(key)).orElse("").toString().replace(" ", "")); - } - dataList.add(singleCheck); - } - //处理导入附件 - List> needUpdataList = Lists.newArrayList(); - for (Map fileMap:fileList){ - int rowNum = Integer.valueOf(fileMap.get("rowNum").toString()); - int colNum = Integer.valueOf(fileMap.get("colNum").toString()); - String fileName = dataList.get(rowNum-1).get(titles.get(colNum)); - fileMap.put("filename",fileName); - - Map fileUploadMap = uploadService.uploadFile(fileMap,ModuleSource.ebuildercard,0L,getCurrentUser(),null); - long docId = ((FileObj)fileUploadMap.get("fileObj")).getDocId(); - dataList.get(rowNum-1).put(titles.get(colNum),String.valueOf(docId)); - Map updataMap = Maps.newHashMap(); - updataMap.put("id",dataList.get(rowNum-1).get("数据ID")); - updataMap.put(titles.get(colNum),String.valueOf(docId)); - needUpdataList.add(updataMap); - } - - Map importResult = uploadService.importData(needUpdataList,tableName,getCurrentUser()); - returnMap.put("importResult",importResult); - returnMap.put("data",dataList); }catch (Exception e){ log.error("error msg :[{}]",e); return WeaResult.fail(e.getMessage(),true); diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/UploadService.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/UploadService.java index 49144af..722a584 100644 --- a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/UploadService.java +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/UploadService.java @@ -8,11 +8,10 @@ import java.util.Map; public interface UploadService { - - Map uploadFile(Map fileMap, ModuleSource module, Long refId, SimpleEmployee employee, String chunks); Map importData(List> dataList,String tableName,SimpleEmployee employee); + Map jcluploadFile(List> list,String tableName,SimpleEmployee employee) throws Exception; } diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/UploadServiceImpl.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/UploadServiceImpl.java index b2c8787..ecc5425 100644 --- a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/UploadServiceImpl.java +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/UploadServiceImpl.java @@ -4,15 +4,20 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.weaver.common.form.metadata.ModuleSource; import com.weaver.common.util.MimeTypeUtil; +import com.weaver.eteams.file.client.file.FileData; import com.weaver.eteams.file.client.file.FileObj; import com.weaver.eteams.file.client.remote.FileClientService; import com.weaver.eteams.file.client.remote.RemoteUploadService; +import com.weaver.file.ud.api.FileDownloadService; import com.weaver.framework.rpc.annotation.RpcReference; import com.weaver.seconddev.jcl.common.service.CommonService; import com.weaver.seconddev.jcl.enums.ContractStatusEnum; import com.weaver.seconddev.jcl.organization.service.UploadService; import com.weaver.seconddev.jcl.organization.util.CommonUtils; import com.weaver.seconddev.jcl.organization.util.DatabaseUtils; +import com.weaver.seconddev.jcl.organization.util.excel.ExcelParseHelper; +import com.weaver.seconddev.jcl.organization.util.excel.ExcelSupport; +import com.weaver.seconddev.jcl.organization.util.excel.ExcelUtil; import com.weaver.teams.client.doc.remote.DocClientService; import com.weaver.teams.crm.property.PropertyType; import com.weaver.teams.domain.EntityType; @@ -24,6 +29,8 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.xssf.usermodel.XSSFSheet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -49,10 +56,78 @@ public class UploadServiceImpl implements UploadService { private RemoteCustomerPropertyService remoteCustomerPropertyService; @Autowired private CommonService commonService; + @Autowired + private FileDownloadService fileDownloadService; + public static final String EXCEL_TYPE_XLSX = "xlsx"; + public static final String EXCEL_TYPE_XLS = "xls"; + @Override + public Map jcluploadFile(List> list,String tableName,SimpleEmployee employee) throws Exception { + Map returnMap = Maps.newHashMap(); + List> importList = Lists.newArrayList(); + for (Map resultMap:list){ + FileData fileData = new FileData(); + fileData.setLoadUrl(fileDownloadService.getDownloadUrl(CommonUtils.null2String(resultMap.get("url")),CommonUtils.null2String(resultMap.get("tenant_key")),CommonUtils.null2String(resultMap.get("name")))); - public Map uploadFile(Map fileMap, ModuleSource module, Long refId,SimpleEmployee employee,String chunks) { + InputStream fileInputStream = fileData.getInputStream(); + + Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX); + //标题 + List titles = ExcelSupport.getSheetHeader(sheet, 0); + returnMap.put("titles",titles); + log.error("title长度:{}",titles.get(0).length()); + String title = titles.get(0).replace(" ", ""); + log.error("处理前年月信息:{}",title); + + + // 处理数值 + List> data = ExcelParseHelper.parse2Map(sheet, 1, 0); + log.error("excel导入数据数量:[{}]", data.size()); + // 表头 + List headers = ExcelSupport.getSheetHeader(sheet, 0); + List> dataList = Lists.newArrayList(); + List> fileList = ExcelUtil.processEmbeddedObjects((XSSFSheet)sheet); + Map map = Maps.newHashMap(); + for (int i = 0; i < data.size(); i++) { + map = data.get(i); + Map singleCheck = new HashMap<>(); + for (int j = 0; j < headers.size(); j++) { + //组装单条数据基础数据 + String key = headers.get(j); + if (key == null) { + continue; + } + singleCheck.put(key.replace(" ", ""), Optional.ofNullable(map.get(key)).orElse("").toString().replace(" ", "")); + } + dataList.add(singleCheck); + } + //处理导入附件 + List> needUpdataList = Lists.newArrayList(); + for (Map fileMap:fileList){ + int rowNum = Integer.valueOf(fileMap.get("rowNum").toString()); + int colNum = Integer.valueOf(fileMap.get("colNum").toString()); + String fileName = dataList.get(rowNum-1).get(titles.get(colNum)); + fileMap.put("filename",fileName); + + Map fileUploadMap = uploadFile(fileMap,ModuleSource.ebuildercard,0L,employee,null); + long docId = ((FileObj)fileUploadMap.get("fileObj")).getDocId(); + dataList.get(rowNum-1).put(titles.get(colNum),String.valueOf(docId)); + Map updataMap = Maps.newHashMap(); + updataMap.put("id",dataList.get(rowNum-1).get("数据ID")); + updataMap.put(titles.get(colNum),String.valueOf(docId)); + needUpdataList.add(updataMap); + } + + Map importResult = importData(needUpdataList,tableName,employee); + importList.add(importResult); + } + returnMap.put("importList",importList); + + return returnMap; + } + + public Map uploadFile(Map fileMap, ModuleSource module, Long refId, SimpleEmployee employee, String chunks) { File data = null; try{ data = File.createTempFile(UUID.randomUUID().toString(),null); @@ -125,7 +200,7 @@ public class UploadServiceImpl implements UploadService { try{ fileObj = remoteUploadService.saveFile(employee.getTenantKey(), fileObj, Files.readAllBytes(data.toPath())); //生成附件文档 - fileObj.setDocId(docClientService.postFileUploadReId(fileObj, employee, new Date(), EntityType.valueOf(module.toString()))); + // fileObj.setDocId(docClientService.postFileUploadReId(fileObj, employee, new Date(), EntityType.valueOf(module.toString()))); fileClientService.update(fileObj); } catch (Exception e) { log.error("error", e); @@ -152,48 +227,6 @@ public class UploadServiceImpl implements UploadService { String sql = "select a.* from form_field a left join form_table b on a.form_id=b.form_id where b.table_name=? and a.delete_type='0'"; List> fieldList = databaseUtils.getSqlList(sql,CommonUtils.getParamList(tableName)); Map>> fieldGroupByTitle = fieldList.stream().collect(Collectors.groupingBy(e->e.get("title").toString())); -// sql = "select id,username from eteams.employee where delete_type=0"; -// List> userList = databaseUtils.getSqlList(sql); -// Map>> userGroup = userList.stream().collect(Collectors.groupingBy(e->e.get("id").toString())); -// sql = "select id,name,parent,type from eteams.department where delete_type=0 "; -// Map departmentMap = databaseUtils.getSqlList(sql).stream().collect(Collectors.toMap(e->e.get("name").toString(),e->e.get("id").toString())); -// sql="select id,name from eteams.position where delete_type=0"; -// Map jobMap = databaseUtils.getSqlList(sql).stream().collect(Collectors.toMap(e->e.get("name").toString(),e->e.get("id").toString())); -// sql = "select id,name from hr_dictionary_setting where type='contractType' and delete_type='0' and is_delete='0'"; -// Map contractTypeMap = databaseUtils.getSqlList(sql).stream().collect(Collectors.toMap(e->e.get("name").toString(),e->e.get("id").toString())); -// -// List> inserData = Lists.newArrayList(); -// for (Map dataMap:dataList){ -// //合同状态 -// Map newMap = Maps.newHashMap(); -// for (Map.Entry entry: dataMap.entrySet()){ -// List> field = fieldGroupByTitle.get(entry.getKey()); -// String compoent_key = CommonUtils.null2String(field.get(0).get("compoent_key")); -// String data_key = CommonUtils.null2String(field.get(0).get("data_key")); -// String value = entry.getValue(); -// if (compoent_key.equals("Employee")){ -// value = userGroup.get(value)==null?value:userGroup.get(value).get(userGroup.get(value).size()-1).get("id").toString(); -// }else if (compoent_key.equals("Department") || compoent_key.equals("Subcompany")){ -// value = departmentMap.get(value)==null?value:departmentMap.get(value); -// }else if (compoent_key.equals("Ebuilder")){ -// String browser_type = CommonUtils.null2String(field.get(0).get("browser_type")); -// if (browser_type.equals("position")){ -// //岗位 -// value = jobMap.get(value)==null?value:jobMap.get(value); -// }else if (browser_type.equals("hrContractType")){ -// //合同类型 -// value = contractTypeMap.get(value)==null?value:contractTypeMap.get(value); -// } -// }else if (compoent_key.equals("Select")){ -// if (data_key.equals("htzt")){ -// value = ContractStatusEnum.getEnumbyValue(value) == null?value:ContractStatusEnum.getEnumbyValue(value).getKey(); -// } -// -// } -// newMap.put(field.get(0).get("data_key").toString(),value); -// } -// inserData.add(newMap); -// } Map>> dataGroupById = dataList.stream().collect(Collectors.groupingBy(e->e.get("id").toString())); for (Map.Entry>>entry : dataGroupById.entrySet()){ Map updataMap = Maps.newHashMap();