KPI绩效考核系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
14 KiB

package flowchart
import (
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelskpi"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
// 生成审批流程流
func (a *ApiMethod) ReviewWorkFlow(c *gin.Context) {
//获取登录人信息
context, err := publicmethod.LoginMyCont(c)
if err != nil {
publicmethod.Result(1, err, c, "未知身份!不可操作!")
return
}
var receivedValue ReviewFlow
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "参数错误!")
return
}
if receivedValue.IsCorrection == 0 {
receivedValue.IsCorrection = 2
}
if len(receivedValue.PeopleList) < 1 {
publicmethod.Result(1, receivedValue, c, "未知被考核人!请指定!")
return
}
//获取考核项性质
var qualEvalScheme modelskpi.QualitativeEvaluationScheme
err = qualEvalScheme.GetCont(map[string]interface{}{"id": receivedValue.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
//抄送人
var sendCopyMan []publicmethod.UserListFlowAll
//流程图
var flowMap []publicmethod.FlowChartList
endStep := 3
//第一步:创建
var begin publicmethod.FlowChartList
begin.Step = 1 //步伐
begin.NodeName = publicmethod.GetSetpName(1) //节点名称
begin.State = 2 //状态 1、不点亮;2、点亮
begin.Class = 1 //节点类型 1、普通节点;2、运行中指定节点
begin.RunType = 1
beginUserList := append(begin.UserList, GetApproveUser(context.Wechat, context.WorkWechat))
for _, bv := range beginUserList {
begin.UserList = append(begin.UserList, bv)
if receivedValue.IsCorrection == 1 {
sendCopyMan = append(sendCopyMan, bv)
}
}
flowMap = append(flowMap, begin)
//第二步:本部门负责人审批
var stepTwo publicmethod.FlowChartList
stepTwo.Step = 2 //步伐
stepTwo.NodeName = publicmethod.GetSetpName(2) //节点名称
stepTwo.State = 1 //状态 1、不点亮;2、点亮
stepTwo.Class = 1 //节点类型 1、普通节点;2、运行中指定节点
if receivedValue.IsCorrection != 1 {
stepTwo.RunType = 2
} else {
stepTwo.RunType = 3
}
//获取审批人weChatOpenID
sendUserList, userErr := publicmethod.GetRefereeTeamWorkWechat(16182159043990656, context.MainDeparment)
if userErr == nil {
for iu := 0; iu < len(sendUserList); iu++ {
departListUser := GetApproveUser(sendUserList[iu], sendUserList[iu])
stepTwo.UserList = append(stepTwo.UserList, departListUser)
if receivedValue.IsCorrection != 1 {
sendCopyMan = append(sendCopyMan, departListUser)
}
}
}
flowMap = append(flowMap, stepTwo)
if qualEvalScheme.Attribute == 1 {
//定性
if receivedValue.IsCorrection != 1 {
//整改措施提交人
var stepThree publicmethod.FlowChartList
stepThree.Step = 3 //步伐
stepThree.NodeName = publicmethod.GetSetpName(4) //节点名称
stepThree.State = 1 //状态 1、不点亮;2、点亮
stepThree.Class = 2 //节点类型 1、普通节点;2、运行中指定节点
stepThree.RunType = 2
//主要责任人负责提交整改措施
if len(receivedValue.PeopleList) > 0 {
for ipv := 0; ipv < len(receivedValue.PeopleList); ipv++ {
var myUsCont modelshr.PersonArchives
meErr := myUsCont.GetCont(map[string]interface{}{"`key": receivedValue.PeopleList[ipv]}, "`wechat`", "`work_wechat`")
if meErr == nil {
appManList := GetApproveUser(myUsCont.Wechat, myUsCont.WorkWechat)
stepThree.UserList = append(stepThree.UserList, appManList)
sendCopyMan = append(sendCopyMan, appManList)
}
}
}
flowMap = append(flowMap, stepThree)
//发起人验收
var stepFour publicmethod.FlowChartList
stepFour.Step = 4
stepFour.NodeName = publicmethod.GetSetpName(5)
stepFour.State = 1
stepFour.Class = 1
stepFour.RunType = 2
stepFour.UserList = append(stepFour.UserList, GetApproveUser(context.Wechat, context.WorkWechat))
flowMap = append(flowMap, stepFour)
endStep = 5
} else {
if len(receivedValue.PeopleList) > 0 {
for ipv := 0; ipv < len(receivedValue.PeopleList); ipv++ {
var myUsCont modelshr.PersonArchives
meErr := myUsCont.GetCont(map[string]interface{}{"`key": receivedValue.PeopleList[ipv]}, "`wechat`", "`work_wechat`")
if meErr == nil {
appManList := GetApproveUser(myUsCont.Wechat, myUsCont.WorkWechat)
sendCopyMan = append(sendCopyMan, appManList)
}
}
}
}
}
//抄送
var stepCopy publicmethod.FlowChartList
stepCopy.Step = endStep
stepCopy.NodeName = publicmethod.GetSetpName(6)
stepCopy.State = 1
stepCopy.Class = 1
stepCopy.RunType = 3
stepCopy.UserList = sendCopyMan
flowMap = append(flowMap, stepCopy)
publicmethod.Result(0, flowMap, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-10-01 09:50:09
@ 功能: 获取人员信息
@ 参数
#wechat 微信Openid
#workWechat 企业微信ID
@ 返回值
#userCont 人员信息
*/
func GetApproveUser(wechat, workWechat string) (userCont publicmethod.UserListFlowAll) {
openId := wechat
if workWechat != "" {
openId = workWechat
}
var myCont modelshr.PersonArchives
err := overall.CONSTANT_DB_HR.Where("`wechat` = ? OR `work_wechat` = ?", openId, openId).First(&myCont).Error
if err == nil {
userCont.Id = strconv.FormatInt(myCont.Key, 10) //操作人ID
userCont.Name = myCont.Name //操作人姓名
userCont.Icon = myCont.Icon //操作人头像
userCont.Wechat = wechat //微信Openid
if workWechat != "" {
userCont.Wechat = workWechat
}
userCont.Company = myCont.Company //集团公司
if myCont.Company != 0 {
var companyCont modelshr.AdministrativeOrganization
companyCont.GetCont(map[string]interface{}{"`id`": myCont.Company}, "`name`")
userCont.CompanyName = companyCont.Name //分厂名称
}
userCont.DepartmentId = myCont.MainDeparment //分厂Id
if myCont.MainDeparment != 0 {
var departmentCont modelshr.AdministrativeOrganization
departmentCont.GetCont(map[string]interface{}{"`id`": myCont.MainDeparment}, "`name`")
userCont.DepartmentName = departmentCont.Name //分厂名称
}
userCont.WorkshopId = myCont.AdminOrg //工段Id
if myCont.AdminOrg != 0 {
var adminOrgCont modelshr.AdministrativeOrganization
adminOrgCont.GetCont(map[string]interface{}{"`id`": myCont.AdminOrg}, "`name`")
userCont.WorkshopName = adminOrgCont.Name //工段名称
}
userCont.PostId = myCont.JobId //职务Id
if myCont.JobId != 0 {
var dutiesCont modelshr.Duties
dutiesCont.GetCont(map[string]interface{}{"`id`": myCont.JobId}, "`name`")
userCont.PostName = dutiesCont.Name //职务名称
}
userCont.Tema = myCont.TeamId //班组Id
if myCont.TeamId != 0 {
var teamCont modelshr.TeamGroup
teamCont.GetCont(map[string]interface{}{"`id`": myCont.TeamId}, "`name`")
userCont.TemaName = teamCont.Name //班组名称
}
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2022-10-01 15:11:56
@ 功能: 创建流程图
@ 参数
#founderWechat 发起人微信或企业微信Openid
#founderDepartment 发起人部门
#reviewFlowParameter 创建流程参数
#isAdd 1创建2其他
@ 返回值
#flowMap 工作流
#err 系统信息
*/
func SetUpWorkFlow(founderWechat string, founderDepartment int64, reviewFlowParameter ReviewFlow, isAdd int) (flowMap []publicmethod.FlowChartList, err error) {
if reviewFlowParameter.IsCorrection == 0 {
reviewFlowParameter.IsCorrection = 2
}
if len(reviewFlowParameter.PeopleList) < 1 {
return
}
//获取考核项性质
var qualEvalScheme modelskpi.QualitativeEvaluationScheme
err = qualEvalScheme.GetCont(map[string]interface{}{"id": reviewFlowParameter.Id})
if err != nil {
return
}
//抄送人
var sendCopyMan []publicmethod.UserListFlowAll
var isTureCopyMan []string
//流程图
// var flowMap []publicmethod.FlowChartList
endStep := 1
//第一步:创建
var begin publicmethod.FlowChartList
begin.Step = endStep //步伐
begin.NodeName = publicmethod.GetSetpName(1) //节点名称
begin.State = 2 //状态 1、不点亮;2、点亮
begin.Class = 1 //节点类型 1、普通节点;2、运行中指定节点
begin.RunType = 1 //运行状态(1:开始;2:操作点;3:结束;4:抄送)
beginUserList := append(begin.UserList, GetApproveUser(founderWechat, founderWechat))
for _, bv := range beginUserList {
if isAdd == 1 {
var setLogList publicmethod.LogList
setLogList.State = 2
setLogList.TimeVal = publicmethod.UnixTimeToDay(time.Now().Unix(), 1)
bv.LogList = append(bv.LogList, setLogList)
}
begin.UserList = append(begin.UserList, bv)
if reviewFlowParameter.IsCorrection == 1 {
sendCopyMan = append(sendCopyMan, bv)
isTureCopyMan = append(isTureCopyMan, bv.Id)
}
}
var oenStep publicmethod.NodeRelationshipStruct
oenStep.FromNode = 0
oenStep.ToNode = 2
oenStep.RejectNode = 0
begin.NodeRelationship = oenStep
flowMap = append(flowMap, begin)
//第二步:本部门负责人审批
endStep = endStep + 1
var stepTwo publicmethod.FlowChartList
stepTwo.Step = endStep //步伐
stepTwo.NodeName = publicmethod.GetSetpName(2) //节点名称
stepTwo.State = 1 //状态 1、不点亮;2、点亮
stepTwo.Class = 1 //节点类型 1、普通节点;2、运行中指定节点
if reviewFlowParameter.IsCorrection == 1 {
stepTwo.RunType = 3
} else {
stepTwo.RunType = 2
}
//获取审批人weChatOpenID
sendUserList, userErr := publicmethod.GetRefereeTeamWorkWechat(16182159043990656, founderDepartment)
if userErr == nil {
for iu := 0; iu < len(sendUserList); iu++ {
departListUser := GetApproveUser(sendUserList[iu], sendUserList[iu])
stepTwo.UserList = append(stepTwo.UserList, departListUser)
if reviewFlowParameter.IsCorrection != 1 {
if publicmethod.IsInTrue[string](departListUser.Id, isTureCopyMan) == false {
sendCopyMan = append(sendCopyMan, departListUser)
isTureCopyMan = append(isTureCopyMan, departListUser.Id)
}
}
}
}
var twoFlowStep publicmethod.NodeRelationshipStruct
twoFlowStep.FromNode = endStep - 1
twoFlowStep.ToNode = endStep + 1
twoFlowStep.RejectNode = 1
stepTwo.NodeRelationship = twoFlowStep
flowMap = append(flowMap, stepTwo)
if qualEvalScheme.Attribute == 1 {
//定性
if reviewFlowParameter.IsCorrection != 1 {
//整改措施提交人
endStep = endStep + 1
var stepThree publicmethod.FlowChartList
stepThree.Step = endStep //步伐
stepThree.NodeName = publicmethod.GetSetpName(4) //节点名称
stepThree.State = 1 //状态 1、不点亮;2、点亮
stepThree.Class = 2 //节点类型 1、普通节点;2、运行中指定节点
stepThree.RunType = 2
//主要责任人负责提交整改措施
if len(reviewFlowParameter.PeopleList) > 0 {
for ipv := 0; ipv < len(reviewFlowParameter.PeopleList); ipv++ {
var myUsCont modelshr.PersonArchives
meErr := myUsCont.GetCont(map[string]interface{}{"`key": reviewFlowParameter.PeopleList[ipv]}, "`wechat`", "`work_wechat`")
if meErr == nil {
appManList := GetApproveUser(myUsCont.Wechat, myUsCont.WorkWechat)
stepThree.UserList = append(stepThree.UserList, appManList)
if publicmethod.IsInTrue[string](appManList.Id, isTureCopyMan) == false {
isTureCopyMan = append(isTureCopyMan, appManList.Id)
sendCopyMan = append(sendCopyMan, appManList)
}
}
}
}
var threeStep publicmethod.NodeRelationshipStruct
threeStep.FromNode = endStep - 1
threeStep.ToNode = endStep + 1
threeStep.RejectNode = 1
stepThree.NodeRelationship = threeStep
flowMap = append(flowMap, stepThree)
//发起人验收
endStep = endStep + 1
var stepFour publicmethod.FlowChartList
stepFour.Step = endStep
stepFour.NodeName = publicmethod.GetSetpName(5)
stepFour.State = 1
stepFour.Class = 1
stepFour.RunType = 3
stepFour.UserList = append(stepFour.UserList, GetApproveUser(founderWechat, founderWechat))
var fourStep publicmethod.NodeRelationshipStruct
fourStep.FromNode = endStep - 1
fourStep.ToNode = endStep + 1
fourStep.RejectNode = endStep - 1
stepFour.NodeRelationship = fourStep
flowMap = append(flowMap, stepFour)
// endStep = 5
} else {
if len(reviewFlowParameter.PeopleList) > 0 {
for ipv := 0; ipv < len(reviewFlowParameter.PeopleList); ipv++ {
var myUsCont modelshr.PersonArchives
meErr := myUsCont.GetCont(map[string]interface{}{"`key": reviewFlowParameter.PeopleList[ipv]}, "`wechat`", "`work_wechat`")
if meErr == nil {
appManList := GetApproveUser(myUsCont.Wechat, myUsCont.WorkWechat)
if publicmethod.IsInTrue[string](appManList.Id, isTureCopyMan) == false {
isTureCopyMan = append(isTureCopyMan, appManList.Id)
sendCopyMan = append(sendCopyMan, appManList)
}
}
}
}
}
}
//抄送
endStep = endStep + 1
var stepCopy publicmethod.FlowChartList
stepCopy.Step = endStep
stepCopy.NodeName = publicmethod.GetSetpName(6)
stepCopy.State = 1
stepCopy.Class = 3
stepCopy.UserList = sendCopyMan
stepCopy.RunType = 4
var endFlowStep publicmethod.NodeRelationshipStruct
endFlowStep.FromNode = endStep - 1
endFlowStep.ToNode = 0
endFlowStep.RejectNode = 0
stepCopy.NodeRelationship = endFlowStep
flowMap = append(flowMap, stepCopy)
return
}
/*
*
@ 作者: 秦东
@ 时间: 2022-10-15 08:46:33
@ 功能: 获取节点操作人列表
@ 参数
#flowMap 流程结构体
#step 第几步
@ 返回值
#userKey 操作人key
#UserList 操作人列表
*/
func GetNodeOperator(flowMap []publicmethod.FlowChartList, step int) (userKey []string, UserList []publicmethod.UserListFlowAll) {
for _, v := range flowMap {
if v.Step == step {
UserList = v.UserList
if step > 0 {
for _, uv := range v.UserList {
if publicmethod.IsInTrue[string](uv.Id, userKey) == false {
userKey = append(userKey, uv.Id)
}
}
}
}
}
return
}