导入设置

This commit is contained in:
liuliang 2025-05-23 14:52:48 +08:00
parent ee9314ff19
commit 0fd3826824
5 changed files with 160 additions and 19 deletions

View File

@ -0,0 +1,7 @@
package com.weaver.seconddev.jcl.enums;
public interface BaseEnum {
String getKey();
String getValue();
}

View File

@ -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<Map<String, Object>> uploadTest(@RequestParam("fileId") String fileId){
public WeaResult<Map<String, Object>> uploadTest(@RequestParam("fileId") String fileId,@RequestParam("tableName") String tableName){
Map<String,Object> returnMap = Maps.newHashMap();
try {
String sql = "select * from fileobj where id=?";
List<Map<String, Object>> list = databaseUtils.getSqlList(sql, CommonUtils.getParamList(fileId));
String sql = "select * from fileobj where id in ("+fileId+")";
List<Map<String, Object>> 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<Map<String, Object>> fieldList = databaseUtils.getSqlList(sql,CommonUtils.getParamList(tableName));
Map<String,List<Map<String, Object>>> fieldGroupByTitle = fieldList.stream().collect(Collectors.groupingBy(e->e.get("title").toString()));
Map<String, Object> 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<String> titles = ExcelSupport.getSheetHeader(sheet, 0);
@ -109,12 +116,25 @@ public class JclUpLoadFileController extends BaseCommonController {
}
dataList.add(singleCheck);
}
List<Map<String,Object>> list1 = Lists.newArrayList();
//处理导入附件
List<Map<String, String>> needUpdataList = Lists.newArrayList();
for (Map<String,Object> fileMap:fileList){
Map<String,Object> 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<String,Object> 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<String,String> 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<String, Object> importResult = uploadService.importData(needUpdataList,tableName,getCurrentUser());
returnMap.put("importResult",importResult);
returnMap.put("data",dataList);
}catch (Exception e){
log.error("error msg :[{}]",e);

View File

@ -20,19 +20,16 @@ import java.util.List;
public class ImportEmployeeAdvice implements ImportDataAdvice {
@Override
public void dataAdvice(BaseImportDataAdviceDto req) {
List<List<DataForImportEntity>> dataList = req.getDataList();
List<List<DataForImportEntity>> newDataList = Lists.newArrayList();
List<String> errorMsg = Lists.newArrayList();
for (List<DataForImportEntity> 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);

View File

@ -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<String, Object> uploadFile(Map<String,Object> fileMap, ModuleSource module, Long refId, SimpleEmployee employee, String chunks);
Map<String, Object> importData(List<Map<String, String>> dataList,String tableName,SimpleEmployee employee);
}

View File

@ -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<String, Object> uploadFile(Map<String,Object> 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<String, Object> importData(List<Map<String, String>> dataList,String tableName,SimpleEmployee employee) {
Map<String,Object> resultMap = Maps.newHashMap();
List<Map<String, Object>> 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<Map<String, Object>> fieldList = databaseUtils.getSqlList(sql,CommonUtils.getParamList(tableName));
Map<String,List<Map<String, Object>>> fieldGroupByTitle = fieldList.stream().collect(Collectors.groupingBy(e->e.get("title").toString()));
// sql = "select id,username from eteams.employee where delete_type=0";
// List<Map<String, Object>> userList = databaseUtils.getSqlList(sql);
// Map<String,List<Map<String, Object>>> 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<String,String> 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<String,String> 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<String,String> contractTypeMap = databaseUtils.getSqlList(sql).stream().collect(Collectors.toMap(e->e.get("name").toString(),e->e.get("id").toString()));
//
// List<Map<String, String>> inserData = Lists.newArrayList();
// for (Map<String, String> dataMap:dataList){
// //合同状态
// Map<String,String> newMap = Maps.newHashMap();
// for (Map.Entry<String, String> entry: dataMap.entrySet()){
// List<Map<String, Object>> 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<String,List<Map<String, String>>> dataGroupById = dataList.stream().collect(Collectors.groupingBy(e->e.get("id").toString()));
for (Map.Entry<String,List<Map<String, String>>>entry : dataGroupById.entrySet()){
Map<String,Object> updataMap = Maps.newHashMap();
String id = entry.getKey();
Map<String,Object> dataMap = Maps.newHashMap();
for (Map<String,String> map : entry.getValue()){
for (Map.Entry<String,String> 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<String,Object> 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 输入流