package personnelapi import ( "encoding/json" "fmt" "hr_server/models" personalitycolor "hr_server/models/personalityColor" "hr_server/overall" "hr_server/overall/overallhandle" "reflect" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2024-01-20 16:20:09 @ 功能: 根据工号获取个人档案 @ 参数 # @ 返回值 # @ 方法原型 # */ func (s *StaffApi) PersonnelFiles(c *gin.Context) { var requestData overallhandle.NmuberOverall err := c.ShouldBindJSON(&requestData) if err != nil { overallhandle.Result(101, requestData, c) return } if requestData.Number == "" { overallhandle.Result(1, requestData, c, "未知人员!不可查询信息") return } var myInfo models.ManCont err = myInfo.GetCont(map[string]interface{}{"`number`": requestData.Number}) if err != nil { overallhandle.Result(105, err, c) return } saveInfo := overallhandle.MapOut() structValue := reflect.ValueOf(myInfo) structType := structValue.Type() for i := 0; i < structValue.NumField(); i++ { fieldValue := structValue.Field(i) fieldType := structType.Field(i) saveInfo[fieldType.Name] = fieldValue.Interface() } if myInfo.Birthday != 0 { saveInfo["birthdayTime"] = overallhandle.UnixTimeToDay(myInfo.Birthday, 14) //生日 } if myInfo.Entrydate != 0 { saveInfo["EntrydateTime"] = overallhandle.UnixTimeToDay(myInfo.Entrydate, 14) //入职日期 } //部门 if myInfo.MainDeparment != 0 { var demperMainInfos models.AdministrativeOrganization demperMainInfos.GetCont(map[string]interface{}{"`id`": myInfo.MainDeparment}, "`name`") saveInfo["MainDeparmentName"] = demperMainInfos.Name } //岗位 if myInfo.AdminOrg != 0 { var adminOrg models.AdministrativeOrganization adminOrg.GetCont(map[string]interface{}{"`id`": myInfo.AdminOrg}, "`name`") saveInfo["AdminOrgName"] = adminOrg.Name } //职务 if myInfo.Position != 0 { var postisInfo models.Position postisInfo.GetCont(map[string]interface{}{"`id`": myInfo.Position}, "`name`", "`person_in_charge`") saveInfo["PositionName"] = postisInfo.Name saveInfo["PersonInCharge"] = postisInfo.PersonInCharge } if myInfo.Isdoubleworker == 1 { var doubleWorkerInfo models.DoubleWorker doubleWorkerInfo.GetCont(map[string]interface{}{"`number`": myInfo.Number, "`state`": 1}, "`name`", "`company`", "`department`", "`position`") saveInfo["WorkCompany"] = fmt.Sprintf("%v%v%v%v", doubleWorkerInfo.Name, doubleWorkerInfo.Company, doubleWorkerInfo.Department, doubleWorkerInfo.Position) } else { saveInfo["WorkCompany"] = "" } saveInfo["GenderName"] = overallhandle.GenderStatus(int64(myInfo.Gender)) saveInfo["ConstellationName"] = overallhandle.StarSign(int64(myInfo.Constellation)) saveInfo["PolitOutlook"] = overallhandle.PoliticalIdentity(int64(myInfo.PoliticalOutlook)) saveInfo["Maristatus"] = overallhandle.MaritalStatus(int64(myInfo.Maritalstatus)) //教育经历 synPro.Add(1) go func() { saveInfo["EducationalExperience"] = UserEducationalExperience(myInfo.Key) }() //工作履历 synPro.Add(1) go func() { saveInfo["ExternalWork"] = getWorkHistoryList(myInfo.Key) //工作履历 }() //集团内工作履历 synPro.Add(1) go func() { saveInfo["InternalWork"] = getGroupWorkHistoryList(myInfo.Key) //工作履历 }() //职称证书 synPro.Add(1) go func() { AcademicTitle := GainCertificateHonors(myInfo.Key, 1) saveInfo["AcademicTitle"] = strings.Join(AcademicTitle, ",") //工作履历 }() //资格证书 synPro.Add(1) go func() { Diploma := GainCertificateHonors(myInfo.Key, 2) saveInfo["Diploma"] = strings.Join(Diploma, ",") //工作履历 }() currentTime := time.Now() years := currentTime.Year() - 1 //绩效成绩 Performance score synPro.Add(1) go func() { saveInfo["Meritslog"] = GainTimeLangMeritslog(myInfo.Key, years, 2) //工作履历 }() //获奖情况 synPro.Add(1) go func() { saveInfo["Rewards"] = GainRewardsPenalties(myInfo.Key, years, 2, 1) //工作履历 }() //惩罚情况 synPro.Add(1) go func() { saveInfo["Penalties"] = GainRewardsPenalties(myInfo.Key, years, 2, 2) //工作履历 }() //性格社彩 synPro.Add(1) go func() { xgsc := GainCharacterColor(myInfo.Number) saveInfo["CharacterColour"] = strings.Join(xgsc.TestNumber, "、") //工作履历 }() synPro.Wait() overallhandle.Result(0, saveInfo, c) } /* * @ 作者: 秦东 @ 时间: 2024-01-24 08:08:43 @ 功能: 获取性格色彩 @ 参数 # @ 返回值 # @ 方法原型 # */ func GainCharacterColor(num string) (tpr TestPageColorResult) { synPro.Done() var myColor personalitycolor.Charcolortest err := myColor.GetCont(map[string]interface{}{"`c_states`": 1, "`c_number`": num}) if err != nil { return } var testPage []TestPageColor if myColor.TestJson != "" { json.Unmarshal([]byte(myColor.TestJson), &testPage) } GetColorVal := JiSuanColor(testPage) var ColorStrAry []TestPageColorVal var redColor TestPageColorVal redColor.Strval = GetColorVal["RedColor"] redColor.Name = "红色" redColor.Setval = 1 ColorStrAry = append(ColorStrAry, redColor) var blueColor TestPageColorVal blueColor.Strval = GetColorVal["BlueColor"] blueColor.Name = "蓝色" blueColor.Setval = 1 ColorStrAry = append(ColorStrAry, blueColor) var yellowColor TestPageColorVal yellowColor.Strval = GetColorVal["YellowColor"] yellowColor.Name = "黄色" yellowColor.Setval = 1 ColorStrAry = append(ColorStrAry, yellowColor) var greenColor TestPageColorVal greenColor.Strval = GetColorVal["GreenColor"] greenColor.Name = "绿色" greenColor.Setval = 1 ColorStrAry = append(ColorStrAry, greenColor) var colorAry []int colorAry = append(colorAry, GetColorVal["RedColor"]) colorAry = append(colorAry, GetColorVal["BlueColor"]) colorAry = append(colorAry, GetColorVal["YellowColor"]) colorAry = append(colorAry, GetColorVal["GreenColor"]) MaxColor := overallhandle.GetMaxNum[int](colorAry) for _, v := range ColorStrAry { if v.Strval == MaxColor { if !overallhandle.IsInTrue[int](v.Setval, tpr.CheckedVal) { tpr.CheckedVal = append(tpr.CheckedVal, v.Setval) } if !overallhandle.IsInTrue[string](v.Name, tpr.TestNumber) { tpr.TestNumber = append(tpr.TestNumber, v.Name) } } } return } // 计算颜色 func JiSuanColor(testPage []TestPageColor) map[string]int { if len(testPage) < 1 { sendDataw := make(map[string]int) sendDataw["RedColor"] = 0 sendDataw["BlueColor"] = 0 sendDataw["YellowColor"] = 0 sendDataw["GreenColor"] = 0 return sendDataw } A_front_count := 0 B_front_count := 0 C_front_count := 0 D_front_count := 0 A_after_count := 0 B_after_count := 0 C_after_count := 0 D_after_count := 0 for _, v := range testPage { testNumInt, _ := strconv.Atoi(v.TestNumber) checkedValInt, _ := strconv.Atoi(v.CheckedVal) if testNumInt <= 15 { switch checkedValInt { case 2: B_front_count++ case 3: C_front_count++ case 4: D_front_count++ default: A_front_count++ } } else { switch checkedValInt { case 2: B_after_count++ case 3: C_after_count++ case 4: D_after_count++ default: A_after_count++ } } } RedColor := A_front_count + D_after_count BlueColor := B_front_count + C_after_count YellowColor := C_front_count + B_after_count GreenColor := D_front_count + A_after_count sendData := make(map[string]int) sendData["RedColor"] = RedColor sendData["BlueColor"] = BlueColor sendData["YellowColor"] = YellowColor sendData["GreenColor"] = GreenColor sendData["A_front_count"] = A_front_count sendData["B_front_count"] = B_front_count sendData["C_front_count"] = C_front_count sendData["D_front_count"] = D_front_count sendData["A_after_count"] = A_after_count sendData["B_after_count"] = B_after_count sendData["C_after_count"] = C_after_count sendData["D_after_count"] = D_after_count return sendData } /* * @ 作者: 秦东 @ 时间: 2024-01-23 15:42:56 @ 功能: 奖惩记录 @ 参数 #userKey 人员KEY #years 当前年 #duration 倒查几年 #class 奖励还是惩罚 @ 返回值 # @ 方法原型 # */ func GainRewardsPenalties(userKey int64, years, duration, class int) map[string]interface{} { synPro.Done() sendData := overallhandle.MapOut() if duration > 0 { // fmt.Printf("奖惩记录111111: %v\n", duration) for i := duration; i >= 0; i-- { // fmt.Printf("奖惩记录33333: %v\n", i) timeVal := years - i var allScore []map[string]interface{} overall.CONSTANT_DB_HR.Model(&models.RewardsPenalties{}).Where("`state` = 1 AND `userkey` = ? AND `years` = ? AND `type` = ?", userKey, timeVal, class).Find(&allScore) // fmt.Printf("奖惩记录11111: %v\n", err) timeValStr := strconv.Itoa(timeVal) sendData[timeValStr] = allScore // fmt.Printf("奖惩记录: %s\n", timeValStr) } } else { var allScore map[string]interface{} overall.CONSTANT_DB_HR.Model(&models.RewardsPenalties{}).Where("`state` = 1 AND `userkey` = ? AND `years` = ? AND `type` = ?", userKey, years, class).Find(&allScore) timeValStr := strconv.Itoa(years) sendData[timeValStr] = allScore } return sendData } /* * @ 作者: 秦东 @ 时间: 2024-01-23 15:20:52 @ 功能: 获取多长时间的绩效 @ 参数 #userKey 人员KEY #years 当前年 #duration 倒查几年 @ 返回值 # @ 方法原型 # */ func GainTimeLangMeritslog(userKey int64, years, duration int) map[string]interface{} { synPro.Done() sendData := overallhandle.MapOut() if duration > 0 { for i := duration; i >= 0; i-- { timeVal := years - i var allScore int64 overall.CONSTANT_DB_HR.Model(&models.Meritslog{}).Select("SUM(`score`) as scoresum").Where("`status` = 1 AND `userkey` = ? AND `years` = ?", userKey, timeVal).Find(&allScore) timeValStr := strconv.Itoa(timeVal) if allScore > 0 { sendData[timeValStr] = float64(allScore) / 10000 } else { sendData[timeValStr] = 0 } } } else { var allScore int64 overall.CONSTANT_DB_HR.Model(&models.Meritslog{}).Select("SUM(`score`) as scoresum").Where("`status` = 1 AND `userkey` = ? AND `years` = ?", userKey, years).Find(&allScore) timeValStr := strconv.Itoa(years) if allScore > 0 { sendData[timeValStr] = float64(allScore) / 10000 } else { sendData[timeValStr] = 0 } } return sendData } /* * @ 作者: 秦东 @ 时间: 2024-01-23 15:08:44 @ 功能: 获取证书 @ 参数 # @ 返回值 # @ 方法原型 # */ func GainCertificateHonors(userKey int64, class int) (titleList []string) { synPro.Done() overall.CONSTANT_DB_HR.Model(&models.CertificateHonors{}).Select("`title`").Where("`state` = 1 AND `type` = ? AND `userkey` = ?", class, userKey).Find(&titleList) return } /* * @ 作者: 秦东 @ 时间: 2024-01-23 09:46:31 @ 功能: 获取教育径路 @ 参数 # @ 返回值 # @ 方法原型 # */ func UserEducationalExperience(num int64) (eduExper []educatExp) { defer synPro.Done() var dowWorkMan []models.PersonnelEducation err := overall.CONSTANT_DB_HR.Model(&models.PersonnelEducation{}).Select("`id`", "`education`", "`graduation_school`", "`subject`", "`admission_time`", "`graduation_time`", "`level`,`academic_degree`").Where("`state` = 1 AND `key` = ?", num).Order("`level` desc").Find(&dowWorkMan).Error if err != nil { return } for _, v := range dowWorkMan { var dwManCont educatExp // dwManCont.GraduationSchool = v.GraduationSchool //毕业学校 dwManCont.Subject = v.Subject //专业 dwManCont.Education = v.Education //学历 dwManCont.EducationName = overallhandle.EducationLevel(int64(v.Education)) if v.AdmissionTime != 0 { dwManCont.AdmissionTime = overallhandle.UnixTimeToDay(v.AdmissionTime, 14) //入学时间 } if v.GraduationTime != 0 { dwManCont.GraduationTime = overallhandle.UnixTimeToDay(v.GraduationTime, 14) //毕业时间 } dwManCont.AcademicDegree = overallhandle.AcademicDegree(int64(v.AcademicDegree)) //学位 dwManCont.AcademicDegreeId = v.AcademicDegree dwManCont.Level = overallhandle.GetXueWeiClass(int64(v.Level)) dwManCont.LevelId = v.Level //学历类型 dwManCont.Id = strconv.FormatInt(v.Id, 10) dwManCont.EducationTypeName = overallhandle.EducationType(int64(v.EducationType)) eduExper = append(eduExper, dwManCont) } return }