This commit is contained in:
六如
2024-10-17 09:41:34 +08:00
parent 35b3e6489d
commit 17bc2d5ca8
15 changed files with 330 additions and 98 deletions

View File

@@ -38,7 +38,7 @@
<commons-logging.version>1.2</commons-logging.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<fastmybatis.version>3.0.10</fastmybatis.version>
<fastmybatis.version>3.0.11</fastmybatis.version>
</properties>
<dependencies>

View File

@@ -0,0 +1,26 @@
package com.gitee.sop.adminbackend.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
/**
* @author 六如
*/
@AllArgsConstructor
@Getter
public enum YesOrNoEnum {
YES(1),
NO(0);
private final int value;
public static YesOrNoEnum of(Integer value) {
return Objects.equals(value, YES.value) ? YES : NO;
}
public static YesOrNoEnum of(Boolean value) {
return Objects.equals(value, true) ? YES : NO;
}
}

View File

@@ -1,6 +1,7 @@
package com.gitee.sop.adminbackend.controller.isv;
import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.LambdaQuery;
import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.query.param.PageParam;
import com.gitee.sop.adminbackend.common.RSATool;
@@ -8,10 +9,13 @@ import com.gitee.sop.adminbackend.common.dto.StatusUpdateDTO;
import com.gitee.sop.adminbackend.common.req.StatusUpdateParam;
import com.gitee.sop.adminbackend.common.resp.Result;
import com.gitee.sop.adminbackend.controller.isv.req.IsvInfoAddParam;
import com.gitee.sop.adminbackend.controller.isv.req.IsvInfoUpdateParam;
import com.gitee.sop.adminbackend.controller.isv.req.IsvKeysGenParam;
import com.gitee.sop.adminbackend.dao.entity.IsvInfo;
import com.gitee.sop.adminbackend.service.isv.IsvInfoService;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoAddDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoUpdateDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvKeysDTO;
import com.gitee.sop.adminbackend.util.CopyUtil;
import org.springframework.validation.annotation.Validated;
@@ -35,7 +39,6 @@ public class IsvInfoController {
private IsvInfoService isvInfoService;
/**
* 分页查询
*
@@ -43,10 +46,10 @@ public class IsvInfoController {
* @return
*/
@GetMapping("/page")
public Result<PageInfo<IsvInfo>> page(PageParam param) {
Query query = param.toQuery();
PageInfo<IsvInfo> pageInfo = isvInfoService.page(query);
return Result.ok(pageInfo);
public Result<PageInfo<IsvInfoDTO>> page(PageParam param) {
LambdaQuery<IsvInfo> query = param.toLambdaQuery(IsvInfo.class);
PageInfo<IsvInfoDTO> isvInfoDTOPageInfo = isvInfoService.doPage(query);
return Result.ok(isvInfoDTOPageInfo);
}
/**
@@ -92,12 +95,13 @@ public class IsvInfoController {
/**
* 修改记录
*
* @param user 表单数据
* @param param 表单数据
* @return 返回影响行数
*/
@PostMapping("/update")
public Result<Integer> update(@Validated @RequestBody IsvInfo user) {
return Result.ok(isvInfoService.update(user));
public Result<Integer> update(@Validated @RequestBody IsvInfoUpdateParam param) {
IsvInfoUpdateDTO isvInfoUpdateDTO = CopyUtil.copyBean(param, IsvInfoUpdateDTO::new);
return Result.ok(isvInfoService.update(isvInfoUpdateDTO));
}
/**

View File

@@ -3,8 +3,6 @@ package com.gitee.sop.adminbackend.controller.isv.req;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
@@ -14,13 +12,6 @@ import javax.validation.constraints.NotNull;
@Data
public class IsvInfoAddParam {
/**
* 秘钥格式1PKCS8(JAVA适用)2PKCS1(非JAVA适用)
*/
@Min(value = 1, message = "秘钥格式错误")
@Max(value = 2, message = "秘钥格式错误")
private Integer keyFormat;
/**
* 1启用2禁用
*/

View File

@@ -1,26 +1,34 @@
package com.gitee.sop.adminbackend.service.isv;
import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.LambdaQuery;
import com.gitee.fastmybatis.core.support.LambdaService;
import com.gitee.sop.adminbackend.common.RSATool;
import com.gitee.sop.adminbackend.common.dto.StatusUpdateDTO;
import com.gitee.sop.adminbackend.common.enums.StatusEnum;
import com.gitee.sop.adminbackend.common.enums.YesOrNoEnum;
import com.gitee.sop.adminbackend.dao.entity.IsvInfo;
import com.gitee.sop.adminbackend.dao.entity.IsvKeys;
import com.gitee.sop.adminbackend.dao.entity.PermIsvRole;
import com.gitee.sop.adminbackend.dao.mapper.IsvInfoMapper;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoAddDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvInfoUpdateDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvKeysDTO;
import com.gitee.sop.adminbackend.service.isv.dto.IsvKeysGenDTO;
import com.gitee.sop.adminbackend.util.CopyUtil;
import com.gitee.sop.adminbackend.util.IdGen;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -35,6 +43,38 @@ public class IsvInfoService implements LambdaService<IsvInfo, IsvInfoMapper> {
@Resource
private PermIsvRoleService permIsvRoleService;
public PageInfo<IsvInfoDTO> doPage(LambdaQuery<IsvInfo> query) {
PageInfo<IsvInfo> page = this.page(query);
List<IsvInfo> list = page.getList();
if (CollectionUtils.isEmpty(list)) {
return page.convert(isvInfo -> new IsvInfoDTO());
}
List<Long> idList = list.stream()
.map(IsvInfo::getId).collect(Collectors.toList());
Map<Long, IsvKeys> isvIdMap = isvKeysService.query()
.in(IsvKeys::getIsvId, idList)
.map(IsvKeys::getIsvId, Function.identity());
// 格式转换
return page.convert(isvInfo -> {
IsvInfoDTO isvInfoDTO = CopyUtil.copyBean(isvInfo, IsvInfoDTO::new);
boolean hasKey = false;
Optional<IsvKeys> isvKeysOpt = Optional.ofNullable(isvIdMap.get(isvInfo.getId()));
if (isvKeysOpt.isPresent()) {
IsvKeys isvKeys = isvKeysOpt.get();
hasKey = !StringUtils.isAllBlank(
isvKeys.getPrivateKeyIsv(),
isvKeys.getPrivateKeyPlatform(),
isvKeys.getPublicKeyIsv(),
isvKeys.getPublicKeyPlatform()
);
}
isvInfoDTO.setHasKeys(YesOrNoEnum.of(hasKey).getValue());
return isvInfoDTO;
});
}
public RSATool.KeyStore createKeys(RSATool.KeyFormat keyFormat) throws Exception {
if (keyFormat == null) {
keyFormat = RSATool.KeyFormat.PKCS8;
@@ -45,36 +85,31 @@ public class IsvInfoService implements LambdaService<IsvInfo, IsvInfoMapper> {
/**
* 添加ISV
*
* @param isvInfoAddDTO
* @return
* @throws Exception
* @return 返回id
*/
@Transactional(rollbackFor = Exception.class)
public long add(IsvInfoAddDTO isvInfoAddDTO) throws Exception {
public long add(IsvInfoAddDTO isvInfoAddDTO) {
IsvInfo rec = CopyUtil.copyBean(isvInfoAddDTO, IsvInfo::new);
String appKey = new SimpleDateFormat("yyyyMMdd").format(new Date()) + IdGen.nextId();
rec.setAppId(appKey);
rec.setStatus(StatusEnum.ENABLE.getStatus());
this.save(rec);
if (CollectionUtils.isNotEmpty(isvInfoAddDTO.getRoleCodes())) {
this.saveIsvRole(rec, isvInfoAddDTO.getRoleCodes());
}
// 生成秘钥
RSATool.KeyFormat keyFormat = RSATool.KeyFormat.of(isvInfoAddDTO.getKeyFormat());
IsvKeysGenDTO isvKeysGenVO = this.createIsvKeys(keyFormat);
IsvKeys isvKeys = new IsvKeys();
isvKeys.setIsvId(rec.getId());
CopyUtil.copyPropertiesIgnoreNull(isvKeysGenVO, isvKeys);
isvKeysService.save(isvKeys);
return rec.getId();
}
public int update(IsvInfoUpdateDTO isvInfoUpdateDTO) {
return this.query()
.eq(IsvInfo::getId, isvInfoUpdateDTO.getId())
.set(IsvInfo::getStatus, isvInfoUpdateDTO.getStatus())
.set(IsvInfo::getRemark, isvInfoUpdateDTO.getRemark())
.update();
}
private void saveIsvRole(IsvInfo isvInfo, List<String> roleCodeList) {
Long isvId = isvInfo.getId();
permIsvRoleService.query()
.eq(PermIsvRole::getIsvId, isvId)
.delete();
permIsvRoleService.deleteByColumn(PermIsvRole::getIsvId, isvId);
List<PermIsvRole> tobeSaveList = roleCodeList.stream()
.map(roleCode -> {

View File

@@ -3,10 +3,7 @@ package com.gitee.sop.adminbackend.service.isv.dto;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@@ -15,13 +12,6 @@ import java.util.List;
@Data
public class IsvInfoAddDTO {
/**
* 秘钥格式1PKCS8(JAVA适用)2PKCS1(非JAVA适用)
*/
@Min(value = 1, message = "秘钥格式错误")
@Max(value = 2, message = "秘钥格式错误")
private Integer keyFormat;
/**
* 1启用2禁用
*/
@@ -34,9 +24,4 @@ public class IsvInfoAddDTO {
@Length(max = 500)
private String remark;
/**
* 角色code
*/
private List<String> roleCodes;
}

View File

@@ -0,0 +1,45 @@
package com.gitee.sop.adminbackend.service.isv.dto;
import com.gitee.fastmybatis.annotation.Pk;
import com.gitee.fastmybatis.annotation.PkStrategy;
import com.gitee.fastmybatis.annotation.Table;
import lombok.Data;
import java.time.LocalDateTime;
/**
*
* @author 六如
*/
@Data
public class IsvInfoDTO {
private Long id;
/**
* appKey
*/
private String appId;
/**
* 1启用2禁用
*/
private Integer status;
/**
* 是否有秘钥
*/
private Integer hasKeys;
/**
* 备注
*/
private String remark;
private LocalDateTime addTime;
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,13 @@
package com.gitee.sop.adminbackend.service.isv.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author 六如
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class IsvInfoUpdateDTO extends IsvInfoAddDTO {
private Long id;
}

View File

@@ -1,11 +1,11 @@
export type Result = {
export interface Result {
success: boolean;
data: object;
msg: "";
code: "";
};
}
export type PageResult = {
export interface PageResult {
success: boolean;
msg: "";
code: "";
@@ -13,4 +13,4 @@ export type PageResult = {
total: 0;
list: Array<any>;
};
};
}

View File

@@ -1,8 +1,7 @@
import { computed, type Ref, ref } from "vue";
import { ref } from "vue";
import {
type ButtonsCallBackParams,
type FieldValues,
type OptionsRow,
type PageInfo,
type PlusColumn,
useTable
@@ -10,6 +9,7 @@ import {
import { ElMessage } from "element-plus";
import { KeyFormatEnum, StatusEnum } from "@/model/enums";
import { api } from "@/api/isvList";
import { settingKeys } from "@/views/isv/list/isvKeys";
const isAdd = ref(false);
@@ -17,10 +17,8 @@ const isAdd = ref(false);
// 查询表单对象
export const searchFormData = ref({
id: "",
appId: "",
status: "",
remark: "",
pageIndex: 1,
pageSize: 10
});
@@ -121,7 +119,6 @@ actionButtons.value = [
props: {
type: "primary"
},
show: computed(() => true),
onClick(params: ButtonsCallBackParams) {
isAdd.value = false;
editFormData.value = Object.assign({}, params.row);
@@ -129,6 +126,16 @@ actionButtons.value = [
dlgShow.value = true;
}
},
{
text: "设置秘钥",
code: "edit",
props: {
type: "primary"
},
onClick(params: ButtonsCallBackParams) {
settingKeys(params.row);
}
},
{
// 启用/禁用
text: row => (row.status === StatusEnum.ENABLE ? "禁用" : "启用"),
@@ -177,15 +184,6 @@ const editFormDataGen = () => {
export const editFormData = ref<FieldValues>(editFormDataGen());
export const editFormRules = {};
// options推荐写法
// 1. 定义一个 `ref`数组
const roleList: Ref<OptionsRow[]> = ref([]);
// 2. 异步函数获取到值赋值到 `ref`
const loadRole = async () => {
//
};
loadRole();
// 表单内容
export const editFormColumns: PlusColumn[] = [
{
@@ -197,29 +195,29 @@ export const editFormColumns: PlusColumn[] = [
placeholder: "自动生成"
}
},
{
label: "秘钥格式",
prop: "keyFormat",
valueType: "radio",
options: [
{
label: "PKCS8(Java适用)",
value: KeyFormatEnum.PKCS8
},
{
label: "PKCS1(非Java适用)",
value: KeyFormatEnum.PKCS1
}
]
},
{
label: "角色",
prop: "roleCodes",
valueType: "checkbox",
// options推荐写法
// 3. 用 computed 返回 ref 的 value
options: computed(() => roleList.value)
},
// {
// label: "秘钥格式",
// prop: "keyFormat",
// valueType: "radio",
// options: [
// {
// label: "PKCS8(Java适用)",
// value: KeyFormatEnum.PKCS8
// },
// {
// label: "PKCS1(非Java适用)",
// value: KeyFormatEnum.PKCS1
// }
// ]
// },
// {
// label: "角色",
// prop: "roleCodes",
// valueType: "checkbox",
// // options推荐写法
// // 3. 用 computed 返回 ref 的 value
// options: computed(() => roleList.value)
// },
{
label: "状态",
prop: "status",

View File

@@ -23,6 +23,11 @@ import {
showKeysFormData,
viewKeys
} from "./showKeys";
import {
dlgKeysSetting,
settingKeysFormColumns,
settingKeysFormData
} from "@/views/isv/list/isvKeys";
</script>
<template>
<el-card shadow="never">
@@ -39,7 +44,7 @@ import {
<PlusTable
:columns="tableColumns"
:table-data="tableData"
:action-bar="{ buttons: actionButtons, width: 120 }"
:action-bar="{ buttons: actionButtons, width: 190 }"
:pagination="{
total,
modelValue: pageInfo,
@@ -52,7 +57,14 @@ import {
<el-button type="primary" @click="handleAdd">新增</el-button>
</template>
<template #plus-cell-keys="scoped">
<el-link type="primary" @click="viewKeys(scoped.row)">查看</el-link>
<el-link
v-if="scoped.row.hasKeys"
type="primary"
@click="viewKeys(scoped.row)"
>
查看
</el-link>
<span v-else>未设置</span>
</template>
</PlusTable>
<PlusDialogForm
@@ -68,12 +80,40 @@ import {
}"
@confirm="handleSave"
/>
<!-- 查看秘钥 -->
<PlusDialogForm
v-model:visible="dlgKeysShow"
v-model="showKeysFormData"
:dialog="{ title: '秘钥' }"
:form="{ group: showKeysFormColumns, labelPosition: 'right' }"
>
<template #plus-field-privateKeyIsv>
<el-input
v-model="showKeysFormData.privateKeyIsv"
readonly
placeholder=""
/>
<el-button style="margin-top: 20px">重置ISV秘钥</el-button>
</template>
<template #dialog-footer="{ handleCancel }">
<el-button type="primary" @click="handleCancel">关闭</el-button>
</template>
</PlusDialogForm>
<!-- 设置秘钥 -->
<PlusDialogForm
v-model:visible="dlgKeysSetting"
v-model="settingKeysFormData"
:dialog="{ title: '秘钥' }"
:form="{ group: settingKeysFormColumns, labelPosition: 'right' }"
>
<template #plus-field-privateKeyIsv>
<el-input
v-model="showKeysFormData.privateKeyIsv"
readonly
placeholder=""
/>
<el-button style="margin-top: 20px">重置ISV秘钥</el-button>
</template>
<template #dialog-footer="{ handleCancel }">
<el-button type="primary" @click="handleCancel">关闭</el-button>
</template>

View File

@@ -0,0 +1,12 @@
// options推荐写法
// 1. 定义一个 `ref`数组
import { type Ref, ref } from "vue";
import { type OptionsRow } from "plus-pro-components";
const groupList: Ref<OptionsRow[]> = ref([]);
// 2. 异步函数获取到值赋值到 `ref`
const loadGroup = async () => {
//
console.log(groupList);
};
loadGroup();

View File

@@ -0,0 +1,83 @@
import { ref } from "vue";
import type { PlusFormGroupRow } from "plus-pro-components";
import { CreditCard } from "@element-plus/icons-vue";
import { api } from "@/api/isvList";
// 弹窗显示
export const dlgKeysSetting = ref(false);
export const settingKeysFormData = ref<any>({
publicKeyIsv: "",
privateKeyIsv: "",
publicKeyPlatform: "",
privateKeyPlatform: ""
});
// 表单内容
export const settingKeysFormColumns: PlusFormGroupRow[] = [
{
title: "ISV公私钥 - 标识☆分配给开发者",
icon: CreditCard,
columns: [
{
label: "ISV公钥",
prop: "publicKeyIsv",
valueType: "textarea",
labelWidth: 100,
fieldProps: {
showWordLimit: false,
placeholder: "",
readonly: true,
autosize: { minRows: 2, maxRows: 4 }
}
},
{
label: "☆ISV私钥",
prop: "privateKeyIsv",
valueType: "textarea",
labelWidth: 100,
fieldProps: {
showWordLimit: false,
placeholder: "",
autosize: { minRows: 2, maxRows: 4 }
}
}
]
},
{
title: "平台公私钥 - 标识☆分配给开发者",
icon: CreditCard,
columns: [
{
label: "☆平台公钥",
prop: "publicKeyPlatform",
valueType: "textarea",
labelWidth: 100,
fieldProps: {
showWordLimit: false,
placeholder: "",
autosize: { minRows: 2, maxRows: 4 }
}
},
{
label: "平台私钥",
prop: "privateKeyPlatform",
valueType: "textarea",
labelWidth: 100,
fieldProps: {
showWordLimit: false,
placeholder: "",
autosize: { minRows: 2, maxRows: 4 }
}
}
]
}
];
export const settingKeys = (row: any) => {
const params = {
isvId: row.id
};
api.viewKeys(params).then(resp => {
settingKeysFormData.value = resp.data;
dlgKeysSetting.value = true;
});
};

View File

@@ -5,7 +5,7 @@ import { api } from "@/api/isvList";
// 弹窗显示
export const dlgKeysShow = ref(false);
export const showKeysFormData = ref<object>({
export const showKeysFormData = ref<any>({
publicKeyIsv: "",
privateKeyIsv: "",
publicKeyPlatform: "",

View File

@@ -38,7 +38,7 @@
<commons-logging.version>1.2</commons-logging.version>
<validation-api.version>2.0.1.Final</validation-api.version>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
<fastmybatis.version>3.0.10</fastmybatis.version>
<fastmybatis.version>3.0.11</fastmybatis.version>
</properties>
<dependencies>