初始代码

This commit is contained in:
wangmingwei
2026-04-21 17:23:02 +08:00
parent c46013ba09
commit 1f23450530
56 changed files with 4237 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<?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-controller</artifactId>
<dependencies>
<dependency>
<groupId>com.yunzhupaas</groupId>
<artifactId>yunzhupaas-datareport-univer-biz</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,393 @@
package com.yunzhupaas.controller;
import cn.hutool.http.Method;
import cn.xuyanwu.spring.file.storage.FileInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.base.vo.DownloadVO;
import com.yunzhupaas.base.vo.ListVO;
import com.yunzhupaas.base.vo.PageListVO;
import com.yunzhupaas.base.vo.PaginationVO;
import com.yunzhupaas.constant.GlobalConst;
import com.yunzhupaas.constant.MsgCode;
import com.yunzhupaas.consts.ApiConst;
import com.yunzhupaas.emnus.ModuleTypeEnum;
import com.yunzhupaas.entity.DictionaryDataEntity;
import com.yunzhupaas.entity.ReportEntity;
import com.yunzhupaas.entity.ReportVersionEntity;
import com.yunzhupaas.entity.UserEntity;
import com.yunzhupaas.exception.DataException;
import com.yunzhupaas.model.data.DataSetInfo;
import com.yunzhupaas.model.data.MenuModel;
import com.yunzhupaas.model.data.ModuleNameVO;
import com.yunzhupaas.model.report.*;
import com.yunzhupaas.service.DictionaryDataService;
import com.yunzhupaas.service.ReportService;
import com.yunzhupaas.service.ReportVersionService;
import com.yunzhupaas.service.UserService;
import com.yunzhupaas.util.*;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author :云筑产品开发平台组
* @version: V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024/5/11 下午4:35
*/
@Tag(name = "报表信息", description = "Report")
@RestController
@RequestMapping("/api/Report")
public class ReportController {
@Autowired
private ReportService reportService;
@Autowired
private UserService userService;
@Autowired
private DictionaryDataService dictionaryDataService;
@Autowired
private ReportVersionService versionService;
@Operation(summary = "列表")
@GetMapping
public ActionResult<PageListVO<ReportListVO>> list(ReportPagination paginationPrint) {
List<ReportEntity> list = reportService.getList(paginationPrint);
List<String> userId = new ArrayList<>();
userId.addAll(list.stream().filter(t -> StringUtil.isNotEmpty(t.getCreatorUserId()))
.map(ReportEntity::getCreatorUserId).collect(Collectors.toList()));
userId.addAll(list.stream().filter(t -> StringUtil.isNotEmpty(t.getLastModifyUserId()))
.map(ReportEntity::getLastModifyUserId).collect(Collectors.toList()));
List<UserEntity> userList = userService.getUserName(userId);
List<String> dictionary = new ArrayList<>();
dictionary.addAll(list.stream().map(ReportEntity::getCategory).collect(Collectors.toList()));
List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(dictionary);
List<ReportListVO> listVOS = new ArrayList<>();
for (ReportEntity entity : list) {
ReportListVO vo = JsonUtil.getJsonToBean(entity, ReportListVO.class);
vo.setState(vo.getEnabledMark());
DictionaryDataEntity dataEntity = dictionList.stream().filter(t -> t.getId().equals(entity.getCategory()))
.findFirst().orElse(null);
vo.setCategory(dataEntity != null ? dataEntity.getFullName() : "");
// 创建者
UserEntity creatorUser = userList.stream().filter(t -> t.getId().equals(entity.getCreatorUserId()))
.findFirst().orElse(null);
vo.setCreatorUser(creatorUser != null ? creatorUser.getRealName() + "/" + creatorUser.getAccount()
: entity.getCreatorUserId());
// 修改人
UserEntity lastModifyUser = userList.stream().filter(t -> t.getId().equals(entity.getLastModifyUserId()))
.findFirst().orElse(null);
vo.setLastModifyUser(
lastModifyUser != null ? lastModifyUser.getRealName() + "/" + lastModifyUser.getAccount()
: entity.getLastModifyUserId());
listVOS.add(vo);
}
PaginationVO paginationVO = JsonUtil.getJsonToBean(paginationPrint, PaginationVO.class);
return ActionResult.page(listVOS, paginationVO);
}
@PostMapping
@Operation(summary = "新建")
@Parameters({
@Parameter(name = "form", description = "模型", required = true),
})
public ActionResult create(@RequestBody ReportCrForm form) {
form.setAllowExport(1);
form.setAllowPrint(1);
reportService.create(form);
return ActionResult.success(MsgCode.SU001.get(), form.getId());
}
@Operation(summary = "详情")
@Parameters({
@Parameter(name = "id", description = "模板id")
})
@GetMapping("/{id}")
public ActionResult<ReportInfoVO> info(@PathVariable("id") String id) {
ReportEntity byId = reportService.getById(id);
ReportInfoVO vo = JsonUtil.getJsonToBean(byId, ReportInfoVO.class);
return ActionResult.success(vo);
}
@Operation(summary = "更新")
@PutMapping("/{id}")
@Parameters({
@Parameter(name = "id", description = "主键", required = true),
@Parameter(name = "form", description = "模型", required = true),
})
public ActionResult update(@PathVariable("id") String id, @RequestBody ReportUpForm form) {
ReportEntity entity = JsonUtil.getJsonToBean(form, ReportEntity.class);
reportService.update(id, entity);
return ActionResult.success(MsgCode.SU004.get());
}
@Operation(summary = "删除")
@Parameters({
@Parameter(name = "id", description = "模板id", required = true)
})
@DeleteMapping("/{id}")
public ActionResult delete(@PathVariable String id) {
if (reportService.getById(id) != null) {
reportService.delete(id);
return ActionResult.success(MsgCode.SU003.get());
} else {
return ActionResult.fail(MsgCode.FA003.get());
}
}
/* ============版本增删改============== */
@Operation(summary = "版本详情")
@Parameters({
@Parameter(name = "versionId", description = "版本id", required = true)
})
@GetMapping("/Info/{versionId}")
public ActionResult<ReportInfoVO> versionInfo(@PathVariable String versionId) {
ReportInfoVO info = reportService.getVersionInfo(versionId);
return ActionResult.success(info);
}
@Operation(summary = "版本新增")
@Parameters({
@Parameter(name = "versionId", description = "版本id", required = true)
})
@PostMapping("/Info/{versionId}")
public ActionResult copyVersion(@PathVariable String versionId) {
String newVersionId = versionService.copyVersion(versionId);
return ActionResult.success(MsgCode.SU005.get(), newVersionId);
}
@Operation(summary = "版本删除")
@Parameters({
@Parameter(name = "versionId", description = "版本id", required = true)
})
@DeleteMapping("/Info/{versionId}")
public ActionResult deleteVersion(@PathVariable String versionId) {
ReportVersionEntity entity = versionService.getById(versionId);
if (entity != null) {
List<ReportVersionEntity> list = versionService.getList(entity.getTemplateId(), ReportVersionEntity::getId);
if (list.size() == 1) {
return ActionResult.fail(MsgCode.SYS043.get());
}
if (Objects.equals(entity.getState(), 1)) {
return ActionResult.fail(MsgCode.SYS044.get());
}
if (Objects.equals(entity.getState(), 2)) {
return ActionResult.fail(MsgCode.SYS045.get());
}
versionService.removeById(versionId);
}
return ActionResult.success(MsgCode.SU003.get());
}
@Operation(summary = "版本列表")
@Parameters({
@Parameter(name = "id", description = "模板id", required = true)
})
@GetMapping("/Version/{id}")
public ActionResult<List<ReportVersionListVO>> versionList(@PathVariable String id) {
List<ReportVersionEntity> list = versionService.getList(id, ReportVersionEntity::getId,
ReportVersionEntity::getState, ReportVersionEntity::getVersion);
List<ReportVersionListVO> listVO = new ArrayList<>();
for (ReportVersionEntity jsonEntity : list) {
ReportVersionListVO vo = JsonUtil.getJsonToBean(jsonEntity, ReportVersionListVO.class);
vo.setFullName("报表版本V" + vo.getVersion());
listVO.add(vo);
}
if (listVO.isEmpty()) {
return ActionResult.fail(MsgCode.PRI008.get());
}
return ActionResult.success(listVO);
}
@Operation(summary = "保存或者发布")
@PostMapping("/Save")
public ActionResult saveOrRelease(@RequestBody ReportUpForm form) {
reportService.saveOrRelease(form);
if (Objects.equals(form.getType(), 1)) {
return ActionResult.success(MsgCode.SU011.get());
}
return ActionResult.success(MsgCode.SU002.get());
}
@Operation(summary = "复制")
@Parameters({
@Parameter(name = "id", description = "模板id", required = true)
})
@PostMapping("/{id}/Actions/Copy")
public ActionResult copy(@PathVariable String id) {
ReportEntity entity = reportService.getById(id);
String copyNum = UUID.randomUUID().toString().substring(0, 5);
String fullName = entity.getFullName() + ".副本" + copyNum;
if (fullName.length() > 50) {
return ActionResult.fail(MsgCode.PRI006.get());
}
List<ReportVersionEntity> list = versionService.getList(id, ReportVersionEntity::getId);
ReportInfoVO info = new ReportInfoVO();
List<DataSetInfo> listVO = new ArrayList<>();
if (CollectionUtils.isNotEmpty(list)) {
info = reportService.getVersionInfo(list.get(0).getId());
List<DataSetInfo> dataSetList = info.getDataSetList() != null ? info.getDataSetList() : new ArrayList<>();
for (DataSetInfo dataSetInfo : dataSetList) {
dataSetInfo.setObjectId(null);
dataSetInfo.setId(null);
listVO.add(dataSetInfo);
}
}
ReportCrForm form = JsonUtil.getJsonToBean(info, ReportCrForm.class);
form.setFullName(fullName);
form.setEnCode(entity.getEnCode() + copyNum);
form.setCategory(entity.getCategory());
form.setSortCode(entity.getSortCode());
form.setDescription(entity.getDescription());
form.setId(null);
reportService.create(form);
return ActionResult.success(MsgCode.SU007.get());
}
@Operation(summary = "导出")
@Parameters({
@Parameter(name = "id", description = "模板id")
})
@GetMapping("/{id}/Actions/Export")
public ActionResult<DownloadVO> export(@PathVariable String id) {
DownloadVO vo = new DownloadVO();
ReportEntity entity = reportService.getById(id);
List<ReportVersionEntity> list = versionService.getList(id, ReportVersionEntity::getId);
if (CollectionUtils.isEmpty(list)) {
throw new DataException(MsgCode.FA001.get());
}
ReportInfoVO info = reportService.getVersionInfo(list.get(0).getId());
String json = JsonUtil.getObjectToString(info);
String tableName = ModuleTypeEnum.REPORT_TEMPLATE.getTableName();
String fileName = entity.getFullName() + "_" + DateUtil.dateFormatByPattern(new Date(), "yyyyMMddHHmmss") + "."
+ tableName;
try {
String type = "Temporary";
String url = "/api/Report/data/Download?name=" + fileName + "&encryption=";
String temporaryFilePath = FilePathUtil.getFilePath(type);
FileInfo fileInfo = FileUploadUtils.uploadFile(json.getBytes(GlobalConst.DEFAULT_CHARSET),
temporaryFilePath, fileName);
vo.setName(fileInfo.getFilename());
vo.setUrl(UploaderUtil.uploaderFile(url, fileInfo.getFilename() + "#" + type));
} catch (Exception e) {
}
return ActionResult.success(vo);
}
@Operation(summary = "导入")
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile,
@RequestParam("type") Integer type) throws DataException {
// 判断是否为.rp结尾
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.REPORT_TEMPLATE.getTableName())) {
return ActionResult.fail(MsgCode.IMP002.get());
}
// 读取文件内容
String fileContent = FileUtil.getFileContent(multipartFile);
ReportInfoVO infVo = JsonUtil.getJsonToBean(fileContent, ReportInfoVO.class);
String str = reportService.importData(infVo, type);
if (StringUtil.isNotEmpty(str)) {
return ActionResult.fail(str);
}
return ActionResult.success(MsgCode.IMP001.get());
}
@Operation(summary = "下拉列表")
@GetMapping("/Selector")
public ActionResult<ListVO<ReportSelectVO>> selectorList() {
List<ReportEntity> list = reportService.getTreeList();
List<String> dictionary = new ArrayList<>();
dictionary.addAll(list.stream().map(ReportEntity::getCategory).collect(Collectors.toList()));
List<DictionaryDataEntity> dictionList = dictionaryDataService.getDictionName(dictionary);
Map<String, List<ReportEntity>> map = list.stream().collect(Collectors.groupingBy(ReportEntity::getCategory));
List<ReportSelectVO> listVO = new ArrayList<>();
for (DictionaryDataEntity entity : dictionList) {
List<ReportEntity> entityList = map.get(entity.getId()) != null ? map.get(entity.getId())
: new ArrayList<>();
if (entityList.size() > 0) {
ReportSelectVO vo = new ReportSelectVO();
vo.setId(entity.getId());
vo.setFullName(entity.getFullName());
vo.setHasChildren(true);
vo.setChildren(JsonUtil.getJsonToList(entityList, ReportSelectVO.class));
listVO.add(vo);
}
}
ListVO vo = new ListVO<>();
vo.setList(listVO);
return ActionResult.success(vo);
}
@Operation(summary = "报表发布菜单")
@Parameters({
@Parameter(name = "id", description = "模板id", required = true)
})
@PostMapping("/{id}/Actions/Module")
public ActionResult module(@PathVariable String id, @RequestBody MenuModel model) {
ReportEntity entity = reportService.getById(id);
if (entity == null) {
return ActionResult.fail(MsgCode.FA012.get());
}
model.setId(id);
model.setFullName(entity.getFullName());
model.setEncode(entity.getEnCode());
model.setType(10);
model.setApp(0);
entity.setPlatformRelease(model.getPlatformRelease());
String json = ReportUtil.http(ApiConst.SAVE_MENU, Method.POST, JsonUtil.entityToMap(model));
ActionResult result = JsonUtil.getJsonToBean(json, ActionResult.class);
if (result == null) {
return ActionResult.fail(MsgCode.FA101.get());
}
if (!Objects.equals(result.getCode(), 200)) {
return ActionResult.fail(result.getMsg());
}
reportService.update(id, entity);
return ActionResult.success(MsgCode.SU011.get());
}
@Operation(summary = "获取报表发布菜单")
@Parameters({
@Parameter(name = "id", description = "模板id", required = true)
})
@GetMapping("/{id}/getReleaseMenu")
public ActionResult getReleaseMenu(@PathVariable String id) {
ReportEntity entity = reportService.getById(id);
if (entity == null) {
return ActionResult.fail(MsgCode.FA012.get());
}
MenuModel model = new MenuModel();
model.setId(id);
String json = ReportUtil.http(ApiConst.GET_MENU, Method.POST, JsonUtil.entityToMap(model));
ActionResult result = JsonUtil.getJsonToBean(json, ActionResult.class);
ModuleNameVO moduleNameVO = new ModuleNameVO();
if (Objects.equals(result.getCode(), 200)) {
moduleNameVO = JsonUtil.getJsonToBean(result.getData(), ModuleNameVO.class);
}
ReportInfoVO vo = JsonUtil.getJsonToBean(entity, ReportInfoVO.class);
vo.setAppIsRelease(0);
vo.setPcIsRelease(0);
if (moduleNameVO != null) {
if (StringUtil.isNotEmpty(moduleNameVO.getPcNames())) {
vo.setPcIsRelease(1);
vo.setPcReleaseName(moduleNameVO.getPcNames());
}
if (StringUtil.isNotEmpty(moduleNameVO.getAppNames())) {
vo.setAppIsRelease(1);
vo.setAppReleaseName(moduleNameVO.getAppNames());
}
}
return ActionResult.success(vo);
}
}

