审核处理

This commit is contained in:
Wenchao Gong 2021-09-10 17:07:47 +08:00
parent 4b43db12cc
commit 98eddbdc0d
11 changed files with 231 additions and 53 deletions

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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;
/**
* 天配额

View File

@ -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;
/**
* 天配额

View File

@ -91,7 +91,7 @@ public class IscAppServiceBo extends BaseEntity {
* 续期时长单位月
*/
@NotNull(message = "续期时长不能为空", groups = { AddGroup.class })
private Long renewalDuration;
private Integer renewalDuration;
/**

View File

@ -72,7 +72,7 @@ public class IscAppServiceApplyVo {
@ExcelProperty(value = "续期时长", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "单=位月")
@ApiModelProperty("续期时长(单位月)")
private Long renewalDuration;
private Integer renewalDuration;
/**
* 天配额

View File

@ -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<IscAppService
}
result = updateById(new IscAppServiceApply().setApplyId(id).setStatus(bo.getStatus())
.setAuditMind(bo.getRemark()));
IscAppService appService = appServiceService.getById(apply.getAppServiceId());
Assert.notNull(appService, () -> 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.<IscAppServiceApply>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;
}
}

View File

@ -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<IscAppServiceMapper, IscAppService, IscAppServiceVo> implements IIscAppServiceService {
public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMapper, IscAppService, IscAppServiceVo> implements IIscAppServiceService
{
@Resource
private IIscServiceService serviceService;
@ -46,19 +46,22 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
private IIscAppServiceApplyService applyService;
@Override
public IscAppServiceVo queryById(Long appServiceId){
public IscAppServiceVo queryById(Long appServiceId)
{
return getVoById(appServiceId);
}
@Override
public TableDataInfo<IscAppServiceVo> queryPageList(IscAppServiceBo bo) {
public TableDataInfo<IscAppServiceVo> queryPageList(IscAppServiceBo bo)
{
PagePlus<IscAppService, IscAppServiceVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
genServiceName(result.getRecordsVo());
return PageUtils.buildDataInfo(result);
}
@Override
public List<IscAppServiceVo> queryList(IscAppServiceBo bo) {
public List<IscAppServiceVo> queryList(IscAppServiceBo bo)
{
final List<IscAppServiceVo> results = listVo(buildQueryWrapper(bo));
genServiceName(results);
return results;
@ -66,22 +69,23 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
/**
* 组装服务名称
*
* @param results 应用服务列表
*/
private void genServiceName(List<IscAppServiceVo> results)
{
if(CollectionUtil.isEmpty(results)) {
if (CollectionUtil.isEmpty(results)) {
return;
}
Set<Long> serviceIds = results.stream().map(IscAppServiceVo::getServiceId).collect(Collectors.toSet());
Map<Long, String> nameMap = serviceService.getNameMap(serviceIds);
for (IscAppServiceVo result : results)
{
for (IscAppServiceVo result : results) {
result.setServiceName(nameMap.get(result.getServiceId()));
}
}
private LambdaQueryWrapper<IscAppService> buildQueryWrapper(IscAppServiceBo bo) {
private LambdaQueryWrapper<IscAppService> buildQueryWrapper(IscAppServiceBo bo)
{
Map<String, Object> params = bo.getParams();
Long userId = SecurityUtils.getUserId();
LambdaQueryWrapper<IscAppService> lqw = Wrappers.lambdaQuery();
@ -94,7 +98,8 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
}
@Override
public Boolean insertByBo(IscAppServiceBo bo) {
public Boolean insertByBo(IscAppServiceBo bo)
{
IscAppService add = BeanUtil.toBean(bo, IscAppService.class);
validEntityBeforeSave(add);
add.setStatus(IscConstants.AUDIT_WAIT);
@ -106,12 +111,21 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
}
@Override
public Boolean updateByBo(IscAppServiceBo bo) {
IscAppService update = BeanUtil.toBean(bo, IscAppService.class);
public Boolean updateByBo(IscAppServiceBo bo)
{
IscAppService appService = getById(bo.getAppServiceId());
Assert.notNull(appService, () -> 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 ServicePlusImpl<IscAppServiceMappe
*
* @param entity 实体类数据
*/
private void validEntityBeforeSave(IscAppService entity){
private void validEntityBeforeSave(IscAppService entity)
{
//判断是否有申请未审核
if(Objects.nonNull(entity.getAppServiceId())){
if (Objects.nonNull(entity.getAppServiceId())) {
long count = applyService.count(Wrappers.<IscAppServiceApply>lambdaQuery()
.eq(IscAppServiceApply::getAppServiceId, entity.getAppServiceId())
.eq(IscAppServiceApply::getStatus, IscConstants.AUDIT_WAIT));
@ -130,8 +145,9 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
}
@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
if(isValid){
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid)
{
if (isValid) {
//TODO 做一些业务上的校验,判断是否需要校验
}
return removeByIds(ids);
@ -141,8 +157,8 @@ public class IscAppServiceServiceImpl extends ServicePlusImpl<IscAppServiceMappe
public List<Tree<Long>> genAppServiceTree(Long applicationId)
{
List<Long> serviceIds = listObjs(Wrappers.<IscAppService>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<IscAppServiceMappe
/**
* 添加 服务申请记录
*
* @param appService 应用服务信息
* @param applyType 申请类型
* @param appServiceId 应用服务ID
* @return 是否添加成功
*/
private Boolean addApplyRecord(IscAppServiceBo appService, String applyType, Long appServiceId) {
private Boolean addApplyRecord(IscAppServiceBo appService, String applyType, Long appServiceId)
{
IscAppServiceApplyBo entity = new IscAppServiceApplyBo();
entity.setAppServiceId(appServiceId);
entity.setApplyType(applyType);

View File

@ -47,17 +47,6 @@
@click="handleAdd"
v-hasPermi="['isc:appservice:add']"
>申请</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-time"
size="mini"
:disabled="single"
@click="handleRenewal"
v-hasPermi="['isc:appservice:edit']"
>续期</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -96,7 +85,7 @@
</el-row>
<el-table v-loading="loading" :data="appserviceList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column type="selection" width="55" align="center" :selectable="selectable"/>
<el-table-column label="应用服务ID" align="center" prop="appServiceId" v-if="false"/>
<el-table-column label="服务名称" align="left" prop="serviceName" />
<el-table-column label="虚拟地址" align="left" prop="virtualAddr" />
@ -136,6 +125,7 @@
icon="el-icon-time"
@click="handleRenewal(scope.row)"
v-hasPermi="['isc:appservice:edit']"
v-if="scope.row.status == 1"
>续期</el-button>
<el-button
size="mini"
@ -143,6 +133,7 @@
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['isc:appservice:edit']"
v-if="scope.row.status != 0"
>修改</el-button>
<el-button
size="mini"
@ -310,6 +301,9 @@ export default {
this.loading = false;
});
},
selectable(row, index) {
return row.status != 0;
},
/** 获取应用信息 */
getApplicationName(applicationId) {
getApplication(applicationId).then(response => {

View File

@ -76,7 +76,7 @@
</el-row>
<el-table v-loading="loading" :data="serviceList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column type="selection" width="55" align="center" :selectable="selectable"/>
<el-table-column label="服务ID" align="center" prop="serviceId" width="100"/>
<el-table-column label="服务名称" align="left" prop="serviceName" />
<el-table-column label="服务分类" align="left" prop="cateName" width="150"/>
@ -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']"
>查看</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-view"
@click="handleAuditSingle(scope.row)"
@click="handleAuditSingle(scope.row, false)"
v-hasPermi="['isc:service:audit']"
v-if="scope.row.status == 0"
>审核</el-button>
</template>
</el-table-column>
@ -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;

View File

@ -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;