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) GetSchemeList(c *gin.Context) { var receivedValue postSchemeList c.ShouldBindJSON(&receivedValue) if receivedValue.Page == 0 { receivedValue.Page = 1 } if receivedValue.PageSize == 0 { receivedValue.PageSize = 20 } var schemeList []modelskpi.PositionPlanVersio gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.PositionPlanVersio{}).Where("`state` BETWEEN ? AND ?", 1, 2) if receivedValue.VersionNumber != "" { gormDb = gormDb.Where("`key` LIKE ?", "%"+receivedValue.VersionNumber+"%") } if receivedValue.CompanyId != "" { gormDb = gormDb.Where("`group` = ?", receivedValue.CompanyId) } if receivedValue.DepartmentId != "" { gormDb = gormDb.Where("`department` = ?", receivedValue.DepartmentId) } if receivedValue.OrgId != "" { gormDb = gormDb.Where("`orgid` = ?", receivedValue.OrgId) } if receivedValue.PostId != "" { gormDb = gormDb.Where("`position` = ?", receivedValue.PostId) } if receivedValue.Year != 0 { gormDb = gormDb.Where("`years` = ?", receivedValue.Year) } if receivedValue.State != 0 { gormDb = gormDb.Where("`state` = ?", receivedValue.State) } else { gormDb = gormDb.Where("`state` BETWEEN ? AND ?", 1, 2) } gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize) err := gormDb.Order("`state` ASC").Order("`version` ASC").Order("`id` DESC").Find(&schemeList).Error var total int64 totalErr := gormDb.Count(&total).Error if totalErr != nil { total = 0 } if err != nil || len(schemeList) < 1 { publicmethod.Result(107, err, c) return } var sendData []sendPostSchemeList for i := 0; i < len(schemeList); i++ { var sendDataCont sendPostSchemeList sendDataCont.Id = schemeList[i].Id sendDataCont.Group = schemeList[i].Group //归属集团"` sendDataCont.Department = schemeList[i].Department //归属部门"` sendDataCont.OrgId = schemeList[i].OrgId //行政组织"` sendDataCont.Position = schemeList[i].Position //归属岗位"` sendDataCont.Key = schemeList[i].Key //编码"` sendDataCont.Versio = schemeList[i].Versio //版本号"` sendDataCont.Year = schemeList[i].Year //年度"` sendDataCont.State = schemeList[i].State //状态(1:启用;2:禁用;3:删除)"` sendDataCont.AddTime = schemeList[i].AddTime //创建时间"` sendDataCont.EiteTime = schemeList[i].EiteTime //修改时间"` sendDataCont.Content = schemeList[i].Content //版本内容"` sendDataCont.IdStr = strconv.FormatInt(schemeList[i].Id, 10) var comCont modelshr.AdministrativeOrganization comCont.GetCont(map[string]interface{}{"`id`": schemeList[i].Group}, "`name`") sendDataCont.CompanyName = comCont.Name //归属公司"` comCont.GetCont(map[string]interface{}{"`id`": schemeList[i].Department}, "`name`") sendDataCont.DepartmentName = comCont.Name //归属部门"` comCont.GetCont(map[string]interface{}{"`id`": schemeList[i].OrgId}, "`name`") sendDataCont.OrgName = comCont.Name //归属行政组织"` var postContInfo modelshr.Position postContInfo.GetCont(map[string]interface{}{"`id`": schemeList[i].Position}, "`name`") sendDataCont.PostName = postContInfo.Name //`归属岗位"` sendData = append(sendData, sendDataCont) } publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(sendData)), sendData, c) } // 获取岗位相关指标 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, 2, 1) //标准分 targetCont.Unit = v.Unit //单位 targetCont.IsTrue = 2 //是否允许修改 1:不允许;2:允许 targetCont.Type = v.Type 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) float64 { 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 syncSetingRun.Add(1) go xieChengWeight(0, orgid, postid, dimensionIdInt64, 0, 1, 1, v.Score) //添加维度分值记录 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 } syncSetingRun.Add(1) go xieChengWeight(int64(cv.Type), orgid, postid, dimensionIdInt64, targetIdInt64, 2, 1, cv.Score) 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 if cv.Content != "" { eidtTargetCont["`content`"] = cv.Content } 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.Content = cv.Content //考核项说明"` 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) fmt.Printf("postSonTarget--------->%v\n", postSonTarget) if len(postSonTarget) > 0 { for _, son_v := range postSonTarget { fmt.Printf("son_v--------->%v\n", son_v) syncSetinges.Add(1) go xizeXiecheng.eidtPostSchemeInfo(versionNumber, companyId, departmentId, orgid, postid, dimensionIdInt64, son_v.ParentId, son_v.Id, cv.State, scoringMethod, judgeState) } } } } } } syncSetinges.Wait() syncSetingRun.Wait() writeData := xizeXiecheng.readDataLock() if len(writeData) > 0 { for _, wdv := range writeData { saveNewData = append(saveNewData, wdv) } } 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) fmt.Printf("postTargetDetailsCont--------->%v\n", postTargetDetailsCont) if len(postTargetDetailsCont) > 0 { for _, v := range postTargetDetailsCont { var saveData modelskpi.QualitativeEvaluationScheme //方案内容结构体 //判断该细则是否存在 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`"] = dimensionId whereLian["`target_id`"] = targetId whereLian["`son_target_id`"] = sonTargetId whereLian["`details_id`"] = v.Id judgeLianErr := saveData.GetCont(whereLian, "`id`", "`state`") if judgeLianErr == nil { eidtTargetCont := publicmethod.MapOut[string]() eidtTargetCont["`scoring_method`"] = scoringMethod eidtTargetCont["`state`"] = targetState eidtTargetCont["`source`"] = 1 eidtTargetCont["`run_state`"] = runState eidtTargetCont["`eitetime`"] = timeData eidtTargetCont["`min_score`"] = v.MinScore eidtTargetCont["`max_score`"] = v.MaxScore eidtTargetCont["`punishmode`"] = v.Punishmode eidtTargetCont["`maxmoney`"] = v.Maxmoney eidtTargetCont["`minmoney`"] = v.Minmoney eidtTargetCont["`add_reduce`"] = v.AddReduce saveData.EiteCont(map[string]interface{}{"`id`": saveData.Id}, eidtTargetCont) fmt.Printf("judgeLianErr--------->%v\n", saveData) } else { //不存在需要新增 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 = dimensionId //维度"` 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 //最低罚款 saveData.AddReduce = v.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"` p.shememList = append(p.shememList, saveData) fmt.Printf("judgeLianErr----saveData----->%v\n", 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 syncSetingRun.Add(1) go xieChengWeight(0, orgid, postid, dimensionIdInt64, 0, 1, 2, v.Score) //添加维度分值记录 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 } } syncSetingRun.Add(1) go xieChengWeight(int64(cv.Type), orgid, postid, dimensionIdInt64, targetIdInt64, 2, 2, cv.Score) 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 if cv.Content != "" { eidtTargetCont["`content`"] = cv.Content } 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.Content = cv.Content 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 if cv.Content != "" { eidtTargetCont["`content`"] = cv.Content } 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.Content = cv.Content 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() syncSetingRun.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) } } } if len(notUsedDimensionId) > 0 { for _, nuduv := range notUsedDimensionId { syncSeting.Add(1) go shemePostList.postHandleShemeNot(schemeCont.OrgId, schemeCont.Position, nuduv) } } syncSeting.Wait() shemeList := shemePostList.readDataLock() if len(shemeList) < 1 { publicmethod.Result(1, shemeList, c, "该岗位没有设定专属指标!您可以从部门指标中引入!") return } //根据维度序号排序 sort.Slice(shemeList, func(i, j int) bool { return shemeList[i].Sort < shemeList[j].Sort }) shemeInfo.PostChild = shemeList publicmethod.Result(0, shemeInfo, c) } /* 协程处理已经生成的维度指标是否有新的内容 @orgid 行政组织ID @postid 岗位ID @dimensId 维度ID @shemeInfo 考核项结构体 */ func (s *shemeSync) postHandleSheme(orgid, postid, dimensId int64, shemeInfo schemeStructure) { s.mutext.Lock() defer s.mutext.Unlock() var targetPostList schemeStructure //获取维度信息 var dimeCont modelskpi.DutyClass dimeCont.GetCont(map[string]interface{}{"`id`": dimensId}, "`title`") targetPostList.Id = shemeInfo.Id targetPostList.Name = shemeInfo.Name targetPostList.Sort = dimeCont.Sort targetPostList.Score = shemeInfo.Score var idIsTrue []string for _, v := range shemeInfo.Child { idIsTrue = append(idIsTrue, v.Id) targetPostList.Child = append(targetPostList.Child, v) } //获取被指标下的其他 var otherTarget []modelskpi.PostTarget if len(idIsTrue) > 0 { overall.CONSTANT_DB_KPI.Where("`state` = 1 AND `rele_depart` = ? AND `departments_post` AND `dimension` = ?", orgid, postid, dimensId).Not(map[string]interface{}{"`id`": idIsTrue}).Find(&otherTarget) } if len(otherTarget) > 0 { for _, otv := range otherTarget { var tarCont schemeTargetStructure tarCont.Id = strconv.FormatInt(otv.Id, 10) //id tarCont.Name = otv.Title //名称 tarCont.Content = "" //说明 scorcFloatInt := getPostDimeTarWeight(orgid, postid, dimensId, otv.Id, 2, 1) tarCont.Score = float64(scorcFloatInt) //`json:"score"` //分数 tarCont.State = 1 //状态:1:启用;2:禁用;3:观察 tarCont.Type = otv.Type // //1、定性指标;2、定量指标 targetPostList.Child = append(targetPostList.Child, tarCont) } } s.shememList = append(s.shememList, targetPostList) syncSeting.Done() } /* 协程处理未生成的维度指标是否有新的内容 @orgid 行政组织ID @postid 岗位ID @dimensId 维度ID */ func (s *shemeSync) postHandleShemeNot(orgid, postid, dimensId int64) { s.mutext.Lock() defer s.mutext.Unlock() var targetPostList schemeStructure //获取维度信息 var dimeCont modelskpi.DutyClass dimeCont.GetCont(map[string]interface{}{"`id`": dimensId}, "`title`") targetPostList.Id = strconv.FormatInt(dimeCont.Id, 10) targetPostList.Name = dimeCont.Title targetPostList.Sort = dimeCont.Sort targetPostList.Score = 0 //获取维度下的指标 var otherTarget []modelskpi.PostTarget overall.CONSTANT_DB_KPI.Where("`state` = 1 AND `rele_depart` = ? AND `departments_post` AND `dimension` = ?", orgid, postid, dimensId).Find(&otherTarget) if len(otherTarget) > 0 { for _, otv := range otherTarget { var tarCont schemeTargetStructure tarCont.Id = strconv.FormatInt(otv.Id, 10) //id tarCont.Name = otv.Title //名称 tarCont.Content = "" //说明 scorcFloatInt := getPostDimeTarWeight(orgid, postid, dimensId, otv.Id, 2, 1) tarCont.Score = float64(scorcFloatInt) //`json:"score"` //分数 tarCont.State = 1 //状态:1:启用;2:禁用;3:观察 tarCont.Type = otv.Type // //1、定性指标;2、定量指标 targetPostList.Child = append(targetPostList.Child, tarCont) } } s.shememList = append(s.shememList, targetPostList) syncSeting.Done() } // 编辑方案版本状态或删除 func (a *ApiMethod) EditSchemeStateOfDel(c *gin.Context) { var receivedValue publicmethod.PublicState err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.IsTrue == 0 { receivedValue.IsTrue = 2 } if receivedValue.State == 0 { receivedValue.State = 1 } if receivedValue.Id == "" { publicmethod.Result(1, err, c, "未知系统参数!") return } where := map[string]interface{}{"`id`": receivedValue.Id} var oldSystemCont modelskpi.PositionPlanVersio err = oldSystemCont.GetCont(where) if err != nil { publicmethod.Result(107, err, c) return } if receivedValue.State != 3 { saveData := publicmethod.MapOut[string]() saveData["`state`"] = receivedValue.State saveData["`eitetime`"] = time.Now().Unix() err = oldSystemCont.EiteCont(where, saveData) } else { // if receivedValue.IsTrue != 1 { saveData := publicmethod.MapOut[string]() saveData["`state`"] = receivedValue.State saveData["`eitetime`"] = time.Now().Unix() err = oldSystemCont.EiteCont(where, saveData) // } else { // err = overall.CONSTANT_DB_System_Permission.Where(where).Delete(&oldSystemCont).Error // } } if err != nil { publicmethod.Result(106, err, c) return } editSchemeOther(oldSystemCont, receivedValue.State) publicmethod.Result(0, err, c) } // 编辑方案状态的时候将附属表单状态一块处理 func editSchemeOther(schemeCont modelskpi.PositionPlanVersio, state int) { if schemeCont.Id == 0 { return } switch state { case 1: // 将本岗位下其他方案内容禁用 saveData := publicmethod.MapOut[string]() saveData["`state`"] = 2 saveData["`eitetime`"] = time.Now().Unix() overall.CONSTANT_DB_KPI.Model(&modelskpi.QualitativeEvaluationScheme{}).Where("`company_id` = ? AND `department_id` = ? AND `org_id` = ? AND `post_id` = ? AND `version_number` <> ?", schemeCont.Group, schemeCont.Department, schemeCont.OrgId, schemeCont.Position, schemeCont.Key).Updates(saveData) // 将本岗位下其他方案禁用 var oldSystemCont modelskpi.PositionPlanVersio saveDataOther := publicmethod.MapOut[string]() saveDataOther["`state`"] = 2 saveDataOther["`eitetime`"] = time.Now().Unix() where := map[string]interface{}{"`id`": schemeCont.Id} oldSystemCont.EiteCont(where, saveDataOther) //开启本岗位方案详情 var qesCont modelskpi.QualitativeEvaluationScheme qesCont.EiteCont(map[string]interface{}{"`version_number`": schemeCont.Key}, map[string]interface{}{"`state": 1}) case 3: var qesCont modelskpi.QualitativeEvaluationScheme qesCont.EiteCont(map[string]interface{}{"`version_number`": schemeCont.Key}, map[string]interface{}{"`state": 4}) default: var qesCont modelskpi.QualitativeEvaluationScheme qesCont.EiteCont(map[string]interface{}{"`version_number`": schemeCont.Key}, map[string]interface{}{"`state": 2}) } } /* * @ 作者: 秦东 @ 时间: 2022-10-25 15:04:05 @ 功能: 协程写入岗位维度或指标权重 @ 参数 #class 0:维度;1:定性考核;2:定量考核"` #orgid 行政组织" #postid 岗位 #dimensionIdInt64 考核维度 #target 指标 #weight 权重 #hierarchy 1:维度;2:指标 #quote 1:不是引用;2:引用部门 xieChengWeight(class, orgid, postid, dimensionIdInt64, target, hierarchy, quote int64, weight float64) syncSetingRun.Done() @ 返回值 # */ func xieChengWeight(class, orgid, postid, dimensionIdInt64, target, hierarchy, quote int64, weight float64) { defer syncSetingRun.Done() var dimWeight modelskpi.DepartDimePostWeight dimWeight.Type = class //1:定性考核;2:定量考核"` dimWeight.Orgid = orgid //行政组织"` dimWeight.Postid = postid //岗位"` dimWeight.Dimension = dimensionIdInt64 //考核维度"` dimWeight.Target = target //指标"` dimWeight.Weight = weight //权重"` dimWeight.Addtime = time.Now().Unix() //添加时间"` dimWeight.Hierarchy = hierarchy //1:维度;2:指标"` dimWeight.Quote = quote //1:不是引用;2:引用部门"` dimWeight.WriteTargetWeight() }