package departmentpc import ( "encoding/json" "fmt" "key_performance_indicators/api/version1/postseting/postweb" "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2023-01-15 09:42:53 @ 功能: 获取定量考核任务列表 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GetQuantitativeTasks(c *gin.Context) { //获取登录人信息 myLoginCont, _ := publicmethod.LoginMyCont(c) //获取参数 var receivedValue GetQuanTasks c.ShouldBindJSON(&receivedValue) var listCont []modelskpi.QualitativeEvaluation gormDb := overall.CONSTANT_DB_KPI.Where("`qe_type` = 2 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)", myLoginCont.Key) if receivedValue.OrgId != "" { gormDb = gormDb.Where("qe_accept_evaluation = ?", receivedValue.OrgId) } if receivedValue.Title != "" { gormDb = gormDb.Joins("LEFT JOIN evaluationtarget ON et_id = qe_target").Where("et_title LIKE ?", "%"+receivedValue.Title+"%") } err := gormDb.Order("qe_type ASC,qe_group ASC,qe_accept_evaluation ASC,qe_dimension ASC,qe_target ASC,qe_target_sun ASC,qe_detailed_target ASC").Find(&listCont).Error if err != nil || len(listCont) < 1 { publicmethod.Result(1, err, c, "您没有要参加的考核项目!") return } var sendListCont []TargetContOutCont for _, v := range listCont { var sendCont TargetContOutCont sendCont.Id = strconv.FormatInt(v.Id, 10) sendCont.Type = v.Type sendCont.Group = strconv.FormatInt(v.Group, 10) //公司 var groupCont modelshr.AdministrativeOrganization groupCont.GetCont(map[string]interface{}{"`id`": v.Group}, "`name`") sendCont.GroupNAme = groupCont.Name //部门 var departCont modelshr.AdministrativeOrganization departCont.GetCont(map[string]interface{}{"`id`": v.AcceptEvaluation}, "`name`") sendCont.DepartmentName = departCont.Name sendCont.DepartmentId = strconv.FormatInt(v.AcceptEvaluation, 10) sendCont.PlanVersionNumber = v.QualEvalId //执行方案版本号 //维度相关信息 sendCont.Dimension = strconv.FormatInt(v.Dimension, 10) var dimeCont modelskpi.DutyClass dimeCont.GetCont(map[string]interface{}{"`id`": v.Dimension}, "`title`") sendCont.DimensionName = dimeCont.Title //指标信息 sendCont.Target = strconv.FormatInt(v.Target, 10) var targetCont modelskpi.EvaluationTarget targetCont.GetCont(map[string]interface{}{"`et_id`": v.Target}, "`et_title`", "`et_scoring_method`") sendCont.TargetName = targetCont.Title //子栏目 sendCont.ScoringMethod = int64(targetCont.ScoringMethod) if v.TargetSun != 0 { sendCont.TargetSun = strconv.FormatInt(v.TargetSun, 10) var sunTargetCont modelskpi.QualitativeTarget sunTargetCont.GetCont(map[string]interface{}{"`q_id`": v.Target}, "`q_title`") sendCont.TargetSunName = sunTargetCont.Title } //指标细则 if v.DetailedTarget != 0 { sendCont.DetailedTarget = strconv.FormatInt(v.DetailedTarget, 10) var detailedTargetCont modelskpi.DetailedTarget detailedTargetCont.GetCont(map[string]interface{}{"`dt_id`": v.Target}, "`dt_title`", "`dt_content`") sendCont.DetailedTargetName = detailedTargetCont.Title sendCont.Content = detailedTargetCont.Content } sendCont.Unit = v.Unit sendCont.ReferenceScore = v.ReferenceScore sendCont.Cycles = v.Cycles sendCont.CycleAttres = v.CycleAttres sendCont.State = v.State userAry := strings.Split(v.Operator, ",") sendCont.UserList = userAry for _, u_v := range userAry { var repoCont modelshr.PersonArchives repoErr := repoCont.GetCont(map[string]interface{}{"`key`": u_v}, "`number`", "`name`") if repoErr == nil { var userCont QualEvalArrt userCont.Id = u_v userCont.Name = repoCont.Name sendCont.UserListAry = append(sendCont.UserListAry, userCont) } } sendCont.DimensionWeight, sendCont.TargetWeight = getPlanVersionWeghit(v.QualEvalId, strconv.FormatInt(v.Dimension, 10), strconv.FormatInt(v.Target, 10)) //获取目标设定 quanTitWhere := publicmethod.MapOut[string]() // quanTitWhere["company_id"] = v.Group quanTitWhere["departmentid"] = v.AcceptEvaluation // quanTitWhere["dimension"] = v.Dimension quanTitWhere["target"] = v.Target if v.DetailedTarget != 0 { quanTitWhere["targetconfig"] = v.DetailedTarget } quanTitWhere["year"] = publicmethod.UnixTimeToDay(time.Now().Unix(), 16) quanTitWhere["timecopy"] = AllZreoConfig(v.Cycles) //目标值设定 var quanTitCont modelskpi.QuantitativeConfig quanTitCont.GetCont(quanTitWhere) //全奖值、零奖值、封顶值 sendCont.ZeroPrize = strconv.FormatFloat(float64(quanTitCont.Zeroprize)/100, 'f', -1, 64) sendCont.AllPrize = strconv.FormatFloat(float64(quanTitCont.Allprize)/100, 'f', -1, 64) sendCont.CappingVal = quanTitCont.CappingVal / 100 //获取实际值 shiJiZhi := publicmethod.MapOut[string]() shiJiZhi["fl_evaluation_user"] = myLoginCont.Key shiJiZhi["fl_evaluation_department"] = myLoginCont.MainDeparment shiJiZhi["fl_evaluation_group"] = myLoginCont.Company operationTime := time.Now().Unix() if receivedValue.Time != "" { strTime := fmt.Sprintf("%v-01 00:00:00", receivedValue.Time) stringToTime, strToTimeErr := publicmethod.DateToTimeStamp(strTime) if strToTimeErr == true { operationTime = stringToTime } else { strTime = fmt.Sprintf("%v 00:00:00", receivedValue.Time) stringToTime, strToTimeErr = publicmethod.DateToTimeStamp(strTime) if strToTimeErr == true { operationTime = stringToTime } } } years := publicmethod.ComputingTime(operationTime, 1) quarter := publicmethod.ComputingTime(operationTime, 2) months := publicmethod.ComputingTime(operationTime, 3) switch v.Cycles { case 1: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter shiJiZhi["fl_month"] = months shiJiZhi["fl_week"] = publicmethod.ComputingTime(operationTime, 4) shiJiZhi["fl_day"] = publicmethod.ComputingTime(operationTime, 5) case 2: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter shiJiZhi["fl_month"] = months shiJiZhi["fl_week"] = publicmethod.ComputingTime(operationTime, 4) shiJiZhi["fl_day"] = publicmethod.ComputingTime(operationTime, 5) case 3: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter shiJiZhi["fl_month"] = months shiJiZhi["fl_week"] = publicmethod.ComputingTime(operationTime, 4) case 4: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter shiJiZhi["fl_month"] = months case 5: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter case 6: shiJiZhi["fl_year"] = years default: shiJiZhi["fl_year"] = years shiJiZhi["fl_quarter"] = quarter shiJiZhi["fl_month"] = months shiJiZhi["fl_week"] = publicmethod.ComputingTime(operationTime, 4) shiJiZhi["fl_day"] = publicmethod.ComputingTime(operationTime, 5) } sendCont.ReferTo = JudgeDingLiangIsTrue(v.Target, v.AcceptEvaluation, years, quarter, months, v.Cycles) actualValue, shouDongScore := GetTimeIntervalDuty(shiJiZhi, v.Id) //实际值 sendCont.Actual = strconv.FormatFloat(actualValue/100, 'f', -1, 64) // chuShuVal := actualValue - quanTitCont.Zeroprize // beiChuShuVal := quanTitCont.Allprize - quanTitCont.Zeroprize // if beiChuShuVal > 0 { // sendCont.ReachScore = chuShuVal / beiChuShuVal // } else { // sendCont.ReachScore = 0 // } var actual float64 actual, sendCont.ReachScore = postweb.GetAchieAndActual(actualValue, float64(sendCont.TargetWeight), quanTitCont.Zeroprize, quanTitCont.Allprize, quanTitCont.CappingVal) if targetCont.ScoringMethod != 1 { sendCont.ReachScore = publicmethod.DecimalEs(shouDongScore/100, 2) } // fmt.Printf("All--->score:%v------>weight:%v------>zeroprize:%v------>allprize:%v------>cappingval:%v------>achievement:%v------>actual:%v\n", actualValue, sendCont.TargetWeight, quanTitCont.Zeroprize, quanTitCont.Allprize, quanTitCont.CappingVal, sendCont.ReachScore, actual) if quanTitCont.Zeroprize == 0 && quanTitCont.Allprize == 0 { sendCont.Reach = "未设置目标值" } else { dividend := quanTitCont.Allprize - quanTitCont.Zeroprize //被除数 if dividend == 0 { sendCont.Reach = "未设置目标值" } else { // sendCont.Reach = fmt.Sprintf("(实际值-零奖值)/(全奖值-零奖值)") actual = publicmethod.DecimalEs(actual*100, 2) sendCont.Reach = fmt.Sprintf("%v%v", actual, "%") if actualValue == 0 { sendCont.Reach = "100%" } } } sendCont.Reason = "" sendCont.DetailedTarget = strconv.FormatInt(v.DetailedTarget, 10) switch v.Cycles { case 5: banNian := []int64{3, 6, 9, 12} if publicmethod.IsInTrue[int64](months, banNian) { sendListCont = append(sendListCont, sendCont) } case 6: if months == 12 { sendListCont = append(sendListCont, sendCont) } case 7: banNian := []int64{6, 12} if publicmethod.IsInTrue[int64](months, banNian) { sendListCont = append(sendListCont, sendCont) } default: sendListCont = append(sendListCont, sendCont) } } publicmethod.Result(0, sendListCont, c) } // 判断定量指标是否已经提交 func JudgeDingLiangIsTrue(targetId, department int64, year, quarter, monthsss int64, types int) bool { var idList []int64 gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.FlowDataLogType{}).Select("`id`").Where("`targetid` = ? AND `department` = ?", targetId, department) switch types { case 5: gormDb = gormDb.Where("`year` = ? AND `quarte` = ?", year, quarter) case 6: gormDb = gormDb.Where("`year` = ?", year) case 7: banNian := []int{1, 2, 3, 4, 5, 6} if monthsss > 6 { banNian = []int{7, 8, 9, 10, 11, 12} } gormDb = gormDb.Where("`year` = ? AND `month` IN ?", year, banNian) default: gormDb = gormDb.Where("`year` = ? AND `month` = ?", year, monthsss) } err := gormDb.Find(&idList).Error if err == nil && len(idList) > 0 { return true } return false } /* * @ 作者: 秦东 @ 时间: 2023-01-15 10:23:22 @ 功能: 获取维度与指标权重 @ 参数 #planKey 方案编号 #dimensionId 维度 #targetId 指标 @ 返回值 #dimensionIdWeghit 维度权重 #targetIdWeghit 指标权重 @ 方法原型 #getPlanVersionWeghit(planKey, dimensionId, targetId string) (dimensionIdWeghit, targetIdWeghit int64) */ func getPlanVersionWeghit(planKey, dimensionId, targetId string) (dimensionIdWeghit, targetIdWeghit int64) { var planVersionCont modelskpi.PlanVersio err := overall.CONSTANT_DB_KPI.Model(&modelskpi.PlanVersio{}).Select("`content`").Where("`key` = ?", planKey).First(&planVersionCont).Error if err != nil { return } var planVersioInfo []AddDutyNewCont jsonErr := json.Unmarshal([]byte(planVersionCont.Content), &planVersioInfo) if jsonErr != nil { return } for _, v := range planVersioInfo { if v.Id == dimensionId { dimensionIdWeghit = int64(v.ZhiFraction) for _, cv := range v.Child { if cv.Id == targetId { targetIdWeghit = cv.ReferenceScore } } } } return } /** @ 作者: 秦东 @ 时间: 2023-01-15 10:49:07 @ 功能: 判断全奖与零奖参数 @ 参数 # @ 返回值 # @ 方法原型 # */ // 判断全奖与零奖参数 func AllZreoConfig(cycles int) (monthInt int64) { switch cycles { case 4: monthInt = publicmethod.ComputingTime(time.Now().Unix(), 3) case 5: monthInt = publicmethod.ComputingTime(time.Now().Unix(), 2) default: } return } // 获取定量考核时间内审批通过的考核数据 func GetTimeIntervalDuty(whereData interface{}, schemeID int64) (actual, shouDongScore float64) { // jsonStr, _ := json.Marshal(whereData) // fmt.Printf("jsonStr------1------>%v\n", string(jsonStr)) actual = 0 //相关审批流 var flowLogList []modelskpi.FlowLog err := overall.CONSTANT_DB_KPI.Where("`fl_reply` IN (2,3) AND FIND_IN_SET(?,`fl_evaluation_id`)", schemeID).Where(whereData).Find(&flowLogList).Error if err != nil { return } for _, v := range flowLogList { ziDongScore, sdScore := GetSchemeFlowData(v.Key, schemeID) actual = actual + ziDongScore shouDongScore = shouDongScore + sdScore } return } // 获取指定审批流方案数据 func GetSchemeFlowData(flowKwy, schemeID int64) (weightSum, shouDongScore float64) { weightSum = 0 overall.CONSTANT_DB_KPI.Model(&modelskpi.FlowLogData{}).Where("`fld_evaluation_id` = ? AND `fld_flow_log` = ?", schemeID, flowKwy).Pluck("COALESCE(SUM(fld_score), 0) as flscore", &weightSum) // weightSum = 0 overall.CONSTANT_DB_KPI.Model(&modelskpi.FlowLogData{}).Where("`fld_evaluation_id` = ? AND `fld_flow_log` = ?", schemeID, flowKwy).Pluck("COALESCE(SUM(fld_scoring_score), 0) as scoring_score", &shouDongScore) return } /* * @ 作者: 秦东 @ 时间: 2023-02-23 16:35:22 @ 功能: 获取关联指标细则 @ 参数 #targetid 指标ID #tableid 栏目Id #bylaws 细则Id #orgid 行政组织 #post 岗位 #types 类型(1:指标;2:子目标;3:细则) #level 级别(1:部门级;2:岗位级) @ 返回值 #bylawsId 相关ID #err 信息 @ 方法原型 #GetTargetDetailsInfoList(targetid, tableid, bylaws, orgid, post int64, types, level int) (bylawsId []int64, err error) */ func GetTargetDetailsInfoList(targetid, tableid, bylaws, orgid, post int64, types, level int) (bylawsId []int64, err error) { if types == 0 { types = 3 } gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}) switch types { case 1: gormDb = gormDb.Distinct(`target_id`) case 2: gormDb = gormDb.Distinct(`target_sun_id`) default: gormDb = gormDb.Distinct(`target_bylaws`) } gormDb = gormDb.Where("`state` = 1 AND `type` = ? AND `level` = ?", types, level) if targetid != 0 { gormDb = gormDb.Where("`target_id` = ?", targetid) } if tableid != 0 { gormDb = gormDb.Where("`target_sun_id` = ?", tableid) } if bylaws != 0 { gormDb = gormDb.Where("`target_bylaws` = ?", bylaws) } err = gormDb.Find(&bylawsId).Error return } /* * @ 作者: 秦东 @ 时间: 2023-04-12 16:03:31 @ 功能: 提交定量考核 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) SubmitQuantifyTarget(c *gin.Context) { var receivedValue SubmitQuantTargetCont c.ShouldBindJSON(&receivedValue) if receivedValue.FlowworkId == "" { publicmethod.Result(1, receivedValue, c, "未知工作流!不可进行提交") return } if receivedValue.DepartmentId == "" { publicmethod.Result(1, receivedValue, c, "未知行政组织!不可进行提交") return } if receivedValue.PlanVersionNumber == "" { publicmethod.Result(1, receivedValue, c, "未知方案!不可进行提交") return } if receivedValue.Time == "" { publicmethod.Result(1, receivedValue, c, "未知考核时间!不可进行提交") return } if len(receivedValue.List) < 1 { publicmethod.Result(1, receivedValue, c, "未知考核项目!不可进行提交") return } var errMsg []string for _, v := range receivedValue.List { if v.Id == "" { errMsg = append(errMsg, "未知考核项目") } if v.Actual == "" { errMsg = append(errMsg, fmt.Sprintf("%v未输入实际值", v.Targetname)) } if v.Addtime == "" { errMsg = append(errMsg, fmt.Sprintf("%v未输入检查时间", v.Targetname)) } var waiBuTime publicmethod.DateTimeTotimes waiBuTime.BaisStrToTime(v.Addtime) where := publicmethod.MapOut[string]() where["fld_year"] = waiBuTime.Years where["fld_quarter"] = waiBuTime.Quarter where["fld_month"] = waiBuTime.Months where["fld_evaluation_id"] = v.Id where["fl_duty_department"] = receivedValue.DepartmentId fmt.Printf("where--->%v\n", where) var dutyData modelskpi.DutyFlowData err := dutyData.GetCont(where, "fld_id") if err == nil { errMsg = append(errMsg, fmt.Sprintf("%v已经提交过!请不要重复提交!", v.Targetname)) } } if len(errMsg) > 0 { errMsgStr := strings.Join(errMsg, ";") publicmethod.Result(1, receivedValue, c, errMsgStr) return } publicmethod.Result(0, receivedValue, c) // uuid := publicmethod.GetUUid(6) //上报数据唯一识别码 // //获取登录人信息 // myLoginCont, _ := publicmethod.LoginMyCont(c) }