package user
import (
"appPlatform/models/modelshr"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"sort"
"strconv"
"strings"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 05 - 22 10 : 54 : 15
@ 功能 : 获取当前登录用户信息
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetUserCont ( c * gin . Context ) {
context , _ := c . Get ( overall . MyContJwt )
var myContInfo modelshr . ManCont
jsonCont , _ := json . Marshal ( context )
jsonUnErr := json . Unmarshal ( jsonCont , & myContInfo )
outMap := publicmethod . MapOut [ string ] ( )
outMap [ "context" ] = context
outMap [ "exi" ] = jsonUnErr
outMap [ "myContInfo" ] = myContInfo
var sendData SendUserCont
sendData . UserId = strconv . FormatInt ( myContInfo . Key , 10 )
sendData . Number = myContInfo . Number
sendData . NickName = myContInfo . Name
sendData . Company = strconv . FormatInt ( myContInfo . Company , 10 ) //公司
var companyCont modelshr . AdministrativeOrganization
companyCont . GetCont ( map [ string ] interface { } { "`id`" : myContInfo . Company } , "`name`" )
sendData . CompanyName = companyCont . Name //公司名称
sendData . Department = strconv . FormatInt ( myContInfo . MainDeparment , 10 ) //主部门
var departCont modelshr . AdministrativeOrganization
departCont . GetCont ( map [ string ] interface { } { "`id`" : myContInfo . MainDeparment } , "`name`" )
sendData . DepartmentName = departCont . Name //主部门名称
sendData . Organization = strconv . FormatInt ( myContInfo . AdminOrg , 10 ) //行政组织
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : myContInfo . MainDeparment } , "`name`" )
sendData . OrganizationName = orgCont . Name //行政组织名称
sendData . Avatar = myContInfo . Icon
if myContInfo . IconPhpto != "" {
sendData . Avatar = myContInfo . IconPhpto
}
roleList := strings . Split ( myContInfo . Role , "," )
// roleList = append(roleList, "ROOT")
sendData . Roles = roleList
//获取权限
menuPoint , _ , _ := GetUserPower ( "appsystem" , myContInfo . Position , roleList )
// menuPoint, opeart, orgList := GetUserPower("appsystem", myContInfo.Position, roleList)
// fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList)
sendData . Perms = menuPoint
switch myContInfo . Gender {
case 1 :
sendData . GenderStr = "男"
case 2 :
sendData . GenderStr = "女"
default :
sendData . GenderStr = "第三性别"
}
sendData . EmpType = myContInfo . EmpType
sendData . PostList = GainOrgPostLog ( myContInfo . Key )
sendData . Mobilephone = myContInfo . Mobilephone
sendData . Currentresidence = myContInfo . Currentresidence
publicmethod . Result ( 0 , sendData , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 11 - 07 10 : 19 : 45
@ 功能 : 获取集团内任职记录
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func GainOrgPostLog ( uid int64 ) ( postLog [ ] string ) {
var workHistory [ ] modelshr . InsideWorkHistory
err := overall . CONSTANT_DB_HR . Where ( "`state` = 1 AND `end_time` = 0 AND `key` = ?" , uid ) . Order ( "`assign_type` ASC" ) . Order ( "`start_time` DESC" ) . Find ( & workHistory ) . Error
if err != nil && len ( workHistory ) < 1 {
return
}
for _ , v := range workHistory {
var orgList [ ] int64
var orgNameList [ ] string
if ! publicmethod . IsInTrue [ int64 ] ( v . Company , orgList ) {
orgList = append ( orgList , v . Company )
var orgOne modelshr . AdministrativeOrganization
orgOne . GetCont ( map [ string ] interface { } { "`id`" : v . Company } , "`name`" )
orgNameList = append ( orgNameList , orgOne . Name )
}
if ! publicmethod . IsInTrue [ int64 ] ( v . Department , orgList ) {
orgList = append ( orgList , v . Department )
var orgTwo modelshr . AdministrativeOrganization
orgTwo . GetCont ( map [ string ] interface { } { "`id`" : v . Department } , "`name`" )
orgNameList = append ( orgNameList , orgTwo . Name )
}
if ! publicmethod . IsInTrue [ int64 ] ( v . WorkShop , orgList ) {
orgList = append ( orgList , v . WorkShop )
var orgTree modelshr . AdministrativeOrganization
orgTree . GetCont ( map [ string ] interface { } { "`id`" : v . WorkShop } , "`name`" )
orgNameList = append ( orgNameList , orgTree . Name )
}
if ! publicmethod . IsInTrue [ int64 ] ( v . WorkshopSection , orgList ) {
orgList = append ( orgList , v . WorkshopSection )
var orgTree modelshr . AdministrativeOrganization
orgTree . GetCont ( map [ string ] interface { } { "`id`" : v . WorkshopSection } , "`name`" )
orgNameList = append ( orgNameList , orgTree . Name )
}
fmt . Println ( orgNameList )
fmt . Println ( orgList )
fmt . Println ( v . WorkshopSection )
if len ( orgNameList ) > 0 {
allOrgName := strings . Join ( orgNameList , " / " )
if v . Position != 0 {
var postCont modelshr . Position
postCont . GetCont ( map [ string ] interface { } { "`id`" : v . Position } , "`name`" )
if v . GradePositions != 0 {
allOrgName = fmt . Sprintf ( "%v %v级%v" , allOrgName , v . GradePositions , postCont . Name )
} else {
allOrgName = fmt . Sprintf ( "%v %v" , allOrgName , postCont . Name )
}
}
if v . AssignType == 1 {
allOrgName = fmt . Sprintf ( "%v(主职)" , allOrgName )
postLog = append ( postLog , allOrgName )
} else {
allOrgName := fmt . Sprintf ( "%v(兼职)" , allOrgName )
postLog = append ( postLog , allOrgName )
}
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 05 - 22 11 : 30 : 44
@ 功能 : 获取用户权限
@ 参数
# appType 系统标识
# postId 职务
# roleList 角色列表
@ 返回值
# menuPoint 菜单操作列表
# opeart 点位
# orgList 行政组织
@ 方法原型
# func GetUserPower ( appType string , postId int64 , roleList [ ] string ) ( menuPoint [ ] string , opeart [ ] string , orgList [ ] string )
* /
func GetUserPower ( appType string , postId int64 , roleList [ ] string ) ( menuPoint , opeart , orgList [ ] string ) {
if postId == 0 {
return
}
//获取职务权限
var emPower modelssystempermission . Empower
err := emPower . GetCont ( map [ string ] interface { } { "`post_id`" : postId , "`system`" : appType } )
if err == nil {
if emPower . PointId != "" {
pointIdList := strings . Split ( emPower . PointId , "," )
menuPoint = publicmethod . MergeStruct [ string ] ( pointIdList , menuPoint )
}
if emPower . Operation != "" {
operationIdList := strings . Split ( emPower . Operation , "," )
opeart = publicmethod . MergeStruct [ string ] ( operationIdList , opeart )
}
if emPower . Organization != "" {
orgIdList := strings . Split ( emPower . Organization , "," )
orgList = publicmethod . MergeStruct [ string ] ( orgIdList , orgList )
}
}
// fmt.Printf("职务权限:---->%v\n:---->%v\n", emPower, orgList)
//获取角色权限
if len ( roleList ) > 0 {
var roleId [ ] int64
err = overall . CONSTANT_DB_System_Permission . Model ( & modelssystempermission . SystemRole { } ) . Select ( "`id`" ) . Where ( "`state` = 1 AND `id` IN ?" , roleList ) . Find ( & roleId ) . Error
if err == nil && len ( roleId ) > 0 {
for _ , v := range roleId {
var roleEmpower modelssystempermission . RoleEmpower
err = roleEmpower . GetCont ( map [ string ] interface { } { "`role_id`" : v , "`system`" : appType } )
if err == nil {
if roleEmpower . PointId != "" {
pointIdList := strings . Split ( roleEmpower . PointId , "," )
menuPoint = publicmethod . MergeStruct [ string ] ( pointIdList , menuPoint )
}
if roleEmpower . Operation != "" {
operationIdList := strings . Split ( roleEmpower . Operation , "," )
opeart = publicmethod . MergeStruct [ string ] ( operationIdList , opeart )
}
if roleEmpower . Organization != "" {
orgIdList := strings . Split ( roleEmpower . Organization , "," )
orgList = publicmethod . MergeStruct [ string ] ( orgIdList , orgList )
}
}
}
}
// for _, v := range roleList {
// var roleEmpower modelssystempermission.RoleEmpower
// err = roleEmpower.GetCont(map[string]interface{}{"`role_id`": v, "`system`": appType})
// if err == nil {
// if roleEmpower.PointId != "" {
// pointIdList := strings.Split(roleEmpower.PointId, ",")
// menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint)
// }
// if roleEmpower.Operation != "" {
// operationIdList := strings.Split(roleEmpower.Operation, ",")
// opeart = publicmethod.MergeStruct[string](operationIdList, opeart)
// }
// if roleEmpower.Organization != "" {
// orgIdList := strings.Split(roleEmpower.Organization, ",")
// orgList = publicmethod.MergeStruct[string](orgIdList, orgList)
// }
// }
// }
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 11 - 0 8 16 : 37 : 43
@ 功能 : 统计行政组织下人员年龄比例
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) StatisticalAgeRatio ( c * gin . Context ) {
var requestData publicmethod . PublicId
err := c . ShouldBindJSON ( & requestData )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if requestData . Id == "" {
requestData . Id = "309"
}
orgId , _ := strconv . ParseInt ( requestData . Id , 10 , 64 )
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSonAllId ( orgId )
sunOrg . Id = append ( sunOrg . Id , orgId )
var idCard [ ] string
err = overall . CONSTANT_DB_HR . Model ( & modelshr . ManCont { } ) . Select ( "COALESCE(`idcardno`,'')" ) . Where ( "`admin_org` IN ? AND emp_type BETWEEN ? AND ?" , sunOrg . Id , 1 , 10 ) . Find ( & idCard ) . Error
if err != nil && len ( idCard ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var ageAry [ ] int
// jisuan
for i := 0 ; i < len ( idCard ) ; i ++ {
if idCard [ i ] != "" {
var myAge publicmethod . BirthdayAge
myAge . GetAgeByBirthday ( idCard [ i ] )
// if publicmethod.IsInTrue[int](myAge.Age,ageAry){}
ageAry = append ( ageAry , myAge . Age )
}
}
if len ( ageAry ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
//根据维度序号排序
sort . Slice ( ageAry , func ( i , j int ) bool {
return ageAry [ i ] < ageAry [ j ]
} )
maxAge := ageAry [ len ( ageAry ) - 1 ]
// maxAge = 42
ageNumberList := publicmethod . StatisticalDuplication [ int ] ( ageAry )
ageMap := make ( map [ int ] int )
if len ( ageNumberList ) > 0 {
for i , v := range ageNumberList {
if i <= maxAge && i <= 20 {
if _ , isOk := ageMap [ 20 ] ; isOk {
ageMap [ 20 ] = ageMap [ 20 ] + v
} else {
ageMap [ 20 ] = v
}
}
if i <= maxAge && i <= 25 && i > 20 {
if _ , isOk := ageMap [ 25 ] ; isOk {
ageMap [ 25 ] = ageMap [ 25 ] + v
} else {
ageMap [ 25 ] = v
}
}
if i <= maxAge && i <= 30 && i > 25 {
if _ , isOk := ageMap [ 30 ] ; isOk {
ageMap [ 30 ] = ageMap [ 30 ] + v
} else {
ageMap [ 30 ] = v
}
}
if i <= maxAge && i <= 35 && i > 30 {
if _ , isOk := ageMap [ 35 ] ; isOk {
ageMap [ 35 ] = ageMap [ 35 ] + v
} else {
ageMap [ 35 ] = v
}
}
if i <= maxAge && i <= 40 && i > 35 {
if _ , isOk := ageMap [ 40 ] ; isOk {
ageMap [ 40 ] = ageMap [ 40 ] + v
} else {
ageMap [ 40 ] = v
}
}
if i <= maxAge && i <= 45 && i > 40 {
if _ , isOk := ageMap [ 45 ] ; isOk {
ageMap [ 45 ] = ageMap [ 45 ] + v
} else {
ageMap [ 45 ] = v
}
}
if i <= maxAge && i <= 50 && i > 45 {
if _ , isOk := ageMap [ 50 ] ; isOk {
ageMap [ 50 ] = ageMap [ 50 ] + v
} else {
ageMap [ 50 ] = v
}
}
if i <= maxAge && i <= 55 && i > 50 {
if _ , isOk := ageMap [ 55 ] ; isOk {
ageMap [ 55 ] = ageMap [ 55 ] + v
} else {
ageMap [ 55 ] = v
}
}
if i <= maxAge && i <= 60 && i > 55 {
if _ , isOk := ageMap [ 60 ] ; isOk {
ageMap [ 60 ] = ageMap [ 60 ] + v
} else {
ageMap [ 60 ] = v
}
}
if i <= maxAge && i > 60 {
if _ , isOk := ageMap [ 70 ] ; isOk {
ageMap [ 70 ] = ageMap [ 70 ] + v
} else {
ageMap [ 70 ] = v
}
}
}
}
var sendAgeAry [ ] AgeType
if len ( ageMap ) > 0 {
if ageVal , isOk := ageMap [ 20 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "20岁以下"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 25 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "20岁-25岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 30 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "25岁-30岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 35 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "30岁-35岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 40 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "35岁-40岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 45 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "40岁-45岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 50 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "45岁-50岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 55 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "50岁-55岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 60 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "55岁-60岁(含)"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
if ageVal , isOk := ageMap [ 70 ] ; isOk {
var sendAgeCont AgeType
sendAgeCont . Name = "60岁以上"
sendAgeCont . Value = ageVal
sendAgeAry = append ( sendAgeAry , sendAgeCont )
}
}
sheng := publicmethod . MapOut [ string ] ( )
sheng [ "aaffg" ] = ageNumberList
sheng [ "ageAry" ] = ageAry
sheng [ "maxAge" ] = maxAge
sheng [ "ageMap" ] = ageMap
sheng [ "sendAgeAry" ] = sendAgeAry
publicmethod . Result ( 0 , sendAgeAry , c )
}