mirror of
https://gitee.com/xiaonuobase/snowy.git
synced 2026-03-22 10:47:16 +08:00
【新增】机构过多后一个个添加麻烦,新增批量复制一批到另一个机构下的功能
This commit is contained in:
@@ -49,5 +49,9 @@ export default {
|
||||
// 获取人员选择器
|
||||
orgUserSelector(data) {
|
||||
return request('userSelector', data, 'get')
|
||||
},
|
||||
// 复制机构
|
||||
orgCopy(data) {
|
||||
return request('copy', data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ export default {
|
||||
orgPage(data) {
|
||||
return request('page', data, 'get')
|
||||
},
|
||||
// 获取组织列表
|
||||
orgList(data) {
|
||||
return request('list', data, 'get')
|
||||
},
|
||||
// 获取组织树
|
||||
orgTree(data) {
|
||||
return request('tree', data, 'get')
|
||||
@@ -49,5 +45,9 @@ export default {
|
||||
// 获取用户选择器
|
||||
orgUserSelector(data) {
|
||||
return request('userSelector', data, 'get')
|
||||
},
|
||||
// 复制组织
|
||||
orgCopy(params) {
|
||||
return request('copy', params)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@
|
||||
:expand-row-by-click="true"
|
||||
:loading="selectedTableListLoading"
|
||||
bordered
|
||||
|
||||
>
|
||||
<template #title>
|
||||
<span>已选择: {{ selectedData.length }}</span>
|
||||
|
||||
109
snowy-admin-web/src/views/biz/org/copyForm.vue
Normal file
109
snowy-admin-web/src/views/biz/org/copyForm.vue
Normal file
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<xn-form-container title="批量复制机构" :width="550" :visible="visible" :destroy-on-close="true" @close="onClose">
|
||||
<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
|
||||
<a-form-item label="目标上级机构:" name="targetParentId">
|
||||
<a-tree-select
|
||||
v-model:value="formData.targetParentId"
|
||||
class="xn-wd"
|
||||
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
|
||||
placeholder="请选择目标上级机构"
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
:tree-data="treeData"
|
||||
:field-names="{
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
value: 'id'
|
||||
}"
|
||||
selectable="false"
|
||||
tree-line
|
||||
/>
|
||||
<a-alert
|
||||
class="mt-3"
|
||||
message="温馨提示:批量复制将自动跳过同名机构;复制内容包含排序号、机构名称、分类;部门主管需重新指定。"
|
||||
type="warning"
|
||||
show-icon
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
<template #footer>
|
||||
<a-button class="xn-mr8" @click="onClose">关闭</a-button>
|
||||
<a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
|
||||
</template>
|
||||
</xn-form-container>
|
||||
</template>
|
||||
|
||||
<script setup name="bizOrgCopyForm">
|
||||
import { required } from '@/utils/formRules'
|
||||
import bizOrgApi from '@/api/biz/bizOrgApi'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
// 定义emit事件
|
||||
const emit = defineEmits({ successful: null })
|
||||
// 默认是关闭状态
|
||||
const visible = ref(false)
|
||||
const formRef = ref()
|
||||
// 表单数据
|
||||
const formData = ref({})
|
||||
// 定义机构元素
|
||||
const treeData = ref([])
|
||||
const submitLoading = ref(false)
|
||||
// 选中的ID列表
|
||||
const ids = ref([])
|
||||
|
||||
// 打开抽屉
|
||||
const onOpen = (idParam) => {
|
||||
visible.value = true
|
||||
formData.value = {}
|
||||
if (idParam) {
|
||||
ids.value = idParam.map((item) => item.id)
|
||||
}
|
||||
// 获取机构树并加入顶级
|
||||
bizOrgApi.orgTreeSelector().then((res) => {
|
||||
treeData.value = [
|
||||
{
|
||||
id: '0',
|
||||
parentId: '-1',
|
||||
name: '顶级',
|
||||
children: res
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
// 关闭抽屉
|
||||
const onClose = () => {
|
||||
visible.value = false
|
||||
}
|
||||
// 默认要校验的
|
||||
const formRules = {
|
||||
targetParentId: [required('请选择目标上级机构')]
|
||||
}
|
||||
|
||||
// 验证并提交数据
|
||||
const onSubmit = () => {
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
submitLoading.value = true
|
||||
const param = {
|
||||
ids: ids.value,
|
||||
targetParentId: formData.value.targetParentId
|
||||
}
|
||||
bizOrgApi
|
||||
.orgCopy(param)
|
||||
.then(() => {
|
||||
visible.value = false
|
||||
message.success('复制成功')
|
||||
emit('successful')
|
||||
})
|
||||
.finally(() => {
|
||||
submitLoading.value = false
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
// 调用这个函数将子组件的一些数据和方法暴露出去
|
||||
defineExpose({
|
||||
onOpen
|
||||
})
|
||||
</script>
|
||||
@@ -75,6 +75,14 @@
|
||||
<template #icon><plus-outlined /></template>
|
||||
新增
|
||||
</a-button>
|
||||
<xn-batch-button
|
||||
v-if="hasPerm('bizOrgCopy')"
|
||||
buttonName="批量复制"
|
||||
icon="CopyOutlined"
|
||||
:isPopconFirm="false"
|
||||
:selectedRowKeys="selectedRowKeys"
|
||||
@batchCallBack="copyBatchOrg"
|
||||
/>
|
||||
<xn-batch-button
|
||||
v-if="hasPerm('bizOrgBatchDelete')"
|
||||
buttonName="批量删除"
|
||||
@@ -101,6 +109,7 @@
|
||||
</template>
|
||||
</XnResizablePanel>
|
||||
<Form ref="formRef" @successful="tableRef.refresh()" />
|
||||
<CopyForm ref="copyFormRef" @successful="tableRef.clearRefreshSelected()" />
|
||||
</template>
|
||||
|
||||
<script setup name="bizOrg">
|
||||
@@ -108,6 +117,7 @@
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import bizOrgApi from '@/api/biz/bizOrgApi'
|
||||
import Form from './form.vue'
|
||||
import CopyForm from './copyForm.vue'
|
||||
|
||||
const columns = [
|
||||
{
|
||||
@@ -219,4 +229,9 @@
|
||||
tableRef.value.clearRefreshSelected()
|
||||
})
|
||||
}
|
||||
// 批量复制
|
||||
const copyFormRef = ref()
|
||||
const copyBatchOrg = (params) => {
|
||||
copyFormRef.value.onOpen(params)
|
||||
}
|
||||
</script>
|
||||
|
||||
109
snowy-admin-web/src/views/sys/org/copyForm.vue
Normal file
109
snowy-admin-web/src/views/sys/org/copyForm.vue
Normal file
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<xn-form-container title="批量复制组织" :width="550" :visible="visible" :destroy-on-close="true" @close="onClose">
|
||||
<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
|
||||
<a-form-item label="目标上级组织:" name="targetParentId">
|
||||
<a-tree-select
|
||||
v-model:value="formData.targetParentId"
|
||||
class="xn-wd"
|
||||
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
|
||||
placeholder="请选择目标上级组织"
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
:tree-data="treeData"
|
||||
:field-names="{
|
||||
children: 'children',
|
||||
label: 'name',
|
||||
value: 'id'
|
||||
}"
|
||||
selectable="false"
|
||||
tree-line
|
||||
/>
|
||||
<a-alert
|
||||
class="mt-3"
|
||||
message="温馨提示:批量复制将自动跳过同名组织;复制内容包含排序号、组织名称、分类;部门主管需重新指定。"
|
||||
type="warning"
|
||||
show-icon
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
<template #footer>
|
||||
<a-button class="xn-mr8" @click="onClose">关闭</a-button>
|
||||
<a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
|
||||
</template>
|
||||
</xn-form-container>
|
||||
</template>
|
||||
|
||||
<script setup name="orgCopyForm">
|
||||
import { required } from '@/utils/formRules'
|
||||
import orgApi from '@/api/sys/orgApi'
|
||||
import { message } from 'ant-design-vue'
|
||||
|
||||
// 定义emit事件
|
||||
const emit = defineEmits({ successful: null })
|
||||
// 默认是关闭状态
|
||||
const visible = ref(false)
|
||||
const formRef = ref()
|
||||
// 表单数据
|
||||
const formData = ref({})
|
||||
// 定义机构元素
|
||||
const treeData = ref([])
|
||||
const submitLoading = ref(false)
|
||||
// 选中的ID列表
|
||||
const ids = ref([])
|
||||
|
||||
// 打开抽屉
|
||||
const onOpen = (idParam) => {
|
||||
visible.value = true
|
||||
formData.value = {}
|
||||
if (idParam) {
|
||||
ids.value = idParam.map((item) => item.id)
|
||||
}
|
||||
// 获取机构树并加入顶级
|
||||
orgApi.orgOrgTreeSelector().then((res) => {
|
||||
treeData.value = [
|
||||
{
|
||||
id: '0',
|
||||
parentId: '-1',
|
||||
name: '顶级',
|
||||
children: res
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
// 关闭抽屉
|
||||
const onClose = () => {
|
||||
visible.value = false
|
||||
}
|
||||
// 默认要校验的
|
||||
const formRules = {
|
||||
targetParentId: [required('请选择目标上级组织')]
|
||||
}
|
||||
|
||||
// 验证并提交数据
|
||||
const onSubmit = () => {
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
submitLoading.value = true
|
||||
const param = {
|
||||
ids: ids.value,
|
||||
targetParentId: formData.value.targetParentId
|
||||
}
|
||||
orgApi
|
||||
.orgCopy(param)
|
||||
.then(() => {
|
||||
visible.value = false
|
||||
message.success('复制成功')
|
||||
emit('successful')
|
||||
})
|
||||
.finally(() => {
|
||||
submitLoading.value = false
|
||||
})
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
// 调用这个函数将子组件的一些数据和方法暴露出去
|
||||
defineExpose({
|
||||
onOpen
|
||||
})
|
||||
</script>
|
||||
@@ -76,6 +76,13 @@
|
||||
</template>
|
||||
新增
|
||||
</a-button>
|
||||
<xn-batch-button
|
||||
buttonName="批量复制"
|
||||
icon="CopyOutlined"
|
||||
:isPopconFirm="false"
|
||||
:selectedRowKeys="selectedRowKeys"
|
||||
@batchCallBack="copyBatchOrg"
|
||||
/>
|
||||
<xn-batch-button
|
||||
buttonName="批量删除"
|
||||
icon="DeleteOutlined"
|
||||
@@ -101,6 +108,7 @@
|
||||
</template>
|
||||
</XnResizablePanel>
|
||||
<Form ref="formRef" @successful="tableRef.refresh()" />
|
||||
<CopyForm ref="copyFormRef" @successful="tableRef.clearRefreshSelected()" />
|
||||
</template>
|
||||
|
||||
<script setup name="sysOrg">
|
||||
@@ -108,6 +116,7 @@
|
||||
import { isEmpty } from 'lodash-es'
|
||||
import orgApi from '@/api/sys/orgApi'
|
||||
import Form from './form.vue'
|
||||
import CopyForm from './copyForm.vue'
|
||||
|
||||
const columns = [
|
||||
{
|
||||
@@ -147,6 +156,7 @@
|
||||
// 定义tableDOM
|
||||
const tableRef = ref(null)
|
||||
const formRef = ref()
|
||||
const copyFormRef = ref()
|
||||
const searchFormRef = ref()
|
||||
const searchFormState = ref({})
|
||||
// 默认展开的节点
|
||||
@@ -216,4 +226,8 @@
|
||||
tableRef.value.clearRefreshSelected()
|
||||
})
|
||||
}
|
||||
// 批量复制
|
||||
const copyBatchOrg = (params) => {
|
||||
copyFormRef.value.onOpen(params)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -143,6 +143,22 @@ public class BizOrgController {
|
||||
return CommonResult.data(bizOrgService.detail(bizOrgIdParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制机构
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/12/24 01:30
|
||||
*/
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "复制机构")
|
||||
@CommonLog("复制机构")
|
||||
@SaCheckPermission("/biz/org/copy")
|
||||
@PostMapping("/biz/org/copy")
|
||||
public CommonResult<String> copy(@RequestBody @Valid BizOrgCopyParam bizOrgCopyParam) {
|
||||
bizOrgService.copy(bizOrgCopyParam);
|
||||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
/* ====机构部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
@@ -151,7 +167,7 @@ public class BizOrgController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "获取机构树选择器")
|
||||
@SaCheckPermission("/biz/org/orgTreeSelector")
|
||||
@GetMapping("/biz/org/orgTreeSelector")
|
||||
@@ -165,7 +181,7 @@ public class BizOrgController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 8)
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(summary = "获取人员选择器")
|
||||
@SaCheckPermission("/biz/org/userSelector")
|
||||
@GetMapping("/biz/org/userSelector")
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright [2022] [https://www.xiaonuo.vip]
|
||||
*
|
||||
* Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
* 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.biz.modular.org.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 机构复制参数
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/12/24 01:30
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
public class BizOrgCopyParam {
|
||||
|
||||
/** 目标父id */
|
||||
@Schema(description = "目标父id")
|
||||
@NotBlank(message = "targetParentId不能为空")
|
||||
private String targetParentId;
|
||||
|
||||
/** 机构id集合 */
|
||||
@Schema(description = "机构id集合")
|
||||
@NotEmpty(message = "ids不能为空")
|
||||
private List<String> ids;
|
||||
}
|
||||
@@ -172,4 +172,12 @@ public interface BizOrgService extends IService<BizOrg> {
|
||||
* @date 2022/4/24 20:08
|
||||
*/
|
||||
Page<BizUser> userSelector(BizOrgSelectorUserParam bizOrgSelectorUserParam);
|
||||
|
||||
/**
|
||||
* 复制机构
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/12/24 01:30
|
||||
*/
|
||||
void copy(BizOrgCopyParam bizOrgCopyParam);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
||||
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.org.enums.BizOrgCategoryEnum;
|
||||
import vip.xiaonuo.biz.modular.org.enums.BizOrgSourceFromTypeEnum;
|
||||
import vip.xiaonuo.biz.modular.org.mapper.BizOrgMapper;
|
||||
import vip.xiaonuo.biz.modular.org.param.*;
|
||||
import vip.xiaonuo.biz.modular.org.service.BizOrgExtService;
|
||||
@@ -395,6 +396,63 @@ public class BizOrgServiceImpl extends ServiceImpl<BizOrgMapper, BizOrg> impleme
|
||||
return bizUserService.page(CommonPageRequest.defaultPage(), queryWrapper.lambda());
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void copy(BizOrgCopyParam bizOrgCopyParam) {
|
||||
// 获取目标父id
|
||||
String targetParentId = bizOrgCopyParam.getTargetParentId();
|
||||
// 获取机构id集合
|
||||
List<String> orgIdList = bizOrgCopyParam.getIds();
|
||||
if(ObjectUtil.isNotEmpty(orgIdList)) {
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
||||
// 如果有数据范围限制,则校验目标父id是否有权限
|
||||
if(!loginUserDataScope.contains(targetParentId)) {
|
||||
throw new CommonException("您没有权限在该机构下增加机构,机构id:{}", targetParentId);
|
||||
}
|
||||
// 再校验源ID权限
|
||||
if(!new HashSet<>(loginUserDataScope).containsAll(orgIdList)) {
|
||||
throw new CommonException("您没有权限复制这些机构,机构id:{}", orgIdList);
|
||||
}
|
||||
} else {
|
||||
throw new CommonException("您没有权限复制机构");
|
||||
}
|
||||
|
||||
// 遍历复制
|
||||
orgIdList.forEach(orgId -> {
|
||||
BizOrg bizOrg = this.getById(orgId);
|
||||
if(ObjectUtil.isNotEmpty(bizOrg)) {
|
||||
// 查询是否有重复名称
|
||||
boolean repeatName = this.count(new LambdaQueryWrapper<BizOrg>()
|
||||
.eq(BizOrg::getParentId, targetParentId)
|
||||
.eq(BizOrg::getName, bizOrg.getName())) > 0;
|
||||
// 如果有重复名称则跳过
|
||||
if(!repeatName) {
|
||||
BizOrg copyBizOrg = new BizOrg();
|
||||
// 复制部分字段
|
||||
copyBizOrg.setName(bizOrg.getName());
|
||||
copyBizOrg.setCategory(bizOrg.getCategory());
|
||||
copyBizOrg.setSortCode(bizOrg.getSortCode());
|
||||
copyBizOrg.setExtJson(bizOrg.getExtJson());
|
||||
// 设置父id
|
||||
copyBizOrg.setParentId(targetParentId);
|
||||
// 重新生成code
|
||||
copyBizOrg.setCode(RandomUtil.randomString(10));
|
||||
// 主管置空
|
||||
copyBizOrg.setDirectorId(null);
|
||||
// 保存
|
||||
this.save(copyBizOrg);
|
||||
// 插入扩展信息
|
||||
bizOrgExtService.createExtInfo(copyBizOrg.getId(), BizOrgSourceFromTypeEnum.SYSTEM_ADD.getValue());
|
||||
// 发布增加事件
|
||||
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(copyBizOrg));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* ====以下为各种递归方法==== */
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,6 +136,21 @@ public class SysOrgController {
|
||||
return CommonResult.data(sysOrgService.detail(sysOrgIdParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制组织
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/12/24 01:10
|
||||
*/
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "复制组织")
|
||||
@CommonLog("复制组织")
|
||||
@PostMapping("/sys/org/copy")
|
||||
public CommonResult<String> copy(@RequestBody @Valid SysOrgCopyParam sysOrgCopyParam) {
|
||||
sysOrgService.copy(sysOrgCopyParam);
|
||||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
/* ====组织部分所需要用到的选择器==== */
|
||||
|
||||
/**
|
||||
@@ -144,7 +159,7 @@ public class SysOrgController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "获取组织树选择器")
|
||||
@GetMapping("/sys/org/orgTreeSelector")
|
||||
public CommonResult<List<Tree<String>>> orgTreeSelector() {
|
||||
@@ -157,7 +172,7 @@ public class SysOrgController {
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 8)
|
||||
@ApiOperationSupport(order = 9)
|
||||
@Operation(summary = "获取用户选择器")
|
||||
@GetMapping("/sys/org/userSelector")
|
||||
public CommonResult<Page<SysUser>> userSelector(SysOrgSelectorUserParam sysOrgSelectorUserParam) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright [2022] [https://www.xiaonuo.vip]
|
||||
*
|
||||
* Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
* 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
package vip.xiaonuo.sys.modular.org.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织复制参数
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/8/15 14:32
|
||||
**/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SysOrgCopyParam {
|
||||
|
||||
/** 目标父id */
|
||||
@Schema(description = "目标父id")
|
||||
@NotBlank(message = "targetParentId不能为空")
|
||||
private String targetParentId;
|
||||
|
||||
/** 组织id集合 */
|
||||
@Schema(description = "组织id集合")
|
||||
@NotEmpty(message = "ids不能为空")
|
||||
private List<String> ids;
|
||||
}
|
||||
@@ -77,6 +77,14 @@ public interface SysOrgService extends IService<SysOrg> {
|
||||
*/
|
||||
SysOrg detail(SysOrgIdParam sysOrgIdParam);
|
||||
|
||||
/**
|
||||
* 复制组织
|
||||
*
|
||||
* @author yubaoshan
|
||||
* @date 2025/12/24 01:10
|
||||
*/
|
||||
void copy(SysOrgCopyParam sysOrgCopyParam);
|
||||
|
||||
/**
|
||||
* 获取组织详情
|
||||
*
|
||||
|
||||
@@ -205,6 +205,49 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
||||
return this.queryEntity(sysOrgIdParam.getId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void copy(SysOrgCopyParam sysOrgCopyParam) {
|
||||
// 获取目标父id
|
||||
String targetParentId = sysOrgCopyParam.getTargetParentId();
|
||||
// 获取组织id集合
|
||||
List<String> orgIdList = sysOrgCopyParam.getIds();
|
||||
if(ObjectUtil.isNotEmpty(orgIdList)) {
|
||||
// 遍历复制
|
||||
orgIdList.forEach(orgId -> {
|
||||
SysOrg sysOrg = this.getById(orgId);
|
||||
if(ObjectUtil.isNotEmpty(sysOrg)) {
|
||||
// 查询是否有重复名称
|
||||
boolean repeatName = this.count(new LambdaQueryWrapper<SysOrg>()
|
||||
.eq(SysOrg::getParentId, targetParentId)
|
||||
.eq(SysOrg::getName, sysOrg.getName())) > 0;
|
||||
// 如果有重复名称则跳过
|
||||
if(!repeatName) {
|
||||
SysOrg copySysOrg = new SysOrg();
|
||||
// 复制部分字段
|
||||
copySysOrg.setName(sysOrg.getName());
|
||||
copySysOrg.setCategory(sysOrg.getCategory());
|
||||
copySysOrg.setSortCode(sysOrg.getSortCode());
|
||||
copySysOrg.setExtJson(sysOrg.getExtJson());
|
||||
// 设置父id
|
||||
copySysOrg.setParentId(targetParentId);
|
||||
// 重新生成code
|
||||
copySysOrg.setCode(RandomUtil.randomString(10));
|
||||
// 主管置空
|
||||
copySysOrg.setDirectorId(null);
|
||||
// 保存
|
||||
this.save(copySysOrg);
|
||||
// 插入扩展信息
|
||||
sysOrgExtService.createExtInfo(copySysOrg.getId(), SysOrgSourceFromTypeEnum.SYSTEM_ADD.getValue());
|
||||
// 发布增加事件
|
||||
CommonDataChangeEventCenter.doAddWithData(SysDataTypeEnum.ORG.getValue(), JSONUtil.createArray().put(copySysOrg));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysOrg queryEntity(String id) {
|
||||
SysOrg sysOrg = this.getById(id);
|
||||
|
||||
@@ -1176,6 +1176,16 @@ INSERT INTO `SYS_RELATION` VALUES ('1813960110876631050', '1570687866138206208',
|
||||
INSERT INTO `SYS_RELATION` VALUES ('1871280434097565701', '1570687866138206208', '1870158678418993154', 'SYS_ROLE_HAS_RESOURCE', '{\"menuId\":\"1870158678418993154\",\"buttonInfo\":[\"1870158678481907713\",\"1870158678481907714\",\"1870158678481907715\",\"1870158678481907716\"]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('1871280434097565751', '1570687866138206208', '1871278073018986498', 'SYS_ROLE_HAS_RESOURCE', '{\"menuId\":\"1871278073018986498\",\"buttonInfo\":[\"1871278073086095361\",\"1871278073086095362\",\"1871278073086095363\",\"1871278073086095364\",\"1871280381043814402\"]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('1909233948956041233', '1570687866138206208', '1548901111999771927', 'SYS_ROLE_HAS_RESOURCE', '{\"menuId\":\"1548901111999771927\",\"buttonInfo\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505988', '1570687866138206208', '/biz/group/add', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/add\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505989', '1570687866138206208', '/biz/group/delete', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/delete\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505990', '1570687866138206208', '/biz/group/detail', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/detail\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505991', '1570687866138206208', '/biz/group/edit', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/edit\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505992', '1570687866138206208', '/biz/group/grantUser', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/grantUser\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505993', '1570687866138206208', '/biz/group/orgTreeSelector', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/orgTreeSelector\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505994', '1570687866138206208', '/biz/group/ownUser', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/ownUser\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505995', '1570687866138206208', '/biz/group/page', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/page\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704174505996', '1570687866138206208', '/biz/group/userSelector', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/group/userSelector\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
INSERT INTO `SYS_RELATION` VALUES ('2003522704178700296', '1570687866138206208', '/biz/org/copy', 'SYS_ROLE_HAS_PERMISSION', '{\"apiUrl\":\"/biz/org/copy\",\"scopeCategory\":\"SCOPE_ALL\",\"scopeDefineOrgIdList\":[]}');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for SYS_RESOURCE
|
||||
@@ -1287,6 +1297,7 @@ INSERT INTO `SYS_RESOURCE` VALUES ('1871278073086095362', '1871278073018986498',
|
||||
INSERT INTO `SYS_RESOURCE` VALUES ('1871278073086095363', '1871278073018986498', '删除用户组', NULL, 'bizGroupDelete', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 3, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||
INSERT INTO `SYS_RESOURCE` VALUES ('1871278073086095364', '1871278073018986498', '批量删除', NULL, 'bizGroupBatchDelete', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 4, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||
INSERT INTO `SYS_RESOURCE` VALUES ('1871280381043814402', '1871278073018986498', '授权用户', NULL, 'bizGroupGrantUser', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 5, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||
INSERT INTO `SYS_RESOURCE` VALUES ('2003522569956777985', '1548901111999773978', '复制机构', NULL, 'bizOrgCopy', 'BUTTON', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 5, NULL, 'NOT_DELETE', NULL, NULL, NULL, NULL);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for SYS_ROLE
|
||||
|
||||
Reference in New Issue
Block a user