初始代码
This commit is contained in:
21
yunzhupaas-datareport-univer-biz/pom.xml
Normal file
21
yunzhupaas-datareport-univer-biz/pom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-datareport-univer</artifactId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>yunzhupaas-datareport-univer-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-datareport-univer-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.yunzhupaas.entity.DictionaryDataEntity;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
public interface DictionaryDataMapper extends SuperMapper<DictionaryDataEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.yunzhupaas.entity.ReportEntity;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface ReportMapper extends SuperMapper<ReportEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.yunzhupaas.entity.ReportVersionEntity;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface ReportVersionMapper extends SuperMapper<ReportVersionEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yunzhupaas.mapper;
|
||||
|
||||
import com.yunzhupaas.base.mapper.SuperMapper;
|
||||
import com.yunzhupaas.entity.UserEntity;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface UserMapper extends SuperMapper<UserEntity> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.entity.DictionaryDataEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
public interface DictionaryDataService extends SuperService<DictionaryDataEntity> {
|
||||
|
||||
List<DictionaryDataEntity> getDictionName(List<String> id);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.entity.ReportEntity;
|
||||
import com.yunzhupaas.model.report.ReportCrForm;
|
||||
import com.yunzhupaas.model.report.ReportInfoVO;
|
||||
import com.yunzhupaas.model.report.ReportPagination;
|
||||
import com.yunzhupaas.model.report.ReportUpForm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface ReportService extends SuperService<ReportEntity> {
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return 实体类
|
||||
*/
|
||||
List<ReportEntity> getList(ReportPagination pagination);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
*/
|
||||
void create(ReportCrForm form);
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*/
|
||||
void update(String id, ReportEntity entity);
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
*
|
||||
* @return ReportInfoVO
|
||||
*/
|
||||
ReportInfoVO getVersionInfo(String versionId);
|
||||
|
||||
/**
|
||||
* 保存或者发布 通过type:0-保存,1-发布
|
||||
*
|
||||
* @param form
|
||||
*/
|
||||
void saveOrRelease(ReportUpForm form);
|
||||
|
||||
/**
|
||||
* 下拉选择
|
||||
*
|
||||
*/
|
||||
List<ReportEntity> getTreeList();
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void delete(String id);
|
||||
|
||||
/**
|
||||
* 导入模板
|
||||
*
|
||||
* @param infoVO
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
String importData(ReportInfoVO infoVO, Integer type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.entity.ReportVersionEntity;
|
||||
import com.yunzhupaas.model.report.ReportCrForm;
|
||||
import com.yunzhupaas.model.report.ReportPagination;
|
||||
import com.yunzhupaas.model.report.UploaderVO;
|
||||
import com.yunzhupaas.univer.model.UniverPreview;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface ReportVersionService extends SuperService<ReportVersionEntity> {
|
||||
|
||||
/**
|
||||
* 创建版本
|
||||
*
|
||||
* @param form
|
||||
*/
|
||||
void create(ReportCrForm form);
|
||||
|
||||
/**
|
||||
* 获取版本列表
|
||||
*
|
||||
* @param templateId
|
||||
* @return
|
||||
*/
|
||||
List<ReportVersionEntity> getList(String templateId, SFunction<ReportVersionEntity, ?>... columns);
|
||||
|
||||
/**
|
||||
* 复制版本(点击新增版本)
|
||||
*
|
||||
* @param versionId
|
||||
*/
|
||||
String copyVersion(String versionId);
|
||||
|
||||
/**
|
||||
* 根据id删除版本
|
||||
*
|
||||
* @param templateId
|
||||
* @return
|
||||
*/
|
||||
void removeByTemplateId(String templateId);
|
||||
|
||||
/**
|
||||
* 预览数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
UniverPreview preview(String id, ReportPagination pagination, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 预览数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
UniverPreview previewTemplate(String id, ReportPagination pagination, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 导入excel
|
||||
*
|
||||
* @param multipartFile
|
||||
*/
|
||||
UniverPreview importExcel(MultipartFile multipartFile) throws IOException;
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
*/
|
||||
UploaderVO downExcel(ReportPagination pagination, Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param pagination
|
||||
*/
|
||||
UploaderVO downExcel(ReportPagination pagination);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.yunzhupaas.service;
|
||||
|
||||
import com.yunzhupaas.base.service.SuperService;
|
||||
import com.yunzhupaas.entity.UserEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
public interface UserService extends SuperService<UserEntity> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idList
|
||||
* @return
|
||||
*/
|
||||
List<UserEntity> getUserName(List<String> idList);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yunzhupaas.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.mapper.DictionaryDataMapper;
|
||||
import com.yunzhupaas.service.DictionaryDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Service
|
||||
public class DictionaryDataServiceImpl extends SuperServiceImpl<DictionaryDataMapper, DictionaryDataEntity>
|
||||
implements DictionaryDataService {
|
||||
|
||||
@Override
|
||||
public List<DictionaryDataEntity> getDictionName(List<String> id) {
|
||||
List<DictionaryDataEntity> dictionList = new ArrayList<>();
|
||||
if (id.size() > 0) {
|
||||
QueryWrapper<DictionaryDataEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().and(
|
||||
t -> t.in(DictionaryDataEntity::getId, id));
|
||||
dictionList = this.list(queryWrapper);
|
||||
}
|
||||
return dictionList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package com.yunzhupaas.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.Method;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.consts.ApiConst;
|
||||
import com.yunzhupaas.emnus.DataSetTypeEnum;
|
||||
import com.yunzhupaas.entity.ReportEntity;
|
||||
import com.yunzhupaas.entity.ReportVersionEntity;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.mapper.ReportMapper;
|
||||
import com.yunzhupaas.model.data.DataForm;
|
||||
import com.yunzhupaas.model.data.DataSetInfo;
|
||||
import com.yunzhupaas.model.data.DataSetPagination;
|
||||
import com.yunzhupaas.model.report.ReportCrForm;
|
||||
import com.yunzhupaas.model.report.ReportInfoVO;
|
||||
import com.yunzhupaas.model.report.ReportPagination;
|
||||
import com.yunzhupaas.model.report.ReportUpForm;
|
||||
import com.yunzhupaas.service.ReportService;
|
||||
import com.yunzhupaas.service.ReportVersionService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
@Service
|
||||
public class ReportServiceImpl extends SuperServiceImpl<ReportMapper, ReportEntity> implements ReportService {
|
||||
|
||||
@Autowired
|
||||
private ReportVersionService versionService;
|
||||
|
||||
@Override
|
||||
public List<ReportEntity> getList(ReportPagination pagination) {
|
||||
QueryWrapper<ReportEntity> queryWrapper = new QueryWrapper<>();
|
||||
String keyword = pagination.getKeyword();
|
||||
if (ObjectUtil.isNotEmpty(keyword)) {
|
||||
queryWrapper.lambda()
|
||||
.and(t -> t.like(ReportEntity::getEnCode, keyword).or().like(ReportEntity::getFullName, keyword));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(pagination.getCategory())) {
|
||||
queryWrapper.lambda().eq(ReportEntity::getCategory, pagination.getCategory());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(pagination.getState())) {
|
||||
queryWrapper.lambda().eq(ReportEntity::getEnabledMark, pagination.getState());
|
||||
}
|
||||
queryWrapper.lambda().orderByAsc(ReportEntity::getSortCode).orderByDesc(ReportEntity::getCreatorTime);
|
||||
Page<ReportEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
|
||||
IPage<ReportEntity> userPage = this.page(page, queryWrapper);
|
||||
return pagination.setData(userPage.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create(ReportCrForm form) {
|
||||
ReportEntity entity = JsonUtil.getJsonToBean(form, ReportEntity.class);
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
this.creUpdateCheck(entity, true, true);
|
||||
String id = StringUtil.isNotEmpty(entity.getId()) ? entity.getId() : RandomUtil.uuId();
|
||||
entity.setId(id);
|
||||
entity.setEnabledMark(0);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setLastModifyUserId(null);
|
||||
entity.setLastModifyTime(null);
|
||||
this.setIgnoreLogicDelete().removeById(entity.getId());
|
||||
this.setIgnoreLogicDelete().saveOrUpdate(entity);
|
||||
this.clearIgnoreLogicDelete();
|
||||
form.setId(id);
|
||||
List<ReportVersionEntity> list = versionService.getList(id, ReportVersionEntity::getId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
versionService.create(form);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(String id, ReportEntity entity) {
|
||||
ReportEntity report = getById(id);
|
||||
this.creUpdateCheck(entity, !report.getFullName().equals(entity.getFullName()),
|
||||
!report.getEnCode().equals(entity.getEnCode()));
|
||||
entity.setId(id);
|
||||
updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportInfoVO getVersionInfo(String versionId) {
|
||||
ReportVersionEntity versionEntity = versionService.getById(versionId);
|
||||
ReportEntity entity = this.getById(versionEntity.getTemplateId());
|
||||
ReportInfoVO vo = JsonUtil.getJsonToBean(versionEntity, ReportInfoVO.class);
|
||||
vo.setVersionId(versionId);
|
||||
vo.setId(entity.getId());
|
||||
vo.setFullName(entity.getFullName());
|
||||
vo.setAllowExport(entity.getAllowExport());
|
||||
vo.setAllowPrint(entity.getAllowPrint());
|
||||
vo.setCategory(entity.getCategory());
|
||||
vo.setEnCode(entity.getEnCode());
|
||||
vo.setSortCode(entity.getSortCode());
|
||||
DataSetPagination pagination = new DataSetPagination();
|
||||
pagination.setObjectId(versionId);
|
||||
pagination.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
String json = ReportUtil.http(ApiConst.DATASET_LIST, Method.GET, JsonUtil.entityToMap(pagination));
|
||||
ActionResult result = JsonUtil.getJsonToBean(json, ActionResult.class);
|
||||
List<DataSetInfo> dataSetList = new ArrayList<>();
|
||||
if (ObjectUtil.isNotEmpty(result.getData())) {
|
||||
dataSetList = JsonUtil.getJsonToList(result.getData(), DataSetInfo.class);
|
||||
}
|
||||
vo.setDataSetList(dataSetList);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrRelease(ReportUpForm form) {
|
||||
ReportVersionEntity versionEntity = versionService.getById(form.getVersionId());
|
||||
ReportVersionEntity versionNew = JsonUtil.getJsonToBean(form, ReportVersionEntity.class);
|
||||
versionNew.setId(versionEntity.getId());
|
||||
versionNew.setState(versionEntity.getState());
|
||||
ReportEntity entity = this.getById(form.getId());
|
||||
// 发布流程
|
||||
if (Objects.equals(form.getType(), 1)) {
|
||||
// 改流程版本
|
||||
if (StringUtil.isNotEmpty(form.getVersionId())) {
|
||||
boolean isRelease = Objects.equals(versionNew.getState(), 2);
|
||||
ReportVersionEntity info = versionService
|
||||
.getList(form.getId(), ReportVersionEntity::getId, ReportVersionEntity::getState).stream()
|
||||
.filter(t -> Objects.equals(t.getState(), 1)).findFirst().orElse(null);
|
||||
if (info != null) {
|
||||
// 变更归档状态,排序码
|
||||
info.setSortCode(0L);
|
||||
info.setState(2);
|
||||
versionService.updateById(info);
|
||||
}
|
||||
versionNew.setState(1);
|
||||
versionNew.setSortCode(1L);
|
||||
entity.setEnabledMark(1);
|
||||
if (isRelease) {
|
||||
versionService.updateById(versionNew);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
versionService.updateById(versionNew);
|
||||
// 数据集创建
|
||||
String versionId = versionNew.getId();
|
||||
List<DataSetInfo> dataSetList = form.getDataSetList() != null ? form.getDataSetList() : new ArrayList<>();
|
||||
DataForm dataForm = new DataForm();
|
||||
dataForm.setObjectId(versionId);
|
||||
dataForm.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
dataForm.setList(dataSetList);
|
||||
ReportUtil.http(ApiConst.DATASET_SAVE, Method.POST, JsonUtil.entityToMap(dataForm));
|
||||
entity.setAllowExport(form.getAllowExport());
|
||||
entity.setAllowPrint(form.getAllowPrint());
|
||||
entity.setLastModifyTime(new Date());
|
||||
entity.setLastModifyUserId(UserProvider.getLoginUserId());
|
||||
this.updateById(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportEntity> getTreeList() {
|
||||
QueryWrapper<ReportEntity> query = new QueryWrapper<>();
|
||||
query.lambda().eq(ReportEntity::getEnabledMark, 1);
|
||||
query.lambda().orderByAsc(ReportEntity::getSortCode).orderByDesc(ReportEntity::getCreatorTime);
|
||||
List<ReportEntity> list = this.list(query);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
removeById(id);
|
||||
versionService.removeByTemplateId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String importData(ReportInfoVO infoVO, Integer type) {
|
||||
ReportEntity entity = JsonUtil.getJsonToBean(infoVO, ReportEntity.class);
|
||||
StringJoiner stringJoiner = new StringJoiner("、");
|
||||
// id为空切名称不存在时
|
||||
QueryWrapper<ReportEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(ReportEntity::getId, entity.getId());
|
||||
if (this.getById(infoVO.getId()) != null) {
|
||||
if (Objects.equals(type, 0)) {
|
||||
stringJoiner.add("ID");
|
||||
} else {
|
||||
entity.setId(RandomUtil.uuId());
|
||||
}
|
||||
}
|
||||
queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(ReportEntity::getEnCode, entity.getEnCode());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
stringJoiner.add(MsgCode.IMP009.get());
|
||||
}
|
||||
queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(ReportEntity::getFullName, entity.getFullName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
stringJoiner.add(MsgCode.IMP008.get());
|
||||
}
|
||||
if (stringJoiner.length() > 0 && ObjectUtil.equal(type, 1)) {
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
entity.setEnCode(entity.getEnCode() + copyNum);
|
||||
} else if (ObjectUtil.equal(type, 0) && stringJoiner.length() > 0) {
|
||||
return stringJoiner + MsgCode.IMP007.get();
|
||||
}
|
||||
entity.setEnabledMark(0);
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
this.setIgnoreLogicDelete().removeById(entity);
|
||||
this.setIgnoreLogicDelete().saveOrUpdate(entity);
|
||||
this.clearIgnoreLogicDelete();
|
||||
// 版本添加
|
||||
ReportVersionEntity versionEntity = JsonUtil.getJsonToBean(infoVO, ReportVersionEntity.class);
|
||||
String versionId = RandomUtil.uuId();
|
||||
versionEntity.setId(versionId);
|
||||
versionEntity.setTemplateId(entity.getId());
|
||||
versionEntity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
versionEntity.setCreatorTime(new Date());
|
||||
versionEntity.setVersion(1);
|
||||
versionEntity.setState(0);
|
||||
versionEntity.setSortCode(0l);
|
||||
versionService.save(versionEntity);
|
||||
// 数据集创建
|
||||
List<DataSetInfo> dataSetList = infoVO.getDataSetList() != null ? infoVO.getDataSetList() : new ArrayList<>();
|
||||
if (dataSetList.size() > 0) {
|
||||
DataForm dataForm = new DataForm();
|
||||
dataForm.setObjectId(versionId);
|
||||
dataForm.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
dataForm.setList(dataSetList);
|
||||
ReportUtil.http(ApiConst.DATASET_SAVE, Method.POST, JsonUtil.entityToMap(dataForm));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void creUpdateCheck(ReportEntity entity, Boolean fullNameCheck, Boolean encodeCheck) {
|
||||
String fullName = entity.getFullName();
|
||||
String encode = entity.getEnCode();
|
||||
// 名称长度验证
|
||||
if (fullName.length() > 80) {
|
||||
throw new DataException(MsgCode.EXIST005.get());
|
||||
}
|
||||
QueryWrapper<ReportEntity> query = new QueryWrapper<>();
|
||||
// 重名验证
|
||||
if (fullNameCheck) {
|
||||
query.lambda().eq(ReportEntity::getFullName, fullName);
|
||||
if (this.list(query).size() > 0) {
|
||||
throw new DataException(MsgCode.EXIST003.get());
|
||||
}
|
||||
}
|
||||
// 编码验证
|
||||
if (encodeCheck) {
|
||||
query.clear();
|
||||
query.lambda().eq(ReportEntity::getEnCode, encode);
|
||||
if (this.list(query).size() > 0) {
|
||||
throw new DataException(MsgCode.EXIST002.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package com.yunzhupaas.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.Method;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.xuyanwu.spring.file.storage.FileInfo;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.consts.ApiConst;
|
||||
import com.yunzhupaas.emnus.DataSetTypeEnum;
|
||||
import com.yunzhupaas.entity.ReportEntity;
|
||||
import com.yunzhupaas.entity.ReportVersionEntity;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.mapper.ReportVersionMapper;
|
||||
import com.yunzhupaas.model.DataQuery;
|
||||
import com.yunzhupaas.model.data.*;
|
||||
import com.yunzhupaas.model.report.ReportCrForm;
|
||||
import com.yunzhupaas.model.report.ReportPagination;
|
||||
import com.yunzhupaas.model.report.UploaderVO;
|
||||
import com.yunzhupaas.service.ReportService;
|
||||
import com.yunzhupaas.service.ReportVersionService;
|
||||
import com.yunzhupaas.univer.chart.UniverChartModel;
|
||||
import com.yunzhupaas.univer.data.custom.UniverCustom;
|
||||
import com.yunzhupaas.univer.model.UniverPreview;
|
||||
import com.yunzhupaas.univer.model.UniverWorkBook;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.Cleanup;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
@Service
|
||||
public class ReportVersionServiceImpl extends SuperServiceImpl<ReportVersionMapper, ReportVersionEntity>
|
||||
implements ReportVersionService {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ReportService reportService;
|
||||
|
||||
@Override
|
||||
@DSTransactional
|
||||
public void create(ReportCrForm form) {
|
||||
String versionId = RandomUtil.uuId();
|
||||
ReportVersionEntity entity = JsonUtil.getJsonToBean(form, ReportVersionEntity.class);
|
||||
entity.setId(versionId);
|
||||
entity.setTemplateId(form.getId());
|
||||
entity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
entity.setCreatorTime(new Date());
|
||||
List<ReportVersionEntity> verList = getList(entity.getId(), ReportVersionEntity::getVersion);
|
||||
int version = verList.stream().map(ReportVersionEntity::getVersion).max(Comparator.naturalOrder()).orElse(0)
|
||||
+ 1;
|
||||
entity.setVersion(version);
|
||||
entity.setState(0);
|
||||
entity.setSortCode(0l);
|
||||
this.setIgnoreLogicDelete().removeById(entity.getId());
|
||||
this.setIgnoreLogicDelete().saveOrUpdate(entity);
|
||||
this.clearIgnoreLogicDelete();
|
||||
List<DataSetInfo> dataSetList = form.getDataSetList() != null ? form.getDataSetList() : new ArrayList<>();
|
||||
if (dataSetList.size() > 0) {
|
||||
// 数据集创建
|
||||
DataForm dataForm = new DataForm();
|
||||
dataForm.setObjectId(versionId);
|
||||
dataForm.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
dataForm.setList(dataSetList);
|
||||
ReportUtil.http(ApiConst.DATASET_SAVE, Method.POST, JsonUtil.entityToMap(dataForm));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReportVersionEntity> getList(String templateId, SFunction<ReportVersionEntity, ?>... columns) {
|
||||
QueryWrapper<ReportVersionEntity> queryWrapper = new QueryWrapper<>();
|
||||
if (columns != null && columns.length > 0) {
|
||||
queryWrapper.lambda().select(columns);
|
||||
}
|
||||
queryWrapper.lambda().eq(ReportVersionEntity::getTemplateId, templateId);
|
||||
queryWrapper.lambda().orderByDesc(ReportVersionEntity::getSortCode).orderByAsc(ReportVersionEntity::getState);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String copyVersion(String versionId) {
|
||||
ReportVersionEntity entity = this.getById(versionId);
|
||||
ReportVersionEntity versionEntity = JsonUtil.getJsonToBean(entity, ReportVersionEntity.class);
|
||||
String newVersionId = RandomUtil.uuId();
|
||||
versionEntity.setId(newVersionId);
|
||||
List<ReportVersionEntity> verList = getList(entity.getTemplateId(), ReportVersionEntity::getVersion);
|
||||
int version = verList.stream().map(ReportVersionEntity::getVersion).max(Comparator.naturalOrder()).orElse(0)
|
||||
+ 1;
|
||||
versionEntity.setVersion(version);
|
||||
versionEntity.setState(0);
|
||||
versionEntity.setSortCode(0l);
|
||||
versionEntity.setCreatorTime(new Date());
|
||||
versionEntity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
versionEntity.setLastModifyTime(null);
|
||||
versionEntity.setLastModifyUserId(null);
|
||||
DataSetPagination pagination = new DataSetPagination();
|
||||
pagination.setObjectId(versionId);
|
||||
pagination.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
String json = ReportUtil.http(ApiConst.DATASET_LIST, Method.GET, JsonUtil.entityToMap(pagination));
|
||||
ActionResult result = JsonUtil.getJsonToBean(json, ActionResult.class);
|
||||
List<DataSetInfo> dataSetList = new ArrayList<>();
|
||||
if (ObjectUtil.isNotEmpty(result.getData())) {
|
||||
dataSetList.addAll(JsonUtil.getJsonToList(result.getData(), DataSetInfo.class));
|
||||
}
|
||||
if (dataSetList.size() > 0) {
|
||||
for (DataSetInfo item : dataSetList) {
|
||||
item.setId(null);
|
||||
item.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
item.setObjectId(newVersionId);
|
||||
}
|
||||
DataForm dataForm = new DataForm();
|
||||
dataForm.setObjectId(newVersionId);
|
||||
dataForm.setObjectType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
dataForm.setList(dataSetList);
|
||||
ReportUtil.http(ApiConst.DATASET_SAVE, Method.POST, JsonUtil.entityToMap(dataForm));
|
||||
}
|
||||
this.save(versionEntity);
|
||||
return newVersionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByTemplateId(String templateId) {
|
||||
QueryWrapper<ReportVersionEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(ReportVersionEntity::getTemplateId, templateId);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniverPreview preview(String id, ReportPagination pagination, Map<String, Object> params) {
|
||||
ReportVersionEntity entity = getById(id);
|
||||
if (ObjectUtil.isEmpty(entity)) {
|
||||
throw new DataException(MsgCode.FA015.get());
|
||||
}
|
||||
if (ObjectUtil.isEmpty(entity.getSnapshot())) {
|
||||
throw new DataException(MsgCode.FA105.get());
|
||||
}
|
||||
Object univerData = redisUtil.getString(id);
|
||||
if (ObjectUtil.isNotEmpty(univerData)) {
|
||||
return JsonUtil.getJsonToBean(String.valueOf(univerData), UniverPreview.class);
|
||||
}
|
||||
// 获取当前
|
||||
UniverWorkBook univerWorkBook = JsonUtil.getJsonToBean(entity.getSnapshot(), UniverWorkBook.class);
|
||||
List<String> sheetOrder = univerWorkBook.getSheetOrder();
|
||||
ReportEntity report = reportService.getById(entity.getTemplateId());
|
||||
Map<String, Map<String, List<Map<String, Object>>>> sheetData = new HashMap<>();
|
||||
Map<String, Map<String, Map<String, Object>>> parameterData = new HashMap<>();
|
||||
// 当前数据
|
||||
String sheet = StringUtil.isNotEmpty(pagination.getSheetId()) ? pagination.getSheetId()
|
||||
: !sheetOrder.isEmpty() ? sheetOrder.get(0) : null;
|
||||
for (String sheetId : sheetOrder) {
|
||||
DataSetQuery query = new DataSetQuery();
|
||||
query.setModuleId(entity.getTemplateId());
|
||||
query.setId(id);
|
||||
Map<String, Object> dataMap = new HashMap<>(params);
|
||||
Object object = params.get(sheetId);
|
||||
if (object instanceof Map) {
|
||||
Map<String, Object> data = (Map<String, Object>) object;
|
||||
dataMap.putAll(data);
|
||||
}
|
||||
query.setMap(dataMap);
|
||||
query.setType(DataSetTypeEnum.REPORT_VER.getCode());
|
||||
query.setSnowFlakeId(RandomUtil.uuId());
|
||||
query.setConvertConfig(entity.getConvertConfig());
|
||||
List<DataQuery> dataQueryList = StringUtil.isNotEmpty(entity.getQueryList())
|
||||
? JsonUtil.getJsonToList(entity.getQueryList(), DataQuery.class)
|
||||
: new ArrayList<>();
|
||||
Map<String, List<DataQuery>> queryMap = dataQueryList.stream()
|
||||
.collect(Collectors.groupingBy(DataQuery::getSheet));
|
||||
List<DataQuery> queryListAll = queryMap.get(sheetId) != null ? queryMap.get(sheetId) : new ArrayList<>();
|
||||
List<Object> queryList = new ArrayList<>();
|
||||
if (Objects.equals(sheetId, sheet)) {
|
||||
for (DataQuery dataQuery : queryListAll) {
|
||||
queryList.addAll(dataQuery.getQueryList());
|
||||
}
|
||||
}
|
||||
query.setQueryList(JSONUtil.toJsonStr(queryList));
|
||||
String sheetJson = ReportUtil.http(ApiConst.DATASET_DATA, Method.POST, JsonUtil.entityToMap(query));
|
||||
if (StringUtil.isNotEmpty(sheetJson)) {
|
||||
Map<String, List<Map<String, Object>>> dataList = new HashMap<>();
|
||||
try {
|
||||
ActionResult result = JsonUtil.getJsonToBean(sheetJson, ActionResult.class);
|
||||
if (ObjectUtil.isNotEmpty(result) && result.getData() instanceof Map) {
|
||||
Map<String, List<Map<String, Object>>> data = JsonUtil.getJsonToBean(result.getData(),
|
||||
Map.class);
|
||||
dataList.putAll(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
sheetData.put(sheetId, dataList);
|
||||
}
|
||||
|
||||
// 参数数据
|
||||
String parameterJson = ReportUtil.http(ApiConst.PARAMETER_DATA, Method.POST, JsonUtil.entityToMap(query));
|
||||
if (StringUtil.isNotEmpty(parameterJson)) {
|
||||
Map<String, Map<String, Object>> dataList = new HashMap<>();
|
||||
try {
|
||||
ActionResult result = JsonUtil.getJsonToBean(parameterJson, ActionResult.class);
|
||||
if (ObjectUtil.isNotEmpty(result) && result.getData() instanceof Map) {
|
||||
Map<String, Map<String, Object>> data = JsonUtil.getJsonToBean(result.getData(), Map.class);
|
||||
dataList.putAll(data);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
parameterData.put(sheetId, dataList);
|
||||
}
|
||||
}
|
||||
|
||||
UniverConvert convert = new UniverConvert();
|
||||
UniverPreview vo = convert.transform(entity.getSnapshot(), entity.getCells(), entity.getSortList(), sheetData,
|
||||
parameterData);
|
||||
vo.setVersionId(id);
|
||||
vo.setQueryList(entity.getQueryList());
|
||||
vo.setFullName(report.getFullName());
|
||||
vo.setAllowExport(report.getAllowExport());
|
||||
vo.setAllowPrint(report.getAllowPrint());
|
||||
redisUtil.insert(id, JSON.toJSONString(vo), 5);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniverPreview previewTemplate(String id, ReportPagination pagination, Map<String, Object> params) {
|
||||
ReportVersionEntity entity = getList(id, ReportVersionEntity::getId, ReportVersionEntity::getState).stream()
|
||||
.filter(t -> Objects.equals(t.getState(), 1)).findFirst().orElse(null);
|
||||
if (ObjectUtil.isEmpty(entity)) {
|
||||
throw new DataException(MsgCode.FA015.get());
|
||||
}
|
||||
return preview(entity.getId(), pagination, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniverPreview importExcel(MultipartFile multipartFile) throws IOException {
|
||||
UniverCustom cellData = new UniverCustom();
|
||||
UniverWorkBook univerWorkBook = UniverExcel.formFile(multipartFile);
|
||||
UniverPreview vo = new UniverPreview();
|
||||
vo.setSnapshot(JSONUtil.toJsonStr(univerWorkBook));
|
||||
vo.setCells(JSONUtil.toJsonStr(cellData));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploaderVO downExcel(ReportPagination pagination, Map<String, Object> params) {
|
||||
String id = pagination.getId();
|
||||
UploaderVO vo = new UploaderVO();
|
||||
ReportVersionEntity versionEntity = getById(id);
|
||||
if (ObjectUtil.isEmpty(versionEntity)) {
|
||||
return vo;
|
||||
}
|
||||
ReportEntity entity = reportService.getById(versionEntity.getTemplateId());
|
||||
UniverPreview preview = preview(id, pagination, params);
|
||||
pagination.setSnapshot(preview.getSnapshot());
|
||||
pagination.setFullName(entity.getFullName());
|
||||
vo = downExcel(pagination);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploaderVO downExcel(ReportPagination pagination) {
|
||||
UploaderVO vo = new UploaderVO();
|
||||
if (StringUtil.isNotEmpty(pagination.getSnapshot())) {
|
||||
try {
|
||||
List<UniverChartModel> chartList = new ArrayList<>();
|
||||
@Cleanup
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
List<String> sheetList = ImmutableList.of(pagination.getSheetId());
|
||||
UniverExcel.downExcel(pagination.getSnapshot(), chartList, workbook, sheetList);
|
||||
String fileName = pagination.getFullName() + ".xlsx";
|
||||
@Cleanup
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
workbook.write(outputStream);
|
||||
String type = "Temporary";
|
||||
String url = "/api/Report/data/Download?name=" + fileName + "&encryption=";
|
||||
String temporaryFilePath = FilePathUtil.getFilePath(type);
|
||||
FileInfo fileInfo = FileUploadUtils.uploadFile(outputStream.toByteArray(), temporaryFilePath, fileName);
|
||||
vo.setName(fileInfo.getFilename());
|
||||
vo.setUrl(UploaderUtil.uploaderFile(url, fileInfo.getFilename() + "#" + type));
|
||||
} catch (Exception e) {
|
||||
log.error("报表导出excel异常:" + e.getMessage());
|
||||
throw new DataException(MsgCode.FA107.get());
|
||||
}
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yunzhupaas.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.yunzhupaas.base.service.SuperServiceImpl;
|
||||
import com.yunzhupaas.entity.UserEntity;
|
||||
import com.yunzhupaas.mapper.UserMapper;
|
||||
import com.yunzhupaas.service.UserService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/11 下午4:35
|
||||
*/
|
||||
@Service
|
||||
public class UserServiceImpl extends SuperServiceImpl<UserMapper, UserEntity> implements UserService {
|
||||
|
||||
@Override
|
||||
public List<UserEntity> getUserName(List<String> idList) {
|
||||
List<UserEntity> list = new ArrayList<>();
|
||||
if (idList.size() > 0) {
|
||||
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().in(UserEntity::getId, idList);
|
||||
list = this.list(queryWrapper);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user