package departmentweb
import (
"encoding/json"
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"math"
"sort"
"time"
"strconv"
"github.com/gin-gonic/gin"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 11 0 8 : 40 : 44
@ 功能 : 指标列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) TargetListForDepartment ( c * gin . Context ) {
var receivedValue GetDepartTargetCont
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . Id == "" {
publicmethod . Result ( 1 , err , c , "未知行政组织结构!" )
return
}
var targetCont modelskpi . EvaluationTarget
gormDb := overall . CONSTANT_DB_KPI . Table ( fmt . Sprintf ( "%s et" , targetCont . TableName ( ) ) ) . Where ( "et.`et_state` = 1 " )
if receivedValue . Attribute != 0 {
gormDb = gormDb . Where ( "et.`et_type` = ?" , receivedValue . Attribute )
}
gormDb = gormDb . Joins ( "JOIN target_department td ON et.et_id = td.target_id AND td.target_sun_id = 0 AND td.target_bylaws = 0 AND td.`type` = 1 AND td.`post_id` = 0 AND td.state = 1 AND td.level = 1 AND td.`department_id` = ?" , receivedValue . Id )
var targetIdAry [ ] int64
err = gormDb . Distinct ( "et.et_id" ) . Find ( & targetIdAry ) . Error
if err != nil || len ( targetIdAry ) < 1 {
publicmethod . Result ( 105 , err , c )
return
}
var departmentTargetList [ ] modelskpi . EvaluationTarget
err = overall . CONSTANT_DB_KPI . Model ( & modelskpi . EvaluationTarget { } ) . Select ( "et_id,et_title" ) . Where ( "et_id IN ?" , targetIdAry ) . Order ( "`et_id` ASC" ) . Find ( & departmentTargetList ) . Error
if err != nil || len ( departmentTargetList ) < 1 {
publicmethod . Result ( 105 , err , c )
return
}
var outputContent [ ] SendTargetCont
for _ , v := range departmentTargetList {
var outCont SendTargetCont
outCont . Id = strconv . FormatInt ( v . Id , 10 )
outCont . Name = v . Title
outputContent = append ( outputContent , outCont )
}
publicmethod . Result ( 0 , outputContent , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 11 11 : 14 : 41
@ 功能 : 根据部门 、 指标 、 年份统计每月的目标值 、 实际值 、 达成率
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) BasisDepartTargetTimeStatistics ( c * gin . Context ) {
var receivedValue BaseDepartTargetTime
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . OrgId == "" {
publicmethod . Result ( 1 , err , c , "未知行政组织!无法统计!" )
return
}
if receivedValue . TargetId == "" {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tarWhere := publicmethod . MapOut [ string ] ( )
tarWhere [ "et_id" ] = receivedValue . TargetId
//获取指标信息
var targetCont modelskpi . EvaluationTarget
err = targetCont . GetCont ( tarWhere )
if err != nil {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tadyTime := time . Now ( ) . Unix ( )
dateYear := publicmethod . UnixTimeToDay ( tadyTime , 16 )
dateMonthMAx := 12
if receivedValue . DateTime == "" {
receivedValue . DateTime = dateYear
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
} else {
if receivedValue . DateTime == dateYear {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
}
}
mubiaozhiTitle := fmt . Sprintf ( "目标值(%v)" , targetCont . Uniteing )
shijizhiTitle := fmt . Sprintf ( "实际值(%v)" , targetCont . Uniteing )
dachenglvTitle := fmt . Sprintf ( "达成率(%v)" , "%" )
var sendCont DrawEcharStatisticsCont
sendCont . Legend = [ ] string { mubiaozhiTitle , shijizhiTitle , dachenglvTitle }
var dttsbSync GetDttsb
for i := 1 ; i <= dateMonthMAx ; i ++ {
sendCont . XAxisVal = append ( sendCont . XAxisVal , fmt . Sprintf ( "%v月" , i ) )
SyncSeting . Add ( 1 )
go dttsbSync . PerformCalculation ( receivedValue . OrgId , receivedValue . TargetId , receivedValue . DateTime , i )
}
SyncSeting . Wait ( )
Target , Actuality , CompletionRate , axisLeftMax , axisLeftMin , axisRightMax , axisRightMin := dttsbSync . readPlanTaskData ( ) //读取协程数据
//根据维度序号排序
sort . Slice ( Target , func ( i , j int ) bool {
return Target [ i ] . Sort < Target [ j ] . Sort
} )
sort . Slice ( Actuality , func ( i , j int ) bool {
return Actuality [ i ] . Sort < Actuality [ j ] . Sort
} )
sort . Slice ( CompletionRate , func ( i , j int ) bool {
return CompletionRate [ i ] . Sort < CompletionRate [ j ] . Sort
} )
var muBiaoVal Seriescont
muBiaoVal . Name = mubiaozhiTitle //名称
muBiaoVal . Type = "bar" //图像类型
muBiaoVal . Tooltip = targetCont . Uniteing //单位
for _ , tv := range Target {
muBiaoVal . Data = append ( muBiaoVal . Data , tv . Val )
}
sendCont . Series = append ( sendCont . Series , muBiaoVal )
var siJiVal Seriescont
siJiVal . Name = shijizhiTitle //名称
siJiVal . Type = "bar" //图像类型
siJiVal . Tooltip = targetCont . Uniteing //单位
for _ , av := range Actuality {
siJiVal . Data = append ( siJiVal . Data , av . Val )
}
sendCont . Series = append ( sendCont . Series , siJiVal )
var daChengLvVal Seriescont
daChengLvVal . Name = dachenglvTitle //名称
daChengLvVal . Type = "line" //图像类型
daChengLvVal . Tooltip = "%" //单位
for _ , cv := range CompletionRate {
daChengLvVal . Data = append ( daChengLvVal . Data , cv . Val )
}
sendCont . Series = append ( sendCont . Series , daChengLvVal )
var yMaxValLeft float64
var yMinValLeft float64
var yMaxValRight float64
var yMinValRight float64
yMinValLeft = axisLeftMin
if axisLeftMin < 0 {
yMinValLeft = 0
}
if axisLeftMax == 0 && axisLeftMin == 0 {
yMaxValLeft = 10
} else {
yMaxValLeft = axisLeftMax
}
fmt . Printf ( "yMinValLeft:%v----------->yMinValLeft:%v----------->axisLeftMax:%v\n" , yMinValLeft , yMinValLeft , axisLeftMax )
maxYZhiStr := strconv . FormatFloat ( yMaxValLeft , 'f' , 0 , 64 )
maxYZhiInt , _ := strconv . ParseInt ( maxYZhiStr , 10 , 64 )
quyuzhi := maxYZhiInt % 10
if yMaxValLeft > 1000 {
yMaxValLeft = yMaxValLeft - float64 ( quyuzhi ) + 100
} else {
if yMaxValLeft < 10 {
yMaxValLeft = yMaxValLeft + 1
} else {
yMaxValLeft = yMaxValLeft - float64 ( quyuzhi ) + 10
}
}
fmt . Printf ( "maxYZhiStr:%v----------->maxYZhiInt:%v----------->quyuzhi:%v----------->yMaxValLeft:%v\n" , maxYZhiStr , maxYZhiInt , quyuzhi , yMaxValLeft )
yMinValRight = axisRightMin
if axisRightMin < 0 {
yMinValRight = 0
}
if axisRightMax == 0 && axisRightMin == 0 {
yMaxValRight = 10
} else {
yMaxValRight = axisRightMax
}
fmt . Printf ( "yMaxValRight:%v----------->yMinValRight:%v----------->axisRightMax:%v\n" , yMaxValRight , yMinValRight , axisRightMax )
maxYZhiStrRight := strconv . FormatFloat ( yMaxValRight , 'f' , 0 , 64 )
maxYZhiIntRight , _ := strconv . ParseInt ( maxYZhiStrRight , 10 , 64 )
quyuzhiRight := maxYZhiIntRight % 10
if yMaxValRight < 10 {
yMaxValRight = yMaxValRight + 1
} else {
yMaxValRight = yMaxValRight - float64 ( quyuzhiRight ) + 10
}
// if yMaxValRight > 100 {
// yMaxValRight = 100
// }
fmt . Printf ( "maxYZhiStrRight:%v----------->maxYZhiIntRight:%v----------->quyuzhiRight:%v\n" , maxYZhiStrRight , maxYZhiIntRight , quyuzhiRight )
var yAxisOne YaxisStruct
yAxisOne . Name = "目标值 / 实际值 / 单位"
// yAxisOne.Name = fmt.Sprintf("目标值(%v)/实际值(%v)/单位(%v)", targetCont.Uniteing, targetCont.Uniteing, "%")
yAxisOne . Type = "value" //图像类型
yAxisOne . Min = publicmethod . DecimalEs ( yMinValLeft , 3 ) //最小值
yAxisOne . Max = publicmethod . DecimalEs ( yMaxValLeft , 3 ) //最大值
yAxisOne . FormAtter = targetCont . Uniteing
sendCont . YAxis = append ( sendCont . YAxis , yAxisOne )
var yAxisTwo YaxisStruct
yAxisTwo . Name = "达成率"
yAxisTwo . Type = "value" //图像类型
yAxisTwo . Min = publicmethod . DecimalEs ( yMinValRight , 3 ) //最小值
yAxisTwo . Max = publicmethod . DecimalEs ( yMaxValRight , 3 ) //最大值
yAxisTwo . FormAtter = "%"
sendCont . YAxis = append ( sendCont . YAxis , yAxisTwo )
fmt . Printf ( "%v---------->%v------------->%v------------->%v------------->%v------------->%v------------->%v\n" , axisLeftMax , axisLeftMin , axisRightMax , axisRightMin , yAxisOne , yAxisTwo , yMaxValLeft )
publicmethod . Result ( 0 , sendCont , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 11 14 : 42 : 20
@ 功能 : 计算目标值 , 实际值 , 达成率
@ 参数
# orgId 行政组织
# targetId 指标
# years 年
# month 月
@ 返回值
#
@ 方法原型
#
* /
func ( g * GetDttsb ) PerformCalculation ( orgId , targetId , years string , month int ) {
g . mutext . Lock ( )
defer g . mutext . Unlock ( )
var listCont [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `targetid` = ? AND `year` = ? AND `month` = ?" , orgId , targetId , years , month ) . Find ( & listCont ) . Error
var maxAllPrize float64
var minZeroPrize float64
var maxCappingPrize float64
var sumScore float64
if err == nil && len ( listCont ) > 0 {
for _ , v := range listCont { //遍历数据
minZeroPrize , maxAllPrize , maxCappingPrize = GetTargetSetUp ( v . Baseline , orgId , targetId , years , month , 3 )
if v . ScoringMethod == 1 {
sumScore = sumScore + float64 ( v . Score )
} else {
sumScore = sumScore + float64 ( v . ScoringScore )
}
}
}
maxAllPrizeChuLi := publicmethod . DecimalEs ( maxAllPrize / 100 , 2 )
sumScoreChuLi := publicmethod . DecimalEs ( sumScore / 100 , 2 )
if g . AxisLeftMax < maxAllPrizeChuLi {
g . AxisLeftMax = maxAllPrizeChuLi
}
if g . AxisLeftMax < sumScoreChuLi {
g . AxisLeftMax = sumScoreChuLi
}
if g . AxisLeftMin > maxAllPrizeChuLi {
g . AxisLeftMin = maxAllPrizeChuLi
}
if g . AxisLeftMin > sumScoreChuLi {
g . AxisLeftMin = sumScoreChuLi
}
//目标值
var targetConfig GetDttsbCont
targetConfig . Val = publicmethod . DecimalEs ( maxAllPrize / 100 , 2 )
targetConfig . Sort = month
g . Target = append ( g . Target , targetConfig )
//实际值
var actualityConfig GetDttsbCont
actualityConfig . Val = publicmethod . DecimalEs ( sumScore / 100 , 2 )
actualityConfig . Sort = month
g . Actuality = append ( g . Actuality , actualityConfig )
//达成率
dachenglv := DepartTargetCompletionRate ( sumScore , minZeroPrize , maxAllPrize , maxCappingPrize )
var completionRateConfig GetDttsbCont
completionRateConfig . Val = dachenglv
completionRateConfig . Sort = month
g . CompletionRate = append ( g . CompletionRate , completionRateConfig )
if g . AxisRightMax < dachenglv {
g . AxisRightMax = dachenglv
}
if g . AxisRightMin > dachenglv {
g . AxisRightMin = dachenglv
}
SyncSeting . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 11 15 : 56 : 21
@ 功能 : 计算达成率
@ 参数
# actualValue 实际值
# zeroPrize 零奖值
# allPrize 全奖值
# cappingPrize 封顶值
@ 返回值
#
@ 方法原型
#
* /
func DepartTargetCompletionRate ( actualValue , zeroPrize , allPrize , cappingPrize float64 ) ( percentageComplete float64 ) {
// fmt.Printf("计算达成率------->%v------->%v------->%v------->%v\n", actualValue, zeroPrize, allPrize, cappingPrize)
if allPrize == 0 && zeroPrize == 0 { //全奖值与零奖值都为0 那么达成率 100
percentageComplete = 10000
} else {
if allPrize > zeroPrize { //如果全奖值大于零奖值 执行一下操作
if actualValue <= zeroPrize { //实际结算值小于零奖值 那么达成率0
percentageComplete = 0
} else { //实际结算值大于零奖值
chushu := actualValue - zeroPrize
beiChuShu := allPrize - zeroPrize
// fmt.Printf("计算达成率-----2-->%v------->%v\n", chushu, beiChuShu)
if beiChuShu != 0 {
// percentageComplete = publicmethod.DecimalEs(chushu/beiChuShu, 4)
percentageComplete = chushu / beiChuShu
// fmt.Printf("计算达成率-----3-->%v------->%v------->%v\n", chushu, beiChuShu, percentageComplete)
if percentageComplete > 0 {
percentageComplete = percentageComplete * 10000
// fmt.Printf("计算达成率-----4-->%v------->%v------->%v\n", chushu, beiChuShu, percentageComplete)
if percentageComplete > cappingPrize {
if cappingPrize != 0 {
percentageComplete = cappingPrize
} else {
percentageComplete = 10000
}
}
// fmt.Printf("计算达成率-----6-->%v------->%v------->%v------->%v\n", chushu, beiChuShu, percentageComplete, cappingPrize)
}
} else { //被除数为0时 那么达成率0
percentageComplete = 0
}
// fmt.Printf("计算达成率-----5-->%v------->%v------->%v\n", chushu, beiChuShu, percentageComplete)
}
} else { //如果全奖值小于零奖值 执行一下操作
if actualValue >= zeroPrize { //实际结算值大于零奖值 那么达成率0
percentageComplete = 0
} else { //实际值小于零奖值
chushu := actualValue - zeroPrize
beiChuShu := allPrize - zeroPrize
if beiChuShu != 0 {
percentageComplete = publicmethod . DecimalEs ( chushu / beiChuShu , 4 )
if percentageComplete > 0 {
percentageComplete = percentageComplete * 10000
if percentageComplete > cappingPrize {
percentageComplete = cappingPrize
}
}
} else { //被除数为0时 那么达成率0
percentageComplete = 0
}
}
}
}
fmt . Printf ( "计算达成率-----1-->%v------->%v------->%v------->%v------->%v\n" , actualValue , zeroPrize , allPrize , cappingPrize , percentageComplete )
percentageComplete = publicmethod . DecimalEs ( percentageComplete / 100 , 2 )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 11 15 : 55 : 35
@ 功能 : 获取目标设置
@ 参数
# targetConfigStr 当前数据记录的全奖值 、 零奖值 、 封顶值
# orgId 行政组织
# targetId 指标
# years 年
# month 月
@ 返回值
# zeroPrize 零奖值
# allPrize 全奖值
# cappingPrize 封顶值
@ 方法原型
# func GetTargetSetUp ( targetConfigStr , orgId , targetId , years string , month , class int ) ( zeroPrize , allPrize , cappingPrize float64 )
* /
func GetTargetSetUp ( targetConfigStr , orgId , targetId , years string , month , class int ) ( zeroPrize , allPrize , cappingPrize float64 ) {
var targetConfig [ ] FlowLogAllZreo
jsonErr := json . Unmarshal ( [ ] byte ( targetConfigStr ) , & targetConfig )
if jsonErr != nil || len ( targetConfig ) < 1 {
var qualConfig modelskpi . QuantitativeConfig
where := publicmethod . MapOut [ string ] ( )
where [ "departmentid" ] = orgId
where [ "target" ] = orgId
where [ "type" ] = class
where [ "year" ] = years
where [ "timecopy" ] = month
where [ "`state`" ] = 1
qualConfig . GetCont ( where , "`zeroprize`" , "`allprize`" , "`capping_val`" )
zeroPrize = qualConfig . Zeroprize
allPrize = qualConfig . Allprize
cappingPrize = qualConfig . CappingVal
}
for _ , v := range targetConfig {
if v . TargetId == targetId {
zeroPrize = v . Zeroprize
allPrize = v . Allprize
cappingPrize = v . Capping
// return
}
}
// fmt.Printf("这是获取目标值数据------------>targetConfigStr:%v----------->orgId:%v----------->targetId:%v----------->years:%v----------->month:%v----------->class:%v----------->jsonErr:%v----------->targetConfig:%v----------->zeroPrize:%v----------->allPrize:%v----------->cappingPrize:%v\n", targetConfigStr, orgId, targetId, years, month, class, jsonErr, targetConfig, zeroPrize, allPrize, cappingPrize)
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 13 13 : 42 : 07
@ 功能 : 历史同比根据部门 、 指标 、 年份统计每月的目标值 、 实际值 、 达成率
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) BasisDepartTargetTimeStatisticsYOY ( c * gin . Context ) {
var receivedValue BaseDepartTargetTimeYOY
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . OrgId == "" {
publicmethod . Result ( 1 , err , c , "未知行政组织!无法统计!" )
return
}
if receivedValue . TargetId == "" {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tarWhere := publicmethod . MapOut [ string ] ( )
tarWhere [ "et_id" ] = receivedValue . TargetId
//获取指标信息
var targetCont modelskpi . EvaluationTarget
err = targetCont . GetCont ( tarWhere )
if err != nil {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tadyTime := time . Now ( ) . Unix ( )
dateYear , _ := strconv . Atoi ( publicmethod . UnixTimeToDay ( tadyTime , 16 ) )
dateMonthMAx := 12
if len ( receivedValue . DateTime ) > 0 {
if len ( receivedValue . DateTime ) == 1 {
if receivedValue . DateTime [ 0 ] == dateYear {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
}
} else {
sort . Slice ( receivedValue . DateTime , func ( i , j int ) bool {
return receivedValue . DateTime [ i ] < receivedValue . DateTime [ j ]
} )
}
} else {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
receivedValue . DateTime = append ( receivedValue . DateTime , dateYear )
}
var sendData SendYOYData
sendData . YAxis . Type = "value"
sendData . YAxis . Name = "实际值"
sendData . YAxis . FormAtter = targetCont . Uniteing
var goSyncData GeteveryYearDttsb
//获取X轴数据
for i := 1 ; i <= dateMonthMAx ; i ++ {
sendData . XAxisVal = append ( sendData . XAxisVal , fmt . Sprintf ( "%v月" , i ) )
}
//获取Y轴数据
for _ , v := range receivedValue . DateTime {
SyncSeting . Add ( 1 )
go goSyncData . getOrgBylawsTime ( receivedValue . OrgId , receivedValue . TargetId , v , dateMonthMAx )
}
SyncSeting . Wait ( )
targetData , maxVal , minVal := goSyncData . readPlanTaskData ( )
if maxVal == 0 && minVal == 0 {
sendData . YAxis . Max = 10
sendData . YAxis . Min = 0
} else {
chaYiZhi := math . Ceil ( ( maxVal - minVal ) / 5 )
if maxVal < 0 {
sendData . YAxis . Max = maxVal - chaYiZhi
} else {
sendData . YAxis . Max = maxVal + chaYiZhi
}
}
maxYZhiStr := strconv . FormatFloat ( sendData . YAxis . Max , 'f' , 0 , 64 )
maxYZhiInt , _ := strconv . ParseInt ( maxYZhiStr , 10 , 64 )
quyuzhi := maxYZhiInt % 10
sendData . YAxis . Max = sendData . YAxis . Max - float64 ( quyuzhi ) + 10
fmt . Printf ( "maxYZhiStr:%v------------------>maxYZhiInt:%v---------------->quyuzhi:%v\n" , maxYZhiStr , maxYZhiInt , quyuzhi )
//根据维度月份排序
sort . Slice ( targetData , func ( i , j int ) bool {
return targetData [ i ] . Months < targetData [ j ] . Months
} )
for _ , v := range targetData {
var serInfo Seriescont
serInfo . Name = v . MonthStr
serInfo . Type = "bar"
serInfo . Tooltip = targetCont . Uniteing
serInfo . Data = v . MonthDataList
sendData . Series = append ( sendData . Series , serInfo )
}
fmt . Printf ( "targetData:%v------------------>maxVal:%v---------------->minVal:%v---------------->Max:%v\n" , targetData , maxVal , minVal , sendData . YAxis . Max )
publicmethod . Result ( 0 , sendData , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 13 14 : 33 : 07
@ 功能 : 协程计算月份历史值
@ 参数
# orgId 行政组织
# targetId 指标
# years 时间 ( 年 )
# months 时间 ( 月 )
@ 返回值
#
@ 方法原型
# ( g * GeteveryYearDttsb ) getOrgBylawsTime ( orgId , targetId string , dateTime [ ] int , months int )
* /
func ( g * GeteveryYearDttsb ) getOrgBylawsTime ( orgId , targetId string , years , months int ) {
g . mutext . Lock ( )
defer g . mutext . Unlock ( )
var dataCont HistorMonthData
dataCont . Months = years
dataCont . MonthStr = fmt . Sprintf ( "%v年" , years )
for i := 1 ; i <= months ; i ++ {
// SyncSetinges.Add(1)
// go g.CalculateYearMonthData(orgId, targetId, v, months)
var listCont [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowDataLogType { } ) . Select ( "`score`,`method`,`scoring_score`" ) . Where ( "`department` = ? AND `targetid` = ? AND `year` = ? AND `month` = ?" , orgId , targetId , years , i ) . Find ( & listCont ) . Error
if err != nil {
dataCont . MonthDataList = append ( dataCont . MonthDataList , 0 )
} else {
var fenScore float64
for _ , v := range listCont {
if v . ScoringMethod == 1 {
fenScore = fenScore + float64 ( v . Score )
} else {
fenScore = fenScore + float64 ( v . ScoringScore )
}
}
fenScore = publicmethod . DecimalEs ( fenScore / 100 , 2 )
dataCont . MonthDataList = append ( dataCont . MonthDataList , fenScore )
if g . AxisMax < fenScore {
g . AxisMax = fenScore
}
if g . AxisMin > fenScore {
g . AxisMin = fenScore
}
}
}
g . Target = append ( g . Target , dataCont )
// SyncSetinges.Wait()
SyncSeting . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 14 16 : 11 : 04
@ 功能 : 通过时间获取组织总分
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) TotalScoreOFOrgComesFromTimeSearch ( c * gin . Context ) {
var receivedValue OrgSecrcFormTime
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . OrgId == "" {
myCont , myErr := publicmethod . LoginMyCont ( c )
if myErr != nil {
receivedValue . OrgId = "309"
} else {
if myCont . Company != 0 {
receivedValue . OrgId = strconv . FormatInt ( myCont . Company , 10 )
} else {
receivedValue . OrgId = "309"
}
}
}
tayTime := time . Now ( ) . Unix ( )
currentYears := publicmethod . UnixTimeToDay ( tayTime , 16 )
currentMonths := publicmethod . UnixTimeToDay ( tayTime , 17 )
if receivedValue . DateTimes != "" {
var dayTime publicmethod . DateTimeTotimes
dayTime . BaisStrToTime ( receivedValue . DateTimes )
if dayTime . Years != "" {
currentYears = dayTime . Years
}
if dayTime . Months != "" {
currentMonths = dayTime . Months
}
}
//获取行政组织列表
var orgListCont [ ] modelshr . AdministrativeOrganization
err = overall . CONSTANT_DB_HR . Model ( & modelshr . AdministrativeOrganization { } ) . Select ( "`id`,`number`,`name`,`ispower`,`sort`" ) . Where ( "ispower = 1 AND state = 1 AND organization_type > 2 AND superior = ? AND `id` NOT IN ?" , receivedValue . OrgId , [ ] int { 281 , 163 } ) . Find ( & orgListCont ) . Error
if err != nil || len ( orgListCont ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
//获取一级主部门下是否由二级主部门
var allOrgListCont [ ] modelshr . AdministrativeOrganization
for _ , ov := range orgListCont {
sunOrgListCont , sunOrgErr := publicmethod . GetSunOrgList ( ov . Id )
if sunOrgErr == nil && len ( sunOrgListCont ) > 0 {
for _ , sv := range sunOrgListCont {
allOrgListCont = append ( allOrgListCont , sv )
}
} else {
allOrgListCont = append ( allOrgListCont , ov )
}
}
//根据维度序号排序
sort . Slice ( allOrgListCont , func ( i , j int ) bool {
return allOrgListCont [ i ] . Sort < allOrgListCont [ j ] . Sort
} )
var sendData SendTimeOfOrgSumScore
//开启协程,分别获取行政组织时间总分
var syncOrgTimeScore SyncOrgTimeAllScore
for _ , v := range allOrgListCont {
// if v.Id == 354 {
sendData . XAxisVal = append ( sendData . XAxisVal , v . Name )
SyncSeting . Add ( 1 )
// go syncOrgTimeScore.OrgCalculateScore(v, currentYears, currentMonths)
go syncOrgTimeScore . TallyUpOrgCalculateScore ( v , currentYears , currentMonths )
// }
}
SyncSeting . Wait ( )
scoreList , maxScore , minSchor := syncOrgTimeScore . readPlanTaskData ( )
// sendDataMap := publicmethod.MapOut[string]()
var suo [ ] Seriescont
for _ , ov := range allOrgListCont {
var seriesInfo Seriescont
seriesInfo . Name = ov . Name
seriesInfo . Type = "bar"
orgScore := GetAryValue ( ov . Id , scoreList )
seriesInfo . Data = append ( seriesInfo . Data , orgScore )
sendData . Series = append ( sendData . Series , orgScore )
suo = append ( suo , seriesInfo )
}
if maxScore > 0 && minSchor < 0 {
if maxScore < 10 {
maxScore = maxScore + 1
} else {
maxScore = maxScore + maxScore / 5
}
if minSchor > - 10 {
minSchor = minSchor - 1
} else {
minSchor = minSchor + minSchor / 5
}
} else if maxScore > 0 && minSchor > 0 {
maxScore = maxScore + ( maxScore - minSchor ) / 5
minSchor = float64 ( int64 ( minSchor / 10 ) ) * 10
}
sendData . YAxis . Min = math . Ceil ( minSchor )
sendData . YAxis . Max = math . Ceil ( maxScore )
// sendDataMap["sendData"] = sendData
// sendDataMap["receivedValue"] = receivedValue
// sendDataMap["currentYears"] = currentYears
// sendDataMap["currentMonths"] = currentMonths
// sendDataMap["allOrgListCont"] = allOrgListCont
// sendDataMap["syncOrgTimeScore"] = syncOrgTimeScore
// sendDataMap["suo"] = suo
// sendDataMap["maxScore"] = maxScore
// sendDataMap["minSchor"] = minSchor
publicmethod . Result ( 0 , sendData , c )
}
// 获取数值值
func GetAryValue ( orgId int64 , orgScoreList [ ] SyncOTASVal ) float64 {
for _ , v := range orgScoreList {
if orgId == v . OrgId {
return v . Score
}
}
return 0
}
// 获取数值值
func GetAryValueMonth ( months int , orgScoreList [ ] SyncOTASVal ) float64 {
for _ , v := range orgScoreList {
if months == v . Months {
return v . Score
}
}
return 0
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 15 11 : 14 : 37
@ 功能 : 计算行政组织成绩
@ 参数
# orgCont 行政组织薪资
# years 年
# months 月
@ 返回值
#
@ 方法原型
#
* /
func ( s * SyncOrgTimeAllScore ) OrgCalculateScore ( orgCont modelshr . AdministrativeOrganization , years , months string ) {
//锁操作
s . mutext . Lock ( )
defer s . mutext . Unlock ( )
tayTime := time . Now ( ) . Unix ( )
currentYears := publicmethod . UnixTimeToDay ( tayTime , 16 )
currentMonth := publicmethod . UnixTimeToDay ( tayTime , 17 )
//获取执行的考核方案
var schemeCont modelskpi . PlanVersio
var err error
if currentYears == years {
where := publicmethod . MapOut [ string ] ( )
where [ "`state`" ] = 1
where [ "`department`" ] = orgCont . Id
err = schemeCont . GetCont ( where )
} else {
err = overall . CONSTANT_DB_KPI . Where ( "state = 2 AND department = ? AND yeares = ?" , orgCont . Id , years ) . Order ( "addtime desc" ) . First ( & schemeCont ) . Error
if err != nil {
err = overall . CONSTANT_DB_KPI . Where ( "state = 3 AND department = ? AND yeares = ?" , orgCont . Id , years ) . Order ( "addtime desc" ) . First ( & schemeCont ) . Error
}
}
var getPoints float64
if err == nil {
//将考核方案解析
var schemeInfoCont [ ] SchemeInfo
jsonErr := json . Unmarshal ( [ ] byte ( schemeCont . Content ) , & schemeInfoCont )
if jsonErr == nil {
for _ , v := range schemeInfoCont { //维度层面
for _ , sv := range v . Child { //指标
//判断是不是观察指标
if sv . Status == 3 {
getPoints = getPoints + float64 ( sv . ReferenceScore )
// fmt.Printf("sv-1-->%v--->%v--->%v\n", sv.Id, sv.Name, sv.ReferenceScore)
} else {
if sv . Status == 1 && sv . Status != 3 { //判断指标是否启用并且不是观察指标
//获取指标内容
var targetInfo modelskpi . EvaluationTarget
targetInfo . GetCont ( map [ string ] interface { } { "`et_id`" : sv . Id } , "et_id" , "et_type" , "et_cycle" )
if sv . Cycles == 0 { //判断统计方式
sv . Cycles = targetInfo . Cycles
}
//判断指标类型
if targetInfo . Type == 1 {
//定性考核
dingXingScore := OrgSchemeDingXing ( orgCont . Id , sv . ReferenceScore , targetInfo . Id , sv . Cycles , sv . Status , years , months )
getPoints = getPoints + dingXingScore
// fmt.Printf("sv-2-->%v--->%v--->%v\n", sv.Id, sv.Name, dingXingScore)
} else {
//定量考核
dingLiangScore := OrgSchemeDingLiang ( orgCont . Id , sv . ReferenceScore , targetInfo . Id , sv . Cycles , sv . Status , years , months )
getPoints = getPoints + dingLiangScore
// fmt.Printf("sv-3-->%v--->%v--->%v\n", sv.Id, sv.Name, dingLiangScore)
}
}
}
// fmt.Printf("sv--->%v--->%v--->%v\n", sv.Id, sv.Name, getPoints)
}
}
}
}
currentYearsInt , _ := strconv . Atoi ( currentYears )
yearsInt , _ := strconv . Atoi ( years )
monthsInt , _ := strconv . Atoi ( months )
currentMonthInt , _ := strconv . Atoi ( currentMonth )
if currentYearsInt == yearsInt && monthsInt > currentMonthInt {
getPoints = 0
// fmt.Printf("currentYears:%v---->years:%v---->months:%v---->currentMonth:%v---->getPoints:%v\n", currentYearsInt, yearsInt, monthsInt, currentMonthInt, getPoints)
}
if s . AxisMax < getPoints {
s . AxisMax = getPoints
}
if s . AxisMin == 0 {
s . AxisMin = getPoints
} else {
if s . AxisMin > getPoints {
s . AxisMin = getPoints
}
}
var orgScore SyncOTASVal
orgScore . OrgId = orgCont . Id
orgScore . Score = publicmethod . DecimalEs ( getPoints , 2 )
orgScore . Months , _ = strconv . Atoi ( months )
s . OrgScore = append ( s . OrgScore , orgScore )
SyncSeting . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 15 14 : 35 : 59
@ 功能 : 计算行政组织考核方案指定时间内定量指标得分
@ 参数
# orgId 行政组织
# targetWeight 指标权重
# targetId 指标Id
# cycles 周期 ( 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年 )
# attribute 属性 ( 1 : 启用 ; 2 : 禁用 ; 3 : 观察 )
# years 年
# months 月
@ 返回值
# score 最终得分
@ 方法原型
# func OrgSchemeDingLiang ( orgId , targetWeight , targetId int64 , cycles , attribute int , years , months string ) ( score float64 )
* /
func OrgSchemeDingLiang ( orgId , targetWeight , targetId int64 , cycles , attribute int , years , months string ) ( score float64 ) {
//获取定量考核记录
var examineListCont [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `year` = ? AND `month` = ? AND `targetid` = ?" , orgId , years , months , targetId ) . Find ( & examineListCont ) . Error
if err != nil || len ( examineListCont ) < 1 {
score = float64 ( targetWeight )
return
}
var actualValue float64 //实际值
var resultValue float64 //得分
for _ , v := range examineListCont {
actualValue = actualValue + float64 ( v . Score )
//判断自动还是手动
if v . ScoringMethod == 1 {
classVal := 3
switch cycles {
case 5 :
classVal = 1
case 6 :
classVal = 2
default :
classVal = 3
}
monthsInt , _ := strconv . Atoi ( months )
//自动计算
zeroPrize , allPrize , cappingPrize := GetTargetSetUp ( v . Baseline , strconv . FormatInt ( orgId , 10 ) , strconv . FormatInt ( targetId , 10 ) , years , monthsInt , classVal )
//达成率
dachenglv := DepartTargetCompletionRate ( float64 ( v . Score ) , zeroPrize , allPrize , cappingPrize )
score = float64 ( targetWeight ) * ( dachenglv / 100 )
resultValue = resultValue + score
fmt . Printf ( "自动得分------->%v------->%v------->%v------->%v------->%v------->%v------->%v------->%v\n" , orgId , resultValue , dachenglv , score , zeroPrize , allPrize , cappingPrize , v . Score )
} else {
resultValue = resultValue + publicmethod . DecimalEs ( v . ScoringScore / 100 , 2 )
}
}
// score = publicmethod.DecimalEs(resultValue, 2)
score = resultValue
if attribute == 3 {
score = float64 ( targetWeight )
} else {
switch cycles {
case 5 :
if publicmethod . IsInTrue [ string ] ( months , [ ] string { "3" , "6" , "9" , "12" } ) == false {
score = float64 ( targetWeight )
}
case 6 :
if months != "12" {
score = float64 ( targetWeight )
}
case 7 :
if publicmethod . IsInTrue [ string ] ( months , [ ] string { "6" , "12" } ) == false {
score = float64 ( targetWeight )
}
default :
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 15 13 : 0 9 : 16
@ 功能 : 计算行政组织考核方案指定时间内定性指标得分
@ 参数
# orgId 行政组织
# targetWeight 指标权重
# targetId 指标Id
# cycles 周期 ( 1 : 班 ; 2 : 天 ; 3 : 周 ; 4 : 月 ; 5 : 季度 ; 6 : 年 )
# attribute 属性 ( 1 : 启用 ; 2 : 禁用 ; 3 : 观察 )
# years 年
# months 月
@ 返回值
# score 最终得分
@ 方法原型
# func OrgSchemeDingXing ( orgId , targetWeight , targetId int64 , cycles , attribute int , years , months string ) ( score float64 )
* /
func OrgSchemeDingXing ( orgId , targetWeight , targetId int64 , cycles , attribute int , years , months string ) ( score float64 ) {
//获取指定指标的所有满足条件的定性考核记录
var examineListCont [ ] modelskpi . ScoreFlow
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . ScoreFlow { } ) . Select ( "sf_score,sf_plus_reduce_score,sf_count" ) . Where ( "sf_reply IN ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , orgId , years , months , targetId ) . Find ( & examineListCont ) . Error
if err == nil && len ( examineListCont ) > 0 {
var minusPoints float64 //减分
var bonusPoint float64 //加分
for _ , v := range examineListCont {
if v . PlusReduceScore == 1 {
//加分操作
bonusPoint = bonusPoint + ( float64 ( v . Score ) * float64 ( v . Count ) ) //分值=原分值+(评分乘以发生次数)
} else {
//减分操作
minusPoints = minusPoints + ( float64 ( v . Score ) * float64 ( v . Count ) ) //分值=原分值+(评分乘以发生次数)
}
}
resultVal := ( float64 ( targetWeight ) + bonusPoint / 100 ) - minusPoints / 100
// score = publicmethod.DecimalEs(resultVal, 3)
score = resultVal
if attribute == 3 {
score = float64 ( targetWeight )
} else {
switch cycles {
case 5 :
if publicmethod . IsInTrue [ string ] ( months , [ ] string { "3" , "6" , "9" , "12" } ) == false {
score = float64 ( targetWeight )
}
case 6 :
if months != "12" {
score = float64 ( targetWeight )
}
case 7 :
if publicmethod . IsInTrue [ string ] ( months , [ ] string { "6" , "12" } ) == false {
score = float64 ( targetWeight )
}
default :
}
}
} else {
score = float64 ( targetWeight )
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 16 0 8 : 40 : 24
@ 功能 : 获取关键指标
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetHingeTarget ( c * gin . Context ) {
var receivedValue HingeTarget
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if len ( receivedValue . Id ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
tayTime := time . Now ( ) . Unix ( )
currentYears := publicmethod . UnixTimeToDay ( tayTime , 16 )
currentMonths := publicmethod . UnixTimeToDay ( tayTime , 17 )
if receivedValue . DateTime != "" {
var dayTime publicmethod . DateTimeTotimes
dayTime . BaisStrToTime ( receivedValue . DateTime )
if dayTime . Years != "" {
currentYears = dayTime . Years
}
if dayTime . Months != "" {
currentMonths = dayTime . Months
}
}
var targetListCont [ ] modelskpi . EvaluationTarget
err = overall . CONSTANT_DB_KPI . Model ( & modelskpi . EvaluationTarget { } ) . Select ( "`et_id`,`et_title`,`et_type`,`et_key`" ) . Where ( "`et_id` IN ?" , receivedValue . Id ) . Find ( & targetListCont ) . Error
if err != nil && len ( targetListCont ) < 1 {
publicmethod . Result ( 107 , err , c )
return
}
var sendListCont [ ] OutPutHingeTarget
for _ , v := range targetListCont {
var sendCont OutPutHingeTarget
sendCont . Id = strconv . FormatInt ( v . Id , 10 )
sendCont . Title = fmt . Sprintf ( "%v年%v月份 %v" , currentYears , currentMonths , v . Title )
sendCont . CharKey = fmt . Sprintf ( "chars_%v" , v . Key )
if len ( receivedValue . OrgId ) > 1 {
sendCont . DataList , sendCont . XAxisVal , sendCont . YAxis . Max , sendCont . YAxis . Min = GetOrgHingeTarget ( v . Id , v . Type , currentYears , currentMonths , receivedValue . OrgId )
}
sendCont . YAxis . Max , sendCont . YAxis . Min = publicmethod . JudjeMaxOfMinVal ( sendCont . YAxis . Max , sendCont . YAxis . Min )
// sendCont.DataList []float64 `json:"datalist"`
// sendCont.XAxisVal []string `json:"xaxis"` //X轴坐标值
sendListCont = append ( sendListCont , sendCont )
}
publicmethod . Result ( 0 , sendListCont , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 16 0 9 : 21 : 11
@ 功能 : 获取行政组织指标指定时间内的得分 ·
@ 参数
# targetId 指标Id
# attribute 属性 ( 1 : 定性考核 ; 2 : 定量考核 )
# ysers 年
# months 月
# orgId 行政组织
@ 返回值
#
@ 方法原型
#
* /
func GetOrgHingeTarget ( targetId int64 , attribute int , ysers , months string , orgId [ ] string ) ( dataList [ ] float64 , titleList [ ] string , maxVal , minVal float64 ) {
if len ( orgId ) < 0 {
return
}
var orgCont [ ] modelshr . AdministrativeOrganization
err := overall . CONSTANT_DB_HR . Model ( & modelshr . AdministrativeOrganization { } ) . Select ( "`id`,`name`,`sort`" ) . Where ( "`id` IN ?" , orgId ) . Order ( "`sort`" ) . Find ( & orgCont ) . Error
if err != nil || len ( orgCont ) < 1 {
return
}
var syncListCont SyncOrgTimeAllScore
for _ , v := range orgCont {
titleList = append ( titleList , v . Name )
SyncSeting . Add ( 1 )
go syncListCont . GetOrgTargetVal ( v . Id , targetId , attribute , ysers , months )
}
SyncSeting . Wait ( )
orgScore , maxVal , minVal := syncListCont . readPlanTaskData ( )
for _ , ov := range orgCont {
orgScore := GetAryValue ( ov . Id , orgScore )
dataList = append ( dataList , orgScore )
}
maxVal = publicmethod . DecimalEs ( maxVal , 2 )
minVal = publicmethod . DecimalEs ( minVal , 2 )
fmt . Printf ( "orgScore------->%v------->%v------->%v\n" , orgScore , maxVal , minVal )
return
}
func ( s * SyncOrgTimeAllScore ) GetOrgTargetVal ( orgId , targetId int64 , attribute int , ysers , months string ) {
//锁操作
s . mutext . Lock ( )
defer s . mutext . Unlock ( )
var tirgetScore SyncOTASVal
if attribute == 1 {
tirgetScore . Score = AuxiliaryCalculationSumNature ( orgId , targetId , ysers , months )
tirgetScore . OrgId = orgId
s . OrgScore = append ( s . OrgScore , tirgetScore )
} else {
tirgetScore . Score = AuxiliaryCalculationSum ( orgId , targetId , attribute , ysers , months )
tirgetScore . OrgId = orgId
s . OrgScore = append ( s . OrgScore , tirgetScore )
}
if s . AxisMin == 0 {
s . AxisMin = tirgetScore . Score
} else {
if s . AxisMin > tirgetScore . Score {
s . AxisMin = tirgetScore . Score
}
}
if s . AxisMax == 0 {
s . AxisMax = tirgetScore . Score
} else {
if s . AxisMax < tirgetScore . Score {
s . AxisMax = tirgetScore . Score
}
}
// fmt.Printf("计算最大====》%v=====>最小值=========>%v\n", s.AxisMax, s.AxisMin)
SyncSeting . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 16 10 : 00 : 53
@ 功能 : 获取定量指标总值
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func AuxiliaryCalculationSum ( orgId , targetId int64 , attribute int , years , months string ) ( sumScore float64 ) {
//获取定量考核记录
var examineListCont [ ] modelskpi . FlowDataLogType
err := overall . CONSTANT_DB_KPI . Where ( "`department` = ? AND `year` = ? AND `month` = ? AND `targetid` = ?" , orgId , years , months , targetId ) . Find ( & examineListCont ) . Error
if err != nil || len ( examineListCont ) < 1 {
sumScore = 0
return
}
for _ , v := range examineListCont {
sumScore = sumScore + float64 ( v . Score )
}
sumScore = publicmethod . DecimalEs ( sumScore / 100 , 2 )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 16 0 9 : 44 : 31
@ 功能 : 获取定性指标总值
@ 参数
# orgId 行政组织
# targetId 指标ID
# years 年
# months 月
@ 返回值
# sumScore 加减分
@ 方法原型
# func AuxiliaryCalculationSumNature ( orgId , targetId int64 , years , months string ) ( sumScore float64 )
* /
func AuxiliaryCalculationSumNature ( orgId , targetId int64 , years , months string ) ( sumScore float64 ) {
var examineListCont [ ] modelskpi . ScoreFlow
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . ScoreFlow { } ) . Select ( "sf_score,sf_plus_reduce_score,sf_count" ) . Where ( "sf_reply IN ? AND sf_duty_department = ? AND sf_year = ? AND sf_month = ? AND sf_target_id = ?" , [ ] int { 2 , 3 } , orgId , years , months , targetId ) . Find ( & examineListCont ) . Error
if err == nil && len ( examineListCont ) > 0 {
var minusPoints float64 //减分
var bonusPoint float64 //加分
for _ , v := range examineListCont {
if v . PlusReduceScore == 1 {
//加分操作
bonusPoint = bonusPoint + ( float64 ( v . Score ) * float64 ( v . Count ) ) //分值=原分值+(评分乘以发生次数)
} else {
//减分操作
minusPoints = minusPoints + ( float64 ( v . Score ) * float64 ( v . Count ) ) //分值=原分值+(评分乘以发生次数)
}
}
sumScore = ( bonusPoint - minusPoints ) / 100
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 16 15 : 50 : 20
@ 功能 : 获取单一行政组织指定年度各月份成绩
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetEveryOneOrgToMonthResult ( c * gin . Context ) {
var receivedValue OrgMonthResult
c . ShouldBindJSON ( & receivedValue )
if receivedValue . OrgId == "" {
publicmethod . Result ( 107 , receivedValue , c )
return
}
tayTime := time . Now ( ) . Unix ( )
tadyYear := publicmethod . UnixTimeToDay ( tayTime , 16 )
currentYears := tadyYear
currentMonths := 12
if receivedValue . DateTime != "" {
var dayTime publicmethod . DateTimeTotimes
dayTime . BaisStrToTime ( receivedValue . DateTime )
if dayTime . Years != "" {
currentYears = dayTime . Years
}
}
if currentYears == tadyYear {
currentMonths , _ = strconv . Atoi ( publicmethod . UnixTimeToDay ( tayTime , 17 ) )
}
var orgCont modelshr . AdministrativeOrganization
err := orgCont . GetCont ( map [ string ] interface { } { "`id`" : receivedValue . OrgId } )
if err != nil {
publicmethod . Result ( 107 , receivedValue , c )
return
}
fmt . Printf ( "年月---->%v---->%v\n" , currentYears , currentMonths )
var sendData SendTimeOfOrgSumScore
//开启协程,分别获取行政组织时间总分
var syncOrgTimeScore SyncOrgTimeAllScore
for i := 1 ; i <= currentMonths ; i ++ {
iStr := strconv . Itoa ( i )
iAxis := fmt . Sprintf ( "%v月" , iStr )
sendData . XAxisVal = append ( sendData . XAxisVal , iAxis )
SyncSeting . Add ( 1 )
go syncOrgTimeScore . OrgCalculateScore ( orgCont , currentYears , iStr )
}
SyncSeting . Wait ( )
scoreList , maxScore , minSchor := syncOrgTimeScore . readPlanTaskData ( )
//根据维度序号排序
sort . Slice ( scoreList , func ( i , j int ) bool {
return scoreList [ i ] . Months < scoreList [ j ] . Months
} )
var suo [ ] Seriescont
for i := 1 ; i <= currentMonths ; i ++ {
var seriesInfo Seriescont
seriesInfo . Name = fmt . Sprintf ( "%v月" , i )
seriesInfo . Type = "bar"
orgScore := GetAryValueMonth ( i , scoreList )
seriesInfo . Data = append ( seriesInfo . Data , orgScore )
sendData . Series = append ( sendData . Series , orgScore )
suo = append ( suo , seriesInfo )
}
sendData . YAxis . Max , sendData . YAxis . Min = publicmethod . JudjeMaxOfMinVal ( maxScore , minSchor )
// outData := publicmethod.MapOut[string]()
// outData["scoreList"] = scoreList
// outData["maxScore"] = maxScore
// outData["minSchor"] = minSchor
// outData["sendData"] = sendData
// outData["suo"] = suo
publicmethod . Result ( 0 , sendData , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 17 0 9 : 04 : 49
@ 功能 : 定性指标同比环比分析
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) BasisDepartAttrTargetTimeStatistics ( c * gin . Context ) {
var receivedValue BaseDepartTargetTimeYOY
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . OrgId == "" {
publicmethod . Result ( 1 , err , c , "未知行政组织!无法统计!" )
return
}
if receivedValue . TargetId == "" {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tarWhere := publicmethod . MapOut [ string ] ( )
tarWhere [ "et_id" ] = receivedValue . TargetId
//获取指标信息
var targetCont modelskpi . EvaluationTarget
err = targetCont . GetCont ( tarWhere )
if err != nil {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tadyTime := time . Now ( ) . Unix ( )
dateYear , _ := strconv . Atoi ( publicmethod . UnixTimeToDay ( tadyTime , 16 ) )
dateMonthMAx := 12
if len ( receivedValue . DateTime ) > 0 {
if len ( receivedValue . DateTime ) == 1 {
if receivedValue . DateTime [ 0 ] == dateYear {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
}
} else {
sort . Slice ( receivedValue . DateTime , func ( i , j int ) bool {
return receivedValue . DateTime [ i ] < receivedValue . DateTime [ j ]
} )
}
} else {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
receivedValue . DateTime = append ( receivedValue . DateTime , dateYear )
}
var sendData SendYOYData
sendData . YAxis . Type = "value"
sendData . YAxis . Name = "实际值"
sendData . YAxis . FormAtter = targetCont . Uniteing
var goSyncData GeteveryYearDttsb
//获取X轴数据
for i := 1 ; i <= dateMonthMAx ; i ++ {
sendData . XAxisVal = append ( sendData . XAxisVal , fmt . Sprintf ( "%v月" , i ) )
}
//获取Y轴数据
for _ , v := range receivedValue . DateTime {
SyncSeting . Add ( 1 )
go goSyncData . GetOrgAttrtargetTime ( receivedValue . OrgId , receivedValue . TargetId , v , dateMonthMAx )
}
SyncSeting . Wait ( )
targetData , maxVal , minVal := goSyncData . readPlanTaskData ( )
sendData . YAxis . Max , sendData . YAxis . Min = publicmethod . JudjeMaxOfMinVal ( maxVal , minVal )
//根据维度月份排序
sort . Slice ( targetData , func ( i , j int ) bool {
return targetData [ i ] . Months < targetData [ j ] . Months
} )
for _ , v := range targetData {
var serInfo Seriescont
serInfo . Name = v . MonthStr
serInfo . Type = "bar"
serInfo . Tooltip = targetCont . Uniteing
serInfo . Data = v . MonthDataList
sendData . Series = append ( sendData . Series , serInfo )
}
// fmt.Printf("targetData:%v------------------>maxVal:%v---------------->minVal:%v---------------->Max:%v\n", targetData, maxVal, minVal, sendData.YAxis.Max)
publicmethod . Result ( 0 , sendData , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 13 14 : 33 : 07
@ 功能 : 协程定性指标计算月份历史值
@ 参数
# orgId 行政组织
# targetId 指标
# years 时间 ( 年 )
# months 时间 ( 月 )
@ 返回值
#
@ 方法原型
# ( g * GeteveryYearDttsb ) getOrgBylawsTime ( orgId , targetId string , dateTime [ ] int , months int )
* /
func ( g * GeteveryYearDttsb ) GetOrgAttrtargetTime ( orgId , targetId string , years , months int ) {
g . mutext . Lock ( )
defer g . mutext . Unlock ( )
var dataCont HistorMonthData
dataCont . Months = years
dataCont . MonthStr = fmt . Sprintf ( "%v年" , years )
for i := 1 ; i <= months ; i ++ {
orgIdInt , _ := strconv . ParseInt ( orgId , 10 , 64 )
targetIdInt , _ := strconv . ParseInt ( targetId , 10 , 64 )
yearsStr := strconv . Itoa ( years )
monthsStr := strconv . Itoa ( i )
scoreVal := AuxiliaryCalculationSumNature ( orgIdInt , targetIdInt , yearsStr , monthsStr )
// scoreVal := 100 + AuxiliaryCalculationSumNature(orgIdInt, targetIdInt, yearsStr, monthsStr)
dataCont . MonthDataList = append ( dataCont . MonthDataList , scoreVal )
if g . AxisMax < scoreVal {
g . AxisMax = scoreVal
}
if g . AxisMin > scoreVal {
g . AxisMin = scoreVal
}
}
g . Target = append ( g . Target , dataCont )
// SyncSetinges.Wait()
SyncSeting . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 03 - 17 0 9 : 50 : 12
@ 功能 : 获取单一行政组织多年度各月份成绩
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetEveryOneOrgToMonthsResult ( c * gin . Context ) {
var receivedValue BaseDepartTimeYOY
err := c . ShouldBindJSON ( & receivedValue )
if err != nil {
publicmethod . Result ( 100 , err , c )
return
}
if receivedValue . OrgId == "" {
publicmethod . Result ( 1 , err , c , "未知行政组织!无法统计!" )
return
}
tarWhere := publicmethod . MapOut [ string ] ( )
tarWhere [ "`id`" ] = receivedValue . OrgId
//获取指标信息
var orgCont modelshr . AdministrativeOrganization
err = orgCont . GetCont ( tarWhere )
if err != nil {
publicmethod . Result ( 1 , err , c , "未知指标!无法统计!" )
return
}
tadyTime := time . Now ( ) . Unix ( )
dateYear , _ := strconv . Atoi ( publicmethod . UnixTimeToDay ( tadyTime , 16 ) )
dateMonthMAx := 12
if len ( receivedValue . DateTime ) > 0 {
if len ( receivedValue . DateTime ) == 1 {
if receivedValue . DateTime [ 0 ] == dateYear {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
}
} else {
sort . Slice ( receivedValue . DateTime , func ( i , j int ) bool {
return receivedValue . DateTime [ i ] < receivedValue . DateTime [ j ]
} )
}
} else {
dateMonthVal := publicmethod . UnixTimeToDay ( tadyTime , 17 )
dateMonthMAx , _ = strconv . Atoi ( dateMonthVal )
receivedValue . DateTime = append ( receivedValue . DateTime , dateYear )
}
var sendData SendYOYData
sendData . YAxis . Type = "value"
sendData . YAxis . Name = "成绩"
sendData . YAxis . FormAtter = "分"
//获取X轴数据
for i := 1 ; i <= dateMonthMAx ; i ++ {
sendData . XAxisVal = append ( sendData . XAxisVal , fmt . Sprintf ( "%v月" , i ) )
}
var goSyncData GeteveryYearDttsb
//获取Y轴数据
for _ , v := range receivedValue . DateTime {
SyncSetinges . Add ( 1 )
go goSyncData . GetOrgMoreTimeScore ( orgCont , v , dateMonthMAx )
}
SyncSetinges . Wait ( )
targetData , maxVal , minVal := goSyncData . readPlanTaskData ( )
sendData . YAxis . Max , sendData . YAxis . Min = publicmethod . JudjeMaxOfMinVal ( maxVal , minVal )
//根据维度月份排序
sort . Slice ( targetData , func ( i , j int ) bool {
return targetData [ i ] . Months < targetData [ j ] . Months
} )
for _ , v := range targetData {
var serInfo Seriescont
serInfo . Name = v . MonthStr
serInfo . Type = "bar"
serInfo . Tooltip = "分"
serInfo . Data = v . MonthDataList
sendData . Series = append ( sendData . Series , serInfo )
}
// fmt.Printf("targetData:%v------------------>maxVal:%v---------------->minVal:%v---------------->Max:%v\n", targetData, maxVal, minVal, sendData.YAxis.Max)
publicmethod . Result ( 0 , sendData , c )
}
// 获取
func ( g * GeteveryYearDttsb ) GetOrgMoreTimeScore ( orgCont modelshr . AdministrativeOrganization , years , months int ) {
//锁操作
g . mutext . Lock ( )
defer g . mutext . Unlock ( )
yearsStr := strconv . Itoa ( years )
var syncOrgTimeScore SyncOrgTimeAllScore
for i := 1 ; i <= months ; i ++ {
monthStr := strconv . Itoa ( i )
SyncSeting . Add ( 1 )
// go syncOrgTimeScore.OrgCalculateScore(orgCont, yearsStr, monthStr)
go syncOrgTimeScore . TallyUpOrgCalculateScore ( orgCont , yearsStr , monthStr )
}
SyncSeting . Wait ( )
scoreList , maxScore , minSchor := syncOrgTimeScore . readPlanTaskData ( )
//根据维度序号排序
sort . Slice ( scoreList , func ( i , j int ) bool {
return scoreList [ i ] . Months < scoreList [ j ] . Months
} )
if g . AxisMax == 0 {
g . AxisMax = maxScore
} else {
if g . AxisMax < maxScore {
g . AxisMax = maxScore
}
}
if g . AxisMin == 0 {
g . AxisMin = minSchor
} else {
if g . AxisMin > minSchor {
g . AxisMin = minSchor
}
}
var dataCont HistorMonthData
dataCont . Months = years
dataCont . MonthStr = fmt . Sprintf ( "%v年" , years )
for _ , v := range scoreList {
dataCont . MonthDataList = append ( dataCont . MonthDataList , v . Score )
}
g . Target = append ( g . Target , dataCont )
// fmt.Printf("获取:%v------------------>%v------------------>%v------------------>scoreList:%v------------------>maxScore:%v---------------->minSchor:%v\n", orgCont.Name, years, months, scoreList, maxScore, minSchor)
SyncSetinges . Done ( )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 21 16 : 30 : 26
@ 功能 : 相关提报人定性考核细则列表 ( web使用 )
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetQualityBylawsTasks ( c * gin . Context ) {
var receivedValue BylawsAboutPeopleDime
c . ShouldBindJSON ( & receivedValue )
if receivedValue . OrgId == "" || receivedValue . TargetId == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
//获取登录人信息
myLoginCont , _ := publicmethod . LoginMyCont ( c )
var qualEvaCont modelskpi . QualitativeEvaluationView
gormDb := overall . CONSTANT_DB_KPI . Table ( fmt . Sprintf ( "%s qe" , qualEvaCont . TableName ( ) ) ) . Select ( "qe.qe_id,qe.qe_target_sun,qe.qe_detailed_target,qe.qe_content,qe.qe_censor_cont,qe.qe_min_score,qe.qe_max_score,qe.qe_unit,qe.qe_target_sun" ) . Where ( "qe.`qe_type` = 1 AND qe.`qe_state` = 1 AND qe.`qe_accept_evaluation` = ? AND qe.`qe_target` = ?" , receivedValue . OrgId , receivedValue . TargetId )
gormDb = gormDb . Joins ( "JOIN target_report td ON qe.qe_target = td.target_id AND qe.qe_accept_evaluation = td.`department_id` AND td.target_bylaws = qe.`qe_detailed_target` AND td.`type` = 1 AND td.`post_id` = 0 AND td.state = 1 AND td.type_level = 3 AND td.`man_key` = ?" , myLoginCont . Key )
// if receivedValue.OrgId != "" {
// gormDb = gormDb.Where("`qe_accept_evaluation` = ?", receivedValue.OrgId)
// }
var qualEvaList [ ] modelskpi . QualitativeEvaluationView
err := gormDb . Order ( "qe_accept_evaluation ASC,qe_target ASC" ) . Find ( & qualEvaList ) . Error
if err != nil {
publicmethod . Result ( 105 , err , c )
return
}
var tableId [ ] int64
var sendContList [ ] OutDimList
for _ , v := range qualEvaList {
if ! publicmethod . IsInTrue [ int64 ] ( v . TargetSun , tableId ) {
tableId = append ( tableId , v . TargetSun )
var sendCont OutDimList
sendCont . Id = strconv . FormatInt ( v . TargetSun , 10 )
var tableCont modelskpi . QualitativeTarget
tableCont . GetCont ( map [ string ] interface { } { "q_id" : v . TargetSun } , "q_title" )
sendCont . Name = tableCont . Title
sendCont . OrgId = receivedValue . OrgId
sendCont . TargetId = receivedValue . TargetId
sendContList = append ( sendContList , sendCont )
}
}
publicmethod . Result ( 0 , sendContList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 22 0 8 : 22 : 01
@ 功能 : 根据栏目获取获取相关指标
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) BasePostTableHaveTarget ( c * gin . Context ) {
var receivedValue BaseTableGetTargetWeb
c . ShouldBindJSON ( & receivedValue )
if receivedValue . OrgId == "" || receivedValue . TargetId == "" {
publicmethod . Result ( 101 , receivedValue , c )
return
}
if receivedValue . Page == 0 {
receivedValue . Page = 1
}
if receivedValue . PageSize == 0 {
receivedValue . PageSize = 15
}
//获取登录人信息
myLoginCont , _ := publicmethod . LoginMyCont ( c )
var qualEvaCont modelskpi . QualitativeEvaluationView
gormDb := overall . CONSTANT_DB_KPI . Table ( fmt . Sprintf ( "%s qe" , qualEvaCont . TableName ( ) ) ) . Select ( "qe.qe_id,qe.qe_target_sun,qe.qe_detailed_target,qe.qe_content,qe.qe_censor_cont,qe.qe_min_score,qe.qe_max_score,qe.qe_unit" ) . Where ( "qe.`qe_type` = 1 AND qe.`qe_state` = 1 AND qe.`qe_accept_evaluation` = ? AND qe.`qe_target` = ? AND qe.`qe_target_sun` = ?" , receivedValue . OrgId , receivedValue . TargetId , receivedValue . TableId )
gormDb = gormDb . Joins ( "JOIN target_report td ON qe.qe_target = td.target_id AND qe.qe_accept_evaluation = td.`department_id` AND td.target_bylaws = qe.`qe_detailed_target` AND td.`type` = 1 AND td.`post_id` = 0 AND td.state = 1 AND td.type_level = 3 AND td.`man_key` = ?" , myLoginCont . Key )
var total int
var qualEvaListCount [ ] modelskpi . QualitativeEvaluationView
totalErr := gormDb . Find ( & qualEvaListCount ) . Error
if totalErr != nil {
total = 0
} else {
total = len ( qualEvaListCount )
}
var qualEvaList [ ] modelskpi . QualitativeEvaluationView
gormDb = publicmethod . PageTurningSettings ( gormDb , receivedValue . Page , receivedValue . PageSize )
err := gormDb . Order ( "qe_accept_evaluation ASC,qe_target ASC" ) . Find ( & qualEvaList ) . Error
if err != nil {
publicmethod . Result ( 105 , err , c )
return
}
var sendContList [ ] OutPutBylawsCont
for _ , v := range qualEvaList {
var sendCont OutPutBylawsCont
sendCont . Id = strconv . FormatInt ( v . Id , 10 )
var bylawsCont modelskpi . DetailedTarget
bylawsCont . GetCont ( map [ string ] interface { } { "`dt_id`" : v . DetailedTarget } , "`dt_title`" , "`dt_content`" , ` dt_add_reduce ` )
var columnCont modelskpi . QualitativeTarget
columnCont . GetCont ( map [ string ] interface { } { "`q_id`" : v . TargetSun } , "`q_title`" )
sendCont . ColumnTitle = columnCont . Title
sendCont . Title = bylawsCont . Title //考核项目
sendCont . Content = bylawsCont . Content //考核内容
if v . Content != "" {
sendCont . Content = v . Content
}
if v . CensorCont != "" {
sendCont . Content = v . CensorCont
}
sendCont . MaxScore = publicmethod . DecimalEs ( float64 ( v . MaxScore ) / 100 , 2 )
sendCont . MinScore = publicmethod . DecimalEs ( float64 ( v . MinScore ) / 100 , 2 )
if sendCont . MinScore > 0 && sendCont . MaxScore > 0 {
sendCont . Standard = fmt . Sprintf ( "%v-%v" , sendCont . MinScore , sendCont . MaxScore ) //标准
sendCont . ScoreType = 2
} else if sendCont . MinScore > 0 && sendCont . MaxScore <= 0 {
sendCont . Standard = fmt . Sprintf ( "%v" , sendCont . MinScore )
sendCont . ScoreType = 1
} else if sendCont . MinScore <= 0 && sendCont . MaxScore > 0 {
sendCont . Standard = fmt . Sprintf ( "%v" , sendCont . MaxScore )
sendCont . ScoreType = 1
} else {
sendCont . Standard = "0"
sendCont . ScoreType = 3
}
sendCont . Unit = v . Unit //单位
sendCont . PlusMinusScore = bylawsCont . AddReduce //加减分
sendContList = append ( sendContList , sendCont )
}
publicmethod . ResultList ( 0 , receivedValue . Page , receivedValue . PageSize , int64 ( total ) , int64 ( len ( sendContList ) ) , sendContList , c )
}