package departmentpc
import (
"encoding/json"
"fmt"
"key_performance_indicators/api/version1/postseting/postweb"
"key_performance_indicators/api/workflow/currency_recipe"
"key_performance_indicators/api/workflow/workflowengine"
"key_performance_indicators/api/workwechat"
"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"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 0 9 : 42 : 53
@ 功能 : 获取定量考核任务列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) GetQuantitativeTasks ( c * gin . Context ) {
//获取登录人信息
myLoginCont , _ := publicmethod . LoginMyCont ( c )
//获取参数
var receivedValue GetQuanTasks
c . ShouldBindJSON ( & receivedValue )
// var listCont []modelskpi.QualitativeEvaluation
// gormDb := overall.CONSTANT_DB_KPI.Where("`qe_type` = 2 AND `qe_state` = 1 AND FIND_IN_SET(?,`qe_operator`)", myLoginCont.Key)
// if receivedValue.OrgId != "" {
// gormDb = gormDb.Where("qe_accept_evaluation = ?", receivedValue.OrgId)
// }
// if receivedValue.Title != "" {
// gormDb = gormDb.Joins("LEFT JOIN evaluationtarget ON et_id = qe_target").Where("et_title LIKE ?", "%"+receivedValue.Title+"%")
// }
// gormDb := overall.CONSTANT_DB_KPI.Where("`qe_type` = 2 AND `qe_state` = 1 ")
// if receivedValue.OrgId != "" {
// gormDb = gormDb.Where("qe_accept_evaluation = ?", receivedValue.OrgId)
// }
// if receivedValue.Title != "" {
// gormDb = gormDb.Joins("LEFT JOIN evaluationtarget ON et_id = qe_target").Where("et_title LIKE ?", "%"+receivedValue.Title+"%")
// }
var qualEvaCont modelskpi . QualitativeEvaluationView
gormDb := overall . CONSTANT_DB_KPI . Table ( fmt . Sprintf ( "%s qe" , qualEvaCont . TableName ( ) ) ) . Select ( "qe.`qe_accept_evaluation`,qe.`qe_target`,qe.`et_title`" ) . Where ( "qe.`qe_type` = 2 AND qe.`qe_state` = 1 " )
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 = 1 AND td.`man_key` = ?" , myLoginCont . Key )
if receivedValue . OrgId != "" {
gormDb = gormDb . Where ( "`qe_accept_evaluation` = ?" , receivedValue . OrgId )
}
if receivedValue . Title != "" {
gormDb = gormDb . Where ( "et_title LIKE ?" , "%" + receivedValue . Title + "%" )
}
var qualEvaList [ ] modelskpi . QualitativeEvaluationView
err := gormDb . Order ( "qe_accept_evaluation ASC,qe_target ASC" ) . Find ( & qualEvaList ) . Error
// publicmethod.Result(1, qualEvaList, c, "您没有要参加的考核项目!")
// return
// err := gormDb.Order("qe_type ASC,qe_group ASC,qe_accept_evaluation ASC,qe_dimension ASC,qe_target ASC,qe_target_sun ASC,qe_detailed_target ASC").Find(&listCont).Error
if err != nil || len ( qualEvaList ) < 1 {
publicmethod . Result ( 1 , qualEvaList , c , "您没有要参加的考核项目!" )
return
}
var sendListCont [ ] TargetContOutCont
for _ , vsss := range qualEvaList {
var v modelskpi . QualitativeEvaluation
v . GetCont ( map [ string ] interface { } { "`qe_accept_evaluation`" : vsss . AcceptEvaluation , "`qe_target`" : vsss . Target , "`qe_state`" : 1 } )
var sendCont TargetContOutCont
sendCont . Id = strconv . FormatInt ( v . Id , 10 )
sendCont . Type = v . Type
sendCont . Group = strconv . FormatInt ( v . Group , 10 )
//公司
var groupCont modelshr . AdministrativeOrganization
groupCont . GetCont ( map [ string ] interface { } { "`id`" : v . Group } , "`name`" )
sendCont . GroupNAme = groupCont . Name
//部门
var departCont modelshr . AdministrativeOrganization
departCont . GetCont ( map [ string ] interface { } { "`id`" : v . AcceptEvaluation } , "`name`" )
sendCont . DepartmentName = departCont . Name
sendCont . DepartmentId = strconv . FormatInt ( v . AcceptEvaluation , 10 )
sendCont . PlanVersionNumber = v . QualEvalId //执行方案版本号
//维度相关信息
sendCont . Dimension = strconv . FormatInt ( v . Dimension , 10 )
var dimeCont modelskpi . DutyClass
dimeCont . GetCont ( map [ string ] interface { } { "`id`" : v . Dimension } , "`title`" )
sendCont . DimensionName = dimeCont . Title
//指标信息
sendCont . Target = strconv . FormatInt ( v . Target , 10 )
var targetCont modelskpi . EvaluationTarget
targetCont . GetCont ( map [ string ] interface { } { "`et_id`" : v . Target } , "`et_title`" , "`et_scoring_method`" )
sendCont . TargetName = targetCont . Title
//子栏目
sendCont . ScoringMethod = int64 ( targetCont . ScoringMethod )
if v . TargetSun != 0 {
sendCont . TargetSun = strconv . FormatInt ( v . TargetSun , 10 )
var sunTargetCont modelskpi . QualitativeTarget
sunTargetCont . GetCont ( map [ string ] interface { } { "`q_id`" : v . Target } , "`q_title`" )
sendCont . TargetSunName = sunTargetCont . Title
}
//指标细则
if v . DetailedTarget != 0 {
sendCont . DetailedTarget = strconv . FormatInt ( v . DetailedTarget , 10 )
var detailedTargetCont modelskpi . DetailedTarget
detailedTargetCont . GetCont ( map [ string ] interface { } { "`dt_id`" : v . Target } , "`dt_title`" , "`dt_content`" )
sendCont . DetailedTargetName = detailedTargetCont . Title
sendCont . Content = detailedTargetCont . Content
}
sendCont . Unit = v . Unit
sendCont . ReferenceScore = v . ReferenceScore
sendCont . Cycles = v . Cycles
sendCont . CycleAttres = v . CycleAttres
sendCont . State = v . State
userAry := strings . Split ( v . Operator , "," )
sendCont . UserList = userAry
for _ , u_v := range userAry {
var repoCont modelshr . PersonArchives
repoErr := repoCont . GetCont ( map [ string ] interface { } { "`key`" : u_v } , "`number`" , "`name`" )
if repoErr == nil {
var userCont QualEvalArrt
userCont . Id = u_v
userCont . Name = repoCont . Name
sendCont . UserListAry = append ( sendCont . UserListAry , userCont )
}
}
fmt . Printf ( "版本号吗!--->%v\n" , v . QualEvalId )
sendCont . DimensionWeight , sendCont . TargetWeight = getPlanVersionWeghit ( v . QualEvalId , strconv . FormatInt ( v . Dimension , 10 ) , strconv . FormatInt ( v . Target , 10 ) )
//获取目标设定
quanTitWhere := publicmethod . MapOut [ string ] ( )
// quanTitWhere["company_id"] = v.Group
quanTitWhere [ "departmentid" ] = v . AcceptEvaluation
// quanTitWhere["dimension"] = v.Dimension
quanTitWhere [ "target" ] = v . Target
if v . DetailedTarget != 0 {
quanTitWhere [ "targetconfig" ] = v . DetailedTarget
}
quanTitWhere [ "year" ] = publicmethod . UnixTimeToDay ( time . Now ( ) . Unix ( ) , 16 )
quanTitWhere [ "timecopy" ] = AllZreoConfig ( v . Cycles )
//目标值设定
var quanTitCont modelskpi . QuantitativeConfig
quanTitCont . GetCont ( quanTitWhere )
//全奖值、零奖值、封顶值
sendCont . ZeroPrize = strconv . FormatFloat ( float64 ( quanTitCont . Zeroprize ) / 100 , 'f' , - 1 , 64 )
sendCont . AllPrize = strconv . FormatFloat ( float64 ( quanTitCont . Allprize ) / 100 , 'f' , - 1 , 64 )
sendCont . CappingVal = quanTitCont . CappingVal / 100
//获取实际值
shiJiZhi := publicmethod . MapOut [ string ] ( )
shiJiZhi [ "fl_evaluation_user" ] = myLoginCont . Key
shiJiZhi [ "fl_evaluation_department" ] = myLoginCont . MainDeparment
shiJiZhi [ "fl_evaluation_group" ] = myLoginCont . Company
shiJiZhi [ "fl_duty_department" ] = v . AcceptEvaluation
operationTime := time . Now ( ) . Unix ( )
if receivedValue . Time != "" {
strTime := fmt . Sprintf ( "%v-01 00:00:00" , receivedValue . Time )
stringToTime , strToTimeErr := publicmethod . DateToTimeStamp ( strTime )
if strToTimeErr == true {
operationTime = stringToTime
} else {
strTime = fmt . Sprintf ( "%v 00:00:00" , receivedValue . Time )
stringToTime , strToTimeErr = publicmethod . DateToTimeStamp ( strTime )
if strToTimeErr == true {
operationTime = stringToTime
}
}
}
years := publicmethod . ComputingTime ( operationTime , 1 )
quarter := publicmethod . ComputingTime ( operationTime , 2 )
months := publicmethod . ComputingTime ( operationTime , 3 )
switch v . Cycles {
case 1 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
case 2 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
case 3 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
case 4 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
case 5 :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
case 6 :
shiJiZhi [ "fl_year" ] = years
default :
shiJiZhi [ "fl_year" ] = years
shiJiZhi [ "fl_quarter" ] = quarter
shiJiZhi [ "fl_month" ] = months
shiJiZhi [ "fl_week" ] = publicmethod . ComputingTime ( operationTime , 4 )
shiJiZhi [ "fl_day" ] = publicmethod . ComputingTime ( operationTime , 5 )
}
sendCont . ReferTo = JudgeDingLiangIsTrue ( v . Id , v . AcceptEvaluation , years , quarter , months , v . Cycles )
actualValue , shouDongScore := GetTimeIntervalDuty ( shiJiZhi , v . Id ) //实际值
sendCont . Actual = strconv . FormatFloat ( actualValue / 100 , 'f' , - 1 , 64 )
// chuShuVal := actualValue - quanTitCont.Zeroprize
// beiChuShuVal := quanTitCont.Allprize - quanTitCont.Zeroprize
// if beiChuShuVal > 0 {
// sendCont.ReachScore = chuShuVal / beiChuShuVal
// } else {
// sendCont.ReachScore = 0
// }
var actual float64
actual , sendCont . ReachScore = postweb . GetAchieAndActual ( actualValue , float64 ( sendCont . TargetWeight ) , quanTitCont . Zeroprize , quanTitCont . Allprize , quanTitCont . CappingVal )
if targetCont . ScoringMethod != 1 {
sendCont . ReachScore = publicmethod . DecimalEs ( shouDongScore / 100 , 2 )
}
// fmt.Printf("All--->score:%v------>weight:%v------>zeroprize:%v------>allprize:%v------>cappingval:%v------>achievement:%v------>actual:%v\n", actualValue, sendCont.TargetWeight, quanTitCont.Zeroprize, quanTitCont.Allprize, quanTitCont.CappingVal, sendCont.ReachScore, actual)
if quanTitCont . Zeroprize == 0 && quanTitCont . Allprize == 0 {
sendCont . Reach = "未设置目标值"
} else {
dividend := quanTitCont . Allprize - quanTitCont . Zeroprize //被除数
if dividend == 0 {
sendCont . Reach = "未设置目标值"
} else {
// sendCont.Reach = fmt.Sprintf("(实际值-零奖值)/(全奖值-零奖值)")
actual = publicmethod . DecimalEs ( actual * 100 , 2 )
sendCont . Reach = fmt . Sprintf ( "%v%v" , actual , "%" )
if actualValue == 0 {
sendCont . Reach = "100%"
}
}
}
sendCont . Reason = ""
sendCont . DetailedTarget = strconv . FormatInt ( v . DetailedTarget , 10 )
// switch v.Cycles {
// case 5:
// banNian := []int64{3, 6, 9, 12}
// if publicmethod.IsInTrue[int64](months, banNian) {
// sendListCont = append(sendListCont, sendCont)
// }
// case 6:
// if months == 12 {
// sendListCont = append(sendListCont, sendCont)
// }
// case 7:
// banNian := []int64{6, 12}
// if publicmethod.IsInTrue[int64](months, banNian) {
// sendListCont = append(sendListCont, sendCont)
// }
// default:
// sendListCont = append(sendListCont, sendCont)
// }
sendListCont = append ( sendListCont , sendCont )
}
publicmethod . Result ( 0 , sendListCont , c )
}
// 判断定量指标是否已经提交
func JudgeDingLiangIsTrue ( targetId , department int64 , year , quarter , monthsss int64 , types int ) bool {
var idList [ ] int64
// gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.FlowDataLogType{}).Select("`id`").Where("`targetid` = ? AND `department` = ?", targetId, department)
gormDb := overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowDataLogType { } ) . Select ( "`id`" ) . Where ( "`fld_evaluation_id` = ? AND `department` = ?" , targetId , department )
// switch types {
// case 5:
// gormDb = gormDb.Where("`year` = ? AND `quarte` = ?", year, quarter)
// case 6:
// gormDb = gormDb.Where("`year` = ?", year)
// case 7:
// banNian := []int{1, 2, 3, 4, 5, 6}
// if monthsss > 6 {
// banNian = []int{7, 8, 9, 10, 11, 12}
// }
// gormDb = gormDb.Where("`year` = ? AND `month` IN ?", year, banNian)
// default:
// gormDb = gormDb.Where("`year` = ? AND `month` = ?", year, monthsss)
// }
/ *
规则改变 , 不管哪种统计类型 , 每个月都要提交数据 , 季度计算未季度平均值在季度末参与计算
* /
gormDb = gormDb . Where ( "`year` = ? AND `month` = ?" , year , monthsss )
err := gormDb . Find ( & idList ) . Error
if err == nil && len ( idList ) > 0 {
return true
}
return false
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 10 : 23 : 22
@ 功能 : 获取维度与指标权重
@ 参数
# planKey 方案编号
# dimensionId 维度
# targetId 指标
@ 返回值
# dimensionIdWeghit 维度权重
# targetIdWeghit 指标权重
@ 方法原型
# getPlanVersionWeghit ( planKey , dimensionId , targetId string ) ( dimensionIdWeghit , targetIdWeghit int64 )
* /
func getPlanVersionWeghit ( planKey , dimensionId , targetId string ) ( dimensionIdWeghit , targetIdWeghit int64 ) {
var planVersionCont modelskpi . PlanVersio
err := overall . CONSTANT_DB_KPI . Model ( & modelskpi . PlanVersio { } ) . Select ( "`content`" ) . Where ( "`key` = ?" , planKey ) . First ( & planVersionCont ) . Error
if err != nil {
return
}
var planVersioInfo [ ] AddDutyNewCont
jsonErr := json . Unmarshal ( [ ] byte ( planVersionCont . Content ) , & planVersioInfo )
if jsonErr != nil {
return
}
for _ , v := range planVersioInfo {
if v . Id == dimensionId {
dimensionIdWeghit = int64 ( v . ZhiFraction )
for _ , cv := range v . Child {
if cv . Id == targetId {
targetIdWeghit = cv . ReferenceScore
}
}
}
}
return
}
/ * *
@ 作者 : 秦东
@ 时间 : 2023 - 01 - 15 10 : 49 : 07
@ 功能 : 判断全奖与零奖参数
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
// 判断全奖与零奖参数
func AllZreoConfig ( cycles int ) ( monthInt int64 ) {
switch cycles {
case 4 :
monthInt = publicmethod . ComputingTime ( time . Now ( ) . Unix ( ) , 3 )
case 5 :
monthInt = publicmethod . ComputingTime ( time . Now ( ) . Unix ( ) , 2 )
default :
}
return
}
// 获取定量考核时间内审批通过的考核数据
func GetTimeIntervalDuty ( whereData interface { } , schemeID int64 ) ( actual , shouDongScore float64 ) {
// jsonStr, _ := json.Marshal(whereData)
// fmt.Printf("jsonStr------1------>%v\n", string(jsonStr))
actual = 0
//相关审批流
var flowLogList [ ] modelskpi . FlowLog
err := overall . CONSTANT_DB_KPI . Where ( "`fl_reply` IN (2,3) AND FIND_IN_SET(?,`fl_evaluation_id`)" , schemeID ) . Where ( whereData ) . Find ( & flowLogList ) . Error
if err != nil {
return
}
for _ , v := range flowLogList {
ziDongScore , sdScore := GetSchemeFlowData ( v . Key , schemeID )
actual = actual + ziDongScore
shouDongScore = shouDongScore + sdScore
}
return
}
// 获取指定审批流方案数据
func GetSchemeFlowData ( flowKwy , schemeID int64 ) ( weightSum , shouDongScore float64 ) {
weightSum = 0
overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowLogData { } ) . Where ( "`fld_evaluation_id` = ? AND `fld_flow_log` = ?" , schemeID , flowKwy ) . Pluck ( "COALESCE(SUM(fld_score), 0) as flscore" , & weightSum )
// weightSum = 0
overall . CONSTANT_DB_KPI . Model ( & modelskpi . FlowLogData { } ) . Where ( "`fld_evaluation_id` = ? AND `fld_flow_log` = ?" , schemeID , flowKwy ) . Pluck ( "COALESCE(SUM(fld_scoring_score), 0) as scoring_score" , & shouDongScore )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 02 - 23 16 : 35 : 22
@ 功能 : 获取关联指标细则
@ 参数
# targetid 指标ID
# tableid 栏目Id
# bylaws 细则Id
# orgid 行政组织
# post 岗位
# types 类型 ( 1 : 指标 ; 2 : 子目标 ; 3 : 细则 )
# level 级别 ( 1 : 部门级 ; 2 : 岗位级 )
@ 返回值
# bylawsId 相关ID
# err 信息
@ 方法原型
# GetTargetDetailsInfoList ( targetid , tableid , bylaws , orgid , post int64 , types , level int ) ( bylawsId [ ] int64 , err error )
* /
func GetTargetDetailsInfoList ( targetid , tableid , bylaws , orgid , post int64 , types , level int ) ( bylawsId [ ] int64 , err error ) {
if types == 0 {
types = 3
}
gormDb := overall . CONSTANT_DB_KPI . Model ( & modelskpi . TargetDepartment { } )
switch types {
case 1 :
gormDb = gormDb . Distinct ( ` target_id ` )
case 2 :
gormDb = gormDb . Distinct ( ` target_sun_id ` )
default :
gormDb = gormDb . Distinct ( ` target_bylaws ` )
}
gormDb = gormDb . Where ( "`state` = 1 AND `type` = ? AND `level` = ?" , types , level )
if targetid != 0 {
gormDb = gormDb . Where ( "`target_id` = ?" , targetid )
}
if tableid != 0 {
gormDb = gormDb . Where ( "`target_sun_id` = ?" , tableid )
}
if bylaws != 0 {
gormDb = gormDb . Where ( "`target_bylaws` = ?" , bylaws )
}
err = gormDb . Find ( & bylawsId ) . Error
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2023 - 04 - 12 16 : 03 : 31
@ 功能 : 提交定量考核
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( a * ApiMethod ) SubmitQuantifyTarget ( c * gin . Context ) {
var receivedValue SubmitQuantTargetCont
c . ShouldBindJSON ( & receivedValue )
if receivedValue . FlowworkId == "" {
publicmethod . Result ( 1 , receivedValue , c , "未知工作流!不可进行提交" )
return
}
if receivedValue . DepartmentId == "" {
publicmethod . Result ( 1 , receivedValue , c , "未知行政组织!不可进行提交" )
return
}
acceptDepartment , _ := strconv . ParseInt ( receivedValue . DepartmentId , 10 , 64 )
if receivedValue . PlanVersionNumber == "" {
publicmethod . Result ( 1 , receivedValue , c , "未知方案!不可进行提交" )
return
}
operationTime := time . Now ( ) . Unix ( ) //统一操作时间
occurrenceTime := operationTime
//计算发生时间
currentYears := strconv . FormatInt ( publicmethod . ComputingTime ( operationTime , 1 ) , 10 )
currentQuarter := strconv . FormatInt ( publicmethod . ComputingTime ( operationTime , 2 ) , 10 )
currentMonths := strconv . FormatInt ( publicmethod . ComputingTime ( operationTime , 3 ) , 10 )
currentWeek := strconv . FormatInt ( publicmethod . ComputingTime ( operationTime , 4 ) , 10 )
if receivedValue . Time == "" {
publicmethod . Result ( 1 , receivedValue , c , "未知考核时间!不可进行提交" )
return
} else {
var dayTime publicmethod . DateTimeTotimes
dayTime . BaisStrToTime ( receivedValue . Time )
if dayTime . Years != "" {
currentYears = dayTime . Years
}
if dayTime . Quarter != "" {
currentQuarter = dayTime . Quarter
}
if dayTime . Months != "" {
currentMonths = dayTime . Months
}
if dayTime . Week != "" {
currentWeek = dayTime . Week
}
occurrenceTime = dayTime . AllTime
}
currentYearsInt , _ := strconv . ParseInt ( currentYears , 10 , 64 ) //年
currentQuarterInt , _ := strconv . ParseInt ( currentQuarter , 10 , 64 ) //季度
currentMonthsInt , _ := strconv . ParseInt ( currentMonths , 10 , 64 ) //月
currentWeekInt , _ := strconv . ParseInt ( currentWeek , 10 , 64 ) //周
if len ( receivedValue . List ) < 1 {
publicmethod . Result ( 1 , receivedValue , c , "未知考核项目!不可进行提交" )
return
}
var errMsg [ ] string
var dimIdList [ ] string
var tarIdList [ ] string
var allZreoConfig [ ] FlowLogAllZreo
for _ , v := range receivedValue . List {
if v . Id == "" {
errMsg = append ( errMsg , "未知考核项目" )
}
var allZreoConfigInfo FlowLogAllZreo
allZreoConfigInfo . Id = v . Id
allZreoConfigInfo . TargetId = v . Target
allZreoConfigInfo . TargetWeight = float64 ( v . TargetWeight )
var qualEvalCont modelskpi . QualitativeEvaluation
err := qualEvalCont . GetCont ( map [ string ] interface { } { "`qe_id`" : v . Id } , "qe_dimension" , "qe_target" )
if err != nil {
errMsg = append ( errMsg , fmt . Sprintf ( "%v未知考核项目!不可进行提交" , v . Targetname ) )
} else {
dimStr := strconv . FormatInt ( qualEvalCont . Dimension , 10 )
if ! publicmethod . IsInTrue [ string ] ( dimStr , dimIdList ) {
dimIdList = append ( dimIdList , dimStr )
}
tarStr := strconv . FormatInt ( qualEvalCont . Target , 10 )
if ! publicmethod . IsInTrue [ string ] ( tarStr , tarIdList ) {
tarIdList = append ( tarIdList , tarStr )
}
switch qualEvalCont . Cycles {
case 5 :
var qualConfig modelskpi . QuantitativeConfig
conWhere := publicmethod . MapOut [ string ] ( )
conWhere [ "`departmentid`" ] = acceptDepartment
conWhere [ "`dimension`" ] = qualEvalCont . Dimension
conWhere [ "`target`" ] = qualEvalCont . Target
conWhere [ "`year`" ] = currentQuarterInt
conWhere [ "`timecopy`" ] = currentMonthsInt
qualConfig . GetCont ( conWhere , "zeroprize" , "allprize" , "capping_val" )
allZreoConfigInfo . Zeroprize = qualConfig . Zeroprize
allZreoConfigInfo . Allprize = qualConfig . Allprize
allZreoConfigInfo . Capping = qualConfig . CappingVal
case 6 :
var qualConfig modelskpi . QuantitativeConfig
conWhere := publicmethod . MapOut [ string ] ( )
conWhere [ "`departmentid`" ] = acceptDepartment
conWhere [ "`dimension`" ] = qualEvalCont . Dimension
conWhere [ "`target`" ] = qualEvalCont . Target
conWhere [ "`year`" ] = currentYearsInt
conWhere [ "`timecopy`" ] = 1
qualConfig . GetCont ( conWhere , "zeroprize" , "allprize" , "capping_val" )
allZreoConfigInfo . Zeroprize = qualConfig . Zeroprize
allZreoConfigInfo . Allprize = qualConfig . Allprize
allZreoConfigInfo . Capping = qualConfig . CappingVal
default :
var qualConfig modelskpi . QuantitativeConfig
conWhere := publicmethod . MapOut [ string ] ( )
conWhere [ "`departmentid`" ] = acceptDepartment
conWhere [ "`dimension`" ] = qualEvalCont . Dimension
conWhere [ "`target`" ] = qualEvalCont . Target
conWhere [ "`year`" ] = currentYearsInt
conWhere [ "`timecopy`" ] = currentMonthsInt
qualConfig . GetCont ( conWhere , "zeroprize" , "allprize" , "capping_val" )
allZreoConfigInfo . Zeroprize = qualConfig . Zeroprize
allZreoConfigInfo . Allprize = qualConfig . Allprize
allZreoConfigInfo . Capping = qualConfig . CappingVal
}
allZreoConfig = append ( allZreoConfig , allZreoConfigInfo )
}
if v . Actual == "" {
errMsg = append ( errMsg , fmt . Sprintf ( "%v未输入实际值" , v . Targetname ) )
}
if v . Addtime == "" {
errMsg = append ( errMsg , fmt . Sprintf ( "%v未输入检查时间" , v . Targetname ) )
}
var waiBuTime publicmethod . DateTimeTotimes
waiBuTime . BaisStrToTime ( v . Addtime )
where := publicmethod . MapOut [ string ] ( )
where [ "fld_year" ] = waiBuTime . Years
where [ "fld_quarter" ] = waiBuTime . Quarter
where [ "fld_month" ] = waiBuTime . Months
where [ "fld_evaluation_id" ] = v . Id
where [ "fl_duty_department" ] = receivedValue . DepartmentId
fmt . Printf ( "where--->%v\n" , where )
var dutyData modelskpi . DutyFlowData
err = dutyData . GetCont ( where , "fld_id" )
if err == nil {
errMsg = append ( errMsg , fmt . Sprintf ( "%v已经提交过!请不要重复提交!" , v . Targetname ) )
}
}
if len ( errMsg ) > 0 {
errMsgStr := strings . Join ( errMsg , ";" )
publicmethod . Result ( 1 , receivedValue , c , errMsgStr )
return
}
uuid := publicmethod . GetUUid ( 6 ) //上报数据唯一识别码
//获取登录人信息
myLoginCont , _ := publicmethod . LoginMyCont ( c )
myUserKey := strconv . FormatInt ( myLoginCont . Key , 10 )
//获取工作流
var workflowInfo currency_recipe . WorkflowEngine
jieguo := workflowInfo . InitWorkflow ( receivedValue . FlowworkId , "" , myUserKey , receivedValue . DepartmentId ) . SendData ( )
//处理工作流
var haveWorkflow workflowengine . OperateWorkflow
haveWorkflow . Step = 1 //操作哪一步
// haveWorkflow.OrderId = uuid //发起表单ID
// haveWorkflow.Attribute = qualEvalCont.Type //属性 1、定性;2、定量
haveWorkflow . OperationStatus = 2 //操作状态
var caoZuoRen workflowengine . ManipulatePeopleInfo
caoZuoRen . Key = strconv . FormatInt ( myLoginCont . Key , 10 ) //操作人
caoZuoRen . OrgId = strconv . FormatInt ( myLoginCont . AdminOrg , 10 ) //操作人行政组织
haveWorkflow . ManipulatePeople = caoZuoRen //操作人相关
haveWorkflow . WorkFlowList = jieguo . NodeContList //流程步进图
flowView := haveWorkflow . ManipulateWorkflow ( ) //处理后的工作流
//审批主体信息
var evalProFlowView modelskpi . EvaluationProcess
evalProFlowView . OrderKey = uuid //发起表单key"`
evalProFlowView . Step = haveWorkflow . Step //当前执行到第几部"`
flowAllJson , _ := json . Marshal ( flowView )
evalProFlowView . Content = string ( flowAllJson ) //流程步进值"`
nextNodeJson , _ := json . Marshal ( haveWorkflow . NextNodeCont )
nextNodeStr := string ( nextNodeJson )
evalProFlowView . NextContent = nextNodeStr //下一步内容"`
evalProFlowView . Time = operationTime //创建时间"`
evalProFlowView . State = 2 //1:起草,2:审批中;3:通过;4:驳回"`
evalProFlowView . RoleGroup = 0 //角色组"`
evalProFlowView . TypeClass = 2 //1、定性;2、定量"`
evalProFlowView . Participants = strings . Join ( haveWorkflow . Participant , "," ) //参与人"`
evalProFlowView . StartTime = operationTime //流程开始时间"`
evalProFlowView . NextStep = haveWorkflow . NextStep //下一步"`
evalProFlowView . NextExecutor = strings . Join ( haveWorkflow . NextNodeContExecutor , "," ) //下一步执行人"`
evalProFlowView . SetupDepartment = myLoginCont . MainDeparment //发起部门"`
evalProFlowView . Dimension = strings . Join ( dimIdList , "," ) //维度"`
evalProFlowView . Target = strings . Join ( tarIdList , "," ) //指标"`
evalProFlowView . AcceptDepartment = acceptDepartment //接受考核部门"`
evalProFlowView . HappenTime = occurrenceTime
flowKyeInt , _ := strconv . ParseInt ( receivedValue . FlowworkId , 10 , 64 )
evalProFlowView . FlowKey = flowKyeInt //流程图唯一识别符
flowVersionInt , _ := strconv . ParseInt ( jieguo . Version , 10 , 64 )
evalProFlowView . FlowVid = flowVersionInt //流程版本"`
evalProFlowView . EpOld = 2
evalProFlowView . Creater = myLoginCont . Key //发起人
evalProFlowView . Clique = myLoginCont . Company //流程归属公司
//定量数据流水值
var planIdList [ ] string
var addFlowDataList [ ] modelskpi . FlowLogData
for _ , v := range receivedValue . List {
var flowDataCont modelskpi . FlowLogData
if ! publicmethod . IsInTrue [ string ] ( v . Id , planIdList ) {
planIdList = append ( planIdList , v . Id )
}
planId , _ := strconv . ParseInt ( v . Id , 10 , 64 )
flowDataCont . EvaluationPlan = planId //考核方案项目ID"`
flowDataCont . Key = uuid //识别标志"`
flowDataCont . Score = publicmethod . StrNumberToInt64 ( v . Actual , 100 ) //数据"`
flowDataCont . Content = v . Reason //描述"`
flowDataCont . Time = operationTime //创建时间"`
flowDataCont . ScoringMethod = v . ScoringMethod
reacVal := publicmethod . StrNumberToInt64 ( v . ReachScore , 100 ) //计分方式(1:自动;2:手动)"`
flowDataCont . ScoringScore = float64 ( reacVal ) //手动分"`
flowDataCont . PlanVersion = v . PlanVersionNumber //版本号"`
flowDataCont . Year = currentYearsInt //年分"`
flowDataCont . Quarter = currentQuarterInt //季度"`
flowDataCont . Month = currentMonthsInt //月"`
flowDataCont . Week = currentWeekInt //周"`
flowDataCont . ToDay = 10 //天"`
tarInt , _ := strconv . ParseInt ( v . Target , 10 , 64 )
flowDataCont . TargetId = tarInt //指标ID"`
addFlowDataList = append ( addFlowDataList , flowDataCont )
}
//定量考核数据表
var workFlowLogCont modelskpi . FlowLog
workFlowLogCont . EvaluationPlan = strings . Join ( planIdList , "," ) //考核方案项目ID"`
// workFlowLogCont.Score = //数据"`
workFlowLogCont . Key = uuid //识别标志"`
// workFlowLogCont.Content = //描述"`
workFlowLogCont . Time = occurrenceTime //创建时间"`
workFlowLogCont . EiteTime = operationTime //修改时间"`
workFlowLogCont . EvaluationDepartment = myLoginCont . MainDeparment //测评部门"`
workFlowLogCont . EvaluationUser = myLoginCont . Key //测评人"`
workFlowLogCont . EvaluationGroup = myLoginCont . Company //测评集团"`
workFlowLogCont . Year = currentYearsInt //年分"`
workFlowLogCont . Quarter = currentQuarterInt //季度"`
workFlowLogCont . Month = currentMonthsInt //月"`
workFlowLogCont . Week = currentWeekInt //周"`
workFlowLogCont . ToDay = 10 //天"`
// workFlowLogCont.Enclosure = //附件"`
_ , companyId , _ , _ , _ := publicmethod . GetOrgStructurees ( acceptDepartment )
workFlowLogCont . DutyGroup = companyId //职责集团"`
workFlowLogCont . DutyDepartment = acceptDepartment //职责部门"`
workFlowLogCont . Reply = 2 //1状态(0:删除;1:起草;2:审批;3:通过)"`
workFlowLogCont . PlanVersion = receivedValue . PlanVersionNumber //版本号"`
baseJson , _ := json . Marshal ( allZreoConfig )
workFlowLogCont . Baseline = string ( baseJson ) //基准线 "`
//审批记录
var stepsTotal int64
overall . CONSTANT_DB_KPI . Model ( & modelskpi . OpenApprovalChangeLog { } ) . Where ( "`orderid` = ?" , uuid ) . Count ( & stepsTotal )
var flowLogCont modelskpi . OpenApprovalChangeLog
flowLogCont . Type = 1 //类型(1:部门;2:岗位)"`
flowLogCont . Title = haveWorkflow . CurrentNode . NodeName //节点名称"`
flowLogCont . Operator = myLoginCont . Key //操作人"`
flowLogCont . OrderId = uuid //订单ID"`
flowLogCont . OperatorTime = operationTime //操作时间"`
flowLogCont . Step = stepsTotal + 1 //操作第几步"`
flowLogCont . OperatorType = haveWorkflow . CurrentNode . State //操作状态(1:位操作;2:已操作)"`
flowLogCont . Msgid = "" //消息id,用于撤回应用消息"`
flowLogCont . ResponseCode = "" //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,24小时内有效,且只能使用一次"`
flowLogCont . Stepper = haveWorkflow . CurrentNode . Step //步进器"`
flowLogCont . ChangeIsTrue = 1 //是否可变更(1:可变更;2:不可变更)"`
flowLogCont . Eiteyime = operationTime //变动时间"`
flowLogCont . YesOrNo = haveWorkflow . CurrentNode . State //未操作;1:同意;2:驳回;3:撤回"`
outPur := publicmethod . MapOut [ string ] ( )
outPur [ "evalProFlowView" ] = evalProFlowView
outPur [ "workFlowLogCont" ] = workFlowLogCont
outPur [ "addFlowDataList" ] = addFlowDataList
outPur [ "flowLogCont" ] = flowLogCont
gormDb := overall . CONSTANT_DB_KPI . Begin ( )
evalProFlowViewErr := gormDb . Create ( & evalProFlowView ) . Error
workFlowLogContErr := gormDb . Create ( & workFlowLogCont ) . Error
addFlowDataListErr := gormDb . Create ( & addFlowDataList ) . Error
flowLogContErr := gormDb . Create ( & flowLogCont ) . Error
var callbackMsg [ ] byte //
var err error
var workwechatErr error
if evalProFlowViewErr == nil && workFlowLogContErr == nil && addFlowDataListErr == nil && flowLogContErr == nil {
addErr := gormDb . Commit ( ) . Error
if addErr == nil {
//下一个节点内容
if nextNodeStr != "" { //判断下个节点是否为空
if len ( haveWorkflow . NextNodeCont . UserList ) > 0 { //判断下个节点是够有审批人
var recipient [ ] string //接收人
var sendWechatUserKey [ ] string
for _ , v := range haveWorkflow . NextNodeCont . UserList { //获取接收人得微信或企业微信Openid用作发送消息的唯一识别码
if ! publicmethod . IsInTrue [ string ] ( v . Id , sendWechatUserKey ) {
sendWechatUserKey = append ( sendWechatUserKey , v . Id )
}
if v . Wechat != "" {
if ! publicmethod . IsInTrue [ string ] ( v . Wechat , recipient ) {
recipient = append ( recipient , v . Wechat )
}
} else {
var userCont modelshr . PersonArchives
userCont . GetCont ( map [ string ] interface { } { "`key`" : v . Id } , "`wechat`" , "`work_wechat`" )
if userCont . Wechat != "" {
if ! publicmethod . IsInTrue [ string ] ( userCont . Wechat , recipient ) {
recipient = append ( recipient , userCont . Wechat )
}
}
if userCont . WorkWechat != "" {
if ! publicmethod . IsInTrue [ string ] ( userCont . WorkWechat , recipient ) {
recipient = append ( recipient , userCont . WorkWechat )
}
}
}
}
if len ( recipient ) > 0 { //判断是否有接收人
//开始组装消息内容
var sendMsg workwechat . SentMiniMessage
sendMsg . ToUser = strings . Join ( recipient , "|" ) //收件人配置
var templateCard workwechat . TemplateCardMsgContMini //模版卡片主体
//头部左标题部分
nodeType := publicmethod . GetSetpNodeName ( haveWorkflow . NextNodeCont . Type )
templateCard . Source . Desc = fmt . Sprintf ( "%v-%v" , haveWorkflow . NextNodeCont . NodeName , nodeType )
//任务id,同一个应用任务id不能重复,只能由数字、字母和“_-@”组成
templateCard . TaskId = fmt . Sprintf ( "kpi_ratify_%v" , uuid )
templateCard . ActionMenu . Desc = "恒信高科"
var rightHand workwechat . ActionListCont
rightHand . Text = "恒信高科"
rightHand . Key = fmt . Sprintf ( "kpi_head_%v" , publicmethod . GetUUid ( 7 ) )
templateCard . ActionMenu . ActionList = append ( templateCard . ActionMenu . ActionList , rightHand )
//主内容框
templateCard . MainTitle . Title = fmt . Sprintf ( "考核周期:%v" , publicmethod . UnixTimeToDay ( occurrenceTime , 15 ) )
//引用文献样式
var yinYongWenXian [ ] string
for _ , v := range receivedValue . List {
if v . ScoringMethod == 1 {
yinYongWenXian = append ( yinYongWenXian , fmt . Sprintf ( "指标:%v\n实际值:%v\n达成率:%v\n得分:%v" , v . Targetname , v . Actual , v . Reach , v . ReachScore ) )
} else {
var lsZeroprize float64
var lsAllprize float64
var lsCapping float64
for _ , cv := range allZreoConfig {
if cv . TargetId == v . Target {
lsZeroprize = cv . Zeroprize
lsAllprize = cv . Allprize
lsCapping = cv . Capping
}
}
actualInt , _ := strconv . ParseInt ( v . Actual , 10 , 64 )
scoreVal , _ , _ , _ , _ := publicmethod . CalculateScore ( v . TargetWeight , float64 ( actualInt ) * 100 , lsAllprize , lsZeroprize , lsCapping , 2 )
yinYongWenXian = append ( yinYongWenXian , fmt . Sprintf ( "指标:%v\n实际值:%v\n达成率:%v\n得分:%v\n手动分:%v\n原因:%v" , v . Targetname , v . Actual , v . Reach , scoreVal , v . ReachScore , v . Reason ) )
}
}
fmt . Printf ( "sendMsg->%v\ntemplateCard->%v\nyinYongWenXian->%v\n" , sendMsg , templateCard , yinYongWenXian )
templateCard . QuoteArea . QuoteText = strings . Join ( yinYongWenXian , "\n" )
//二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
var userRecarCont modelshr . PersonArchives
userRecarCont . GetCont ( map [ string ] interface { } { "`key`" : myLoginCont . Key } , "`wechat`" , "`work_wechat`" , "`maindeparment`" )
recipientWechat := userRecarCont . Wechat
if userRecarCont . WorkWechat != "" {
recipientWechat = userRecarCont . WorkWechat
}
var orgContInfo modelshr . AdministrativeOrganization
orgContInfo . GetCont ( map [ string ] interface { } { "`id`" : userRecarCont . MainDeparment } , "name" )
var hcListCont1 workwechat . HorizontalContentListCont
hcListCont1 . Type = 0
hcListCont1 . Keyname = "提报部门:"
hcListCont1 . Value = orgContInfo . Name
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont1 )
var hcListCont3 workwechat . HorizontalContentListCont
hcListCont3 . Keyname = "提报人:"
hcListCont3 . Value = fmt . Sprintf ( "%v(%v)" , myLoginCont . Name , myLoginCont . Number )
if recipientWechat != "" {
hcListCont3 . Type = 3
hcListCont3 . UserId = recipientWechat
} else {
hcListCont3 . Type = 0
}
templateCard . HorizontalContentList = append ( templateCard . HorizontalContentList , hcListCont3 )
//审批详情访问地址
jumpUrl := fmt . Sprintf ( "%v/#/pages/approval/departworkflowcont?id=%v" , overall . CONSTANT_CONFIG . Appsetup . WebUrl , evalProFlowView . Id )
//跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
var jmpCont1 workwechat . JumpListCont
jmpCont1 . Type = 1
jmpCont1 . Title = "前往处理"
jmpCont1 . Url = jumpUrl
templateCard . JumpList = append ( templateCard . JumpList , jmpCont1 )
//整体卡片的点击跳转事件,text_notice必填本字段
templateCard . CardAction . Url = jumpUrl
sendMsg . TemplateCard = templateCard
callbackMsg , err = sendMsg . InitMes ( ) . SendMessage ( )
workwechatErr = workwechat . WriteUpdateWechatTempmsg ( callbackMsg , sendMsg , 1 , uuid , sendWechatUserKey )
var callbackCont publicmethod . WechatCallBack
json . Unmarshal ( callbackMsg , & callbackCont )
}
}
}
outErr := publicmethod . MapOut [ string ] ( )
outErr [ "addErr" ] = addErr
outErr [ "err" ] = err
outErr [ "workwechatErr" ] = workwechatErr
outErr [ "callbackMsg" ] = string ( callbackMsg )
publicmethod . Result ( 0 , outErr , c )
} else {
addErr := gormDb . Rollback ( ) . Error
publicmethod . Result ( 104 , addErr , c )
}
} else {
outErr := publicmethod . MapOut [ string ] ( )
addErr := gormDb . Rollback ( ) . Error
outErr [ "evalProFlowViewErr" ] = evalProFlowViewErr
outErr [ "workFlowLogContErr" ] = workFlowLogContErr
outErr [ "addFlowDataListErr" ] = addFlowDataListErr
outErr [ "flowLogContErr" ] = flowLogContErr
outErr [ "addErr" ] = addErr
publicmethod . Result ( 1014 , outErr , c )
}
// publicmethod.Result(0, outPur, c)
}