diff --git a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/license/vo/LicenseRespVO.java b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/license/vo/LicenseRespVO.java index 0fb0802..0549c97 100644 --- a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/license/vo/LicenseRespVO.java +++ b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/license/vo/LicenseRespVO.java @@ -109,6 +109,10 @@ public class LicenseRespVO implements VO { @ExcelProperty("申请时间") private LocalDateTime applicationTime; + @Schema(description = "申请次数") + @ExcelProperty("申请次数") + private Integer applyCount; + private LicenseRespVO oldLicense; private boolean hasHistory; diff --git a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/project/vo/ProjectRespVO.java b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/project/vo/ProjectRespVO.java index 35b362b..89c2773 100644 --- a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/project/vo/ProjectRespVO.java +++ b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/controller/admin/project/vo/ProjectRespVO.java @@ -123,6 +123,10 @@ public class ProjectRespVO implements VO { @ExcelProperty("评论数") private Integer commentNum; + @Schema(description = "申请数") + @ExcelProperty("申请数") + private Integer applyCount; + @Schema(description = "最后修改时间", requiredMode = Schema.RequiredMode.REQUIRED) @ExcelProperty("最后修改时间") private LocalDateTime updateTime; diff --git a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/license/LicenseServiceImpl.java b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/license/LicenseServiceImpl.java index 936646d..2a419a9 100644 --- a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/license/LicenseServiceImpl.java +++ b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/license/LicenseServiceImpl.java @@ -38,6 +38,7 @@ import org.agt.module.system.api.mail.MailSendApi; import org.agt.module.system.api.mail.dto.MailSendSingleToUserReqDTO; import org.agt.module.system.api.notify.NotifyMessageSendApi; import org.agt.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -480,7 +481,12 @@ public class LicenseServiceImpl implements LicenseService { .eq(LicenseHistoryDO::getLicenseId, license.getId()) .orderByDesc(LicenseHistoryDO::getApplicationTime)); Optional histroyOptional = historyList.stream().findFirst(); - license.setHasHistory(histroyOptional.isPresent()); + license.setHasHistory(LicenseStatusEnum.COMPLETED.getCode().equals(license.getStatus()) || histroyOptional.isPresent()); + int applyCount = 1; + if (histroyOptional.isPresent()) { + applyCount = applyCount + historyList.size(); + } + license.setApplyCount(applyCount); if (LicenseStatusEnum.REAPPLYING.getCode().equals(license.getStatus())) { if (histroyOptional.isPresent()) { LicenseHistoryDO historyDO = histroyOptional.get(); @@ -492,44 +498,53 @@ public class LicenseServiceImpl implements LicenseService { license.setOldLicense(oldLicense); - int maxLength = oldDetails.size(); - if (oldDetails.size() < details.size()) { - maxLength = details.size(); - } - - List mergeDetails = new ArrayList<>(); - for (int i = 0; i < maxLength; i++) { - Map activationCodeMap = new HashMap<>(); - Map> neListMap = new HashMap<>(); - Map> fileUrlListMap = new HashMap<>(); - - LicenseDetailVO mergeDetail = new LicenseDetailVO(); - if (i < oldDetails.size()) { - activationCodeMap.put("old", oldDetails.get(i).getActivationCode()); - neListMap.put("old", oldDetails.get(i).getNeList()); - fileUrlListMap.put("old", null); - mergeDetail.setFileUrl(oldDetails.get(i).getFileUrl()); - mergeDetail.setNeList(oldDetails.get(i).getNeList()); - mergeDetail.setActivationCode(oldDetails.get(i).getActivationCode()); - mergeDetail.setFileUrlList(oldDetails.get(i).getFileUrlList()); - } - - if (i < details.size()) { - activationCodeMap.put("new", details.get(i).getActivationCode()); - neListMap.put("new", details.get(i).getNeList()); - fileUrlListMap.put("new", null); - } - mergeDetail.setActivationCodeMap(activationCodeMap); - mergeDetail.setNeListMap(neListMap); - mergeDetail.setFileUrlListMap(fileUrlListMap); - mergeDetails.add(mergeDetail); - } + List mergeDetails = fillMergeDetails(oldDetails, details, false); license.setNeCodeList(mergeDetails); } } } + private static @NotNull List fillMergeDetails(List oldDetails, List details, boolean isHistory) { + int maxLength = oldDetails.size(); + if (oldDetails.size() < details.size()) { + maxLength = details.size(); + } + + List mergeDetails = new ArrayList<>(); + for (int i = 0; i < maxLength; i++) { + Map activationCodeMap = new HashMap<>(); + Map> neListMap = new HashMap<>(); + Map> fileUrlListMap = new HashMap<>(); + + LicenseDetailVO mergeDetail = new LicenseDetailVO(); + if (i < oldDetails.size()) { + activationCodeMap.put("old", oldDetails.get(i).getActivationCode()); + neListMap.put("old", oldDetails.get(i).getNeList()); + fileUrlListMap.put("old", null); + mergeDetail.setFileUrl(oldDetails.get(i).getFileUrl()); + mergeDetail.setNeList(oldDetails.get(i).getNeList()); + mergeDetail.setActivationCode(oldDetails.get(i).getActivationCode()); + mergeDetail.setFileUrlList(oldDetails.get(i).getFileUrlList()); + } + + if (i < details.size()) { + activationCodeMap.put("new", details.get(i).getActivationCode()); + neListMap.put("new", details.get(i).getNeList()); + if (isHistory) { + fileUrlListMap.put("old", details.get(i).getFileUrlList()); + } else { + fileUrlListMap.put("new", null); + } + } + mergeDetail.setActivationCodeMap(activationCodeMap); + mergeDetail.setNeListMap(neListMap); + mergeDetail.setFileUrlListMap(fileUrlListMap); + mergeDetails.add(mergeDetail); + } + return mergeDetails; + } + private void fillDetail(List details, LicenseRespVO licenseRespVO) { for (LicenseDetailVO detail : details) { List fileUrlList = new ArrayList<>(); @@ -596,13 +611,31 @@ public class LicenseServiceImpl implements LicenseService { @Override public List getLicenseHistory(Long id) { + LicenseDO licenseDO = licenseMapper.selectById(id); + List allLicenses = new ArrayList<>(); + if (LicenseStatusEnum.COMPLETED.getCode().equals(licenseDO.getStatus())) { + LicenseRespVO license = BeanUtils.toBean(licenseDO, LicenseRespVO.class); + List licenseDetailDOS = licenseDetailMapper.selectList(Wrappers.lambdaQuery().eq(LicenseDetailDO::getLicenseId, license.getId())); + List details = BeanUtils.toBean(licenseDetailDOS, LicenseDetailVO.class); + fillDetail(details, license); + allLicenses.add(license); + } List historyDOList = licenseHistoryMapper.selectList(Wrappers.lambdaQuery() .eq(LicenseHistoryDO::getLicenseId, id).orderByDesc(LicenseHistoryDO::getApplicationTime)); List voList = BeanUtils.toBean(historyDOList, LicenseRespVO.class); for (LicenseRespVO licenseRespVO : voList) { fillLicenseHistoryRespVO(licenseRespVO); } - return voList; + allLicenses.addAll(voList); + for (int i = 0; i < allLicenses.size(); i++) { + if (i + 1 >= allLicenses.size()) { + continue; + } + allLicenses.get(i).setOldLicense(allLicenses.get(i + 1)); + List mergeDetails = fillMergeDetails(allLicenses.get(i).getOldLicense().getNeCodeList(), allLicenses.get(i).getNeCodeList(), true); + allLicenses.get(i).setNeCodeList(mergeDetails); + } + return allLicenses; } @Override diff --git a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/project/ProjectServiceImpl.java b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/project/ProjectServiceImpl.java index 61252cc..dd4cf5f 100644 --- a/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/project/ProjectServiceImpl.java +++ b/agt-module-license/agt-module-license-server/src/main/java/org/agt/module/license/service/project/ProjectServiceImpl.java @@ -17,9 +17,13 @@ import org.agt.module.license.controller.admin.project.vo.ProjectPageReqVO; import org.agt.module.license.controller.admin.project.vo.ProjectRespVO; import org.agt.module.license.controller.admin.project.vo.ProjectSaveReqVO; import org.agt.module.license.dal.dataobject.customer.CustomerDO; +import org.agt.module.license.dal.dataobject.license.LicenseDO; +import org.agt.module.license.dal.dataobject.license.LicenseHistoryDO; import org.agt.module.license.dal.dataobject.project.ProjectDO; import org.agt.module.license.dal.mysql.comment.CommentMapper; import org.agt.module.license.dal.mysql.customer.CustomerMapper; +import org.agt.module.license.dal.mysql.license.LicenseHistoryMapper; +import org.agt.module.license.dal.mysql.license.LicenseMapper; import org.agt.module.license.dal.mysql.project.ProjectMapper; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -27,6 +31,7 @@ import org.springframework.validation.annotation.Validated; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Optional; import static org.agt.framework.common.exception.util.ServiceExceptionUtil.exception; import static org.agt.module.license.enums.ErrorCodeConstants.PROJECT_CODE_DUPLICATE; @@ -53,6 +58,12 @@ public class ProjectServiceImpl implements ProjectService { @Resource private CommentMapper commentMapper; + @Resource + private LicenseMapper licenseMapper; + + @Resource + private LicenseHistoryMapper licenseHistoryMapper; + @Override public Long createProject(ProjectSaveReqVO createReqVO) { // 校验项目名称和编号是否唯一 @@ -112,6 +123,17 @@ public class ProjectServiceImpl implements ProjectService { for (ProjectRespVO record : page.getRecords()) { List comments = commentMapper.getCommentList(record.getId()); record.setCommentNum(comments.size()); + + List licenseList = licenseMapper.selectList(Wrappers.lambdaQuery().eq(LicenseDO::getProjectId, record.getId())); + Optional licenseOptional = licenseList.stream().findFirst(); + int applyCount = 0; + if (licenseOptional.isPresent()) { + List historyList = licenseHistoryMapper.selectList(Wrappers.lambdaQuery() + .eq(LicenseHistoryDO::getLicenseId, licenseOptional.get().getId())); + applyCount = 1 + historyList.size(); + } + record.setApplyCount(applyCount); + } return new PageResult<>(page.getRecords(), page.getTotal()); }