View File

@@ -0,0 +1,158 @@
package com.yunzhupaas.controller;
import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.Method;
import cn.xuyanwu.spring.file.storage.FileInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.yunzhupaas.base.ActionResult;
import com.yunzhupaas.enums.ImageEnum;
import com.yunzhupaas.model.report.ReportPagination;
import com.yunzhupaas.model.report.UploaderVO;
import com.yunzhupaas.service.ReportVersionService;
import com.yunzhupaas.univer.model.UniverPreview;
import com.yunzhupaas.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author :云筑产品开发平台组
* @version: V3.1.0
* @copyright 深圳市乐程软件有限公司
* @date 2024/5/11 下午4:35
*/
@Tag(name = "报表数据", description = "Report")
@RestController
@RequestMapping("/api/Report/data")
public class ReportDataController {
@Autowired
private ReportVersionService reportVersionService;
@Operation(summary = "预览")
@Parameters({
@Parameter(name = "id", description = "模板id")
})
@PostMapping("/{id}/preview")
public ActionResult preview(@PathVariable String id, @RequestBody Map<String, Object> params) {
ReportPagination pagination = JsonUtil.getJsonToBean(params, ReportPagination.class);
UniverPreview preview = reportVersionService.preview(id, pagination, params);
return ActionResult.success(preview);
}
@Operation(summary = "预览")
@Parameters({
@Parameter(name = "id", description = "模板id")
})
@PostMapping("/{id}/previewTemplate")
public ActionResult previewTemplate(@PathVariable String id, @RequestBody Map<String, Object> params) {
ReportPagination pagination = JsonUtil.getJsonToBean(params, ReportPagination.class);
UniverPreview preview = reportVersionService.previewTemplate(id, pagination, params);
return ActionResult.success(preview);
}
@Operation(summary = "上传图片")
@PostMapping(value = "/upload/file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ActionResult upload(@RequestPart("file") MultipartFile file) {
UploaderVO vo = new UploaderVO();
String type = "annex";
try {
String filePath = FilePathUtil.getFilePath(type);
String fileName = RandomUtil.uuId() + ".jpeg";
byte[] bytes = file.getBytes();
String url = "/api/Report/data/Download?name=" + fileName + "&encryption=";
FileInfo fileInfo = FileUploadUtils.uploadFile(bytes, filePath, fileName);
vo.setName(fileInfo.getFilename());
vo.setUrl(UploaderUtil.uploaderFile(url, fileInfo.getFilename() + "#" + type));
} catch (Exception e) {
}
return ActionResult.success(vo);
}
@Operation(summary = "远端接口下载图片")
@PostMapping(value = "/downImg")
public ActionResult upload(@RequestBody ReportPagination pagination) {
UploaderVO vo = new UploaderVO();
String type = "annex";
try {
byte[] bytes = null;
String imgValue = pagination.getImgValue();
String imgType = pagination.getImgType();
if (StringUtil.isNotEmpty(imgValue)) {
if (Objects.equals(ImageEnum.BASE64.name(), imgType)) {
String regex = "data:image/\\w+;base64,";
String base64Img = imgValue;
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(imgValue);
if (matcher.find()) {
base64Img = imgValue.replace(matcher.group(), "");
}
bytes = Base64.decode(base64Img);
} else {
HttpRequest request = HttpRequest.of(imgValue).method(Method.GET);
bytes = request.execute().bodyBytes();
}
}
if (bytes != null && bytes.length > 0) {
String filePath = FilePathUtil.getFilePath(type);
String fileName = RandomUtil.uuId() + ".jpeg";
String url = "/api/Report/data/Download?name=" + fileName + "&encryption=";
FileInfo fileInfo = FileUploadUtils.uploadFile(bytes, filePath, fileName);
vo.setName(fileInfo.getFilename());
vo.setUrl(UploaderUtil.uploaderFile(url, fileInfo.getFilename() + "#" + type));
}
} catch (Exception e) {
}
return ActionResult.success(vo);
}
@Operation(summary = "上传excel")
@PostMapping(value = "/ImportExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ActionResult importExcel(@RequestPart("file") MultipartFile multipartFile) throws IOException {
UniverPreview preview = reportVersionService.importExcel(multipartFile);
return ActionResult.success(preview);
}
@Operation(summary = "下载excel")
@Parameters({
@Parameter(name = "id", description = "模板id")
})
@PostMapping("/{id}/DownExcel")
public ActionResult down(@PathVariable String id, @RequestBody Map<String, Object> params) {
ReportPagination pagination = JsonUtil.getJsonToBean(params, ReportPagination.class);
pagination.setId(id);
UploaderVO vo = reportVersionService.downExcel(pagination);
return ActionResult.success(vo);
}
@NoDataSourceBind()
@Operation(summary = "下载文件")
@GetMapping("/Download")
public void downExcel(String encryption, String name) {
String fileNameAll = DesUtil.aesDecode(encryption).replaceAll("\n", "");
if (!StringUtil.isEmpty(fileNameAll)) {
String[] data = fileNameAll.split("#");
String fileName = data.length > 1 ? data[1] : "";
String type = data.length > 2 ? data[2] : "";
String typePath = FilePathUtil.getFilePath(type.toLowerCase());
byte[] bytes = FileUploadUtils.downloadFileByte(typePath, fileName, false);
if (fileName.endsWith(".jpeg")) {
FileDownloadUtil.flushImage(bytes, fileName);
} else {
FileDownloadUtil.downloadFile(bytes, fileName, name);
}
}
}
}