|
|
package SysLoginpersonService
|
|
|
|
|
|
import (
|
|
|
"dsBaseRpc/RpcService/SysLoginperson/SysLoginpersonDao"
|
|
|
"dsBaseRpc/Utils/CommonUtil"
|
|
|
"dsBaseRpc/Utils/LdapUtil"
|
|
|
"dsBaseRpc/models"
|
|
|
"github.com/xormplus/xorm"
|
|
|
"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(session *xorm.Session, 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
|
|
|
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")
|
|
|
}
|
|
|
}
|