|
@@ -6,19 +6,25 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.bo.FormStorePageBO;
|
|
import com.management.platform.entity.bo.FormStorePageBO;
|
|
-import com.management.platform.entity.bo.PageBO;
|
|
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.service.CusTableColumnService;
|
|
import com.management.platform.service.CusTableColumnService;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.MessageUtils;
|
|
import com.management.platform.util.MessageUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.sql.DataSource;
|
|
|
|
+import java.sql.*;
|
|
|
|
+import java.util.Date;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.regex.Matcher;
|
|
|
|
+import java.util.regex.Pattern;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -51,6 +57,28 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
@Resource
|
|
@Resource
|
|
private SysRoleFunctionMapper sysRoleFunctionMapper;
|
|
private SysRoleFunctionMapper sysRoleFunctionMapper;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private CompanyMapper companyMapper;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataSource dataSource;
|
|
|
|
+
|
|
|
|
+ public static final String REGEX_MAIN_TABLE = "(?i)\\bFROM\\b\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\s+(?:AS\\s+)?([a-zA-Z_][a-zA-Z0-9_]*)";
|
|
|
|
+
|
|
|
|
+ public static final Pattern MAIN_TABLE_PATTERN = Pattern.compile(REGEX_MAIN_TABLE);
|
|
|
|
+
|
|
|
|
+ public static final String REGEX_DELETE_SIGN = "(?i)\\bdelete\\b";
|
|
|
|
+
|
|
|
|
+ public static final Pattern DELETE_SGIN_PATTERN = Pattern.compile(REGEX_DELETE_SIGN);
|
|
|
|
+
|
|
|
|
+ public static final String REGEX_UPDATE_SIGN = "(?i)\\bupdate\\b";
|
|
|
|
+
|
|
|
|
+ public static final Pattern UPDATE_SIGN_PATTERN = Pattern.compile(REGEX_UPDATE_SIGN);
|
|
|
|
+
|
|
|
|
+ public static final String REGEX_INSERT_SIGN = "(?i)\\binsert\\b";
|
|
|
|
+
|
|
|
|
+ public static final Pattern INSERT_SIGN_PATTERN = Pattern.compile(REGEX_INSERT_SIGN);
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getStructByTableName(String tableName, HttpServletRequest request) {
|
|
public HttpRespMsg getStructByTableName(String tableName, HttpServletRequest request) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -105,17 +133,16 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public HttpRespMsg getFormStorePage(PageBO<FormStorePageBO> queryBO,HttpServletRequest request) {
|
|
|
|
|
|
+ public HttpRespMsg getFormStorePage(FormStorePageBO queryBO,HttpServletRequest request) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
IPage<BusReportStore> page =new Page<>();
|
|
IPage<BusReportStore> page =new Page<>();
|
|
page.setCurrent(queryBO.getPageIndex());
|
|
page.setCurrent(queryBO.getPageIndex());
|
|
page.setSize(queryBO.getPageSize());
|
|
page.setSize(queryBO.getPageSize());
|
|
- FormStorePageBO pageQueryBO = queryBO.getData();
|
|
|
|
- pageQueryBO.setUserId(user.getId());
|
|
|
|
- pageQueryBO.setDepartmentId(user.getDepartmentId());
|
|
|
|
- pageQueryBO.setCompanyId(user.getCompanyId());
|
|
|
|
- page = busReportStoreMapper.getPrivilegedFormStore(page,queryBO.getData());
|
|
|
|
|
|
+ queryBO.setUserId(user.getId());
|
|
|
|
+ queryBO.setDepartmentId(user.getDepartmentId());
|
|
|
|
+ queryBO.setCompanyId(user.getCompanyId());
|
|
|
|
+ page = busReportStoreMapper.getPrivilegedFormStore(page,queryBO);
|
|
List<BusReportStore> records = page.getRecords();
|
|
List<BusReportStore> records = page.getRecords();
|
|
if(CollectionUtils.isNotEmpty(records)){
|
|
if(CollectionUtils.isNotEmpty(records)){
|
|
List<Integer> formIds = records.stream().filter(t -> null != t.getRelateFormId()).map(BusReportStore::getRelateFormId)
|
|
List<Integer> formIds = records.stream().filter(t -> null != t.getRelateFormId()).map(BusReportStore::getRelateFormId)
|
|
@@ -157,6 +184,13 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
}
|
|
}
|
|
|
|
|
|
if(null == busReportStore.getId()){
|
|
if(null == busReportStore.getId()){
|
|
|
|
+ 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);
|
|
busReportStore.setCreateBy(user.getId());
|
|
busReportStore.setCreateBy(user.getId());
|
|
busReportStore.setCompanyId(user.getCompanyId());
|
|
busReportStore.setCompanyId(user.getCompanyId());
|
|
busReportStoreMapper.insert(busReportStore);
|
|
busReportStoreMapper.insert(busReportStore);
|
|
@@ -171,88 +205,137 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional
|
|
public HttpRespMsg addOrUpdateReportForm(CusReportForm cusReportForm, HttpServletRequest request) {
|
|
public HttpRespMsg addOrUpdateReportForm(CusReportForm cusReportForm, HttpServletRequest request) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
- if(null == cusReportForm.getId()){
|
|
|
|
- BusReportStore busReportStore = new BusReportStore();
|
|
|
|
- busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
|
|
- busReportStore.setCreateBy(user.getId());
|
|
|
|
- busReportStore.setStoreType(2);
|
|
|
|
- busReportStore.setOrderItem(cusReportForm.getOrderItem());
|
|
|
|
- busReportStore.setParentStoreId(cusReportForm.getParentStoreId());
|
|
|
|
- busReportStore.setDescription(cusReportForm.getDescription());
|
|
|
|
- busReportStore.setCompanyId(user.getCompanyId());
|
|
|
|
- busReportStoreMapper.insert(busReportStore);
|
|
|
|
-
|
|
|
|
- cusReportForm.setCreateBy(user.getId());
|
|
|
|
- cusReportForm.setCompanyId(user.getCompanyId());
|
|
|
|
- cusReportFormMapper.insert(cusReportForm);
|
|
|
|
-
|
|
|
|
- List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
|
|
- 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);
|
|
|
|
|
|
+ Matcher deleteMatcher = DELETE_SGIN_PATTERN.matcher(cusReportForm.getExecuteSql());
|
|
|
|
+ Matcher updateMatcher = UPDATE_SIGN_PATTERN.matcher(cusReportForm.getExecuteSql());
|
|
|
|
+ Matcher insertMatcher = INSERT_SIGN_PATTERN.matcher(cusReportForm.getExecuteSql());
|
|
|
|
+ if (deleteMatcher.find() || updateMatcher.find() || insertMatcher.find()) {
|
|
|
|
+ msg.setError("包含非法字符,无法存储");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ Matcher mainMatcher = MAIN_TABLE_PATTERN.matcher(cusReportForm.getExecuteSql());
|
|
|
|
+ String tableName = "";
|
|
|
|
+ String tableAlias = "";
|
|
|
|
+ if (mainMatcher.find()) {
|
|
|
|
+ tableName= mainMatcher.group(1);
|
|
|
|
+ tableAlias = mainMatcher.group(2);
|
|
|
|
+ } else {
|
|
|
|
+ msg.setError("主业务表无法识别公司,请联系管理员");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ if(StringUtils.isNotBlank(tableAlias) && StringUtils.isNotBlank(tableName)){
|
|
|
|
+ String s = cusReportForm.getExecuteSql()+" and "+tableAlias+".company_id="+user.getCompanyId()+" ";
|
|
|
|
+ cusReportForm.setExecuteSql(s);
|
|
|
|
+ if(null == cusReportForm.getId()){
|
|
|
|
+
|
|
|
|
+ Company company = companyMapper.selectById(user.getId());
|
|
|
|
+ if(1 == company.getVersionControl()){
|
|
|
|
+ Integer count = busReportStoreMapper.selectCount(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
|
+ );
|
|
|
|
+ if(count >= 5){
|
|
|
|
+ msg.setError("专业版最多可创建5张报表,请升级到旗舰版");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- reportFormAccessMapper.batchInsert(toAddList);
|
|
|
|
|
|
|
|
- }else{
|
|
|
|
- BusReportStore busReportStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
- .eq(BusReportStore::getRelateFormId, cusReportForm.getId())
|
|
|
|
- );
|
|
|
|
- if(null != busReportStore){
|
|
|
|
|
|
+ BusReportStore lastStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(BusReportStore::getParentStoreId, cusReportForm.getParentStoreId())
|
|
|
|
+ .orderByDesc(BusReportStore::getOrderItem)
|
|
|
|
+ .last(" limit 1")
|
|
|
|
+ );
|
|
|
|
+ BusReportStore busReportStore = new BusReportStore();
|
|
busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
- busReportStore.setUpdateBy(user.getId());
|
|
|
|
- busReportStore.setUpdateTime(new Date());
|
|
|
|
- busReportStore.setOrderItem(cusReportForm.getOrderItem());
|
|
|
|
|
|
+ busReportStore.setCreateBy(user.getId());
|
|
|
|
+ busReportStore.setStoreType(2);
|
|
busReportStore.setParentStoreId(cusReportForm.getParentStoreId());
|
|
busReportStore.setParentStoreId(cusReportForm.getParentStoreId());
|
|
busReportStore.setDescription(cusReportForm.getDescription());
|
|
busReportStore.setDescription(cusReportForm.getDescription());
|
|
- busReportStoreMapper.updateById(busReportStore);
|
|
|
|
|
|
+ busReportStore.setCompanyId(user.getCompanyId());
|
|
|
|
+ if(null == lastStore){
|
|
|
|
+ busReportStore.setOrderItem(1);
|
|
|
|
+ }else{
|
|
|
|
+ busReportStore.setOrderItem(lastStore.getOrderItem()+1);
|
|
|
|
+ }
|
|
|
|
+ busReportStoreMapper.insert(busReportStore);
|
|
|
|
|
|
- cusReportFormMapper.updateById(cusReportForm);
|
|
|
|
|
|
+ cusReportForm.setCreateBy(user.getId());
|
|
|
|
+ cusReportForm.setCompanyId(user.getCompanyId());
|
|
|
|
+ cusReportFormMapper.insert(cusReportForm);
|
|
|
|
|
|
List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
- List<ReportFormAccess> deptAccessList = cusReportForm.getDeptAccessList();
|
|
|
|
- if(CollectionUtils.isNotEmpty(deptAccessList)){
|
|
|
|
- for (ReportFormAccess reportFormAccess : deptAccessList) {
|
|
|
|
|
|
+// List<ReportFormAccess> deptAccessList = cusReportForm.getDeptAccessList();
|
|
|
|
+ List<Integer> departmentIds = cusReportForm.getDepartmentIds();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(departmentIds)){
|
|
|
|
+ for (Integer deptId: departmentIds) {
|
|
|
|
+ ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
reportFormAccess.setAccessType(2);
|
|
reportFormAccess.setAccessType(2);
|
|
|
|
+ reportFormAccess.setDepartmentId(deptId);
|
|
toAddList.add(reportFormAccess);
|
|
toAddList.add(reportFormAccess);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- List<ReportFormAccess> userAccessList = cusReportForm.getUserAccessList();
|
|
|
|
- if(CollectionUtils.isNotEmpty(userAccessList)){
|
|
|
|
- for (ReportFormAccess reportFormAccess : userAccessList) {
|
|
|
|
|
|
+// List<ReportFormAccess> userAccessList = cusReportForm.getUserAccessList();
|
|
|
|
+ List<String> userIds = cusReportForm.getUserIds();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(userIds)){
|
|
|
|
+ for (String userId: userIds) {
|
|
|
|
+ ReportFormAccess reportFormAccess = new ReportFormAccess();
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
reportFormAccess.setRelateFormId(cusReportForm.getId());
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
reportFormAccess.setCompanyId(user.getCompanyId());
|
|
reportFormAccess.setAccessType(1);
|
|
reportFormAccess.setAccessType(1);
|
|
|
|
+ reportFormAccess.setUserId(userId);
|
|
toAddList.add(reportFormAccess);
|
|
toAddList.add(reportFormAccess);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- reportFormAccessMapper.delete(new LambdaQueryWrapper<ReportFormAccess>()
|
|
|
|
- .eq(ReportFormAccess::getRelateFormId, cusReportForm.getId())
|
|
|
|
- );
|
|
|
|
reportFormAccessMapper.batchInsert(toAddList);
|
|
reportFormAccessMapper.batchInsert(toAddList);
|
|
|
|
|
|
}else{
|
|
}else{
|
|
- msg.setError("未找到对应报表");
|
|
|
|
|
|
+ BusReportStore busReportStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getRelateFormId, cusReportForm.getId())
|
|
|
|
+ );
|
|
|
|
+ if(null != busReportStore){
|
|
|
|
+ busReportStore.setStoreName(cusReportForm.getReportFormName());
|
|
|
|
+ busReportStore.setUpdateBy(user.getId());
|
|
|
|
+ busReportStore.setUpdateTime(new Date());
|
|
|
|
+ busReportStore.setParentStoreId(cusReportForm.getParentStoreId());
|
|
|
|
+ busReportStore.setDescription(cusReportForm.getDescription());
|
|
|
|
+ busReportStoreMapper.updateById(busReportStore);
|
|
|
|
+
|
|
|
|
+ cusReportFormMapper.updateById(cusReportForm);
|
|
|
|
+
|
|
|
|
+ List<ReportFormAccess> toAddList = new ArrayList<>();
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ reportFormAccessMapper.delete(new LambdaQueryWrapper<ReportFormAccess>()
|
|
|
|
+ .eq(ReportFormAccess::getRelateFormId, cusReportForm.getId())
|
|
|
|
+ );
|
|
|
|
+ reportFormAccessMapper.batchInsert(toAddList);
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ msg.setError("未找到对应报表");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return msg;
|
|
return msg;
|
|
@@ -269,7 +352,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
BusReportStore busReportStore = busReportStoreMapper.selectById(storeId);
|
|
BusReportStore busReportStore = busReportStoreMapper.selectById(storeId);
|
|
- if(busReportStore.getCreateBy() != user.getId()){
|
|
|
|
|
|
+ if(!busReportStore.getCreateBy().equals(user.getId())){
|
|
msg.setError("非创建人无法删除");
|
|
msg.setError("非创建人无法删除");
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
@@ -288,7 +371,7 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
CusReportForm cusReportForm = cusReportFormMapper.selectById(formId);
|
|
CusReportForm cusReportForm = cusReportFormMapper.selectById(formId);
|
|
- if(cusReportForm.getCreateBy() != user.getId()){
|
|
|
|
|
|
+ if(!cusReportForm.getCreateBy().equals(user.getId())){
|
|
msg.setError("非创建人不能删除");
|
|
msg.setError("非创建人不能删除");
|
|
}
|
|
}
|
|
cusReportFormMapper.deleteById(formId);
|
|
cusReportFormMapper.deleteById(formId);
|
|
@@ -298,4 +381,121 @@ public class CusTableColumnServiceImpl extends ServiceImpl<CusTableColumnMapper,
|
|
);
|
|
);
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getFormResByFormId(Integer formId, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ List<Map<String,Object>> columnList = new ArrayList<>();
|
|
|
|
+ CusReportForm cusReportForm = cusReportFormMapper.selectById(formId);
|
|
|
|
+ if(null == cusReportForm){
|
|
|
|
+ msg.setError("未找到该报表,请联系管理员");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ String tableColumnSql = cusReportForm.getExecuteSql();
|
|
|
|
+ try (Connection connection = dataSource.getConnection()) {
|
|
|
|
+ PreparedStatement preparedStatement = connection.prepareStatement(tableColumnSql);
|
|
|
|
+ ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
+ columnList = this.convertList(resultSet);
|
|
|
|
+ }catch (SQLException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("SQL语句有误,请联系管理员");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ msg.setData(columnList);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**移动报表到文件夹*/
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg moveFormStore(Integer formId,Integer targetStoreId, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
|
+ BusReportStore busReportStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(BusReportStore::getRelateFormId, formId)
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ BusReportStore lastOneStore = busReportStoreMapper.selectOne(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
|
+ .eq(BusReportStore::getParentStoreId, busReportStore.getParentStoreId())
|
|
|
|
+ .orderByDesc(BusReportStore::getOrderItem)
|
|
|
|
+ .last(" limit 1 ")
|
|
|
|
+ );
|
|
|
|
+ if(null == lastOneStore){
|
|
|
|
+ busReportStore.setParentStoreId(targetStoreId);
|
|
|
|
+ busReportStore.setOrderItem(1);
|
|
|
|
+ busReportStore.setUpdateBy(user.getId());
|
|
|
|
+ busReportStore.setUpdateTime(new Date());
|
|
|
|
+ }else{
|
|
|
|
+ busReportStore.setParentStoreId(targetStoreId);
|
|
|
|
+ busReportStore.setOrderItem(lastOneStore.getOrderItem()+1);
|
|
|
|
+ busReportStore.setUpdateBy(user.getId());
|
|
|
|
+ busReportStore.setUpdateTime(new Date());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ busReportStoreMapper.updateById(busReportStore);
|
|
|
|
+
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getAllStoresTree(HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
|
+ List<BusReportStore> busReportStores = busReportStoreMapper.selectList(new LambdaQueryWrapper<BusReportStore>()
|
|
|
|
+ .eq(BusReportStore::getCompanyId, user.getCompanyId())
|
|
|
|
+ );
|
|
|
|
+ List<BusReportStore> listTree = this.listToTree(busReportStores);
|
|
|
|
+ msg.setData(listTree);
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<BusReportStore> listToTree(List<BusReportStore> treeNodeList){
|
|
|
|
+ if(null == treeNodeList){
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ List<BusReportStore> resList = new ArrayList<>();
|
|
|
|
+ Stack<BusReportStore> stack = new Stack<>();
|
|
|
|
+ resList = treeNodeList.stream().filter(ele -> 0 == ele.getParentStoreId()).collect(Collectors.toList());
|
|
|
|
+ stack.addAll(resList);
|
|
|
|
+
|
|
|
|
+ while(!stack.isEmpty()) {
|
|
|
|
+ BusReportStore store = stack.pop();
|
|
|
|
+ List<BusReportStore> child = treeNodeList.stream()
|
|
|
|
+ .filter(ele -> store.getId().equals(ele.getParentStoreId())).collect(Collectors.toList());
|
|
|
|
+ if(!child.isEmpty()) {
|
|
|
|
+ store.setChildStoreList(child);
|
|
|
|
+ }
|
|
|
|
+ if(!child.isEmpty()) {
|
|
|
|
+ stack.addAll(child);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return resList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static List<Map<String, Object>> convertList(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.getColumnName(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;
|
|
|
|
+ }
|
|
}
|
|
}
|