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.

1104 lines
37 KiB

package departmentpc
import (
"encoding/json"
"fmt"
"key_performance_indicators/middleware/snowflake"
"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-02-08 11:33:09
@ 功能: 添加部门指标(新版)
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) NewAddDepartmentTarget(c *gin.Context) {
var receivedValue addTargetContDepart
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, err, c, "请输入指标名称!!")
return
}
if receivedValue.Nature == 0 {
receivedValue.Nature = 1
}
if receivedValue.Share == 0 {
if len(receivedValue.AcceptDepartmentId) > 0 {
receivedValue.Share = 2
} else {
receivedValue.Share = 1
}
} else {
if receivedValue.Share > 1 {
if len(receivedValue.AcceptDepartmentId) < 1 {
publicmethod.Result(101, err, c, "您选择了此指标为指定部门使用!但您未指定具体使用部门!请指定相关使用部门!")
return
}
}
}
if receivedValue.Unit == "" {
publicmethod.Result(101, err, c, "请输入计量单位!")
return
}
if receivedValue.Cycles == 0 {
receivedValue.Cycles = 4
}
if receivedValue.CycleAttres == 0 {
receivedValue.CycleAttres = 1
}
if receivedValue.ScoringMethod == 0 {
receivedValue.ScoringMethod = 1
}
JudgeIsTrue := publicmethod.MapOut[string]()
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{}).Select("et_title").Where("`et_title` = ? AND `et_type` = ? AND `et_dimension` = ?", receivedValue.Name, receivedValue.Nature, receivedValue.Dimension).First(&JudgeIsTrue).Error
if err == nil {
publicmethod.Result(101, err, c, "此考核指标已经存在!请不要重复添加!")
return
}
var uuId int64 = 0
snowflakeId, snowflakeErr := snowflake.NewWorker(1)
if snowflakeErr != nil {
uuId = publicmethod.TableNumber()
} else {
uuId = snowflakeId.GetId()
}
var saveData modelskpi.EvaluationTarget
saveData.Title = receivedValue.Name //指标名称"`
saveData.Type = receivedValue.Nature //1:定性考核;2:定量考核"`
saveData.State = 1 //状态(1:启用;2:禁用;3:删除)"`
saveData.AddTime = time.Now().Unix() //制定时间"`
saveData.Share = 1 //1:共用;2:私用"`
saveData.RelevantDepartments = strings.Join(receivedValue.AcceptDepartmentId, ",") //相关部门"`
dimensionId, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
saveData.Dimension = dimensionId //维度"`
saveData.Key = uuId //UUID"`
saveData.Report = strings.Join(receivedValue.Operator, ",") //上报人"`
saveData.Uniteing = receivedValue.Unit //计量单位"`
saveData.Cycles = receivedValue.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年"`
saveData.CycleAttres = receivedValue.CycleAttres //辅助计数"`
saveData.VisibleRange = strings.Join(receivedValue.VisibleRangeDepart, ",") //可见范围"`
saveData.VisibleRangeGroup = strings.Join(receivedValue.VisibleRangeGroup, ",") //可见范围(集团)"`
saveData.ScoringMethod = receivedValue.ScoringMethod //计分方式(1:自动;2:手动)"`
err = overall.CONSTANT_DB_KPI.Create(&saveData).Error
if err != nil {
publicmethod.Result(104, err, c)
return
}
SyncSeting.Add(1)
go DepartAboutTarget(dimensionId, saveData.Id, 0, 0, receivedValue.AcceptDepartmentId, 1, receivedValue.Nature, 1)
SyncSeting.Add(1)
go DepartAndReportAboutTarget(dimensionId, saveData.Id, 0, 0, receivedValue.AcceptDepartmentId, receivedValue.Operator, 1, receivedValue.Nature, 1)
SyncSeting.Wait()
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-08 11:33:17
@ 功能: 处理指标与部门关联关系
@ 参数
#
@ 返回值
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#postId 岗位
#typeInt 类型1指标2子目标3细则
#class 属性1定性考核2定量考核
#level 级别1部门级2岗位级
@ 方法原型
#DepartAboutTarget(dimensionId, targetId, targetSunId, targetBylaws int64, departmentId []string, typeInt, class, level int)
*/
func DepartAboutTarget(dimensionId, targetId, targetSunId, targetBylaws int64, departmentId []string, typeInt, class, level int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if level == 0 {
level = 1
}
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where("`post_id` = 0 AND `level` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND `type` = ?", level, targetId, targetSunId, targetBylaws, typeInt).Not(map[string]interface{}{"department_id": departmentId}).Updates(&otherSaveData)
//循环处理行政组织
for _, v := range departmentId {
var tarDepartCont modelskpi.TargetDepartment
saveErr := tarDepartCont.GetCont(map[string]interface{}{"`level`": level, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": targetBylaws, "`department_id`": v, "`post_id`": 0}, "`id`", "`state`")
if saveErr == nil {
if tarDepartCont.State != 1 {
tarDepartCont.EiteCont(map[string]interface{}{"`id`": tarDepartCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
}
} else {
xiZe := 3
if targetId != 0 && targetSunId != 0 && targetBylaws == 0 {
xiZe = 2
} else if targetId != 0 && targetSunId == 0 && targetBylaws == 0 {
xiZe = 1
}
tarDepartCont.Dimension = dimensionId
tarDepartCont.TargetId = targetId //指标ID"`
tarDepartCont.TargetSunId = targetSunId //子目标"`
tarDepartCont.TargetBylaws = targetBylaws //指标细则"`
tarDepartCont.Type = xiZe //类型(1:指标;2:子目标;3:细则)"`
departId, _ := strconv.ParseInt(v, 10, 64)
tarDepartCont.DepartmentId = departId //部门ID"`
tarDepartCont.PostId = 0 //岗位ID"`
tarDepartCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
tarDepartCont.Time = time.Now().Unix() //写入时间"`
tarDepartCont.Class = class //1:定性考核;2:定量考核"`
tarDepartCont.Level = level //级别(1:部门级;2:岗位级)"`
overall.CONSTANT_DB_KPI.Create(&tarDepartCont)
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-08 13:05:36
@ 功能: 处理指标与部门和提报人关联关系
@ 参数
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#typeInt 类型1公司级2部门级
#manKey 用户Key
#class 属性1定性考核2定量考核
#typeLevel 级别1指标2子目标3细则
@ 返回值
#
@ 方法原型
#DepartAndReportAboutTarget(dimensionId, targetId, targetSunId, targetBylaws int64, departmentId, manKey []string, typeInt, class, typeLevel int)
*/
func DepartAndReportAboutTarget(dimensionId, targetId, targetSunId, targetBylaws int64, departmentId, manKey []string, typeInt, class, typeLevel int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if typeLevel == 0 {
typeLevel = 1
}
3 years ago
fmt.Printf("管理部门提报人---->\ndimensionId------->%v\ntargetId------->%v\ntargetSunId------->%v\ntargetBylaws------->%v\ndepartmentId------->%v\nmanKey------->%v\ntypeInt------->%v\nclass------->%v\ntypeLevel------->%v\n", dimensionId, targetId, targetSunId, targetBylaws, departmentId, manKey, typeInt, class, typeLevel)
//循环遍历部门
for _, dv := range departmentId {
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where("`post_id` = 0 AND `type_level` = ? AND `type` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND department_id = ?", typeLevel, typeInt, targetId, targetSunId, targetBylaws, dv).Not(map[string]interface{}{"man_key": manKey}).Updates(&otherSaveData)
//循环遍历人员
for _, v := range manKey {
//获取评价人部门
var manCont modelshr.PersonArchives
manCont.GetCont(map[string]interface{}{"`key`": v}, "`maindeparment`")
var tarReportCont modelskpi.TargetReport
saveErr := tarReportCont.GetCont(map[string]interface{}{"`type_level`": typeLevel, "`post_id`": 0, "`type`": typeInt, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": targetBylaws, "`department_id`": dv, "`man_key`": v}, "`id`", "`state`")
if saveErr == nil {
if tarReportCont.State != 1 {
tarReportCont.EiteCont(map[string]interface{}{"`id`": tarReportCont.Id}, map[string]interface{}{"`state`": 1, "`man_department`": manCont.MainDeparment, "`time`": time.Now().Unix()})
}
// fmt.Printf("获取评价人部门----编辑------>%v\n", tarReportCont)
} else {
xiZe := 3
if targetId != 0 && targetSunId != 0 && targetBylaws == 0 {
xiZe = 2
} else if targetId != 0 && targetSunId == 0 && targetBylaws == 0 {
xiZe = 1
}
var tarReportContAdd modelskpi.TargetReport
tarReportContAdd.Dimension = dimensionId //维度
tarReportContAdd.TargetId = targetId //指标ID"`
tarReportContAdd.TargetSunId = targetSunId //子目标"`
tarReportContAdd.TargetBylaws = targetBylaws //指标细则"`
dvInt, _ := strconv.ParseInt(dv, 10, 64)
tarReportContAdd.DepartmentId = dvInt //部门ID"`
tarReportContAdd.PostId = 0 //岗位ID"`
tarReportContAdd.Type = typeInt //类型(1:公司级;2:部门级)"`
tarReportContAdd.State = 1 //状态(1:启用;2:禁用;3:删除)"`
reportId, _ := strconv.ParseInt(v, 10, 64)
tarReportContAdd.ReportPerson = reportId //上报人"`
tarReportContAdd.ManDepartment = manCont.MainDeparment //提报人所在部门"`
tarReportContAdd.Time = time.Now().Unix() //写入时间"`
tarReportContAdd.Class = class //1:定性考核;2:定量考核"`
tarReportContAdd.Level = xiZe //1:指标;2:子目标;3:细则
overall.CONSTANT_DB_KPI.Create(&tarReportContAdd)
// fmt.Printf("获取评价人部门----新增------>%v\n", tarReportContAdd)
}
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-08 13:47:54
@ 功能: 删除部门指标
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) TargetChangeState(c *gin.Context) {
var receivedValue publicmethod.PublicState
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c, "参数错误!!")
return
}
if receivedValue.State == 0 {
receivedValue.State = 1
}
if receivedValue.IsTrue == 0 {
receivedValue.IsTrue = 2
}
where := publicmethod.MapOut[string]()
where["et_id"] = receivedValue.Id
var targetCont modelskpi.EvaluationTarget
err := targetCont.GetCont(where, "et_id")
if err != nil {
publicmethod.Result(107, err, c)
return
}
softDel := 1
if receivedValue.State == 3 && receivedValue.IsTrue == 1 {
//强制删除
//判断该指标是否在使用中,使用中的只能软删除
var epIdList []int64
overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationProcess{}).Select("`ep_id`").Where("FIND_IN_SET(?,`ep_target`)", receivedValue.Id).Find(&epIdList)
if len(epIdList) > 0 {
softDel = 1
} else {
softDel = 2
}
}
delTime := time.Now().Unix()
var editTargetState modelskpi.EvaluationTarget
if softDel == 1 {
//软删除
editTargetState.EiteCont(where, map[string]interface{}{"`et_state`": receivedValue.State, "`et_time`": delTime})
} else {
//硬删除
editTargetState.DelCont(where)
}
SyncSeting.Add(1)
go SunTargetState(targetCont.Id, receivedValue.State, softDel) // 处理目标
SyncSeting.Add(1)
go TargetDatailedState(targetCont.Id, 0, receivedValue.State, softDel) // 处理细则
SyncSeting.Add(1)
go TarDepartState(targetCont.Id, 0, 0, receivedValue.State, softDel, 1, 1) // 处理关联部门
SyncSeting.Add(1)
go TarAboutReport(targetCont.Id, 0, 0, receivedValue.State, softDel, 1, 1) // 处理相关提报人
SyncSeting.Wait()
publicmethod.Result(0, err, c)
}
// 处理目标
/*
#ParentId 指标ID
#state 状态
#isTrue 1软删非1硬删除
*/
func SunTargetState(ParentId int64, state, isTrue int) {
defer SyncSeting.Done()
if state == 0 {
state = 1
}
if isTrue == 0 {
isTrue = 1
}
var sunTargetCont modelskpi.QualitativeTarget
if isTrue == 1 {
//软删除
if state != 1 {
sunTargetCont.EiteCont(map[string]interface{}{"`q_parent_id`": ParentId}, map[string]interface{}{"`q_state`": state, "`q_time`": time.Now().Unix()})
} else {
overall.CONSTANT_DB_KPI.Model(&modelskpi.QualitativeTarget{}).Where("`q_state` BETWEEN 1 AND 2 AND `q_parent_id` = ?", ParentId).Updates(map[string]interface{}{"`q_state`": state, "`q_time`": time.Now().Unix()})
}
} else {
sunTargetCont.DelCont(map[string]interface{}{"`q_parent_id`": ParentId})
}
}
// 处理细则
/*
#ParentId 指标ID
#SunID 栏目
#state 状态
#isTrue 1软删非1硬删除
*/
func TargetDatailedState(ParentId, SunID int64, state, isTrue int) {
defer SyncSeting.Done()
if state == 0 {
state = 1
}
if isTrue == 0 {
isTrue = 1
}
wheAry := publicmethod.MapOut[string]()
if ParentId != 0 {
wheAry["dt_parentid"] = ParentId
}
if SunID != 0 {
wheAry["dt_parentid_sun"] = SunID
}
var tarDataCont modelskpi.DetailedTarget
if isTrue == 1 {
//软删除
if state != 1 {
tarDataCont.EiteCont(wheAry, map[string]interface{}{"`dt_state`": state, "`dt_time`": time.Now().Unix()})
} else {
overall.CONSTANT_DB_KPI.Model(&modelskpi.DetailedTarget{}).Where("`dt_state` BETWEEN 1 AND 2").Where(wheAry).Updates(map[string]interface{}{"`dt_state`": state, "`dt_time`": time.Now().Unix()})
}
} else {
tarDataCont.DelCont(wheAry)
}
}
// 处理关联部门
/*
#parentId 指标ID
#sunID 栏目
#bylawsId 细则
#state 状态
#isTrue 1软删非1硬删除
#level 1:部门级2岗位级
#typeInt 1指标2子目标3细则
*/
func TarDepartState(parentId, sunID, bylawsId int64, state, isTrue, level, typeInt int) {
defer SyncSeting.Done()
if state == 0 {
state = 1
}
if isTrue == 0 {
isTrue = 1
}
wheAry := publicmethod.MapOut[string]()
wheAry["level"] = level
wheAry["type"] = typeInt
if parentId != 0 {
wheAry["target_id"] = parentId
}
if sunID != 0 {
wheAry["target_sun_id"] = sunID
}
if bylawsId != 0 {
wheAry["target_bylaws"] = bylawsId
}
var tarDataCont modelskpi.TargetDepartment
if isTrue == 1 {
//软删除
if state != 1 {
tarDataCont.EiteCont(wheAry, map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
} else {
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where("`state` BETWEEN 1 AND 2").Where(wheAry).Updates(map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
}
} else {
tarDataCont.DelCont(wheAry)
}
}
//处理相关提报人
/*
#parentId 指标ID
#sunID 栏目
#bylawsId 细则
#state 状态
#isTrue 1软删非1硬删除
#level 1:部门级2岗位级
#typeInt 1指标2子目标3细则
*/
func TarAboutReport(parentId, sunID, bylawsId int64, state, isTrue, level, typeInt int) {
defer SyncSeting.Done()
if state == 0 {
state = 1
}
if isTrue == 0 {
isTrue = 1
}
if level == 0 {
level = 1
}
wheAry := publicmethod.MapOut[string]()
wheAry["type"] = level
wheAry["type_level"] = typeInt
if parentId != 0 {
wheAry["target_id"] = parentId
}
if sunID != 0 {
wheAry["target_sun_id"] = sunID
}
if bylawsId != 0 {
wheAry["target_bylaws"] = bylawsId
}
var tarDataCont modelskpi.TargetReport
if isTrue == 1 {
//软删除
if state != 1 {
tarDataCont.EiteCont(wheAry, map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
} else {
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where("`state` BETWEEN 1 AND 2").Where(wheAry).Updates(map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
}
} else {
tarDataCont.DelCont(wheAry)
}
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 08:40:17
@ 功能: 编辑单一部门指标(新版)
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) NewEditOneTarget(c *gin.Context) {
var receivedValue printOneTargetCont
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, err, c, "请输入指标ID!!")
return
}
where := publicmethod.MapOut[string]()
where["et_id"] = receivedValue.Id
var targetCont modelskpi.EvaluationTarget
err = targetCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, err, c, "请输入指标名称!!")
return
}
if receivedValue.Nature == 0 {
receivedValue.Nature = 1
}
if len(receivedValue.AcceptDepartmentId) < 1 {
publicmethod.Result(101, err, c, "请指定相关使用部门!")
return
}
if receivedValue.Unit == "" {
publicmethod.Result(101, err, c, "请输入计量单位!")
return
}
if receivedValue.Cycles == 0 {
receivedValue.Cycles = 4
}
if receivedValue.CycleAttres == 0 {
receivedValue.CycleAttres = 1
}
if receivedValue.ScoringMethod == 0 {
receivedValue.ScoringMethod = 1
}
saveData := publicmethod.MapOut[string]()
if receivedValue.Name != targetCont.Title {
JudgeIsTrue := publicmethod.MapOut[string]()
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{}).Select("et_title").Where("`et_title` = ? AND `et_type` = ? AND `et_dimension` = ?", receivedValue.Name, receivedValue.Nature, receivedValue.Dimension).First(&JudgeIsTrue).Error
if err == nil {
publicmethod.Result(101, err, c, "此考核指标已经存在!请更换名称!")
return
} else {
saveData["et_title"] = receivedValue.Name
}
}
dimensionId := targetCont.Dimension
if receivedValue.Dimension != "" {
dimensionStr, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
if dimensionStr != targetCont.Dimension {
saveData["et_dimension"] = dimensionStr
dimensionId = dimensionStr
}
}
natureVal := targetCont.Type
if receivedValue.Nature != targetCont.Type {
saveData["et_type"] = receivedValue.Nature
natureVal = receivedValue.Nature
}
if receivedValue.Unit != targetCont.Uniteing {
saveData["et_unit"] = receivedValue.Nature
}
if receivedValue.Cycles != targetCont.Cycles {
saveData["et_cycle"] = receivedValue.Cycles
}
if receivedValue.CycleAttres != targetCont.CycleAttres {
saveData["et_cycleattr"] = receivedValue.CycleAttres
}
if receivedValue.ScoringMethod != targetCont.ScoringMethod {
saveData["et_scoring_method"] = receivedValue.ScoringMethod
}
visiblerangegroup := strings.Join(receivedValue.VisibleRangeGroup, ",")
if visiblerangegroup != targetCont.VisibleRangeGroup {
saveData["et_visible_group"] = visiblerangegroup
}
visiblerange := strings.Join(receivedValue.VisibleRangeDepart, ",")
if visiblerange != targetCont.VisibleRange {
saveData["et_visible_range"] = visiblerange
}
departIsTreu := false
reportIsTrue := false
//判断关联部门是否改变
if len(receivedValue.AcceptDepartmentId) > 0 {
departWhere := publicmethod.MapOut[string]()
departWhere["`target_id`"] = receivedValue.Id
departWhere["`target_sun_id`"] = 0
departWhere["`target_bylaws`"] = 0
departWhere["`type`"] = 1
departWhere["`state`"] = 1
_, departAry, _ := GetAboutDepartment(departWhere, 1)
departAryStr := strings.Join(departAry, ",")
accDepart := strings.Join(receivedValue.AcceptDepartmentId, ",")
if departAryStr != accDepart {
departIsTreu = true
saveData["et_relevant_departments"] = accDepart
SyncSeting.Add(1)
go DepartAboutTarget(dimensionId, targetCont.Id, 0, 0, receivedValue.AcceptDepartmentId, 1, natureVal, 1)
}
}
//判断提报人是否改变
if len(receivedValue.Operator) > 0 {
reportWhere := publicmethod.MapOut[string]()
reportWhere["`target_id`"] = receivedValue.Id
reportWhere["`target_sun_id`"] = 0
reportWhere["`target_bylaws`"] = 0
reportWhere["`post_id`"] = 0
reportWhere["`type_level`"] = 1
reportWhere["`state`"] = 1
_, report, _ := GetAboutReport(reportWhere, 1)
reportStr := strings.Join(report, ",")
accDepart := strings.Join(receivedValue.Operator, ",")
if reportStr != accDepart {
reportIsTrue = true
saveData["et_report"] = accDepart
SyncSeting.Add(1)
go DepartAndReportAboutTarget(dimensionId, targetCont.Id, 0, 0, receivedValue.AcceptDepartmentId, receivedValue.Operator, 1, natureVal, 1)
}
}
if len(saveData) > 0 {
saveData["et_time"] = time.Now().Unix()
err = targetCont.EiteCont(where, saveData)
}
if err != nil {
publicmethod.Result(106, err, c)
return
}
if reportIsTrue == true || departIsTreu == true {
SyncSeting.Wait()
}
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 11:52:32
@ 功能: 指标关联岗位新版
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) NewDeparmentTargetAboutPost(c *gin.Context) {
var receivedValue depTarAboutPost
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c, "请输入指标ID!!")
return
}
where := publicmethod.MapOut[string]()
where["et_id"] = receivedValue.Id
var targetCont modelskpi.EvaluationTarget
err := targetCont.GetCont(where)
jsonCont, _ := json.Marshal(receivedValue)
fmt.Printf("targetCont--------->%v--------->%v\n", string(jsonCont), err)
if err != nil {
publicmethod.Result(107, err, c)
return
}
if len(receivedValue.OrgList) < 1 {
publicmethod.Result(101, receivedValue, c, "请指定部岗位与指标关联关系!")
return
}
for _, v := range receivedValue.OrgList {
if v.Id == "" {
publicmethod.Result(1, receivedValue, c, "存在未选择的部门!")
return
} else {
if len(v.Child) < 1 {
publicmethod.Result(1, receivedValue, c, "存在未选择的岗位!")
return
} else {
for _, vc := range v.Child {
if vc.Id == "" {
publicmethod.Result(1, receivedValue, c, "存在未选择的岗位!")
return
} else {
if len(vc.Child) < 1 {
publicmethod.Result(1, receivedValue, c, "存在未选择的提报人!")
return
} else {
for _, vvc := range vc.Child {
if vvc.Id == "" {
publicmethod.Result(1, receivedValue, c, "存在未选择的提报人!")
return
}
}
}
}
}
}
}
}
for _, v := range receivedValue.OrgList { //抽离部门数据
departId, _ := strconv.ParseInt(v.Id, 10, 64)
var postListId []int64
for _, vc := range v.Child { //抽离岗位数据
postId, _ := strconv.ParseInt(vc.Id, 10, 64)
postListId = append(postListId, postId)
SyncSeting.Add(1)
go DepartTargetAboutPost(targetCont.Dimension, targetCont.Id, 0, 0, departId, postId, 1, targetCont.Type, 1)
var peopleListId []int64
for _, vvc := range vc.Child { //抽离人员
peoId, _ := strconv.ParseInt(vvc.Id, 10, 64)
peopleListId = append(peopleListId, peoId)
SyncSeting.Add(1)
go BeparTargetAboutPostMan(targetCont.Dimension, targetCont.Id, 0, 0, departId, postId, peoId, 1, targetCont.Type, 1)
}
if len(peopleListId) > 0 {
SyncSeting.Add(1)
go ClearTargetDepartAboutPostMan(targetCont.Dimension, targetCont.Id, 0, 0, departId, postId, peopleListId, 1, targetCont.Type, 1)
}
}
if len(postListId) > 0 {
//清理不需要的岗位关联
SyncSeting.Add(1)
go ClearTargetDepartAboutPost(targetCont.Dimension, targetCont.Id, 0, 0, departId, postListId, 1, targetCont.Type, 1)
}
}
SyncSeting.Wait()
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 13:55:26
@ 功能: 清理部门指标不在关联的岗位提报人
@ 参数
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#postId 岗位
#manKey 岗位
#typeInt 级别1部门级2岗位级
#class 属性1定性考核2定量考核
#level 类型1指标2子目标3细则
@ 返回值
#
@ 方法原型
#ClearTargetDepartAboutPostMan(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId int64, manKey []int64, typeInt, class, level int)
*/
func ClearTargetDepartAboutPostMan(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId int64, manKey []int64, typeInt, class, level int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if level == 0 {
level = 1
}
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where("`target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND `department_id` = ? AND `post_id` = ? AND `type` = ? AND `type_level` = ?", targetId, targetSunId, targetBylaws, departmentId, postId, typeInt, level).Not(map[string]interface{}{"man_key": manKey}).Updates(&otherSaveData)
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 14:09:41
@ 功能: 处理部门指标关联岗位提报人关系
@ 参数
#
@ 返回值
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#postId 岗位
#typeInt 类型1公司级2部门级
#manKey 用户Key
#class 属性1定性考核2定量考核
#typeLevel 级别1指标2子目标3细则
@ 方法原型
#func BeparTargetAboutPostMan(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId, manKey int64, typeInt, class, typeLevel int)
*/
func BeparTargetAboutPostMan(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId, manKey int64, typeInt, class, typeLevel int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if typeLevel == 0 {
typeLevel = 1
}
var manCont modelshr.PersonArchives
manCont.GetCont(map[string]interface{}{"`key`": manKey}, "`maindeparment`")
var targetReporCont modelskpi.TargetReport
err := targetReporCont.GetCont(map[string]interface{}{"`type_level`": typeLevel, "`type`": typeInt, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": targetBylaws, "`department_id`": departmentId, "`post_id`": postId, "man_key": manKey})
if err != nil {
//不存在,新增
var tarReportContAdd modelskpi.TargetReport
tarReportContAdd.Dimension = dimensionId //维度
tarReportContAdd.TargetId = targetId //指标ID"`
tarReportContAdd.TargetSunId = targetSunId //子目标"`
tarReportContAdd.TargetBylaws = targetBylaws //指标细则"`
tarReportContAdd.DepartmentId = departmentId //部门ID"`
tarReportContAdd.PostId = postId //岗位ID"`
tarReportContAdd.Type = typeInt //类型(1:公司级;2:部门级)"`
tarReportContAdd.State = 1 //状态(1:启用;2:禁用;3:删除)"`
tarReportContAdd.ReportPerson = manKey //上报人"`
tarReportContAdd.ManDepartment = manCont.MainDeparment //提报人所在部门"`
tarReportContAdd.Time = time.Now().Unix() //写入时间"`
tarReportContAdd.Class = class //1:定性考核;2:定量考核"`
tarReportContAdd.Level = typeLevel //1:指标;2:子目标;3:细则
overall.CONSTANT_DB_KPI.Create(&tarReportContAdd)
} else {
//存在编辑
if targetReporCont.State != 1 {
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
if manCont.MainDeparment != targetReporCont.ManDepartment {
otherSaveData["`man_department`"] = manCont.MainDeparment
}
otherSaveData["`time`"] = time.Now().Unix()
var editTarReportCont modelskpi.TargetReport
editTarReportCont.EiteCont(map[string]interface{}{"`id`": targetReporCont.Id}, otherSaveData)
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 13:55:26
@ 功能: 清理部门指标不在关联的岗位
@ 参数
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#postId 岗位
#typeInt 类型1指标2子目标3细则
#class 属性1定性考核2定量考核
#level 级别1部门级2岗位级
@ 返回值
#
@ 方法原型
#ClearTargetDepartAboutPost(dimensionId, targetId, targetSunId, targetBylaws, departmentId int64, postId []int64, typeInt, class, level int)
*/
func ClearTargetDepartAboutPost(dimensionId, targetId, targetSunId, targetBylaws, departmentId int64, postId []int64, typeInt, class, level int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if level == 0 {
level = 1
}
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where("`post_id` > 0 AND `level` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND `type` = ? AND department_id = ?", level, targetId, targetSunId, targetBylaws, typeInt, departmentId).Not(map[string]interface{}{"post_id": postId}).Updates(&otherSaveData)
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 13:35:06
@ 功能: 部门指标关联岗位
@ 参数
#dimensionId 维度
#targetId 指标
#targetSunId 栏目
#targetBylaws 细则
#departmentId 部门
#postId 岗位
#typeInt 类型1指标2子目标3细则
#class 属性1定性考核2定量考核
#level 级别1部门级2岗位级
@ 返回值
#
@ 方法原型
#func DepartTargetAboutPost(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId int64, typeInt, class, level int)
*/
func DepartTargetAboutPost(dimensionId, targetId, targetSunId, targetBylaws, departmentId, postId int64, typeInt, class, level int) {
defer SyncSeting.Done()
if typeInt == 0 {
typeInt = 1
}
if class == 0 {
class = 1
}
if level == 0 {
level = 1
}
var targetDeparCont modelskpi.TargetDepartment
err := targetDeparCont.GetCont(map[string]interface{}{"`level`": level, "`type`": typeInt, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": targetBylaws, "`department_id`": departmentId, "`post_id`": postId})
if err != nil {
//不存在新增
var tarDepartCont modelskpi.TargetDepartment
tarDepartCont.Dimension = dimensionId
tarDepartCont.TargetId = targetId //指标ID"`
tarDepartCont.TargetSunId = targetSunId //子目标"`
tarDepartCont.TargetBylaws = targetBylaws //指标细则"`
tarDepartCont.Type = typeInt //类型(1:指标;2:子目标;3:细则)"`
tarDepartCont.DepartmentId = departmentId //部门ID"`
tarDepartCont.PostId = postId //岗位ID"`
tarDepartCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
tarDepartCont.Time = time.Now().Unix() //写入时间"`
tarDepartCont.Class = class //1:定性考核;2:定量考核"`
tarDepartCont.Level = level //级别(1:部门级;2:岗位级)"`
overall.CONSTANT_DB_KPI.Create(&tarDepartCont)
} else {
//存在修改状态
if targetDeparCont.State != 1 {
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
var editTarDepartCont modelskpi.TargetDepartment
editTarDepartCont.EiteCont(map[string]interface{}{"`id`": targetDeparCont.Id}, otherSaveData)
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-09 14:53:04
@ 功能: 获取部门指标关联的岗位及提报人
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) GetTargetRelevantPostOfReport(c *gin.Context) {
var receivedValue publicmethod.PublicId
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, receivedValue, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c, "请输入指标ID!!")
return
}
var targetCont modelskpi.EvaluationTarget
err = targetCont.GetCont(map[string]interface{}{"`et_id`": receivedValue.Id}, "`et_id`", "`et_title`")
if err != nil {
publicmethod.Result(107, receivedValue, c)
return
}
var sendData []LoopStructEs
// sendData.Id = receivedValue.Id
//获取关联岗位的部门
var departIdList []int64
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = 1 AND `type` = 1 AND `target_sun_id` = 0 AND `target_bylaws` = 0 AND `post_id` > 0 AND `target_id` = ?", targetCont.Id).Find(&departIdList).Error
if err != nil || len(departIdList) < 1 {
publicmethod.Result(107, receivedValue, c)
return
}
for _, v := range departIdList {
var departList LoopStructEs
departList.Id = strconv.FormatInt(v, 10)
var orgCont modelshr.AdministrativeOrganization
orgCont.GetCont(map[string]interface{}{"`id`": v}, "`number`", "`name`")
departList.Name = orgCont.Name
_, _, departmentId, _, _ := publicmethod.GetOrgStructure(v)
if departmentId != v {
var orgMainCont modelshr.AdministrativeOrganization
orgMainCont.GetCont(map[string]interface{}{"`id`": departmentId}, "`number`", "`name`")
departList.Name = fmt.Sprintf("%v-%v", orgMainCont.Name, orgCont.Name)
}
departList.Number = orgCont.Number
departList.Child = departTargetPost(targetCont.Id, v)
//获取相关岗位
sendData = append(sendData, departList)
}
publicmethod.Result(0, sendData, c)
}
// 获取部门指标关联岗位
/*
#targetId 指标ID
#departId 部门ID
*/
func departTargetPost(targetId, departId int64) (postListCont []LoopStructEs) {
var postIdList []int64
err := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = 1 AND `type` = 1 AND `target_sun_id` = 0 AND `target_bylaws` = 0 AND `post_id` > 0 AND `target_id` = ? AND `department_id` = ?", targetId, departId).Find(&postIdList).Error
if err != nil || len(postIdList) < 1 {
return
}
for _, v := range postIdList {
var postList LoopStructEs
postList.Id = strconv.FormatInt(v, 10)
var orgCont modelshr.Position
orgCont.GetCont(map[string]interface{}{"`id`": v}, "`number`", "`name`")
postList.Number = orgCont.Number
postList.Name = orgCont.Name
postList.Child, _ = departTargetPostPrte(targetId, departId, v)
postListCont = append(postListCont, postList)
}
return
}
//获取关联岗位提报人员
/*
#targetId 指标ID
#departId 部门ID
#postId 岗位Id
*/
func departTargetPostPrte(targetId, departId, postId int64) (manListCont []LoopStructEs, manKeyList []string) {
var manKey []int64
err := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = 1 AND `type_level` = 1 AND `target_sun_id` = 0 AND `target_bylaws` = 0 AND `post_id` > 0 AND `target_id` = ? AND `department_id` = ? AND `post_id` =?", targetId, departId, postId).Find(&manKey).Error
if err != nil || len(manKey) < 1 {
return
}
for _, v := range manKey {
var postList LoopStructEs
idStr := strconv.FormatInt(v, 10)
postList.Id = idStr
var orgCont modelshr.PersonArchives
orgCont.GetCont(map[string]interface{}{"`key`": v}, "`number`", "`name`")
postList.Number = orgCont.Number
postList.Name = orgCont.Name
manKeyList = append(manKeyList, idStr)
manListCont = append(manListCont, postList)
}
return
}