1232 lines
31 KiB
Go
1232 lines
31 KiB
Go
|
package account
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
"dubbo.apache.org/dubbo-go/v3/common/constant"
|
|||
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
|||
|
"encoding/json"
|
|||
|
"errors"
|
|||
|
"fmt"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/account"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/department"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/position"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/api/rule"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/config"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/logic/auth"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/query"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/union"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/vo"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/vo/turnstile"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/vo/v2/user"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/serializer"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
|||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/secret"
|
|||
|
"github.com/fonchain_enterprise/utils/utils"
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
"github.com/gin-gonic/gin/binding"
|
|||
|
"unicode/utf8"
|
|||
|
)
|
|||
|
|
|||
|
// UserRegisterV2 用户注册操作
|
|||
|
func UserRegisterV2(c *gin.Context) {
|
|||
|
var req query.User
|
|||
|
var res *account.RequestStatus
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.Password == "" {
|
|||
|
req.Password = e.DEFAULT_PWD
|
|||
|
}
|
|||
|
|
|||
|
err, res := UserRegistersV2(c, req) //注册
|
|||
|
|
|||
|
if err != nil {
|
|||
|
|
|||
|
if err.Error() == "账号已存在" {
|
|||
|
service.Error(c, e.InvalidParams, errors.New("该手机号已存在,请检查此人是否在其他部门"))
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, res)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//UserLoginSqueezeOther 检测相同帐号的状态
|
|||
|
|
|||
|
// UserLoginSqueezeOther 用户登录操作
|
|||
|
func UserLoginSqueezeOther(c *gin.Context) {
|
|||
|
|
|||
|
var jumpToWhere = "setting"
|
|||
|
var isDriverAuth = false
|
|||
|
var isDriverSupervisorAuth = false
|
|||
|
|
|||
|
var req account.LoginRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
req.Ip = c.ClientIP()
|
|||
|
req.From = ""
|
|||
|
|
|||
|
isAuth, err := isOnlySiteAuth(c, req.TelNum)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
var res *account.TokenInfo
|
|||
|
if isAuth == true { //没有唯一登录的权限
|
|||
|
req.From = e.LoginFromPC
|
|||
|
res, err = service.AccountProvider.LoginAndSqueezeOther(c, &req)
|
|||
|
} else { //老登陆
|
|||
|
res, err = service.AccountProvider.Login(c, &req)
|
|||
|
}
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//获取用户的岗位信息
|
|||
|
uReq := rule.RulesRequest{
|
|||
|
AccountID: res.AccountInfo.ID,
|
|||
|
}
|
|||
|
|
|||
|
qres, err1 := service.RuleProvider.UserInfo(c, &uReq)
|
|||
|
|
|||
|
if err1 != nil {
|
|||
|
service.Error(c, e.Error, err1)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if len(qres.PositionUsers) >= 1 {
|
|||
|
isDriverAuth = isHaveDriverAuth(c, res.AccountInfo.ID, qres.PositionUsers[0].DepartmentId)
|
|||
|
isDriverSupervisorAuth = isHaveDriverSupervisorAuth(c, res.AccountInfo.ID, qres.PositionUsers[0].DepartmentId)
|
|||
|
}
|
|||
|
|
|||
|
accountInfo := &union.AccountInfo{
|
|||
|
ID: res.AccountInfo.ID,
|
|||
|
Account: res.AccountInfo.Account,
|
|||
|
NickName: res.AccountInfo.NickName,
|
|||
|
Domain: res.AccountInfo.Domain,
|
|||
|
TelNum: res.AccountInfo.TelNum,
|
|||
|
Status: res.AccountInfo.Status,
|
|||
|
Avatar: res.AccountInfo.Avatar,
|
|||
|
CreatedAt: res.AccountInfo.CreateAt,
|
|||
|
IsNeedChange: res.AccountInfo.IsNeedChange,
|
|||
|
EnterDate: res.AccountInfo.EnterDate,
|
|||
|
WorkYear: res.AccountInfo.WorkYear,
|
|||
|
IsAdmin: qres.IsAdmin,
|
|||
|
PositionUsers: qres.PositionUsers,
|
|||
|
JumpTo: res.AccountInfo.Extend.JumpTo,
|
|||
|
DepartmentName: "",
|
|||
|
JobNum: res.AccountInfo.JobNum,
|
|||
|
BirthDate: res.AccountInfo.BirthDate,
|
|||
|
Age: res.AccountInfo.Age,
|
|||
|
Sex: res.AccountInfo.Sex,
|
|||
|
Title: res.AccountInfo.Title,
|
|||
|
IDNum: res.AccountInfo.IDNum,
|
|||
|
DriverAuth: isDriverAuth,
|
|||
|
DriverSupervisorAuth: isDriverSupervisorAuth,
|
|||
|
MailAccount: res.AccountInfo.MailAccount,
|
|||
|
Train: res.AccountInfo.Train,
|
|||
|
Certificate: res.AccountInfo.Certificate,
|
|||
|
TrainVideos: res.AccountInfo.TrainVideos,
|
|||
|
}
|
|||
|
|
|||
|
code := "xxx"
|
|||
|
if len(qres.PositionUsers) >= 1 {
|
|||
|
accountInfo.DepartmentName = qres.PositionUsers[0].DepartmentName
|
|||
|
code = secret.GetPositionCode(qres.PositionUsers[0].PositionName)
|
|||
|
}
|
|||
|
|
|||
|
token, err := secret.CombineSecret(code, accountInfo.DepartmentName, res.Token)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
ruleUrlReq := rule.FindRuleByUrlRequest{
|
|||
|
AccountID: accountInfo.ID,
|
|||
|
Type: "menu",
|
|||
|
Domain: accountInfo.Domain,
|
|||
|
Url: "/home",
|
|||
|
Method: "*",
|
|||
|
}
|
|||
|
|
|||
|
ruleInfo, ruleErr := service.RuleProvider.FindUserRule(c, &ruleUrlReq)
|
|||
|
if ruleInfo.IsPass == true {
|
|||
|
jumpToWhere = "home"
|
|||
|
}
|
|||
|
|
|||
|
if ruleErr != nil {
|
|||
|
service.Error(c, e.Error, ruleErr)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
resInfo := &union.Login{
|
|||
|
Token: token,
|
|||
|
RefreshToken: res.RefreshToken,
|
|||
|
AccountInfo: accountInfo,
|
|||
|
JumpToWhere: jumpToWhere,
|
|||
|
}
|
|||
|
|
|||
|
fmt.Println("是否相同:", res.IsSampleAddress, res.AccountInfo.NowLogId)
|
|||
|
if res.IsSampleAddress == false && res.AccountInfo.NowLogId != 0 { //登陆地址异常
|
|||
|
|
|||
|
url := fmt.Sprintf("https://erpapi.fontree.cn/off7524164487E?id=%d", res.AccountInfo.NowLogId)
|
|||
|
shortUrl, err := utils.CreateShortUrl(url)
|
|||
|
if err == nil {
|
|||
|
url = shortUrl
|
|||
|
}
|
|||
|
|
|||
|
msgReq := account.SendCustomMsgRequest{
|
|||
|
ID: res.AccountInfo.ID,
|
|||
|
TelNum: res.AccountInfo.TelNum,
|
|||
|
MId: 134802,
|
|||
|
SigNo: uint32(config.DefaultSignNo),
|
|||
|
}
|
|||
|
|
|||
|
msgReq.Url = res.NowAddress + "|" + url
|
|||
|
fmt.Println("发送短信", msgReq)
|
|||
|
service.AccountProvider.SendCustomMsg(c, &msgReq)
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, resInfo)
|
|||
|
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// isOnlySiteAuth 检测相同帐号的状态
|
|||
|
func isOnlySiteAuth(c *gin.Context, tel string) (bool, error) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.SampleAccountRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
return false, err
|
|||
|
}
|
|||
|
|
|||
|
userByTelRes, err := service.AccountProvider.UserByTel(c, &account.UserByTelRequest{Tel: tel})
|
|||
|
if err != nil {
|
|||
|
return false, err
|
|||
|
}
|
|||
|
|
|||
|
if userByTelRes == nil || userByTelRes.IsExist == false {
|
|||
|
return false, errors.New(e.ErrAccountNotExist)
|
|||
|
}
|
|||
|
|
|||
|
if isHaveAuth(c, userByTelRes.Info.ID, e.AUthOnlySiteLogin, "button") == false {
|
|||
|
return false, nil
|
|||
|
}
|
|||
|
|
|||
|
return true, nil
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// SampleAccount 检测相同帐号的状态
|
|||
|
func SampleAccount(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.SampleAccountRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.TelNum == "" {
|
|||
|
service.Error(c, e.InvalidParams, errors.New("no tel exist!"))
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
req.From = e.LoginFromPC
|
|||
|
|
|||
|
sampleAccountRes := &account.SampleAccountResponse{IsNowAlreadyLogin: false, Num: 0}
|
|||
|
|
|||
|
isAuth, err := isOnlySiteAuth(c, req.TelNum)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if isAuth == true { //没有唯一登录的权限
|
|||
|
sampleAccountRes, err = service.AccountProvider.SampleAccount(context.Background(), &req)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, sampleAccountRes)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// ListV2 列表
|
|||
|
func ListV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.ListV2Request
|
|||
|
var userIds []uint32
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.EndEnterDate != "" {
|
|||
|
req.EndEnterDate += " 23:59:59"
|
|||
|
}
|
|||
|
|
|||
|
response := vo.PageResponseV2{
|
|||
|
Count: 0,
|
|||
|
}
|
|||
|
|
|||
|
res, err := service.AccountProvider.ListV2(context.Background(), &req)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if res.Count <= 0 {
|
|||
|
service.Success(c, response)
|
|||
|
return
|
|||
|
}
|
|||
|
response.Count = res.Count
|
|||
|
|
|||
|
for _, v := range res.Data {
|
|||
|
userIds = append(userIds, uint32(v.ID))
|
|||
|
}
|
|||
|
|
|||
|
//查询部门
|
|||
|
puRequest := &position.UserInfosV2Request{IDs: userIds}
|
|||
|
puRes, err := service.PositionProvider.UserInfosV2(c, puRequest)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.FatherDepartmentId != 0 { //父级节点
|
|||
|
|
|||
|
treeRes, err := auth.GetAllCompanyAuthTree()
|
|||
|
|
|||
|
if err != nil {
|
|||
|
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
nodes := getNowList(treeRes.Nodes, req.FatherDepartmentId)
|
|||
|
fmt.Println("1---------------", nodes, err)
|
|||
|
idsMap := make(map[uint32]struct{}, len(nodes))
|
|||
|
for _, v := range nodes {
|
|||
|
idsMap[v.ID] = struct{}{}
|
|||
|
}
|
|||
|
fmt.Println("1-------------------", idsMap)
|
|||
|
|
|||
|
response.Data, err = serializer.UserV3(res, puRes, req.FatherDepartmentId, idsMap)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
} else {
|
|||
|
response.Data = serializer.UserV2(res, puRes, req.DepartmentId)
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, response)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// CheckBeforeRegister 插入前检测
|
|||
|
func Face(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.IsSamePersonRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
res, err := service.AccountProvider.IsSamePerson(c, &req)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, res)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// CheckBeforeRegister 插入前检测
|
|||
|
func CheckBeforeRegister(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.CheckBeforeRegisterRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
lang := c.Request.Header.Get("Accept-Language")
|
|||
|
tempContext := context.WithValue(c, constant.DubboCtxKey("attachment"), map[string]interface{}{"lang": lang})
|
|||
|
|
|||
|
res, err := service.AccountProvider.CheckBeforeRegister(tempContext, &req)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, res)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// BatchRemoveV2 用户删除
|
|||
|
func BatchRemoveV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req query.BatchRemoves
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for _, v := range req.IDs {
|
|||
|
|
|||
|
_, err := service.AccountProvider.Remove(context.Background(), &account.RemoveRequest{ID: uint64(v)})
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//岗位删除
|
|||
|
positionReq := &position.RemoveUserRequest{
|
|||
|
ID: uint64(v),
|
|||
|
}
|
|||
|
|
|||
|
_, err1 := service.PositionProvider.RemoveUser(c, positionReq)
|
|||
|
if err1 != nil {
|
|||
|
service.Error(c, e.Error, err1)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, struct{}{})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// RemoveV2 用户删除
|
|||
|
func RemoveV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.RemoveRequest
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
_, err := service.AccountProvider.Remove(context.Background(), &req)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//岗位删除
|
|||
|
positionReq := &position.RemoveUserRequest{
|
|||
|
ID: req.ID,
|
|||
|
}
|
|||
|
|
|||
|
_, err1 := service.PositionProvider.RemoveUser(c, positionReq)
|
|||
|
if err1 != nil {
|
|||
|
service.Error(c, e.Error, err1)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, struct{}{})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func InfoV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.InfoRequest
|
|||
|
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
user, err := GetUserInfoById(c, req.ID, req.Domain)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, user)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// ResetPwd 用户更新信息
|
|||
|
func ResetPwd(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req query.BatchRemoves
|
|||
|
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
userInfo, err := login.GetUserInfoFromCV2(c)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.NotLoginRes(c, err.Error())
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for _, k := range req.IDs {
|
|||
|
|
|||
|
var updateReq = account.UpdateRequest{
|
|||
|
ID: uint64(k),
|
|||
|
Password: e.DEFAULT_PWD,
|
|||
|
Operator: &account.Operator{
|
|||
|
ID: uint32(userInfo.ID),
|
|||
|
Name: "重置密码:" + userInfo.NickName,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
_, err := service.AccountProvider.Update(context.Background(), &updateReq)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//账号服务
|
|||
|
service.Success(c, struct{}{})
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// UpdateV2 用户更新信息
|
|||
|
func UpdateV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req query.User
|
|||
|
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.NickName == "" || utf8.RuneCountInString(req.NickName) >= 20 {
|
|||
|
service.Error(c, e.InvalidParams, errors.New(e.GetMsg(e.ErrNickName)))
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
//账号服务
|
|||
|
var updateReq = account.UpdateRequest{
|
|||
|
ID: req.ID,
|
|||
|
NickName: req.NickName,
|
|||
|
Password: req.Password,
|
|||
|
TelNum: req.TelNum,
|
|||
|
Avatar: req.Avatar,
|
|||
|
Status: req.Status,
|
|||
|
EnterDate: req.EnterDate,
|
|||
|
JobNum: req.JobNum,
|
|||
|
BirthDate: req.BirthDate,
|
|||
|
Sex: req.Sex,
|
|||
|
Title: req.Title,
|
|||
|
LeftDate: req.LeftDate,
|
|||
|
RecentImg: req.RecentImg,
|
|||
|
ICNum: req.ICNum,
|
|||
|
Operator: &account.Operator{
|
|||
|
ID: uint32(userInfo.ID),
|
|||
|
Name: "人员管理:" + userInfo.NickName,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
updateReq.Extend = &account.Extend{
|
|||
|
JumpTo: req.Extend.JumpTo,
|
|||
|
Lang: req.Extend.Lang,
|
|||
|
CanScan: req.Extend.CanScan,
|
|||
|
ResolutionRatio: req.Extend.ResolutionRatio,
|
|||
|
}
|
|||
|
|
|||
|
userObj, err := GetUserInfoById(c, req.ID, config.Domain)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
_, err = service.AccountProvider.Update(context.Background(), &updateReq)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
positionReq := getFormPositionReq(req, uint32(req.ID))
|
|||
|
|
|||
|
_, err = service.PositionProvider.BindUserV2(c, positionReq)
|
|||
|
|
|||
|
if req.RecentImg != "" && len(userObj.Clocks) > 0 && (req.RecentImg != userObj.RecentImg || req.NickName !=
|
|||
|
userObj.NickName || req.TelNum != userObj.TelNum || req.ICNum != userObj.ICNum) {
|
|||
|
var dataSet []turnstile.DeviceUserData
|
|||
|
var userId account.ClockUserDeviceBatch
|
|||
|
deviceNums := make(map[string]string)
|
|||
|
for _, i := range userObj.Clocks {
|
|||
|
data := turnstile.DeviceUserData{
|
|||
|
JobNum: userObj.ID,
|
|||
|
RecentImg: req.RecentImg,
|
|||
|
DeviceNum: i.Device.DeviceNum,
|
|||
|
NickName: req.NickName,
|
|||
|
Phone: req.TelNum,
|
|||
|
DeviceName: i.Device.DeviceName,
|
|||
|
IcNum: req.ICNum,
|
|||
|
}
|
|||
|
dataSet = append(dataSet, data)
|
|||
|
}
|
|||
|
for _, i := range userObj.Clocks {
|
|||
|
deviceNums[i.Device.DeviceNum] = i.Device.DeviceName
|
|||
|
}
|
|||
|
//判断设备是否离线
|
|||
|
oline := CheckDeviceIsOnline(deviceNums)
|
|||
|
if oline != "" {
|
|||
|
service.Error(c, e.Error, errors.New(oline))
|
|||
|
return
|
|||
|
}
|
|||
|
//并发下发数据
|
|||
|
err = ConcurrentUpdateDeviceUser(c, dataSet, 10)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
//更新绑定关系
|
|||
|
userId.UserId = userObj.ID
|
|||
|
_, err = service.AccountProvider.UpdateDeviceRelevance(c, &userId)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
service.Success(c, struct{}{})
|
|||
|
}
|
|||
|
|
|||
|
func UserRegistersV2(c *gin.Context, req query.User) (err error, res *account.RequestStatus) {
|
|||
|
if req.Avatar == "" {
|
|||
|
req.Avatar = "https://dci-file-new.bj.bcebos.com/fonchain-main/test/runtime/image/avatar/40/b8ed6fea-6662-416d-8bb3-1fd8a8197061.jpg"
|
|||
|
}
|
|||
|
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
//账号服务
|
|||
|
registRequest := account.RegistRequest{
|
|||
|
Domain: config.Domain,
|
|||
|
NickName: req.NickName,
|
|||
|
TelNum: req.TelNum,
|
|||
|
Password: req.Password,
|
|||
|
JobNum: req.JobNum,
|
|||
|
Status: req.Status,
|
|||
|
Avatar: req.Avatar,
|
|||
|
EnterDate: req.EnterDate,
|
|||
|
LeftDate: req.LeftDate,
|
|||
|
Extend: &account.Extend{JumpTo: "setting"},
|
|||
|
RecentImg: req.RecentImg,
|
|||
|
Source: "",
|
|||
|
Operator: &account.Operator{
|
|||
|
ID: uint32(userInfo.ID),
|
|||
|
Name: userInfo.NickName,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
res, err = service.AccountProvider.Register(c, ®istRequest)
|
|||
|
if err != nil {
|
|||
|
return err, res
|
|||
|
}
|
|||
|
|
|||
|
if len(req.DepPositions) <= 0 {
|
|||
|
return nil, res
|
|||
|
}
|
|||
|
|
|||
|
//if len(req.DepPositions) > 0 && req.PositionUsers[0].DepartmentName != "" && req.PositionUsers[0].PositionName != "" {
|
|||
|
positionReq := getFormPositionReq(req, uint32(res.ID))
|
|||
|
fmt.Println("推送数据positionReq", positionReq)
|
|||
|
s, err := json.Marshal(positionReq)
|
|||
|
fmt.Println("user_list", string(s))
|
|||
|
|
|||
|
_, err = service.PositionProvider.BindUserV2(c, positionReq)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
return err, nil
|
|||
|
}
|
|||
|
|
|||
|
return err, res
|
|||
|
}
|
|||
|
|
|||
|
func getFormPositionDepartmentReqV2(req query.User, userId uint32, controllerDepIds []uint) (*position.BindUserV2Request, error) {
|
|||
|
|
|||
|
departmentIdMap := make(map[uint32]struct{}, len(controllerDepIds))
|
|||
|
|
|||
|
for _, v := range controllerDepIds {
|
|||
|
departmentIdMap[uint32(v)] = struct{}{}
|
|||
|
}
|
|||
|
// 获取老的全部岗位
|
|||
|
oldAllPositionRes, err := service.PositionProvider.UserInfoV2(context.Background(), &position.CreateResponse{ID: uint64(userId)})
|
|||
|
if err != nil {
|
|||
|
return nil, err
|
|||
|
}
|
|||
|
|
|||
|
//岗位服务 绑定岗位
|
|||
|
positionReq := &position.BindUserV2Request{
|
|||
|
Domain: config.Domain,
|
|||
|
UserInfo: &position.UserInfo{
|
|||
|
UserName: req.NickName,
|
|||
|
Avatar: req.Avatar,
|
|||
|
UserID: userId,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
if len(req.DepPositions) > 0 {
|
|||
|
var deps []*position.DepPosition
|
|||
|
for _, v := range req.DepPositions {
|
|||
|
temp := &position.DepPosition{
|
|||
|
ID: uint32(v.ID),
|
|||
|
Name: v.Name,
|
|||
|
IsLeader: v.IsLeader,
|
|||
|
}
|
|||
|
for _, v1 := range v.Positions {
|
|||
|
temp.Positions = append(temp.Positions, &position.PositionV2{ID: uint32(v1.ID), Name: v1.Name})
|
|||
|
}
|
|||
|
|
|||
|
deps = append(deps, temp)
|
|||
|
}
|
|||
|
|
|||
|
positionReq.DepPositions = deps
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
for k, v := range oldAllPositionRes.DepPositions {
|
|||
|
//如果不在则增加
|
|||
|
if _, exist := departmentIdMap[v.ID]; exist == false {
|
|||
|
positionReq.DepPositions = append(positionReq.DepPositions, oldAllPositionRes.DepPositions[k])
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return positionReq, err
|
|||
|
}
|
|||
|
|
|||
|
func getFormPositionReq(req query.User, userId uint32) *position.BindUserV2Request {
|
|||
|
|
|||
|
//岗位服务 绑定岗位
|
|||
|
positionReq := &position.BindUserV2Request{
|
|||
|
Domain: config.Domain,
|
|||
|
UserInfo: &position.UserInfo{
|
|||
|
UserName: req.NickName,
|
|||
|
Avatar: req.Avatar,
|
|||
|
UserID: userId,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
if len(req.DepPositions) > 0 {
|
|||
|
var deps []*position.DepPosition
|
|||
|
for _, v := range req.DepPositions {
|
|||
|
temp := &position.DepPosition{
|
|||
|
ID: uint32(v.ID),
|
|||
|
Name: v.Name,
|
|||
|
IsLeader: v.IsLeader,
|
|||
|
}
|
|||
|
for _, v1 := range v.Positions {
|
|||
|
temp.Positions = append(temp.Positions, &position.PositionV2{ID: uint32(v1.ID), Name: v1.Name})
|
|||
|
}
|
|||
|
|
|||
|
deps = append(deps, temp)
|
|||
|
}
|
|||
|
|
|||
|
positionReq.DepPositions = deps
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
return positionReq
|
|||
|
}
|
|||
|
|
|||
|
// MyInfo 当前用户详情
|
|||
|
func MyInfo(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
res, err := GetUserInfoByIdV2(c, userInfo.ID)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, res)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
func DetailV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.InfoRequest
|
|||
|
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
res, err := GetBaseUserInfoByIdV2(c, req.ID)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, res)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// BossDetailUpdate 展示当前用户的可以看到的部门列表下 当前人员的部门
|
|||
|
func BossDetailUpdate(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req query.User
|
|||
|
var departmentIds []uint
|
|||
|
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if req.NickName == "" || utf8.RuneCountInString(req.NickName) >= 20 {
|
|||
|
service.Error(c, e.InvalidParams, errors.New(e.GetMsg(e.ErrNickName)))
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
departmentRes, err := service.DepartmentProvider.BaseList(c, &department.BaseAllRequest{UserID: uint32(userInfo.ID)})
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for _, v := range departmentRes.Data {
|
|||
|
departmentIds = append(departmentIds, uint(v.ID))
|
|||
|
}
|
|||
|
|
|||
|
//账号服务
|
|||
|
var updateReq = account.UpdateRequest{
|
|||
|
ID: req.ID,
|
|||
|
NickName: req.NickName,
|
|||
|
Password: req.Password,
|
|||
|
TelNum: req.TelNum,
|
|||
|
Avatar: req.Avatar,
|
|||
|
Status: req.Status,
|
|||
|
EnterDate: req.EnterDate,
|
|||
|
JobNum: req.JobNum,
|
|||
|
BirthDate: req.BirthDate,
|
|||
|
Sex: req.Sex,
|
|||
|
Title: req.Title,
|
|||
|
LeftDate: req.LeftDate,
|
|||
|
RecentImg: req.RecentImg,
|
|||
|
ICNum: req.ICNum,
|
|||
|
Operator: &account.Operator{
|
|||
|
ID: uint32(userInfo.ID),
|
|||
|
Name: "人员管理:" + userInfo.NickName,
|
|||
|
},
|
|||
|
}
|
|||
|
|
|||
|
updateReq.Extend = &account.Extend{
|
|||
|
JumpTo: req.Extend.JumpTo,
|
|||
|
Lang: req.Extend.Lang,
|
|||
|
CanScan: req.Extend.CanScan,
|
|||
|
ResolutionRatio: req.Extend.ResolutionRatio,
|
|||
|
}
|
|||
|
|
|||
|
userObj, err := GetUserInfoById(c, req.ID, config.Domain)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//获取默认所有的部门岗位以及ID
|
|||
|
positionReq, err := getFormPositionDepartmentReqV2(req, uint32(req.ID), departmentIds)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
_, err = service.AccountProvider.Update(context.Background(), &updateReq)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
_, err = service.PositionProvider.BindUserV2(c, positionReq)
|
|||
|
|
|||
|
//// 生成电子名片信息
|
|||
|
//addChainRequest, err := GetECardInfo(req.ID, "系统设置-人员管理")
|
|||
|
//fmt.Println("系统设置-人员管理", addChainRequest)
|
|||
|
//if err != nil {
|
|||
|
// service.Error(c, e.InvalidParams, err)
|
|||
|
// return
|
|||
|
//}
|
|||
|
//
|
|||
|
//_, err = service.ECardProvider.AddChain(c, addChainRequest)
|
|||
|
//if err != nil {
|
|||
|
// service.Error(c, e.InvalidParams, err)
|
|||
|
// return
|
|||
|
//}
|
|||
|
|
|||
|
if req.RecentImg != "" && len(userObj.Clocks) > 0 && (req.RecentImg != userObj.RecentImg || req.NickName !=
|
|||
|
userObj.NickName || req.TelNum != userObj.TelNum || req.ICNum != userObj.ICNum) {
|
|||
|
var dataSet []turnstile.DeviceUserData
|
|||
|
var userId account.ClockUserDeviceBatch
|
|||
|
deviceNums := make(map[string]string)
|
|||
|
for _, i := range userObj.Clocks {
|
|||
|
data := turnstile.DeviceUserData{
|
|||
|
JobNum: userObj.ID,
|
|||
|
RecentImg: req.RecentImg,
|
|||
|
DeviceNum: i.Device.DeviceNum,
|
|||
|
NickName: req.NickName,
|
|||
|
Phone: req.TelNum,
|
|||
|
DeviceName: i.Device.DeviceName,
|
|||
|
IcNum: req.ICNum,
|
|||
|
}
|
|||
|
dataSet = append(dataSet, data)
|
|||
|
}
|
|||
|
for _, i := range userObj.Clocks {
|
|||
|
deviceNums[i.Device.DeviceNum] = i.Device.DeviceName
|
|||
|
}
|
|||
|
//判断设备是否离线
|
|||
|
oline := CheckDeviceIsOnline(deviceNums)
|
|||
|
if oline != "" {
|
|||
|
service.Error(c, e.Error, errors.New(oline))
|
|||
|
return
|
|||
|
}
|
|||
|
//并发下发数据
|
|||
|
err = ConcurrentUpdateDeviceUser(c, dataSet, 10)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
//更新绑定关系
|
|||
|
userId.UserId = userObj.ID
|
|||
|
_, err = service.AccountProvider.UpdateDeviceRelevance(c, &userId)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.Error, err)
|
|||
|
return
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, struct{}{})
|
|||
|
}
|
|||
|
|
|||
|
// DetailNowDepartmentV2 展示当前用户的可以看到的部门列表下 当前人员的部门
|
|||
|
func DetailNowDepartmentV2(c *gin.Context) {
|
|||
|
//创建一个UserLoginService对象
|
|||
|
var req account.InfoRequest
|
|||
|
var departmentIds []uint
|
|||
|
|
|||
|
logger.Error("领导查看用户开始")
|
|||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
logger.Error("领导查看用户,请求", req)
|
|||
|
|
|||
|
userInfo := login.GetUserInfoFromC(c)
|
|||
|
logger.Error("领导查看用户,信息", userInfo)
|
|||
|
fmt.Println("1-----------", userInfo)
|
|||
|
|
|||
|
res, err := service.DepartmentProvider.BaseList(c, &department.BaseAllRequest{UserID: uint32(userInfo.ID)})
|
|||
|
|
|||
|
logger.Error("领导查看用户,返回", res, err)
|
|||
|
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
for _, v := range res.Data {
|
|||
|
departmentIds = append(departmentIds, uint(v.ID))
|
|||
|
}
|
|||
|
|
|||
|
logger.Error("领导查看用户,部门id", departmentIds)
|
|||
|
fmt.Println("1------------", departmentIds)
|
|||
|
userRes, err := GetBaseUserInfoByIdAndDepIDV2(c, req.ID, departmentIds)
|
|||
|
|
|||
|
logger.Error("领导查看用户,返回", userRes, err)
|
|||
|
if err != nil {
|
|||
|
service.Error(c, e.InvalidParams, err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
service.Success(c, userRes)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
// GetBaseUserInfoByIdAndDepIDV2 数据展示 仅仅展示可以看见的部门
|
|||
|
func GetBaseUserInfoByIdAndDepIDV2(c *gin.Context, ID uint64, departmentIds []uint) (*user.BaseUserResponse, error) {
|
|||
|
info := &user.BaseUserResponse{}
|
|||
|
|
|||
|
departmentIdMap := make(map[uint32]struct{}, len(departmentIds))
|
|||
|
for _, v := range departmentIds {
|
|||
|
departmentIdMap[uint32(v)] = struct{}{}
|
|||
|
}
|
|||
|
|
|||
|
req := account.InfoRequest{
|
|||
|
ID: ID,
|
|||
|
}
|
|||
|
|
|||
|
logger.Error("领导查看用户,数据展示", req)
|
|||
|
res, err := service.AccountProvider.Info(c, &req)
|
|||
|
if err != nil {
|
|||
|
return info, err
|
|||
|
}
|
|||
|
|
|||
|
logger.Error("领导查看用户,数据展示请求", ID)
|
|||
|
puRes, err := service.PositionProvider.UserInfoV2(c, &position.CreateResponse{ID: ID})
|
|||
|
|
|||
|
logger.Error("领导查看用户,数据展示请求", puRes, err)
|
|||
|
if err != nil {
|
|||
|
return info, err
|
|||
|
}
|
|||
|
|
|||
|
temp := &user.BaseUserResponse{
|
|||
|
ID: res.Info.ID,
|
|||
|
JobNum: res.Info.JobNum,
|
|||
|
NickName: res.Info.NickName,
|
|||
|
TelNum: res.Info.TelNum,
|
|||
|
MailAccount: res.Info.MailAccount,
|
|||
|
Avatar: res.Info.Avatar,
|
|||
|
RecentImg: res.Info.RecentImg,
|
|||
|
Status: res.Info.Status,
|
|||
|
EnterDate: res.Info.EnterDate,
|
|||
|
UpdatedAt: res.Info.UpdatedAt,
|
|||
|
}
|
|||
|
|
|||
|
if res.Info.Status == serializer.USERLEFT { //离职 手机号优化下
|
|||
|
temp.TelNum = serializer.GetLeftToNormalStaffRealTel(temp.TelNum)
|
|||
|
}
|
|||
|
|
|||
|
if res.Info.Operator != nil {
|
|||
|
temp.OperatorName = res.Info.Operator.Name
|
|||
|
}
|
|||
|
|
|||
|
var canSeeDepPositions []*position.DepPosition
|
|||
|
|
|||
|
if departmentIdMap != nil {
|
|||
|
for k, v := range puRes.DepPositions {
|
|||
|
if _, exist := departmentIdMap[v.ID]; exist {
|
|||
|
canSeeDepPositions = append(canSeeDepPositions, puRes.DepPositions[k])
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
temp.DepPositions = canSeeDepPositions
|
|||
|
|
|||
|
return temp, nil
|
|||
|
}
|
|||
|
|
|||
|
func GetBaseUserInfoByIdV2(c *gin.Context, ID uint64) (*user.BaseUserResponse, error) {
|
|||
|
info := &user.BaseUserResponse{}
|
|||
|
|
|||
|
req := account.InfoRequest{
|
|||
|
ID: ID,
|
|||
|
}
|
|||
|
|
|||
|
res, err := service.AccountProvider.Info(c, &req)
|
|||
|
if err != nil {
|
|||
|
return info, err
|
|||
|
}
|
|||
|
|
|||
|
puRes, err := service.PositionProvider.UserInfoV2(c, &position.CreateResponse{ID: ID})
|
|||
|
|
|||
|
if err != nil {
|
|||
|
return info, err
|
|||
|
}
|
|||
|
|
|||
|
temp := &user.BaseUserResponse{
|
|||
|
ID: res.Info.ID,
|
|||
|
JobNum: res.Info.JobNum,
|
|||
|
NickName: res.Info.NickName,
|
|||
|
TelNum: res.Info.TelNum,
|
|||
|
MailAccount: res.Info.MailAccount,
|
|||
|
Avatar: res.Info.Avatar,
|
|||
|
RecentImg: res.Info.RecentImg,
|
|||
|
Status: res.Info.Status,
|
|||
|
EnterDate: res.Info.EnterDate,
|
|||
|
UpdatedAt: res.Info.UpdatedAt,
|
|||
|
}
|
|||
|
|
|||
|
if res.Info.Operator != nil {
|
|||
|
temp.OperatorName = res.Info.Operator.Name
|
|||
|
}
|
|||
|
|
|||
|
if res.Info.Status == serializer.USERLEFT { //离职 手机号优化下
|
|||
|
temp.TelNum = serializer.GetLeftToNormalStaffRealTel(temp.TelNum)
|
|||
|
}
|
|||
|
|
|||
|
temp.DepPositions = puRes.DepPositions
|
|||
|
|
|||
|
return temp, nil
|
|||
|
}
|
|||
|
|
|||
|
func GetUserInfoByIdV2(c *gin.Context, ID uint64) (user.UserResponse, error) {
|
|||
|
info := user.UserResponse{}
|
|||
|
|
|||
|
req := account.InfoRequest{
|
|||
|
ID: ID,
|
|||
|
}
|
|||
|
|
|||
|
res, err := service.AccountProvider.Info(c, &req)
|
|||
|
if err != nil {
|
|||
|
return info, err
|
|||
|
}
|
|||
|
|
|||
|
//获取用户的岗位信息
|
|||
|
uReq := rule.RulesRequest{
|
|||
|
AccountID: req.ID,
|
|||
|
}
|
|||
|
|
|||
|
qres, err1 := service.RuleProvider.UserInfo(c, &uReq)
|
|||
|
|
|||
|
if err1 != nil {
|
|||
|
return info, err1
|
|||
|
}
|
|||
|
|
|||
|
pUserInfo, err := service.PositionProvider.UserInfoV2(c, &position.CreateResponse{ID: req.ID})
|
|||
|
|
|||
|
if err != nil {
|
|||
|
return info, err1
|
|||
|
}
|
|||
|
|
|||
|
fReq := position.FindRuleByUserIdRequest{
|
|||
|
UserId: ID,
|
|||
|
Urls: []string{e.AuthFinanceKey, e.AuthTrainingKey, e.AuthPublicizeKey, e.AuthWarehouseKey},
|
|||
|
}
|
|||
|
|
|||
|
fRes, err := service.PositionProvider.FindRuleByUserId(c, &fReq)
|
|||
|
if err != nil {
|
|||
|
return info, err1
|
|||
|
}
|
|||
|
|
|||
|
info = user.UserResponse{
|
|||
|
ID: res.Info.ID,
|
|||
|
NickName: res.Info.NickName,
|
|||
|
TelNum: res.Info.TelNum,
|
|||
|
Avatar: res.Info.Avatar,
|
|||
|
Status: res.Info.Status,
|
|||
|
CreateAt: res.Info.CreateAt,
|
|||
|
IsAdmin: qres.IsAdmin,
|
|||
|
RealNameID: res.Info.RealNameID,
|
|||
|
RealName: res.Info.RealName,
|
|||
|
PositionUsers: qres.PositionUsers,
|
|||
|
DepartmentLeaders: qres.DepartmentLeaders,
|
|||
|
IsNeedChange: res.Info.IsNeedChange,
|
|||
|
WorkYear: res.Info.WorkYear,
|
|||
|
EnterDate: res.Info.EnterDate,
|
|||
|
DepartmentName: "",
|
|||
|
JumpTo: "",
|
|||
|
JobNum: res.Info.JobNum,
|
|||
|
BirthDate: res.Info.BirthDate,
|
|||
|
Sex: res.Info.Sex,
|
|||
|
Title: res.Info.Title,
|
|||
|
Age: res.Info.Age,
|
|||
|
IDNum: res.Info.IDNum,
|
|||
|
LeftDate: res.Info.LeftDate,
|
|||
|
RecentImg: res.Info.RecentImg,
|
|||
|
Clocks: res.Info.Clocks,
|
|||
|
MailAccount: res.Info.MailAccount,
|
|||
|
ICNum: res.Info.ICNum,
|
|||
|
Train: res.Info.Train,
|
|||
|
Certificate: res.Info.Certificate,
|
|||
|
TrainVideos: res.Info.TrainVideos,
|
|||
|
DepPositions: pUserInfo.DepPositions,
|
|||
|
}
|
|||
|
|
|||
|
if len(qres.PositionUsers) >= 1 {
|
|||
|
|
|||
|
positionsMap := make(map[uint64]struct{}, len(qres.PositionUsers))
|
|||
|
|
|||
|
info.DriverAuth = isHaveDriverAuth(c, ID, qres.PositionUsers[0].DepartmentId)
|
|||
|
info.DriverSupervisorAuth = isHaveDriverSupervisorAuth(c, ID, qres.PositionUsers[0].DepartmentId)
|
|||
|
for _, v := range qres.PositionUsers {
|
|||
|
if _, ok := positionsMap[v.PositionID]; !ok {
|
|||
|
info.UniquePositionName = append(info.UniquePositionName, v.PositionName)
|
|||
|
positionsMap[v.PositionID] = struct{}{}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if res.Info.Extend != nil {
|
|||
|
info.JumpTo = res.Info.Extend.JumpTo
|
|||
|
info.Extend = &user.Extend{
|
|||
|
JumpTo: res.Info.Extend.JumpTo,
|
|||
|
Lang: res.Info.Extend.Lang,
|
|||
|
CanScan: res.Info.Extend.CanScan,
|
|||
|
ResolutionRatio: res.Info.Extend.ResolutionRatio,
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if len(qres.PositionUsers) >= 1 {
|
|||
|
info.DepartmentName = qres.PositionUsers[0].DepartmentName
|
|||
|
}
|
|||
|
|
|||
|
if len(fRes.Rules) >= 1 {
|
|||
|
info.IdentityKey = fRes.Rules[0].Url
|
|||
|
}
|
|||
|
|
|||
|
return info, nil
|
|||
|
}
|
|||
|
|
|||
|
func getNowList(list []*department.Node, departmentId uint32) []*department.Node {
|
|||
|
tempNode := getSonNodes(list, departmentId)
|
|||
|
fmt.Println(tempNode)
|
|||
|
|
|||
|
tempList := getList([]*department.Node{tempNode})
|
|||
|
return tempList
|
|||
|
}
|
|||
|
|
|||
|
func getSonNodes(list []*department.Node, departmentId uint32) *department.Node {
|
|||
|
|
|||
|
for k, v := range list {
|
|||
|
if v.ID == departmentId {
|
|||
|
return list[k]
|
|||
|
}
|
|||
|
|
|||
|
if len(v.Sons) > 0 { // 有儿子的话
|
|||
|
tempNode := getSonNodes(list[k].Sons, departmentId)
|
|||
|
if tempNode != nil { //儿子匹配的话
|
|||
|
return tempNode
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return nil
|
|||
|
}
|
|||
|
|
|||
|
func getList(list []*department.Node) []*department.Node {
|
|||
|
var temp []*department.Node
|
|||
|
|
|||
|
for _, v := range list {
|
|||
|
|
|||
|
temp = append(temp, &department.Node{
|
|||
|
ID: v.ID,
|
|||
|
Name: v.Name,
|
|||
|
})
|
|||
|
|
|||
|
if len(v.Sons) > 0 { //没有儿子
|
|||
|
tempNode := getList(v.Sons)
|
|||
|
if tempNode != nil {
|
|||
|
temp = append(temp, tempNode...)
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return temp
|
|||
|
}
|