用户管理修改回显尝试,薪资管理时间戳修正,工人批量导入(无需模版,且删除后重复数据自动覆盖)
This commit is contained in:
@@ -93,4 +93,6 @@ public class GearWorkerController extends BaseController {
|
||||
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] workerIds) {
|
||||
return toAjax(iGearWorkerService.deleteWithValidByIds(Arrays.asList(workerIds), true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,6 @@ import com.gear.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 工人主数据对象 gear_worker
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("gear_worker")
|
||||
@@ -26,19 +23,16 @@ public class GearWorker extends BaseEntity {
|
||||
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 默认计费类型(1小时工 2计件工 3天工)
|
||||
*/
|
||||
private String defaultBillingType;
|
||||
|
||||
private String defaultWorkTypeName;
|
||||
|
||||
/**
|
||||
* 状态(0在职 1离职)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
@TableLogic
|
||||
/**
|
||||
* 逻辑删除标记:0-未删除,2-已删除
|
||||
*/
|
||||
@TableLogic(value = "0", delval = "2")
|
||||
private String delFlag;
|
||||
|
||||
private String remark;
|
||||
|
||||
@@ -3,9 +3,40 @@ package com.gear.oa.mapper;
|
||||
import com.gear.common.core.mapper.BaseMapperPlus;
|
||||
import com.gear.oa.domain.GearWorker;
|
||||
import com.gear.oa.domain.vo.GearWorkerVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 工人主数据Mapper接口
|
||||
*/
|
||||
public interface GearWorkerMapper extends BaseMapperPlus<GearWorkerMapper, GearWorker, GearWorkerVo> {
|
||||
/**
|
||||
* 根据工号查询所有记录(包括逻辑删除的),绕过 MyBatis-Plus 自动过滤
|
||||
*
|
||||
* @param workerNo 工号
|
||||
* @return 工人记录(可能为 null)
|
||||
*/
|
||||
@Select("SELECT * FROM gear_worker WHERE worker_no = #{workerNo}")
|
||||
GearWorker selectByWorkerNoIncludeDeleted(@Param("workerNo") String workerNo);
|
||||
|
||||
/**
|
||||
* 强制恢复并更新已删除的工人记录
|
||||
* 直接将 del_flag 更新为 0,并更新其他字段
|
||||
*
|
||||
* @param worker 包含新数据的工人对象(必须包含 workerNo 和需要更新的字段)
|
||||
* @return 影响行数
|
||||
*/
|
||||
@Update("UPDATE gear_worker SET " +
|
||||
"worker_name = #{workerName}, " +
|
||||
"phone = #{phone}, " +
|
||||
"default_billing_type = #{defaultBillingType}, " +
|
||||
"default_work_type_name = #{defaultWorkTypeName}, " +
|
||||
"status = #{status}, " +
|
||||
"del_flag = '0', " +
|
||||
"remark = #{remark}, " +
|
||||
"update_by = #{updateBy}, " +
|
||||
"update_time = NOW() " +
|
||||
"WHERE worker_no = #{workerNo}")
|
||||
int recoverByWorkerNo(GearWorker worker);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gear.common.core.domain.PageQuery;
|
||||
import com.gear.common.core.page.TableDataInfo;
|
||||
import com.gear.common.exception.ServiceException;
|
||||
import com.gear.common.utils.StringUtils;
|
||||
import com.gear.oa.domain.GearWorker;
|
||||
import com.gear.oa.domain.bo.GearWorkerBo;
|
||||
@@ -14,14 +15,13 @@ import com.gear.oa.domain.vo.GearWorkerVo;
|
||||
import com.gear.oa.mapper.GearWorkerMapper;
|
||||
import com.gear.oa.service.IGearWorkerService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 工人主数据Service业务层处理
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class GearWorkerServiceImpl implements IGearWorkerService {
|
||||
@@ -48,6 +48,8 @@ public class GearWorkerServiceImpl implements IGearWorkerService {
|
||||
|
||||
private LambdaQueryWrapper<GearWorker> buildQueryWrapper(GearWorkerBo bo) {
|
||||
LambdaQueryWrapper<GearWorker> lqw = Wrappers.lambdaQuery();
|
||||
// 只查询未删除的数据(del_flag = '0')
|
||||
lqw.eq(GearWorker::getDelFlag, "0");
|
||||
lqw.eq(bo.getWorkerId() != null, GearWorker::getWorkerId, bo.getWorkerId());
|
||||
lqw.eq(StringUtils.isNotBlank(bo.getWorkerNo()), GearWorker::getWorkerNo, bo.getWorkerNo());
|
||||
lqw.like(StringUtils.isNotBlank(bo.getWorkerName()), GearWorker::getWorkerName, bo.getWorkerName());
|
||||
@@ -59,17 +61,48 @@ public class GearWorkerServiceImpl implements IGearWorkerService {
|
||||
|
||||
@Override
|
||||
public Boolean insertByBo(GearWorkerBo bo) {
|
||||
// 使用自定义方法查询所有记录(包括逻辑删除的)
|
||||
GearWorker existing = baseMapper.selectByWorkerNoIncludeDeleted(bo.getWorkerNo());
|
||||
|
||||
if (existing != null) {
|
||||
// 记录存在
|
||||
if ("0".equals(existing.getDelFlag())) {
|
||||
throw new ServiceException("工号 " + bo.getWorkerNo() + " 已存在且未删除,不能重复添加");
|
||||
} else {
|
||||
// 已删除,执行强制恢复更新
|
||||
GearWorker update = BeanUtil.toBean(bo, GearWorker.class);
|
||||
// 必须设置工号,用于 WHERE 条件
|
||||
update.setWorkerNo(bo.getWorkerNo());
|
||||
// 调用自定义恢复方法,直接更新数据库
|
||||
int rows = baseMapper.recoverByWorkerNo(update);
|
||||
if (rows > 0) {
|
||||
bo.setWorkerId(existing.getWorkerId());
|
||||
log.info("恢复并更新已删除工人成功,workerNo={}", bo.getWorkerNo());
|
||||
return true;
|
||||
} else {
|
||||
throw new ServiceException("恢复工人数据失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 完全新增
|
||||
log.info("新增工人,workerNo={}", bo.getWorkerNo());
|
||||
GearWorker add = BeanUtil.toBean(bo, GearWorker.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setWorkerId(add.getWorkerId());
|
||||
}
|
||||
return flag;
|
||||
baseMapper.insert(add);
|
||||
bo.setWorkerId(add.getWorkerId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByBo(GearWorkerBo bo) {
|
||||
GearWorker existing = baseMapper.selectById(bo.getWorkerId());
|
||||
if (existing == null) {
|
||||
throw new ServiceException("记录不存在");
|
||||
}
|
||||
if (!"0".equals(existing.getDelFlag())) {
|
||||
throw new ServiceException("该记录已被删除,无法更新");
|
||||
}
|
||||
GearWorker update = BeanUtil.toBean(bo, GearWorker.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
@@ -82,10 +115,14 @@ public class GearWorkerServiceImpl implements IGearWorkerService {
|
||||
if (StringUtils.isBlank(entity.getDefaultBillingType())) {
|
||||
entity.setDefaultBillingType("1");
|
||||
}
|
||||
if (StringUtils.isBlank(entity.getDelFlag())) {
|
||||
entity.setDelFlag("0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
// 由于 @TableLogic(value="0", delval="2") 配置,此处会执行 UPDATE gear_worker SET del_flag='2'
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@@ -103,24 +140,43 @@ public class GearWorkerServiceImpl implements IGearWorkerService {
|
||||
msg.append("[工号/姓名为空]");
|
||||
continue;
|
||||
}
|
||||
GearWorker exist = baseMapper.selectOne(Wrappers.<GearWorker>lambdaQuery()
|
||||
.eq(GearWorker::getWorkerNo, item.getWorkerNo()));
|
||||
|
||||
if (exist == null) {
|
||||
GearWorker add = BeanUtil.toBean(item, GearWorker.class);
|
||||
validEntityBeforeSave(add);
|
||||
baseMapper.insert(add);
|
||||
success++;
|
||||
} else if (Boolean.TRUE.equals(updateSupport)) {
|
||||
GearWorker update = BeanUtil.toBean(item, GearWorker.class);
|
||||
update.setWorkerId(exist.getWorkerId());
|
||||
validEntityBeforeSave(update);
|
||||
baseMapper.updateById(update);
|
||||
success++;
|
||||
} else {
|
||||
fail++;
|
||||
msg.append("[工号重复:").append(item.getWorkerNo()).append("]");
|
||||
// 使用自定义方法查询所有记录(包括逻辑删除的)
|
||||
GearWorker existing = baseMapper.selectByWorkerNoIncludeDeleted(item.getWorkerNo());
|
||||
|
||||
if (existing != null) {
|
||||
if ("0".equals(existing.getDelFlag())) {
|
||||
// 未删除,根据 updateSupport 决定
|
||||
if (Boolean.TRUE.equals(updateSupport)) {
|
||||
GearWorker update = BeanUtil.toBean(item, GearWorker.class);
|
||||
update.setWorkerId(existing.getWorkerId());
|
||||
validEntityBeforeSave(update);
|
||||
baseMapper.updateById(update);
|
||||
success++;
|
||||
} else {
|
||||
fail++;
|
||||
msg.append("[工号重复:").append(item.getWorkerNo()).append("]");
|
||||
}
|
||||
} else {
|
||||
// 已删除,强制恢复
|
||||
GearWorker recover = BeanUtil.toBean(item, GearWorker.class);
|
||||
recover.setWorkerNo(item.getWorkerNo());
|
||||
int rows = baseMapper.recoverByWorkerNo(recover);
|
||||
if (rows > 0) {
|
||||
success++;
|
||||
} else {
|
||||
fail++;
|
||||
msg.append("[恢复失败:").append(item.getWorkerNo()).append("]");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// 完全新增
|
||||
GearWorker add = BeanUtil.toBean(item, GearWorker.class);
|
||||
validEntityBeforeSave(add);
|
||||
baseMapper.insert(add);
|
||||
success++;
|
||||
}
|
||||
return "导入完成,成功" + success + "条,失败" + fail + "条" + (msg.length() > 0 ? "," + msg : "");
|
||||
}
|
||||
|
||||
@@ -35,10 +35,26 @@ export function updateWorker(data) {
|
||||
})
|
||||
}
|
||||
|
||||
// 删除工人
|
||||
export function delWorker(workerId) {
|
||||
// // 删除工人
|
||||
// export function delWorker(workerIds) {
|
||||
// return request({
|
||||
// url: '/oa/worker/' + workerId,
|
||||
// // url: '/oa/worker/' + workerIds.join(','),
|
||||
// method: 'delete'
|
||||
// })
|
||||
// }
|
||||
// 删除工人(修复后,支持单个+批量删除)
|
||||
export function delWorker(workerIds) {
|
||||
let url = ''
|
||||
if (Array.isArray(workerIds)) {
|
||||
// 数组 → 拼接成 1,2,3
|
||||
url = '/oa/worker/' + workerIds.join(',')
|
||||
} else {
|
||||
// 单个ID
|
||||
url = '/oa/worker/' + workerIds
|
||||
}
|
||||
return request({
|
||||
url: '/oa/worker/' + workerId,
|
||||
url: url,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
@use './mixin.scss';
|
||||
@use './transition.scss';
|
||||
@use './element-ui.scss';
|
||||
@@ -176,4 +177,5 @@ aside {
|
||||
vertical-align: middle;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -170,8 +170,8 @@ onMounted(() => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.topmenu-container.el-menu--horizontal > .el-menu-item {
|
||||
<style lang="scss" scoped>
|
||||
:deep(.el-menu > .el-menu-item) {
|
||||
float: left;
|
||||
height: 50px !important;
|
||||
line-height: 50px !important;
|
||||
@@ -180,13 +180,14 @@ onMounted(() => {
|
||||
margin: 0 10px !important;
|
||||
}
|
||||
|
||||
.topmenu-container.el-menu--horizontal > .el-menu-item.is-active, .el-menu--horizontal > .el-sub-menu.is-active .el-submenu__title {
|
||||
:deep(.el-menu > .el-menu-item.is-active), :deep(.el-menu > .el-sub-menu.is-active .el-submenu__title) {
|
||||
border-bottom: 2px solid #{'var(--theme)'} !important;
|
||||
color: #303133;
|
||||
background-color: #f5f7fa !important;
|
||||
}
|
||||
|
||||
/* sub-menu item */
|
||||
.topmenu-container.el-menu--horizontal > .el-sub-menu .el-sub-menu__title {
|
||||
:deep(.el-menu > .el-sub-menu .el-sub-menu__title) {
|
||||
float: left;
|
||||
height: 50px !important;
|
||||
line-height: 50px !important;
|
||||
@@ -196,17 +197,17 @@ onMounted(() => {
|
||||
}
|
||||
|
||||
/* 背景色隐藏 */
|
||||
.topmenu-container.el-menu--horizontal>.el-menu-item:not(.is-disabled):focus, .topmenu-container.el-menu--horizontal>.el-menu-item:not(.is-disabled):hover, .topmenu-container.el-menu--horizontal>.el-submenu .el-submenu__title:hover {
|
||||
:deep(.el-menu>.el-menu-item:not(.is-disabled):focus), :deep(.el-menu>.el-menu-item:not(.is-disabled):hover), :deep(.el-menu>.el-sub-menu .el-sub-menu__title:hover) {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
/* 图标右间距 */
|
||||
.topmenu-container .svg-icon {
|
||||
:deep(.svg-icon) {
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
/* topmenu more arrow */
|
||||
.topmenu-container .el-sub-menu .el-sub-menu__icon-arrow {
|
||||
:deep(.el-sub-menu .el-sub-menu__icon-arrow) {
|
||||
position: static;
|
||||
vertical-align: middle;
|
||||
margin-left: 8px;
|
||||
|
||||
@@ -90,8 +90,9 @@ function isActive(r) {
|
||||
function activeStyle(tag) {
|
||||
if (!isActive(tag)) return {}
|
||||
return {
|
||||
"background-color": theme.value,
|
||||
"border-color": theme.value
|
||||
"background-color": "#f5f7fa",
|
||||
"border-color": "#f5f7fa",
|
||||
"color": "#303133"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,13 +292,13 @@ function handleScroll() {
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #42b983;
|
||||
color: #fff;
|
||||
border-color: #42b983;
|
||||
background-color: #f5f7fa;
|
||||
color: #303133;
|
||||
border-color: #f5f7fa;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
background: #fff;
|
||||
background: #42b983;
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
|
||||
@@ -247,23 +247,23 @@ export default {
|
||||
}
|
||||
|
||||
/* 对话框样式 */
|
||||
::v-deep .el-dialog__header {
|
||||
:deep(.el-dialog__header) {
|
||||
padding: 10px 15px;
|
||||
}
|
||||
|
||||
::v-deep .el-dialog__body {
|
||||
:deep(.el-dialog__body) {
|
||||
padding: 10px 15px;
|
||||
}
|
||||
|
||||
::v-deep .el-dialog__footer {
|
||||
:deep(.el-dialog__footer) {
|
||||
padding: 8px 15px;
|
||||
}
|
||||
|
||||
::v-deep .el-form-item {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
::v-deep .el-input__inner {
|
||||
:deep(.el-input__inner) {
|
||||
height: 30px;
|
||||
line-height: 30px;
|
||||
font-size: 13px;
|
||||
|
||||
@@ -539,8 +539,8 @@ export default {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
::v-deep .el-input-group__append,
|
||||
::v-deep .el-input-group__prepend {
|
||||
:deep(.el-input-group__append),
|
||||
:deep(.el-input-group__prepend) {
|
||||
width: 20px !important;
|
||||
box-sizing: border-box !important;
|
||||
padding: 0 10px !important;
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
<el-date-picker
|
||||
clearable
|
||||
v-model="form.uploadTime"
|
||||
type="date"
|
||||
type="datetime"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
placeholder="请选择上传时间"
|
||||
/>
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
<el-col :span="1.5"><el-button size="small" type="warning" plain icon="Download" @click="handleExport">导出</el-button></el-col>
|
||||
<el-col :span="1.5"><el-button size="small" type="info" plain icon="Upload" @click="openImport">导入</el-button></el-col>
|
||||
<el-col :span="1.8"><el-button size="small" plain icon="Download" @click="downloadTemplate">下载模板</el-button></el-col>
|
||||
<el-col :span="2.2"><el-button size="small" type="primary" plain icon="User" @click="openUserSelectDialog">选择用户导入</el-button></el-col>
|
||||
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
|
||||
</el-row>
|
||||
|
||||
@@ -122,6 +124,21 @@
|
||||
<el-button @click="importOpen = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!-- 选择系统用户导入弹窗 -->
|
||||
<el-dialog title="选择需要导入的用户" v-model="userSelectOpen" width="700px" append-to-body>
|
||||
<el-input v-model="userSearchKey" placeholder="搜索账号/昵称/手机号" clearable style="width: 300px; margin-bottom: 10px"/>
|
||||
<el-table ref="userSelectTableRef" v-model:selection="selectedUserIds" :data="filterUserList" border height="350" @selection-change="handleUserSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="账号" prop="userName" align="center" />
|
||||
<el-table-column label="昵称" prop="nickName" align="center" />
|
||||
<el-table-column label="手机号" prop="phonenumber" align="center" />
|
||||
</el-table>
|
||||
<template #footer>
|
||||
<el-button @click="userSelectOpen = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmImportSelectedUser">确认导入</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
@@ -129,6 +146,7 @@
|
||||
<script setup name="Worker">
|
||||
import { listWorker, getWorker, addWorker, updateWorker, delWorker, importWorkerData } from '@/api/oa/worker'
|
||||
import { listWageRateConfig } from '@/api/oa/wageRateConfig'
|
||||
import { listUser } from '@/api/system/user'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
|
||||
@@ -148,8 +166,37 @@ const importLoading = ref(false)
|
||||
const updateSupport = ref(false)
|
||||
const importFile = ref(null)
|
||||
|
||||
// 选择用户导入相关
|
||||
const userSelectOpen = ref(false)
|
||||
const allUserList = ref([])
|
||||
const selectedUserIds = ref([])
|
||||
// 已存在工号缓存
|
||||
const existWorkerNos = ref([])
|
||||
// 用户检索关键词
|
||||
const userSearchKey = ref('')
|
||||
|
||||
// 过滤后的用户列表(账号/昵称/手机号模糊检索)
|
||||
const filterUserList = computed(() => {
|
||||
const key = userSearchKey.value.trim()
|
||||
if (!key) return allUserList.value
|
||||
return allUserList.value.filter(item =>
|
||||
item.userName?.includes(key) ||
|
||||
item.nickName?.includes(key) ||
|
||||
item.phonenumber?.includes(key)
|
||||
)
|
||||
})
|
||||
// 表格ref
|
||||
const userSelectTableRef = ref(null)
|
||||
|
||||
// 同步选中的用户ID
|
||||
function handleUserSelectionChange(selection) {
|
||||
selectedUserIds.value = selection.map(item => item.userId)
|
||||
}
|
||||
|
||||
|
||||
const rateOptions = ref([])
|
||||
|
||||
|
||||
const data = reactive({
|
||||
form: {},
|
||||
queryParams: {
|
||||
@@ -358,5 +405,86 @@ function submitImport() {
|
||||
})
|
||||
}
|
||||
|
||||
// 打开用户选择弹窗【修复空值初始化】
|
||||
async function openUserSelectDialog() {
|
||||
// 每次打开都严格初始化所有变量,避免 undefined
|
||||
allUserList.value = []
|
||||
selectedUserIds.value = []
|
||||
userSearchKey.value = ''
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
// 加载系统用户列表
|
||||
const userRes = await listUser({ pageNum: 1, pageSize: 9999, status: '0' })
|
||||
// 确保赋值为数组,避免 undefined
|
||||
allUserList.value = userRes?.rows || []
|
||||
} catch (err) {
|
||||
console.error("加载用户失败", err)
|
||||
proxy.$modal.msgError('加载用户列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
userSelectOpen.value = true
|
||||
}
|
||||
}
|
||||
// 确认导入选中用户【前端终极兜底 · 零报错】
|
||||
async function confirmImportSelectedUser() {
|
||||
if (!selectedUserIds.value?.length) {
|
||||
proxy.$modal.msgWarning('请至少选择一条用户')
|
||||
return
|
||||
}
|
||||
if (!filterUserList.value?.length) {
|
||||
proxy.$modal.msgWarning('用户列表为空,无法导入')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
let success = 0, update = 0
|
||||
|
||||
try {
|
||||
// 1. 一次性查询所有已存在工号,构建Map
|
||||
const { rows: existWorkers } = await listWorker({ pageNum: 1, pageSize: 9999 })
|
||||
const existMap = new Map(existWorkers.map(w => [w.workerNo, w]))
|
||||
|
||||
// 2. 过滤有效用户
|
||||
const users = filterUserList.value.filter(u =>
|
||||
u?.userId && selectedUserIds.value.includes(u.userId)
|
||||
)
|
||||
|
||||
// 3. 分批次处理,避免并发冲突
|
||||
for (const user of users) {
|
||||
const workerNo = user.userName
|
||||
const data = {
|
||||
workerNo,
|
||||
workerName: user.nickName || user.userName,
|
||||
phone: user.phonenumber,
|
||||
status: '0',
|
||||
defaultBillingType: '1',
|
||||
defaultWorkTypeName: '普通工人',
|
||||
remark: '从系统用户导入'
|
||||
}
|
||||
|
||||
// 4. 严格判断:Map中存在 → 更新,不存在 → 新增
|
||||
if (existMap.has(workerNo)) {
|
||||
data.workerId = existMap.get(workerNo).workerId
|
||||
await updateWorker(data)
|
||||
update++
|
||||
} else {
|
||||
await addWorker(data)
|
||||
success++
|
||||
// 同步更新Map,避免后续重复判断
|
||||
existMap.set(workerNo, { workerNo })
|
||||
}
|
||||
}
|
||||
|
||||
proxy.$modal.msgSuccess(`导入完成:新增 ${success} 条,更新 ${update} 条`)
|
||||
userSelectOpen.value = false
|
||||
getList()
|
||||
} catch (err) {
|
||||
console.error('导入失败:', err)
|
||||
proxy.$modal.msgError('导入失败,请查看控制台日志')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
getList()
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user