package statistics import ( "encoding/json" "fmt" "strconv" "strings" "time" "github.com/flipped-aurora/gin-vue-admin/server/api/statistics/quantification" "github.com/flipped-aurora/gin-vue-admin/server/commonus" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/gin-gonic/gin" ) //考核入口 func (a *ApiGroup) Index(c *gin.Context) { outPut := commonus.MapOut() response.Result(0, outPut, "方案数据表格获取成功", c) } //方案数据表格统计 func (a *ApiGroup) PlanVersioStatistics(c *gin.Context) { var requestData commonus.SetIds err := c.ShouldBindJSON(&requestData) if err != nil { response.Result(101, err, "参数错误!请重新提交!", c) return } if requestData.Id == 0 && requestData.OutId == "" { response.Result(102, err, "参数错误!请重新提交!", c) return } if requestData.OutId != "" && requestData.Id == 0 { idInt, _ := strconv.ParseInt(requestData.OutId, 10, 64) requestData.Id = idInt } var planVersioCont DutyPlanVersioOut contErr := global.GVA_DB_Performanceappraisal.Where("`id` = ?", requestData.Id).First(&planVersioCont).Error if contErr != nil { response.Result(103, contErr, "没有查询到数据", c) return } var planInfo []AddDutyNewCont jsonErr := json.Unmarshal([]byte(planVersioCont.Content), &planInfo) if jsonErr != nil { response.Result(104, contErr, "没有查询到数据", c) return } outCont := commonus.MapOut() outCont["planInfo"] = planInfo outCont["jsonErr"] = jsonErr outCont["Content"] = planVersioCont.Content response.Result(0, outCont, "获取成功", c) } //根据部门获取绩效考核数据统计表格 func (a *ApiGroup) DepartPerAppDataStatistics(c *gin.Context) { isTrue, userCont := commonus.ClientIdentity() if isTrue != true { response.Result(101, isTrue, "您的身份令牌已经失效!请重新登录获取身份令牌!", c) return } var requestData DutyPlanVersio c.ShouldBindJSON(&requestData) if requestData.Year == "" { requestData.Year = commonus.TimeStampToDate(time.Now().Unix(), 11) } var planVersioCont []assessmentmodel.PlanVersio gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.PlanVersio{}).Where("`state` = 1") switch userCont.IsAdmin { case "2": if requestData.DeaprtId != "" { gormDb = gormDb.Where("`department` = ? ", userCont.Deparment) } gormDb = gormDb.Where("`group` = ? ", userCont.Company) case "3": if requestData.Group != "" { gormDb = gormDb.Where("`group` = ? ", requestData.Group) } if requestData.DeaprtId != "" { gormDb = gormDb.Where("`department` = ? ", requestData.DeaprtId) } case "4": if requestData.Group != "" { gormDb = gormDb.Where("`group` = ? ", requestData.Group) } if requestData.DeaprtId != "" { gormDb = gormDb.Where("`department` = ? ", requestData.DeaprtId) } default: // gormDb = gormDb.Where("`group` = ? AND `department` = ?", userCont.Company, userCont.Deparment) } err := gormDb.Find(&planVersioCont).Error if err != nil { response.Result(102, err, "没有查询到数据", c) return } // response.Result(102, planVersioCont, "没有查询到数据", c) // return var statisticsAry []OrgStatics for _, v := range planVersioCont { var statisticsCont OrgStatics idStr := strconv.FormatInt(v.Group, 10) if judgeOrgStatic(idStr, statisticsAry) == true { strDepartment := strconv.FormatInt(v.Department, 10) if judegOrgDeparStatic(idStr, strDepartment, statisticsAry) == false { var departInfo OrgStaticsDepary departInfo.Id = strDepartment whereDepart := commonus.MapOut() whereDepart["id"] = strDepartment orgContDer, _ := commonus.GetNewOrgCont(whereDepart, "id", "name") departInfo.Name = orgContDer.Name sunChild, sunChildErr := StaticDataOperation(v.Key, idStr, strDepartment, v.Content, requestData.Year) if sunChildErr == true { departInfo.Child = sunChild } for ori, orv := range statisticsAry { fmt.Printf("opp---------->%v---------->%v\n", orv.Id, idStr) if orv.Id == idStr { statisticsAry[ori].Child = append(statisticsAry[ori].Child, departInfo) } } // statisticsCont.Child = append(statisticsCont.Child, departInfo) } // fmt.Printf("kkkkkk------1--------->%v\n", v) } else { // fmt.Printf("kkkkkk------2--------->%v\n", v) statisticsCont.Id = idStr where := commonus.MapOut() where["id"] = idStr orgCont, _ := commonus.GetNewOrgCont(where, "id", "name") statisticsCont.Name = orgCont.Name strDepartment := strconv.FormatInt(v.Department, 10) if judegOrgDeparStatic(idStr, strDepartment, statisticsAry) == false { var departInfo OrgStaticsDepary departInfo.Id = strDepartment whereDepart := commonus.MapOut() whereDepart["id"] = strDepartment orgContDer, _ := commonus.GetNewOrgCont(whereDepart, "id", "name") departInfo.Name = orgContDer.Name sunChild, sunChildErr := StaticDataOperation(v.Key, idStr, strDepartment, v.Content, requestData.Year) if sunChildErr == true { departInfo.Child = sunChild } statisticsCont.Child = append(statisticsCont.Child, departInfo) } statisticsAry = append(statisticsAry, statisticsCont) } } response.Result(0, statisticsAry, "查询完成", c) } //判断集团是否存在 func judgeOrgStatic(id string, orgAry []OrgStatics) bool { for _, v := range orgAry { if id == v.Id { return true } } return false } //判断部门是否存在 func judegOrgDeparStatic(id, departId string, orgAry []OrgStatics) bool { for _, v := range orgAry { if id == v.Id { for _, cv := range v.Child { if departId == cv.Id { return true } } } } return false } //统计值 func StaticDataOperation(key, group, depart, staticFrame, year string) (staticDataAry []ProgrammeStatisticsCallBack, isTrue bool) { isTrue = false var planInfo []AddDutyNewCont jsonErr := json.Unmarshal([]byte(staticFrame), &planInfo) if jsonErr != nil { return } yserInt, _ := strconv.ParseInt(year, 10, 64) //统计 // var staticData ProgrammeStatisticsCallBack for _, v := range planInfo { var staticData ProgrammeStatisticsCallBack staticData.Id = v.Id staticData.Name = v.Name for _, cv := range v.Child { if cv.Status == 1 { var tarCont EvaluProssCall tarCont.Id = cv.Id tarCont.Name = cv.Name tarCont.Content = cv.Content tarCont.ReferenceScore = cv.ReferenceScore taskId, _, departName, cycle, cycleattr, isDuty, isDutyErr := getDepartTarget(key, v.Id, cv.Id, group, depart) if isDutyErr == nil { tarCont.ExecuteDepart = departName tarCont.Cycles = cycle tarCont.CycleAttres = cycleattr if isDuty == 1 { } else { switch cycle { case 1: //按班统计 allYearDays := 365 // yserInt, _ := strconv.ParseInt(year, 10, 64) if commonus.IsLeapYear(yserInt) == true { allYearDays = 366 } for i := 1; i <= allYearDays; i++ { wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v AND `fl_day` = %v", taskId, year, group, depart, i) resultData := commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr) / 100) tarCont.TimeData = append(tarCont.TimeData, quantification.GetQuantitativeConfig(resultData, group, depart, v.Id, cv.Id, "0", yserInt, 0)) // tarCont.TimeData = append(tarCont.TimeData, commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr)/100)) } case 2: //按天统计 allYearDays := 365 // yserInt, _ := strconv.ParseInt(year, 10, 64) if commonus.IsLeapYear(yserInt) == true { allYearDays = 366 } for i := 1; i <= allYearDays; i++ { wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v AND `fl_day` = %v", taskId, year, group, depart, i) resultData := commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr) / 100) tarCont.TimeData = append(tarCont.TimeData, quantification.GetQuantitativeConfig(resultData, group, depart, v.Id, cv.Id, "0", yserInt, 0)) // tarCont.TimeData = append(tarCont.TimeData, commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr)/100)) } case 3: case 4: monthValue := commonus.TimeStampToDate(time.Now().Unix(), 12) if commonus.TimeStampToDate(time.Now().Unix(), 11) != year { monthValue = "12" } monthValueInt, _ := strconv.Atoi(monthValue) for i := 1; i <= monthValueInt; i++ { wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v AND `fl_month` = %v", taskId, year, group, depart, i) resultData := commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr) / 100) tarCont.TimeData = append(tarCont.TimeData, quantification.GetQuantitativeConfig(resultData, group, depart, v.Id, cv.Id, "0", yserInt, i)) // tarCont.TimeData = append(tarCont.TimeData, commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr)/100)) } case 5: for i := 1; i <= 4; i++ { wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v AND `fl_quarter` = %v", taskId, year, group, depart, i) resultData := commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr) / 100) tarCont.TimeData = append(tarCont.TimeData, quantification.GetQuantitativeConfig(resultData, group, depart, v.Id, cv.Id, "0", yserInt, i)) // tarCont.TimeData = append(tarCont.TimeData, commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr)/100)) } default: wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v ", taskId, year, group, depart) resultData := commonus.Decimal(quantification.AuxiliaryCalculationSum(wherStr) / 100) tarCont.TimeData = append(tarCont.TimeData, quantification.GetQuantitativeConfig(resultData, group, depart, v.Id, cv.Id, "0", yserInt, 0)) } } } // tarCont.ExecuteDepart = cv.ExecuteDepart staticData.Child = append(staticData.Child, tarCont) } } staticDataAry = append(staticDataAry, staticData) } isTrue = true return } //获取执行部门及指标性质 /* @key 方案版本号 @dimeId 维度 @targetId 指标 @accDepartId 接收考核的部门 outPut @qualId //方案ID @departId 执行部门ID @departName 执行部门名称 @cycle 1:班;2:天;3:周;4:月;5:季度;6:年 @cycleattr 辅助计数 @isDuty 1:定性考核;2:定量考核 */ func getDepartTarget(key, dimeId, targetId, group, accDepartId string) (qualId int64, departId, departName []string, cycle, cycleattr, isDuty int, err error) { var qualEvalCont assessmentmodel.QualitativeEvaluation err = global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.QualitativeEvaluation{}).Select("qe_id,qe_department_id,qe_type,qe_cycle,qe_cycleattr").Where("qe_qual_eval_id = ? AND qe_dimension = ? AND qe_target = ? AND qe_accept_evaluation = ? AND qe_group = ? AND qe_state = 1", key, dimeId, targetId, accDepartId, group).First(&qualEvalCont).Error departId = strings.Split(qualEvalCont.DepartmentId, ",") if len(departId) > 0 { for _, v := range departId { fmt.Printf("部门Id =====>%v\n", v) where := commonus.MapOut() where["id"] = v orgCont, _ := commonus.GetNewOrgCont(where, "id", "name") departName = append(departName, orgCont.Name) } } isDuty = qualEvalCont.Type cycle = qualEvalCont.Cycles cycleattr = qualEvalCont.CycleAttres qualId = qualEvalCont.Id return }