package postweb import ( "encoding/json" "fmt" "key_performance_indicators/api/version1/flowchart" "key_performance_indicators/middleware/wechatapp/wechatsendmsg" "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" ) //岗位指标相关操作 // 获取指定人要考核的项目列表 func (a *ApiMethod) GetPostTarget(c *gin.Context) { var receivedValue getPostManTargetList err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Id == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.Class == 0 { receivedValue.Class = 1 } //获取被考核人基本西悉尼 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.Id}, "`company`", "`maindeparment`", "`admin_org`", "`position`") if err != nil { publicmethod.Result(107, err, c) return } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) var qualitSchemeList []modelskpi.QualitativeEvaluationScheme err = overall.CONSTANT_DB_KPI.Raw("SELECT q.* FROM qualitative_evaluation_scheme q Where q.state = 1 AND `attribute` = ? AND q.target_id = some (SELECT target_id FROM target_report tr WHERE tr.type = 2 AND tr.department_id = ? AND tr.post_id = ? AND tr.man_key = ?)", receivedValue.Class, userCont.MainDeparment, userCont.Position, context.Key).Scan(&qualitSchemeList).Error if err != nil || len(qualitSchemeList) < 1 { publicmethod.Result(107, err, c) return } var outDataAry []outPostManTargetList for _, v := range qualitSchemeList { // jsonStr, _ := json.Marshal(v) // fmt.Printf("v----------->%v\n", string(jsonStr)) var outCont outPostManTargetList outCont.Id = strconv.FormatInt(v.Id, 10) outCont.Class = v.Attribute outCont.Title = v.Title if v.Attribute == 1 { if v.Source == 1 { //岗位 var postTarDeta modelskpi.PostTargetDetails postTarDeta.GetCont(map[string]interface{}{"`id`": v.DetailsId}, "`punishmode`") outCont.AddReduce = postTarDeta.Punishmode } else { //部门 var departTarDeta modelskpi.DetailedTarget departTarDeta.GetCont(map[string]interface{}{"`dt_id`": v.DetailsId}, "`dt_add_reduce`") outCont.AddReduce = departTarDeta.AddReduce } } outDataAry = append(outDataAry, outCont) } publicmethod.Result(0, outDataAry, c) } // 定性指标列表 func (a *ApiMethod) GetPostNature(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 } //获取被考核人基本信息 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.Id}, "`company`", "`maindeparment`", "`admin_org`", "`position`") if err != nil { publicmethod.Result(107, err, c) return } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) //获取被考核人本岗位的考核项目 var itemList []modelskpi.ShemePeople err = overall.CONSTANT_DB_KPI.Where("`state` = 1 AND `tr_type` = 2 AND `attribute` = 1 AND `run_state` <> 2 AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?", userCont.AdminOrg, userCont.Position, context.Key).Find(&itemList).Error if err != nil || len(itemList) < 1 { publicmethod.Result(107, err, c) return } var targetId []int64 //获取指标内容 var outDataAry []outPostManTargetList for _, v := range itemList { if publicmethod.IsInTrue[int64](v.TargetId, targetId) == false { var tarCont modelskpi.PostTarget tarCont.GetCont(map[string]interface{}{"`id`": v.TargetId}, "`title`") var outCont outPostManTargetList outCont.Id = strconv.FormatInt(v.TargetId, 10) outCont.Title = tarCont.Title outCont.Class = v.Attribute if v.Source == 1 { //岗位 var postTarDeta modelskpi.PostTargetDetails postTarDeta.GetCont(map[string]interface{}{"`id`": v.DetailsId}, "`add_reduce`") outCont.AddReduce = postTarDeta.AddReduce } else { //部门 var departTarDeta modelskpi.DetailedTarget departTarDeta.GetCont(map[string]interface{}{"`dt_id`": v.DetailsId}, "`dt_add_reduce`") outCont.AddReduce = departTarDeta.AddReduce } outCont.UserKey = receivedValue.Id outCont.DimensionId = strconv.FormatInt(v.DimensionId, 10) outDataAry = append(outDataAry, outCont) targetId = append(targetId, v.TargetId) } } publicmethod.Result(0, outDataAry, c) } // 获取定性指标子栏目列表 func (a *ApiMethod) GetPostNatureSonTarget(c *gin.Context) { var receivedValue getSonTarList err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Id == "" { publicmethod.Result(101, receivedValue, c) return } var sonTargetList []modelskpi.PostSonTarget gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.PostSonTarget{}).Where("`parent_id` = ?", receivedValue.Id) if receivedValue.OrgId != "" { gormDb = gormDb.Where("`depart` = ?", receivedValue.OrgId) } if receivedValue.PostId != "" { gormDb = gormDb.Where("`depart_post` = ?", receivedValue.PostId) } err = gormDb.Find(&sonTargetList).Error if err != nil || len(sonTargetList) < 1 { publicmethod.Result(104, err, c) return } publicmethod.Result(0, sonTargetList, c) } // 获取定量指标列表 func (a *ApiMethod) GetPostRation(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 } //获取被考核人基本信息 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.Id}, "`company`", "`maindeparment`", "`admin_org`", "`position`") if err != nil { publicmethod.Result(107, err, c) return } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) //获取被考核人本岗位的考核项目 var itemList []modelskpi.ShemePeople err = overall.CONSTANT_DB_KPI.Where("`state` = 1 AND `tr_type` = 2 AND `attribute` = 2 AND `run_state` <> 2 AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?", userCont.AdminOrg, userCont.Position, context.Key).Find(&itemList).Error if err != nil || len(itemList) < 1 { publicmethod.Result(107, err, c) return } var targetId []int64 //获取指标内容 var outDataAry []outPostRation for _, v := range itemList { if publicmethod.IsInTrue[int64](v.TargetId, targetId) == false { var outCont outPostRation outCont.Id = strconv.FormatInt(v.TargetId, 10) outCont.ShemeId = strconv.FormatInt(v.Id, 10) outCont.Title = v.Title outCont.UserKey = receivedValue.Id outCont.DimensionId = strconv.FormatInt(v.DimensionId, 10) outDataAry = append(outDataAry, outCont) } } publicmethod.Result(0, outDataAry, c) } // 获取岗位定性考核指标细则列表 func (a *ApiMethod) GetPostDeimensoInfo(c *gin.Context) { var receivedValue getNatureDimeList err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.UserKey == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.DimensionId == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.TargetId == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.PageSize < 1 { receivedValue.PageSize = 20 } //获取被考核人基本信息 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.UserKey}, "`company`", "`maindeparment`", "`admin_org`", "`position`") if err != nil { publicmethod.Result(107, err, c) return } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) //获取被考核人本岗位的考核项目 var itemList []modelskpi.ShemePeople //SELECT * FROM `sheme_people` WHERE `state` = 1 AND `tr_type` = 2 AND `attribute` = 1 AND `run_state` <> 2 AND `dimension_id` = '16468024054665111' AND `target_id` = '3' AND `org_id` = 272 AND `post_id` = 794 AND `man_key` = 15993815826844528 AND `son_target_id` = '2' ORDER BY `son_target_id` DESC LIMIT 20 OFFSET 20 sqlStrList := "SELECT * FROM `sheme_people`" sqlListCount := "SELECT count(*) FROM `sheme_people`" sqlStr := "WHERE `state` = 1 AND `tr_type` = 2 AND `attribute` = 1 AND `run_state` <> 2" if receivedValue.DimensionId != "" { sqlStr = fmt.Sprintf("%v AND `dimension_id` = %v", sqlStr, receivedValue.DimensionId) } if receivedValue.TargetId != "" { sqlStr = fmt.Sprintf("%v AND `target_id` = %v", sqlStr, receivedValue.TargetId) } if receivedValue.Sontargetid != "" { sqlStr = fmt.Sprintf("%v AND `son_target_id` = %v", sqlStr, receivedValue.Sontargetid) } if userCont.AdminOrg != 0 { sqlStr = fmt.Sprintf("%v AND `org_id` = %v", sqlStr, userCont.AdminOrg) } if userCont.Position != 0 { sqlStr = fmt.Sprintf("%v AND `post_id` = %v", sqlStr, userCont.Position) } if context.Key != 0 { sqlStr = fmt.Sprintf("%v AND `man_key` = %v", sqlStr, context.Key) } sqlStr = fmt.Sprintf("%v ORDER BY `son_target_id` DESC", sqlStr) if receivedValue.Page <= 1 { sqlStr = fmt.Sprintf("%v LIMIT %v", sqlStr, receivedValue.PageSize) } else { sqlStr = fmt.Sprintf("%v LIMIT %v OFFSET %v", sqlStr, receivedValue.PageSize, publicmethod.LimitPage(receivedValue.Page, receivedValue.PageSize)) } var total int64 selectSqlStr := fmt.Sprintf("%v %v", sqlStrList, sqlStr) selectSqlStrCount := fmt.Sprintf("%v %v", sqlListCount, sqlStr) //原生查询 errGormEaw := overall.CONSTANT_DB_KPI.Raw(selectSqlStr).Scan(&itemList).Error overall.CONSTANT_DB_KPI.Raw(selectSqlStrCount).Scan(&total) // fmt.Printf("errGormEaw------------------->%v----------->%v----------->%v\n", itemList, errGormEaw, total) // gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.ShemePeople{}) // // gormDb = gormDb.Where("`state` = 1 AND `tr_type` = 2 AND `attribute` = 1") // // gormDb = gormDb.Where("`dimension_id` = ? AND `target_id` = ? ", receivedValue.DimensionId, receivedValue.TargetId) // // gormDb = gormDb.Where("`org_id` = ? AND `post_id` = ? AND `man_key` = ?", userCont.AdminOrg, userCont.Position, context.Key) // gormDb = gormDb.Where("`state` = 1 AND `tr_type` = 2 AND `attribute` = 1 AND `run_state` <> 2 AND `dimension_id` = ? AND `target_id` = ? AND `org_id` = ? AND `post_id` = ? AND `man_key` = ?", receivedValue.DimensionId, receivedValue.TargetId, userCont.AdminOrg, userCont.Position, context.Key) // if receivedValue.Sontargetid != "" { // gormDb = gormDb.Where("`son_target_id` = ?", receivedValue.Sontargetid) // } // gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize) // errGorm := gormDb.Order("`son_target_id` DESC").Find(&itemList).Error // totalErr := gormDb.Count(&total).Error // if totalErr != nil { // total = 0 // } // fmt.Printf("outList------------------->%v----------->%v\n", itemList, total) if errGormEaw != nil || total < 1 { publicmethod.Result(107, err, c) return } var outList []outNatureDimeCont for _, v := range itemList { var outCont outNatureDimeCont outCont.Id = v.Id outCont.VersionNumber = v.VersionNumber // 版本编号"` outCont.CompanyId = v.CompanyId // 归属公司"` outCont.DepartmentId = v.DepartmentId // 归属部门"` outCont.OrgId = v.OrgId // 归属行政组织"` outCont.PostId = v.PostId // 归属岗位"` outCont.Title = v.Title //考核项名称"` outCont.DimensionId = v.DimensionId //维度"` outCont.TargetId = v.TargetId // 指标"` outCont.SonTargetId = v.SonTargetId //子栏目"` outCont.DetailsId = v.DetailsId //细则"` outCont.Attribute = v.Attribute // 属性 1:定性考核;2:定量考核"` outCont.MinScore = publicmethod.DecimalEs(v.MinScore/100, 2) // 最小分*100保存"` outCont.MaxScore = publicmethod.DecimalEs(v.MaxScore/100, 2) //最大分*100保存"` outCont.ScoringMethod = v.ScoringMethod //计分方式(1:自动;2:手动)"` outCont.State = v.State //状态(1:启用;2:禁用;3:删除)"` outCont.Addtime = v.Addtime //添加时间"` outCont.Eitetime = v.Eitetime // 编辑时间"` outCont.CensorType = v.CensorType //检查方式(1:现场检查;2:资料检查;3:事件触发)"` outCont.Source = v.Source //来源(1:岗位;2:部门引用)"` outCont.RunState = v.RunState //运行状态(1:启用;2:禁用;3:观察)"` outCont.Type = v.Type //类型(1:公司级;2:部门级)"` outCont.ReportPerson = v.ReportPerson //上报人"` outCont.ManDepartment = v.ManDepartment //提报人所在部门"` outCont.Class = v.Class //1:定性考核;2:定量考核"` outCont.Level = v.Level //类型(1:指标;2:子目标;3:细则)"` outCont.Punishmode = v.Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金 outCont.Maxmoney = publicmethod.DecimalEs(v.Maxmoney/100, 2) //最高罚款 outCont.Minmoney = publicmethod.DecimalEs(v.Minmoney/100, 2) //最低罚款 if v.CensorType != "" { outCont.CensorTypeAry = strings.Split(v.CensorType, ",") } if v.DetailsId != 0 { //获取指标信息 if v.Source == 1 { //岗位 var targetCont modelskpi.PostTargetDetails targetCont.GetCont(map[string]interface{}{"`id`": v.DetailsId}, "`content`", "`add_reduce`", "`censor_cont`", "`company`") outCont.Context = targetCont.Content //指标说明"` outCont.AddReduce = targetCont.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"` outCont.CensorCont = targetCont.CensorCont //检查依据"` outCont.Unity = targetCont.Company } else { //部门 var departTarDeta modelskpi.DetailedTarget departTarDeta.GetCont(map[string]interface{}{"`dt_id`": v.DetailsId}, "`dt_add_reduce`", "`dt_company`") outCont.Context = departTarDeta.Content //指标说明"` outCont.AddReduce = departTarDeta.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"` outCont.CensorCont = departTarDeta.CensorCont //检查依据"` outCont.Unity = departTarDeta.Company } } if v.MinScore != 0 { outCont.ScoreStr = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(v.MinScore/100, 2), publicmethod.DecimalEs(v.MaxScore/100, 2)) } else { outCont.ScoreStr = fmt.Sprintf("%v", publicmethod.DecimalEs(v.MaxScore/100, 2)) } if v.Minmoney != 0 { outCont.MoneyStr = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(v.Minmoney/100, 2), publicmethod.DecimalEs(v.Maxmoney/100, 2)) } else { outCont.MoneyStr = fmt.Sprintf("%v", publicmethod.DecimalEs(v.Maxmoney/100, 2)) } outCont.UserKey = receivedValue.UserKey outList = append(outList, outCont) } // fmt.Printf("outList------------------->%v\n", outList) publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(outList)), outList, c) } // 获取被考核人定性指标细则详细内容 func (a *ApiMethod) GetNaturePostDimerons(c *gin.Context) { var receivedValue postNaturcInfo err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.UserKey == "" { publicmethod.Result(101, receivedValue, c) return } if receivedValue.Id == "" { publicmethod.Result(101, receivedValue, c) return } var shemeCont modelskpi.QualitativeEvaluationScheme errSheme := shemeCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}) if errSheme != nil { publicmethod.Result(107, receivedValue, c) return } var outCont outNatureDimePostCont outCont.Id = shemeCont.Id outCont.VersionNumber = shemeCont.VersionNumber // 版本编号"` outCont.CompanyId = shemeCont.CompanyId // 归属公司"` outCont.DepartmentId = shemeCont.DepartmentId // 归属部门"` outCont.OrgId = shemeCont.OrgId // 归属行政组织"` outCont.PostId = shemeCont.PostId // 归属岗位"` outCont.Title = shemeCont.Title //考核项名称"` outCont.DimensionId = shemeCont.DimensionId //维度"` outCont.TargetId = shemeCont.TargetId // 指标"` outCont.SonTargetId = shemeCont.SonTargetId //子栏目"` outCont.DetailsId = shemeCont.DetailsId //细则"` outCont.Attribute = shemeCont.Attribute // 属性 1:定性考核;2:定量考核"` outCont.MinScore = shemeCont.MinScore // 最小分*100保存"` outCont.MaxScore = shemeCont.MaxScore //最大分*100保存"` outCont.ScoringMethod = shemeCont.ScoringMethod //计分方式(1:自动;2:手动)"` outCont.State = shemeCont.State //状态(1:启用;2:禁用;3:删除)"` outCont.Addtime = shemeCont.Addtime //添加时间"` outCont.Eitetime = shemeCont.Eitetime // 编辑时间"` outCont.CensorType = shemeCont.CensorType //检查方式(1:现场检查;2:资料检查;3:事件触发)"` outCont.Source = shemeCont.Source //来源(1:岗位;2:部门引用)"` outCont.RunState = shemeCont.RunState //运行状态(1:启用;2:禁用;3:观察)"` outCont.Punishmode = shemeCont.Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金 outCont.Maxmoney = shemeCont.Maxmoney //最高罚款 outCont.Minmoney = shemeCont.Minmoney //最低罚款 if shemeCont.CensorType != "" { outCont.CensorTypeAry = strings.Split(shemeCont.CensorType, ",") } if shemeCont.DetailsId != 0 { //获取指标信息 if shemeCont.Source == 1 { //岗位 var targetCont modelskpi.PostTargetDetails targetCont.GetCont(map[string]interface{}{"`id`": shemeCont.DetailsId}, "content", "add_reduce", "censor_cont") outCont.Context = targetCont.Content //指标说明"` outCont.AddReduce = targetCont.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"` outCont.CensorCont = targetCont.CensorCont //检查依据"` } else { //部门 var departTarDeta modelskpi.DetailedTarget departTarDeta.GetCont(map[string]interface{}{"`dt_id`": shemeCont.DetailsId}, "`dt_add_reduce`") outCont.Context = departTarDeta.Content //指标说明"` outCont.AddReduce = departTarDeta.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"` outCont.CensorCont = departTarDeta.CensorCont //检查依据"` } } if shemeCont.MinScore != 0 { outCont.ScoreStr = fmt.Sprintf("%v-%v", shemeCont.MinScore, shemeCont.MaxScore) outCont.ScoreState = 2 } else if shemeCont.MinScore > 0 && shemeCont.MaxScore <= 0 { outCont.ScoreStr = fmt.Sprintf("%v", float64(shemeCont.MinScore)/100) outCont.ScoreState = 1 } else if shemeCont.MinScore <= 0 && shemeCont.MaxScore > 0 { outCont.ScoreStr = fmt.Sprintf("%v", float64(shemeCont.MaxScore)/100) outCont.ScoreState = 1 } else { outCont.ScoreStr = "0" outCont.ScoreState = 3 } if shemeCont.Minmoney != 0 { outCont.MoneyStr = fmt.Sprintf("%v-%v", shemeCont.Minmoney, shemeCont.Maxmoney) outCont.MoneyState = 2 } else if shemeCont.Minmoney > 0 && shemeCont.Maxmoney <= 0 { outCont.MoneyStr = fmt.Sprintf("%v", float64(shemeCont.Minmoney)/100) outCont.MoneyState = 1 } else if shemeCont.Minmoney <= 0 && shemeCont.Maxmoney > 0 { outCont.MoneyStr = fmt.Sprintf("%v", float64(shemeCont.Maxmoney)/100) outCont.MoneyState = 1 } else { outCont.MoneyStr = "0" outCont.MoneyState = 3 } // if shemeCont.Minmoney != 0 { // outCont.MoneyStr = fmt.Sprintf("%v-%v", shemeCont.Minmoney, shemeCont.Maxmoney) // } else { // outCont.MoneyStr = fmt.Sprintf("%v", shemeCont.Maxmoney) // } outCont.UserKey = receivedValue.UserKey publicmethod.Result(0, outCont, c) } // 提交个人岗位定性考核数据 func (a *ApiMethod) SendUsNatureEvaluation(c *gin.Context) { var receivedValue sendMyEvaluationData err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.Id == "" { publicmethod.Result(101, 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 unitTitle string var postTargetDetailInfo modelskpi.PostTargetDetails overall.CONSTANT_DB_KPI.Where(map[string]interface{}{"`id`": postShemeCont.DetailsId}).First(&postTargetDetailInfo) unitTitle = postTargetDetailInfo.Company var targetUnit modelskpi.PostTarget overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTarget{}).Select("`unit`,`title`").Where(map[string]interface{}{"`id`": postShemeCont.TargetId}).First(&targetUnit) if unitTitle == "" { unitTitle = targetUnit.Unit } if receivedValue.UserKey == "" { publicmethod.Result(101, receivedValue, c) return } //获取被考核人基本信息 var userCont modelshr.PersonArchives err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.UserKey}, "`company`", "`maindeparment`", "`admin_org`", "`position`,`wechat`,`work_wechat`") if err != nil { publicmethod.Result(107, err, c) return } if receivedValue.AddOrDecrease == 0 { receivedValue.AddOrDecrease = 2 } if receivedValue.Punishmode == 0 { receivedValue.Punishmode = 1 } var scoreVal int64 = 0 var moneyVal int64 = 0 isTrue := false var msg string switch receivedValue.Punishmode { case 1: scoreVal, isTrue, msg = judgeScoreOrMoneyIsTrue(receivedValue.ScoreState, receivedValue.Score, postShemeCont.MaxScore, postShemeCont.MinScore) if isTrue != true { publicmethod.Result(1, isTrue, c, msg) return } case 2: moneyVal, isTrue, msg = judgeScoreOrMoneyIsTrue(receivedValue.MoneyState, receivedValue.Money, postShemeCont.Maxmoney, postShemeCont.Minmoney) if isTrue != true { publicmethod.Result(1, isTrue, c, msg) return } case 3: scoreVal, isTrue, msg = judgeScoreOrMoneyIsTrue(receivedValue.ScoreState, receivedValue.Score, postShemeCont.MaxScore, postShemeCont.MinScore) if isTrue != true { publicmethod.Result(1, isTrue, c, msg) return } moneyVal, isTrue, msg = judgeScoreOrMoneyIsTrue(receivedValue.MoneyState, receivedValue.Money, postShemeCont.Maxmoney, postShemeCont.Minmoney) if isTrue != true { publicmethod.Result(1, isTrue, c, msg) return } } if receivedValue.Count == 0 { receivedValue.Count = 1 } currentTime := time.Now().Unix() if receivedValue.HappenTime != "" { happTime, timeErr := publicmethod.DateToTimeStamp(receivedValue.HappenTime) if timeErr == true { currentTime = happTime } } if receivedValue.Rectification == 0 { receivedValue.Rectification = 2 } var correctionTime int64 = 0 if receivedValue.Rectification == 1 { if receivedValue.CorrectionPeriod == "" { publicmethod.Result(1, isTrue, c, "请选择什么时间前整改完成!") return } var corrTimeErr bool = false correctionTime, corrTimeErr = publicmethod.DateToTimeStamp(receivedValue.CorrectionPeriod) if corrTimeErr == false { publicmethod.Result(1, corrTimeErr, c, "请输入整改期限时间格式不对,谢谢!") return } } //获取登录人信息 context, _ := publicmethod.LoginMyCont(c) uuId := publicmethod.GetUUid(1) addTime := time.Now().Unix() //生成工作流 wechatOpenId := context.Wechat if context.WorkWechat != "" { wechatOpenId = context.WorkWechat } var reviewFlowCont flowchart.ReviewFlow reviewFlowCont.Id = receivedValue.Id reviewFlowCont.IsCorrection = receivedValue.Rectification reviewFlowCont.PlusReduction = receivedValue.AddOrDecrease reviewFlowCont.PeopleList = append(reviewFlowCont.PeopleList, receivedValue.UserKey) flowMap, _ := flowchart.SetUpWorkFlow(wechatOpenId, context.MainDeparment, reviewFlowCont, 1) var sendUserList []string //审批人列表 var sendTitle string //标题 //获取下一个节点审批人 for _, v := range flowMap { if v.Step == 2 { sendTitle = v.NodeName for _, vu := range v.UserList { // fmt.Printf("vu------------>%v\n", vu) if publicmethod.IsInTrue[string](vu.Wechat, sendUserList) == false { sendUserList = append(sendUserList, vu.Wechat) } } } } //流程列表 var flowCont modelskpi.PostWorkflowOrders flowCont.OrderId = uuId //审批单ID"` flowCont.Step = 1 //当前执行到第几步"` flowCont.NextStep = 2 //下一步执行哪个步骤"` flowMapJson, _ := json.Marshal(flowMap) flowCont.WorkFlow = string(flowMapJson) //工作流(审批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) //附件"` } //定性考核流水 var postNatureFlowCont modelskpi.PostNatureFlow postNatureFlowCont.OrderId = uuId //审批单ID"` postNatureFlowCont.AddOrDecrease = receivedValue.AddOrDecrease //增加或减少(1:增加;2:减少)"` postNatureFlowCont.Score = scoreVal //分值(*100保存)"` postNatureFlowCont.Money = moneyVal //钱(扣款或奖励)*100保存"` postNatureFlowCont.Reason = receivedValue.Reason //这样操作的原因"` postNatureFlowCont.ShemeId = postShemeCont.Id //方案ID"` postNatureFlowCont.ShemeVersion = postShemeCont.VersionNumber //方案版本编号"` postNatureFlowCont.Dimension = postShemeCont.DimensionId //维度"` postNatureFlowCont.Target = postShemeCont.TargetId //指标"` postNatureFlowCont.SonTarget = postShemeCont.SonTargetId //指标子栏目"` postNatureFlowCont.Detailed = postShemeCont.DetailsId //指标细则"` postNatureFlowCont.Year = publicmethod.ComputingTime(currentTime, 1) //年"` postNatureFlowCont.Quarter = publicmethod.ComputingTime(currentTime, 2) //季度"` postNatureFlowCont.Month = publicmethod.ComputingTime(currentTime, 3) //月"` postNatureFlowCont.Week = publicmethod.ComputingTime(currentTime, 4) //周"` postNatureFlowCont.PersonLiable = userCont.Key //责任人"` postNatureFlowCont.CompanyId = userCont.Company //公司"` postNatureFlowCont.DepartmentId = userCont.MainDeparment //部门"` postNatureFlowCont.OrgId = userCont.AdminOrg //行政组织"` postNatureFlowCont.PostId = userCont.Position //岗位"` postNatureFlowCont.Executor = context.Key //执行人"` postNatureFlowCont.ExecutorDepartment = context.MainDeparment //执行人部门"` postNatureFlowCont.Rectification = receivedValue.Rectification //是否需要整改 1、需要整改;2:无需整改"` postNatureFlowCont.CorrectionTime = correctionTime //整改期限"` postNatureFlowCont.HappenTime = currentTime //发生时间"` postNatureFlowCont.HappenCount = receivedValue.Count //发生次数"` postNatureFlowCont.Time = time.Now().Unix() //时间"` //开启事务提交 gormDbAffair := overall.CONSTANT_DB_KPI.Begin() passorErr := gormDbAffair.Create(&flowCont).Error flowErr := gormDbAffair.Create(&postNatureFlowCont).Error // openAppChangeErr := gormDbAffair.Create(&openAppChangeLog).Error if passorErr == nil && flowErr == nil { addErr := gormDbAffair.Commit().Error publicmethod.Result(0, addErr, c) if len(sendUserList) > 0 { //项下一个审批节点发送审批通知 //头部信息 var sourceText wechatsendmsg.SourceText sourceText.IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png" sourceText.Desc = fmt.Sprintf("恒信高科-%v", sendTitle) sourceText.DescColor = 1 //考核标准 var sunTextCont string var quoteTextCont string switch postTargetDetailInfo.Punishmode { case 2: var moneyTitle string if receivedValue.AddOrDecrease == 1 { moneyTitle = "现金奖励标准" quoteTextCont = fmt.Sprintf("奖励现金:%v元", receivedValue.Money) } else { moneyTitle = "现金罚款标准" quoteTextCont = fmt.Sprintf("罚款现金:%v元", receivedValue.Money) } var scoreStr string if postTargetDetailInfo.Minmoney != 0 { scoreStr = fmt.Sprintf("%v元-%v元", publicmethod.DecimalEs(float64(postTargetDetailInfo.Minmoney)/100, 2), publicmethod.DecimalEs(float64(postTargetDetailInfo.Maxmoney)/100, 2)) } else { scoreStr = fmt.Sprintf("%v元", publicmethod.DecimalEs(float64(postTargetDetailInfo.Maxmoney)/100, 2)) } sunTextCont = fmt.Sprintf("%v:%v", moneyTitle, scoreStr) if receivedValue.Reason != "" { quoteTextCont = fmt.Sprintf("%v\n备注:%v", quoteTextCont, receivedValue.Reason) } case 3: var moneyTitle string var scoreTitle string if receivedValue.AddOrDecrease == 1 { moneyTitle = "现金奖励标准" scoreTitle = "考核扣分标准" quoteTextCont = fmt.Sprintf("考核加:%v%v\n奖励现金:%v元", receivedValue.Score, unitTitle, receivedValue.Money) } else { moneyTitle = "现金罚款标准" scoreTitle = "考核加分标准" quoteTextCont = fmt.Sprintf("考核扣:%v%v\n罚款现金:%v元", receivedValue.Score, unitTitle, receivedValue.Money) } var scoreStr string if postTargetDetailInfo.MinScore != 0 { scoreStr = fmt.Sprintf("%v%v-%v%v", publicmethod.DecimalEs(float64(postTargetDetailInfo.MinScore)/100, 2), unitTitle, publicmethod.DecimalEs(float64(postTargetDetailInfo.MaxScore)/100, 2), unitTitle) } else { scoreStr = fmt.Sprintf("%v%v", publicmethod.DecimalEs(float64(postTargetDetailInfo.MaxScore)/100, 2), unitTitle) } sunTextCont = fmt.Sprintf("%v:%v", scoreTitle, scoreStr) if postTargetDetailInfo.Minmoney != 0 { sunTextCont = fmt.Sprintf("%v\n%v:%v元-%v元", sunTextCont, moneyTitle, publicmethod.DecimalEs(float64(postTargetDetailInfo.Minmoney)/100, 2), publicmethod.DecimalEs(float64(postTargetDetailInfo.Maxmoney)/100, 2)) } else { sunTextCont = fmt.Sprintf("%v\n%v:%v元", sunTextCont, moneyTitle, publicmethod.DecimalEs(float64(postTargetDetailInfo.Maxmoney)/100, 2)) } if receivedValue.Reason != "" { quoteTextCont = fmt.Sprintf("%v\n备注:%v", quoteTextCont, receivedValue.Reason) } default: var scoreTitle string if receivedValue.AddOrDecrease == 1 { scoreTitle = "考核加分标准" quoteTextCont = fmt.Sprintf("考核加:%v%v", receivedValue.Score, unitTitle) } else { scoreTitle = "考核扣分标准" quoteTextCont = fmt.Sprintf("考核扣:%v%v", receivedValue.Score, unitTitle) } var scoreStr string if postTargetDetailInfo.MinScore != 0 { scoreStr = fmt.Sprintf("%v%v-%v%v", publicmethod.DecimalEs(float64(postTargetDetailInfo.MinScore)/100, 2), unitTitle, publicmethod.DecimalEs(float64(postTargetDetailInfo.MaxScore)/100, 2), unitTitle) } else { scoreStr = fmt.Sprintf("%v%v", publicmethod.DecimalEs(float64(postTargetDetailInfo.MaxScore)/100, 2), unitTitle) } sunTextCont = fmt.Sprintf("%v:%v", scoreTitle, scoreStr) if receivedValue.Reason != "" { quoteTextCont = fmt.Sprintf("%v\n备注:%v", quoteTextCont, receivedValue.Reason) } } //引用文献 var quoteAreaInfo wechatsendmsg.QuoteAreaCont quoteAreaInfo.Type = 0 quoteAreaInfo.Title = "考核明细" quoteAreaInfo.QuoteText = quoteTextCont //按钮 var buttonList []wechatsendmsg.ButtonListCont var buttonList1 wechatsendmsg.ButtonListCont buttonList1.Text = "批准" buttonList1.Style = 1 buttonList1.Key = fmt.Sprintf("KPI_post_%v_%v_%v", uuId, 1, 1) buttonList = append(buttonList, buttonList1) var buttonList2 wechatsendmsg.ButtonListCont buttonList2.Text = "驳回" buttonList2.Style = 3 buttonList2.Key = fmt.Sprintf("KPI_post_%v_%v_%v", uuId, 2, 1) buttonList = append(buttonList, buttonList2) //二级标题+文本列表 var twoTitleTextList []wechatsendmsg.HorizontalContentListInfo //发送人 var horizontalContentLis3 wechatsendmsg.HorizontalContentListInfo horizontalContentLis3.KeyName = "申请人:" horizontalContentLis3.Value = "点击查看" horizontalContentLis3.Type = 3 horizontalContentLis3.Userid = wechatOpenId twoTitleTextList = append(twoTitleTextList, horizontalContentLis3) //被考核人 if userCont.Wechat != "" || userCont.WorkWechat != "" { weChatStrs := userCont.Wechat if userCont.WorkWechat != "" { weChatStrs = userCont.WorkWechat } var twoTitleTextCont wechatsendmsg.HorizontalContentListInfo twoTitleTextCont.KeyName = "被考核人:" twoTitleTextCont.Value = "点击查看" twoTitleTextCont.Type = 3 twoTitleTextCont.Userid = weChatStrs twoTitleTextList = append(twoTitleTextList, twoTitleTextCont) } //卡片跳转地址 var cardActionContStr wechatsendmsg.CardActionCont cardActionContStr.Type = 1 cardActionContStr.Url = fmt.Sprintf("http://new.hxgk.group/#/quantitativeList?id=%v", uuId) var sendButtionMsg wechatsendmsg.SendButtonInteractionSimplify // sendButtionMsg.Touser = strings.Join(sendUserList, "|") sendButtionMsg.Touser = "KaiXinGuo" //指定接收消息的成员,成员ID列表;特殊情况:指定为 sendButtionMsg.Msgtype = "template_card" agentIdInt, _ := strconv.ParseInt(overall.CONSTANT_CONFIG.WechatKpi.Agentid, 10, 64) sendButtionMsg.Agentid = agentIdInt sendButtionMsg.EnableDuplicateCheck = 0 sendButtionMsg.DuplicateCheckInterval = 1800 sendButtionMsg.EnableIdTrans = 0 sendButtionMsg.TemplateCard.CardType = "button_interaction" sendButtionMsg.TemplateCard.Source = sourceText sendButtionMsg.TemplateCard.TaskId = fmt.Sprintf("KPI_%v", uuId) sendButtionMsg.TemplateCard.MainTitle.Title = targetUnit.Title descInfo := postTargetDetailInfo.Title // if postTargetDetailInfo.CensorCont != "" { // descInfo = fmt.Sprintf("%v\n检查依据:%v", descInfo, postTargetDetailInfo.CensorCont) // } // if postTargetDetailInfo.Content != "" { // if descInfo != "" { // descInfo = fmt.Sprintf("%v\n备注:%v", descInfo, postTargetDetailInfo.Content) // } else { // descInfo = fmt.Sprintf("备注:%v", postTargetDetailInfo.Content) // } // } sendButtionMsg.TemplateCard.MainTitle.Desc = descInfo sendButtionMsg.TemplateCard.QuoteArea = quoteAreaInfo sendButtionMsg.TemplateCard.SubTitleText = sunTextCont sendButtionMsg.TemplateCard.ButtonList = buttonList sendButtionMsg.TemplateCard.HorizontalContentList = twoTitleTextList sendButtionMsg.TemplateCard.CardAction = cardActionContStr callData, err := sendButtionMsg.SendMsg("kpi") if err == nil { if callData.Errcode == 0 { // var operatorIsTrueCont modelskpi.OperatorIsTrue // operatorIsTrueCont.OrderId = uuId //订单ID"` // operatorIsTrueCont.Step = 1 //审批到第几步"` // operatorIsTrueCont.State = 1 //:状态:1:可操作;2:不可操作"` // operatorIsTrueCont.Time = addTime //操作时间"` // operatorIsTrueCont.Msgid = callData.Msgid //:消息id,用于撤回应用消息"` // operatorIsTrueCont.ResponseCode = callData.ResponseCode //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,24小时内有效,且只能使用一次"` // operatorIsTrueCont.Stepper = 1 // overall.CONSTANT_DB_KPI.Create(&operatorIsTrueCont) var openAppChangeLog modelskpi.OpenApprovalChangeLog openAppChangeLog.Type = 2 openAppChangeLog.Title = "创建申请" openAppChangeLog.Operator = context.Key openAppChangeLog.OrderId = uuId // 审批单ID"` openAppChangeLog.OperatorTime = addTime openAppChangeLog.Step = 1 openAppChangeLog.OperatorType = 2 openAppChangeLog.Msgid = callData.Msgid //:消息id,用于撤回应用消息"` openAppChangeLog.ResponseCode = callData.ResponseCode //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,24小时内有效,且只能使用一次"` openAppChangeLog.Stepper = 1 openAppChangeLog.ChangeIsTrue = 1 //是否可变更(1:可变更;2:不可变更)"` overall.CONSTANT_DB_KPI.Create(&openAppChangeLog) } } // jsonstr, _ := json.Marshal(callData) // fmt.Printf("callData------>%v--------err--------->%v--------->%v\n", callData, err, string(jsonstr)) } } else { addErr := gormDbAffair.Rollback().Error publicmethod.Result(104, addErr, c) } // fmt.Printf("%v---%v---%v---%v---%v\n", currentTime, uuId, flowCont, scoreVal, moneyVal) } /* 判断分数是否符合要求 @scoreState 1、定分;2、区间分;3、不定性分值 @score 要操作的数值 @MaxScore 最大值 @minScore 最小值 */ func judgeScoreOrMoneyIsTrue(scoreState int, score string, maxScore, minScore int64) (scoreInt64 int64, isTrue bool, msg string) { isTrue = false switch scoreState { case 2, 3: if score == "" { return } scoreInt64, _ = strconv.ParseInt(score, 10, 64) scoreInt64 = scoreInt64 * 100 if scoreInt64 > maxScore { msg = fmt.Sprintf("您提交的数值超过允许提交的最大值(最大值:%v)!", float64(maxScore)/100) return } if scoreInt64 < minScore { msg = fmt.Sprintf("您提交的数值低于允许提交的最小值(最小值:%v)!", float64(minScore)/100) return } isTrue = true case 1: scoreInt64, _ = strconv.ParseInt(score, 10, 64) scoreInt64 = scoreInt64 * 100 isTrue = true default: msg = "请您输入要操作的数据,谢谢!" return } return }