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.
440 lines
18 KiB
440 lines
18 KiB
package postweb
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"key_performance_indicators/api/version1/flowchart"
|
|
"key_performance_indicators/middleware/wechatapp/wechatsendmsg"
|
|
"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"
|
|
)
|
|
|
|
//定量考核相关操作
|
|
|
|
// 获取定量考核详细内容
|
|
func (a *ApiMethod) GetRationTargetCont(c *gin.Context) {
|
|
var receivedValue publicmethod.PublicId
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if receivedValue.Id == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
currentTime := time.Now().Unix()
|
|
|
|
var schemeCont modelskpi.QualitativeEvaluationScheme
|
|
err = schemeCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var sendData sendPostTargetRationCont
|
|
sendData.Id = receivedValue.Id
|
|
//获取指标信息
|
|
var targerCont modelskpi.PostTarget
|
|
targerCont.GetCont(map[string]interface{}{"`id`": schemeCont.TargetId})
|
|
sendData.Name = targerCont.Title
|
|
sendData.Content = schemeCont.Content
|
|
yearVal := publicmethod.ComputingTime(currentTime, 1)
|
|
timecopy := publicmethod.ComputingTime(currentTime, 3) //月"`
|
|
switch targerCont.Cycle {
|
|
case 5:
|
|
timecopy = publicmethod.ComputingTime(currentTime, 2) //季度"`
|
|
case 6:
|
|
timecopy = 1
|
|
default:
|
|
timecopy = publicmethod.ComputingTime(currentTime, 3) //月"`
|
|
}
|
|
//获取指标的全奖、零奖、封顶值
|
|
sendData.Allprize, sendData.Zeroprize, sendData.Capping = GetPostTagetRewardSeting(schemeCont.CompanyId, schemeCont.OrgId, schemeCont.PostId, schemeCont.DimensionId, schemeCont.TargetId, schemeCont.DetailsId, yearVal, timecopy)
|
|
//获取指标权重
|
|
dimensionIdStr := strconv.FormatInt(schemeCont.DimensionId, 10)
|
|
targetIdStr := strconv.FormatInt(schemeCont.TargetId, 10)
|
|
sendData.Weight = GetSchemeTargetWeight(schemeCont.VersionNumber, dimensionIdStr, targetIdStr, schemeCont.Source)
|
|
sendData.ScoringMethod = schemeCont.ScoringMethod
|
|
publicmethod.Result(0, sendData, c)
|
|
}
|
|
|
|
/*
|
|
获取岗位指标全奖、零奖、封顶值
|
|
@company 公司
|
|
@org 行政组织
|
|
@post 岗位
|
|
@dimension 维度
|
|
@target 指标
|
|
@detailed 细则
|
|
GetPostTagetRewardSeting(company, org, post, dimension, target, detailed, year int64, timecopy int)
|
|
*/
|
|
func GetPostTagetRewardSeting(company, org, post, dimension, target, detailed, year, timecopy int64) (allprize, zeroprize, capping float64) {
|
|
allprize = 0
|
|
zeroprize = 0
|
|
capping = 0
|
|
var quanPostConfig modelskpi.QuanPostConfig
|
|
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.QuanPostConfig{}).Where("`state` = 1 AND `company_id` = ? AND `org_id` = ? AND `post_id` = ? AND `dimension` = ? AND `target` = ? AND `year` = ? AND `timecopy` = ?", company, org, post, dimension, target, year, timecopy)
|
|
if detailed != 0 {
|
|
gormDb = gormDb.Where("`detailed` = ?", detailed)
|
|
}
|
|
err := gormDb.First(&quanPostConfig).Error
|
|
if err == nil {
|
|
allprize = publicmethod.DecimalEs(quanPostConfig.Allprize, 2)
|
|
zeroprize = publicmethod.DecimalEs(quanPostConfig.Zeroprize, 2)
|
|
capping = publicmethod.DecimalEs(quanPostConfig.CappingVal, 2)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取考核项目指标权重
|
|
@versionNumber 版本编号
|
|
@dimension 维度
|
|
@target 指标
|
|
@source 来源(1:岗位;2:部门引用)
|
|
@weight 指标权重
|
|
GetSchemeTargetWeight(versionNumber, dimension, target string, source int)
|
|
*/
|
|
func GetSchemeTargetWeight(versionNumber, dimension, target string, source int) (weight float64) {
|
|
var postPlanVersion modelskpi.PositionPlanVersio
|
|
err := postPlanVersion.GetCont(map[string]interface{}{"`key`": versionNumber})
|
|
if err != nil {
|
|
return
|
|
}
|
|
//解析岗位指标放啊
|
|
var shemeInfo postScheme
|
|
jsonErr := json.Unmarshal([]byte(postPlanVersion.Content), &shemeInfo)
|
|
if jsonErr != nil {
|
|
return
|
|
}
|
|
if source == 1 { //岗位
|
|
if len(shemeInfo.PostChild) > 0 {
|
|
for _, pv := range shemeInfo.PostChild { //维度
|
|
if pv.Id == dimension {
|
|
if len(pv.Child) > 0 {
|
|
for _, tv := range pv.Child { //指标
|
|
if tv.Id == target {
|
|
weight = tv.Score
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else { //部门引用
|
|
if len(shemeInfo.DepartmentChild) > 0 {
|
|
for _, pv := range shemeInfo.DepartmentChild { //维度
|
|
if pv.Id == dimension {
|
|
if len(pv.Child) > 0 {
|
|
for _, tv := range pv.Child { //指标
|
|
if tv.Id == target {
|
|
weight = tv.Score
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 提交定量考核数据
|
|
func (a *ApiMethod) SubmitRationPostCont(c *gin.Context) {
|
|
var receivedValue submitPostSchemeTarget
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if receivedValue.Id == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
currentTime := time.Now().Unix()
|
|
if receivedValue.SubmitTime != "" {
|
|
happTime, timeErr := publicmethod.DateToTimeStamp(fmt.Sprintf("%v-01 12:00:00", receivedValue.SubmitTime))
|
|
if timeErr == true {
|
|
currentTime = happTime
|
|
}
|
|
} else {
|
|
yearVal := publicmethod.ComputingTime(currentTime, 1)
|
|
timecopy := publicmethod.ComputingTime(currentTime, 3) //月"`
|
|
happTime, timeErr := publicmethod.DateToTimeStamp(fmt.Sprintf("%v-%v-01 12:00:00", yearVal, timecopy))
|
|
if timeErr == true {
|
|
currentTime = happTime
|
|
}
|
|
}
|
|
if receivedValue.Score == 0 {
|
|
publicmethod.Result(1, receivedValue, c, "请输入您的实际值!")
|
|
return
|
|
}
|
|
if receivedValue.ScoringMethod == 0 {
|
|
receivedValue.ScoringMethod = 1
|
|
}
|
|
|
|
if receivedValue.ScoringMethod != 1 {
|
|
if receivedValue.ScoringScore == 0 {
|
|
publicmethod.Result(1, receivedValue, c, "请输入您的手动打分值!")
|
|
return
|
|
}
|
|
}
|
|
if receivedValue.PersonLiable == "" {
|
|
publicmethod.Result(1, receivedValue, c, "没有确定责任人是谁!")
|
|
return
|
|
}
|
|
//获取考核项目信息
|
|
var postShemeCont modelskpi.QualitativeEvaluationScheme
|
|
err = postShemeCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
//获取指标单位
|
|
var targetUnit modelskpi.PostTarget
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTarget{}).Select("unit").Where(map[string]interface{}{"`id`": postShemeCont.TargetId}).First(&targetUnit)
|
|
//获取被考核人基本信息
|
|
var userCont modelshr.PersonArchives
|
|
err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.PersonLiable}, "`company`", "`maindeparment`", "`admin_org`", "`position`", "`wechat`", "`work_wechat`", "`key`")
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
//获取登录人信息
|
|
context, _ := publicmethod.LoginMyCont(c)
|
|
|
|
uuId := publicmethod.GetUUid(1)
|
|
|
|
//生成工作流
|
|
wechatOpenId := context.Wechat
|
|
if context.WorkWechat != "" {
|
|
wechatOpenId = context.WorkWechat
|
|
}
|
|
var reviewFlowCont flowchart.ReviewFlow
|
|
reviewFlowCont.Id = receivedValue.Id
|
|
reviewFlowCont.IsCorrection = 1
|
|
reviewFlowCont.PlusReduction = 1
|
|
reviewFlowCont.PeopleList = append(reviewFlowCont.PeopleList, receivedValue.PersonLiable)
|
|
flowMap, _ := flowchart.SetUpWorkFlow(wechatOpenId, context.MainDeparment, reviewFlowCont, 1)
|
|
|
|
var sendUserList []string
|
|
var sendTitle string
|
|
//获取下一个节点审批人
|
|
for _, v := range flowMap {
|
|
if v.Step == 2 {
|
|
sendTitle = v.NodeName
|
|
for _, vu := range v.UserList {
|
|
// fmt.Printf("vu------------>%v\n", vu)
|
|
if publicmethod.IsInTrue[string](vu.Wechat, sendUserList) == false {
|
|
sendUserList = append(sendUserList, vu.Wechat)
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
addTime := time.Now().Unix()
|
|
//流程列表
|
|
var flowCont modelskpi.PostWorkflowOrders
|
|
flowCont.OrderId = uuId //审批单ID"`
|
|
flowCont.Step = 1 //当前执行到第几步"`
|
|
flowCont.NextStep = 2 //下一步执行哪个步骤"`
|
|
sumStep := len(flowMap)
|
|
if sumStep-1 > 0 {
|
|
sumStep = sumStep - 1
|
|
} else {
|
|
sumStep = 1
|
|
}
|
|
flowCont.CountStep = sumStep
|
|
flowMapJson, _ := json.Marshal(flowMap)
|
|
flowCont.WorkFlow = string(flowMapJson) //工作流(审批json字符串)"`
|
|
flowCont.CompanyId = userCont.Company //公司"`
|
|
flowCont.DepartmentId = userCont.MainDeparment //部门"`
|
|
flowCont.OrgId = userCont.AdminOrg //行政组织"`
|
|
flowCont.PostId = userCont.Position //岗位"`
|
|
flowCont.Class = postShemeCont.Attribute //属性1、定性;2、定量"`
|
|
flowCont.Dimension = postShemeCont.DimensionId //维度"`
|
|
flowCont.Target = postShemeCont.TargetId //指标"`
|
|
flowCont.SonTarget = postShemeCont.SonTargetId //指标子栏目"`
|
|
flowCont.Detailed = postShemeCont.DetailsId //指标细则"`
|
|
flowCont.Executor = context.Key //执行人"`
|
|
flowCont.ExecutorDepartment = context.MainDeparment //执行人部门"`
|
|
flowCont.State = 3 //流程状态 1:草稿;2:驳回;3:审批中;4:归档;5:废弃;6:删除"`
|
|
flowCont.StartTime = addTime //流程开始时间"`
|
|
flowCont.Time = addTime //时间"`
|
|
if len(receivedValue.Enclosure) > 0 {
|
|
jsonFileList, _ := json.Marshal(receivedValue.Enclosure)
|
|
flowCont.EnclosureFormat = string(jsonFileList) //附件"`
|
|
}
|
|
|
|
yearVal := publicmethod.ComputingTime(currentTime, 1)
|
|
timecopy := publicmethod.ComputingTime(currentTime, 3) //月"`
|
|
var baseLine baseLineType
|
|
//获取指标的全奖、零奖、封顶值
|
|
baseLine.Allprize, baseLine.Zeroprize, baseLine.Capping = GetPostTagetRewardSeting(postShemeCont.CompanyId, postShemeCont.OrgId, postShemeCont.PostId, postShemeCont.DimensionId, postShemeCont.TargetId, postShemeCont.DetailsId, yearVal, timecopy)
|
|
//获取指标权重
|
|
dimensionIdStr := strconv.FormatInt(postShemeCont.DimensionId, 10)
|
|
targetIdStr := strconv.FormatInt(postShemeCont.TargetId, 10)
|
|
baseLine.Weight = GetSchemeTargetWeight(postShemeCont.VersionNumber, dimensionIdStr, targetIdStr, postShemeCont.Source)
|
|
|
|
baseLine.SchemeId = receivedValue.Id
|
|
baseLine.TargetId = targetIdStr
|
|
//定量考核流水
|
|
var postMeterFlow modelskpi.PostMeteringFlow
|
|
|
|
postMeterFlow.OrderId = uuId // 审批单ID"`
|
|
postMeterFlow.ShemeId = postShemeCont.Id // 方案ID"`
|
|
postMeterFlow.ShemeVersion = postShemeCont.VersionNumber //方案版本编号"`
|
|
postMeterFlow.Dimension = postShemeCont.DimensionId //维度"`
|
|
postMeterFlow.Target = postShemeCont.TargetId //指标"`
|
|
postMeterFlow.Score = receivedValue.Score * 100 //分值(*100保存)"`
|
|
postMeterFlow.Reason = receivedValue.Reason //这样操作的原因"`
|
|
postMeterFlow.Year = yearVal //年"`
|
|
postMeterFlow.Quarter = publicmethod.ComputingTime(currentTime, 2) //季度"`
|
|
postMeterFlow.Month = publicmethod.ComputingTime(currentTime, 3) //月"`
|
|
postMeterFlow.Week = publicmethod.ComputingTime(currentTime, 4) //周"`
|
|
postMeterFlow.PersonLiable = userCont.Key //责任人"`
|
|
postMeterFlow.CompanyId = userCont.Company //公司"`
|
|
postMeterFlow.DepartmentId = userCont.MainDeparment //部门"`
|
|
postMeterFlow.OrgId = userCont.AdminOrg //行政组织"`
|
|
postMeterFlow.PostId = userCont.Position //岗位"`
|
|
postMeterFlow.Executor = context.Key //执行人"`
|
|
postMeterFlow.ExecutorDepartment = context.MainDeparment //执行人部门"`
|
|
postMeterFlow.HappenTime = currentTime //发生时间"`
|
|
postMeterFlow.Time = addTime //时间"`
|
|
baseLineJson, _ := json.Marshal(baseLine)
|
|
postMeterFlow.Baseline = string(baseLineJson) //基准线"`
|
|
|
|
postMeterFlow.ScoringMethod = receivedValue.ScoringMethod //计分方式(1:自动;2:手动)
|
|
if receivedValue.ScoringMethod != 1 {
|
|
postMeterFlow.ScoringScore = receivedValue.ScoringScore * 100 //手动分
|
|
}
|
|
|
|
//开启事务提交
|
|
gormDbAffair := overall.CONSTANT_DB_KPI.Begin()
|
|
passorErr := gormDbAffair.Create(&flowCont).Error
|
|
flowErr := gormDbAffair.Create(&postMeterFlow).Error
|
|
// openAppChangeErr := gormDbAffair.Create(&openAppChangeLog).Error
|
|
|
|
if passorErr == nil && flowErr == nil {
|
|
addErr := gormDbAffair.Commit().Error
|
|
publicmethod.Result(0, addErr, c)
|
|
|
|
// fmt.Printf("callData---2--->%v--------err--------->%v--------->%v\n", sendUserList, sendTitle, flowMap)
|
|
if len(sendUserList) > 0 {
|
|
//项下一个审批节点发送审批通知
|
|
//头部信息
|
|
var sourceText wechatsendmsg.SourceText
|
|
sourceText.IconUrl = "https://docu.hxgk.group/images/2022_01/3f7a1120a559e9bee3991b85eb34d103.png"
|
|
sourceText.Desc = fmt.Sprintf("恒信高科-%v", sendTitle)
|
|
sourceText.DescColor = 1
|
|
|
|
//引用文献
|
|
var quoteAreaInfo wechatsendmsg.QuoteAreaCont
|
|
quoteAreaInfo.Type = 0
|
|
quoteAreaInfo.Title = "数据详细"
|
|
quoteAreaInfo.QuoteText = fmt.Sprintf("数值:%v%v\n备注:%v", receivedValue.Score, targetUnit.Unit, receivedValue.Reason)
|
|
//按钮
|
|
var buttonList []wechatsendmsg.ButtonListCont
|
|
var buttonList1 wechatsendmsg.ButtonListCont
|
|
buttonList1.Text = "批准"
|
|
buttonList1.Style = 1
|
|
buttonList1.Key = fmt.Sprintf("KPI_post_%v_%v_%v", uuId, 1, 2)
|
|
buttonList = append(buttonList, buttonList1)
|
|
var buttonList2 wechatsendmsg.ButtonListCont
|
|
buttonList2.Text = "驳回"
|
|
buttonList2.Style = 3
|
|
buttonList2.Key = fmt.Sprintf("KPI_post_%v_%v_%v", uuId, 2, 2)
|
|
buttonList = append(buttonList, buttonList2)
|
|
//二级标题+文本列表
|
|
var twoTitleTextList []wechatsendmsg.HorizontalContentListInfo
|
|
//发送人
|
|
var horizontalContentLis3 wechatsendmsg.HorizontalContentListInfo
|
|
horizontalContentLis3.KeyName = "申请人"
|
|
horizontalContentLis3.Value = "点击查看"
|
|
horizontalContentLis3.Type = 3
|
|
horizontalContentLis3.Userid = wechatOpenId
|
|
twoTitleTextList = append(twoTitleTextList, horizontalContentLis3)
|
|
//被考核人
|
|
if userCont.Wechat != "" || userCont.WorkWechat != "" {
|
|
weChatStrs := userCont.Wechat
|
|
if userCont.WorkWechat != "" {
|
|
weChatStrs = userCont.WorkWechat
|
|
}
|
|
var twoTitleTextCont wechatsendmsg.HorizontalContentListInfo
|
|
twoTitleTextCont.KeyName = "被考核人:"
|
|
twoTitleTextCont.Value = "点击查看"
|
|
twoTitleTextCont.Type = 3
|
|
twoTitleTextCont.Userid = weChatStrs
|
|
twoTitleTextList = append(twoTitleTextList, twoTitleTextCont)
|
|
}
|
|
//卡片跳转地址
|
|
var cardActionContStr wechatsendmsg.CardActionCont
|
|
cardActionContStr.Type = 1
|
|
cardActionContStr.Url = fmt.Sprintf("http://new.hxgk.group/#/quantitativeList?id=%v", uuId)
|
|
|
|
var sendButtionMsg wechatsendmsg.SendButtonInteractionSimplify
|
|
sendButtionMsg.Touser = strings.Join(sendUserList, "|")
|
|
// sendButtionMsg.Touser = "KaiXinGuo" //指定接收消息的成员,成员ID列表;特殊情况:指定为
|
|
sendButtionMsg.Msgtype = "template_card"
|
|
agentIdInt, _ := strconv.ParseInt(overall.CONSTANT_CONFIG.WechatKpi.Agentid, 10, 64)
|
|
sendButtionMsg.Agentid = agentIdInt
|
|
sendButtionMsg.EnableDuplicateCheck = 0
|
|
sendButtionMsg.DuplicateCheckInterval = 1800
|
|
sendButtionMsg.EnableIdTrans = 0
|
|
sendButtionMsg.TemplateCard.CardType = "button_interaction"
|
|
sendButtionMsg.TemplateCard.Source = sourceText
|
|
sendButtionMsg.TemplateCard.TaskId = fmt.Sprintf("KPI_%v", uuId)
|
|
sendButtionMsg.TemplateCard.MainTitle.Title = postShemeCont.Title
|
|
sendButtionMsg.TemplateCard.MainTitle.Desc = postShemeCont.Content
|
|
sendButtionMsg.TemplateCard.QuoteArea = quoteAreaInfo
|
|
// sendButtionMsg.TemplateCard.SubTitleText = fmt.Sprintf("")
|
|
sendButtionMsg.TemplateCard.ButtonList = buttonList
|
|
sendButtionMsg.TemplateCard.HorizontalContentList = twoTitleTextList
|
|
sendButtionMsg.TemplateCard.CardAction = cardActionContStr
|
|
// sendButtionMsg.SendMsg("kpi")
|
|
callData, err := sendButtionMsg.SendMsg("kpi")
|
|
if err == nil {
|
|
if callData.Errcode == 0 {
|
|
// var operatorIsTrueCont modelskpi.OperatorIsTrue
|
|
// operatorIsTrueCont.OrderId = uuId //订单ID"`
|
|
// operatorIsTrueCont.Step = 1 //审批到第几步"`
|
|
// operatorIsTrueCont.State = 1 //:状态:1:可操作;2:不可操作"`
|
|
// operatorIsTrueCont.Time = addTime //操作时间"`
|
|
// operatorIsTrueCont.Msgid = callData.Msgid //:消息id,用于撤回应用消息"`
|
|
// operatorIsTrueCont.ResponseCode = callData.ResponseCode //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,24小时内有效,且只能使用一次"`
|
|
// operatorIsTrueCont.Stepper = 1
|
|
// overall.CONSTANT_DB_KPI.Create(&operatorIsTrueCont)
|
|
|
|
var openAppChangeLog modelskpi.OpenApprovalChangeLog
|
|
openAppChangeLog.Type = 2
|
|
openAppChangeLog.Title = "创建申请"
|
|
openAppChangeLog.Operator = context.Key
|
|
openAppChangeLog.OrderId = uuId // 审批单ID"`
|
|
openAppChangeLog.OperatorTime = addTime
|
|
openAppChangeLog.Step = 1
|
|
openAppChangeLog.OperatorType = 2
|
|
openAppChangeLog.Msgid = callData.Msgid //:消息id,用于撤回应用消息"`
|
|
openAppChangeLog.ResponseCode = callData.ResponseCode //仅消息类型为“按钮交互型”,“投票选择型”和“多项选择型”的模板卡片消息返回,应用可使用response_code调用更新模版卡片消息接口,24小时内有效,且只能使用一次"`
|
|
openAppChangeLog.Stepper = 1
|
|
openAppChangeLog.ChangeIsTrue = 1 //是否可变更(1:可变更;2:不可变更)"`
|
|
openAppChangeLog.Eiteyime = addTime
|
|
openAppChangeLog.YesOrNo = 1
|
|
overall.CONSTANT_DB_KPI.Create(&openAppChangeLog)
|
|
}
|
|
}
|
|
// jsonstr, _ := json.Marshal(sendButtionMsg)
|
|
// fmt.Printf("callData------>%v--------err--------->%v--------->%v\n", callData, err, targetUnit)
|
|
}
|
|
|
|
} else {
|
|
addErr := gormDbAffair.Rollback().Error
|
|
publicmethod.Result(104, addErr, c)
|
|
}
|
|
}
|
|
|