From 98eddbdc0d71c56386b923902fa5084a6a607f73 Mon Sep 17 00:00:00 2001 From: Wenchao Gong Date: Fri, 10 Sep 2021 17:07:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/DateUtils.java | 43 +++++++-- .../main/java/com/ruoyi/isc/RouteUtils.java | 36 +++++++ .../ruoyi/isc/domain/IscAppServiceApply.java | 4 +- .../isc/domain/bo/IscAppServiceApplyBo.java | 8 +- .../ruoyi/isc/domain/bo/IscAppServiceBo.java | 2 +- .../isc/domain/vo/IscAppServiceApplyVo.java | 2 +- .../impl/IscAppServiceApplyServiceImpl.java | 96 +++++++++++++++++++ .../impl/IscAppServiceServiceImpl.java | 62 +++++++----- ruoyi-ui/src/views/isc/appservice/index.vue | 18 ++-- ruoyi-ui/src/views/isc/service/audit.vue | 12 ++- ruoyi-ui/src/views/isc/serviceapply/index.vue | 1 + 11 files changed, 231 insertions(+), 53 deletions(-) create mode 100644 ruoyi-isc/src/main/java/com/ruoyi/isc/RouteUtils.java diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 536cb3cf0..dbfea97c0 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -1,14 +1,17 @@ package com.ruoyi.common.utils; +import cn.hutool.core.date.LocalDateTimeUtil; +import org.apache.commons.lang3.time.DateFormatUtils; + import java.lang.management.ManagementFactory; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.ZoneId; import java.util.Date; -import org.apache.commons.lang3.time.DateFormatUtils; /** * 时间工具类 - * + * * @author ruoyi */ public class DateUtils extends org.apache.commons.lang3.time.DateUtils @@ -22,15 +25,15 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; - + private static String[] parsePatterns = { - "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", + "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; /** * 获取当前Date型日期 - * + * * @return Date() 当前日期 */ public static Date getNowDate() @@ -40,7 +43,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils /** * 获取当前日期, 默认格式为yyyy-MM-dd - * + * * @return String */ public static String getDate() @@ -121,7 +124,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return null; } } - + /** * 获取服务器启动时间 */ @@ -152,4 +155,30 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils // long sec = diff % nd % nh % nm / ns; return day + "天" + hour + "小时" + min + "分钟"; } + + /** + * 获取一天的开始时间 即00:00:00 + * + * @param date 日期 + * @return 一天的开始时间 + */ + public static Date beginOfDay(Date date) + { + return Date.from(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.of(date)) + .atZone(ZoneId.systemDefault()).toInstant()); + } + + + + /** + * 获取一天的结束时间 即23:59:59 + * + * @param date 日期 + * @return 一天的最后一秒 + */ + public static Date endOfDay(Date date) + { + return Date.from(LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.of(date)) + .atZone(ZoneId.systemDefault()).toInstant()); + } } diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/RouteUtils.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/RouteUtils.java new file mode 100644 index 000000000..63352a594 --- /dev/null +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/RouteUtils.java @@ -0,0 +1,36 @@ +package com.ruoyi.isc; + +import cn.hutool.crypto.SecureUtil; +import com.ruoyi.common.exception.ServiceException; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * @author Wenchao Gong + * @date 2021/9/10 14:46 + */ +public class RouteUtils +{ + public static final String PATH_PREFIX = "/proxy"; + + /** + * 获取虚拟URL Path 部分 + * + * @param applicationId 应用ID + * @param serviceId 服务Id + * @param serviceAddr 服务地址 + * @return + */ + public static String genVirtualAddrPath(Long applicationId, Long serviceId, String serviceAddr) + { + URI uri = null; + try { + uri = new URI(serviceAddr); + } catch (URISyntaxException e) { + throw new ServiceException("URL格式异常"); + } + return String.format("%s/%s/%s%s", PATH_PREFIX, SecureUtil.md5(String.valueOf(applicationId)), + SecureUtil.md5(String.valueOf(serviceId)), uri.getPath()); + } +} diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/IscAppServiceApply.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/IscAppServiceApply.java index 76fcd14c7..1f8cc6195 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/IscAppServiceApply.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/IscAppServiceApply.java @@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; + import java.io.Serializable; import java.util.Date; -import java.math.BigDecimal; /** * 应用服务申请信息对象 isc_app_service_apply @@ -52,7 +52,7 @@ public class IscAppServiceApply implements Serializable { /** * 续期时长(单位月) */ - private Long renewalDuration; + private Integer renewalDuration; /** * 天配额 diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceApplyBo.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceApplyBo.java index 27d151064..0b79e1ec4 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceApplyBo.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceApplyBo.java @@ -1,16 +1,14 @@ package com.ruoyi.isc.domain.bo; +import com.ruoyi.common.core.domain.BaseEntity; import com.ruoyi.common.core.validate.AddGroup; import com.ruoyi.common.core.validate.EditGroup; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.validation.constraints.*; -import java.util.Date; - -import com.ruoyi.common.core.domain.BaseEntity; +import javax.validation.constraints.NotNull; /** * 应用服务申请信息业务对象 isc_app_service_apply @@ -53,7 +51,7 @@ public class IscAppServiceApplyBo extends BaseEntity { * 续期时长(单位月) */ @ApiModelProperty(value = "续期时长(单位月)") - private Long renewalDuration; + private Integer renewalDuration; /** * 天配额 diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceBo.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceBo.java index 5fb254b01..8a0397684 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceBo.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/bo/IscAppServiceBo.java @@ -91,7 +91,7 @@ public class IscAppServiceBo extends BaseEntity { * 续期时长(单位月) */ @NotNull(message = "续期时长不能为空", groups = { AddGroup.class }) - private Long renewalDuration; + private Integer renewalDuration; /** diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/vo/IscAppServiceApplyVo.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/vo/IscAppServiceApplyVo.java index f6a42ad47..0d461831a 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/vo/IscAppServiceApplyVo.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/domain/vo/IscAppServiceApplyVo.java @@ -72,7 +72,7 @@ public class IscAppServiceApplyVo { @ExcelProperty(value = "续期时长", converter = ExcelDictConvert.class) @ExcelDictFormat(readConverterExp = "单=位月") @ApiModelProperty("续期时长(单位月)") - private Long renewalDuration; + private Integer renewalDuration; /** * 天配额 diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceApplyServiceImpl.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceApplyServiceImpl.java index a48376e36..127c3d181 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceApplyServiceImpl.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceApplyServiceImpl.java @@ -2,16 +2,21 @@ package com.ruoyi.isc.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.lang.Assert; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.constant.IscConstants; import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; import com.ruoyi.common.core.page.PagePlus; import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.isc.RouteUtils; import com.ruoyi.isc.domain.IscAppService; import com.ruoyi.isc.domain.IscAppServiceApply; +import com.ruoyi.isc.domain.IscService; import com.ruoyi.isc.domain.bo.IscAppServiceApplyBo; import com.ruoyi.isc.domain.bo.IscAuditBo; import com.ruoyi.isc.domain.vo.IscAppServiceApplyVo; @@ -148,7 +153,98 @@ public class IscAppServiceApplyServiceImpl extends ServicePlusImpl new ServiceException("申请信息不存在")); + + IscAppService updateData = null; + if(IscConstants.AUDIT_PASS.equals(bo.getStatus())) { + updateData = genAuditPassData(apply, appService, bo.getStatus()); + }else{ + //如果 应用服务 状态为不通过 时需要同步状态 + updateData = genAuditRejectData(appService, bo); + } + if(Objects.nonNull(updateData)) { + result = appServiceService.updateById(updateData); + } } return result; } + + /** + * 审核通过处理 + * @param apply 申请信息 + * @param appService 应用服务信息 + * @param status 操作状态 + * @return 更新数据 + */ + private IscAppService genAuditPassData(IscAppServiceApply apply, IscAppService appService, String status) + { + IscAppService updateData = new IscAppService().setAppServiceId(appService.getAppServiceId()); + //如果是 服务申请 修改 应用服务 审核状态、生成虚拟地址、服务到期时间 + //如果是续期申请 修改 服务到期时间 + switch (apply.getApplyType()) { + case IscConstants.APPLY_TYPE_APPLY: + genServicePassInit(apply, appService, status, updateData); + break; + case IscConstants.APPLY_TYPE_MODIFY: + //如果 应用服务 状态不为通过 则修改状态(如果是通过:续期不能影响使用) + if(!IscConstants.AUDIT_PASS.equals(appService.getStatus())) { + genServicePassInit(apply, appService, status, updateData); + } + updateData.setQuotaDays(apply.getQuotaDays()); + updateData.setQuotaHours(apply.getQuotaHours()); + updateData.setQuotaMinutes(apply.getQuotaMinutes()); + updateData.setQuotaSeconds(apply.getQuotaSeconds()); + break; + case IscConstants.APPLY_TYPE_RENEWAL: + Date startDate = Objects.isNull(appService.getEndTime()) ? DateUtils.getNowDate() : appService.getEndTime(); + updateData.setEndTime(DateUtils.beginOfDay(DateUtils.addMonths(startDate, apply.getRenewalDuration()))); + break; + default: + throw new ServiceException("申请类型异常"); + } + return updateData; + } + + /** + * 审核通过 初始化生成 虚拟地址、服务结束时间 + * @param apply 申请信息 + * @param appService 应用服务信息 + * @param status 审核状态 + * @param updateData 需要修改的数据 + */ + private void genServicePassInit(IscAppServiceApply apply, IscAppService appService, String status, + IscAppService updateData) + { + updateData.setStatus(status); + IscService service = serviceService.getById(appService.getServiceId()); + Assert.notNull(service, () -> new ServiceException("服务信息不存在")); + Integer renewalDuration = apply.getRenewalDuration(); + //如果 申请时长为空,需要查询审核记录 中的审核时长 + if(Objects.isNull(renewalDuration)) { + IscAppServiceApply log = getOne(Wrappers.lambdaQuery() + .eq(IscAppServiceApply::getAppServiceId, appService.getAppServiceId()) + .eq(IscAppServiceApply::getApplyType, IscConstants.APPLY_TYPE_APPLY) + .last("LIMIT 1"), false); + renewalDuration = Objects.nonNull(log) ? log.getRenewalDuration() : 1; + } + updateData.setEndTime(DateUtils.beginOfDay(DateUtils.addMonths(DateUtils.getNowDate(), renewalDuration))); + updateData.setVirtualAddr(RouteUtils.genVirtualAddrPath(appService.getApplicationId(), + appService.getServiceId(), service.getServiceAddr())); + } + + /** + * 审核不通过处理 + * @param appService 应用服务信息 + * @param bo 审核数据 + * @return 需要更新的信息 + */ + private IscAppService genAuditRejectData(IscAppService appService, IscAuditBo bo) { + if(!IscConstants.AUDIT_PASS.equals(appService.getStatus())) { + IscAppService updateData = new IscAppService().setAppServiceId(appService.getAppServiceId()); + updateData.setStatus(bo.getStatus()); + return updateData; + } + return null; + } } diff --git a/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceServiceImpl.java b/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceServiceImpl.java index c5995713b..a3c643b30 100644 --- a/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceServiceImpl.java +++ b/ruoyi-isc/src/main/java/com/ruoyi/isc/service/impl/IscAppServiceServiceImpl.java @@ -28,7 +28,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; /** @@ -38,7 +37,8 @@ import java.util.stream.Collectors; * @date 2021-09-08 */ @Service -public class IscAppServiceServiceImpl extends ServicePlusImpl implements IIscAppServiceService { +public class IscAppServiceServiceImpl extends ServicePlusImpl implements IIscAppServiceService +{ @Resource private IIscServiceService serviceService; @@ -46,19 +46,22 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl queryPageList(IscAppServiceBo bo) { + public TableDataInfo queryPageList(IscAppServiceBo bo) + { PagePlus result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo)); genServiceName(result.getRecordsVo()); return PageUtils.buildDataInfo(result); } @Override - public List queryList(IscAppServiceBo bo) { + public List queryList(IscAppServiceBo bo) + { final List results = listVo(buildQueryWrapper(bo)); genServiceName(results); return results; @@ -66,22 +69,23 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl results) { - if(CollectionUtil.isEmpty(results)) { + if (CollectionUtil.isEmpty(results)) { return; } Set serviceIds = results.stream().map(IscAppServiceVo::getServiceId).collect(Collectors.toSet()); Map nameMap = serviceService.getNameMap(serviceIds); - for (IscAppServiceVo result : results) - { + for (IscAppServiceVo result : results) { result.setServiceName(nameMap.get(result.getServiceId())); } } - private LambdaQueryWrapper buildQueryWrapper(IscAppServiceBo bo) { + private LambdaQueryWrapper buildQueryWrapper(IscAppServiceBo bo) + { Map params = bo.getParams(); Long userId = SecurityUtils.getUserId(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); @@ -94,7 +98,8 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl new ServiceException("申请信息不存在")); + IscAppService update = new IscAppService().setAppServiceId(bo.getAppServiceId()); validEntityBeforeSave(update); - update.setStatus(IscConstants.AUDIT_WAIT); - addApplyRecord(bo, IscConstants.APPLY_TYPE_RENEWAL, bo.getAppServiceId()); - return updateById(update); + boolean result = true; + if(!IscConstants.AUDIT_PASS.equals(appService.getStatus())) { + update.setStatus(IscConstants.AUDIT_WAIT); + result = updateById(update); + } + String applyType = Objects.nonNull(bo.getRenewalDuration()) ? IscConstants.APPLY_TYPE_RENEWAL : + IscConstants.APPLY_TYPE_MODIFY; + addApplyRecord(bo, applyType, bo.getAppServiceId()); + return result; } /** @@ -119,9 +133,10 @@ public class IscAppServiceServiceImpl extends ServicePlusImpllambdaQuery() .eq(IscAppServiceApply::getAppServiceId, entity.getAppServiceId()) .eq(IscAppServiceApply::getStatus, IscConstants.AUDIT_WAIT)); @@ -130,8 +145,9 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl ids, Boolean isValid) { - if(isValid){ + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) + { + if (isValid) { //TODO 做一些业务上的校验,判断是否需要校验 } return removeByIds(ids); @@ -141,8 +157,8 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl> genAppServiceTree(Long applicationId) { List serviceIds = listObjs(Wrappers.lambdaQuery() - .select(IscAppService::getServiceId) - .eq(IscAppService::getApplicationId, applicationId), o -> (Long) o); + .select(IscAppService::getServiceId) + .eq(IscAppService::getApplicationId, applicationId), o -> (Long) o); return serviceService.genServiceTree(CollectionUtil.newHashSet(serviceIds)); } @@ -156,12 +172,14 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl申请 - - - 续期 - + @@ -136,6 +125,7 @@ icon="el-icon-time" @click="handleRenewal(scope.row)" v-hasPermi="['isc:appservice:edit']" + v-if="scope.row.status == 1" >续期 修改 { diff --git a/ruoyi-ui/src/views/isc/service/audit.vue b/ruoyi-ui/src/views/isc/service/audit.vue index 92a66f0f8..13de6885a 100644 --- a/ruoyi-ui/src/views/isc/service/audit.vue +++ b/ruoyi-ui/src/views/isc/service/audit.vue @@ -76,7 +76,7 @@ - + @@ -107,15 +107,16 @@ size="mini" type="text" icon="el-icon-info" - @click="handleAuditSingle(scope.row)" + @click="handleAuditSingle(scope.row, true)" v-hasPermi="['isc:service:query']" >查看 审核 @@ -292,6 +293,10 @@ export default { cancel() { this.open = false; this.reset(); + this.resetAudit(); + }, + selectable(row, index) { + return row.status == 0; }, // 表单重置 reset() { @@ -360,6 +365,7 @@ export default { this.view = view; this.show = true; this.reset(); + this.resetAudit(); const serviceId = row.serviceId || this.ids getService(serviceId).then(response => { this.loading = false; diff --git a/ruoyi-ui/src/views/isc/serviceapply/index.vue b/ruoyi-ui/src/views/isc/serviceapply/index.vue index 3a11bca06..478d4025a 100644 --- a/ruoyi-ui/src/views/isc/serviceapply/index.vue +++ b/ruoyi-ui/src/views/isc/serviceapply/index.vue @@ -309,6 +309,7 @@ export default { this.view = view; this.show = true; this.reset(); + this.resetAudit(); const applyId = row.applyId || this.ids getServiceapply(applyId).then(response => { this.loading = false;