package humanResources
import (
"appPlatform/models/modelshr"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 12 - 02 11 : 31 : 56
@ 功能 : 根据权限获取数据
* /
func ( a * ApiMethod ) AuthorizePeopleList ( c * gin . Context ) {
var requestData SearchPowPople
c . ShouldBindJSON ( & requestData )
if requestData . Page < 0 {
requestData . Page = 1
}
if requestData . PageSize < 0 {
requestData . PageSize = 10
}
//获取当前操作人
context , _ := c . Get ( overall . MyContJwt )
var myContInfo modelshr . ManCont
jsonCont , _ := json . Marshal ( context )
json . Unmarshal ( jsonCont , & myContInfo )
//获取权限
myPower := publicmethod . GetMyMenuPower ( myContInfo . Key , requestData . MenuId )
//获取人员列表
// var peopelList []modelshr.PersonArchives
gormDb := overall . CONSTANT_DB_HR . Model ( & modelshr . ManCont { } ) . Select ( "`id`" ) . Where ( "`number` NOT LIKE ?" , "%W%" )
if requestData . Name != "" {
gormDb = gormDb . Where ( "`number` LIKE ? OR `name` LIKE ? OR `mobilephone` LIKE ?" , "%" + requestData . Name + "%" , "%" + requestData . Name + "%" , "%" + requestData . Name + "%" )
}
if len ( requestData . Employ ) > 0 {
gormDb = gormDb . Where ( "`emp_type` IN ?" , requestData . Employ )
} else {
if requestData . OnJob != 0 {
gormDb = gormDb . Where ( "`emp_type` BETWEEN ? AND ?" , 11 , 14 )
} else {
gormDb = gormDb . Where ( "`emp_type` BETWEEN ? AND ?" , 1 , 10 )
}
}
if len ( requestData . Team ) > 0 {
gormDb = gormDb . Where ( "`teamid` IN ?" , requestData . Team )
}
if requestData . JoinTime != "" {
startTime , endTime := publicmethod . OenDayStartOrEndTime ( requestData . JoinTime , 1 )
gormDb = gormDb . Where ( "`entrydate` BETWEEN ? AND ?" , startTime , endTime )
}
switch myPower . Scope { //可见范围(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有)
case 2 :
gormDb = gormDb . Where ( "`position` = ?" , myContInfo . Position )
case 3 :
if requestData . OrgId != 0 {
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSun ( int64 ( myContInfo . MainDeparment ) )
sunOrg . Id = append ( sunOrg . Id , int64 ( myContInfo . MainDeparment ) )
if publicmethod . IsInTrue [ int64 ] ( int64 ( requestData . OrgId ) , sunOrg . Id ) {
var pickSunOrg publicmethod . GetOrgAllParent
pickSunOrg . GetOrgSun ( int64 ( requestData . OrgId ) )
pickSunOrg . Id = append ( pickSunOrg . Id , int64 ( requestData . OrgId ) )
gormDb = gormDb . Where ( "`admin_org` = ?" , pickSunOrg . Id )
} else {
gormDb = gormDb . Where ( "`maindeparment` = ?" , myContInfo . MainDeparment )
}
} else {
gormDb = gormDb . Where ( "`maindeparment` = ?" , myContInfo . MainDeparment )
}
case 4 :
if requestData . OrgId != 0 {
if int64 ( requestData . OrgId ) == myContInfo . Company {
gormDb = gormDb . Where ( "`company` = ?" , myContInfo . Company )
} else {
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSun ( myContInfo . Company )
if publicmethod . IsInTrue [ int64 ] ( int64 ( requestData . OrgId ) , sunOrg . Id ) {
var pickSunOrg publicmethod . GetOrgAllParent
pickSunOrg . GetOrgSun ( int64 ( requestData . OrgId ) )
pickSunOrg . Id = append ( pickSunOrg . Id , int64 ( requestData . OrgId ) )
gormDb = gormDb . Where ( "`admin_org` = ?" , pickSunOrg . Id )
} else {
gormDb = gormDb . Where ( "`company` = ?" , myContInfo . Company )
}
}
} else {
}
case 5 :
if requestData . OrgId != 0 {
//目标行政组织
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSun ( int64 ( requestData . OrgId ) )
sunOrg . Id = append ( sunOrg . Id , int64 ( requestData . OrgId ) )
//可观测的行政组织
var oid [ ] int64
for _ , v := range myPower . ScopeManAry {
oid = append ( oid , int64 ( v ) )
}
lookOrg := publicmethod . Intersect [ int64 ] ( sunOrg . Id , oid )
if len ( lookOrg ) > 0 {
gormDb = gormDb . Where ( "`admin_org` IN ?" , lookOrg )
} else {
gormDb = gormDb . Where ( "`admin_org` = ?" , myContInfo . AdminOrg )
}
}
case 6 :
if requestData . OrgId != 0 {
var sunOrg publicmethod . GetOrgAllParent
sunOrg . GetOrgSun ( int64 ( requestData . OrgId ) )
sunOrg . Id = append ( sunOrg . Id , int64 ( requestData . OrgId ) )
if len ( sunOrg . Id ) > 0 {
gormDb = gormDb . Where ( "`admin_org` IN ?" , sunOrg . Id )
} else {
gormDb = gormDb . Where ( "`admin_org` = ?" , requestData . OrgId )
}
}
default :
gormDb = gormDb . Where ( "`key` = ?" , myContInfo . Key )
}
//获取人员总数
var total int64
totalErr := gormDb . Count ( & total ) . Error
if totalErr != nil {
total = 0
}
var idAry [ ] int64
gormDb = publicmethod . PageTurningSettings ( gormDb , requestData . Page , requestData . PageSize )
err := gormDb . Order ( "`time` DESC" ) . Find ( & idAry ) . Error
if err != nil && len ( idAry ) < 1 {
publicmethod . ResultList ( 0 , requestData . Page , requestData . PageSize , total , int64 ( len ( idAry ) ) , idAry , c )
return
}
var manContList [ ] modelshr . ManCont
err = overall . CONSTANT_DB_HR . Where ( "`id` IN ?" , idAry ) . Order ( "`time` DESC" ) . Find ( & manContList ) . Error
if err != nil {
publicmethod . ResultList ( 0 , requestData . Page , requestData . PageSize , total , int64 ( len ( idAry ) ) , idAry , c )
return
}
var sendList [ ] SendPowerPeople
for _ , v := range manContList {
var sendCont SendPowerPeople
sendCont . ManCont = v
if v . Position != 0 {
var postCont modelshr . Position
postCont . GetCont ( map [ string ] interface { } { "`id`" : v . Position } , "`name`" )
sendCont . PositionName = postCont . Name
}
sendCont . KeyStr = strconv . FormatInt ( v . Key , 10 )
var orgAllName [ ] string
if v . Company != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . Company } , "`name`" )
if orgCont . Name != "" {
if ! publicmethod . IsInTrue [ string ] ( orgCont . Name , orgAllName ) {
orgAllName = append ( orgAllName , orgCont . Name )
}
}
}
if v . MainDeparment != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . MainDeparment } , "`name`" )
if orgCont . Name != "" {
if ! publicmethod . IsInTrue [ string ] ( orgCont . Name , orgAllName ) {
orgAllName = append ( orgAllName , orgCont . Name )
}
}
}
if v . SunMainDeparment != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . SunMainDeparment } , "`name`" )
if orgCont . Name != "" {
if ! publicmethod . IsInTrue [ string ] ( orgCont . Name , orgAllName ) {
orgAllName = append ( orgAllName , orgCont . Name )
}
}
}
if v . AdminOrg != 0 {
var orgCont modelshr . AdministrativeOrganization
orgCont . GetCont ( map [ string ] interface { } { "`id`" : v . AdminOrg } , "`name`" )
if orgCont . Name != "" {
if ! publicmethod . IsInTrue [ string ] ( orgCont . Name , orgAllName ) {
orgAllName = append ( orgAllName , orgCont . Name )
}
}
}
sendCont . OrgAllName = strings . Join ( orgAllName , " / " )
sendCont . PersonInCharge = 2
if v . PersonInCharge == 1 {
orgResList := strings . Split ( v . ResponsibleDepartment , "," )
if len ( orgResList ) > 0 {
orgIdStr := strconv . FormatInt ( int64 ( requestData . OrgId ) , 10 )
if publicmethod . IsInTrue [ string ] ( orgIdStr , orgResList ) == true {
sendCont . PersonInCharge = 1
}
}
}
sendList = append ( sendList , sendCont )
}
publicmethod . ResultList ( 0 , requestData . Page , requestData . PageSize , total , int64 ( len ( sendList ) ) , sendList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 12 - 03 15 : 48 : 03
@ 功能 : 新增人员
* /
func ( a * ApiMethod ) AddNewPeople ( c * gin . Context ) {
var requestData PeopleInfo
err := c . ShouldBindJSON ( & requestData )
if requestData . OrgId == 0 {
publicmethod . Result ( 100 , err , c , "请选择归属部门" )
return
}
if requestData . Name == "" {
publicmethod . Result ( 100 , err , c , "请输入姓名" )
return
}
if requestData . Code == "" {
publicmethod . Result ( 100 , err , c , "请输入工号" )
return
}
if requestData . Mobile == "" {
publicmethod . Result ( 100 , err , c , "请输入联系电话" )
return
}
if requestData . Employment == "" {
publicmethod . Result ( 100 , err , c , "请选择用工关系" )
return
}
sexVal := 1
sexVal , swxErr := strconv . Atoi ( requestData . Sex )
if swxErr != nil {
sexVal = 1
}
var myInfoOld modelshr . PersonArchives
myInfoOld . GetCont ( map [ string ] interface { } { "`number`" : requestData . Code } , "`id`" )
if myInfoOld . Id != 0 {
publicmethod . Result ( 100 , err , c , "该工号已被使用请不要重复使用!" )
return
}
uuid := publicmethod . GetUUid ( 1 )
var myInfo modelshr . PersonArchives
myInfo . Key = uuid
myInfo . Name = requestData . Name
myInfo . Number = requestData . Code
myInfo . Icon = requestData . Icon
_ , myInfo . Company , myInfo . MainDeparment , myInfo . SunMainDeparment , myInfo . AdminOrg = publicmethod . GetOrgStructurees ( requestData . OrgId )
myInfo . EmpType , _ = strconv . Atoi ( requestData . Employment )
var myAboutInfo modelshr . PersonnelContent
myAboutInfo . Number = requestData . Code
myAboutInfo . NameUsedBefore = requestData . OldName
myAboutInfo . Mobilephone = requestData . Mobile
myAboutInfo . Myfolk = requestData . Nation
myAboutInfo . Gender = sexVal
var creTimeAll publicmethod . DateTimeTotimes
creTimeAll . BaisStrToTime ( requestData . Age )
myAboutInfo . Birthday = creTimeAll . AllTime
myAboutInfo . Currentresidence = requestData . Address
myAboutInfo . Health , _ = strconv . Atoi ( requestData . BodyStatus )
myAboutInfo . Maritalstatus , _ = strconv . Atoi ( requestData . MarriageStatus )
myAboutInfo . Key = uuid
err = overall . CONSTANT_DB_HR . Create ( & myInfo ) . Error
if err == nil {
overall . CONSTANT_DB_HR . Create ( & myAboutInfo )
publicmethod . Result ( 0 , err , c )
} else {
publicmethod . Result ( 104 , err , c )
}
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 12 - 04 14 : 21 : 21
@ 功能 : 编辑自己登陆密码
* /
func ( a * ApiMethod ) EditMyPwd ( c * gin . Context ) {
var requestData SaveMyPwd
err := c . ShouldBindJSON ( & requestData )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if requestData . OldPassword == "" || requestData . NewPassword == "" || requestData . ConfirmPassword == "" {
publicmethod . Result ( 1 , requestData , c , "您输入的数据不符合要求!" )
return
}
if requestData . NewPassword != requestData . ConfirmPassword {
publicmethod . Result ( 2 , err , c , "您输入的数据不符合要求!" )
return
}
//获取当前操作人
context , _ := c . Get ( overall . MyContJwt )
var myContInfo modelshr . ManCont
jsonCont , _ := json . Marshal ( context )
json . Unmarshal ( jsonCont , & myContInfo )
var oldPwd publicmethod . Md5Encryption
oldPwd . Md5EncryptionInit ( requestData . OldPassword )
oldPwdMd5 := oldPwd . Md5EncryptionAlgorithm ( )
if oldPwdMd5 != myContInfo . Password {
publicmethod . Result ( 3 , err , c , "您输入的数据不符合要求!" )
return
}
var newPwd publicmethod . Md5Encryption
newPwd . Md5EncryptionInit ( requestData . ConfirmPassword )
saveData := publicmethod . MapOut [ string ] ( )
saveData [ "`password`" ] = newPwd . Md5EncryptionAlgorithm ( )
saveData [ "`eite_time`" ] = time . Now ( ) . Unix ( )
var myInfo modelshr . PersonArchives
err = myInfo . EiteCont ( map [ string ] interface { } { "`key`" : myContInfo . Key } , saveData )
if err != nil {
publicmethod . Result ( 104 , err , c , "" )
return
}
publicmethod . Result ( 0 , err , c )
}