|
@@ -10,16 +10,12 @@ import com.management.platform.entity.bo.FormStorePageBO;
|
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.CusTableColumnService;
|
|
|
+import com.management.platform.service.ExcelExportService;
|
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -28,8 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.sql.DataSource;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
import java.sql.*;
|
|
|
import java.util.Date;
|
|
|
import java.util.*;
|
|
@@ -79,6 +73,12 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
@Resource
|
|
|
private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ExcelExportService excelExportService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ColumnFixTransMapper columnFixTransMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DataSource dataSource;
|
|
|
|
|
@@ -102,6 +102,10 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
public static final Pattern INSERT_SIGN_PATTERN = Pattern.compile(REGEX_INSERT_SIGN);
|
|
|
|
|
|
+ public static final String REGEX_COMMENT_SIGN = "shortName\\((.*?)\\)";
|
|
|
+
|
|
|
+ public static final Pattern COMMENT_SIGN_PATTERN = Pattern.compile(REGEX_COMMENT_SIGN);
|
|
|
+
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
|
|
|
@@ -129,7 +133,29 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
Map<String,Object> resMap = new HashMap<>();
|
|
|
resMap.put("busObject",busObject);
|
|
|
- List<CusTableColumn> columnList = cusTableColumnMapper.getStructByTableName(tableName);
|
|
|
+
|
|
|
+ //排除relation表中的关联字段
|
|
|
+ List<BusObjRelation> busObjRelations = busObjRelationMapper.selectList(new LambdaQueryWrapper<BusObjRelation>()
|
|
|
+ .eq(BusObjRelation::getFromTbl, tableName)
|
|
|
+ );
|
|
|
+ List<CusTableColumn> columnList = cusTableColumnMapper.getStructByTableName(tableName,busObjRelations);
|
|
|
+
|
|
|
+ //超过10个字段长度取shortName
|
|
|
+ for (CusTableColumn cusTableColumn : columnList) {
|
|
|
+ String columnComment = cusTableColumn.getColumnComment();
|
|
|
+ if(cusTableColumn.getColumnComment().length()>10){
|
|
|
+ Matcher matcher = COMMENT_SIGN_PATTERN.matcher(columnComment);
|
|
|
+ if(matcher.find()){
|
|
|
+ cusTableColumn.setColumnComment(matcher.group(1));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ int i = columnComment.indexOf("shortName");
|
|
|
+ if(-1 != i){
|
|
|
+ String trim = columnComment.substring(0, i).trim();
|
|
|
+ cusTableColumn.setColumnComment(trim);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//字段转义提示
|
|
|
if(1 == user.getUserNameNeedTranslate()){ //TODO user.getUserNameNeedTranslate()
|
|
@@ -777,13 +803,15 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
List<FormFieldHead> formFieldHeads = JSONArray.parseArray(cusReportForm.getFormFieldHead(), FormFieldHead.class);
|
|
|
|
|
|
- List<Map<String,String>> tableNameAliasList = new ArrayList<>();
|
|
|
+// List<Map<String,String>> tableNameAliasList = new ArrayList<>();
|
|
|
+ Map<String,String> tableNameAliasMap = new HashMap<>();
|
|
|
Matcher mainMatcher = MAIN_TABLE_PATTERN.matcher(tableColumnSql);
|
|
|
if (mainMatcher.find()) {
|
|
|
- Map<String,String> tableNameMap = new HashMap<>();
|
|
|
- tableNameMap.put("tableName",mainMatcher.group(1));
|
|
|
- tableNameMap.put("tableAlias",mainMatcher.group(2));
|
|
|
- tableNameAliasList.add(tableNameMap);
|
|
|
+// Map<String,String> tableNameMap = new HashMap<>();
|
|
|
+// tableNameMap.put("tableName",mainMatcher.group(1));
|
|
|
+// tableNameMap.put("tableAlias",mainMatcher.group(2));
|
|
|
+// tableNameAliasList.add(tableNameMap);
|
|
|
+ tableNameAliasMap.put(mainMatcher.group(1),mainMatcher.group(2));
|
|
|
} else {
|
|
|
msg.setError("主业务表无法识别,请联系管理员");
|
|
|
return msg;
|
|
@@ -791,19 +819,23 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
Matcher joinMatcher = JOIN_TABLE_PATTERN.matcher(tableColumnSql);
|
|
|
while (joinMatcher.find()){
|
|
|
- Map<String,String> tableNameMap = new HashMap<>();
|
|
|
- tableNameMap.put("tableName",joinMatcher.group(1));
|
|
|
- tableNameMap.put("tableAlias",joinMatcher.group(2));
|
|
|
- tableNameAliasList.add(tableNameMap);
|
|
|
+// Map<String,String> tableNameMap = new HashMap<>();
|
|
|
+// tableNameAliasMap.put("tableName",joinMatcher.group(1));
|
|
|
+// tableNameAliasMap.put("tableAlias",joinMatcher.group(2));
|
|
|
+// tableNameAliasList.add(tableNameMap);
|
|
|
+ tableNameAliasMap.put(joinMatcher.group(1),joinMatcher.group(2));
|
|
|
}
|
|
|
|
|
|
|
|
|
Map<String,List<String>> indexMap = new HashMap<>(2);
|
|
|
indexMap.put("userName",new ArrayList<>());
|
|
|
indexMap.put("deptName",new ArrayList<>());
|
|
|
- for (Map<String, String> tableNameMap : tableNameAliasList) {
|
|
|
- List<FormTransColumn> tmpColList = tblColumnMap.get(tableNameMap.get("tableName"));
|
|
|
- String tableAlias = tableNameMap.get("tableAlias");
|
|
|
+// for (Map<String, String> tableNameMap : tableNameAliasList) {
|
|
|
+ for (String tableName : tableNameAliasMap.keySet()) {
|
|
|
+ List<FormTransColumn> tmpColList = tblColumnMap.get(tableName);
|
|
|
+ String tableAlias = tableNameAliasMap.get(tableName);
|
|
|
+// List<FormTransColumn> tmpColList = tblColumnMap.get(tableNameMap.get("tableName"));
|
|
|
+// String tableAlias = tableNameMap.get("tableAlias");
|
|
|
if(CollectionUtils.isNotEmpty(tmpColList)){
|
|
|
for (FormTransColumn formTransColumn : tmpColList) {
|
|
|
String col = tableAlias+"."+formTransColumn.getColName();
|
|
@@ -811,23 +843,35 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
if(1 == formTransColumn.getTransType()){
|
|
|
//当前位置的是人名,需要转义
|
|
|
for (int i = 0; i < formFieldHeads.size(); i++) {
|
|
|
- if(formFieldHeads.get(i).getTableName().equals(tableNameMap.get("tableName"))
|
|
|
- &&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
+ if(formFieldHeads.get(i).getTableName().equals(tableName)
|
|
|
+ &&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
){
|
|
|
List<String> tmpList = indexMap.get("userName");
|
|
|
tmpList.add(formFieldHeads.get(i).getColumnVal());
|
|
|
}
|
|
|
+// if(formFieldHeads.get(i).getTableName().equals(tableNameMap.get("tableName"))
|
|
|
+// &&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
+// ){
|
|
|
+// List<String> tmpList = indexMap.get("userName");
|
|
|
+// tmpList.add(formFieldHeads.get(i).getColumnVal());
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
else if (2 == formTransColumn.getTransType()) {
|
|
|
//当前位置是部门,需要转义
|
|
|
for (int i = 0; i < formFieldHeads.size(); i++) {
|
|
|
- if(formFieldHeads.get(i).getTableName().equals(tableNameMap.get("tableName"))
|
|
|
+ if(formFieldHeads.get(i).getTableName().equals(tableName)
|
|
|
&&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
){
|
|
|
List<String> tmpList = indexMap.get("deptName");
|
|
|
tmpList.add(formFieldHeads.get(i).getColumnVal());
|
|
|
}
|
|
|
+// if(formFieldHeads.get(i).getTableName().equals(tableNameMap.get("tableName"))
|
|
|
+// &&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
+// ){
|
|
|
+// List<String> tmpList = indexMap.get("deptName");
|
|
|
+// tmpList.add(formFieldHeads.get(i).getColumnVal());
|
|
|
+// }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -837,6 +881,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
|
|
|
try (Connection connection = dataSource.getConnection()) {
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(tableColumnSql);
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
@@ -847,94 +892,165 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ //转换固定值
|
|
|
+ List<ColumnFixTrans> columnFixTrans = columnFixTransMapper.selectList(null);
|
|
|
+ Map<String, List<ColumnFixTrans>> tableColumnFixTransMap = columnFixTrans.stream()
|
|
|
+ .collect(Collectors.groupingBy(ColumnFixTrans::getTblName));// key tblName
|
|
|
+
|
|
|
+ //根据表头获取 'xxx' --> 别名.字段名 --> 表名.字段名
|
|
|
+ Map<String, FormFieldHead> columnAliasMap = new HashMap<>();
|
|
|
+ for (FormFieldHead formFieldHead : formFieldHeads) {
|
|
|
+ columnAliasMap.put(formFieldHead.getColumnVal(),formFieldHead);
|
|
|
+// ColumnAliasVO tmpVO = new ColumnAliasVO();
|
|
|
+// String key = formFieldHead.getColumnVal();
|
|
|
+// tmpVO.setColumnCHN(key);
|
|
|
+// tmpVO.setColumnTblName(formFieldHead.getTableName()+"."+formFieldHead.getColumnName());
|
|
|
+// tmpVO.setColumnAliasName(tableNameAliasMap.get(formFieldHead.getTableName())+"."+formFieldHead.getColumnName());
|
|
|
+// columnAliasMap.put(key,tmpVO);
|
|
|
+ }
|
|
|
+
|
|
|
if(CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ List<List<String>> resList=new ArrayList<>();
|
|
|
// 创建工作簿和工作表
|
|
|
- Workbook workbook = new XSSFWorkbook();
|
|
|
- Sheet sheet = workbook.createSheet("Sheet01");
|
|
|
+// Workbook workbook = new XSSFWorkbook();
|
|
|
+// Sheet sheet = workbook.createSheet("Sheet01");
|
|
|
|
|
|
// 创建表头
|
|
|
- Row headerRow = sheet.createRow(0);
|
|
|
- int colNum = 0;
|
|
|
- for (String key : dataList.get(0).keySet()) {
|
|
|
- Cell cell = headerRow.createCell(colNum++);
|
|
|
- cell.setCellValue(key);
|
|
|
+// Row headerRow = sheet.createRow(0);
|
|
|
+// int colNum = 0;
|
|
|
+// for (String key : dataList.get(0).keySet()) {
|
|
|
+// Cell cell = headerRow.createCell(colNum++);
|
|
|
+// cell.setCellValue(key);
|
|
|
+// }
|
|
|
+
|
|
|
+ List<String> titleList=new ArrayList<>();
|
|
|
+ for (String s : dataList.get(0).keySet()) {
|
|
|
+ titleList.add(s);
|
|
|
}
|
|
|
+ resList.add(titleList);
|
|
|
+
|
|
|
+ List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, user.getCompanyId()));
|
|
|
|
|
|
// 填充数据
|
|
|
- int rowNum = 1;
|
|
|
+// int rowNum = 1;
|
|
|
for (Map<String, Object> data : dataList) {
|
|
|
- Row row = sheet.createRow(rowNum++);
|
|
|
- colNum = 0;
|
|
|
+ String valRes = "";
|
|
|
+// Row row = sheet.createRow(rowNum++);
|
|
|
+// colNum = 0;
|
|
|
+ List<String> item=new ArrayList<>();
|
|
|
+
|
|
|
for (String key : dataList.get(0).keySet()) {
|
|
|
- List<String> userNameIndexes = indexMap.get("userName");
|
|
|
- List<String> deptNameIndexes = indexMap.get("deptName");
|
|
|
- if(1 == user.getUserNameNeedTranslate()){
|
|
|
- Cell cell = row.createCell(colNum++);
|
|
|
+
|
|
|
+ //固定值转换
|
|
|
+ FormFieldHead formFieldHead = columnAliasMap.get(key);//字段对应别名和表
|
|
|
+ List<ColumnFixTrans> transColList = tableColumnFixTransMap.get(formFieldHead.getTableName());//固定值字段集合
|
|
|
+ List<ColumnFixTrans> currentFixValList = transColList.stream()
|
|
|
+ .filter(t -> t.getColName().equals(formFieldHead.getColumnName()))
|
|
|
+ .collect(Collectors.toList());//当前字段固定值对照值
|
|
|
+ if(CollectionUtils.isNotEmpty(currentFixValList)){
|
|
|
+ Map<String, String> valMeanMap = currentFixValList.stream()
|
|
|
+ .collect(Collectors.toMap(ColumnFixTrans::getColVal, ColumnFixTrans::getValMean));
|
|
|
Object value = data.get(key);
|
|
|
- if (value == null) {
|
|
|
- cell.setCellValue(""); // 将null值替换为空格
|
|
|
- } else {
|
|
|
- String val = value.toString();
|
|
|
- if(CollectionUtils.isNotEmpty(userNameIndexes)){
|
|
|
- if(userNameIndexes.contains(key)){
|
|
|
- List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getName, val).last(" limit 1 ")
|
|
|
- );
|
|
|
- if(CollectionUtils.isNotEmpty(users)){
|
|
|
- val = "$username="+users.get(0).getCorpwxUserid()+"$";
|
|
|
+ String mean = valMeanMap.get(value.toString());
|
|
|
+ valRes = mean;
|
|
|
+ }else{
|
|
|
+ //转义
|
|
|
+ List<String> userNameIndexes = indexMap.get("userName");
|
|
|
+ List<String> deptNameIndexes = indexMap.get("deptName");
|
|
|
+ if(1 == user.getUserNameNeedTranslate()){
|
|
|
+// Cell cell = row.createCell(colNum++);
|
|
|
+ Object value = data.get(key);
|
|
|
+ if (value == null) {
|
|
|
+// cell.setCellValue(""); // 将null值替换为空格
|
|
|
+ } else {
|
|
|
+ String val = value.toString();
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ if(CollectionUtils.isNotEmpty(userNameIndexes) && userNameIndexes.contains(key)){
|
|
|
+// List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
+// .eq(User::getName, val).last(" limit 1 ")
|
|
|
+// );
|
|
|
+// if(CollectionUtils.isNotEmpty(users)){
|
|
|
+// val = "$username="+users.get(0).getCorpwxUserid()+"$";
|
|
|
+// }
|
|
|
+ String name = val;
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(name)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ val = "$userName="+first.get().getCorpwxUserid()+"$";
|
|
|
+ }else {
|
|
|
+ val = "";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if(CollectionUtils.isNotEmpty(deptNameIndexes)){
|
|
|
- if(deptNameIndexes.contains(key)){
|
|
|
- List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getName, val).last(" limit 1 ")
|
|
|
- );
|
|
|
- if(CollectionUtils.isNotEmpty(users)){
|
|
|
- val = "$departmentName="+users.get(0).getCorpwxDeptid()+"$";
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(deptNameIndexes) && deptNameIndexes.contains(key)){
|
|
|
+// List<User> users = userMapper.selectList(new LambdaQueryWrapper<User>()
|
|
|
+// .eq(User::getName, val).last(" limit 1 ")
|
|
|
+// );
|
|
|
+// if(CollectionUtils.isNotEmpty(users)){
|
|
|
+// val = "$departmentName="+users.get(0).getCorpwxDeptid()+"$";
|
|
|
+// }
|
|
|
+ String name = val;
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(name)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ val = "$departmentName="+first.get().getCorpwxDeptid()+"$";
|
|
|
+ }else {
|
|
|
+ val = "";
|
|
|
}
|
|
|
}
|
|
|
+// cell.setCellValue(val);
|
|
|
+ valRes = val;
|
|
|
}
|
|
|
- cell.setCellValue(val);
|
|
|
- }
|
|
|
|
|
|
- }else{
|
|
|
- Cell cell = row.createCell(colNum++);
|
|
|
- Object value = data.get(key);
|
|
|
- if (value == null) {
|
|
|
- cell.setCellValue(""); // 将null值替换为空格
|
|
|
- } else {
|
|
|
- cell.setCellValue(value.toString());
|
|
|
+ }else{
|
|
|
+// Cell cell = row.createCell(colNum++);
|
|
|
+ Object value = data.get(key);
|
|
|
+ if (value == null) {
|
|
|
+// cell.setCellValue(""); // 将null值替换为空格
|
|
|
+ valRes = "";
|
|
|
+ } else {
|
|
|
+// cell.setCellValue(value.toString());
|
|
|
+ valRes = value.toString();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ item.add(valRes);
|
|
|
}
|
|
|
+ resList.add(item);
|
|
|
}
|
|
|
|
|
|
// 自动调整列宽
|
|
|
- for (int i = 0; i < dataList.get(0).size(); i++) {
|
|
|
- sheet.autoSizeColumn(i);
|
|
|
- }
|
|
|
+// for (int i = 0; i < dataList.get(0).size(); i++) {
|
|
|
+// sheet.autoSizeColumn(i);
|
|
|
+// }
|
|
|
|
|
|
//生成Excel文件
|
|
|
- String fileUrlSuffix = cusReportForm.getReportFormName()+System.currentTimeMillis() + ".xlsx";
|
|
|
- try (FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix)){
|
|
|
- workbook.write(fos);
|
|
|
- msg.data = "/upload/" + fileUrlSuffix;
|
|
|
- } catch (NullPointerException e) {
|
|
|
- msg.setError(MessageUtils.message("access.verErrorOrDataLack"));
|
|
|
- return msg;
|
|
|
- } catch (IOException e) {
|
|
|
- msg.setError(MessageUtils.message("file.generateError"));
|
|
|
- return msg;
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- workbook.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ String fileUrlSuffix = cusReportForm.getReportFormName()+System.currentTimeMillis();
|
|
|
+// try (FileOutputStream fos = new FileOutputStream(path + fileUrlSuffix)){
|
|
|
+// workbook.write(fos);
|
|
|
+// msg.data = "/upload/" + fileUrlSuffix;
|
|
|
+// } catch (NullPointerException e) {
|
|
|
+// msg.setError(MessageUtils.message("access.verErrorOrDataLack"));
|
|
|
+// return msg;
|
|
|
+// } catch (IOException e) {
|
|
|
+// msg.setError(MessageUtils.message("file.generateError"));
|
|
|
+// return msg;
|
|
|
+// } finally {
|
|
|
+// try {
|
|
|
+// workbook.close();
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ try {
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileUrlSuffix,resList,path);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return msg;
|