|
|
|
|
package authorize
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"key_performance_indicators/models/modelshr"
|
|
|
|
|
"key_performance_indicators/overall"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
|
|
"key_performance_indicators/middleware/grocerystore"
|
|
|
|
|
"key_performance_indicators/overall/publicmethod"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 授权
|
|
|
|
|
func (e *EmpowerApi) GainToken(c *gin.Context) {
|
|
|
|
|
ContentType := c.Request.Header.Get("Content-Type")
|
|
|
|
|
Origin := c.Request.Header.Get("Origin")
|
|
|
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
|
|
|
|
|
|
|
|
var requestData gainAuthorize
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ContentType == "" || userAgent == "" || Origin == "" {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if requestData.UserNumber == "" || requestData.Password == "" {
|
|
|
|
|
publicmethod.Result(101, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//密码加密
|
|
|
|
|
var passwordMd5 publicmethod.Md5Encryption
|
|
|
|
|
passwordMd5.Md5EncryptionInit(requestData.Password)
|
|
|
|
|
passwordMd5Str := passwordMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
var empowerUser modelshr.EmpowerUser
|
|
|
|
|
userErr := empowerUser.GetCont(map[string]interface{}{"userkey": requestData.UserNumber, "password": passwordMd5Str}, "verification_code")
|
|
|
|
|
if userErr != nil {
|
|
|
|
|
publicmethod.Result(2000, passwordMd5Str, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//获取随机数
|
|
|
|
|
randCode := strconv.FormatInt(publicmethod.TableNumber(), 10)
|
|
|
|
|
// randCode := strconv.FormatInt(16557925694780, 10)
|
|
|
|
|
//头文件加密
|
|
|
|
|
//ContentType
|
|
|
|
|
var ContentTypeMd5 publicmethod.Md5Encryption
|
|
|
|
|
ContentTypeMd5.Md5EncryptionInit(ContentType)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
ContentTypeMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("ContentTypeMd5Str ----->%v\n", ContentTypeMd5)
|
|
|
|
|
|
|
|
|
|
ContentTypeMd5Str := ContentTypeMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//Origin
|
|
|
|
|
var OriginMd5 publicmethod.Md5Encryption
|
|
|
|
|
OriginMd5.Md5EncryptionInit(Origin)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
OriginMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
originMd5Str := OriginMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//userAgent
|
|
|
|
|
var userAgentMd5 publicmethod.Md5Encryption
|
|
|
|
|
userAgentMd5.Md5EncryptionInit(userAgent)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
userAgentMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
userAgentMd5Str := userAgentMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
//随机数加密
|
|
|
|
|
var randomNumberMd5 publicmethod.Md5Encryption
|
|
|
|
|
randomNumberMd5.Md5EncryptionInit(randCode)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
randomNumberMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
numberMd5 := randomNumberMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
//用户名加密
|
|
|
|
|
var userKeyMd5 publicmethod.Md5Encryption
|
|
|
|
|
userKeyMd5.Md5EncryptionInit(requestData.UserNumber)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
userKeyMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
userKeyMd5Str := userKeyMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
clearCodeToken := fmt.Sprintf("%v-%v-%v-%v-%v-%v", ContentTypeMd5Str, originMd5Str, userAgentMd5Str, numberMd5, userKeyMd5Str, passwordMd5Str)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("redisKey---->ContentTypeMd5Str:%v-originMd5Str:%v-userAgentMd5Str:%v-numberMd5:%v-userKeyMd5Str:%v-passwordMd5Str:%v\n", ContentTypeMd5Str, originMd5Str, userAgentMd5Str, numberMd5, userKeyMd5Str, passwordMd5Str)
|
|
|
|
|
//token 加密
|
|
|
|
|
var tokenMd5 publicmethod.Md5Encryption
|
|
|
|
|
tokenMd5.Md5EncryptionInit(clearCodeToken)
|
|
|
|
|
if empowerUser.VerificationCode != "" {
|
|
|
|
|
tokenMd5.AppKey = empowerUser.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("tokenMd5Appk ----->%v\n", tokenMd5)
|
|
|
|
|
tokenMd5Str := tokenMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
//设定redis Key名称
|
|
|
|
|
redisKey := fmt.Sprintf("Authentication:ApiAuthent_%v", tokenMd5Str)
|
|
|
|
|
|
|
|
|
|
saveTokenRedis := publicmethod.MapOut[string]()
|
|
|
|
|
saveTokenRedis["number"] = randCode
|
|
|
|
|
saveTokenRedis["userkey"] = requestData.UserNumber
|
|
|
|
|
saveTokenRedis["password"] = requestData.Password
|
|
|
|
|
//将验证信息写入Redis
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
|
|
|
redisClient.HashMsetAdd(redisKey, saveTokenRedis)
|
|
|
|
|
//输出验证
|
|
|
|
|
// clearTokenStr := fmt.Sprintf("%v-%v", tokenMd5Str, numberMd5)
|
|
|
|
|
// var clearTokenMd5 publicmethod.Md5Encryption
|
|
|
|
|
// clearTokenMd5.Md5EncryptionInit(clearTokenStr)
|
|
|
|
|
// clearTokenMd5Str := clearTokenMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
var sendToken SendToken
|
|
|
|
|
sendToken.Number = randCode
|
|
|
|
|
sendToken.Token = tokenMd5Str
|
|
|
|
|
publicmethod.Result(0, sendToken, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 加密验证
|
|
|
|
|
func (e *EmpowerApi) Encryption(c *gin.Context) {
|
|
|
|
|
var requestData EncryptionData
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var ContentTypeMd5 publicmethod.Md5Encryption
|
|
|
|
|
ContentTypeMd5.Md5EncryptionInit(requestData.Number)
|
|
|
|
|
ContentTypeMd5.AppKey = requestData.AppKey
|
|
|
|
|
ContentTypeMd5Str, dfg := ContentTypeMd5.Md5EncryptionAlgorithmFj()
|
|
|
|
|
outputCont := publicmethod.MapOut[string]()
|
|
|
|
|
outputCont["index"] = "MD5加密验证"
|
|
|
|
|
// outputCont["userErr"] = userErr
|
|
|
|
|
outputCont["md5"] = ContentTypeMd5Str
|
|
|
|
|
outputCont["number"] = requestData.Number
|
|
|
|
|
outputCont["appkey"] = requestData.AppKey
|
|
|
|
|
outputCont["step"] = dfg
|
|
|
|
|
publicmethod.Result(0, outputCont, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 写入令牌
|
|
|
|
|
func (a *EmpowerApi) WriteToken(c *gin.Context) {
|
|
|
|
|
var requestData WriteIderCont
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if requestData.Openid == "" || requestData.Key == "" || requestData.Token == "" {
|
|
|
|
|
publicmethod.Result(101, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if requestData.UserInfo.Number == "" || requestData.UserInfo.Password == "" || requestData.UserInfo.Key == "" {
|
|
|
|
|
publicmethod.Result(101, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var userCont modelshr.ManCont
|
|
|
|
|
err = userCont.GetCont(map[string]interface{}{"`number`": requestData.UserInfo.Number, "`key`": requestData.UserInfo.Key, "`password`": requestData.UserInfo.Password})
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(105, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if requestData.Openid != userCont.Wechat && requestData.Openid != userCont.WorkWechat {
|
|
|
|
|
publicmethod.Result(105, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, pointId, operation, _ := publicmethod.GetNewAccredit("cangchu", userCont.Role, userCont.Key, userCont.AdminOrg, userCont.Position)
|
|
|
|
|
|
|
|
|
|
saveData := publicmethod.MapOut[string]()
|
|
|
|
|
saveData["key"] = requestData.Key
|
|
|
|
|
saveData["token"] = requestData.Token
|
|
|
|
|
saveData["userinfo"] = userCont
|
|
|
|
|
writeRedisData := map[string]interface{}{
|
|
|
|
|
"userkey": requestData.Key,
|
|
|
|
|
"key": userCont.Key,
|
|
|
|
|
"usernumber": userCont.Number,
|
|
|
|
|
"userpwd": userCont.Password,
|
|
|
|
|
"usertoken": requestData.Token,
|
|
|
|
|
"jurisdiction": operation,
|
|
|
|
|
"menuOper": pointId,
|
|
|
|
|
"wand": 118,
|
|
|
|
|
}
|
|
|
|
|
var surisdictionStr []string
|
|
|
|
|
var surisdictionInt []int64
|
|
|
|
|
jsonErr := json.Unmarshal([]byte(operation), &surisdictionStr)
|
|
|
|
|
if jsonErr == nil {
|
|
|
|
|
for _, jurVal := range surisdictionStr {
|
|
|
|
|
jurValInt, jurValErr := strconv.ParseInt(jurVal, 10, 64)
|
|
|
|
|
if jurValErr == nil {
|
|
|
|
|
surisdictionInt = append(surisdictionInt, jurValInt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var menuOperStr []string
|
|
|
|
|
var menuOperInts []int64
|
|
|
|
|
menuOperStr = strings.Split(pointId, ",")
|
|
|
|
|
for _, menuOperVal := range menuOperStr {
|
|
|
|
|
menuOperInt, menuOperErr := strconv.ParseInt(menuOperVal, 10, 64)
|
|
|
|
|
if menuOperErr == nil {
|
|
|
|
|
menuOperInts = append(menuOperInts, menuOperInt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// redisFileKey := "ScanCode:Authentication:LoginApi_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + userKeyCode
|
|
|
|
|
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, requestData.Key)
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
|
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
|
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
|
|
|
|
|
|
|
|
//缓存写入个人信息
|
|
|
|
|
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number)
|
|
|
|
|
myCont := publicmethod.MapOut[string]()
|
|
|
|
|
myCont["id"] = userCont.Id
|
|
|
|
|
myCont["number"] = userCont.Number //员工工号
|
|
|
|
|
myCont["name"] = userCont.Name //姓名
|
|
|
|
|
myCont["icon"] = userCont.Icon //头像
|
|
|
|
|
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
|
|
|
|
|
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
|
|
|
|
|
myCont["company"] = userCont.Company //入职公司
|
|
|
|
|
myCont["maindeparment"] = userCont.MainDeparment //主部门
|
|
|
|
|
myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
|
|
|
|
|
myCont["deparment"] = userCont.Deparment //部门
|
|
|
|
|
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
|
|
|
|
|
myCont["teamid"] = userCont.TeamId //班组
|
|
|
|
|
myCont["position"] = userCont.Position //职位
|
|
|
|
|
myCont["jobclass"] = userCont.JobClass //职务分类
|
|
|
|
|
myCont["jobid"] = userCont.JobId //职务
|
|
|
|
|
myCont["jobleve"] = userCont.JobLeve //职务等级
|
|
|
|
|
myCont["wechat"] = userCont.Wechat //微信UserId
|
|
|
|
|
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
|
|
|
|
|
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
|
|
|
|
|
myCont["key"] = userCont.Key //key
|
|
|
|
|
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
|
|
|
|
|
myCont["password"] = userCont.Password //密码
|
|
|
|
|
myCont["role"] = userCont.Role //角色
|
|
|
|
|
myCont["idcardno"] = userCont.Idcardno //身份证号
|
|
|
|
|
myCont["passportno"] = userCont.Passportno //护照号码
|
|
|
|
|
myCont["globalroaming"] = userCont.Globalroaming //国际区号
|
|
|
|
|
myCont["mobilephone"] = userCont.Mobilephone //手机号码
|
|
|
|
|
myCont["email"] = userCont.Email //电子邮件
|
|
|
|
|
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
|
|
|
|
|
myCont["birthday"] = userCont.Birthday //birthday
|
|
|
|
|
myCont["myfolk"] = userCont.Myfolk //民族
|
|
|
|
|
myCont["nativeplace"] = userCont.Nativeplace //籍贯
|
|
|
|
|
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
|
|
|
|
|
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
|
|
|
|
|
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
|
|
|
|
|
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
|
|
|
|
|
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
|
|
|
|
|
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
|
|
|
|
|
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
|
|
|
|
|
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
|
|
|
|
|
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
|
|
|
|
|
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
|
|
|
|
|
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
|
|
|
|
|
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
|
|
|
|
|
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
|
|
|
|
|
myCont["entrydate"] = userCont.Entrydate //入职日期
|
|
|
|
|
myCont["probationperiod"] = userCont.Probationperiod //试用期
|
|
|
|
|
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
|
|
|
|
|
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
|
|
|
|
|
|
|
|
|
|
var companyCont modelshr.AdministrativeOrganization
|
|
|
|
|
companyCont.GetCont(map[string]interface{}{"`id`": userCont.Company}, "`name`")
|
|
|
|
|
myCont["companyname"] = companyCont.Name
|
|
|
|
|
var departmentCont modelshr.AdministrativeOrganization
|
|
|
|
|
departmentCont.GetCont(map[string]interface{}{"`id`": userCont.MainDeparment}, "`name`")
|
|
|
|
|
myCont["maindeparmentname"] = departmentCont.Name
|
|
|
|
|
var postInfo modelshr.Position
|
|
|
|
|
postInfo.GetCont(map[string]interface{}{"`id`": userCont.Position}, "`name`")
|
|
|
|
|
myCont["positionname"] = postInfo.Name
|
|
|
|
|
redisClient.HashMsetAdd(redisMyContKey, myCont)
|
|
|
|
|
|
|
|
|
|
saveData["usercont"] = myCont
|
|
|
|
|
// fmt.Printf("redisMyContKey------Login----->%v\n", redisMyContKey)
|
|
|
|
|
publicmethod.Result(0, saveData, c)
|
|
|
|
|
}
|