feat(REQ-3300): 导出

This commit is contained in:
chenwenjian 2025-02-08 18:44:07 +08:00
parent 6113aaeab8
commit 2c3ad3ce17

View File

@ -8,6 +8,7 @@ import cn.axzo.basics.common.constant.enums.OrganizationalNodeTypeEnum;
import cn.axzo.basics.common.util.AssertUtil;
import cn.axzo.basics.common.util.NumberUtil;
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
import cn.axzo.basics.report.api.ReportServiceSDK;
import cn.axzo.basics.report.api.sheet.SheetWrapper;
import cn.axzo.foundation.page.PageResp;
import cn.axzo.framework.domain.ServiceException;
@ -53,6 +54,7 @@ import cn.axzo.nanopart.visa.server.domain.ChangeRecordRelation;
import cn.axzo.nanopart.visa.server.dto.VisaAddLogContext;
import cn.axzo.nanopart.visa.server.dto.VisaBillDto;
import cn.axzo.nanopart.visa.server.dto.VisaConfirmDto;
import cn.axzo.nanopart.visa.server.dto.VisaExportDto;
import cn.axzo.nanopart.visa.server.dto.VisaLogParam;
import cn.axzo.nanopart.visa.server.mapper.ChangeRecordDao;
import cn.axzo.nanopart.visa.server.rpc.ApolloConstructionAreaGateway;
@ -104,6 +106,7 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@ -165,8 +168,9 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
@Resource
private VisaOrganizationalNodeUserGateway nodeUserGateway;
// @Resource
// private ReportServiceSDK reportServiceSDK;
@Resource
private ReportServiceSDK reportServiceSDK;
@Resource
private WorkflowGateway workflowGateway;
@Resource
@ -809,6 +813,10 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
public void export(VisaChangeExportReq req) {
VisaChangePageSearchReq filter = req.getFilter();
List<VisaChangeFieldEnum> fields = req.getFields();
// 默认导出全部字段
if (CollectionUtils.isEmpty(fields)) {
fields = Arrays.asList(VisaChangeFieldEnum.values());
}
// Set<Long> permissionVisaIdSet = this.fetchPermissionVisaIdSet(filter);
List<ChangeRecord> changeRecordList = Lists.newArrayList();
@ -819,16 +827,55 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
/*获取数据*/
changeRecordList = getFilter(filter, Sets.newHashSet()).list();
AssertUtil.notEmpty(changeRecordList, "没有数据需要导出");
AssertUtil.isTrue(CollUtil.isNotEmpty(changeRecordList), "");
/*数据转换*/
// 所属工程
Map<Long, String> projectInfoMapById;
Map<Long, OrgNodeUserBriefInfoResp> initiatorMap;
if (fields.contains(VisaChangeFieldEnum.RELATION_PROJECT)) {
List<Long> projectIdList = changeRecordList.stream().map(ChangeRecord::getRelationProject).collect(Collectors.toList());
projectInfoMapById = getProjectInfoMapById(projectIdList);
} else {
projectInfoMapById = Collections.emptyMap();
}
// 发起人
if (fields.contains(VisaChangeFieldEnum.CREATE_BY)) {
List<Long> initiatorPersonIdList = changeRecordList.stream().map(ChangeRecord::getCreateBy).distinct().collect(Collectors.toList());
// Map<personId,OrgNodeUserBriefInfoResp>
initiatorMap = getPersonBriefInfoMap(changeRecordList.get(0).getRelationWorkspaceId(), initiatorPersonIdList);
} else {
initiatorMap = Collections.emptyMap();
}
List<Object> data = changeRecordList.stream()
.map(item -> VisaExportDto.builder()
.no(item.getNo())
.type(item.getType().getDesc())
.status(item.getStatus().getDesc())
.topic(item.getTopic())
.relationProject(CollUtil.isNotEmpty(projectInfoMapById) ? projectInfoMapById.getOrDefault(item.getRelationProject(), "") : "")
.happenTime(item.getHappenTime())
.amountChange(item.getAmountChange())
.approvalCompleteTime(Objects.equals(VisaStatusEnum.COMPLETED, item.getStatus()) ? item.getApprovalCompleteTime() : null)
.initiator(CollUtil.isNotEmpty(initiatorMap) ? initiatorMap.getOrDefault(item.getCreateBy(), OrgNodeUserBriefInfoResp.builder().build()).getRealName() : "")
.build())
.collect(Collectors.toList());
/*导出文excel并上传至云*/
String scene = "visa";
String fileName = String.format("变更签证单%s", DateUtil.format(new Date(), "yyyyMMddHHmmss"));
SheetWrapper sheetWrapper = new SheetWrapper();
sheetWrapper.setTitle("变更签证单");
// sheetWrapper
// reportServiceSDK.asyncUploadReportPsw(scene, fileName, null, false, );
String sheetName = "变更签证表";
String headerName = "变更签证单";
SheetWrapper sheetWrapper = SheetWrapper.builder()
.title(headerName)
.sheetName(sheetName)
.includeColumnFieldNames(fields.stream()
.map(VisaChangeFieldEnum::getDesc)
.collect(Collectors.toList()))
.sourceData(data)
.build();
reportServiceSDK.asyncUploadReportPsw(scene, fileName, null, false, sheetWrapper);
}
private LambdaQueryChainWrapper<ChangeRecord> getFilter(VisaChangePageSearchReq filter, Set<Long> permissionVisaIdSet) {
@ -918,10 +965,7 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
}
/*获取工程信息*/
List<Long> projectIdList = records.stream().map(ChangeRecord::getRelationProject).distinct().collect(Collectors.toList());
List<ProjectBriefResp> projectBriefByIds = visaProjectApiGateway.getProjectBriefByIds(projectIdList);
AssertUtil.notEmpty(projectBriefByIds, "工程信息获取失败");
// Map<projectId,name>
Map<Long, String> projectIdNameMap = projectBriefByIds.stream().collect(Collectors.toMap(ProjectBriefResp::getId, ProjectBriefResp::getName));
Map<Long, String> projectIdNameMap = getProjectInfoMapById(projectIdList);
/*获取变更单发起人*/
List<Long> visaIdList = records.stream().map(ChangeRecord::getId).distinct().collect(Collectors.toList());
@ -931,7 +975,7 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
/*获取发起人岗位*/
List<Long> initiatorPersonIdList = visaIdInitiatorMap.values().stream().map(ChangeRecordConfirm::getPersonId).distinct().collect(Collectors.toList());
// Map<id,OrgNodeUserBriefInfoResp>
// Map<personId,OrgNodeUserBriefInfoResp>
Map<Long, OrgNodeUserBriefInfoResp> initiatorMap = getPersonBriefInfoMap(records.get(0).getRelationWorkspaceId(), initiatorPersonIdList);
AssertUtil.isTrue(CollUtil.isNotEmpty(initiatorMap), "发起人信息获取失败");
@ -966,6 +1010,15 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
.collect(Collectors.toList());
}
private Map<Long, String> getProjectInfoMapById(List<Long> projectIdList) {
List<ProjectBriefResp> projectBriefByIds = visaProjectApiGateway.getProjectBriefByIds(projectIdList);
if (CollectionUtils.isEmpty(projectBriefByIds)) {
return Collections.emptyMap();
}
// Map<projectId,name>
return projectBriefByIds.stream().collect(Collectors.toMap(ProjectBriefResp::getId, ProjectBriefResp::getName));
}
private Map<Long, ChangeRecordConfirm> getInitiatorMapByVisaId(List<Long> visaIdList) {
VisaConfirmDto visaConfirmDto = VisaConfirmDto.builder()
.bizType(VisaConfirmBizTypeEnum.CREATE)
@ -980,17 +1033,17 @@ public class ChangeRecordServiceImpl extends ServiceImpl<ChangeRecordDao, Change
private static void validSearchCondition(VisaChangePageSearchReq req) {
if (CollectionUtils.isNotEmpty(req.getAmountChange())) {
AssertUtil.notNull(req.getAmountChange().size() < 2, "请填写金额范围");
AssertUtil.isFalse(req.getAmountChange().size() < 2, "请填写金额范围");
// 最大最小值的符号必须相同
AssertUtil.isTrue(Objects.equals(req.getAmountChange().get(0).signum(), req.getAmountChange().get(1).signum()), "请输入合法的变更金额范围");
AssertUtil.isTrue(req.getAmountChange().get(0).compareTo(req.getAmountChange().get(1)) < 0, "最大金额不能小于最小金额");
}
if (CollectionUtils.isNotEmpty(req.getHappenTime())) {
AssertUtil.notNull(req.getHappenTime().size() < 2, "请填写提出时间范围");
AssertUtil.isFalse(req.getHappenTime().size() < 2, "请填写提出时间范围");
AssertUtil.isTrue(req.getHappenTime().get(0).compareTo(req.getHappenTime().get(1)) < 0, "提出结束时间不能小于开始时间");
}
if (CollectionUtils.isNotEmpty(req.getApproveCompletedDate())) {
AssertUtil.notNull(req.getApproveCompletedDate().size() < 2, "请填写审批完成范围");
AssertUtil.isFalse(req.getApproveCompletedDate().size() < 2, "请填写审批完成范围");
AssertUtil.isTrue(req.getApproveCompletedDate().get(0).compareTo(req.getApproveCompletedDate().get(1)) < 0, "审批完成结束时间不能小于开始时间");
}
}