Merge remote-tracking branch 'origin/main'

This commit is contained in:
Administrator 2025-05-26 15:59:54 +08:00
commit a1026b1bac
3 changed files with 80 additions and 119 deletions

View File

@ -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<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 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()));
returnMap = uploadService.jcluploadFile(list,tableName,getCurrentUser());
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);
returnMap.put("titles",titles);
log.error("title长度:{}",titles.get(0).length());
String title = titles.get(0).replace(" ", "");
log.error("处理前年月信息:{}",title);
// 处理数值
List<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 1, 0);
log.error("excel导入数据数量[{}]", data.size());
// 表头
List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
List<Map<String, String>> dataList = Lists.newArrayList();
List<Map<String,Object>> fileList = ExcelUtil.processEmbeddedObjects((XSSFSheet)sheet);
Map<String,Object> map = Maps.newHashMap();
for (int i = 0; i < data.size(); i++) {
map = data.get(i);
Map<String, String> 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<Map<String, String>> needUpdataList = Lists.newArrayList();
for (Map<String,Object> 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<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);
}
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);
return WeaResult.fail(e.getMessage(),true);

View File

@ -8,11 +8,10 @@ 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);
Map<String, Object> jcluploadFile(List<Map<String, Object>> list,String tableName,SimpleEmployee employee) throws Exception;
}

View File

@ -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<String, Object> jcluploadFile(List<Map<String, Object>> list,String tableName,SimpleEmployee employee) throws Exception {
Map<String,Object> returnMap = Maps.newHashMap();
List<Map<String, Object>> importList = Lists.newArrayList();
for (Map<String, Object> 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<String, Object> uploadFile(Map<String,Object> fileMap, ModuleSource module, Long refId,SimpleEmployee employee,String chunks) {
InputStream fileInputStream = fileData.getInputStream();
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
//标题
List<String> 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<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 1, 0);
log.error("excel导入数据数量[{}]", data.size());
// 表头
List<String> headers = ExcelSupport.getSheetHeader(sheet, 0);
List<Map<String, String>> dataList = Lists.newArrayList();
List<Map<String,Object>> fileList = ExcelUtil.processEmbeddedObjects((XSSFSheet)sheet);
Map<String,Object> map = Maps.newHashMap();
for (int i = 0; i < data.size(); i++) {
map = data.get(i);
Map<String, String> 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<Map<String, String>> needUpdataList = Lists.newArrayList();
for (Map<String,Object> 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<String,Object> 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<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);
}
Map<String, Object> importResult = importData(needUpdataList,tableName,employee);
importList.add(importResult);
}
returnMap.put("importList",importList);
return returnMap;
}
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);
@ -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<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();