fix: 用户数据导入

This commit is contained in:
TsMask
2023-10-27 09:48:53 +08:00
parent a010b7f284
commit 1e1264cee4
3 changed files with 26 additions and 24 deletions

View File

@@ -400,10 +400,11 @@ func (s *SysUserController) Export(c *gin.Context) {
"E1": "手机号码",
"F1": "用户性别",
"G1": "帐号状态",
"H1": "最后登录IP",
"I1": "最后登录时间",
"J1": "部门名称",
"K1": "部门负责人",
"H1": "部门编号",
"I1": "部门名称",
"J1": "部门负责人",
"K1": "最后登录IP",
"L1": "最后登录时间",
}
// 读取用户性别字典数据
dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
@@ -432,10 +433,11 @@ func (s *SysUserController) Export(c *gin.Context) {
"E" + idx: row.PhoneNumber,
"F" + idx: sysUserSex,
"G" + idx: statusValue,
"H" + idx: row.LoginIP,
"I" + idx: date.ParseDateToStr(row.LoginDate, date.YYYY_MM_DD_HH_MM_SS),
"J" + idx: row.Dept.DeptName,
"K" + idx: row.Dept.Leader,
"H" + idx: row.Dept.DeptID,
"I" + idx: row.Dept.DeptName,
"J" + idx: row.Dept.Leader,
"K" + idx: row.LoginIP,
"L" + idx: date.ParseDateToStr(row.LoginDate, date.YYYY_MM_DD_HH_MM_SS),
})
}

View File

@@ -198,7 +198,7 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
failureNum := 0
successMsgArr := []string{}
failureMsgArr := []string{}
mustItemArr := []string{"C", "D"}
mustItemArr := []string{"B", "C"}
for _, row := range rows {
// 检查必填列
ownItem := true
@@ -218,13 +218,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
// 用户性别转值
sysUserSex := "0"
for _, v := range dictSysUserSex {
if row["G"] == v.DictLabel {
if row["F"] == v.DictLabel {
sysUserSex = v.DictValue
break
}
}
sysUserStatus := common.STATUS_NO
if row["H"] == "正常" {
if row["G"] == "正常" {
sysUserStatus = common.STATUS_YES
}
@@ -232,11 +232,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser := model.SysUser{
UserType: "sys",
Password: initPassword,
DeptID: row["B"],
UserName: row["C"],
NickName: row["D"],
PhoneNumber: row["F"],
Email: row["E"],
DeptID: row["H"],
UserName: row["B"],
NickName: row["C"],
PhoneNumber: row["E"],
Email: row["D"],
Status: sysUserStatus,
Sex: sysUserSex,
}
@@ -246,13 +246,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidMobile(newSysUser.PhoneNumber) {
uniquePhone := r.CheckUniquePhone(newSysUser.PhoneNumber, "")
if !uniquePhone {
msg := fmt.Sprintf("序号:%s 手机号码 %s 已存在", row["A"], row["F"])
msg := fmt.Sprintf("序号:%s 手机号码 %s 已存在", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("序号:%s 手机号码 %s 格式错误", row["A"], row["F"])
msg := fmt.Sprintf("序号:%s 手机号码 %s 格式错误", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -264,13 +264,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidEmail(newSysUser.Email) {
uniqueEmail := r.CheckUniqueEmail(newSysUser.Email, "")
if !uniqueEmail {
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 已存在", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 已存在", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 格式错误", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 用户邮箱 %s 格式错误", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -283,11 +283,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.CreateBy = operName
insertId := r.InsertUser(newSysUser)
if insertId != "" {
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入成功", row["A"], row["C"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入成功", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入失败", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 导入失败", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}
@@ -300,11 +300,11 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.UpdateBy = operName
rows := r.UpdateUser(newSysUser)
if rows > 0 {
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新成功", row["A"], row["C"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新成功", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新失败", row["A"], row["E"])
msg := fmt.Sprintf("序号:%s 登录名称 %s 更新失败", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}