You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package SysLoginpersonService
import (
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonDao"
"dsBaseRpc/Utils/CommonUtil"
"dsBaseRpc/Utils/DbUtil"
"dsBaseRpc/Utils/LdapUtil"
"dsBaseRpc/models"
"time"
)
/**
功能:为指定身份的人员,批量生成账号
描述:生成登录账号 1:管理员2教师3学生4: 家长
作者:黄海
时间2020-05-30
*/
type LoginAccount struct {
LoginName string //登录名
Pwd string //密码支持ldap
OriginalPwd string //初始密码
}
func GenerateLoginAccount(identityId int32, count int64) []LoginAccount {
var loginPrefix = ""
switch identityId {
case 1:
loginPrefix = "sys"
break
case 2:
loginPrefix = "tea"
break
case 3:
loginPrefix = "stu"
break
case 4:
loginPrefix = "par"
break
}
//获取最大人员编号
loginIdInt := SysLoginpersonDao.GetLoginIdIntMax(count)
//循环生成
result := make([]LoginAccount, 0)
for i := 0; i < int(count); i++ {
var loginAccount LoginAccount
loginAccount.LoginName = loginPrefix +
CommonUtil.ConvertInt64ToString(CommonUtil.ConvertIntToInt64(i)+loginIdInt-count+1)
//休眠2毫秒使随机数不一样
time.Sleep(2 * time.Microsecond)
loginAccount.OriginalPwd = CommonUtil.GenValidateCode(6)
loginAccount.Pwd = LdapUtil.GetLdapPassword(loginAccount.OriginalPwd)
result = append(result, loginAccount)
}
return result
}
//增加登录人员
func AddLoginperson(identityId int32, personId string, personName string) (int64, error) {
//生成登录名和密码
accountArray := GenerateLoginAccount(identityId, 1)
//调用dao
model := new(models.TSysLoginperson)
model.Id = CommonUtil.GetUUID()
model.LoginName = accountArray[0].LoginName
model.Pwd = accountArray[0].Pwd
model.OriginalPwd = accountArray[0].OriginalPwd
//不管是不是管理员还是普通教师、学生都是先有实体数据即t_base_teacher或t_base_student,t_base_parent三张表中存在了数据
//有了person_id,然后再来添加登录账号,所以person_id是肯定有的不用这里现生成.
model.IdentityId = identityId
model.PersonId = personId
model.PersonName = personName
model.BUse = 1
var db = DbUtil.Engine
var session = db.NewSession()
count, err := SysLoginpersonDao.AddSysLoginPerson(session, *model)
return count, err
}
/**
功能传入一个列表判断密码是不是修改过了扩展change_pwd列,通过Golang的指针进行修改
作者:黄海
时间2020-06-05
*/
func FillPwdIsChange(list2 *[]map[string]interface{}) {
list := *list2
for i := range list {
if list[i]["login_b_use"].(int64) == 1 {
list[i]["login_status"] = "已启用"
} else {
list[i]["login_status"] = "已禁用"
}
if list[i]["pwd"].(string) != LdapUtil.GetLdapPassword(list[i]["original_pwd"].(string)) {
list[i]["original_pwd"] = "用户已修改"
}
//移除pwd
delete(list[i], "pwd")
delete(list[i], "login_b_use")
}
}