|
@@ -1,5 +1,6 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -9,17 +10,26 @@ 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.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;
|
|
|
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.*;
|
|
@@ -60,6 +70,15 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
@Resource
|
|
|
private CompanyMapper companyMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FormTransColumnMapper formTransColumnMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DataSource dataSource;
|
|
|
|
|
@@ -67,6 +86,10 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
public static final Pattern MAIN_TABLE_PATTERN = Pattern.compile(REGEX_MAIN_TABLE);
|
|
|
|
|
|
+ public static final String REGEX_JOIN_TABLE = "(?i)\\bleft join\\b\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s+(?:AS\\s+)?([a-zA-Z_][a-zA-Z0-9_]*)";
|
|
|
+
|
|
|
+ public static final Pattern JOIN_TABLE_PATTERN = Pattern.compile(REGEX_JOIN_TABLE);
|
|
|
+
|
|
|
public static final String REGEX_DELETE_SIGN = "(?i)\\bdelete\\b";
|
|
|
|
|
|
public static final Pattern DELETE_SGIN_PATTERN = Pattern.compile(REGEX_DELETE_SIGN);
|
|
@@ -79,6 +102,9 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
|
|
|
public static final Pattern INSERT_SIGN_PATTERN = Pattern.compile(REGEX_INSERT_SIGN);
|
|
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
+ private String path;
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg getStructByTableName(String tableName, HttpServletRequest request) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -88,16 +114,40 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
msg.setError(MessageUtils.message("user.notExists"));
|
|
|
return msg;
|
|
|
}
|
|
|
- BusObject busObject = busObjectMapper.selectOne(new LambdaQueryWrapper<BusObject>()
|
|
|
- .eq(BusObject::getTblName, tableName)
|
|
|
- );
|
|
|
- if(null == busObject){
|
|
|
- msg.setError("该表不存在");
|
|
|
- return msg;
|
|
|
- }
|
|
|
+// BusObject busObject = busObjectMapper.selectOne(new LambdaQueryWrapper<BusObject>()
|
|
|
+// .eq(BusObject::getTblName, tableName)
|
|
|
+// );
|
|
|
+// if(null == busObject){
|
|
|
+// msg.setError("该表不存在");
|
|
|
+// return msg;
|
|
|
+// }
|
|
|
+ //直接读取表结构
|
|
|
+ String tableAlias = cusTableColumnMapper.getTableAliasByTableName(tableName);
|
|
|
+ BusObject busObject = new BusObject();
|
|
|
+ busObject.setTblName(tableName);
|
|
|
+ busObject.setName(tableAlias);
|
|
|
+
|
|
|
Map<String,Object> resMap = new HashMap<>();
|
|
|
resMap.put("busObject",busObject);
|
|
|
List<CusTableColumn> columnList = cusTableColumnMapper.getStructByTableName(tableName);
|
|
|
+
|
|
|
+ //字段转义提示
|
|
|
+ if(1 == user.getUserNameNeedTranslate()){ //TODO user.getUserNameNeedTranslate()
|
|
|
+ List<FormTransColumn> formTransColumns = formTransColumnMapper.selectList(new LambdaQueryWrapper<FormTransColumn>()
|
|
|
+ .eq(FormTransColumn::getTblName, tableName)
|
|
|
+ );
|
|
|
+ if(CollectionUtils.isNotEmpty(formTransColumns)){
|
|
|
+// List<String> colList = formTransColumns.stream().map(FormTransColumn::getColName).collect(Collectors.toList());
|
|
|
+ Map<String, FormTransColumn> collect = formTransColumns.stream().collect(Collectors.toMap(FormTransColumn::getColName, t -> t));
|
|
|
+ for (CusTableColumn cusTableColumn : columnList) {
|
|
|
+ FormTransColumn formTransColumn = collect.get(cusTableColumn.getColumnName());
|
|
|
+ if(null != formTransColumn){
|
|
|
+ cusTableColumn.setTransType(formTransColumn.getTransType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
resMap.put("columnList",columnList);
|
|
|
msg.setData(resMap);
|
|
|
return msg;
|
|
@@ -125,7 +175,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
public HttpRespMsg getRelateBusTableByFromTable(String tableName, HttpServletRequest request) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
List<BusObjRelation> relationList = busObjRelationMapper.selectList(new LambdaQueryWrapper<BusObjRelation>()
|
|
|
- .select(BusObjRelation::getToTbl, BusObjRelation::getFromColBusName)
|
|
|
+// .select(BusObjRelation::getToTbl, BusObjRelation::getFromColBusName)
|
|
|
.eq(BusObjRelation::getFromTbl, tableName)
|
|
|
);
|
|
|
msg.setData(relationList);
|
|
@@ -151,18 +201,34 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
List<CusReportForm> cusReportForms = cusReportFormMapper.selectList(new LambdaQueryWrapper<CusReportForm>()
|
|
|
.in(CusReportForm::getId, formIds)
|
|
|
);
|
|
|
+ Map<Integer, CusReportForm> reportFormMap = cusReportForms.stream().collect(Collectors.toMap(CusReportForm::getId,t->t));
|
|
|
List<ReportFormAccess> reportFormAccesses = reportFormAccessMapper.getAccessesByFormIds(user.getCompanyId(),formIds);
|
|
|
Map<Integer, List<ReportFormAccess>> accessGroupMap = reportFormAccesses.stream()
|
|
|
.collect(Collectors.groupingBy(ReportFormAccess::getRelateFormId));
|
|
|
- for (CusReportForm cusReportForm : cusReportForms) {
|
|
|
- List<ReportFormAccess> accesses = accessGroupMap.get(cusReportForm.getId());
|
|
|
- if(CollectionUtils.isNotEmpty(accesses)){
|
|
|
- List<ReportFormAccess> userAccesses = accesses.stream().filter(t -> 1 == t.getAccessType()).collect(Collectors.toList());
|
|
|
- List<ReportFormAccess> deptAccesses = accesses.stream().filter(t -> 2 == t.getAccessType()).collect(Collectors.toList());
|
|
|
- cusReportForm.setUserAccessList(userAccesses);
|
|
|
- cusReportForm.setDeptAccessList(deptAccesses);
|
|
|
+ for (BusReportStore record : records) {
|
|
|
+ if(null != record.getRelateFormId()){
|
|
|
+ CusReportForm tmpForm = reportFormMap.get(record.getRelateFormId());
|
|
|
+ if(null != tmpForm){
|
|
|
+ record.setPrivilege(tmpForm.getPrivilege());
|
|
|
+ }
|
|
|
+ List<ReportFormAccess> accesses = accessGroupMap.get( record.getRelateFormId());
|
|
|
+ if(CollectionUtils.isNotEmpty(accesses)){
|
|
|
+ List<ReportFormAccess> userAccesses = accesses.stream().filter(t -> 1 == t.getAccessType()).collect(Collectors.toList());
|
|
|
+ List<ReportFormAccess> deptAccesses = accesses.stream().filter(t -> 2 == t.getAccessType()).collect(Collectors.toList());
|
|
|
+ record.setUserAccessList(userAccesses);
|
|
|
+ record.setDeptAccessList(deptAccesses);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+// for (CusReportForm cusReportForm : cusReportForms) {
|
|
|
+// List<ReportFormAccess> accesses = accessGroupMap.get(cusReportForm.getId());
|
|
|
+// if(CollectionUtils.isNotEmpty(accesses)){
|
|
|
+// List<ReportFormAccess> userAccesses = accesses.stream().filter(t -> 1 == t.getAccessType()).collect(Collectors.toList());
|
|
|
+// List<ReportFormAccess> deptAccesses = accesses.stream().filter(t -> 2 == t.getAccessType()).collect(Collectors.toList());
|
|
|
+// cusReportForm.setUserAccessList(userAccesses);
|
|
|
+// cusReportForm.setDeptAccessList(deptAccesses);
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
page.setRecords(records);
|
|
|
}
|
|
@@ -184,17 +250,41 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
}
|
|
|
|
|
|
if(null == busReportStore.getId()){
|
|
|
+ Integer sameNameCheck = busReportStore.selectCount(new LambdaQueryWrapper<BusReportStore>()
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(BusReportStore::getStoreType, 1)
|
|
|
+ .eq(BusReportStore::getStoreName, busReportStore.getStoreName())
|
|
|
+ );
|
|
|
+ if(null != sameNameCheck && 0 < sameNameCheck){
|
|
|
+ msg.setError("已存在同名文件夹");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
BusReportStore lastStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
.eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
.eq(BusReportStore::getParentStoreId, busReportStore.getParentStoreId())
|
|
|
.orderByDesc(BusReportStore::getOrderItem)
|
|
|
.last(" limit 1")
|
|
|
);
|
|
|
- busReportStore.setOrderItem(lastStore.getOrderItem()+1);
|
|
|
+ if(null == lastStore){
|
|
|
+ busReportStore.setOrderItem(1);
|
|
|
+ }else{
|
|
|
+ busReportStore.setOrderItem(lastStore.getOrderItem()+1);
|
|
|
+ }
|
|
|
busReportStore.setCreateBy(user.getId());
|
|
|
busReportStore.setCompanyId(user.getCompanyId());
|
|
|
busReportStoreMapper.insert(busReportStore);
|
|
|
}else{
|
|
|
+ Integer sameNameCheck = busReportStore.selectCount(new LambdaQueryWrapper<BusReportStore>()
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(BusReportStore::getStoreType, 1)
|
|
|
+ .eq(BusReportStore::getStoreName, busReportStore.getStoreName())
|
|
|
+ .ne(BusReportStore::getId,busReportStore.getId())
|
|
|
+ );
|
|
|
+ if(null != sameNameCheck && 0 < sameNameCheck){
|
|
|
+ msg.setError("已存在同名文件夹");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
busReportStore.setUpdateBy(user.getId());
|
|
|
busReportStore.setUpdateTime(new Date());
|
|
|
|
|
@@ -223,15 +313,86 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
tableName= mainMatcher.group(1);
|
|
|
tableAlias = mainMatcher.group(2);
|
|
|
} else {
|
|
|
- msg.setError("主业务表无法识别公司,请联系管理员");
|
|
|
+ msg.setError("主业务表无法识别,请联系管理员");
|
|
|
return msg;
|
|
|
}
|
|
|
+// WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", user.getCompanyId()));
|
|
|
if(StringUtils.isNotBlank(tableAlias) && StringUtils.isNotBlank(tableName)){
|
|
|
String s = cusReportForm.getExecuteSql()+" and "+tableAlias+".company_id="+user.getCompanyId()+" ";
|
|
|
+
|
|
|
+// List<FormTransCondition> formTransConditions = JSONObject.parseArray(cusReportForm.getFormTransConditionJson(), FormTransCondition.class);
|
|
|
+// for (FormTransCondition formTransCondition : formTransConditions) {
|
|
|
+// String str = formTransCondition.getTblAlias()+"."+formTransCondition.getColName();
|
|
|
+// String replaceObj = str+" like concat('%','"+formTransCondition.getUseVal()+"','%')";
|
|
|
+// if(1 == formTransCondition.getTransType()){
|
|
|
+// HashMap<String, List> result = null;
|
|
|
+// try {
|
|
|
+// result = wxCorpInfoService.getOpenId(wxCorpInfo.getCorpid(), formTransCondition.getUseVal(), null,1,200);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// msg.setError("企微转义有误,请联系管理员");
|
|
|
+// return msg;
|
|
|
+// }
|
|
|
+// List users = result.get("user");
|
|
|
+// List<User> realUser = userMapper.getUserByDepartment(null, user.getCompanyId(), null,null, null, null, null, users);
|
|
|
+// String replaceStr = str+" in(";
|
|
|
+// int count = 0;
|
|
|
+// for (User tmpUser : realUser) {
|
|
|
+// replaceStr += "'"+tmpUser.getName()+"'";
|
|
|
+// count++;
|
|
|
+// if(count<realUser.size()){
|
|
|
+// replaceStr += ", ";
|
|
|
+// }
|
|
|
+// }
|
|
|
+// replaceStr +=") ";
|
|
|
+//
|
|
|
+// s.replace(replaceObj,replaceStr);
|
|
|
+//
|
|
|
+// } else if (2 == formTransCondition.getTransType()) {
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
cusReportForm.setExecuteSql(s);
|
|
|
+
|
|
|
+ PreparedStatement preparedStatement = null;
|
|
|
+ ResultSet resultSet = null;
|
|
|
+ try (Connection connection = dataSource.getConnection()) {
|
|
|
+ preparedStatement = connection.prepareStatement(s);
|
|
|
+ resultSet = preparedStatement.executeQuery();
|
|
|
+ }catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("SQL语句有误,请联系管理员");
|
|
|
+ return msg;
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ if (resultSet != null)
|
|
|
+ resultSet.close();
|
|
|
+ resultSet = null;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (preparedStatement != null)
|
|
|
+ preparedStatement.close();
|
|
|
+ preparedStatement = null;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(null == cusReportForm.getId()){
|
|
|
|
|
|
- Company company = companyMapper.selectById(user.getId());
|
|
|
+ Integer sameNameCheck = cusReportFormMapper.selectCount(new LambdaQueryWrapper<CusReportForm>()
|
|
|
+ .eq(CusReportForm::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(CusReportForm::getReportFormName, cusReportForm.getReportFormName())
|
|
|
+ );
|
|
|
+ if(null != sameNameCheck && 0 < sameNameCheck){
|
|
|
+ msg.setError("已存在同名报表");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ Company company = companyMapper.selectById(user.getCompanyId());
|
|
|
if(1 == company.getVersionControl()){
|
|
|
Integer count = busReportStoreMapper.selectCount(new LambdaQueryWrapper<BusReportStore>()
|
|
|
.eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
@@ -242,6 +403,10 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ cusReportForm.setCreateBy(user.getId());
|
|
|
+ cusReportForm.setCompanyId(user.getCompanyId());
|
|
|
+ cusReportFormMapper.insert(cusReportForm);
|
|
|
+
|
|
|
BusReportStore lastStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
.eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
.eq(BusReportStore::getParentStoreId, cusReportForm.getParentStoreId())
|
|
@@ -249,6 +414,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
.last(" limit 1")
|
|
|
);
|
|
|
BusReportStore busReportStore = new BusReportStore();
|
|
|
+ busReportStore.setRelateFormId(cusReportForm.getId());
|
|
|
busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
|
busReportStore.setCreateBy(user.getId());
|
|
|
busReportStore.setStoreType(2);
|
|
@@ -262,27 +428,46 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
}
|
|
|
busReportStoreMapper.insert(busReportStore);
|
|
|
|
|
|
- cusReportForm.setCreateBy(user.getId());
|
|
|
- cusReportForm.setCompanyId(user.getCompanyId());
|
|
|
- cusReportFormMapper.insert(cusReportForm);
|
|
|
-
|
|
|
List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
|
// List<ReportFormAccess> deptAccessList = cusReportForm.getDeptAccessList();
|
|
|
- List<Integer> departmentIds = cusReportForm.getDepartmentIds();
|
|
|
- if(CollectionUtils.isNotEmpty(departmentIds)){
|
|
|
- for (Integer deptId: departmentIds) {
|
|
|
+ if(StringUtils.isNotBlank(cusReportForm.getDepartmentIds())){
|
|
|
+ String[] departmentIds = cusReportForm.getDepartmentIds().split(",");
|
|
|
+ for (String deptId: departmentIds) {
|
|
|
ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
reportFormAccess.setAccessType(2);
|
|
|
- reportFormAccess.setDepartmentId(deptId);
|
|
|
+ reportFormAccess.setDepartmentId(Integer.parseInt(deptId));
|
|
|
toAddList.add(reportFormAccess);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// List<Integer> departmentIds = cusReportForm.getDepartmentIds();
|
|
|
+// if(CollectionUtils.isNotEmpty(departmentIds)){
|
|
|
+// for (Integer deptId: departmentIds) {
|
|
|
+// ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
+// reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
+// reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
+// reportFormAccess.setAccessType(2);
|
|
|
+// reportFormAccess.setDepartmentId(deptId);
|
|
|
+// toAddList.add(reportFormAccess);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
// List<ReportFormAccess> userAccessList = cusReportForm.getUserAccessList();
|
|
|
- List<String> userIds = cusReportForm.getUserIds();
|
|
|
- if(CollectionUtils.isNotEmpty(userIds)){
|
|
|
+// List<String> userIds = cusReportForm.getUserIds();
|
|
|
+// if(CollectionUtils.isNotEmpty(userIds)){
|
|
|
+// for (String userId: userIds) {
|
|
|
+// ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
+// reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
+// reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
+// reportFormAccess.setAccessType(1);
|
|
|
+// reportFormAccess.setUserId(userId);
|
|
|
+// toAddList.add(reportFormAccess);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ if(StringUtils.isNotBlank(cusReportForm.getUserIds())){
|
|
|
+ String[] userIds = cusReportForm.getUserIds().split(",");
|
|
|
for (String userId: userIds) {
|
|
|
ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
@@ -292,14 +477,46 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
toAddList.add(reportFormAccess);
|
|
|
}
|
|
|
}
|
|
|
- reportFormAccessMapper.batchInsert(toAddList);
|
|
|
+// List<List<ReportFormAccess>> all = new ArrayList<>();
|
|
|
+// if (toAddList.size() > 500) {
|
|
|
+// int i = 0;
|
|
|
+// while (i < toAddList.size()) {
|
|
|
+// List<ReportFormAccess> subList;
|
|
|
+// if (i + 500 > toAddList.size()) {
|
|
|
+// subList = toAddList.subList(i, toAddList.size());
|
|
|
+// } else {
|
|
|
+// subList = toAddList.subList(i, i + 500);
|
|
|
+// }
|
|
|
+// i = i + 500;
|
|
|
+// all.add(subList);
|
|
|
+// }
|
|
|
+// for (List<ReportFormAccess> reportFormAccesses : all) {
|
|
|
+// reportFormAccessMapper.batchInsert(reportFormAccesses);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// reportFormAccessMapper.batchInsert(toAddList);
|
|
|
+// }
|
|
|
+ for (ReportFormAccess reportFormAccess : toAddList) {
|
|
|
+ reportFormAccessMapper.insert(reportFormAccess);
|
|
|
+ }
|
|
|
+// reportFormAccessMapper.batchInsert(toAddList);
|
|
|
|
|
|
}else{
|
|
|
BusReportStore busReportStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
.eq(BusReportStore::getRelateFormId, cusReportForm.getId())
|
|
|
);
|
|
|
if(null != busReportStore){
|
|
|
+ Integer sameNameCheck = cusReportFormMapper.selectCount(new LambdaQueryWrapper<CusReportForm>()
|
|
|
+ .eq(CusReportForm::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(CusReportForm::getReportFormName, cusReportForm.getReportFormName())
|
|
|
+ .ne(CusReportForm::getId,cusReportForm.getId())
|
|
|
+ );
|
|
|
+ if(null != sameNameCheck && 0 < sameNameCheck){
|
|
|
+ msg.setError("已存在同名报表");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
|
+ busReportStore.setRelateFormId(cusReportForm.getId());
|
|
|
busReportStore.setUpdateBy(user.getId());
|
|
|
busReportStore.setUpdateTime(new Date());
|
|
|
busReportStore.setParentStoreId(cusReportForm.getParentStoreId());
|
|
@@ -309,29 +526,76 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
cusReportFormMapper.updateById(cusReportForm);
|
|
|
|
|
|
List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
|
- List<ReportFormAccess> deptAccessList = cusReportForm.getDeptAccessList();
|
|
|
- if(CollectionUtils.isNotEmpty(deptAccessList)){
|
|
|
- for (ReportFormAccess reportFormAccess : deptAccessList) {
|
|
|
+// List<ReportFormAccess> deptAccessList = cusReportForm.getDeptAccessList();
|
|
|
+// if(CollectionUtils.isNotEmpty(deptAccessList)){
|
|
|
+// for (ReportFormAccess reportFormAccess : deptAccessList) {
|
|
|
+// reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
+// reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
+// reportFormAccess.setAccessType(2);
|
|
|
+// toAddList.add(reportFormAccess);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// List<ReportFormAccess> userAccessList = cusReportForm.getUserAccessList();
|
|
|
+// if(CollectionUtils.isNotEmpty(userAccessList)){
|
|
|
+// for (ReportFormAccess reportFormAccess : userAccessList) {
|
|
|
+// reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
+// reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
+// reportFormAccess.setAccessType(1);
|
|
|
+// toAddList.add(reportFormAccess);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(cusReportForm.getDepartmentIds())){
|
|
|
+ String[] departmentIds = cusReportForm.getDepartmentIds().split(",");
|
|
|
+ for (String deptId: departmentIds) {
|
|
|
+ ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
reportFormAccess.setAccessType(2);
|
|
|
+ reportFormAccess.setDepartmentId(Integer.parseInt(deptId));
|
|
|
toAddList.add(reportFormAccess);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- List<ReportFormAccess> userAccessList = cusReportForm.getUserAccessList();
|
|
|
- if(CollectionUtils.isNotEmpty(userAccessList)){
|
|
|
- for (ReportFormAccess reportFormAccess : userAccessList) {
|
|
|
+ if(StringUtils.isNotBlank(cusReportForm.getUserIds())){
|
|
|
+ String[] userIds = cusReportForm.getUserIds().split(",");
|
|
|
+ for (String userId: userIds) {
|
|
|
+ ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
|
reportFormAccess.setAccessType(1);
|
|
|
+ reportFormAccess.setUserId(userId);
|
|
|
toAddList.add(reportFormAccess);
|
|
|
}
|
|
|
}
|
|
|
reportFormAccessMapper.delete(new LambdaQueryWrapper<ReportFormAccess>()
|
|
|
.eq(ReportFormAccess::getRelateFormId, cusReportForm.getId())
|
|
|
);
|
|
|
- reportFormAccessMapper.batchInsert(toAddList);
|
|
|
+
|
|
|
+// List<List<ReportFormAccess>> all = new ArrayList<>();
|
|
|
+// if (toAddList.size() > 500) {
|
|
|
+// int i = 0;
|
|
|
+// while (i < toAddList.size()) {
|
|
|
+// List<ReportFormAccess> subList;
|
|
|
+// if (i + 500 > toAddList.size()) {
|
|
|
+// subList = toAddList.subList(i, toAddList.size());
|
|
|
+// } else {
|
|
|
+// subList = toAddList.subList(i, i + 500);
|
|
|
+// }
|
|
|
+// i = i + 500;
|
|
|
+// all.add(subList);
|
|
|
+// }
|
|
|
+// for (List<ReportFormAccess> reportFormAccesses : all) {
|
|
|
+// reportFormAccessMapper.batchInsert(reportFormAccesses);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// reportFormAccessMapper.batchInsert(toAddList);
|
|
|
+// }
|
|
|
+
|
|
|
+ for (ReportFormAccess reportFormAccess : toAddList) {
|
|
|
+ reportFormAccessMapper.insert(reportFormAccess);
|
|
|
+ }
|
|
|
+// reportFormAccessMapper.batchInsert(toAddList);
|
|
|
|
|
|
}else{
|
|
|
msg.setError("未找到对应报表");
|
|
@@ -395,7 +659,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
try (Connection connection = dataSource.getConnection()) {
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(tableColumnSql);
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
- columnList = this.convertList(resultSet);
|
|
|
+ columnList = this.convertListWithAlias(resultSet);
|
|
|
}catch (SQLException e) {
|
|
|
e.printStackTrace();
|
|
|
msg.setError("SQL语句有误,请联系管理员");
|
|
@@ -444,12 +708,238 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
|
List<BusReportStore> busReportStores = busReportStoreMapper.selectList(new LambdaQueryWrapper<BusReportStore>()
|
|
|
.eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
+ .ne(BusReportStore::getStoreType,2)
|
|
|
);
|
|
|
List<BusReportStore> listTree = this.listToTree(busReportStores);
|
|
|
msg.setData(listTree);
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getResByFormJson(String formJson, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ List<Map<String,Object>> columnList = new ArrayList<>();
|
|
|
+ Matcher deleteMatcher = DELETE_SGIN_PATTERN.matcher(formJson);
|
|
|
+ Matcher updateMatcher = UPDATE_SIGN_PATTERN.matcher(formJson);
|
|
|
+ Matcher insertMatcher = INSERT_SIGN_PATTERN.matcher(formJson);
|
|
|
+ if (deleteMatcher.find() || updateMatcher.find() || insertMatcher.find()) {
|
|
|
+ msg.setError("包含非法字符,无法执行");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ try (Connection connection = dataSource.getConnection()) {
|
|
|
+ PreparedStatement preparedStatement = connection.prepareStatement(formJson);
|
|
|
+ ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
+ columnList = this.convertListWithAlias(resultSet);
|
|
|
+ }catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("SQL语句有误,请联系管理员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ msg.setData(columnList);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getFormJsonByFormId(Integer formId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ CusReportForm cusReportForm = cusReportFormMapper.selectById(formId);
|
|
|
+// Map<String,Object> map = new HashMap<>();
|
|
|
+// map.put("formJson",cusReportForm.getFormJson());
|
|
|
+// map.put("formFieldHead",cusReportForm.getFormFieldHead());
|
|
|
+ msg.setData(cusReportForm.getFormJson());
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportCusReportForm(Integer formId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ CusReportForm cusReportForm = cusReportFormMapper.selectById(formId);
|
|
|
+ /**
|
|
|
+ * 获取表名和别名
|
|
|
+ * 1、获取主表和别名
|
|
|
+ * 2、若存在left join 获取从表和别名
|
|
|
+ * */
|
|
|
+ if(null == cusReportForm){
|
|
|
+ msg.setError("未找到该报表,请联系管理员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+
|
|
|
+ List<FormTransColumn> columnList = formTransColumnMapper.selectList(new LambdaQueryWrapper<FormTransColumn>());
|
|
|
+ Map<String, List<FormTransColumn>> tblColumnMap = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(columnList)){
|
|
|
+ tblColumnMap = columnList.stream()
|
|
|
+ .collect(Collectors.groupingBy(FormTransColumn::getTblName));
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ String tableColumnSql = cusReportForm.getExecuteSql();
|
|
|
+
|
|
|
+ List<FormFieldHead> formFieldHeads = JSONArray.parseArray(cusReportForm.getFormFieldHead(), FormFieldHead.class);
|
|
|
+
|
|
|
+ List<Map<String,String>> tableNameAliasList = new ArrayList<>();
|
|
|
+ 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);
|
|
|
+ } else {
|
|
|
+ msg.setError("主业务表无法识别,请联系管理员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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,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");
|
|
|
+ if(CollectionUtils.isNotEmpty(tmpColList)){
|
|
|
+ for (FormTransColumn formTransColumn : tmpColList) {
|
|
|
+ String col = tableAlias+"."+formTransColumn.getColName();
|
|
|
+ if(tableColumnSql.contains(col)){
|
|
|
+ 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())
|
|
|
+ ){
|
|
|
+ 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"))
|
|
|
+ &&formFieldHeads.get(i).getColumnName().equals(formTransColumn.getColName())
|
|
|
+ ){
|
|
|
+ List<String> tmpList = indexMap.get("deptName");
|
|
|
+ tmpList.add(formFieldHeads.get(i).getColumnVal());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try (Connection connection = dataSource.getConnection()) {
|
|
|
+ PreparedStatement preparedStatement = connection.prepareStatement(tableColumnSql);
|
|
|
+ ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
+ dataList = convertListWithAlias(resultSet);
|
|
|
+ }catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("SQL语句有误,请联系管理员");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(dataList)){
|
|
|
+ // 创建工作簿和工作表
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 填充数据
|
|
|
+ int rowNum = 1;
|
|
|
+ for (Map<String, Object> data : dataList) {
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
+ colNum = 0;
|
|
|
+ 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++);
|
|
|
+ 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()+"$";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()+"$";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自动调整列宽
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
private List<BusReportStore> listToTree(List<BusReportStore> treeNodeList){
|
|
|
if(null == treeNodeList){
|
|
|
return null;
|
|
@@ -481,7 +971,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
while (rs.next()) {
|
|
|
Map<String, Object> rowData = new HashMap<String, Object>();
|
|
|
for (int i = 1; i <= columnCount; i++) {
|
|
|
- rowData.put(md.getColumnName(i), rs.getObject(i));
|
|
|
+ rowData.put(md.getTableName(i)+"_"+md.getColumnName(i), rs.getObject(i));
|
|
|
}
|
|
|
list.add(rowData);
|
|
|
}
|
|
@@ -498,4 +988,32 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public static List<Map<String, Object>> convertListWithAlias(ResultSet rs) {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+ try {
|
|
|
+ ResultSetMetaData md = rs.getMetaData();
|
|
|
+ int columnCount = md.getColumnCount();
|
|
|
+ while (rs.next()) {
|
|
|
+ Map<String, Object> rowData = new HashMap<String, Object>();
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ rowData.put(md.getColumnLabel(i), rs.getObject(i));
|
|
|
+ }
|
|
|
+ list.add(rowData);
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (rs != null)
|
|
|
+ rs.close();
|
|
|
+ rs = null;
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|