应用集成平台服务端
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.

553 lines
16 KiB

3 years ago
package user
import (
"appPlatform/models/modelshr"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"sort"
3 years ago
"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
}
3 years ago
roleList := strings.Split(myContInfo.Role, ",")
// roleList = append(roleList, "ROOT")
3 years ago
sendData.Roles = roleList
//获取权限
menuPoint, _, _, _ := GetUserPower("appsystem", myContInfo.Position, roleList)
// menuPoint, opeart, orgList.level := GetUserPower("appsystem", myContInfo.Position, roleList)
// fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList)
3 years ago
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
3 years ago
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
}
3 years ago
/*
*
@ 作者: 秦东
@ 时间: 2023-05-22 11:30:44
@ 功能: 获取用户权限
@ 参数
#appType 系统标识
#postId 职务
#roleList 角色列表
@ 返回值
#menuPoint 菜单操作列表
#opeart 点位
#orgList 行政组织
#lever 最高管理等级
3 years ago
@ 方法原型
#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, lever int) {
if postId == 0 {
return
}
3 years ago
//获取职务权限
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)
}
if lever <= emPower.Level {
lever = emPower.Level
}
3 years ago
}
// fmt.Printf("职务权限:---->%v\n:---->%v\n", len(roleList), roleList)
3 years ago
//获取角色权限
if len(roleList) > 0 {
3 years ago
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)
}
if lever <= roleEmpower.Level {
lever = roleEmpower.Level
}
3 years ago
}
}
}
3 years ago
// 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)
// }
// }
// }
3 years ago
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2023-11-08 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)
}
/*
*
@ 作者: 秦东
@ 时间: 2024-01-24 11:30:15
@ 功能: 获取人员信息单页手机查看权限
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) LookOnePeopleArchives(c *gin.Context) {
var requestData LookOneMan
err := c.ShouldBindJSON(&requestData)
if err != nil {
publicmethod.Result(100, err, c)
return
}
var sendData SendPower
sendData.IsOk = 2
if requestData.SurveyMan == "" {
publicmethod.Result(0, sendData, c)
return
}
if requestData.UnSurveyMan == "" {
requestData.UnSurveyMan = requestData.SurveyMan
}
var surverManInfo modelshr.ManCont
err = surverManInfo.GetCont(map[string]interface{}{"`number`": requestData.SurveyMan}, "`emp_type`", "`company`", "`maindeparment`", "`admin_org`", "`position`", "`position`", "`role`")
if err != nil {
publicmethod.Result(0, sendData, c)
return
}
roleList := strings.Split(surverManInfo.Role, ",")
//获取权限
var orgList []string
sendData.Purview, _, orgList, sendData.Level = GetUserPower("appsystem", surverManInfo.Position, roleList)
if publicmethod.IsInTrue[string]("210700510225772544", sendData.Purview) {
//获取被查看人行政组织
var lookManInfo modelshr.PersonArchives
lookManInfo.GetCont(map[string]interface{}{"`number`": requestData.UnSurveyMan}, "`company`", "`maindeparment`", "`admin_org`")
switch sendData.Level {
case 1:
var sunOrg publicmethod.GetOrgAllParent
sunOrg.GetOrgSun(surverManInfo.AdminOrg)
sunOrg.Id = append(sunOrg.Id, surverManInfo.AdminOrg)
if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) {
sendData.IsOk = 1
}
case 2:
var sunOrg publicmethod.GetOrgAllParent
sunOrg.GetOrgSun(surverManInfo.MainDeparment)
sunOrg.Id = append(sunOrg.Id, surverManInfo.MainDeparment)
if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) {
sendData.IsOk = 1
}
case 3:
var sunOrg publicmethod.GetOrgAllParent
sunOrg.GetOrgSun(surverManInfo.Company)
sunOrg.Id = append(sunOrg.Id, surverManInfo.Company)
if publicmethod.IsInTrue[int64](lookManInfo.Company, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.MainDeparment, sunOrg.Id) || publicmethod.IsInTrue[int64](lookManInfo.AdminOrg, sunOrg.Id) {
sendData.IsOk = 1
}
case 4:
departMent := strconv.FormatInt(lookManInfo.MainDeparment, 10)
orgId := strconv.FormatInt(lookManInfo.AdminOrg, 10)
companyId := strconv.FormatInt(lookManInfo.Company, 10)
if publicmethod.IsInTrue[string](companyId, orgList) || publicmethod.IsInTrue[string](departMent, orgList) || publicmethod.IsInTrue[string](orgId, orgList) {
sendData.IsOk = 1
}
case 5:
sendData.IsOk = 1
default:
sendData.IsOk = 2
}
}
publicmethod.Result(0, sendData, c)
}