package personnelapi
import (
"fmt"
"hr_server/models"
"hr_server/overall"
"hr_server/overall/overallhandle"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
//人员列表
func ( s * StaffApi ) StaffList ( c * gin . Context ) {
var requestData peopleList
c . ShouldBindJSON ( & requestData )
if requestData . Page < 0 {
requestData . Page = 1
}
if requestData . PageSize < 0 {
requestData . PageSize = 10
}
// gormDb := overall.CONSTANT_DB_HR.Model(&models.JobClass{}).Select("").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type")
var personnelModels models . Personnel
gormDb := overall . CONSTANT_DB_HR . Table ( fmt . Sprintf ( "%s p" , personnelModels . TableName ( ) ) ) . Select ( "p.*,pc.mobilephone,pc.gender,pc.isdoubleworker,pc.isveterans,pc.entrydate,pc.probationperiod,pc.planformaldate" ) . Joins ( "left join personnel_content as pc on pc.number = p.number" )
if requestData . Number != "" {
gormDb = gormDb . Where ( "p.number LIKE ?" , "%" + requestData . Number + "%" )
}
if requestData . Name != "" {
gormDb = gormDb . Where ( "p.name LIKE ?" , "%" + requestData . Name + "%" )
}
if requestData . HireClass != 0 {
gormDb = gormDb . Where ( "p.hire_class = ?" , requestData . HireClass )
}
if requestData . Company != 0 {
gormDb = gormDb . Where ( "p.company = ?" , requestData . Company )
}
// if requestData.Deparment != "" {
// gormDb = gormDb.Where("FIND_IN_SET(?,p.`deparment`)", requestData.Deparment)
// }
if requestData . AdminOrg != 0 {
gormDb = gormDb . Where ( "p.admin_org = ?" , requestData . AdminOrg )
}
if requestData . Position != 0 {
gormDb = gormDb . Where ( "p.position = ?" , requestData . Position )
}
if requestData . EmpType != 0 {
gormDb = gormDb . Where ( "p.emp_type = ?" , requestData . EmpType )
} else {
gormDb = gormDb . Where ( "p.emp_type IN ?" , overall . EmployeeStatusIng )
}
if requestData . Role != "" {
gormDb = gormDb . Where ( "FIND_IN_SET(?,p.`role`)" , requestData . Role )
}
gormDb = gormDb . Where ( "p.state = 1" )
var total int64
totalErr := gormDb . Count ( & total ) . Error
if totalErr != nil {
total = 0
}
var positionAry [ ] peopleOutList
errGorm := gormDb . Order ( "p.company ASC,p.deparment ASC,p.admin_org ASC,p.position ASC" ) . Limit ( requestData . PageSize ) . Offset ( overallhandle . LimitPage ( requestData . Page , requestData . PageSize ) ) . Find ( & positionAry ) . Error
fmt . Printf ( "%v\n" , positionAry )
for i , v := range positionAry {
positionAry [ i ] . KeyStr = strconv . FormatInt ( positionAry [ i ] . Key , 10 )
var getSpur models . Position
getWhe := overallhandle . MapOut ( )
getWhe [ "id" ] = v . Position
getSpur . GetCont ( getWhe , "name" )
positionAry [ i ] . PositionName = getSpur . Name
var getSpurDepart models . AdministrativeOrganization
getWheDepart := overallhandle . MapOut ( )
getWheDepart [ "id" ] = v . Company
getSpurDepart . GetCont ( getWheDepart , "name" )
positionAry [ i ] . CompanyName = getSpurDepart . Name
//获取部门
departmentAry := strings . Split ( v . Deparment , "," )
if len ( departmentAry ) > 0 {
var departCont [ ] getDepartmentInfo
departErr := overall . CONSTANT_DB_HR . Model ( & models . AdministrativeOrganization { } ) . Select ( "id,number,name" ) . Where ( "`id` IN ?" , departmentAry ) . Order ( "`organization_type` ASC" ) . Find ( & departCont ) . Error
if departErr == nil {
var departNameAry [ ] string
for _ , d_v := range departCont {
departNameAry = append ( departNameAry , d_v . Name )
}
if len ( departNameAry ) > 0 {
positionAry [ i ] . DeparmentName = strings . Join ( departNameAry , " " )
}
}
}
}
if errGorm != nil {
overallhandle . Result ( 105 , errGorm , c )
} else {
overallhandle . ResultList ( 0 , requestData . Page , requestData . PageSize , total , int64 ( len ( positionAry ) ) , positionAry , c )
}
}
//添加员工
func ( s * StaffApi ) AddStaff ( c * gin . Context ) {
var requestData addPersonnel
c . ShouldBindJSON ( & requestData )
if requestData . Number == "" {
overallhandle . Result ( 1 , requestData . Number , c , "工号不能为空!" )
return
}
if requestData . Name == "" {
overallhandle . Result ( 1 , requestData . Name , c , "姓名不能为空!" )
return
}
if requestData . Gender == 0 {
requestData . Gender = 1
}
if requestData . HireType == 0 {
requestData . HireType = 1
}
if requestData . PoliticalOutlook == 0 {
requestData . PoliticalOutlook = 1
}
if requestData . AdminOrg == 0 {
overallhandle . Result ( 1 , requestData . Position , c , "请选择员工归属行政组织!" )
return
}
// if len(requestData.Department) < 1 {
// overallhandle.Result(1, requestData.Department, c, "请您选择该员工归属哪个分厂(部室)!")
// return
// }
if requestData . Position == 0 {
overallhandle . Result ( 1 , requestData . Position , c , "请分配员工职位(岗位)!" )
return
}
if requestData . EmpType == 0 {
requestData . EmpType = 2
}
if requestData . PositionGrade == 0 {
overallhandle . Result ( 1 , requestData . PositionGrade , c , "请分配员入职等级!" )
return
}
if requestData . ProbationPeriod == 0 {
requestData . ProbationPeriod = 3
}
if requestData . Constellation == 0 {
requestData . Constellation = 1
}
if requestData . Health == 0 {
requestData . Health = 2
}
if requestData . Maritalstatus == 0 {
requestData . Maritalstatus = 1
}
if requestData . Iisdoubleworker == 0 {
requestData . Iisdoubleworker = 2
} else {
if requestData . Iisdoubleworker == 1 {
if len ( requestData . DoubleWorkerList ) < 0 {
overallhandle . Result ( 1 , requestData . DoubleWorkerList , c , "请输入配偶信息!" )
return
}
}
}
if requestData . Isveterans == 0 {
requestData . Isveterans = 2
} else {
if requestData . Isveterans == 1 && requestData . Veteransnumber == "" {
overallhandle . Result ( 1 , requestData . Veteransnumber , c , "请输入退役证编号!" )
return
}
}
if requestData . Password == "" && requestData . EmpType != 9 {
requestData . Password = overall . CONSTANT_CONFIG . Appsetup . DefaultPassword
}
//员工档案主
var staffInfo models . PersonArchives
//判断工号是存在
whereAry := overallhandle . MapOut ( )
whereAry [ "number" ] = requestData . Number
if judgeNoErr := staffInfo . GetCont ( whereAry , "number" ) ; judgeNoErr == nil {
overallhandle . Result ( 1 , requestData , c , "该工号已经被使用!请不要重复使用!" )
return
}
staffInfo . Number = requestData . Number
staffInfo . Name = requestData . Name
staffInfo . Icon = requestData . Icon
staffInfo . HireClass = requestData . HireType
staffInfo . EmpType = requestData . EmpType
// mainDepartmentId, _ := strconv.ParseInt(requestData.MainDepartment, 10, 64)
_ , companyId , departmentId , sunDepartId , _ := overallhandle . GetOrgStructure ( requestData . AdminOrg )
staffInfo . Company = companyId
staffInfo . MainDeparment = departmentId
staffInfo . SunMainDeparment = sunDepartId
// staffInfo.Deparment = strings.Join(requestData.Department, ",")
staffInfo . AdminOrg = requestData . AdminOrg
teamIdInt , _ := strconv . ParseInt ( requestData . Team , 10 , 64 )
staffInfo . TeamId = teamIdInt
staffInfo . Position = requestData . Position
//获取职务信息
var postDuitesCont models . PostDutiesJob
jobErr := postDuitesCont . GetCont ( map [ string ] interface { } { "id" : requestData . Position } , "duties" )
// jobCont, jobErr := getJobInfo(requestData.Position)
if jobErr == nil {
staffInfo . JobClass = postDuitesCont . JobType
staffInfo . JobId = postDuitesCont . Duties
}
staffInfo . JobLeve = requestData . PositionGrade
staffInfo . Time = time . Now ( ) . Unix ( )
staffInfo . EiteTime = time . Now ( ) . Unix ( )
staffInfo . State = 1
// staffInfo.Password = requestData.Password
if requestData . Password != "" {
var md5JiaMi overallhandle . Md5Encryption
md5JiaMi . Md5EncryptionInit ( requestData . Password )
md5Token := md5JiaMi . Md5EncryptionAlgorithm ( )
staffInfo . Password = md5Token
}
manKeyNum := overallhandle . TableNumber ( )
staffInfo . Key = manKeyNum
staffInfo . IsAdmin = 1
staffInfo . Role = ""
peopleMasterErr := overall . CONSTANT_DB_HR . Create ( & staffInfo ) . Error
if peopleMasterErr != nil {
overallhandle . Result ( 104 , staffInfo , c )
return
}
//员工档案附表
synPro . Add ( 1 )
go staffInfoCont ( manKeyNum , requestData )
//双职工
if requestData . Iisdoubleworker == 1 {
synPro . Add ( 1 )
go doubleWorkerStaff ( manKeyNum , requestData . Number , requestData . DoubleWorkerList )
}
//人员变动记录
// synPro.Add(1)
// go peopleGaiDong(staffInfo)
//教育经历
if len ( requestData . EducationalExperience ) > 0 {
synPro . Add ( 1 )
go eduExperience ( manKeyNum , requestData . Number , requestData . EducationalExperience )
}
//紧急联系人
if len ( requestData . EmergencyContact ) > 0 {
synPro . Add ( 1 )
go emeContact ( manKeyNum , requestData . Number , requestData . EmergencyContact )
}
//家庭成员
if len ( requestData . MemberOfFamily ) > 0 {
synPro . Add ( 1 )
go familyPeople ( manKeyNum , requestData . Number , requestData . MemberOfFamily )
}
//工作履历
if len ( requestData . WorkHistoryList ) > 0 {
synPro . Add ( 1 )
go workHistoryLog ( manKeyNum , requestData . Number , requestData . WorkHistoryList )
}
//公司内部工作履历
if len ( requestData . InsideWorkHistory ) > 0 {
synPro . Add ( 1 )
go workInsideHistoryLog ( manKeyNum , requestData . Number , requestData . InsideWorkHistory )
}
synPro . Wait ( )
overallhandle . Result ( 0 , staffInfo , c )
}
//获取职务相关属性
func getJobInfo ( jobId int64 ) ( cont jobAttber , err error ) {
var positionInfo models . Position
err = overall . CONSTANT_DB_HR . Model ( & positionInfo ) . Select ( "position.id,position.number,position.name,position.person_in_charge,d.id as dutid,d.name as dutname,d.number as dutnumber,j.id as jobid,j.name as jobname" ) . Joins ( "left join duties as d on d.id = position.duties" ) . Joins ( "left join job_class as j on j.id = d.job_type" ) . Where ( "`position`.`id` = ?" , jobId ) . First ( & cont ) . Error
return
}
//员工档案详情
func staffInfoCont ( manKeyNum int64 , contData addPersonnel ) {
defer synPro . Done ( )
var staffAttribute models . PersonnelContent
contErr := staffAttribute . GetCont ( map [ string ] interface { } { "`key`" : manKeyNum } )
if contErr == nil {
saveData := overallhandle . MapOut ( )
if contData . Passportno != "" && contData . Passportno != staffAttribute . Passportno {
saveData [ "passportno" ] = contData . Passportno
}
if contData . Globalroaming != "" && contData . Globalroaming != staffAttribute . Globalroaming {
saveData [ "globalroaming" ] = contData . Globalroaming
}
if contData . IDCardNo != "" && contData . IDCardNo != staffAttribute . Idcardno {
saveData [ "idcardno" ] = contData . IDCardNo
}
if contData . IDCardStartTime != "" {
idCardStarTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardStartTime ) )
if idCardStarTime != staffAttribute . Idcardstartdate {
saveData [ "idcardstartdate" ] = idCardStarTime
}
}
if contData . IDCardEndTime != "" {
idCardEndTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardEndTime ) )
if idCardEndTime != staffAttribute . Idcardenddate {
saveData [ "idcardenddate" ] = idCardEndTime
}
}
if contData . IDCardAddress != "" && contData . IDCardAddress != staffAttribute . Idcardaddress {
saveData [ "idcardaddress" ] = contData . IDCardAddress
}
if contData . IDCardIsSued != "" && contData . IDCardIsSued != staffAttribute . IdcardIssued {
saveData [ "idcardIssued" ] = contData . IDCardIsSued
}
if contData . Mobilephone != "" && contData . Mobilephone != staffAttribute . Mobilephone {
saveData [ "mobilephone" ] = contData . Mobilephone
}
if contData . Email != "" && contData . Email != staffAttribute . Email {
saveData [ "email" ] = contData . Email
}
if contData . Gender != 0 && contData . Gender != staffAttribute . Gender {
saveData [ "gender" ] = contData . Gender
}
if contData . Birthday != "" {
brrthday , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . Birthday ) )
if brrthday != staffAttribute . Birthday {
saveData [ "birthday" ] = brrthday
}
}
if contData . Nation != "" && contData . Nation != staffAttribute . Myfolk {
saveData [ "myfolk" ] = contData . Nation
}
if contData . NativePlace != "" && contData . NativePlace != staffAttribute . Nativeplace {
saveData [ "nativeplace" ] = contData . NativePlace
}
if contData . Health != 0 && contData . Health != staffAttribute . Health {
saveData [ "health" ] = contData . Health
}
if contData . Maritalstatus != 0 && contData . Maritalstatus != staffAttribute . Maritalstatus {
saveData [ "maritalstatus" ] = contData . Maritalstatus
}
if contData . CurrentResidence != "" && contData . CurrentResidence != staffAttribute . Currentresidence {
saveData [ "currentresidence" ] = contData . CurrentResidence
}
if contData . Constellation != 0 && contData . Constellation != staffAttribute . Constellation {
saveData [ "constellationing" ] = contData . Constellation
}
if contData . Iisdoubleworker != 0 && contData . Iisdoubleworker != staffAttribute . Isdoubleworker {
saveData [ "isdoubleworker" ] = contData . Iisdoubleworker
// eidtDoubleWorker(contData, contData.Iisdoubleworker)
doubleWorkerStaff ( manKeyNum , staffAttribute . Number , contData . DoubleWorkerList )
}
if contData . Isveterans != 0 && contData . Isveterans != staffAttribute . Isveterans {
saveData [ "isveterans" ] = contData . Isveterans
if contData . Isveterans == 1 {
if contData . Veteransnumber != "" && contData . Veteransnumber != staffAttribute . Veteransnumber {
saveData [ "veteransnumber" ] = contData . Veteransnumber
}
} else {
saveData [ "veteransnumber" ] = ""
}
}
if contData . WorkingDate != "" {
workInData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . WorkingDate ) )
if workInData != staffAttribute . Jobstartdate {
saveData [ "jobstartdate" ] = workInData
}
}
if contData . EntryDate != "" {
entryData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
if entryData != staffAttribute . Entrydate {
saveData [ "entrydate" ] = entryData
}
}
if contData . ProbationPeriod != 0 && contData . ProbationPeriod != staffAttribute . Probationperiod {
saveData [ "probationperiod" ] = contData . ProbationPeriod
entryData := staffAttribute . Entrydate
if contData . EntryDate != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
}
planformalData := overallhandle . GetFutureMonthTime ( entryData , contData . ProbationPeriod , 2 )
saveData [ "planformaldate" ] = planformalData
}
if contData . ConfirmationDate != "" {
planformalData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . ConfirmationDate ) )
saveData [ "planformaldate" ] = planformalData
}
if contData . PoliticalOutlook != 0 && contData . PoliticalOutlook != staffAttribute . PoliticalOutlook {
saveData [ "political_outlook" ] = contData . PoliticalOutlook
}
if len ( saveData ) > 0 {
saveData [ "`time`" ] = time . Now ( ) . Unix ( )
staffAttribute . EiteCont ( map [ string ] interface { } { "`key`" : staffAttribute . Key } , saveData )
}
} else {
staffAttribute . Key = manKeyNum
staffAttribute . Number = contData . Number
staffAttribute . Passportno = contData . Passportno
staffAttribute . Globalroaming = contData . Globalroaming
staffAttribute . Idcardno = contData . IDCardNo
staffAttribute . Mobilephone = contData . Mobilephone
staffAttribute . Email = contData . Email
staffAttribute . Gender = contData . Gender
brrthday , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . Birthday ) )
staffAttribute . Birthday = brrthday
staffAttribute . Myfolk = contData . Nation
staffAttribute . Nativeplace = contData . NativePlace
idCardStarTime := time . Now ( ) . Unix ( )
if contData . IDCardStartTime != "" {
idCardStarTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardStartTime ) )
}
staffAttribute . Idcardstartdate = idCardStarTime //身份证有效期开始
idCardEndTime := time . Now ( ) . Unix ( )
if contData . IDCardEndTime != "" {
idCardEndTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardEndTime ) )
}
staffAttribute . Idcardenddate = idCardEndTime //身份证有效期结束
staffAttribute . Idcardaddress = contData . IDCardAddress //身份证地址
staffAttribute . IdcardIssued = contData . IDCardIsSued //身份证签发机关
staffAttribute . Health = contData . Health
staffAttribute . Maritalstatus = contData . Maritalstatus
staffAttribute . Internaltelephone = ""
staffAttribute . Currentresidence = contData . CurrentResidence
staffAttribute . Time = time . Now ( ) . Unix ( )
staffAttribute . Constellation = contData . Constellation
staffAttribute . Isdoubleworker = contData . Iisdoubleworker
staffAttribute . Isveterans = contData . Isveterans
staffAttribute . Veteransnumber = contData . Veteransnumber
workInData := time . Now ( ) . Unix ( )
if contData . WorkingDate != "" {
workInData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . WorkingDate ) )
}
staffAttribute . Jobstartdate = workInData
entryData := time . Now ( ) . Unix ( )
if contData . EntryDate != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
}
staffAttribute . Entrydate = entryData
staffAttribute . Probationperiod = contData . ProbationPeriod
planformalData := time . Now ( ) . Unix ( )
if contData . ConfirmationDate != "" {
planformalData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . ConfirmationDate ) )
} else {
planformalData = overallhandle . GetFutureMonthTime ( entryData , contData . ProbationPeriod , 2 )
}
staffAttribute . Planformaldate = planformalData
staffAttribute . PoliticalOutlook = contData . PoliticalOutlook
overall . CONSTANT_DB_HR . Create ( & staffAttribute )
}
}
//双职工
func doubleWorkerStaff ( manKeyNum int64 , numStr string , dobleMan [ ] DoubleWorkerInFo ) {
defer synPro . Done ( )
var dwManAry [ ] models . DoubleWorker
dwManAryErr := overall . CONSTANT_DB_HR . Where ( "`key` = ?" , manKeyNum ) . Find ( & dwManAry ) . Error
if dwManAryErr == nil {
var eidtIint [ ] int
for i , v := range dobleMan {
var dwManInfo models . DoubleWorker
dwInFoErr := dwManInfo . GetCont ( map [ string ] interface { } { "`key`" : manKeyNum , "`name`" : v . Name } )
if dwInFoErr == nil {
eidtIint = append ( eidtIint , i )
saveData := overallhandle . MapOut ( )
if v . Number != "" && v . Number != dwManInfo . Number {
saveData [ "number" ] = v . Number
}
if v . Company != "" && v . Company != dwManInfo . Company {
saveData [ "company" ] = v . Company
}
if v . Department != "" && v . Department != dwManInfo . Department {
saveData [ "department" ] = v . Department
}
if v . Position != "" && v . Position != dwManInfo . Position {
saveData [ "position" ] = v . Position
}
if v . Mobilephone != "" && v . Mobilephone != dwManInfo . Tel {
saveData [ "tel" ] = v . Mobilephone
}
if dwManInfo . State != 1 {
saveData [ "state" ] = 1
}
if len ( saveData ) > 0 {
saveData [ "`time`" ] = time . Now ( ) . Unix ( )
dwManInfo . EiteCont ( map [ string ] interface { } { "`id`" : dwManInfo . Id } , saveData )
}
}
}
} else {
var doublePeopleInset [ ] models . DoubleWorker
if len ( dobleMan ) > 0 {
for _ , v := range dobleMan {
var doublePeople models . DoubleWorker
doublePeople . Key = manKeyNum
doublePeople . Number = v . Number
doublePeople . Name = v . Name
doublePeople . Company = v . Company
doublePeople . Department = v . Department
doublePeople . Position = v . Position
doublePeople . Tel = v . Mobilephone
doublePeople . Time = time . Now ( ) . Unix ( )
doublePeopleInset = append ( doublePeopleInset , doublePeople )
}
}
if len ( doublePeopleInset ) > 0 {
overall . CONSTANT_DB_HR . Create ( & doublePeopleInset )
}
}
}
//人员变动记录
func peopleGaiDong ( contData models . Personnel ) {
defer synPro . Done ( )
var pcrInfo models . PersonnelChangeRecord
pcrInfo . Number = contData . Number
pcrInfo . Type = contData . HireClass
reason := ""
switch contData . HireClass {
case 1 :
reason = "雇佣入职"
case 2 :
reason = "再入职"
case 3 :
reason = "职位分配"
case 4 :
reason = "转正"
case 5 :
reason = "停薪留职"
case 6 :
reason = "退休"
case 7 :
reason = "辞退"
case 8 :
reason = "离职"
default :
reason = ""
}
pcrInfo . Reason = reason
pcrInfo . Position = contData . Position
// pcrInfo.JobLevel = strconv.FormatInt(contData.PositionLevel, 10)
// pcrInfo.JobLevel = contData.PositionLevel
pcrInfo . JobLevel = contData . PositionGrade
pcrInfo . Company = contData . Company
pcrInfo . Department = contData . Deparment
pcrInfo . Adminorg = contData . AdminOrg
pcrInfo . Time = time . Now ( ) . Unix ( )
overall . CONSTANT_DB_HR . Create ( & pcrInfo )
}
//教育经历
func eduExperience ( manKeyNum int64 , number string , eduExpAry [ ] educationalExperience ) {
defer synPro . Done ( )
var oldEduExp [ ] models . PersonnelEducation
oldEduExpErr := overall . CONSTANT_DB_HR . Model ( & models . PersonnelEducation { } ) . Select ( "`id`,`graduation_school`,`subject`,`education`" ) . Where ( "`key` = ?" , manKeyNum ) . Find ( & oldEduExp ) . Error
if oldEduExpErr == nil {
var eduExpAryI [ ] int
for i , v := range eduExpAry {
for _ , ov := range oldEduExp {
if v . GraduationSchool == ov . GraduationSchool && v . Subject == ov . Subject && v . Education == ov . Education {
eduExpAryI = append ( eduExpAryI , i )
eidtCont := overallhandle . MapOut ( )
if v . AdmissionTime != "" {
insetTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , v . AdmissionTime ) )
if ov . AdmissionTime != insetTime {
eidtCont [ "admission_time" ] = insetTime
}
}
if v . GraduationTime != "" {
insetEndTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , v . GraduationTime ) )
if ov . GraduationTime != insetEndTime {
eidtCont [ "graduation_time" ] = insetEndTime
}
}
if v . AcademicDegree != strconv . Itoa ( ov . AcademicDegree ) {
acdInt , _ := strconv . Atoi ( v . AcademicDegree )
eidtCont [ "graduation_time" ] = acdInt
}
if v . Level != strconv . Itoa ( ov . Level ) {
acdLeveInt , _ := strconv . Atoi ( v . Level )
eidtCont [ "level" ] = acdLeveInt
}
if ov . State != 1 {
eidtCont [ "state" ] = 1
}
if len ( eidtCont ) > 0 {
eidtCont [ "time" ] = time . Now ( ) . Unix ( )
var eidtPerEduCont models . PersonnelEducation
eidtPerEduCont . EiteCont ( map [ string ] interface { } { "`id`" : ov . Id } , eidtCont )
}
}
}
}
if len ( eduExpAryI ) < len ( eduExpAry ) {
var leaAddExp [ ] models . PersonnelEducation
for ei , ev := range eduExpAry {
if overallhandle . IsInTrue [ int ] ( ei , eduExpAryI ) == false {
var leaExpInfo models . PersonnelEducation
leaExpInfo . Key = manKeyNum
leaExpInfo . Number = number
leaExpInfo . Education = ev . Education
leaExpInfo . GraduationSchool = ev . GraduationSchool
leaExpInfo . Subject = ev . Subject
admissionTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , ev . AdmissionTime ) )
leaExpInfo . AdmissionTime = admissionTime
graduationTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , ev . GraduationTime ) )
leaExpInfo . GraduationTime = graduationTime
leaExpInfo . Time = time . Now ( ) . Unix ( )
if ev . AcademicDegree != "" {
acdInt , _ := strconv . Atoi ( ev . AcademicDegree )
leaExpInfo . Level = acdInt
}
leaExpInfo . State = 1
leaAddExp = append ( leaAddExp , leaExpInfo )
}
}
if len ( leaAddExp ) > 0 {
overall . CONSTANT_DB_HR . Create ( & leaAddExp )
}
}
} else {
//不存在教育经历,进行新增
var leaExp [ ] models . PersonnelEducation
maxLevel := 1
for eei , eev := range eduExpAry {
if maxLevel < eev . Education {
maxLevel = eev . Education
}
var leaExpInfo models . PersonnelEducation
leaExpInfo . Key = manKeyNum
leaExpInfo . Number = number
leaExpInfo . Education = eev . Education
leaExpInfo . GraduationSchool = eev . GraduationSchool
leaExpInfo . Subject = eev . Subject
admissionTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , eev . AdmissionTime ) )
leaExpInfo . AdmissionTime = admissionTime
graduationTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , eev . GraduationTime ) )
leaExpInfo . GraduationTime = graduationTime
leaExpInfo . Time = time . Now ( ) . Unix ( )
if eei == 0 {
leaExpInfo . Level = 2
}
leaExp = append ( leaExp , leaExpInfo )
}
//设定最高学历
if len ( leaExp ) > 1 {
for mei , maxEdv := range leaExp {
if maxEdv . Education != 2 && maxEdv . Education == maxLevel {
leaExp [ mei ] . Level = 3
}
}
}
if len ( leaExp ) > 0 {
overall . CONSTANT_DB_HR . Create ( & leaExp )
}
}
}
//紧急联系人
func emeContact ( manKeyNum int64 , number string , contAry [ ] emergencyContact ) {
defer synPro . Done ( )
var emerContList [ ] models . EmergencyContact
emerContErr := overall . CONSTANT_DB_HR . Where ( "`key` = ?" , manKeyNum ) . Find ( & emerContList ) . Error
if emerContErr == nil {
var eidtIint [ ] int
for i , v := range contAry {
for _ , emv := range emerContList {
if v . Name == emv . Name {
eidtIint = append ( eidtIint , i )
saveData := overallhandle . MapOut ( )
if v . Relationship != "" && v . Relationship != emv . Relationship {
saveData [ "relationship" ] = v . Relationship
}
if v . Mobilephone != "" && v . Mobilephone != emv . Tel {
saveData [ "tel" ] = v . Mobilephone
}
if emv . State != 1 {
saveData [ "state" ] = 1
}
if len ( saveData ) > 0 {
saveData [ "time" ] = time . Now ( ) . Unix ( )
var eidtEmerData models . EmergencyContact
eidtEmerData . EiteCont ( map [ string ] interface { } { "`id`" : emv . Id } , saveData )
}
}
}
}
if len ( eidtIint ) < len ( contAry ) {
var emerContAry [ ] models . EmergencyContact
for ci , cv := range contAry {
if overallhandle . IsInTrue [ int ] ( ci , eidtIint ) == false {
var emerInfo models . EmergencyContact
emerInfo . Key = manKeyNum
emerInfo . Number = number
emerInfo . Name = cv . Name
emerInfo . Relationship = cv . Relationship
emerInfo . Tel = cv . Mobilephone
emerInfo . Time = time . Now ( ) . Unix ( )
emerInfo . State = 1
emerContAry = append ( emerContAry , emerInfo )
}
}
if len ( emerContAry ) > 0 {
overall . CONSTANT_DB_HR . Create ( & emerContAry )
}
}
} else {
var emerContAry [ ] models . EmergencyContact
for _ , emev := range contAry {
var emerInfo models . EmergencyContact
emerInfo . Key = manKeyNum
emerInfo . Number = number
emerInfo . Name = emev . Name
emerInfo . Relationship = emev . Relationship
emerInfo . Tel = emev . Mobilephone
emerInfo . Time = time . Now ( ) . Unix ( )
emerInfo . State = 1
emerContAry = append ( emerContAry , emerInfo )
}
if len ( emerContAry ) > 0 {
overall . CONSTANT_DB_HR . Create ( & emerContAry )
}
}
}
//家庭成员
func familyPeople ( manKeyNum int64 , number string , contAry [ ] memberOfFamily ) {
defer synPro . Done ( )
var familyList [ ] models . FamilyMembers
fllErr := overall . CONSTANT_DB_HR . Where ( "key = ?" , manKeyNum ) . Find ( & familyList ) . Error
if fllErr == nil {
var eidtIint [ ] int
for i , v := range contAry {
for _ , fv := range familyList {
if v . Name == fv . Name {
eidtIint = append ( eidtIint , i )
saveData := overallhandle . MapOut ( )
if v . Relationship != "" && v . Relationship != fv . Relationship {
saveData [ "relation" ] = v . Relationship
}
if v . Mobilephone != "" && v . Mobilephone != fv . Tel {
saveData [ "tel" ] = v . Mobilephone
}
if v . Company != "" && v . Company != fv . Company {
saveData [ "company" ] = v . Company
}
if v . Department != "" && v . Department != fv . Deparment {
saveData [ "deparment" ] = v . Department
}
if v . Position != "" && v . Position != fv . Postnme {
saveData [ "postnme" ] = v . Position
}
if v . PoliticalOutlook != 0 && v . PoliticalOutlook != fv . PoliticalOutlook {
saveData [ "political_outlook" ] = v . PoliticalOutlook
}
if fv . State != 1 {
saveData [ "state" ] = 1
}
if len ( saveData ) > 0 {
var eidtContInfo models . FamilyMembers
eidtContInfo . EiteCont ( map [ string ] interface { } { "`id`" : fv . Id } , saveData )
}
}
}
}
if len ( eidtIint ) < len ( contAry ) {
var familyAry [ ] models . FamilyMembers
for ci , cv := range contAry {
if overallhandle . IsInTrue [ int ] ( ci , eidtIint ) == false {
var familyInfo models . FamilyMembers
familyInfo . Key = manKeyNum
familyInfo . Number = number
familyInfo . Relationship = cv . Relationship
familyInfo . Name = cv . Name
familyInfo . Company = cv . Company
familyInfo . Deparment = cv . Department
familyInfo . Postnme = cv . Position
familyInfo . Tel = cv . Mobilephone
familyInfo . PoliticalOutlook = cv . PoliticalOutlook
familyInfo . Time = time . Now ( ) . Unix ( )
familyAry = append ( familyAry , familyInfo )
}
}
if len ( familyAry ) > 0 {
overall . CONSTANT_DB_HR . Create ( & familyAry )
}
}
} else {
var familyAry [ ] models . FamilyMembers
for _ , fv := range contAry {
var familyInfo models . FamilyMembers
familyInfo . Key = manKeyNum
familyInfo . Number = number
familyInfo . Relationship = fv . Relationship
familyInfo . Name = fv . Name
familyInfo . Company = fv . Company
familyInfo . Deparment = fv . Department
familyInfo . Postnme = fv . Position
familyInfo . Tel = fv . Mobilephone
familyInfo . PoliticalOutlook = fv . PoliticalOutlook
familyInfo . Time = time . Now ( ) . Unix ( )
familyAry = append ( familyAry , familyInfo )
}
if len ( familyAry ) > 0 {
overall . CONSTANT_DB_HR . Create ( & familyAry )
}
}
}
//分配权限
func ( s * StaffApi ) AllocationOfRights ( c * gin . Context ) {
var requestData allocationOfRightsToRole
err := c . ShouldBindJSON ( & requestData )
if err != nil {
overallhandle . Result ( 1 , requestData . Id , c , "数据格式错误!" )
return
}
if requestData . Id == "" {
overallhandle . Result ( 1 , requestData . Id , c , "ID不能为空!" )
return
}
if requestData . RoleId == "" {
overallhandle . Result ( 1 , requestData . RoleId , c , "请选择角色!" )
return
}
var setUserRole models . Personnel
judgeIsTrueWhere := overallhandle . MapOut ( )
judgeIsTrueWhere [ "id" ] = requestData . Id
getUserErr := setUserRole . GetCont ( judgeIsTrueWhere , "role" )
if getUserErr != nil {
overallhandle . Result ( 105 , getUserErr , c )
return
}
if setUserRole . Role != "" {
roleAry := strings . Split ( setUserRole . Role , "," )
if overallhandle . StringIsInMap ( requestData . RoleId , roleAry ) == false {
roleAry = append ( roleAry , requestData . RoleId )
saveData := overallhandle . MapOut ( )
saveData [ "eite_time" ] = time . Now ( ) . Unix ( )
saveData [ "role" ] = strings . Join ( roleAry , "," )
saveErr := setUserRole . EiteCont ( judgeIsTrueWhere , saveData )
if saveErr != nil {
overallhandle . Result ( 106 , saveErr , c )
return
}
overallhandle . Result ( 0 , setUserRole , c )
} else {
overallhandle . Result ( 0 , setUserRole , c )
}
} else {
saveData := overallhandle . MapOut ( )
saveData [ "eite_time" ] = time . Now ( ) . Unix ( )
saveData [ "role" ] = requestData . RoleId
saveErr := setUserRole . EiteCont ( judgeIsTrueWhere , saveData )
if saveErr != nil {
overallhandle . Result ( 106 , saveErr , c )
return
}
overallhandle . Result ( 0 , setUserRole , c )
}
}
//工作履历
func workHistoryLog ( manKeyNum int64 , num string , workHistoryList [ ] workHistoryAry ) {
defer synPro . Done ( )
if len ( workHistoryList ) > 0 && manKeyNum != 0 {
var oldWork [ ] models . WorkHistory
oldWorkErr := overall . CONSTANT_DB_HR . Where ( "`key` = ?" , manKeyNum ) . Find ( & oldWork ) . Error
if oldWorkErr == nil {
for _ , wvs := range workHistoryList {
var whCont models . WorkHistory
isEidtErr := whCont . GetCont ( map [ string ] interface { } { "`key`" : manKeyNum , "`company`" : wvs . Company , "`deparment`" : wvs . Department , "`job`" : wvs . Position } , "id" , "entry_time" , "leavedate" , "witness" , "witness_tel" , "remarks" )
if isEidtErr == nil {
saveDate := overallhandle . MapOut ( )
if wvs . EntryTime != "" { //入职时间"`
entryData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , wvs . EntryTime ) )
if entryData != whCont . EntryTime {
saveDate [ "entry_time" ] = entryData
}
}
if wvs . LeaveDate != "" { //离职日期"`
leaveTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , wvs . LeaveDate ) )
if leaveTime != whCont . Leavedate {
saveDate [ "leavedate" ] = leaveTime
}
}
if wvs . Witness != "" && wvs . Witness != whCont . Witness {
saveDate [ "witness" ] = wvs . Witness
}
if wvs . WitnessTel != "" && wvs . WitnessTel != whCont . WitnessTel {
saveDate [ "witness_tel" ] = wvs . WitnessTel
}
if wvs . Remarks != "" && wvs . Remarks != whCont . Remarks {
saveDate [ "remarks" ] = wvs . Remarks
}
if len ( saveDate ) > 0 {
saveDate [ "time" ] = time . Now ( ) . Unix ( )
saveDate [ "state" ] = 1
var eidtWorkHisCont models . WorkHistory
eidtWorkHisCont . EiteCont ( map [ string ] interface { } { "`id`" : whCont . Id } , saveDate )
}
} else {
var addWorkCont models . WorkHistory
addWorkCont . Number = num //工号"`
addWorkCont . Key = manKeyNum //身份识别"`
addWorkCont . Company = wvs . Company //公司"`
addWorkCont . Deparment = wvs . Department //部门"`
addWorkCont . Job = wvs . Position //职务"`
entryData := time . Now ( ) . Unix ( )
if wvs . EntryTime != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , wvs . EntryTime ) )
}
addWorkCont . EntryTime = entryData //入职时间"`
leaveTime := time . Now ( ) . Unix ( )
if wvs . LeaveDate != "" {
leaveTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , wvs . LeaveDate ) )
}
addWorkCont . Leavedate = leaveTime //离职日期"`
addWorkCont . Witness = wvs . Witness //证明人"`
addWorkCont . WitnessTel = wvs . WitnessTel //证明人电话"`
addWorkCont . Remarks = wvs . Remarks //备注"`
addWorkCont . Time = time . Now ( ) . Unix ( ) //创建时间"`
addWorkCont . State = 1 //状态(1:启用;2:禁用;3:删除)"`
overall . CONSTANT_DB_HR . Create ( & addWorkCont )
}
}
} else {
var addAllWork [ ] models . WorkHistory
for _ , v := range workHistoryList {
var addWorkCont models . WorkHistory
addWorkCont . Number = num //工号"`
addWorkCont . Key = manKeyNum //身份识别"`
addWorkCont . Company = v . Company //公司"`
addWorkCont . Deparment = v . Department //部门"`
addWorkCont . Job = v . Position //职务"`
entryData := time . Now ( ) . Unix ( )
if v . EntryTime != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , v . EntryTime ) )
}
addWorkCont . EntryTime = entryData //入职时间"`
leaveTime := time . Now ( ) . Unix ( )
if v . LeaveDate != "" {
leaveTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 12:00:00" , v . LeaveDate ) )
}
addWorkCont . Leavedate = leaveTime //离职日期"`
addWorkCont . Witness = v . Witness //证明人"`
addWorkCont . WitnessTel = v . WitnessTel //证明人电话"`
addWorkCont . Remarks = v . Remarks //备注"`
addWorkCont . Time = time . Now ( ) . Unix ( ) //创建时间"`
addWorkCont . State = 1 //状态(1:启用;2:禁用;3:删除)"`
addAllWork = append ( addAllWork , addWorkCont )
}
if len ( addAllWork ) > 0 {
overall . CONSTANT_DB_HR . Create ( & addAllWork )
}
}
}
}
//编辑员工主体信息
func ( s * StaffApi ) EidtStaffCont ( c * gin . Context ) {
var requestData eitePersonnel
c . ShouldBindJSON ( & requestData )
if requestData . Id == "" {
overallhandle . Result ( 101 , requestData . Id , c )
return
}
var staffCont models . PersonArchives
err := staffCont . GetCont ( map [ string ] interface { } { "`id`" : requestData . Id } , "`key`" , "`number`" )
if err != nil {
overallhandle . Result ( 105 , err , c )
return
}
saveData := overallhandle . MapOut ( )
if requestData . Name != "" {
saveData [ "name" ] = requestData . Name
}
if requestData . Icon != "" {
saveData [ "icon" ] = requestData . Icon
}
if requestData . HireType != 0 {
saveData [ "hire_class" ] = requestData . HireType
}
if requestData . EmpType != 0 {
saveData [ "emp_type" ] = requestData . EmpType
}
if requestData . Company != 0 {
saveData [ "company" ] = requestData . Company
}
if requestData . MainDepartment != 0 {
saveData [ "maindeparment" ] = requestData . MainDepartment
}
if len ( requestData . Department ) > 0 {
mainDepart := strconv . FormatInt ( requestData . MainDepartment , 10 )
if overallhandle . IsInTrue [ string ] ( mainDepart , requestData . Department ) == false {
requestData . Department = append ( requestData . Department , mainDepart )
}
saveData [ "deparment" ] = strings . Join ( requestData . Department , "," )
}
if requestData . AdminOrg != 0 {
saveData [ "admin_org" ] = requestData . AdminOrg
}
if requestData . Position != 0 {
saveData [ "position" ] = requestData . Position
}
// if requestData.Iisdoubleworker != 0 {
// saveData["job_id"] = requestData.Iisdoubleworker
// }
//获取职务信息
var postDuitesCont models . PostDutiesJob
jobErr := postDuitesCont . GetCont ( map [ string ] interface { } { "id" : requestData . Position } , "duties" )
// jobCont, jobErr := getJobInfo(requestData.Position)
if jobErr == nil {
saveData [ "job_id" ] = postDuitesCont . Duties
saveData [ "job_class" ] = postDuitesCont . JobType
}
if requestData . PositionGrade != 0 {
saveData [ "job_leve" ] = requestData . PositionGrade
}
if len ( saveData ) > 0 {
saveData [ "eite_time" ] = time . Now ( ) . Unix ( )
saveErr := staffCont . EiteCont ( map [ string ] interface { } { "`id`" : staffCont . Id } , saveData )
if saveErr == nil {
//员工档案附表
staffInfoContEidt ( staffCont . Key , staffCont . Number , requestData )
overallhandle . Result ( 0 , saveErr , c )
} else {
overallhandle . Result ( 106 , saveErr , c )
}
} else {
overallhandle . Result ( 0 , err , c )
}
}
//员工档案详情
func staffInfoContEidt ( manKeyNum int64 , num string , contData eitePersonnel ) {
var staffAttribute models . PersonnelContent
contErr := staffAttribute . GetCont ( map [ string ] interface { } { "`key`" : manKeyNum } )
if contErr == nil {
saveData := overallhandle . MapOut ( )
if contData . Passportno != "" && contData . Passportno != staffAttribute . Passportno {
saveData [ "passportno" ] = contData . Passportno
}
if contData . Globalroaming != "" && contData . Globalroaming != staffAttribute . Globalroaming {
saveData [ "globalroaming" ] = contData . Globalroaming
}
if contData . IDCardNo != "" && contData . IDCardNo != staffAttribute . Idcardno {
saveData [ "idcardno" ] = contData . IDCardNo
}
if contData . IDCardStartTime != "" {
idCardStarTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardStartTime ) )
if idCardStarTime != staffAttribute . Idcardstartdate {
saveData [ "idcardstartdate" ] = idCardStarTime
}
}
if contData . IDCardEndTime != "" {
idCardEndTime , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardEndTime ) )
if idCardEndTime != staffAttribute . Idcardenddate {
saveData [ "idcardenddate" ] = idCardEndTime
}
}
if contData . IDCardAddress != "" && contData . IDCardAddress != staffAttribute . Idcardaddress {
saveData [ "idcardaddress" ] = contData . IDCardAddress
}
if contData . IDCardIsSued != "" && contData . IDCardIsSued != staffAttribute . IdcardIssued {
saveData [ "idcardIssued" ] = contData . IDCardIsSued
}
if contData . Mobilephone != "" && contData . Mobilephone != staffAttribute . Mobilephone {
saveData [ "mobilephone" ] = contData . Mobilephone
}
if contData . Email != "" && contData . Email != staffAttribute . Email {
saveData [ "email" ] = contData . Email
}
if contData . Gender != 0 && contData . Gender != staffAttribute . Gender {
saveData [ "gender" ] = contData . Gender
}
if contData . Birthday != "" {
brrthday , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . Birthday ) )
if brrthday != staffAttribute . Birthday {
saveData [ "birthday" ] = brrthday
}
}
if contData . Nation != "" && contData . Nation != staffAttribute . Myfolk {
saveData [ "myfolk" ] = contData . Nation
}
if contData . NativePlace != "" && contData . NativePlace != staffAttribute . Nativeplace {
saveData [ "nativeplace" ] = contData . NativePlace
}
if contData . Health != 0 && contData . Health != staffAttribute . Health {
saveData [ "health" ] = contData . Health
}
if contData . Maritalstatus != 0 && contData . Maritalstatus != staffAttribute . Maritalstatus {
saveData [ "maritalstatus" ] = contData . Maritalstatus
}
if contData . CurrentResidence != "" && contData . CurrentResidence != staffAttribute . Currentresidence {
saveData [ "currentresidence" ] = contData . CurrentResidence
}
if contData . Constellation != 0 && contData . Constellation != staffAttribute . Constellation {
saveData [ "constellationing" ] = contData . Constellation
}
if contData . Iisdoubleworker != 0 && contData . Iisdoubleworker != staffAttribute . Isdoubleworker {
saveData [ "isdoubleworker" ] = contData . Iisdoubleworker
// eidtDoubleWorker(contData, contData.Iisdoubleworker)
doubleWorkerStaffNoXiecheng ( manKeyNum , staffAttribute . Number , contData . DoubleWorkerList )
}
if contData . Isveterans != 0 && contData . Isveterans != staffAttribute . Isveterans {
saveData [ "isveterans" ] = contData . Isveterans
if contData . Isveterans == 1 {
if contData . Veteransnumber != "" && contData . Veteransnumber != staffAttribute . Veteransnumber {
saveData [ "veteransnumber" ] = contData . Veteransnumber
}
} else {
saveData [ "veteransnumber" ] = ""
}
}
if contData . WorkingDate != "" {
workInData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . WorkingDate ) )
if workInData != staffAttribute . Jobstartdate {
saveData [ "jobstartdate" ] = workInData
}
}
if contData . EntryDate != "" {
entryData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
if entryData != staffAttribute . Entrydate {
saveData [ "entrydate" ] = entryData
}
}
if contData . ProbationPeriod != 0 && contData . ProbationPeriod != staffAttribute . Probationperiod {
saveData [ "probationperiod" ] = contData . ProbationPeriod
entryData := staffAttribute . Entrydate
if contData . EntryDate != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
}
planformalData := overallhandle . GetFutureMonthTime ( entryData , contData . ProbationPeriod , 2 )
saveData [ "planformaldate" ] = planformalData
}
if contData . ConfirmationDate != "" {
planformalData , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . ConfirmationDate ) )
saveData [ "planformaldate" ] = planformalData
}
if contData . PoliticalOutlook != 0 && contData . PoliticalOutlook != staffAttribute . PoliticalOutlook {
saveData [ "political_outlook" ] = contData . PoliticalOutlook
}
if len ( saveData ) > 0 {
saveData [ "`time`" ] = time . Now ( ) . Unix ( )
staffAttribute . EiteCont ( map [ string ] interface { } { "`key`" : staffAttribute . Key } , saveData )
}
} else {
staffAttribute . Key = manKeyNum
staffAttribute . Number = num
staffAttribute . Passportno = contData . Passportno
staffAttribute . Globalroaming = contData . Globalroaming
staffAttribute . Idcardno = contData . IDCardNo
staffAttribute . Mobilephone = contData . Mobilephone
staffAttribute . Email = contData . Email
staffAttribute . Gender = contData . Gender
brrthday , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . Birthday ) )
staffAttribute . Birthday = brrthday
staffAttribute . Myfolk = contData . Nation
staffAttribute . Nativeplace = contData . NativePlace
idCardStarTime := time . Now ( ) . Unix ( )
if contData . IDCardStartTime != "" {
idCardStarTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardStartTime ) )
}
staffAttribute . Idcardstartdate = idCardStarTime //身份证有效期开始
idCardEndTime := time . Now ( ) . Unix ( )
if contData . IDCardEndTime != "" {
idCardEndTime , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . IDCardEndTime ) )
}
staffAttribute . Idcardenddate = idCardEndTime //身份证有效期结束
staffAttribute . Idcardaddress = contData . IDCardAddress //身份证地址
staffAttribute . IdcardIssued = contData . IDCardIsSued //身份证签发机关
staffAttribute . Health = contData . Health
staffAttribute . Maritalstatus = contData . Maritalstatus
staffAttribute . Internaltelephone = ""
staffAttribute . Currentresidence = contData . CurrentResidence
staffAttribute . Time = time . Now ( ) . Unix ( )
staffAttribute . Constellation = contData . Constellation
staffAttribute . Isdoubleworker = contData . Iisdoubleworker
staffAttribute . Isveterans = contData . Isveterans
staffAttribute . Veteransnumber = contData . Veteransnumber
workInData := time . Now ( ) . Unix ( )
if contData . WorkingDate != "" {
workInData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . WorkingDate ) )
}
staffAttribute . Jobstartdate = workInData
entryData := time . Now ( ) . Unix ( )
if contData . EntryDate != "" {
entryData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . EntryDate ) )
}
staffAttribute . Entrydate = entryData
staffAttribute . Probationperiod = contData . ProbationPeriod
planformalData := time . Now ( ) . Unix ( )
if contData . ConfirmationDate != "" {
planformalData , _ = overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , contData . ConfirmationDate ) )
} else {
planformalData = overallhandle . GetFutureMonthTime ( entryData , contData . ProbationPeriod , 2 )
}
staffAttribute . Planformaldate = planformalData
staffAttribute . PoliticalOutlook = contData . PoliticalOutlook
overall . CONSTANT_DB_HR . Create ( & staffAttribute )
}
}
//双职工
func doubleWorkerStaffNoXiecheng ( manKeyNum int64 , numStr string , dobleMan [ ] DoubleWorkerInFo ) {
var dwManAry [ ] models . DoubleWorker
dwManAryErr := overall . CONSTANT_DB_HR . Where ( "`key` = ?" , manKeyNum ) . Find ( & dwManAry ) . Error
if dwManAryErr == nil {
var eidtIint [ ] int
for i , v := range dobleMan {
var dwManInfo models . DoubleWorker
dwInFoErr := dwManInfo . GetCont ( map [ string ] interface { } { "`key`" : manKeyNum , "`name`" : v . Name } )
if dwInFoErr == nil {
eidtIint = append ( eidtIint , i )
saveData := overallhandle . MapOut ( )
if v . Company != "" && v . Company != dwManInfo . Company {
saveData [ "company" ] = v . Company
}
if v . Department != "" && v . Department != dwManInfo . Department {
saveData [ "department" ] = v . Department
}
if v . Position != "" && v . Position != dwManInfo . Position {
saveData [ "position" ] = v . Position
}
if v . Mobilephone != "" && v . Mobilephone != dwManInfo . Tel {
saveData [ "tel" ] = v . Mobilephone
}
if dwManInfo . State != 1 {
saveData [ "state" ] = 1
}
if len ( saveData ) > 0 {
saveData [ "`time`" ] = time . Now ( ) . Unix ( )
dwManInfo . EiteCont ( map [ string ] interface { } { "`id`" : dwManInfo . Id } , saveData )
}
}
}
} else {
var doublePeopleInset [ ] models . DoubleWorker
if len ( dobleMan ) > 0 {
for _ , v := range dobleMan {
var doublePeople models . DoubleWorker
doublePeople . Key = manKeyNum
doublePeople . Number = numStr
doublePeople . Name = v . Name
doublePeople . Company = v . Company
doublePeople . Department = v . Department
doublePeople . Position = v . Position
doublePeople . Tel = v . Mobilephone
doublePeople . Time = time . Now ( ) . Unix ( )
doublePeopleInset = append ( doublePeopleInset , doublePeople )
}
}
if len ( doublePeopleInset ) > 0 {
overall . CONSTANT_DB_HR . Create ( & doublePeopleInset )
}
}
}
//
func workInsideHistoryLog ( manKeyNum int64 , num string , workHistoryList [ ] insideHistoryerMy ) {
defer synPro . Done ( )
if len ( workHistoryList ) > 0 && manKeyNum != 0 {
var insetConr [ ] models . InsideWorkHistory
for _ , v := range workHistoryList {
var insetInfor models . InsideWorkHistory
orgIdInt , _ := strconv . ParseInt ( v . OrgId , 10 , 64 )
groupId , companyId , departmentId , sunDepartId , workShopId := overallhandle . GetOrgStructure ( orgIdInt )
insetInfor . Group = groupId
insetInfor . Company = companyId
insetInfor . Department = departmentId
insetInfor . WorkShop = sunDepartId
insetInfor . WorkshopSection = workShopId
positionIdInt , _ := strconv . ParseInt ( v . Position , 10 , 64 )
insetInfor . Position = positionIdInt
insetInfor . GradePositions = v . GradePositions
startTimeInt , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , v . StartTime ) )
insetInfor . StartTime = startTimeInt
if v . EndTime != "" {
endTimeInt , _ := overallhandle . DateToTimeStamp ( fmt . Sprintf ( "%v 00:00:00" , v . EndTime ) )
insetInfor . EndTime = endTimeInt
}
teamIdInt , _ := strconv . ParseInt ( v . Team , 10 , 64 )
insetInfor . Team = teamIdInt
insetInfor . ChangeType = v . ChangeType
insetInfor . AssignType = v . AssignType
insetInfor . Time = time . Now ( ) . Unix ( )
insetInfor . State = 1
insetConr = append ( insetConr , insetInfor )
}
if len ( insetConr ) > 0 {
overall . CONSTANT_DB_HR . Create ( & insetConr )
}
}
}