package postweb import ( "encoding/json" "fmt" "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "time" "github.com/gin-gonic/gin" ) //定量考核相关操作 // 获取定量考核详细内容 func (a *ApiMethod) GetRationTargetCont(c *gin.Context) { var receivedValue publicmethod.PublicId err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Id == "" { publicmethod.Result(101, receivedValue, c) return } currentTime := time.Now().Unix() var schemeCont modelskpi.QualitativeEvaluationScheme err = schemeCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}) if err != nil { publicmethod.Result(107, err, c) return } var sendData sendPostTargetRationCont sendData.Id = receivedValue.Id //获取指标信息 var targerCont modelskpi.PostTarget targerCont.GetCont(map[string]interface{}{"`id`": schemeCont.TargetId}) sendData.Name = targerCont.Title sendData.Content = schemeCont.Content yearVal := publicmethod.ComputingTime(currentTime, 1) timecopy := publicmethod.ComputingTime(currentTime, 3) //月"` switch targerCont.Cycle { case 5: timecopy = publicmethod.ComputingTime(currentTime, 2) //季度"` case 6: timecopy = 1 default: timecopy = publicmethod.ComputingTime(currentTime, 3) //月"` } //获取指标的全奖、零奖、封顶值 sendData.Allprize, sendData.Zeroprize, sendData.Capping = GetPostTagetRewardSeting(schemeCont.CompanyId, schemeCont.OrgId, schemeCont.PostId, schemeCont.DimensionId, schemeCont.TargetId, schemeCont.DetailsId, yearVal, timecopy) //获取指标权重 dimensionIdStr := strconv.FormatInt(schemeCont.DimensionId, 10) targetIdStr := strconv.FormatInt(schemeCont.TargetId, 10) sendData.Weight = GetSchemeTargetWeight(schemeCont.VersionNumber, dimensionIdStr, targetIdStr, schemeCont.Source) sendData.ScoringMethod = schemeCont.ScoringMethod publicmethod.Result(0, sendData, c) } /* 获取岗位指标全奖、零奖、封顶值 @company 公司 @org 行政组织 @post 岗位 @dimension 维度 @target 指标 @detailed 细则 GetPostTagetRewardSeting(company, org, post, dimension, target, detailed, year int64, timecopy int) */ func GetPostTagetRewardSeting(company, org, post, dimension, target, detailed, year, timecopy int64) (allprize, zeroprize, capping float64) { allprize = 0 zeroprize = 0 capping = 0 var quanPostConfig modelskpi.QuanPostConfig gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.QuanPostConfig{}).Where("`state` = 1 AND `company_id` = ? AND `org_id` = ? AND `post_id` = ? AND `dimension` = ? AND `target` = ? AND `year` = ? AND `timecopy` = ?", company, org, post, dimension, target, year, timecopy) if detailed != 0 { gormDb = gormDb.Where("`detailed` = ?", detailed) } err := gormDb.First(&quanPostConfig).Error if err == nil { allprize = publicmethod.DecimalEs(quanPostConfig.Allprize, 2) zeroprize = publicmethod.DecimalEs(quanPostConfig.Zeroprize, 2) capping = publicmethod.DecimalEs(quanPostConfig.CappingVal, 2) } return } /* 获取考核项目指标权重 @versionNumber 版本编号 @dimension 维度 @target 指标 @source 来源(1:岗位;2:部门引用) @weight 指标权重 GetSchemeTargetWeight(versionNumber, dimension, target string, source int) */ func GetSchemeTargetWeight(versionNumber, dimension, target string, source int) (weight float64) { var postPlanVersion modelskpi.PositionPlanVersio err := postPlanVersion.GetCont(map[string]interface{}{"`key`": versionNumber}) if err != nil { return } //解析岗位指标放啊 var shemeInfo postScheme jsonErr := json.Unmarshal([]byte(postPlanVersion.Content), &shemeInfo) if jsonErr != nil { return } if source == 1 { //岗位 if len(shemeInfo.PostChild) > 0 { for _, pv := range shemeInfo.PostChild { //维度 if pv.Id == dimension { if len(pv.Child) > 0 { for _, tv := range pv.Child { //指标 if tv.Id == target { weight = tv.Score } } } } } } } else { //部门引用 if len(shemeInfo.DepartmentChild) > 0 { for _, pv := range shemeInfo.DepartmentChild { //维度 if pv.Id == dimension { if len(pv.Child) > 0 { for _, tv := range pv.Child { //指标 if tv.Id == target { weight = tv.Score } } } } } } } return } // 提交定量考核数据 func (a *ApiMethod) SubmitRationPostCont(c *gin.Context) { var receivedValue submitPostSchemeTarget err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Id == "" { publicmethod.Result(101, receivedValue, c) return } currentTime := time.Now().Unix() if receivedValue.SubmitTime != "" { happTime, timeErr := publicmethod.DateToTimeStamp(fmt.Sprintf("%v-01 12:00:00", receivedValue.SubmitTime)) if timeErr == true { currentTime = happTime } } else { yearVal := publicmethod.ComputingTime(currentTime, 1) timecopy := publicmethod.ComputingTime(currentTime, 3) //月"` happTime, timeErr := publicmethod.DateToTimeStamp(fmt.Sprintf("%v-%v-01 12:00:00", yearVal, timecopy)) if timeErr == true { currentTime = happTime } } if receivedValue.Score == 0 { publicmethod.Result(1, receivedValue, c, "请输入您的实际值!") return } if receivedValue.ScoringMethod == 0 { receivedValue.ScoringMethod = 1 } if receivedValue.ScoringMethod != 1 { if receivedValue.ScoringScore == 0 { publicmethod.Result(1, receivedValue, c, "请输入您的手动打分值!") return } } if receivedValue.PersonLiable == "" { publicmethod.Result(1, receivedValue, c, "没有确定责任人是谁!") return } //获取考核项目信息 var postShemeCont modelskpi.QualitativeEvaluationScheme err = postShemeCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}) if err != nil { publicmethod.Result(107, err, c) return } //获取被考核人基本信息 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.PersonLiable}, "`company`", "`maindeparment`", "`admin_org`", "`position`") if err != nil { publicmethod.Result(107, err, c) return } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) uuId := publicmethod.GetUUid(1) //流程列表 var flowCont modelskpi.PostWorkflowOrders flowCont.OrderId = uuId //审批单ID"` flowCont.Step = 1 //当前执行到第几步"` flowCont.NextStep = 2 //下一步执行哪个步骤"` flowCont.WorkFlow = "" //工作流(审批json字符串)"` flowCont.CompanyId = userCont.Company //公司"` flowCont.DepartmentId = userCont.MainDeparment //部门"` flowCont.OrgId = userCont.AdminOrg //行政组织"` flowCont.PostId = userCont.Position //岗位"` flowCont.Class = postShemeCont.Attribute //属性1、定性;2、定量"` flowCont.Dimension = postShemeCont.DimensionId //维度"` flowCont.Target = postShemeCont.TargetId //指标"` flowCont.SonTarget = postShemeCont.SonTargetId //指标子栏目"` flowCont.Detailed = postShemeCont.DetailsId //指标细则"` flowCont.Executor = context.Key //执行人"` flowCont.ExecutorDepartment = context.MainDeparment //执行人部门"` flowCont.State = 3 //流程状态 1:草稿;2:驳回;3:审批中;4:归档;5:废弃;6:删除"` flowCont.StartTime = time.Now().Unix() //流程开始时间"` flowCont.Time = time.Now().Unix() //时间"` if len(receivedValue.Enclosure) > 0 { jsonFileList, _ := json.Marshal(receivedValue.Enclosure) flowCont.EnclosureFormat = string(jsonFileList) //附件"` } yearVal := publicmethod.ComputingTime(currentTime, 1) timecopy := publicmethod.ComputingTime(currentTime, 3) //月"` var baseLine baseLineType //获取指标的全奖、零奖、封顶值 baseLine.Allprize, baseLine.Zeroprize, baseLine.Capping = GetPostTagetRewardSeting(postShemeCont.CompanyId, postShemeCont.OrgId, postShemeCont.PostId, postShemeCont.DimensionId, postShemeCont.TargetId, postShemeCont.DetailsId, yearVal, timecopy) //获取指标权重 dimensionIdStr := strconv.FormatInt(postShemeCont.DimensionId, 10) targetIdStr := strconv.FormatInt(postShemeCont.TargetId, 10) baseLine.Weight = GetSchemeTargetWeight(postShemeCont.VersionNumber, dimensionIdStr, targetIdStr, postShemeCont.Source) baseLine.SchemeId = receivedValue.Id baseLine.TargetId = targetIdStr //定量考核流水 var postMeterFlow modelskpi.PostMeteringFlow postMeterFlow.OrderId = uuId // 审批单ID"` postMeterFlow.ShemeId = postShemeCont.Id // 方案ID"` postMeterFlow.ShemeVersion = postShemeCont.VersionNumber //方案版本编号"` postMeterFlow.Dimension = postShemeCont.DimensionId //维度"` postMeterFlow.Target = postShemeCont.TargetId //指标"` postMeterFlow.Score = receivedValue.Score * 100 //分值(*100保存)"` postMeterFlow.Reason = receivedValue.Reason //这样操作的原因"` postMeterFlow.Year = yearVal //年"` postMeterFlow.Quarter = publicmethod.ComputingTime(currentTime, 2) //季度"` postMeterFlow.Month = publicmethod.ComputingTime(currentTime, 3) //月"` postMeterFlow.Week = publicmethod.ComputingTime(currentTime, 4) //周"` postMeterFlow.PersonLiable = userCont.Key //责任人"` postMeterFlow.CompanyId = userCont.Company //公司"` postMeterFlow.DepartmentId = userCont.MainDeparment //部门"` postMeterFlow.OrgId = userCont.AdminOrg //行政组织"` postMeterFlow.PostId = userCont.Position //岗位"` postMeterFlow.Executor = context.Key //执行人"` postMeterFlow.ExecutorDepartment = context.MainDeparment //执行人部门"` postMeterFlow.HappenTime = currentTime //发生时间"` postMeterFlow.Time = time.Now().Unix() //时间"` baseLineJson, _ := json.Marshal(baseLine) postMeterFlow.Baseline = string(baseLineJson) //基准线"` postMeterFlow.ScoringMethod = receivedValue.ScoringMethod //计分方式(1:自动;2:手动) if receivedValue.ScoringMethod != 1 { postMeterFlow.ScoringScore = receivedValue.ScoringScore * 100 //手动分 } //开启事务提交 gormDbAffair := overall.CONSTANT_DB_KPI passorErr := gormDbAffair.Create(&flowCont).Error flowErr := gormDbAffair.Create(&postMeterFlow).Error if passorErr == nil && flowErr == nil { addErr := gormDbAffair.Commit().Error publicmethod.Result(0, addErr, c) } else { addErr := gormDbAffair.Rollback().Error publicmethod.Result(104, addErr, c) } }