package postpc import ( "encoding/json" "fmt" "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelskpi" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "sort" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) // 获取岗位相关指标 func (a *ApiMethod) GetPostAboutTarget(c *gin.Context) { var receivedValue publicmethod.PublicId err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } //获取岗位相关信息 var postCont modelshr.Position postContErr := postCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}, "`id`", "`duties`", "`administrative_organization`", "`superior`", "`department`") if postContErr != nil { publicmethod.Result(107, postContErr, c) return } //根据维度生成方案列表 //1、获取维度 var dimensionModels modelskpi.DutyClass dimensionList, dimeErr := dimensionModels.ContMap(map[string]interface{}{"`state`": 1}, "`id`", "`title`", "`sort`") // fmt.Printf("dimensionList--->%v\n", dimensionList) if dimeErr != nil || len(dimensionList) <= 0 { publicmethod.Result(107, postContErr, c) return } //2、根据维度获取岗位相关指标 var postPlanSync postDimeTarSync for _, v := range dimensionList { syncSeting.Add(1) go postPlanSync.GetPostTargent(postCont, v) } syncSeting.Wait() planAry := postPlanSync.readDataLock() //读取线程通道数据 if len(planAry) < 1 { publicmethod.Result(1, planAry, c, "该岗位没有设定专属指标!您可以从部门指标中引入!") return } //根据维度序号排序 sort.Slice(planAry, func(i, j int) bool { return planAry[i].Sort < planAry[j].Sort }) publicmethod.Result(0, planAry, c) } // 获取岗位与维度相关的指标 /* @position 岗位信息 @dutyClass 维度信息 */ func (p *postDimeTarSync) GetPostTargent(position modelshr.Position, dutyClass modelskpi.DutyClass) { p.mutext.Lock() defer p.mutext.Unlock() //获取相关指标 var postTargetList []modelskpi.PostTarget postTarErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTarget{}).Where("`state` = 1 AND `dimension` = ? AND `rele_depart` = ? AND FIND_IN_SET(?,`departments_post`)", dutyClass.Id, position.AdministrativeOrganization, position.Id).Find(&postTargetList).Error // fmt.Printf("postTargetList---->%v\n", postTargetList) if postTarErr == nil && len(postTargetList) > 0 { var planCont postAboutDimeTar planCont.Id = strconv.FormatInt(dutyClass.Id, 10) planCont.Name = dutyClass.Title planCont.Sort = dutyClass.Sort for _, v := range postTargetList { var targetCont postAboutTarget targetCont.Id = strconv.FormatInt(v.Id, 10) targetCont.Name = v.Title targetCont.Content = "" //指标描述 targetCont.StandardScore = getPostDimeTarWeight(position.AdministrativeOrganization, position.Id, dutyClass.Id, v.Id, 1, 1) //标准分 targetCont.Unit = v.Unit //单位 targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许 targetCont.State = 1 //状态 1:启用;2:禁用;3:观察 planCont.Child = append(planCont.Child, targetCont) } p.planList = append(p.planList, planCont) } syncSeting.Done() } /* 获取岗位考核指标或维度标准分 @orgid 行政组织 @postid 岗位 @dimensionid 维度 @targetid 指标 @hierarchy 1:维度;2:指标 @isQuote 1:不是引用;2:引用部门 getPostDimeTarWeight(orgid, postid, dimensionid, targetid int64, hierarchy, isQuote int) */ func getPostDimeTarWeight(orgid, postid, dimensionid, targetid int64, hierarchy, isQuote int) int64 { if hierarchy == 0 { hierarchy = 2 } where := publicmethod.MapOut[string]() where["orgid"] = orgid where["postid"] = postid where["dimension"] = dimensionid var ddpwCont modelskpi.DepartDimePostWeight if hierarchy == 1 { where["hierarchy"] = 1 // ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "hierarchy": 1}, "`weight`") ddpwCont.GetCont(where, "`weight`") } else { where["target"] = targetid where["hierarchy"] = 2 // ddpwCont.GetCont(map[string]interface{}{"orgid": orgid, "postid": postid, "dimension": dimensionid, "target": targetid, "hierarchy": 2}, "`weight`") ddpwCont.GetCont(where, "`weight`") } return ddpwCont.Weight } // 引用指标部门指标 func (a *ApiMethod) QuoteDepartmentTarget(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, err, c) return } //获取维度 var dimenId []int64 err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`dimension_id`").Where("`state` = 1 AND `level` = 2 AND `post_id` = ?", receivedValue.Id).Find(&dimenId).Error if err != nil || len(dimenId) < 1 { publicmethod.Result(107, err, c) return } var targetlist postDimeTarSync //获取指标列表 for _, v := range dimenId { syncSeting.Add(1) go targetlist.getPostQuoteDepartmentTarget(v, receivedValue.Id) } syncSeting.Wait() planAry := targetlist.readDataLock() //读取线程通道数据 if len(planAry) < 1 { publicmethod.Result(1, planAry, c, "该岗位没有设定部门指标引入项!") return } //根据维度序号排序 sort.Slice(planAry, func(i, j int) bool { return planAry[i].Sort < planAry[j].Sort }) publicmethod.Result(0, planAry, c) } /* 获取岗位引入部门指标的列表 @dimensionId 维度 @postId 岗位 */ func (p *postDimeTarSync) getPostQuoteDepartmentTarget(dimensionId int64, postId string) { p.mutext.Lock() defer p.mutext.Unlock() var listCont postAboutDimeTar //获取维度信息 var dimenCont modelskpi.DutyClass dimenCont.GetCont(map[string]interface{}{"`id`": dimensionId}, "`title`", `sort`) listCont.Id = strconv.FormatInt(dimensionId, 10) listCont.Name = dimenCont.Title listCont.Sort = dimenCont.Sort //获取岗位信息 var postCont modelshr.Position postCont.GetCont(map[string]interface{}{"`id`": postId}, "`id`", "`administrative_organization`") var targetId []int64 overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`target_id`").Where("`state` = 1 AND `level` = 2 AND `dimension_id` = ? AND `post_id` = ?", dimensionId, postId).Find(&targetId) if len(targetId) > 0 { //获取指标信息 var targetList []modelskpi.EvaluationTarget overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{}).Where("`et_state` = 1 AND `et_id` IN ?", targetId).Find(&targetList) if len(targetList) > 0 { for _, v := range targetList { var targetCont postAboutTarget targetCont.Id = strconv.FormatInt(v.Id, 10) targetCont.Name = v.Title targetCont.Content = "" //指标描述 targetCont.StandardScore = getPostDimeTarWeight(postCont.AdministrativeOrganization, postCont.Id, dimensionId, v.Id, 2, 2) //标准分 targetCont.Unit = v.Uniteing //单位 targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许 targetCont.State = 1 //状态 1:启用;2:禁用;3:观察 targetCont.Type = v.Type if v.Type == 1 { detaildList := getQuoteTargetDepartList(dimensionId, v.Id, postCont.Id) if len(detaildList) > 0 { targetCont.Child = detaildList listCont.Child = append(listCont.Child, targetCont) } } else { listCont.Child = append(listCont.Child, targetCont) } } } } if len(listCont.Child) > 0 { p.planList = append(p.planList, listCont) } jsonStr, _ := json.Marshal(listCont) fmt.Printf("jsonStr------->%v\n", string(jsonStr)) syncSeting.Done() } // 获取部门引用关联指标细则 func getQuoteTargetDepartList(dimensionId, targetId, postId int64) (listCont []quoteDeatinDeparment) { var detaildId []int64 overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`target_bylaws`").Where("`state` = 1 AND `level` = 2 AND `dimension_id` = ? AND `target_id` = ? AND `post_id` = ? AND `target_bylaws` <> 0", dimensionId, targetId, postId).Find(&detaildId) if len(detaildId) < 1 { return } var detaildList []modelskpi.DetailedTarget overall.CONSTANT_DB_KPI.Model(&modelskpi.DetailedTarget{}).Select("`dt_id`,`dt_title`,`dt_content`,`dt_min_score`,`dt_max_score`").Where("`dt_state` = 1 AND `dt_id` IN ?", detaildId).Find(&detaildList) if len(detaildList) < 1 { return } for _, v := range detaildList { var contList quoteDeatinDeparment contList.Id = strconv.FormatInt(v.Id, 10) contList.Name = v.Title biaoZhun := "" if v.MinScore != 0 { biaoZhun = fmt.Sprintf("%v-%v", v.MinScore, v.MaxScore) } else { biaoZhun = fmt.Sprintf("%v", v.MaxScore) } contList.ReferenceScore = biaoZhun listCont = append(listCont, contList) } fmt.Println("----------------->") return } // 提交岗位考核方案 func (a *ApiMethod) SubmitPostScheme(c *gin.Context) { var receivedValue postScheme c.ShouldBindJSON(&receivedValue) if receivedValue.OrgId == "" { publicmethod.Result(101, receivedValue.OrgId, c, "请指定行政组织ID") return } if receivedValue.PostId == "" { publicmethod.Result(101, receivedValue.PostId, c, "请指定行政组织ID") return } if receivedValue.Year == "" { publicmethod.Result(101, receivedValue.Year, c, "请指定方案属于哪一年的?") return } if len(receivedValue.PostChild) < 1 && len(receivedValue.DepartmentChild) < 1 { publicmethod.Result(1, receivedValue, c, "考核项目不能为空!") return } orderIdInt, _ := strconv.ParseInt(receivedValue.OrgId, 10, 64) //根据行政组织Id获取集团信息,及部门信息 groupId, companyId, departmentId, sunDepartId, workShopId := publicmethod.GetOrgStructure(orderIdInt) //获取公司首字母 var companyCont modelshr.AdministrativeOrganization companyCont.GetCont(map[string]interface{}{"`id`": companyId}, "`name`", "`abbreviation`") firstNameWord := companyCont.Abbreviation if firstNameWord == "" { firstNameWord = companyCont.Name } companyFirstWord := publicmethod.ChineseFirstWordCapitalize(firstNameWord) //公司首字母 //获取部门首字母 var departmentCont modelshr.AdministrativeOrganization departmentCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`name`", "`abbreviation`") firstNameWordDepart := departmentCont.Abbreviation if firstNameWordDepart == "" { firstNameWordDepart = departmentCont.Name } departmentFirstWord := publicmethod.ChineseFirstWordCapitalize(firstNameWordDepart) //部门首字母 judgeState := 1 //方案初始状态 //判断该岗位是否有生成的考核方案 var versionState []int overall.CONSTANT_DB_KPI.Model(&modelskpi.PositionPlanVersio{}).Select("state").Where("`orgid` = ? AND `position` = ?", orderIdInt, receivedValue.PostId).Find(&versionState) // fmt.Printf("versionState----------->%v------------>%v\n", len(versionState), versionState) if len(versionState) > 0 { for _, s_v := range versionState { if s_v == 1 { judgeState = 2 } } } var versioNum string //版本号 //判断年度是否存在版本 var sumVerson int64 judgeVersioNum := overall.CONSTANT_DB_KPI.Model(&modelskpi.PositionPlanVersio{}).Select("`id`").Where("`group` = ? AND `department` = ? AND `years` = ?", companyId, departmentId, receivedValue.Year).Pluck("COALESCE(COUNT(id), 0) as countid", &sumVerson).Error if judgeVersioNum != nil { versioNum = "0001" } else { if sumVerson == 0 { versioNum = "0001" } else { sumVerson++ sumVersonStr := strconv.FormatInt(sumVerson, 10) versioNum = publicmethod.ZeroFillByStr(sumVersonStr, 4, true) } } todyTime := time.Now().Unix() versionNumber := fmt.Sprintf("%v-%v-%v%v", companyFirstWord, departmentFirstWord, publicmethod.UnixTimeToDay(todyTime, 21), versioNum) postIdInt, _ := strconv.ParseInt(receivedValue.PostId, 10, 64) //岗位id转成整形 yearInt, _ := strconv.ParseInt(receivedValue.Year, 10, 64) jsonPlanCont, _ := json.Marshal(receivedValue) //准备写入方案 var postPlanScheme modelskpi.PositionPlanVersio postPlanScheme.Group = companyId //归属集团"` postPlanScheme.Department = departmentId //归属部门"` postPlanScheme.OrgId = orderIdInt //行政组织"` postPlanScheme.Position = postIdInt //归属岗位"` postPlanScheme.Key = versionNumber //编码"` postPlanScheme.Versio = versioNum //版本号"` postPlanScheme.Year = yearInt //年度"` postPlanScheme.State = judgeState //状态(1:启用;2:禁用;3:删除)"` postPlanScheme.AddTime = todyTime //创建时间"` postPlanScheme.EiteTime = todyTime //修改时间"` postPlanScheme.Content = string(jsonPlanCont) //版本内容"` err := overall.CONSTANT_DB_KPI.Create(&postPlanScheme).Error if err != nil { publicmethod.Result(104, receivedValue.OrgId, c, "请检查您的数据格式!") return } fmt.Printf("groupId-------->%v---->companyId-------->%v---->departmentId-------->%v---->sunDepartId-------->%v---->workShopId-------->%v---------versionNumber----------->%v---------judgeState----------->%v\n", groupId, companyId, departmentId, sunDepartId, workShopId, versionNumber, judgeState) //岗位指标处理 if len(receivedValue.PostChild) > 0 { syncSeting.Add(1) go postSchemeTargetPost(versionNumber, 1, judgeState, receivedValue.PostChild, companyId, departmentId, orderIdInt, postIdInt) } //引用部门指标处理 if len(receivedValue.DepartmentChild) > 0 { syncSeting.Add(1) go postSchemeTarget(versionNumber, 2, judgeState, receivedValue.DepartmentChild, companyId, departmentId, orderIdInt, postIdInt) } syncSeting.Wait() jsonCont, _ := json.Marshal(postPlanScheme) publicmethod.Result(0, string(jsonCont), c) } /* 岗位指标写入 @versionNumber 方案版本号 @source 来源(1:岗位;2:部门引用) @judgeState 考核项状态 @scheme 方案结构体 @companyId 公司 @departmentId 部门 @orgid 行政组织 @postid 岗位 */ func postSchemeTargetPost(versionNumber string, source, judgeState int, scheme []schemeStructure, companyId, departmentId, orgid, postid int64) { defer syncSeting.Done() timeData := time.Now().Unix() var saveNewData []modelskpi.QualitativeEvaluationScheme //要新加的考核指标 var xizeXiecheng postShemeListCont for _, v := range scheme { //解析维度 dimensionIdInt64, _ := strconv.ParseInt(v.Id, 10, 64) //转换维度ID if len(v.Child) > 0 { //判断是否有指标 for _, cv := range v.Child { //解析指标 targetIdInt64, _ := strconv.ParseInt(cv.Id, 10, 64) //转换指标ID var saveData modelskpi.QualitativeEvaluationScheme //方案内容结构体 scoringMethod := 1 //判断是自动计分还是手动计分 var departPostTargetInfo modelskpi.PostTarget departPostTargetInfo.GetCont(map[string]interface{}{"`id`": targetIdInt64}, "`scoring_method`") if departPostTargetInfo.ScoringMethod != 0 { scoringMethod = departPostTargetInfo.ScoringMethod } if cv.Type != 1 { //定量考核 //判断该指标是否存在 whereLian := publicmethod.MapOut[string]() whereLian["`version_number`"] = versionNumber whereLian["`company_id`"] = companyId whereLian["`department_id`"] = departmentId whereLian["`org_id`"] = orgid whereLian["`post_id`"] = postid whereLian["`dimension_id`"] = dimensionIdInt64 whereLian["`target_id`"] = targetIdInt64 judgeLianErr := saveData.GetCont(whereLian, "`id`", "`state`") if judgeLianErr == nil { eidtTargetCont := publicmethod.MapOut[string]() eidtTargetCont["`scoring_method`"] = scoringMethod eidtTargetCont["`state`"] = judgeState eidtTargetCont["`source`"] = source eidtTargetCont["`run_state`"] = cv.State eidtTargetCont["`eitetime`"] = timeData saveData.EiteCont(map[string]interface{}{"`id`": saveData.Id}, eidtTargetCont) } else { //不存在需要新增 saveData.VersionNumber = versionNumber //版本编号"` saveData.CompanyId = companyId //归属公司"` saveData.DepartmentId = departmentId //归属部门"` saveData.OrgId = orgid //归属行政组织"` saveData.PostId = postid //归属岗位"` saveData.Title = cv.Name //考核项名称"` saveData.DimensionId = dimensionIdInt64 //维度"` saveData.TargetId = targetIdInt64 //指标"` saveData.SonTargetId = 0 //子栏目"` saveData.DetailsId = 0 //细则"` saveData.Attribute = cv.Type //属性 1:定性考核;2:定量考核"` saveData.MinScore = 0 //最小分*100保存"` saveData.MaxScore = 0 //最大分*100保存"` saveData.ScoringMethod = scoringMethod //计分方式(1:自动;2:手动)"` saveData.State = judgeState //状态(1:启用;2:禁用;3:删除)"` saveData.Addtime = timeData //添加时间"` saveData.Eitetime = timeData //编辑时间"` saveData.CensorType = "2" //检查方式(1:现场检查;2:资料检查;3:事件触发)"` saveData.Source = source //来源(1:岗位;2:部门引用)"` saveData.RunState = cv.State //运行状态(1:启用;2:禁用;3:观察) saveNewData = append(saveNewData, saveData) } } else { //定性考核 //获取该指标的岗位指标子栏目 var postSonTarget []modelskpi.PostSonTarget overall.CONSTANT_DB_KPI.Model(&modelskpi.PostSonTarget{}).Select("`id`,`parent_id`").Where("`state` = 1 AND `depart` = ? AND `depart_post` = ? AND `parent_id` = ?", orgid, postid, targetIdInt64).Find(&postSonTarget) if len(postSonTarget) > 0 { for _, son_v := range postSonTarget { syncSetinges.Add(1) go xizeXiecheng.eidtPostSchemeInfo(versionNumber, companyId, departmentId, orgid, postid, dimensionIdInt64, son_v.ParentId, son_v.Id, cv.State, scoringMethod, judgeState) } } } } } } syncSetinges.Wait() if len(saveNewData) > 0 { overall.CONSTANT_DB_KPI.Create(&saveNewData) } } /* 协程处理岗位方案定性指标细则内容 @versionNumber 方案版本号 @companyId 公司 @departmentId 部门 @orgid 行政组织 @postid 岗位 @dimensionId 维度 @targetId 指标 @sonTargetId 子栏目 @runState 运行状态(1:启用;2:禁用;3:观察) @scoringMethod 计分方式(1:自动;2:手动) @targetState 指标状态(1:启用;2:禁用;3:删除) */ func (p *postShemeListCont) eidtPostSchemeInfo(versionNumber string, companyId, departmentId, orgid, postid, dimensionId, targetId, sonTargetId int64, runState, scoringMethod, targetState int) { p.mutext.Lock() defer p.mutext.Unlock() timeData := time.Now().Unix() //获取相关指标细则内容 var postTargetDetailsCont []modelskpi.PostTargetDetails overall.CONSTANT_DB_KPI.Where("`state` = 1 AND `parentid` = ? AND `parentid_sun` = ? AND `paretment` = ? AND `paretment_post` = ?", targetId, sonTargetId, orgid, postid).Find(&postTargetDetailsCont) if len(postTargetDetailsCont) > 0 { for _, v := range postTargetDetailsCont { var saveData modelskpi.QualitativeEvaluationScheme //方案内容结构体 saveData.VersionNumber = versionNumber //版本编号"` saveData.CompanyId = companyId //归属公司"` saveData.DepartmentId = departmentId //归属部门"` saveData.OrgId = orgid //归属行政组织"` saveData.PostId = postid //归属岗位"` saveData.Title = v.Title //考核项名称"` saveData.DimensionId = departmentId //维度"` saveData.TargetId = targetId //指标"` saveData.SonTargetId = sonTargetId //子栏目"` saveData.DetailsId = v.Id //细则"` saveData.Attribute = 1 //属性 1:定性考核;2:定量考核"` saveData.MinScore = v.MinScore //最小分*100保存"` saveData.MaxScore = v.MaxScore //最大分*100保存"` saveData.ScoringMethod = scoringMethod //计分方式(1:自动;2:手动)"` saveData.State = targetState //状态(1:启用;2:禁用;3:删除)"` saveData.Addtime = timeData //添加时间"` saveData.Eitetime = timeData //编辑时间"` saveData.CensorType = "2" //检查方式(1:现场检查;2:资料检查;3:事件触发)"` saveData.Source = 1 //来源(1:岗位;2:部门引用)"` saveData.RunState = runState //运行状态(1:启用;2:禁用;3:观察) saveData.Punishmode = v.Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金 saveData.Maxmoney = v.Maxmoney //最高罚款 saveData.Minmoney = v.Minmoney //最低罚款 p.shememList = append(p.shememList, saveData) } } syncSetinges.Done() } /* 部门引入指标写入 @versionNumber 方案版本号 @source 来源(1:岗位;2:部门引用) @judgeState 考核项状态 @scheme 方案结构体 @companyId 公司 @departmentId 部门 @orgid 行政组织 @postid 岗位 */ func postSchemeTarget(versionNumber string, source, judgeState int, scheme []schemeStructure, companyId, departmentId, orgid, postid int64) { defer syncSeting.Done() timeData := time.Now().Unix() var saveNewData []modelskpi.QualitativeEvaluationScheme for _, v := range scheme { //解析维度 dimensionIdInt64, _ := strconv.ParseInt(v.Id, 10, 64) //转换维度ID if len(v.Child) > 0 { //判断是否有指标 for _, cv := range v.Child { //解析指标 targetIdInt64, _ := strconv.ParseInt(cv.Id, 10, 64) //转换指标ID var saveData modelskpi.QualitativeEvaluationScheme scoringMethod := 1 //判断计分方式 if source != 1 { //来源于部门引用 var departTargetInfo modelskpi.EvaluationTarget departTargetInfo.GetCont(map[string]interface{}{"`et_id`": targetIdInt64}, "`et_scoring_method`") if departTargetInfo.ScoringMethod != 0 { scoringMethod = departTargetInfo.ScoringMethod } } else { //来源于岗位考核 var departPostTargetInfo modelskpi.PostTarget departPostTargetInfo.GetCont(map[string]interface{}{"`id`": targetIdInt64}, "`scoring_method`") if departPostTargetInfo.ScoringMethod != 0 { scoringMethod = departPostTargetInfo.ScoringMethod } } if cv.Type != 1 { //定量考核 //判断该指标是否存在 whereLian := publicmethod.MapOut[string]() whereLian["`version_number`"] = versionNumber whereLian["`company_id`"] = companyId whereLian["`department_id`"] = departmentId whereLian["`org_id`"] = orgid whereLian["`post_id`"] = postid whereLian["`dimension_id`"] = dimensionIdInt64 whereLian["`target_id`"] = targetIdInt64 judgeLianErr := saveData.GetCont(whereLian, "`id`", "`state`") if judgeLianErr == nil { eidtTargetCont := publicmethod.MapOut[string]() eidtTargetCont["`scoring_method`"] = scoringMethod eidtTargetCont["`state`"] = judgeState eidtTargetCont["`source`"] = source eidtTargetCont["`run_state`"] = cv.State eidtTargetCont["`eitetime`"] = timeData saveData.EiteCont(map[string]interface{}{"`id`": saveData.Id}, eidtTargetCont) } else { //不存在需要新增 saveData.VersionNumber = versionNumber //版本编号"` saveData.CompanyId = companyId //归属公司"` saveData.DepartmentId = departmentId //归属部门"` saveData.OrgId = orgid //归属行政组织"` saveData.PostId = postid //归属岗位"` saveData.Title = cv.Name //考核项名称"` saveData.DimensionId = dimensionIdInt64 //维度"` saveData.TargetId = targetIdInt64 //指标"` saveData.SonTargetId = 0 //子栏目"` saveData.DetailsId = 0 //细则"` saveData.Attribute = cv.Type //属性 1:定性考核;2:定量考核"` saveData.MinScore = 0 //最小分*100保存"` saveData.MaxScore = 0 //最大分*100保存"` saveData.ScoringMethod = scoringMethod //计分方式(1:自动;2:手动)"` saveData.State = judgeState //状态(1:启用;2:禁用;3:删除)"` saveData.Addtime = timeData //添加时间"` saveData.Eitetime = timeData //编辑时间"` saveData.CensorType = "2" //检查方式(1:现场检查;2:资料检查;3:事件触发)"` saveData.Source = source //来源(1:岗位;2:部门引用)"` saveData.RunState = cv.State //运行状态(1:启用;2:禁用;3:观察) saveNewData = append(saveNewData, saveData) } if source != 1 { //来源于部门引用 // fmt.Printf("启用人员管理--1--->%v--->%v--->%v--->%v\n", source, targetIdInt64, len(cv.Operator), cv.Operator) if len(cv.Operator) > 0 { // fmt.Printf("启用人员管理--2--->%v\n", targetIdInt64) syncSetinges.Add(1) go DepartAboutPostTargetReport(dimensionIdInt64, targetIdInt64, 0, 0, orgid, postid, cv.Operator, 2, cv.Type) } } } else { //定性考核 if len(cv.Child) > 0 { //判断是否有定性考核项目 for _, cvt := range cv.Child { var sonTargetIdInt64 int64 = 0 var detailsIdInt64 int64 = 0 //获取细则内容 if source != 1 { //来源于部门引用 var depatrDeatCont modelskpi.DetailedTarget depatrDeatCont.GetCont(map[string]interface{}{"`dt_id`": cvt.Id}) sonTargetIdInt64 = depatrDeatCont.ParentIdSun detailsIdInt64 = depatrDeatCont.Id } else { //来源于岗位考核 var depatrDeatCont modelskpi.PostTargetDetails depatrDeatCont.GetCont(map[string]interface{}{"`id`": cvt.Id}) sonTargetIdInt64 = depatrDeatCont.ParentIdSun detailsIdInt64 = depatrDeatCont.Id } //判断该细则是否存在 whereLian := publicmethod.MapOut[string]() whereLian["`version_number`"] = versionNumber whereLian["`company_id`"] = companyId whereLian["`department_id`"] = departmentId whereLian["`org_id`"] = orgid whereLian["`post_id`"] = postid whereLian["`dimension_id`"] = dimensionIdInt64 whereLian["`target_id`"] = targetIdInt64 whereLian["`son_target_id`"] = sonTargetIdInt64 whereLian["`details_id`"] = detailsIdInt64 judgeLianErr := saveData.GetCont(whereLian, "`id`", "`state`") if judgeLianErr == nil { eidtTargetCont := publicmethod.MapOut[string]() eidtTargetCont["`scoring_method`"] = scoringMethod eidtTargetCont["`state`"] = judgeState eidtTargetCont["`source`"] = source eidtTargetCont["`run_state`"] = cv.State eidtTargetCont["`eitetime`"] = timeData saveData.EiteCont(map[string]interface{}{"`id`": saveData.Id}, eidtTargetCont) } else { //不存在需要新增 var minScoreInt int64 = 0 var maxScoreInt int64 = 0 scoreAry := strings.Split(cvt.ReferenceScore, "-") scoreLen := len(scoreAry) if scoreLen > 0 { if scoreLen == 1 { maxScore, _ := strconv.ParseFloat(scoreAry[0], 64) maxScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64) minScoreInt = 0 } else { minScore, _ := strconv.ParseFloat(scoreAry[0], 64) maxScore, _ := strconv.ParseFloat(scoreAry[scoreLen-1], 64) minScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(minScore*100, 'f', -1, 64), 10, 64) maxScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64) } } saveData.VersionNumber = versionNumber //版本编号"` saveData.CompanyId = companyId //归属公司"` saveData.DepartmentId = departmentId //归属部门"` saveData.OrgId = orgid //归属行政组织"` saveData.PostId = postid //归属岗位"` saveData.Title = cv.Name //考核项名称"` saveData.DimensionId = dimensionIdInt64 //维度"` saveData.TargetId = targetIdInt64 //指标"` saveData.SonTargetId = sonTargetIdInt64 //子栏目"` saveData.DetailsId = detailsIdInt64 //细则"` saveData.Attribute = cv.Type //属性 1:定性考核;2:定量考核"` saveData.MinScore = minScoreInt //最小分*100保存"` saveData.MaxScore = maxScoreInt //最大分*100保存"` saveData.ScoringMethod = scoringMethod //计分方式(1:自动;2:手动)"` saveData.State = judgeState //状态(1:启用;2:禁用;3:删除)"` saveData.Addtime = timeData //添加时间"` saveData.Eitetime = timeData //编辑时间"` saveData.CensorType = "2" //检查方式(1:现场检查;2:资料检查;3:事件触发)"` saveData.Source = source //来源(1:岗位;2:部门引用)"` saveData.RunState = cv.State //运行状态(1:启用;2:禁用;3:观察) saveNewData = append(saveNewData, saveData) } if source != 1 { //来源于部门引用 // fmt.Printf("启用人员管理--3--->%v--->%v--->%v--->%v\n", source, targetIdInt64, len(cv.Operator), cv.Operator) if len(cvt.Operator) > 0 { // fmt.Printf("启用人员管理--4--->%v--->%v\n", targetIdInt64, detailsIdInt64) syncSetinges.Add(1) go DepartAboutPostTargetReport(dimensionIdInt64, targetIdInt64, sonTargetIdInt64, detailsIdInt64, orgid, postid, cvt.Operator, 2, cv.Type) } } } } } } } } if len(saveNewData) > 0 { overall.CONSTANT_DB_KPI.Create(&saveNewData) } syncSetinges.Wait() } /* 协程处理 部门指标岗位提报人关联通用函数 @dimensionId 维度 @targetId 指标ID @targetSunId 栏目ID @bylawsId 指标细则 @departmentId 接受考核部门 @postId 岗位 @repart 提报人 @class 级别(1:部门级;2:岗位级) @nature 1:定性考核;2:定量考核 func departAboutPostTargetReport(dimensionId, targetId, targetSunId, bylawsId, departmentId, postId int64, repart []loopStruct, class, nature int) */ func DepartAboutPostTargetReport(dimensionId, targetId, targetSunId, bylawsId, departmentId, postId int64, repart []string, class, nature int) { defer syncSetinges.Done() // fmt.Printf("启用人员管理----->%v\n", targetId) //将不属于该指标细则的部门至禁用 otherSaveData := publicmethod.MapOut[string]() otherSaveData["`state`"] = 2 otherSaveData["`time`"] = time.Now().Unix() where := publicmethod.MapOut[string]() where["`type`"] = class if targetId != 0 { where["`target_id`"] = targetId } if targetSunId != 0 { where["`target_sun_id`"] = targetSunId } if bylawsId != 0 { where["`target_bylaws`"] = bylawsId } if departmentId != 0 { where["`department_id`"] = departmentId } if postId != 0 { where["`post_id`"] = postId } if len(repart) < 1 { overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(where).Updates(&otherSaveData) } else { //获取关联的人员 var userKeyAbout []string for _, v := range repart { if publicmethod.IsInTrue[string](v, userKeyAbout) == false { userKeyAbout = append(userKeyAbout, v) //获取评价人部门 var manCont modelshr.PersonArchives manCont.GetCont(map[string]interface{}{"`key`": v}, "`maindeparment`") var tarReportCont modelskpi.TargetReport trWhere := publicmethod.MapOut[string]() trWhere["`man_key`"] = v trWhere["`type`"] = class if targetId != 0 { trWhere["`target_id`"] = targetId } if targetSunId != 0 { trWhere["`target_sun_id`"] = targetSunId } if bylawsId != 0 { trWhere["`target_bylaws`"] = bylawsId } if departmentId != 0 { trWhere["`department_id`"] = departmentId } if postId != 0 { trWhere["`post_id`"] = postId } saveErr := tarReportCont.GetCont(trWhere, "`id`", "`state`") if saveErr == nil { if tarReportCont.State != 1 { tarReportCont.EiteCont(map[string]interface{}{"`id`": tarReportCont.Id}, map[string]interface{}{"`state`": 1, "`dimension_id`": dimensionId, "`man_department`": manCont.MainDeparment, "`time`": time.Now().Unix()}) } } else { xiZe := 3 if targetId != 0 && targetSunId != 0 && bylawsId == 0 { xiZe = 2 } else if targetId != 0 && targetSunId == 0 && bylawsId == 0 { xiZe = 1 } tarReportCont.Dimension = dimensionId tarReportCont.TargetId = targetId //指标ID"` tarReportCont.TargetSunId = targetSunId //子目标"` tarReportCont.TargetBylaws = bylawsId //指标细则"` tarReportCont.DepartmentId = departmentId //部门ID"` tarReportCont.PostId = postId //岗位ID"` tarReportCont.Type = class //类型(1:公司级;2:部门级)"` tarReportCont.State = 1 //状态(1:启用;2:禁用;3:删除)"` reportId, _ := strconv.ParseInt(v, 10, 64) tarReportCont.ReportPerson = reportId //上报人"` tarReportCont.ManDepartment = manCont.MainDeparment //提报人所在部门"` tarReportCont.Time = time.Now().Unix() //写入时间"` tarReportCont.Class = nature //1:定性考核;2:定量考核"` tarReportCont.Level = xiZe //1:指标;2:子目标;3:细则 overall.CONSTANT_DB_KPI.Create(&tarReportCont) } } } //清除不需要提报的人员 // if len(userKeyAbout) > 0 { // overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(where).Not(map[string]interface{}{"man_key": userKeyAbout}).Updates(&otherSaveData) // } } } // 获取岗位方案内容列表 func (a *ApiMethod) GetPostScheme(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, err, c) return } //获取维度 var schemeCont modelskpi.PositionPlanVersio errShe := overall.CONSTANT_DB_KPI.Where("`id` = ?", receivedValue.Id).First(&schemeCont).Error if errShe != nil { publicmethod.Result(107, errShe, c) return } var outData outShemeVersionCont outData.Id = strconv.FormatInt(schemeCont.Id, 10) outData.OrgId = strconv.FormatInt(schemeCont.OrgId, 10) //行政组织ID outData.PostId = strconv.FormatInt(schemeCont.Position, 10) //岗位 outData.Year = strconv.FormatInt(schemeCont.Year, 10) //年 //解析岗位指标放啊 var shemeInfo postScheme jsonErr := json.Unmarshal([]byte(schemeCont.Content), &shemeInfo) if jsonErr == nil { outData.PostChild = shemeInfo.PostChild //岗位指标 outData.DepartmentChild = shemeInfo.DepartmentChild //引用部门指标 } publicmethod.Result(0, outData, c) } // 获取复制岗位考核方案 func (a *ApiMethod) GetCopyShemeInfor(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, err, c) return } //获取维度 var schemeCont modelskpi.PositionPlanVersio errShe := overall.CONSTANT_DB_KPI.Where("`id` = ?", receivedValue.Id).First(&schemeCont).Error if errShe != nil { publicmethod.Result(107, errShe, c) return } //解析岗位指标放啊 var shemeInfo postScheme jsonErr := json.Unmarshal([]byte(schemeCont.Content), &shemeInfo) //1、获取维度 var dimensionModels modelskpi.DutyClass dimensionList, dimeErr := dimensionModels.ContMap(map[string]interface{}{"`state`": 1}, "`id`", "`title`", "`sort`") // fmt.Printf("dimensionList--->%v\n", dimensionList) if dimeErr != nil || len(dimensionList) <= 0 { publicmethod.Result(107, jsonErr, c) return } var shemePostList shemeSync //未使用的维度 var notUsedDimensionId []int64 for _, v := range dimensionList { idIsTrue := true //判断此维度是否已经使用 for _, pv := range shemeInfo.PostChild { vIdStr := strconv.FormatInt(v.Id, 10) if vIdStr == pv.Id { idIsTrue = false syncSeting.Add(1) go shemePostList.postHandleSheme(schemeCont.OrgId, schemeCont.Position, v.Id, pv) } } if idIsTrue == true { //未使用的维度,检查一下时候有需要考核的项目 if publicmethod.IsInTrue[int64](v.Id, notUsedDimensionId) == false { notUsedDimensionId = append(notUsedDimensionId, v.Id) } } } syncSeting.Wait() } /* 协程处理已经生成的维度指标是否有新的内容 @orgid 行政组织ID @postid 岗位ID @dimensId 维度ID @shemeInfo 考核项结构体 */ func (s *shemeSync) postHandleSheme(orgid, postid, dimensId int64, shemeInfo schemeStructure) { // var targetPostList []schemeTargetStructure // var idIsTrue []string // for _, v := range shemeInfo.Child { // idIsTrue = append(idIsTrue, v.Id) // var targetCont schemeTargetStructure // targetCont.Id = v.Id // targetCont.Name = v.Title // targetCont.Content = "" //指标描述 // targetCont.StandardScore = getPostDimeTarWeight(orgid, postid, dimensId, v.Id, 1, 1) //标准分 // targetCont.Unit = v.Unit //单位 // targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许 // targetCont.State = 1 // targetPostList = append(targetPostList, targetCont) // } }