package departmentpc
import (
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strconv"
"strings"
"github.com/gin-gonic/gin"
)
// 定性指标细则与部门矩阵
func ( a * ApiMethod ) DepartmentRulesMatrix ( c * gin . Context ) {
var receivedValue rulesMatrixParameter
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , receivedValue , c )
return
}
if receivedValue . Company == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . Target == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
var zbz [ ] matrixZhuBiaoZhoo
//获取公司下的最小主责部门
organizationList := publicmethod . GetMinMainDutyDeparment ( receivedValue . Company )
var departmentList [ ] int64
for _ , dv := range organizationList {
if publicmethod . IsInTrue [ int64 ] ( dv . Id , departmentList ) == false {
var zbzCont matrixZhuBiaoZhoo
var ordCont modelshr . AdministrativeOrganization
ordCont . GetCont ( map [ string ] interface { } { "`id`" : dv . Id } , "`name`" )
zbzCont . Id = strconv . FormatInt ( dv . Id , 10 )
zbzCont . Name = ordCont . Name
zbz = append ( zbz , zbzCont )
departmentList = append ( departmentList , dv . Id )
}
}
//获取该指标下的所有细则
var targetList [ ] modelskpi . DetailedTarget
overall . CONSTANT_DB_KPI . Where ( "`dt_state` = 1 AND `dt_parentid` = ?" , receivedValue . Target ) . Order ( "dt_parentid ASC" ) . Order ( "dt_parentid_sun ASC" ) . Find ( & targetList )
if len ( targetList ) < 1 {
publicmethod . Result ( 105 , receivedValue , c )
return
}
var sendDataList [ ] rulesMatrixParaList
for _ , v := range targetList {
var sendDataCont rulesMatrixParaList
sendDataCont . Id = v . Id
sendDataCont . Title = v . Title //指标细则"`
sendDataCont . Content = v . Content //指标说明"`
sendDataCont . ParentId = v . ParentId //归属指标栏目"`
sendDataCont . ParentIdSun = v . ParentIdSun //归属指标子栏目"`
sendDataCont . State = v . State //状态(1:启用;2:禁用;3:删除)"`
sendDataCont . AddTime = v . AddTime //制定时间"`
sendDataCont . MinScore = v . MinScore //最小分*100保存"`
sendDataCont . MaxScore = v . MaxScore //100保存"`
sendDataCont . Company = v . Company //单位"`
sendDataCont . AddReduce = v . AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
sendDataCont . CensorType = v . CensorType //检查方式"`
sendDataCont . CensorCont = v . CensorCont //检查依据"`
sendDataCont . CensorRate = v . CensorRate //检查频次"`
sendDataCont . Cycles = v . Cycles //1:班;2:天;3:周;4:月;5:季度;6:年"`
sendDataCont . CycleAttres = v . CycleAttres //辅助计数"`
sendDataCont . Paretment = v . Paretment //接受考核的部门"`
sendDataCont . Reportary = v . Reportary //提报人"`
standardStr := ""
if v . MinScore != 0 {
standardStr = fmt . Sprintf ( "%v-%v" , publicmethod . DecimalEs ( float64 ( v . MinScore ) / 100 , 2 ) , publicmethod . DecimalEs ( float64 ( v . MaxScore ) / 100 , 2 ) )
} else {
standardStr = fmt . Sprintf ( "%v" , publicmethod . DecimalEs ( float64 ( v . MaxScore ) / 100 , 2 ) )
}
sendDataCont . Standard = standardStr
//子栏目信息
var sonTargetInfo modelskpi . QualitativeTarget
sonTargetInfo . GetCont ( map [ string ] interface { } { "`q_id`" : v . ParentIdSun } , "q_title" )
sendDataCont . SonTargetName = sonTargetInfo . Title
sendDataCont . CensorTypeList = strings . Split ( v . CensorType , "," )
relationOrg := GetRulesDepartment ( v . ParentId , v . ParentIdSun , v . Id , 1 )
for i := 0 ; i < len ( departmentList ) ; i ++ {
// var matrDepart matrixDepartment
// matrDepart.Id = strconv.FormatInt(departmentList[i], 10)
// var ordCont modelshr.AdministrativeOrganization
// ordCont.GetCont(map[string]interface{}{"`id`": departmentList[i]}, "`name`")
// matrDepart.Name = ordCont.Name
if publicmethod . IsInTrue [ int64 ] ( departmentList [ i ] , relationOrg ) == true {
// fmt.Printf("relationOrg--------True------>%v------>%v\n", v.Id, departmentList[i])
sendDataCont . IsTrue = append ( sendDataCont . IsTrue , 1 )
// matrDepart.IsTrue = 1
} else {
// fmt.Printf("relationOrg--------False------>%v------>%v\n", v.Id, departmentList[i])
sendDataCont . IsTrue = append ( sendDataCont . IsTrue , 0 )
// matrDepart.IsTrue = 0
}
// sendDataCont.DepartmentIsTrue = append(sendDataCont.DepartmentIsTrue, matrDepart)
}
sendDataList = append ( sendDataList , sendDataCont )
}
sendMap := publicmethod . MapOut [ string ] ( )
// orgJson, _ := json.Marshal(organizationList)
// fmt.Printf("orgJson-------------->%v\n", string(orgJson))
sendMap [ "list" ] = sendDataList
sendMap [ "department" ] = zbz
publicmethod . Result ( 0 , sendMap , c )
}
/ *
获取指标细则关联部门
@ target 指标
@ sonTarget 子栏目
@ bylaws 细则
@ level 级别 ( 1 : 部门级 ; 2 : 岗位级 ) " `
* /
func GetRulesDepartment ( target , sonTarget , bylaws int64 , level int ) ( orgId [ ] int64 ) {
// var targetDepartmentList []modelskpi.TargetDetailedRelationDepartment
// var
overall . CONSTANT_DB_KPI . Model ( & modelskpi . TargetDetailedRelationDepartment { } ) . Distinct ( "`tddepartment`" ) . Where ( "`dt_state` = 1 AND `dt_parentid` = ? AND `dt_parentid_sun` = ? AND `dt_id` = ? AND `level` = ?" , target , sonTarget , bylaws , level ) . Find ( & orgId )
// var snedId []int64
// for _, v := range orgId {
// snedId = append(snedId, publicmethod.GetGroupOrDepartPower(v, 1))
// }
// fmt.Printf("orgId----------->%v----------->%v\n", orgId, snedId)
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 02 - 13 15 : 17 : 31
@ 功能 : 获取指定指标下的细则列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetTargetDetailsList ( c * gin . Context ) {
var receivedValue GetTarDetails
c . ShouldBindJSON ( & receivedValue )
if receivedValue . TargetId == 0 {
publicmethod . Result ( 1 , receivedValue , c , "未获取到指标ID!" )
return
}
var idList [ ] int64
var detCont modelskpi . DetailedTarget
gormDb := overall . CONSTANT_DB_KPI . Table ( fmt . Sprintf ( "%s dt" , detCont . TableName ( ) ) ) . Distinct ( "dt.dt_id" ) . Where ( "dt.dt_state BETWEEN 1 AND 2 AND dt.dt_parentid = ?" , receivedValue . TargetId )
if receivedValue . Cycle != 0 {
gormDb = gormDb . Where ( "dt.`dt_cycle` = ?" , receivedValue . Cycle )
}
if len ( receivedValue . TestMethod ) > 0 {
var sqlOrStr string
for ti , tv := range receivedValue . TestMethod {
if ti == 0 {
// gormDb = gormDb.Where("FIND_IN_SET(?,`dt_censor_type`)", tv)
sqlOrStr = fmt . Sprintf ( "FIND_IN_SET(%v,`dt_censor_type`)" , tv )
} else {
// gormDb = gormDb.Or("FIND_IN_SET(?,`dt_censor_type`)", tv)
sqlOrStr = fmt . Sprintf ( "%v OR FIND_IN_SET(%v,`dt_censor_type`)" , sqlOrStr , tv )
}
}
gormDb = gormDb . Where ( sqlOrStr )
}
if len ( receivedValue . OrgList ) > 0 {
gormDb = gormDb . Joins ( "LEFT JOIN `target_department` `td` on td.target_id = dt.dt_parentid AND td.target_sun_id = dt.dt_parentid_sun AND td.target_bylaws = dt.dt_id" ) . Where ( "td.`type` = 3 AND td.`state` BETWEEN 1 AND 2 AND td.`level` = 1 AND td.department_id IN ?" , receivedValue . OrgList )
}
err := gormDb . Find ( & idList ) . Error
if err != nil || len ( idList ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
// return
var listCont [ ] modelskpi . DetailedTarget
err = overall . CONSTANT_DB_KPI . Where ( "`dt_id` IN ?" , idList ) . Order ( "dt_parentid desc, dt_parentid_sun" ) . Find ( & listCont ) . Error
if err != nil || len ( listCont ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var sendListCont [ ] outputTargetDetails
jishuqi := 1
var lastSunTable int64
for _ , v := range listCont {
var sendCont outputTargetDetails
sendCont . Id = v . Id
sendCont . Title = v . Title //指标细则"`
sendCont . Content = v . Content //指标说明"`
sendCont . ParentId = v . ParentId //归属指标栏目"`
if lastSunTable != v . ParentIdSun {
lastSunTable = v . ParentIdSun
jishuqi = 1
} else {
jishuqi = jishuqi + 1
}
sendCont . JiBuQi = jishuqi
sendCont . ParentIdSun = v . ParentIdSun //归属指标子栏目"`
sendCont . State = v . State //状态(1:启用;2:禁用;3:删除)"`
sendCont . AddTime = v . AddTime //制定时间"`
sendCont . MinScore = v . MinScore //最小分*100保存"`
sendCont . MaxScore = v . MaxScore //最大分*100保存"`
sendCont . Company = v . Company //单位"`
sendCont . AddReduce = v . AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
sendCont . CensorType = v . CensorType //检查方式"`
sendCont . CensorCont = v . CensorCont //检查依据"`
sendCont . CensorRate = v . CensorRate //检查频次"`
sendCont . Cycles = v . Cycles //1:班;2:天;3:周;4:月;5:季度;6:年"`
sendCont . CycleAttres = v . CycleAttres //辅助计数"`
sendCont . Paretment = v . Paretment //接受考核的部门"`
sendCont . Reportary = v . Reportary //提报人"`
var sonTargetCont modelskpi . QualitativeTarget
sonTargetCont . GetCont ( map [ string ] interface { } { "q_id" : v . ParentIdSun } , "q_title" )
sendCont . ColumnName = sonTargetCont . Title
if v . MinScore != 0 && v . MaxScore != 0 {
minScoreFloat64 := publicmethod . DecimalEs ( float64 ( v . MinScore ) / 100 , 2 )
maxScoreFloat64 := publicmethod . DecimalEs ( float64 ( v . MaxScore ) / 100 , 2 )
sendCont . Standard = fmt . Sprintf ( "%v-%v" , minScoreFloat64 , maxScoreFloat64 )
} else if v . MinScore == 0 && v . MaxScore != 0 {
maxScoreFloat64 := publicmethod . DecimalEs ( float64 ( v . MaxScore ) / 100 , 2 )
sendCont . Standard = fmt . Sprintf ( "%v" , maxScoreFloat64 )
} else if v . MinScore != 0 && v . MaxScore == 0 {
minScoreFloat64 := publicmethod . DecimalEs ( float64 ( v . MinScore ) / 100 , 2 )
sendCont . Standard = fmt . Sprintf ( "%v" , minScoreFloat64 )
} else {
sendCont . Standard = "0"
}
sendListCont = append ( sendListCont , sendCont )
}
publicmethod . Result ( 0 , sendListCont , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 02 - 15 11 : 38 : 24
@ 功能 :
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetTargetColumnList ( c * gin . Context ) {
var receivedValue publicmethod . PublicId
err := c . ShouldBindJSON ( & receivedValue )
if err != nil || receivedValue . Id == "" {
publicmethod . Result ( 100 , receivedValue , c )
return
}
var columnContList [ ] modelskpi . QualitativeTarget
err = overall . CONSTANT_DB_KPI . Where ( "`q_state` = 1 AND `q_parent_id` = ?" , receivedValue . Id ) . Find ( & columnContList ) . Error
if err != nil {
publicmethod . Result ( 107 , err , c )
return
}
publicmethod . Result ( 0 , columnContList , c )
}