8 changed files with 557 additions and 35 deletions
@ -0,0 +1,288 @@ |
|||
package postweb |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"fmt" |
|||
"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) 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 userCont modelshr.PersonArchives |
|||
err = userCont.GetCont(map[string]interface{}{"`key`": receivedValue.PersonLiable}, "`company`", "`maindeparment`", "`admin_org`", "`position`") |
|||
if err != nil { |
|||
publicmethod.Result(107, err, c) |
|||
return |
|||
} |
|||
//获取登录人信息
|
|||
context, _ := publicmethod.LoginMyCont(c) |
|||
|
|||
uuId := publicmethod.GetUUid(1) |
|||
|
|||
//流程列表
|
|||
var flowCont modelskpi.PostWorkflowOrders |
|||
flowCont.OrderId = uuId //审批单ID"`
|
|||
flowCont.Step = 1 //当前执行到第几步"`
|
|||
flowCont.NextStep = 2 //下一步执行哪个步骤"`
|
|||
flowCont.WorkFlow = "" //工作流(审批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 = time.Now().Unix() //流程开始时间"`
|
|||
flowCont.Time = time.Now().Unix() //时间"`
|
|||
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 = time.Now().Unix() //时间"`
|
|||
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 |
|||
passorErr := gormDbAffair.Create(&flowCont).Error |
|||
flowErr := gormDbAffair.Create(&postMeterFlow).Error |
|||
|
|||
if passorErr == nil && flowErr == nil { |
|||
addErr := gormDbAffair.Commit().Error |
|||
publicmethod.Result(0, addErr, c) |
|||
} else { |
|||
addErr := gormDbAffair.Rollback().Error |
|||
publicmethod.Result(104, addErr, c) |
|||
} |
|||
} |
|||
@ -0,0 +1,72 @@ |
|||
package modelskpi |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 岗位定量考核目标设定
|
|||
type QuanPostConfig struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
CompanyId int64 `json:"companyid" gorm:"column:company_id;type:bigint(20) unsigned;default:0;not null;comment:公司"` |
|||
DepartmentId int64 `json:"departmentid" gorm:"column:department_id;type:bigint(20) unsigned;default:0;not null;comment:部门ID"` |
|||
OrgId int64 `json:"orgid" gorm:"column:org_id;type:bigint(20) unsigned;default:0;not null;comment:行政组织"` |
|||
PostId int64 `json:"postid" gorm:"column:post_id;type:bigint(20) unsigned;default:0;not null;comment:岗位"` |
|||
Dimension int64 `json:"dimension" gorm:"column:dimension;type:bigint(20) unsigned;default:0;not null;comment:维度"` |
|||
Target int64 `json:"target" gorm:"column:target;type:bigint(20) unsigned;default:0;not null;comment:指标"` |
|||
Detailed int64 `json:"detailed" gorm:"column:detailed;type:bigint(20) unsigned;default:0;not null;comment:指标细则"` |
|||
Type int64 `json:"type" gorm:"column:type;type:tinyint(1) unsigned;default:0;not null;comment:1、年度;2、季度;3、月度"` |
|||
Year int64 `json:"year" gorm:"column:year;type:bigint(20) unsigned;default:0;not null;comment:年度"` |
|||
Timecopy int64 `json:"timecopy" gorm:"column:timecopy;type:int(3) unsigned;default:0;not null;comment:季度与月度辅助值"` |
|||
Zeroprize float64 `json:"zeroprize" gorm:"column:zeroprize;type:int(7) unsigned;default:0;not null;comment:零奖值"` |
|||
Allprize float64 `json:"allprize" gorm:"column:allprize;type:int(7) unsigned;default:0;not null;comment:全奖值"` |
|||
Capping int `json:"capping" gorm:"column:capping;type:int(1) unsigned;default:2;not null;comment:是否封顶(1、是;2:否)"` |
|||
CappingVal float64 `json:"cappingval" gorm:"column:capping_val;type:bigint(20) unsigned;default:0;not null;comment:封顶值"` |
|||
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (QuanPostConfig *QuanPostConfig) TableName() string { |
|||
return "quan_post_config" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *QuanPostConfig) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *QuanPostConfig) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *QuanPostConfig) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *QuanPostConfig) ContMap(whereMap interface{}, field ...string) (countAry []QuanPostConfig, err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *QuanPostConfig) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
package modelskpi |
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 定量考核目标设定
|
|||
type QuantitativeConfig struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
DepartmentId int64 `json:"departmentid" gorm:"column:departmentid;type:bigint(20) unsigned;default:0;not null;comment:部门ID"` |
|||
Group int64 `json:"group" gorm:"column:group;type:bigint(20) unsigned;default:0;not null;comment:集团ID"` |
|||
Dimension int64 `json:"dimension" gorm:"column:dimension;type:bigint(20) unsigned;default:0;not null;comment:维度"` |
|||
Target int64 `json:"target" gorm:"column:target;type:bigint(20) unsigned;default:0;not null;comment:指标"` |
|||
TargetConfig int64 `json:"targetconfig" gorm:"column:targetconfig;type:bigint(20) unsigned;default:0;not null;comment:指标细则"` |
|||
Type int64 `json:"type" gorm:"column:type;type:tinyint(1) unsigned;default:0;not null;comment:1、年度;2、季度;3、月度"` |
|||
Year int64 `json:"year" gorm:"column:year;type:bigint(20) unsigned;default:0;not null;comment:年度"` |
|||
Timecopy int64 `json:"timecopy" gorm:"column:timecopy;type:int(3) unsigned;default:0;not null;comment:季度与月度辅助值"` |
|||
Zeroprize float64 `json:"zeroprize" gorm:"column:zeroprize;type:int(7) unsigned;default:0;not null;comment:零奖值"` |
|||
Allprize float64 `json:"allprize" gorm:"column:allprize;type:int(7) unsigned;default:0;not null;comment:全奖值"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Capping int `json:"capping" gorm:"column:capping;type:int(1) unsigned;default:2;not null;comment:是否封顶(1、是;2:否)"` |
|||
CappingVal float64 `json:"cappingval" gorm:"column:capping_val;type:bigint(20) unsigned;default:0;not null;comment:封顶值"` |
|||
} |
|||
|
|||
func (QuantitativeConfig *QuantitativeConfig) TableName() string { |
|||
return "quantitative_config" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *QuantitativeConfig) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *QuantitativeConfig) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *QuantitativeConfig) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *QuantitativeConfig) ContMap(whereMap interface{}, field ...string) (countAry []QuantitativeConfig, err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *QuantitativeConfig) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue