mirror of https://gitee.com/xiaonuobase/snowy
【更新】完善业务模块的导入导出,导出新SQL
parent
b47192516a
commit
16b2263ae5
|
@ -221,7 +221,7 @@ QQ技术群:732230670
|
|||
## 曾获荣誉
|
||||
|
||||
<p align="center">
|
||||
<img src="https://pan.xiaonuo.vip/?explorer/share/fileOut&shareID=7xtGQLOA&path=%7BshareItemLink%3A7xtGQLOA%7D%2F"/>
|
||||
<img src="https://pan.xiaonuo.vip/?explorer/share/file&hash=ec54DtG4v8DfcUEPF0ACAHWW-urCcymI_0fSSaqMmMXKLsTWdHpQqH0e&name=/%E8%8D%A3%E8%AA%892021%E4%B8%8E2022.jpg"/>
|
||||
</p>
|
||||
|
||||
## 版权说明
|
||||
|
|
|
@ -70,20 +70,16 @@ export default {
|
|||
grantRole(data) {
|
||||
return request('grantRole', data)
|
||||
},
|
||||
// 下载用户导入模板
|
||||
userDownloadImportUserTemplate(data) {
|
||||
return request('downloadImportUserTemplate', data, 'get', {
|
||||
responseType: 'blob'
|
||||
})
|
||||
},
|
||||
// 用户导入
|
||||
userImport(data) {
|
||||
return request('import', data)
|
||||
},
|
||||
// 用户导出
|
||||
// 人员导出
|
||||
userExport(data) {
|
||||
return request('export', data, 'get', {
|
||||
responseType: 'blob'
|
||||
})
|
||||
},
|
||||
// 导出人员个人信息
|
||||
userExportUserInfo(data) {
|
||||
return request('exportUserInfo', data, 'get', {
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ export default {
|
|||
responseType: 'blob'
|
||||
})
|
||||
},
|
||||
// 按模板导出用户个人信息
|
||||
// 导出用户个人信息
|
||||
userExportUserInfo(data) {
|
||||
return request('exportUserInfo', data, 'get', {
|
||||
responseType: 'blob'
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
<template>
|
||||
<a-drawer
|
||||
title="导入导出"
|
||||
:width="620"
|
||||
:visible="visible"
|
||||
:destroy-on-close="true"
|
||||
:footer-style="{ textAlign: 'right' }"
|
||||
@close="onClose"
|
||||
>
|
||||
<span
|
||||
>导入数据格式严格按照系统模板进行数据录入,请点击
|
||||
<a-button type="primary" size="small" @click="downloadImportUserTemplate">下载模板</a-button>
|
||||
</span>
|
||||
<a-divider dashed />
|
||||
<div>
|
||||
<a-spin :spinning="impUploadLoading">
|
||||
<a-upload-dragger :show-upload-list="false" :custom-request="customRequestLocal">
|
||||
<p class="ant-upload-drag-icon">
|
||||
<inbox-outlined></inbox-outlined>
|
||||
</p>
|
||||
<p class="ant-upload-text">单击或拖动文件到此区域进行上传</p>
|
||||
<p class="ant-upload-hint">仅支持xls、xlsx格式文件</p>
|
||||
</a-upload-dragger>
|
||||
</a-spin>
|
||||
</div>
|
||||
<a-alert v-if="impAlertStatus" type="info" :show-icon="false" banner closable @close="onImpClose" class="mt-3">
|
||||
<template #description>
|
||||
<p>导入总数:{{ impResultData.totalCount }} 条</p>
|
||||
<p>导入成功:{{ impResultData.successCount }} 条</p>
|
||||
<div v-if="impResultData.errorCount > 0">
|
||||
<p><span style="color: red">失败条数:</span>{{ impResultData.errorCount }} 条</p>
|
||||
<a-table :dataSource="impResultErrorDataSource" :columns="impErrorColumns" size="small" />
|
||||
</div>
|
||||
</template>
|
||||
</a-alert>
|
||||
</a-drawer>
|
||||
</template>
|
||||
|
||||
<script setup name="bizUserImpExp">
|
||||
import { message } from 'ant-design-vue'
|
||||
import userApi from '@/api/sys/userApi'
|
||||
import bizUserApi from '@/api/biz/bizUserApi'
|
||||
import downloadUtil from '@/utils/downloadUtil'
|
||||
|
||||
const impUploadLoading = ref(false)
|
||||
const impAlertStatus = ref(false)
|
||||
const impResultData = ref({})
|
||||
const impResultErrorDataSource = ref([])
|
||||
const impAccept = [
|
||||
{
|
||||
extension: '.xls',
|
||||
mimeType: 'application/vnd.ms-excel'
|
||||
},
|
||||
{
|
||||
extension: '.xlsx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
}
|
||||
]
|
||||
// 指定能选择的文件类型
|
||||
const uploadAccept = String(
|
||||
impAccept.map((item) => {
|
||||
return item.mimeType
|
||||
})
|
||||
)
|
||||
// 导入
|
||||
const customRequestLocal = (data) => {
|
||||
impUploadLoading.value = true
|
||||
const fileData = new FormData()
|
||||
// 校验上传文件扩展名和文件类型是否为.xls、.xlsx
|
||||
const extension = '.'.concat(data.file.name.split('.').slice(-1).toString().toLowerCase())
|
||||
const mimeType = data.file.type
|
||||
// 提取允许的扩展名
|
||||
const extensionArr = impAccept.map((item) => item.extension)
|
||||
// 提取允许的MIMEType
|
||||
const mimeTypeArr = impAccept.map((item) => item.mimeType)
|
||||
if (!extensionArr.includes(extension) || !mimeTypeArr.includes(mimeType)) {
|
||||
message.warning('上传文件类型仅支持xls、xlsx格式文件!')
|
||||
impUploadLoading.value = false
|
||||
return false
|
||||
}
|
||||
fileData.append('file', data.file)
|
||||
return bizUserApi
|
||||
.userImport(fileData)
|
||||
.then((res) => {
|
||||
impAlertStatus.value = true
|
||||
impResultData.value = res
|
||||
impResultErrorDataSource.value = res.errorDetail
|
||||
})
|
||||
.finally(() => {
|
||||
impUploadLoading.value = false
|
||||
})
|
||||
}
|
||||
// 关闭导入提示
|
||||
const onImpClose = () => {
|
||||
impAlertStatus.value = false
|
||||
}
|
||||
const impErrorColumns = [
|
||||
{
|
||||
title: '索引',
|
||||
dataIndex: 'index',
|
||||
width: '80px'
|
||||
},
|
||||
{
|
||||
title: '原因',
|
||||
dataIndex: 'msg'
|
||||
}
|
||||
]
|
||||
// 定义emit事件
|
||||
const emit = defineEmits({ successful: null })
|
||||
// 默认是关闭状态
|
||||
let visible = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
|
||||
// 打开抽屉
|
||||
const onOpen = () => {
|
||||
visible.value = true
|
||||
}
|
||||
// 关闭抽屉
|
||||
const onClose = () => {
|
||||
visible.value = false
|
||||
// 关闭导入的提示
|
||||
onImpClose()
|
||||
}
|
||||
// 下载用户导入模板
|
||||
const downloadImportUserTemplate = () => {
|
||||
bizUserApi.userDownloadImportUserTemplate().then((res) => {
|
||||
downloadUtil.resultDownload(res)
|
||||
})
|
||||
}
|
||||
// 调用这个函数将子组件的一些数据和方法暴露出去
|
||||
defineExpose({
|
||||
onOpen
|
||||
})
|
||||
</script>
|
|
@ -69,12 +69,8 @@
|
|||
<template #icon><plus-outlined /></template>
|
||||
<span>{{ $t('common.addButton') }}{{ $t('model.user') }}</span>
|
||||
</a-button>
|
||||
<a-button @click="ImpExpRef.onOpen()" v-if="hasPerm('bizUserImport')">
|
||||
<template #icon><import-outlined /></template>
|
||||
<span>{{ $t('common.imports') }}</span>
|
||||
</a-button>
|
||||
<a-button @click="exportBatchUserVerify" v-if="hasPerm('bizUserBatchExport')">
|
||||
<template #icon><delete-outlined /></template>
|
||||
<template #icon><export-outlined /></template>
|
||||
{{ $t('user.batchExportButton') }}
|
||||
</a-button>
|
||||
<xn-batch-delete
|
||||
|
@ -109,8 +105,8 @@
|
|||
$t('common.removeButton')
|
||||
}}</a-button>
|
||||
</a-popconfirm>
|
||||
<a-divider type="vertical" v-if="hasPerm(['bizUserGrantRole', 'bizUserPwdReset'], 'and')" />
|
||||
<a-dropdown v-if="hasPerm(['bizUserGrantRole', 'bizUserPwdReset'], 'and')">
|
||||
<a-divider type="vertical" v-if="hasPerm(['bizUserGrantRole', 'bizUserPwdReset', 'bizUserExportUserInfo'], 'and')" />
|
||||
<a-dropdown v-if="hasPerm(['bizUserGrantRole', 'bizUserPwdReset', 'bizUserExportUserInfo'], 'and')">
|
||||
<a class="ant-dropdown-link">
|
||||
{{ $t('common.more') }}
|
||||
<DownOutlined />
|
||||
|
@ -149,7 +145,6 @@
|
|||
:role-global="false"
|
||||
@onBack="roleBack"
|
||||
/>
|
||||
<ImpExp ref="ImpExpRef" />
|
||||
</template>
|
||||
<script setup name="bizUser">
|
||||
import { message, Empty } from 'ant-design-vue'
|
||||
|
@ -158,8 +153,6 @@
|
|||
import bizUserApi from '@/api/biz/bizUserApi'
|
||||
import roleSelectorPlus from '@/components/Selector/roleSelectorPlus.vue'
|
||||
import Form from './form.vue'
|
||||
import ImpExp from './impExp.vue'
|
||||
import userApi from "@/api/sys/userApi";
|
||||
|
||||
const columns = [
|
||||
{
|
||||
|
@ -329,6 +322,7 @@
|
|||
const params = selectedRowKeys.value.map((m) => {
|
||||
return m
|
||||
})
|
||||
console.log(params)
|
||||
exportBatchUser(params)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
<span>{{ $t('common.imports') }}</span>
|
||||
</a-button>
|
||||
<a-button @click="exportBatchUserVerify">
|
||||
<template #icon><delete-outlined /></template>
|
||||
<template #icon><export-outlined /></template>
|
||||
{{ $t('user.batchExportButton') }}
|
||||
</a-button>
|
||||
<xn-batch-delete
|
||||
|
|
|
@ -14,17 +14,17 @@ package vip.xiaonuo.biz.modular.user.controller;
|
|||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
|
@ -212,44 +212,13 @@ public class BizUserController {
|
|||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载人员导入模板
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 11)
|
||||
@ApiOperation("下载人员导入模板")
|
||||
@CommonLog("下载人员导入模板")
|
||||
@SaCheckPermission("/biz/user/downloadImportUserTemplate")
|
||||
@GetMapping(value = "/biz/user/downloadImportUserTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
|
||||
public CommonResult<String> downloadImportUserTemplate(HttpServletResponse response) throws IOException {
|
||||
bizUserService.downloadImportUserTemplate(response);
|
||||
return CommonResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 人员导入
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 12)
|
||||
@ApiOperation("人员导入")
|
||||
@CommonLog("人员导入")
|
||||
@SaCheckPermission("/biz/user/import")
|
||||
@PostMapping("/biz/user/import")
|
||||
public CommonResult<JSONObject> importUser(@RequestPart("file") @ApiParam(value="文件", required = true) MultipartFile file) {
|
||||
return CommonResult.data(bizUserService.importUser(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 人员导出
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 13)
|
||||
@ApiOperationSupport(order = 11)
|
||||
@ApiOperation("人员导出")
|
||||
@CommonLog("人员导出")
|
||||
@SaCheckPermission("/biz/user/export")
|
||||
|
@ -264,7 +233,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 14)
|
||||
@ApiOperationSupport(order = 12)
|
||||
@ApiOperation("导出人员个人信息")
|
||||
@CommonLog("导出人员个人信息")
|
||||
@SaCheckPermission("/biz/user/exportUserInfo")
|
||||
|
@ -281,7 +250,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 15)
|
||||
@ApiOperationSupport(order = 13)
|
||||
@ApiOperation("获取机构树选择器")
|
||||
@SaCheckPermission("/biz/user/orgTreeSelector")
|
||||
@GetMapping("/biz/user/orgTreeSelector")
|
||||
|
@ -295,7 +264,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 16)
|
||||
@ApiOperationSupport(order = 14)
|
||||
@ApiOperation("获取机构列表选择器")
|
||||
@SaCheckPermission("/biz/user/orgListSelector")
|
||||
@GetMapping("/biz/user/orgListSelector")
|
||||
|
@ -309,7 +278,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 17)
|
||||
@ApiOperationSupport(order = 15)
|
||||
@ApiOperation("获取岗位选择器")
|
||||
@SaCheckPermission("/biz/user/positionSelector")
|
||||
@GetMapping("/biz/user/positionSelector")
|
||||
|
@ -323,7 +292,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 18)
|
||||
@ApiOperationSupport(order = 16)
|
||||
@ApiOperation("获取角色选择器")
|
||||
@SaCheckPermission("/biz/user/roleSelector")
|
||||
@GetMapping("/biz/user/roleSelector")
|
||||
|
@ -337,7 +306,7 @@ public class BizUserController {
|
|||
* @author xuyuxiang
|
||||
* @date 2022/4/24 20:00
|
||||
*/
|
||||
@ApiOperationSupport(order = 19)
|
||||
@ApiOperationSupport(order = 17)
|
||||
@ApiOperation("获取人员选择器")
|
||||
@SaCheckPermission("/biz/user/userSelector")
|
||||
@GetMapping("/biz/user/userSelector")
|
||||
|
|
|
@ -16,8 +16,6 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 人员导出参数
|
||||
*
|
||||
|
@ -38,5 +36,5 @@ public class BizUserExportParam {
|
|||
|
||||
/** 人员id集合 */
|
||||
@ApiModelProperty(value = "人员id集合")
|
||||
private List<String> userIdList;
|
||||
private String userIds;
|
||||
}
|
||||
|
|
|
@ -13,10 +13,8 @@
|
|||
package vip.xiaonuo.biz.modular.user.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
||||
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
||||
import vip.xiaonuo.biz.modular.user.entity.BizUser;
|
||||
|
@ -123,22 +121,6 @@ public interface BizUserService extends IService<BizUser> {
|
|||
**/
|
||||
void grantRole(BizUserGrantRoleParam bizUserGrantRoleParam);
|
||||
|
||||
/**
|
||||
* 下载用户导入模板
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/8/8 13:16
|
||||
**/
|
||||
void downloadImportUserTemplate(HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 人员导入
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2022/8/8 13:16
|
||||
**/
|
||||
JSONObject importUser(MultipartFile file);
|
||||
|
||||
/**
|
||||
* 用户导出
|
||||
*
|
||||
|
|
|
@ -24,14 +24,12 @@ import cn.hutool.core.date.DateTime;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.PhoneUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
|
@ -46,7 +44,6 @@ import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fhs.trans.service.impl.TransService;
|
||||
|
@ -54,7 +51,6 @@ import org.apache.poi.ss.usermodel.*;
|
|||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
||||
import vip.xiaonuo.biz.core.enums.BizBuildInEnum;
|
||||
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
|
||||
|
@ -398,186 +394,22 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|||
sysUserApi.grantRole(bizUserGrantRoleParam.getId(), bizUserGrantRoleParam.getRoleIdList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadImportUserTemplate(HttpServletResponse response) throws IOException {
|
||||
try {
|
||||
InputStream inputStream = POICacheManager.getFile("userImportTemplate.xlsx");
|
||||
byte[] bytes = IoUtil.readBytes(inputStream);
|
||||
CommonDownloadUtil.download("SNOWY2.0系统B端人员导入模板.xlsx", bytes, response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
CommonResponseUtil.renderError(response, "导出失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public JSONObject importUser(MultipartFile file) {
|
||||
try {
|
||||
int successCount = 0;
|
||||
int errorCount = 0;
|
||||
JSONArray errorDetail = JSONUtil.createArray();
|
||||
// 创建临时文件
|
||||
File tempFile = FileUtil.writeBytes(file.getBytes(), FileUtil.file(FileUtil.getTmpDir() +
|
||||
FileUtil.FILE_SEPARATOR + "userImportTemplate.xlsx"));
|
||||
// 读取excel
|
||||
List<BizUserImportParam> bizUserImportParamList = EasyExcel.read(tempFile).head(BizUserImportParam.class).sheet()
|
||||
.headRowNumber(2).doReadSync();
|
||||
List<BizUser> allUserList = this.list();
|
||||
for (int i = 0; i < bizUserImportParamList.size(); i++) {
|
||||
JSONObject jsonObject = this.doImport(allUserList, bizUserImportParamList.get(i), i);
|
||||
if(jsonObject.getBool("success")) {
|
||||
successCount += 1;
|
||||
} else{
|
||||
errorCount += 1;
|
||||
errorDetail.add(jsonObject);
|
||||
}
|
||||
}
|
||||
return JSONUtil.createObj()
|
||||
.set("totalCount", bizUserImportParamList.size())
|
||||
.set("successCount", successCount)
|
||||
.set("errorCount", errorCount)
|
||||
.set("errorDetail", errorDetail);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new CommonException("文件导入失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行导入
|
||||
*
|
||||
* @author xuyuxiang
|
||||
* @date 2023/3/7 13:22
|
||||
**/
|
||||
public JSONObject doImport(List<BizUser> allUserList, BizUserImportParam bizUserImportParam, int i) {
|
||||
String account = bizUserImportParam.getAccount();
|
||||
String name = bizUserImportParam.getName();
|
||||
String orgFullName = bizUserImportParam.getOrgName();
|
||||
String positionFullName = bizUserImportParam.getPositionName();
|
||||
// 校验必填参数
|
||||
if(ObjectUtil.hasEmpty(account, name, orgFullName, positionFullName)) {
|
||||
return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "必填字段存在空值");
|
||||
} else {
|
||||
try {
|
||||
// 机构名称
|
||||
String orgName = CollectionUtil.getLast(StrUtil.split(orgFullName, StrUtil.DASHED));
|
||||
// 职位名称
|
||||
String positionName = CollectionUtil.getLast(StrUtil.split(positionFullName, StrUtil.DASHED));
|
||||
// 机构id
|
||||
String orgId = bizOrgService.getOrgIdByOrgFullNameWithCreate(orgFullName);
|
||||
// 职位id
|
||||
String positionId = bizPositionService.getPositionIdByPositionNameWithCreate(orgId, positionName);
|
||||
|
||||
// 查找账号对应索引
|
||||
int index = CollStreamUtil.toList(allUserList, BizUser::getAccount).indexOf(account);
|
||||
BizUser bizUser = new BizUser();
|
||||
boolean isAdd = false;
|
||||
if(index == -1) {
|
||||
isAdd = true;
|
||||
} else {
|
||||
bizUser = allUserList.get(index);
|
||||
}
|
||||
|
||||
// 获取手机号和邮箱
|
||||
String phone = bizUserImportParam.getPhone();
|
||||
String email = bizUserImportParam.getEmail();
|
||||
|
||||
// 判断手机号是否跟系统现有的重复
|
||||
if(ObjectUtil.isNotEmpty(phone)) {
|
||||
if(isAdd) {
|
||||
boolean repeatPhone = allUserList.stream().anyMatch(tempBizUser -> ObjectUtil
|
||||
.isNotEmpty(tempBizUser.getPhone()) && tempBizUser.getPhone().equals(phone));
|
||||
if(repeatPhone) {
|
||||
// 新增人员手机号重复则不导入该手机号
|
||||
bizUserImportParam.setPhone(null);
|
||||
}
|
||||
} else {
|
||||
String finalExistUserId = bizUser.getId();
|
||||
boolean repeatPhone = allUserList.stream().anyMatch(tempBizUser -> ObjectUtil
|
||||
.isNotEmpty(tempBizUser.getPhone()) && tempBizUser.getPhone()
|
||||
.equals(phone) && !tempBizUser.getId().equals(finalExistUserId));
|
||||
if(repeatPhone) {
|
||||
// 更新人员手机号重复则使用原手机号
|
||||
bizUser.setPhone(bizUser.getPhone());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断邮箱是否跟系统现有的重复
|
||||
if(ObjectUtil.isNotEmpty(email)) {
|
||||
if(isAdd) {
|
||||
boolean repeatEmail = allUserList.stream().anyMatch(tempBizUser -> ObjectUtil
|
||||
.isNotEmpty(tempBizUser.getEmail()) && tempBizUser.getEmail().equals(email));
|
||||
if(repeatEmail) {
|
||||
// 新增邮箱重复则不导入该邮箱
|
||||
bizUserImportParam.setEmail(null);
|
||||
}
|
||||
} else {
|
||||
String finalExistUserId = bizUser.getId();
|
||||
boolean repeatEmail = allUserList.stream().anyMatch(tempBizUser -> ObjectUtil
|
||||
.isNotEmpty(tempBizUser.getEmail()) && tempBizUser.getEmail()
|
||||
.equals(email) && !tempBizUser.getId().equals(finalExistUserId));
|
||||
if(repeatEmail) {
|
||||
// 更新人员手机号重复则使用原邮箱
|
||||
bizUser.setEmail(bizUser.getEmail());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 拷贝属性
|
||||
BeanUtil.copyProperties(bizUserImportParam, bizUser);
|
||||
|
||||
// 设置机构id和职位id
|
||||
bizUser.setOrgId(orgId);
|
||||
bizUser.setPositionId(positionId);
|
||||
|
||||
// 设置机构名称和职位名称(暂时无作用)
|
||||
bizUser.setOrgName(orgName);
|
||||
bizUser.setPositionName(positionName);
|
||||
|
||||
// 发布事件
|
||||
if(isAdd) {
|
||||
// 设置id
|
||||
bizUser.setId(IdWorker.getIdStr());
|
||||
// 设置默认头像
|
||||
bizUser.setAvatar(CommonAvatarUtil.generateImg(bizUser.getName()));
|
||||
// 设置默认密码
|
||||
bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
|
||||
// 设置排序码
|
||||
bizUser.setSortCode(99);
|
||||
// 设置状态
|
||||
bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
|
||||
// 发布增加事件
|
||||
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.USER.getValue(), JSONUtil.createArray().put(bizUser));
|
||||
// 更新全部人员
|
||||
allUserList.add(bizUser);
|
||||
} else {
|
||||
// 发布更新事件
|
||||
CommonDataChangeEventCenter.doUpdateWithData(BizDataTypeEnum.USER.getValue(), JSONUtil.createArray().put(bizUser));
|
||||
// 删除指定索引元素
|
||||
allUserList.remove(index);
|
||||
// 插入指定索引元素
|
||||
allUserList.add(index, bizUser);
|
||||
}
|
||||
|
||||
// 保存或更新
|
||||
this.saveOrUpdate(bizUser);
|
||||
|
||||
// 返回成功
|
||||
return JSONUtil.createObj().set("success", true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return JSONUtil.createObj().set("success", false).set("index", i + 1).set("msg", "数据导入异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportUser(BizUserExportParam bizUserExportParam, HttpServletResponse response) throws IOException {
|
||||
File tempFile = null;
|
||||
try {
|
||||
QueryWrapper<BizUser> queryWrapper = new QueryWrapper<>();
|
||||
if(ObjectUtil.isNotEmpty(bizUserExportParam.getUserIdList())) {
|
||||
queryWrapper.lambda().in(BizUser::getId, bizUserExportParam.getUserIdList());
|
||||
// 排除超管
|
||||
queryWrapper.lambda().ne(BizUser::getAccount, BizBuildInEnum.BUILD_IN_USER_ACCOUNT.getValue());
|
||||
// 校验数据范围
|
||||
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
||||
if(ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
||||
queryWrapper.lambda().in(BizUser::getOrgId, loginUserDataScope);
|
||||
} else {
|
||||
queryWrapper.lambda().eq(BizUser::getId, StpUtil.getLoginIdAsString());
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(bizUserExportParam.getUserIds())) {
|
||||
queryWrapper.lambda().in(BizUser::getId, StrUtil.split(bizUserExportParam.getUserIds(), StrUtil.COMMA));
|
||||
} else {
|
||||
if (ObjectUtil.isNotEmpty(bizUserExportParam.getSearchKey())) {
|
||||
queryWrapper.lambda().like(BizUser::getAccount, bizUserExportParam.getSearchKey())
|
||||
|
|
|
@ -16,8 +16,6 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户导出参数
|
||||
*
|
||||
|
@ -38,5 +36,5 @@ public class SysUserExportParam {
|
|||
|
||||
/** 用户id集合 */
|
||||
@ApiModelProperty(value = "用户id集合")
|
||||
private List<String> userIdList;
|
||||
private String userIds;
|
||||
}
|
||||
|
|
|
@ -1145,8 +1145,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
File tempFile = null;
|
||||
try {
|
||||
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
||||
if(ObjectUtil.isNotEmpty(sysUserExportParam.getUserIdList())) {
|
||||
queryWrapper.lambda().in(SysUser::getId, sysUserExportParam.getUserIdList());
|
||||
if(ObjectUtil.isNotEmpty(sysUserExportParam.getUserIds())) {
|
||||
queryWrapper.lambda().in(SysUser::getId, StrUtil.split(sysUserExportParam.getUserIds(), StrUtil.COMMA));
|
||||
} else {
|
||||
if (ObjectUtil.isNotEmpty(sysUserExportParam.getSearchKey())) {
|
||||
queryWrapper.lambda().like(SysUser::getAccount, sysUserExportParam.getSearchKey())
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue