You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
319 lines
13 KiB
319 lines
13 KiB
|
4 years ago
|
package statistics
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"strconv"
|
||
|
|
"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) GetPlanVersionValid(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
|
||
|
|
}
|
||
|
|
yserInt, _ := strconv.ParseInt(requestData.Year, 10, 64)
|
||
|
|
var outData []TargetContOutCont
|
||
|
|
for _, v := range planVersioCont { //版本列表
|
||
|
|
|
||
|
|
if v.Content != "" {
|
||
|
|
var planInfo []AddDutyNewCont
|
||
|
|
jsonErr := json.Unmarshal([]byte(v.Content), &planInfo)
|
||
|
|
if jsonErr == nil {
|
||
|
|
for _, pv := range planInfo { //维度列表
|
||
|
|
|
||
|
|
for _, pcv := range pv.Child { //指标列表
|
||
|
|
if pcv.Status != 2 {
|
||
|
|
var outCont TargetContOutCont
|
||
|
|
outCont.Id = strconv.FormatInt(v.Id, 10)
|
||
|
|
//集团信息
|
||
|
|
outCont.Group = strconv.FormatInt(v.Group, 10)
|
||
|
|
where := commonus.MapOut()
|
||
|
|
where["id"] = v.Group
|
||
|
|
orgCont, _ := commonus.GetNewOrgCont(where, "id", "name")
|
||
|
|
outCont.GroupName = orgCont.Name
|
||
|
|
//接受考核部门
|
||
|
|
outCont.DepartmentId = strconv.FormatInt(v.Department, 10)
|
||
|
|
whereDepart := commonus.MapOut()
|
||
|
|
whereDepart["id"] = v.Department
|
||
|
|
orgContDer, _ := commonus.GetNewOrgCont(whereDepart, "id", "name")
|
||
|
|
outCont.DepartmentName = orgContDer.Name
|
||
|
|
//维度信息
|
||
|
|
outCont.Dimension = pv.Id
|
||
|
|
outCont.DimensionName = pv.Name
|
||
|
|
outCont.DimensionWeight = int64(pv.ZhiFraction)
|
||
|
|
//指标信息
|
||
|
|
outCont.Target = pcv.Id
|
||
|
|
outCont.TargetName = pcv.Name
|
||
|
|
outCont.TargetCont = pcv.Content
|
||
|
|
outCont.TargetWeight = pcv.ReferenceScore
|
||
|
|
outCont.Unit = pcv.Unit
|
||
|
|
//获取指标内容
|
||
|
|
var evalTargerCont assessmentmodel.EvaluationTarget
|
||
|
|
evalErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.EvaluationTarget{}).Select("et_type,et_scoring_method").Where("`et_id` = ?", pcv.Id).First(&evalTargerCont).Error
|
||
|
|
scoringMethod := 1
|
||
|
|
if evalErr == nil {
|
||
|
|
outCont.Type = evalTargerCont.Type
|
||
|
|
scoringMethod = evalTargerCont.ScoringMethod
|
||
|
|
}
|
||
|
|
/*
|
||
|
|
@key 方案版本号
|
||
|
|
@dimeId 维度
|
||
|
|
@targetId 指标
|
||
|
|
@accDepartId 接收考核的部门
|
||
|
|
|
||
|
|
outPut
|
||
|
|
|
||
|
|
@qualId //方案ID
|
||
|
|
@departId 执行部门ID
|
||
|
|
@departName 执行部门名称
|
||
|
|
@cycle 1:班;2:天;3:周;4:月;5:季度;6:年
|
||
|
|
@cycleattr 辅助计数
|
||
|
|
@isDuty 1:定性考核;2:定量考核
|
||
|
|
*/
|
||
|
|
taskId, _, departName, cycle, cycleattr, isDuty, isDutyErr := getDepartTarget(v.Key, pv.Id, pcv.Id, strconv.FormatInt(v.Group, 10), strconv.FormatInt(v.Department, 10))
|
||
|
|
if isDutyErr == nil {
|
||
|
|
outCont.ExecutiveDepartment = departName
|
||
|
|
outCont.Cycles = cycle
|
||
|
|
outCont.CycleAttres = cycleattr
|
||
|
|
if isDuty != 0 {
|
||
|
|
outCont.Type = isDuty
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
isDuty = 2
|
||
|
|
}
|
||
|
|
|
||
|
|
if isDuty == 1 {
|
||
|
|
//定性考核
|
||
|
|
switch cycle {
|
||
|
|
case 1:
|
||
|
|
case 2: //天
|
||
|
|
allYearDays := 365
|
||
|
|
if commonus.IsLeapYear(yserInt) == true {
|
||
|
|
allYearDays = 366
|
||
|
|
}
|
||
|
|
for i := 1; i <= allYearDays; i++ {
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
wherStr := fmt.Sprintf("`sf_evaluation_plan` = %v AND `sf_duty_group` = %v AND `sf_duty_department` = %v AND `sf_year` = %v AND `sf_week` = %v", taskId, v.Group, v.Department, yserInt, i)
|
||
|
|
|
||
|
|
resultData := commonus.Decimal(SubjectiveAuxiliaryCalculationSumMethod(wherStr) / 100)
|
||
|
|
if resultData > float64(pcv.ReferenceScore) {
|
||
|
|
resultData = float64(pcv.ReferenceScore)
|
||
|
|
}
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
case 3:
|
||
|
|
case 5: //季度
|
||
|
|
for i := 1; i <= 4; i++ {
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
wherStr := fmt.Sprintf("`sf_evaluation_plan` = %v AND `sf_duty_group` = %v AND `sf_duty_department` = %v AND `sf_year` = %v AND `sf_quarter` = %v", taskId, v.Group, v.Department, yserInt, i)
|
||
|
|
|
||
|
|
resultData := commonus.Decimal(SubjectiveAuxiliaryCalculationSumMethod(wherStr) / 100)
|
||
|
|
if resultData > float64(pcv.ReferenceScore) {
|
||
|
|
resultData = float64(pcv.ReferenceScore)
|
||
|
|
}
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
case 6: //年
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
wherStr := fmt.Sprintf("`sf_evaluation_plan` = %v AND `sf_duty_group` = %v AND `sf_duty_department` = %v AND `sf_year` = %v", taskId, v.Group, v.Department, yserInt)
|
||
|
|
|
||
|
|
resultData := commonus.Decimal(SubjectiveAuxiliaryCalculationSumMethod(wherStr) / 100)
|
||
|
|
if resultData > float64(pcv.ReferenceScore) {
|
||
|
|
resultData = float64(pcv.ReferenceScore)
|
||
|
|
}
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
default: //月
|
||
|
|
monthValue := commonus.TimeStampToDate(time.Now().Unix(), 12)
|
||
|
|
if commonus.TimeStampToDate(time.Now().Unix(), 11) != requestData.Year {
|
||
|
|
monthValue = "12"
|
||
|
|
}
|
||
|
|
monthValueInt, _ := strconv.Atoi(monthValue)
|
||
|
|
for i := 1; i <= monthValueInt; i++ {
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
wherStr := fmt.Sprintf("`sf_evaluation_plan` = %v AND `sf_duty_group` = %v AND `sf_duty_department` = %v AND `sf_year` = %v AND `sf_month` = %v", taskId, v.Group, v.Department, yserInt, i)
|
||
|
|
|
||
|
|
resultData := commonus.Decimal(SubjectiveAuxiliaryCalculationSumMethod(wherStr) / 100)
|
||
|
|
if resultData > float64(pcv.ReferenceScore) {
|
||
|
|
resultData = float64(pcv.ReferenceScore)
|
||
|
|
}
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
//定量考核
|
||
|
|
switch cycle {
|
||
|
|
case 1:
|
||
|
|
case 2: //天
|
||
|
|
allYearDays := 365
|
||
|
|
if commonus.IsLeapYear(yserInt) == true {
|
||
|
|
allYearDays = 366
|
||
|
|
}
|
||
|
|
for i := 1; i <= allYearDays; i++ {
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
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, yserInt, v.Group, v.Department, i)
|
||
|
|
resultData := commonus.Decimal(AuxiliaryCalculationSumMethod(wherStr, scoringMethod) / 100)
|
||
|
|
if scoringMethod != 2 {
|
||
|
|
outCont.Score = append(outCont.Score, quantification.GetQuantitativeConfig(resultData, strconv.FormatInt(v.Group, 10), strconv.FormatInt(v.Department, 10), pv.Id, pcv.Id, "0", yserInt, 0))
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
case 3:
|
||
|
|
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, yserInt, v.Group, v.Department, i)
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
resultData := commonus.Decimal(AuxiliaryCalculationSumMethod(wherStr, scoringMethod) / 100)
|
||
|
|
if scoringMethod != 2 {
|
||
|
|
outCont.Score = append(outCont.Score, quantification.GetQuantitativeConfig(resultData, strconv.FormatInt(v.Group, 10), strconv.FormatInt(v.Department, 10), pv.Id, pcv.Id, "0", yserInt, 0))
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
case 6: //年
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
wherStr := fmt.Sprintf("fld_evaluation_id = %v AND `fl_year` = %v AND `fl_duty_group` = %v AND `fl_duty_department` = %v ", taskId, yserInt, v.Group, v.Department)
|
||
|
|
resultData := commonus.Decimal(AuxiliaryCalculationSumMethod(wherStr, scoringMethod) / 100)
|
||
|
|
if scoringMethod != 2 {
|
||
|
|
outCont.Score = append(outCont.Score, quantification.GetQuantitativeConfig(resultData, strconv.FormatInt(v.Group, 10), strconv.FormatInt(v.Department, 10), pv.Id, pcv.Id, "0", yserInt, 0))
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
default: //月
|
||
|
|
monthValue := commonus.TimeStampToDate(time.Now().Unix(), 12)
|
||
|
|
if commonus.TimeStampToDate(time.Now().Unix(), 11) != requestData.Year {
|
||
|
|
monthValue = "12"
|
||
|
|
}
|
||
|
|
monthValueInt, _ := strconv.Atoi(monthValue)
|
||
|
|
for i := 1; i <= monthValueInt; i++ {
|
||
|
|
if pcv.Status != 3 {
|
||
|
|
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, yserInt, v.Group, v.Department, i)
|
||
|
|
resultData := commonus.Decimal(AuxiliaryCalculationSumMethod(wherStr, scoringMethod) / 100)
|
||
|
|
if scoringMethod != 2 {
|
||
|
|
outCont.Score = append(outCont.Score, quantification.GetQuantitativeConfig(resultData, strconv.FormatInt(v.Group, 10), strconv.FormatInt(v.Department, 10), pv.Id, pcv.Id, "0", yserInt, i))
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, resultData)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
outCont.Score = append(outCont.Score, float64(pcv.ReferenceScore))
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
outData = append(outData, outCont)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
response.Result(0, outData, "获取成功", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取总值 定量
|
||
|
|
func AuxiliaryCalculationSumMethod(where interface{}, scoringMethod int) (sumScore float64) {
|
||
|
|
if scoringMethod == 2 {
|
||
|
|
gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowLogData{}).Joins("left join flow_log as fl on fl.fl_key = flow_log_data.fld_flow_log").Where(where)
|
||
|
|
gormDb.Pluck("COALESCE(SUM(fld_scoring_score), 0) as rescore", &sumScore)
|
||
|
|
} else {
|
||
|
|
gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowLogData{}).Joins("left join flow_log as fl on fl.fl_key = flow_log_data.fld_flow_log").Where(where)
|
||
|
|
gormDb.Pluck("COALESCE(SUM(fld_score), 0) as rescore", &sumScore)
|
||
|
|
}
|
||
|
|
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
//定性
|
||
|
|
func SubjectiveAuxiliaryCalculationSumMethod(where interface{}) (sumScore float64) {
|
||
|
|
//加分
|
||
|
|
var addSumScore float64 = 0
|
||
|
|
global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowLogData{}).Select("sf_score").Where(where).Where("sf_plus_reduce_score = 1").Pluck("COALESCE(SUM(sf_score), 0) as addrescore", &addSumScore)
|
||
|
|
//加分
|
||
|
|
var scoreReduction float64 = 0
|
||
|
|
global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.FlowLogData{}).Select("sf_score").Where(where).Where("sf_plus_reduce_score = 2").Pluck("COALESCE(SUM(sf_score), 0) as redurescore", &scoreReduction)
|
||
|
|
if addSumScore != 0 && scoreReduction != 0 {
|
||
|
|
if addSumScore > scoreReduction {
|
||
|
|
sumScore = addSumScore - scoreReduction
|
||
|
|
} else {
|
||
|
|
sumScore = scoreReduction - addSumScore
|
||
|
|
}
|
||
|
|
} else if addSumScore != 0 {
|
||
|
|
sumScore = addSumScore
|
||
|
|
} else {
|
||
|
|
sumScore = scoreReduction
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|