package evaluation
import (
"encoding/json"
"fmt"
"strconv"
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/gin-gonic/gin"
)
//查看定量考核目标设定
func ( e * EvaluationInterface ) LookQuantitativeConfig ( c * gin . Context ) {
var requestData SelectQuantitativeConfig
err := c . ShouldBindJSON ( & requestData )
if err != nil {
response . Result ( 101 , err , "数据获取失败!" , c )
return
}
var qualConfigList [ ] assessmentmodel . QuantitativeConfig
gormDb := global . GVA_DB_Performanceappraisal
if requestData . GroupId != "" {
gormDb = gormDb . Where ( "`group` = ?" , requestData . GroupId )
}
if requestData . DepartmentID != "" {
gormDb = gormDb . Where ( "`departmentid` = ?" , requestData . DepartmentID )
}
if requestData . Dimension != "" {
gormDb = gormDb . Where ( "`dimension` = ?" , requestData . Dimension )
}
if requestData . Target != "" {
gormDb = gormDb . Where ( "`target` = ?" , requestData . Target )
}
if requestData . DetailedTarget != "" {
gormDb = gormDb . Where ( "`targetconfig` = ?" , requestData . DetailedTarget )
}
switch requestData . Type {
case 1 :
gormDb = gormDb . Where ( "`type` = ?" , requestData . Type )
case 2 :
gormDb = gormDb . Where ( "`type` = ?" , requestData . Type )
if requestData . Class != 0 {
gormDb = gormDb . Where ( "`timecopy` = ?" , requestData . Class )
}
case 3 :
gormDb = gormDb . Where ( "`type` = ?" , requestData . Type )
if requestData . Class != 0 {
gormDb = gormDb . Where ( "`timecopy` = ?" , requestData . Class )
}
default :
}
if requestData . Year != 0 {
gormDb = gormDb . Where ( "`year` = ?" , requestData . Year )
}
if requestData . State != 0 {
gormDb = gormDb . Where ( "`state` = ?" , requestData . State )
}
// gormDb = gormDb.Order("group ASC,departmentid ASC,dimension ASC,target ASC,targetconfig ASC").Order("year DESC").Order("timecopy ASC,id ASC")
gormDb = gormDb . Order ( "`group` ASC" ) . Order ( "`departmentid` ASC" ) . Order ( "`dimension` ASC" ) . Order ( "`target` ASC" ) . Order ( "`targetconfig` ASC" ) . Order ( "`year` DESC" ) . Order ( "`timecopy` ASC" ) . Order ( "`id` ASC" )
contErr := gormDb . Find ( & qualConfigList ) . Error
if contErr != nil {
response . Result ( 102 , err , "没有数据!" , c )
return
}
var outList [ ] OutQuantitativeConfig
for _ , v := range qualConfigList {
var outCont OutQuantitativeConfig
outCont . Id = v . Id
outCont . DepartmentId = v . DepartmentId
outCont . Group = v . Group
outCont . Dimension = v . Dimension
outCont . Target = v . Target
outCont . TargetConfig = v . TargetConfig
outCont . Type = v . Type
outCont . Year = v . Year
outCont . Timecopy = v . Timecopy
outCont . Zeroprize = v . Zeroprize / 100
outCont . Allprize = v . Allprize / 100
outCont . Time = v . Time
outCont . State = v . State
where := commonus . MapOut ( )
where [ "id" ] = v . Group
orgCont , _ := commonus . GetNewOrgCont ( where , "id" , "name" )
outCont . GroupTitle = orgCont . Name
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = v . DepartmentId
orgContDepart , _ := commonus . GetNewOrgCont ( whereDepart , "id" , "name" )
outCont . DimensionTitle = orgContDepart . Name
// gErr, groupInfo := commonus.GetGroupCont(v.Group)
// if gErr == true {
// outCont.GroupTitle = groupInfo.Name
// }
// dErr, departmentInfo := commonus.GetBranchFactory(v.DepartmentId)
// if dErr == true {
// outCont.DimensionTitle = departmentInfo.Name
// }
targetInfo , tErr := commonus . GetTargetInfo ( v . Target )
if tErr == true {
outCont . TargetTitle = targetInfo . Title
}
dtargetInfo , dtErr := commonus . GetDetailedTargetInfo ( v . TargetConfig )
if dtErr == true {
outCont . DetailedTargetTitle = dtargetInfo . Title
}
outList = append ( outList , outCont )
}
response . Result ( 0 , outList , "获取成功!" , c )
}
//查看审批流程
func ( e * EvaluationInterface ) SeeFlowLog ( c * gin . Context ) {
isTrue , userCont := commonus . ClientIdentity ( )
if isTrue != true {
response . Result ( 1001 , userCont , "您的身份令牌已经失效!请重新登录获取身份令牌!" , c )
return
}
var requestData FlowLogType
c . ShouldBindJSON ( & requestData )
if requestData . PageSize == 0 {
requestData . PageSize = 20
}
if requestData . Page <= 0 {
requestData . Page = 1
}
offSetPage := commonus . CalculatePages ( requestData . Page , requestData . PageSize )
// var evalProContList []assessmentmodel.EvaluationProcess
var evalProContList [ ] accPerFlowLog
gormDb := global . GVA_DB_Performanceappraisal . Model ( & assessmentmodel . EvaluationProcess { } )
gormDb = gormDb . Select ( "evaluation_process.*,sf.sf_duty_department,sf.sf_evaluation_plan,fl.fl_evaluation_id,fl.fl_evaluation_department,qe.qe_dimension,qe.qe_target,qe.qe_detailed_target,dc.title,et.et_title,dt.dt_title" )
gormDb = gormDb . Joins ( ( "left join score_flow as sf on sf.sf_key = evaluation_process.ep_order_key" ) )
gormDb = gormDb . Joins ( ( "left join flow_log as fl on fl.fl_key = evaluation_process.ep_order_key" ) )
gormDb = gormDb . Joins ( ( "left join qualitative_evaluation as qe on qe.qe_id = sf.sf_evaluation_plan OR qe.qe_id = fl.fl_evaluation_id" ) )
gormDb = gormDb . Joins ( ( "left join dutyclass as dc on dc.id = qe.qe_dimension" ) )
gormDb = gormDb . Joins ( ( "left join evaluationtarget as et on et.et_id = qe.qe_target" ) )
gormDb = gormDb . Joins ( ( "left join detailed_target as dt on dt.dt_id = qe.qe_detailed_target" ) )
if requestData . Title != "" || requestData . Department != "" {
if requestData . Title != "" {
gormDb = gormDb . Where ( "dc.title LIKE ? OR et.et_title LIKE ? OR dt.dt_title LIKE ?" , "%" + requestData . Title + "%" , "%" + requestData . Title + "%" , "%" + requestData . Title + "%" )
}
if requestData . Department != "" {
gormDb = gormDb . Where ( "sf.sf_duty_department = ? OR fl.fl_evaluation_department = ?" , requestData . Department , requestData . Department )
}
}
gormDb = gormDb . Where ( "FIND_IN_SET(?,`ep_participants`)" , userCont . Key )
if requestData . State != 0 {
gormDb = gormDb . Where ( "evaluation_process.ep_state = ?" , requestData . State )
} else {
gormDb = gormDb . Where ( "evaluation_process.ep_state IN ?" , [ ] int { 1 , 2 , 3 } )
}
if requestData . Time != "" {
startTime , endTime := commonus . GetAppointMonthStarAndEndTime ( requestData . Time )
gormDb = gormDb . Where ( "evaluation_process.ep_start_time BETWEEN ? AND ?" , startTime , endTime )
}
/ *
获取总共有多少记录
* /
var total int64
totalErr := gormDb . Count ( & total ) . Error
if totalErr != nil {
total = 0
}
//获取记录数据
evaErr := gormDb . Order ( "ep_id ASC" ) . Limit ( requestData . PageSize ) . Offset ( offSetPage ) . Find ( & evalProContList ) . Error
if evaErr != nil {
response . Result ( 104 , evaErr , "数据获取失败!" , c )
return
}
// response.Result(104, evalProContList, "数据获取失败!", c)
// return
var flowLogListOut [ ] FlowLogListOut
for _ , v := range evalProContList {
var flowLogListCont FlowLogListOut
orderId := strconv . FormatInt ( v . OrderKey , 10 )
flowLogListCont . OutId = orderId
flowLogListCont . Class = v . TypeClass
flowLogListCont . MonthDays = commonus . TimeStampToDate ( v . StartTime , 15 )
if v . TypeClass == 1 {
//获取考核项目关联项目
targettitle , detailedRulesTitle , _ , _ , scoreFlowCont , qualEvalInfo , dutyTarDetErr := commonus . GetDutyAssociatedItems ( orderId )
if dutyTarDetErr == true {
addUser , addUserErr := commonus . GetWorkUser ( strconv . FormatInt ( scoreFlowCont . EvaluationUser , 10 ) )
if addUserErr == true {
flowLogListCont . FounDer = addUser . Name
}
var departTitleName string
flowLogListCont . Cycles = qualEvalInfo . Cycles
flowLogListCont . CycleAttres = qualEvalInfo . CycleAttres
if qualEvalInfo . AcceptEvaluation != 0 {
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = qualEvalInfo . AcceptEvaluation
orgContDer , orgContDerErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgContDerErr == nil {
if departTitleName == "" {
departTitleName = orgContDer . Name
} else {
departTitleName = fmt . Sprintf ( "%v、%v" , departTitleName , orgContDer . Name )
}
flowLogListCont . ExecutiveDepartment = append ( flowLogListCont . ExecutiveDepartment , orgContDer . Name )
}
}
if detailedRulesTitle != "" {
flowLogListCont . Title = fmt . Sprintf ( "%v %v" , departTitleName , detailedRulesTitle )
} else {
flowLogListCont . Title = fmt . Sprintf ( "%v %v" , departTitleName , targettitle )
}
flowLogListCont . Year = scoreFlowCont . Year //`json:"year"` //年分"`
flowLogListCont . Quarter = scoreFlowCont . Quarter //`json:"quarter"` //季度"`
flowLogListCont . Month = scoreFlowCont . Month //`json:"month"` //月"`
flowLogListCont . Week = scoreFlowCont . Week //`json:"week"` //周"`
flowLogListCont . Days = commonus . ComputingTime ( scoreFlowCont . HappenTime , 5 ) //`json:"days"` //天
}
} else {
flowLogInfo , flowLogErr := commonus . GetFlowLog ( orderId )
if flowLogErr == true {
flowLogListCont . Year = flowLogInfo . Year //`json:"year"` //年分"`
flowLogListCont . Quarter = flowLogInfo . Quarter //`json:"quarter"` //季度"`
flowLogListCont . Month = flowLogInfo . Month //`json:"month"` //月"`
flowLogListCont . Week = flowLogInfo . Week //`json:"week"` //周"`
flowLogListCont . Days = flowLogInfo . ToDay //`json:"days"` //天
// fmt.Printf("Title---1-->%v\n", flowLogErr)
var qualEvalInfo assessmentmodel . QualitativeEvaluation
qualEvaTargetErr := qualEvalInfo . GetCont ( map [ string ] interface { } { "qe_id" : flowLogInfo . EvaluationPlan } , "qe_target" , "qe_cycle" , "qe_cycleattr" , "qe_accept_evaluation" )
// fmt.Printf("Title---2-->%v\n", qualEvaTargetErr)
if qualEvaTargetErr == nil {
flowLogListCont . Cycles = qualEvalInfo . Cycles
flowLogListCont . CycleAttres = qualEvalInfo . CycleAttres
var departTitleName string
if qualEvalInfo . AcceptEvaluation != 0 {
whereDepart := commonus . MapOut ( )
whereDepart [ "id" ] = qualEvalInfo . AcceptEvaluation
orgContDer , orgContDerErr := commonus . GetNewOrgCont ( whereDepart , "name" )
if orgContDerErr == nil {
if departTitleName == "" {
departTitleName = orgContDer . Name
} else {
departTitleName = fmt . Sprintf ( "%v、%v" , departTitleName , orgContDer . Name )
}
flowLogListCont . ExecutiveDepartment = append ( flowLogListCont . ExecutiveDepartment , orgContDer . Name )
}
}
var targetInfo assessmentmodel . EvaluationTarget
targetInfoErr := targetInfo . GetCont ( map [ string ] interface { } { "et_id" : qualEvalInfo . Target } , "et_title" )
// fmt.Printf("Title---3-->%v\n", targetInfoErr)
if targetInfoErr == nil {
flowLogListCont . Title = fmt . Sprintf ( "%v %v" , departTitleName , targetInfo . Title )
// flowLogListCont.Title = fmt.Sprintf("%v %v-%v-%v数据上报", targetInfo.Title, flowLogInfo.Year, flowLogInfo.Month, flowLogInfo.ToDay)
} else {
// flowLogListCont.Title = fmt.Sprintf("%v-%v-%v数据上报", flowLogInfo.Year, flowLogInfo.Month, flowLogInfo.ToDay)
flowLogListCont . Title = fmt . Sprintf ( "%v" , departTitleName )
}
} else {
flowLogListCont . Title = fmt . Sprintf ( "%v-%v-%v数据上报" , flowLogInfo . Year , flowLogInfo . Month , flowLogInfo . ToDay )
}
addUser , addUserErr := commonus . GetWorkUser ( strconv . FormatInt ( flowLogInfo . EvaluationUser , 10 ) )
if addUserErr == true {
flowLogListCont . FounDer = addUser . Name
}
}
}
//解析审批流
var flowLog [ ] FlowStep
jsonFlowErr := json . Unmarshal ( [ ] byte ( v . Content ) , & flowLog )
setpLen := len ( flowLog )
if jsonFlowErr == nil {
//得到当前步进值
currentSetp := setpLen - 1
if currentSetp < 0 {
currentSetp = 0
}
flowLogListCont . Node = flowLog [ currentSetp ] . StepName
addUser , addUserErr := commonus . GetWorkUser ( flowLog [ currentSetp ] . ClickName )
if addUserErr == true {
flowLogListCont . CurrentPeo = addUser . Name
}
}
switch v . State {
case 2 :
flowLogListCont . Result = "审批通过"
flowLogListCont . Condition = "已结束"
case 3 :
flowLogListCont . Result = "驳回"
flowLogListCont . Condition = "审批中"
default :
flowLogListCont . Result = "审批中"
flowLogListCont . Condition = "审批中"
}
flowLogListOut = append ( flowLogListOut , flowLogListCont )
}
countSum := len ( flowLogListOut )
printData := commonus . OutPutList ( total , int64 ( countSum ) , requestData . Page , requestData . PageSize , flowLogListOut )
response . Result ( 0 , printData , "查询成功!" , c )
}