diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/enums/BaseEnum.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/enums/BaseEnum.java new file mode 100644 index 0000000..a388f56 --- /dev/null +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/enums/BaseEnum.java @@ -0,0 +1,7 @@ +package com.weaver.seconddev.jcl.enums; + +public interface BaseEnum { + String getKey(); + + String getValue(); +} 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 5017d8d..acde447 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 @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.*; import java.util.*; +import java.util.stream.Collectors; /** * 上传文件 @@ -69,16 +70,22 @@ public class JclUpLoadFileController extends BaseCommonController { @WeaPermission(publicPermission = true) @GetMapping("/uploadTest") @ResponseBody - public WeaResult> uploadTest(@RequestParam("fileId") String fileId){ + public WeaResult> uploadTest(@RequestParam("fileId") String fileId,@RequestParam("tableName") String tableName){ Map returnMap = Maps.newHashMap(); try { - String sql = "select * from fileobj where id=?"; - List> list = databaseUtils.getSqlList(sql, CommonUtils.getParamList(fileId)); + 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())); + 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); @@ -109,12 +116,25 @@ public class JclUpLoadFileController extends BaseCommonController { } dataList.add(singleCheck); } - List> list1 = Lists.newArrayList(); + //处理导入附件 + List> needUpdataList = Lists.newArrayList(); for (Map fileMap:fileList){ - Map fileUploadMap = uploadService.uploadFile(fileMap,ModuleSource.ebuildercard,0L,getCurrentUser(),"0"); - list1.add(fileUploadMap); + 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); } - returnMap.put("list1",list1); + + Map importResult = uploadService.importData(needUpdataList,tableName,getCurrentUser()); + returnMap.put("importResult",importResult); returnMap.put("data",dataList); }catch (Exception e){ log.error("error msg :[{}]",e); diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/importAdvice/ImportEmployeeAdvice.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/importAdvice/ImportEmployeeAdvice.java index e738ce4..6f555e5 100644 --- a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/importAdvice/ImportEmployeeAdvice.java +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/importAdvice/ImportEmployeeAdvice.java @@ -20,19 +20,16 @@ import java.util.List; public class ImportEmployeeAdvice implements ImportDataAdvice { @Override public void dataAdvice(BaseImportDataAdviceDto req) { + + List> dataList = req.getDataList(); List> newDataList = Lists.newArrayList(); List errorMsg = Lists.newArrayList(); for (List data:dataList){ boolean mark = true; for (DataForImportEntity entity:data){ - if (entity.getDataKey().equals("手机号") && entity.getValue().equals("18816254117")){ - entity.setErrorMsg("手机号重复"); - errorMsg.add("手机号重复"); - mark = false; - }else { - - } + log.error("key :" +entity.getDataKey()); + log.error(entity.getValue().getClass().getTypeName()); } if (mark){ newDataList.add(data); 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 cf68233..49144af 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 @@ -3,8 +3,16 @@ package com.weaver.seconddev.jcl.organization.service; import com.weaver.common.form.metadata.ModuleSource; import com.weaver.teams.domain.user.SimpleEmployee; +import java.util.List; 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); + + } 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 60c947d..b2c8787 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 @@ -1,29 +1,37 @@ package com.weaver.seconddev.jcl.organization.service.impl; +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.FileObj; import com.weaver.eteams.file.client.remote.FileClientService; import com.weaver.eteams.file.client.remote.RemoteUploadService; 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.teams.client.doc.remote.DocClientService; +import com.weaver.teams.crm.property.PropertyType; import com.weaver.teams.domain.EntityType; +import com.weaver.teams.domain.crm.RemoteCustomerProperty; +import com.weaver.teams.domain.crm.RemoteCustomerPropertyService; import com.weaver.teams.domain.user.SimpleEmployee; import lombok.extern.slf4j.Slf4j; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.nio.file.Files; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; @Slf4j @Service @@ -35,13 +43,31 @@ public class UploadServiceImpl implements UploadService { private DocClientService docClientService; @RpcReference private FileClientService fileClientService; + @Autowired + private DatabaseUtils databaseUtils; + @RpcReference + private RemoteCustomerPropertyService remoteCustomerPropertyService; + @Autowired + private CommonService commonService; + + public Map uploadFile(Map fileMap, ModuleSource module, Long refId,SimpleEmployee employee,String chunks) { File data = null; try{ data = File.createTempFile(UUID.randomUUID().toString(),null); InputStream stream = (InputStream)fileMap.get("stream"); - FileUtils.copyInputStreamToFile(stream, data); + String filename = CommonUtils.null2String(fileMap.get("filename")); + if (filename.endsWith(".pdf") || filename.endsWith(".bin")){ + PDDocument document = PDDocument.load(stream); + document.save(data); + if (filename.endsWith(".bin")){ + filename = filename.replace(".bin",".pdf"); + fileMap.put("filename",filename); + } + }else { + FileUtils.copyInputStreamToFile(stream, data); + } stream.close(); }catch (Exception e){ log.error("error", e); @@ -116,6 +142,89 @@ public class UploadServiceImpl implements UploadService { return result; } + + @Override + public Map importData(List> dataList,String tableName,SimpleEmployee employee) { + + Map resultMap = Maps.newHashMap(); + + List> updateData = Lists.newArrayList(); + 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(); + String id = entry.getKey(); + Map dataMap = Maps.newHashMap(); + for (Map map : entry.getValue()){ + for (Map.Entry data: map.entrySet()){ + String key = data.getKey(); + key = fieldGroupByTitle.get(key)==null?key:fieldGroupByTitle.get(key).get(0).get("data_key").toString(); + String value = data.getValue(); + if (dataMap.get(key) == null){ + dataMap.put(key,value); + }else { + String oldValue = CommonUtils.null2String(dataMap.get(key)); + dataMap.put(key,oldValue+","+value); + } + } + } + Map condition = Maps.newHashMap(); + condition.put("id",id); + updataMap.put("condition",condition); + updataMap.put("dataMap",dataMap); + updataMap.put("tableName",tableName); + commonService.updateCommon(updataMap); + updateData.add(updataMap); + } + + resultMap.put("updateData",updateData); + return resultMap; + } + /** * InputStream转化为byte数组 * @param input 输入流