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.

1967 lines
74 KiB

package postpc
import (
"fmt"
"key_performance_indicators/api/version1/departmentseting/departmentpc"
"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) GetPostTarget(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
}
var postTargetCont modelskpi.PostTarget
err = postTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
var sendData getPostOneTarget
sendData.Id = postTargetCont.Id
sendData.Title = postTargetCont.Title //标题"`
sendData.Type = postTargetCont.Type //1:定性考核;2:定量考核"`
sendData.State = postTargetCont.State //:状态(1:启用;2:禁用;3:删除)"`
sendData.Time = postTargetCont.Time //创建时间"`
sendData.Share = postTargetCont.Share //1:共用;2:私用"`
sendData.ReleDepart = postTargetCont.ReleDepart //相关部门"`
sendData.DepartmentsPost = postTargetCont.DepartmentsPost //相关岗位"`
sendData.Dimension = postTargetCont.Dimension //维度"`
sendData.DimensionStr = strconv.FormatInt(postTargetCont.Dimension, 10)
sendData.Key = postTargetCont.Key //UUID"`
sendData.Report = postTargetCont.Report //上报人"`
sendData.Unit = postTargetCont.Unit //单位"`
sendData.Cycle = postTargetCont.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"`
sendData.Cycleattr = postTargetCont.Cycleattr //辅助计数"`
sendData.ScoringMethod = postTargetCont.ScoringMethod //计分方式(1:自动;2:手动)"`
sendData.VisibleRange = postTargetCont.VisibleRange //可见范围"`
sendData.VisibleGroup = postTargetCont.VisibleGroup //可见范围(集团)"`
sendData.OtherPostTarget, sendData.PostName, _ = getOrgOfPostReport(postTargetCont.Dimension, postTargetCont.Id, 0, 0, postTargetCont.State, 1, 2)
// _, sendData.RelevantPostsMan, _ = getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id, 2)
publicmethod.Result(0, sendData, c)
}
/*
获取行政组织及岗位提报人
#dimensionId 维度
#targetId 指标
#sunTargetId 栏目
#targetBylawsId 细则
#state 状态
#typeInt 类型(1:指标;2:子目标;3:细则)
#level 级别(1:部门级;2:岗位级)
*/
func getOrgOfPostReport(dimensionId, targetId, sunTargetId, targetBylawsId int64, state, typeInt, level int) (postPeopleList []OtherPostTargetCont, postName string, err error) {
var tarDepartList []modelskpi.TargetDepartment
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Select("`department_id`,`post_id`").Where("`state` = ? AND `level` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", state, level, dimensionId, targetId, sunTargetId, targetBylawsId).Find(&tarDepartList).Error
var postIsAry []int64
if err == nil && len(tarDepartList) > 0 {
var postId int64
for _, v := range tarDepartList {
if publicmethod.IsInTrue[int64](v.PostId, postIsAry) == false {
postIsAry = append(postIsAry, v.PostId)
var postPeopleCont OtherPostTargetCont
postPeopleCont.OrgId = v.DepartmentId
postPeopleCont.PostId = v.PostId
_, postPeopleCont.Operator, _ = getTargetAboutPostMan(v.DepartmentId, v.PostId, dimensionId, targetId, level, typeInt)
postPeopleList = append(postPeopleList, postPeopleCont)
postId = v.PostId
}
}
if postId != 0 {
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": postId}, "`name`")
postName = postCont.Name
}
}
return
}
/*
获取岗位指标相关岗位
@departmentId 部门Id
@dimensionId 维度
@targetId 指标
@typeInt 级别(1:部门级;2:岗位级)
@level 1:指标;2:子目标;3:细则
func getTargetAboutPost(departmentId, dimensionId, targetId int64, level int) (postId []int64, postPeopleList []postPeople, err error)
*/
func getTargetAboutPost(departmentId, dimensionId, targetId int64, typeInt, level int) (postId []int64, postPeopleList []postPeople, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `type` = ? AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ?", level, typeInt, departmentId, dimensionId, targetId).Find(&postId).Error
if len(postId) > 0 {
for i := 0; i < len(postId); i++ {
var postmanCont postPeople
postmanCont.Id = strconv.FormatInt(postId[i], 10)
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": postId[i]}, "`name`")
postmanCont.Name = postCont.Name
_, postmanCont.Operator, _ = getTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId, typeInt, level)
postPeopleList = append(postPeopleList, postmanCont)
}
}
return
}
/*
获取岗位指标相关岗位提报人
@departmentId 部门Id
@postid 岗位
@dimensionId 维度
@targetId 指标
@type 级别(1:部门级;2:岗位级)
@level 1:指标;2:子目标;3:细则
*/
func getTargetAboutPostMan(departmentId, postid, dimensionId, targetId int64, typeInt, level int) (peopleId []int64, postPeople []string, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = ? AND `type_level` = ? AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ?", typeInt, level, departmentId, postid, dimensionId, targetId).Find(&peopleId).Error
if len(peopleId) > 0 {
for i := 0; i < len(peopleId); i++ {
postPeople = append(postPeople, strconv.FormatInt(peopleId[i], 10))
}
}
return
}
// 添加岗位指标
func (a *ApiMethod) AddPostTarget(c *gin.Context) {
var receivedValue addPostTarget
c.ShouldBindJSON(&receivedValue)
if receivedValue.Title == "" {
publicmethod.Result(1, receivedValue, c, "请输入指标名称!")
return
}
if receivedValue.Type == 0 {
receivedValue.Type = 2
}
if receivedValue.ScoringMethod == 0 {
receivedValue.ScoringMethod = 1
}
if receivedValue.RelevantDepartments == "" {
publicmethod.Result(1, receivedValue, c, "请选择该指标归属部门!")
return
}
if len(receivedValue.RelevantPostsMan) < 1 {
publicmethod.Result(1, receivedValue, c, "请选择该指标归属岗位!")
return
}
if receivedValue.Dimension == "" {
publicmethod.Result(1, receivedValue, c, "请选择指标归属维度!")
return
}
if receivedValue.Unit == "" {
publicmethod.Result(1, receivedValue, c, "请输入该指标计算单位!")
return
}
if receivedValue.Cycle == 0 {
receivedValue.Cycle = 1
}
if receivedValue.CycleAttr == 0 {
receivedValue.CycleAttr = 1
}
var saveData modelskpi.PostTarget
saveData.Title = receivedValue.Title //标题"`
saveData.Type = receivedValue.Type //1:定性考核;2:定量考核"`
saveData.State = 1 //状态(1:启用;2:禁用;3:删除)"`
saveData.Time = time.Now().Unix() //创建时间"`
saveData.Share = 2 //1:共用;2:私用"`
departmentId, _ := strconv.ParseInt(receivedValue.RelevantDepartments, 10, 64)
saveData.ReleDepart = departmentId //相关部门"`
// saveData.DepartmentsPost = strings.Join(receivedValue.DepartmentsPost, ",") //相关岗位"`
dimensionId, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
saveData.Dimension = dimensionId //维度"`
saveData.Key = publicmethod.GetUUid(1) //UUID"`
// saveData.Report = strings.Join(receivedValue.Report, ",") //上报人"`
saveData.Unit = receivedValue.Unit //单位"`
saveData.Cycle = receivedValue.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"`
saveData.Cycleattr = receivedValue.CycleAttr //辅助计数"`
saveData.ScoringMethod = receivedValue.ScoringMethod //计分方式(1:自动;2:手动)"`
saveData.VisibleRange = strings.Join(receivedValue.VisibleRange, ",") //可见范围"`
saveData.VisibleGroup = strings.Join(receivedValue.VisibleGroup, ",") //可见范围(集团)"`
//获取岗位与提报人
var departAny []string
var peopletAny []string
for _, v := range receivedValue.RelevantPostsMan {
if publicmethod.IsInTrue[string](v.Id, departAny) == false {
departAny = append(departAny, v.Id)
}
if len(v.Operator) > 0 {
for _, ov := range v.Operator {
if publicmethod.IsInTrue[string](ov, peopletAny) == false {
peopletAny = append(peopletAny, ov)
}
}
}
}
saveData.DepartmentsPost = strings.Join(departAny, ",") //相关岗位"`
saveData.Report = strings.Join(peopletAny, ",") //上报人"`
err := overall.CONSTANT_DB_KPI.Create(&saveData).Error
if err != nil {
publicmethod.Result(104, err, c)
return
}
//关联部门岗位
if len(departAny) > 0 {
syncSetinges.Add(1)
go EditTargetTableDimenAboutPostOfDepart(dimensionId, saveData.Id, 0, 0, departmentId, departAny, 2, receivedValue.Type)
}
//关联考核岗位和提报人
for _, dv := range receivedValue.RelevantPostsMan {
postid, _ := strconv.ParseInt(dv.Id, 10, 64)
syncSetinges.Add(1)
go DepartAboutPostTargetReport(dimensionId, saveData.Id, 0, 0, departmentId, postid, dv.Operator, 2, receivedValue.Type)
}
syncSetinges.Wait()
publicmethod.Result(0, err, c)
}
/*
编辑指标、栏目、细则关联部门
协程处理
部门指标岗位提报人关联通用函数
@dimensionId 维度
@targetId 指标ID
@targetSunId 栏目ID
@bylawsId 指标细则
@departmentId 接受考核部门
@postId 岗位
@class 级别(1:部门级;2:岗位级)
@nature 1:定性考核;2:定量考核
EditTargetTableDimenAboutPostOfDepart(dimensionId, targetId, targetSunId, bylawsId, departmentId int64, postId []string, class, nature int)
*/
func EditTargetTableDimenAboutPostOfDepart(dimensionId, targetId, targetSunId, bylawsId, departmentId int64, postId []string, class, nature int) {
defer syncSetinges.Done()
//将不属于的信息禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
//判断岗位是否存在
where := publicmethod.MapOut[string]()
where["`type`"] = class
if targetId != 0 {
where["`dimension_id`"] = dimensionId
}
if targetId != 0 {
where["`target_id`"] = targetId
}
if targetSunId != 0 {
where["`target_sun_id`"] = targetSunId
}
if bylawsId != 0 {
where["`target_bylaws`"] = bylawsId
}
if departmentId != 0 {
where["`department_id`"] = departmentId
}
if len(postId) < 1 {
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(where).Updates(&otherSaveData)
} else {
//获取关联部门
var aboutDepartment []string
for _, v := range postId {
if publicmethod.IsInTrue[string](v, aboutDepartment) == false {
aboutDepartment = append(aboutDepartment, v)
//判断该岗位是否已经关联
var tarDeparCont modelskpi.TargetDepartment
judgeAboutErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Select("`id`,`state`").Where(where).Where("`post_id` = ?", v).First(&tarDeparCont).Error
if judgeAboutErr == nil {
tarDeparCont.EiteCont(map[string]interface{}{"`id`": tarDeparCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
} else {
xiZe := 3
if targetId != 0 && targetSunId != 0 && bylawsId == 0 {
xiZe = 2
} else if targetId != 0 && targetSunId == 0 && bylawsId == 0 {
xiZe = 1
}
tarDeparCont.Dimension = dimensionId //维度"`
tarDeparCont.TargetId = targetId //指标ID"`
tarDeparCont.TargetSunId = targetSunId //子目标"`
tarDeparCont.TargetBylaws = bylawsId //指标细则"`
tarDeparCont.Type = xiZe //类型(1:指标;2:子目标;3:细则)"`
tarDeparCont.DepartmentId = departmentId //部门ID"`
postIdInt64, _ := strconv.ParseInt(v, 10, 64)
tarDeparCont.PostId = postIdInt64 //岗位ID"`
tarDeparCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
tarDeparCont.Time = time.Now().Unix() //写入时间"`
tarDeparCont.Class = nature //1:定性考核;2:定量考核"`
tarDeparCont.Level = class //级别(1:部门级;2:岗位级)"`
overall.CONSTANT_DB_KPI.Create(&tarDeparCont)
}
}
}
//清除不需要关联的部门
if len(aboutDepartment) > 0 {
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where(where).Not(map[string]interface{}{"`post_id`": aboutDepartment}).Updates(&otherSaveData)
}
}
}
// 编辑岗位指标
func (a *ApiMethod) EditPostTarget(c *gin.Context) {
var receivedValue editPostTargetCont
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "参数错误!")
return
}
where := publicmethod.MapOut[string]()
where["`id`"] = receivedValue.Id
var postTargetCont modelskpi.PostTarget
err := postTargetCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
saveData := publicmethod.MapOut[string]()
if receivedValue.Title != "" && receivedValue.Title != postTargetCont.Title {
saveData["title"] = receivedValue.Title
}
if receivedValue.Type != 0 && receivedValue.Type != postTargetCont.Type {
saveData["type"] = receivedValue.Type
}
if receivedValue.ScoringMethod != 0 && receivedValue.ScoringMethod != postTargetCont.ScoringMethod {
saveData["scoring_method"] = receivedValue.ScoringMethod
}
if receivedValue.RelevantDepartments != "" {
departmentId, _ := strconv.ParseInt(receivedValue.RelevantDepartments, 10, 64)
if departmentId != postTargetCont.ReleDepart {
saveData["rele_depart"] = departmentId
}
}
if receivedValue.Dimension != "" {
dimensionId, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
if dimensionId != postTargetCont.Dimension {
saveData["dimension"] = dimensionId
}
}
if receivedValue.Unit != "" && receivedValue.Unit != postTargetCont.Unit {
saveData["unit"] = receivedValue.Unit
}
if receivedValue.Cycle != 0 && receivedValue.Cycle != postTargetCont.Cycle {
saveData["cycle"] = receivedValue.Cycle
}
if receivedValue.CycleAttr != 0 && receivedValue.CycleAttr != postTargetCont.Cycleattr {
saveData["cycleattr"] = receivedValue.CycleAttr
}
if len(receivedValue.VisibleRange) > 0 {
visibleRangeStr := strings.Join(receivedValue.VisibleRange, ",")
if visibleRangeStr != postTargetCont.VisibleRange {
saveData["visible_range"] = visibleRangeStr
}
}
if len(receivedValue.VisibleGroup) > 0 {
visibleGroupStr := strings.Join(receivedValue.VisibleGroup, ",")
if visibleGroupStr != postTargetCont.VisibleGroup {
saveData["visible_group"] = visibleGroupStr
}
}
//获取岗位与提报人
var departAny []string
var peopletAny []string
for _, v := range receivedValue.RelevantPostsMan {
if publicmethod.IsInTrue[string](v.Id, departAny) == false {
departAny = append(departAny, v.Id)
}
if len(v.Operator) > 0 {
for _, ov := range v.Operator {
if publicmethod.IsInTrue[string](ov, peopletAny) == false {
peopletAny = append(peopletAny, ov)
}
}
}
}
if len(departAny) > 0 {
departPostStr := strings.Join(departAny, ",")
if departPostStr != postTargetCont.DepartmentsPost {
saveData["departments_post"] = departPostStr
//关联部门岗位
if len(departAny) > 0 {
syncSetinges.Add(1)
go EditTargetTableDimenAboutPostOfDepart(postTargetCont.Dimension, postTargetCont.Id, 0, 0, postTargetCont.ReleDepart, departAny, 2, postTargetCont.Type)
}
}
}
if len(peopletAny) > 0 {
reportStr := strings.Join(peopletAny, ",")
if reportStr != postTargetCont.Report {
saveData["report"] = reportStr
//关联考核岗位和提报人
for _, dv := range receivedValue.RelevantPostsMan {
postid, _ := strconv.ParseInt(dv.Id, 10, 64)
syncSetinges.Add(1)
go DepartAboutPostTargetReport(postTargetCont.Dimension, postTargetCont.Id, 0, 0, postTargetCont.ReleDepart, postid, dv.Operator, 2, postTargetCont.Type)
}
}
}
if len(saveData) > 0 {
saveData["time"] = time.Now().Unix()
saveErr := postTargetCont.EiteCont(where, saveData)
if saveErr != nil {
publicmethod.Result(106, saveErr, c)
} else {
publicmethod.Result(0, saveErr, c)
}
} else {
publicmethod.Result(0, err, c)
}
}
// 获取岗位指标关联部门相关岗位及提报人
func (a *ApiMethod) GetTargetAboutDepartToPostMan(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
}
var postTargetCont modelskpi.PostTarget
err = postTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
_, outData, _ := getTargetAboutPost(postTargetCont.ReleDepart, postTargetCont.Dimension, postTargetCont.Id, 2, 1)
publicmethod.Result(0, outData, c)
}
// 根据指标添加岗位细则
func (a *ApiMethod) AddPostTargetCont(c *gin.Context) {
var receivedValue addPostContTarget
c.ShouldBindJSON(&receivedValue)
if receivedValue.TargetId == "" {
publicmethod.Result(1, receivedValue, c, "请选择岗位指标!")
return
}
if receivedValue.DepartmentId == "" {
publicmethod.Result(1, receivedValue, c, "请选择行政组织!")
return
}
if receivedValue.TargetSunTitle == "" {
publicmethod.Result(1, receivedValue, c, "请输入子栏目名称!")
return
}
if len(receivedValue.PostId) < 1 {
publicmethod.Result(1, receivedValue, c, "请选择岗位!")
return
}
if len(receivedValue.List) < 1 {
publicmethod.Result(1, receivedValue, c, "请输入指标细则!")
return
}
xiZeIsTrue := 1
for _, v := range receivedValue.List {
if v.Title == "" {
xiZeIsTrue = 2
break
}
if v.ReferenceScore == "" {
xiZeIsTrue = 2
break
}
if v.Unit == "" {
xiZeIsTrue = 2
break
}
}
if xiZeIsTrue != 1 {
publicmethod.Result(1, receivedValue, c, "请检查你输入的指标细则!其中有不符合标准的细则!")
return
}
targetSunIdInt, _ := strconv.ParseInt(receivedValue.TargetId, 10, 64)
deartmentIdInt, _ := strconv.ParseInt(receivedValue.DepartmentId, 10, 64)
//获取指标信息
var getTargetCont modelskpi.PostTarget
getTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.TargetId})
_, postPeople, _ := getTargetAboutPost(deartmentIdInt, getTargetCont.Dimension, getTargetCont.Id, 2, 3)
//指标子栏目
var sunTargetCont modelskpi.PostSonTarget
sunErr := sunTargetCont.GetCont(map[string]interface{}{"`title`": receivedValue.TargetSunTitle, "`parent_id`": receivedValue.TargetId, "depart": receivedValue.DepartmentId}, "`id`")
if sunErr != nil {
sunTargetCont.Title = receivedValue.TargetSunTitle //标题"`
sunTargetCont.ParentId = targetSunIdInt //归属指标"`
sunTargetCont.Time = time.Now().Unix() //创建时间"`
sunTargetCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
sunTargetCont.Depart = receivedValue.DepartmentId //关联部门"`
sunTargetCont.DepartPost = strings.Join(receivedValue.PostId, ",")
sunTargetErr := overall.CONSTANT_DB_KPI.Create(&sunTargetCont).Error
if sunTargetErr != nil {
publicmethod.Result(104, sunTargetErr, c)
return
}
} else {
if sunTargetCont.State != 1 {
sunTargetCont.EiteCont(map[string]interface{}{"`id`": sunTargetCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
}
}
if sunTargetCont.Id == 0 {
publicmethod.Result(104, sunTargetCont, c)
return
}
//考核细则写入
for _, lv := range receivedValue.List {
if lv.Class == 0 {
lv.Class = 1
}
if len(lv.Inspect) == 0 {
lv.Inspect = append(lv.Inspect, "1")
}
if lv.Cycle == 0 {
lv.Cycle = getTargetCont.Cycle
}
if lv.CycleAttr == 0 {
lv.CycleAttr = getTargetCont.Cycleattr
}
if lv.Frequency == 0 {
lv.Frequency = 1
}
var minScoreInt int64
var maxScoreInt int64
scoreAry := strings.Split(lv.ReferenceScore, "-")
scoreLen := len(scoreAry)
// fmt.Printf("ScoreAry:%v----------->%v------------>%v------------>%v\n", ReferenceScore, scoreLen, scoreAry[0], scoreAry)
if scoreLen > 0 {
if scoreLen == 1 {
maxScore, _ := strconv.ParseFloat(scoreAry[0], 64)
// zhhh := maxScore * 100
// zhuanStr := strconv.FormatFloat(zhhh, 'f', -1, 64)
maxScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
minScoreInt = 0
} else {
minScore, _ := strconv.ParseFloat(scoreAry[0], 64)
maxScore, _ := strconv.ParseFloat(scoreAry[scoreLen-1], 64)
minScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(minScore*100, 'f', -1, 64), 10, 64)
maxScoreInt, _ = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
}
} else {
minScoreInt = 0
maxScoreInt = 0
}
var minMoney int64 //罚款或奖励最高金额
var maxMoney int64 //罚款或奖励最新金额
moneyAry := strings.Split(lv.CashStandard, "-")
moneyAryLen := len(moneyAry)
if moneyAryLen > 0 {
if moneyAryLen == 1 {
maxMoneyEs, _ := strconv.ParseFloat(moneyAry[0], 64)
maxMoney, _ = strconv.ParseInt(strconv.FormatFloat(maxMoneyEs*100, 'f', -1, 64), 10, 64)
minMoney = 0
} else {
maxMoneyEs, _ := strconv.ParseFloat(moneyAry[moneyAryLen-1], 64)
maxMoney, _ = strconv.ParseInt(strconv.FormatFloat(maxMoneyEs*100, 'f', -1, 64), 10, 64)
minMoneyEs, _ := strconv.ParseFloat(moneyAry[0], 64)
minMoney, _ = strconv.ParseInt(strconv.FormatFloat(minMoneyEs*100, 'f', -1, 64), 10, 64)
}
} else {
minMoney = 0
maxMoney = 0
}
var saveCont modelskpi.PostTargetDetails
saveCont.Title = lv.Title //指标细则"`
saveCont.Content = lv.Explain //备注说明"`
saveCont.ParentId = targetSunIdInt //归属指标栏目"`
saveCont.ParentIdSun = sunTargetCont.Id //归属指标子栏目"`
saveCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
saveCont.AddTime = time.Now().Unix() //制定时间"`
saveCont.MinScore = minScoreInt //最小分*100保存"`
saveCont.MaxScore = maxScoreInt //最大分*100保存"`
saveCont.Company = lv.Unit //单位"`
saveCont.AddReduce = lv.Class //1:减少;2:增加;3:无属性,现场确认加或减"`
saveCont.CensorType = strings.Join(lv.Inspect, ",") //检查方式"`
saveCont.CensorCont = lv.Evidence //客观证据"`
saveCont.CensorRate = lv.Frequency //检查频次"`
saveCont.Cycles = lv.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"`
saveCont.CycleAttres = lv.CycleAttr //辅助计数"`
saveCont.Paretment = strconv.FormatInt(deartmentIdInt, 10) //接受考核的部门"`
// saveCont.ParetmentPost = strings.Join(requestData.PostId, ",") //接受考核的部门岗位"`
// saveCont.Reportary = strings.Join(lv.ReportAry, ",") //接受考核的部门岗位"`
saveCont.Punishmode = lv.PunishMode //处罚或奖励方式 1:分数;2:现金;3:分数加现金
saveCont.Minmoney = minMoney //最高罚款*100保存"`
saveCont.Maxmoney = maxMoney //最低罚款*100保存"`
syncSeting.Add(1)
go addDetaonsCont(saveCont, lv.RelevantPostsMan, postPeople, getTargetCont.Dimension)
}
syncSeting.Wait()
//获取子栏目关联岗位
var postIdInt64 []int64
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ?", 2, deartmentIdInt, getTargetCont.Dimension, getTargetCont.Id, sunTargetCont.Id).Find(&postIdInt64)
if len(postIdInt64) > 0 {
var postIdStr []string
for si := 0; si < len(postIdInt64); si++ {
postIdIntToStr := strconv.FormatInt(postIdInt64[si], 10)
postIdStr = append(postIdStr, postIdIntToStr)
}
sunTargetCont.EiteCont(map[string]interface{}{"`id`": sunTargetCont.Id}, map[string]interface{}{"`depart_post`": strings.Join(postIdStr, ","), "`time`": time.Now().Unix()})
}
publicmethod.Result(0, postIdInt64, c)
}
/*
添加指标细则
@saveCont 指标细则数据
@postMan 指标细则岗位提报人键对
@targetPostMan 指标设定提报人
@dimensionId 维度
*/
func addDetaonsCont(saveCont modelskpi.PostTargetDetails, postMan, targetPostMan []postPeople, dimensionId int64) {
defer syncSeting.Done()
//获取岗位与提报人
var departAny []string
var peopletAny []string
var peoplePost []postDeasiteMan
for _, v := range postMan {
var peoPostCont postDeasiteMan
peoPostCont.Id = v.Id
if publicmethod.IsInTrue[string](v.Id, departAny) == false {
departAny = append(departAny, v.Id)
}
if len(v.Operator) > 0 {
for _, ov := range v.Operator {
if publicmethod.IsInTrue[string](ov, peopletAny) == false {
peopletAny = append(peopletAny, ov)
peoPostCont.Operator = append(peoPostCont.Operator, ov)
}
}
} else {
for _, tarv := range targetPostMan {
if tarv.Id == v.Id {
for _, otv := range tarv.Operator {
if publicmethod.IsInTrue[string](otv, peopletAny) == false {
peopletAny = append(peopletAny, otv)
peoPostCont.Operator = append(peoPostCont.Operator, otv)
}
}
}
}
}
peoplePost = append(peoplePost, peoPostCont)
}
saveCont.ParetmentPost = strings.Join(departAny, ",") //相关岗位"`
saveCont.Reportary = strings.Join(peopletAny, ",") //上报人"`
fmt.Printf("postMan------->%v--------targetPostMan------->%v--------departAny------->%v--------peopletAny------->%v\n", postMan, targetPostMan, departAny, peopletAny)
overall.CONSTANT_DB_KPI.Create(&saveCont)
fmt.Printf("postMan------->%v--------targetPostMan------->%v--------departAny------->%v--------peopletAny------->%v\n", postMan, targetPostMan, departAny, peopletAny)
//关联部门岗位
if len(departAny) > 0 {
paretmentIdInt, _ := strconv.ParseInt(saveCont.Paretment, 10, 64)
syncSetinges.Add(1)
go EditTargetTableDimenAboutPostOfDepart(dimensionId, saveCont.ParentId, saveCont.ParentIdSun, saveCont.Id, paretmentIdInt, departAny, 2, 1)
}
//关联考核岗位和提报人
for _, dv := range peoplePost {
operatorList := dv.Operator
if len(operatorList) < 1 {
for _, tarv := range targetPostMan {
if tarv.Id == dv.Id {
operatorList = tarv.Operator
}
}
}
postid, _ := strconv.ParseInt(dv.Id, 10, 64)
paretmentIdInts, _ := strconv.ParseInt(saveCont.Paretment, 10, 64)
syncSetinges.Add(1)
go DepartAboutPostTargetReport(dimensionId, saveCont.ParentId, saveCont.ParentIdSun, saveCont.Id, paretmentIdInts, postid, operatorList, 2, 1)
}
syncSetinges.Wait()
}
/*
协程处理
部门指标岗位提报人关联通用函数
@dimensionId 维度
@targetId 指标ID
@targetSunId 栏目ID
@bylawsId 指标细则
@departmentId 接受考核部门
@postId 岗位
@repart 提报人
@class 级别(1:部门级;2:岗位级)
@nature 1:定性考核;2:定量考核
func departAboutPostTargetReport(dimensionId, targetId, targetSunId, bylawsId, departmentId, postId int64, repart []loopStruct, class, nature int)
*/
// 根据指标获取岗位定性指标细则列表
func (a *ApiMethod) PostTargetSunList(c *gin.Context) {
var requestData lookPostTargetDeta
c.ShouldBindJSON(&requestData)
if requestData.Page == 0 {
requestData.Page = 1
}
if requestData.PageSize == 0 {
requestData.Page = 10
}
var postDetails []modelskpi.PostTargetDetails
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTargetDetails{}).Where("`state` BETWEEN 1 AND 2")
if requestData.Title != "" {
gormDb = gormDb.Where("`title` LIKE ?", "%"+requestData.Title+"%")
}
if requestData.DepartmentId != "" {
gormDb = gormDb.Where("`paretment` = ?", requestData.DepartmentId)
}
if requestData.TargetId != "" {
gormDb = gormDb.Where("`parentid` = ?", requestData.TargetId)
}
if requestData.Cycle != 0 {
gormDb = gormDb.Where("`cycle` = ?", requestData.Cycle)
}
if len(requestData.PostId) > 0 {
var findInSet []string
for _, ctv := range requestData.PostId {
findWher := fmt.Sprintf("FIND_IN_SET(%v,`paretment_post`)", ctv)
if publicmethod.IsInTrue[string](findWher, findInSet) == false {
findInSet = append(findInSet, findWher)
}
}
if len(findInSet) > 0 {
gormDb = gormDb.Where(strings.Join(findInSet, " OR "))
}
}
if len(requestData.PostId) > 0 {
var findInSetType []string
for _, ctvt := range requestData.Inspect {
findWherType := fmt.Sprintf("FIND_IN_SET(%v,`censor_type`)", ctvt)
if publicmethod.IsInTrue[string](findWherType, findInSetType) == false {
findInSetType = append(findInSetType, findWherType)
}
}
if len(findInSetType) > 0 {
gormDb = gormDb.Where(strings.Join(findInSetType, " OR "))
}
}
gormDb = publicmethod.PageTurningSettings(gormDb, requestData.Page, requestData.PageSize)
err := gormDb.Order("`parentid_sun` asc").Order("`id` desc").Find(&postDetails).Error
if err != nil {
publicmethod.Result(107, err.Error(), c)
return
}
var total int64
totalErr := gormDb.Count(&total).Error
if totalErr != nil {
total = 0
}
var sendDataAry []sendNaitonTargetDeiment
for _, v := range postDetails {
var sendDataCont sendNaitonTargetDeiment
sendDataCont.Id = v.Id
sendDataCont.Title = v.Title //指标细则"`
sendDataCont.Content = v.Content //指标说明"`
sendDataCont.ParentId = v.ParentId //归属指标栏目"`
sendDataCont.ParentIdSun = v.ParentIdSun //归属指标子栏目"`
sendDataCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
sendDataCont.AddTime = v.AddTime //制定时间"`
sendDataCont.MinScore = v.MinScore //最小分*100保存"`
sendDataCont.MaxScore = v.MaxScore //最大分*100保存"`
sendDataCont.Company = v.Company //单位"`
sendDataCont.AddReduce = v.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
sendDataCont.CensorType = v.CensorType //检查方式"`
sendDataCont.CensorCont = v.CensorCont //检查依据"`
sendDataCont.CensorRate = v.CensorRate // 检查频次"`
sendDataCont.Cycles = v.Cycles // 1:班;2:天;3:周;4:月;5:季度;6:年"`
sendDataCont.CycleAttres = v.CycleAttres //辅助计数"`
sendDataCont.Paretment = v.Paretment //接受考核的部门"`
sendDataCont.ParetmentPost = v.ParetmentPost //接受考核的部门岗位"`
sendDataCont.Reportary = v.Reportary //提报人"`
sendDataCont.Punishmode = v.Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金"`
sendDataCont.Maxmoney = v.Maxmoney //最高罚款"`
sendDataCont.Minmoney = v.Minmoney //最低罚款"`
var sonTargetCont modelskpi.PostSonTarget
sonTargetCont.GetCont(map[string]interface{}{"`id`": v.ParentIdSun}, "`title`")
sendDataCont.SonTargetTitle = sonTargetCont.Title
if v.MinScore != 0 {
sendDataCont.ReferenceScore = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(float64(v.MinScore)/100, 2), publicmethod.DecimalEs(float64(v.MaxScore)/100, 2))
} else {
sendDataCont.ReferenceScore = fmt.Sprintf("%v", publicmethod.DecimalEs(float64(v.MaxScore)/100, 2))
}
if v.Minmoney != 0 {
sendDataCont.CashStandard = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(float64(v.Minmoney)/100, 2), publicmethod.DecimalEs(float64(v.Maxmoney)/100, 2))
} else {
sendDataCont.CashStandard = fmt.Sprintf("%v", publicmethod.DecimalEs(float64(v.Maxmoney)/100, 2))
}
sendDataAry = append(sendDataAry, sendDataCont)
}
publicmethod.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(sendDataAry)), sendDataAry, c)
}
// 获取岗位子栏目详情
func (a *ApiMethod) GetSunTargetInfo(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, err, c)
return
}
var sonTargetCont modelskpi.PostSonTarget
err = sonTargetCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id})
if err != nil {
publicmethod.Result(107, err, c)
return
}
var sendData sendOneSonTargetCont
sendData.Id = sonTargetCont.Id
sendData.Title = sonTargetCont.Title //标题"`
sendData.ParentId = sonTargetCont.ParentId //归属指标"`
sendData.Time = sonTargetCont.Time //创建时间"`
sendData.State = sonTargetCont.State //状态(1:启用;2:禁用;3:删除)"`
sendData.Depart = sonTargetCont.Depart //关联部门"`
sendData.DepartPost = sonTargetCont.DepartPost //关联部门岗位"`
var departCont modelshr.AdministrativeOrganization
departCont.GetCont(map[string]interface{}{"`id`": sonTargetCont.Depart}, "`name`")
sendData.Department = departCont.Name
sendData.IdStr = strconv.FormatInt(sonTargetCont.Id, 10)
//获取提报岗位
var reportPost []int64
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = 2 AND `department_id` = ? AND `target_id` = ? AND `target_sun_id` = ?", sonTargetCont.Depart, sonTargetCont.ParentId, sonTargetCont.Id).Find(&reportPost).Error
if err == nil && len(reportPost) > 0 {
for i := 0; i < len(reportPost); i++ {
var postOfMan postOperator
postOfMan.Id = strconv.FormatInt(reportPost[i], 10)
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": reportPost[i]}, "`name`")
postOfMan.Name = postCont.Name
var operList operatorList
reportWhere := publicmethod.MapOut[string]()
reportWhere["`target_id`"] = sonTargetCont.ParentId
reportWhere["`target_sun_id`"] = sonTargetCont.Id
reportWhere["`department_id`"] = sonTargetCont.Depart
reportWhere["`post_id`"] = reportPost[i]
reportWhere["`state`"] = 1
_, operList.UserKey, _ = departmentpc.GetAboutReport(reportWhere, 2)
if len(operList.UserKey) > 0 {
for _, uv := range operList.UserKey {
var myCont modelshr.PersonArchives
myCont.GetCont(map[string]interface{}{"`key`": uv}, "`number`", "`name`", "`icon`")
var myInfo UserContList
myInfo.Id = uv
myInfo.Name = myCont.Name
myInfo.Number = myCont.Number
myInfo.Icon = myCont.Icon
operList.UserList = append(operList.UserList, myInfo)
}
}
postOfMan.Operator = operList
sendData.PostOfOperator = append(sendData.PostOfOperator, postOfMan)
}
}
publicmethod.Result(0, sendData, c)
}
// 编辑岗位子栏目
func (a *ApiMethod) EditSonTargetCont(c *gin.Context) {
var receivedValue editSonTargetPost
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "您输入的参数不正确!")
return
}
where := map[string]interface{}{"`id`": receivedValue.Id}
var sonTarCont modelskpi.PostSonTarget
err = sonTarCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
saveData := publicmethod.MapOut[string]()
if receivedValue.Name != "" && receivedValue.Name != sonTarCont.Title {
saveData["title"] = sonTarCont.Title
}
saveData["time"] = time.Now().Unix()
err = sonTarCont.EiteCont(map[string]interface{}{"`id`": sonTarCont.Id}, saveData)
var postTarCont modelskpi.PostTarget
postTarCont.GetCont(map[string]interface{}{"`id`": sonTarCont.ParentId}, "`dimension`")
if len(receivedValue.PostOfOperator) > 0 {
syncSeting.Add(1)
departInt, _ := strconv.ParseInt(sonTarCont.Depart, 10, 64)
go postSonTargetAboutOrder(postTarCont.Dimension, departInt, sonTarCont.ParentId, sonTarCont.Id, receivedValue.PostOfOperator)
}
syncSeting.Wait()
//获取子栏目关联岗位
var postIdInt64 []int64
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ?", 2, sonTarCont.Depart, postTarCont.Dimension, sonTarCont.ParentId, sonTarCont.Id).Find(&postIdInt64)
if len(postIdInt64) > 0 {
var postIdStr []string
for si := 0; si < len(postIdInt64); si++ {
postIdIntToStr := strconv.FormatInt(postIdInt64[si], 10)
postIdStr = append(postIdStr, postIdIntToStr)
}
sonTarCont.EiteCont(map[string]interface{}{"`id`": sonTarCont.Id}, map[string]interface{}{"`depart_post`": strings.Join(postIdStr, ","), "`time`": time.Now().Unix()})
}
if err != nil {
publicmethod.Result(106, err, c)
return
}
publicmethod.Result(0, err, c)
}
/*
岗位子栏目关联岗位操作
@dimensionId 维度
@departmentId 部门
@targetId 指标
@sonTargetId 子栏目
@postOfOperator 岗位与提报人
*/
func postSonTargetAboutOrder(dimensionId, departmentId, targetId, sonTargetId int64, postOfOperator []postDeasiteMan) {
defer syncSeting.Done()
wherePost := publicmethod.MapOut[string]()
// wherePost["`state`"] = 1
wherePost["`level`"] = 2
wherePost["`department_id`"] = departmentId
wherePost["`target_id`"] = targetId
wherePost["`target_sun_id`"] = sonTargetId
var sonTarDepartAddAry []modelskpi.TargetDepartment
var postIdAry []string
for _, v := range postOfOperator {
if publicmethod.IsInTrue[string](v.Id, postIdAry) == false {
postIdAry = append(postIdAry, v.Id)
}
var tarDepartCont []modelskpi.TargetDepartment
judgeErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where(wherePost).Where("`post_id` = ?", v.Id).Find(&tarDepartCont).Error
if judgeErr == nil && len(tarDepartCont) > 0 {
for _, tdcv := range tarDepartCont {
if tdcv.State != 1 {
var sonTargetContEdit modelskpi.TargetDepartment
sonTargetContEdit.EiteCont(map[string]interface{}{"`id`": tdcv.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
}
}
} else {
var sonTarDepartAdd modelskpi.TargetDepartment
sonTarDepartAdd.Dimension = dimensionId // 维度"`
sonTarDepartAdd.TargetId = targetId //指标ID"`
sonTarDepartAdd.TargetSunId = sonTargetId //子目标"`
sonTarDepartAdd.TargetBylaws = 0 //指标细则"`
sonTarDepartAdd.Type = 2 //类型(1:指标;2:子目标;3:细则)"`
sonTarDepartAdd.DepartmentId = departmentId //部门ID"`
idInt64, _ := strconv.ParseInt(v.Id, 10, 64)
sonTarDepartAdd.PostId = idInt64 //岗位ID"`
sonTarDepartAdd.State = 1 //状态(1:启用;2:禁用;3:删除)"`
sonTarDepartAdd.Time = time.Now().Unix() //写入时间"`
sonTarDepartAdd.Class = 1 //1:定性考核;2:定量考核"`
sonTarDepartAdd.Level = 2 //级别(1:部门级;2:岗位级)"`
sonTarDepartAddAry = append(sonTarDepartAddAry, sonTarDepartAdd)
}
//处理提报人
syncSetinges.Add(1)
go sonPostTargetPeople(dimensionId, departmentId, targetId, sonTargetId, v.Id, v.Operator)
}
if len(sonTarDepartAddAry) > 0 {
overall.CONSTANT_DB_KPI.Create(&sonTarDepartAddAry)
}
//其他的岗位禁用
if len(postIdAry) > 0 {
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where(wherePost).Not(map[string]interface{}{"post_id": postIdAry}).Updates(&otherSaveData)
}
syncSetinges.Wait()
}
/*
子栏目与提报人
@dimensionId 维度
@departmentId 部门
@targetId 指标
@sonTargetId 子栏目
@postId 岗位
*/
func sonPostTargetPeople(dimensionId, departmentId, targetId, sonTargetId int64, postId string, operator []string) {
defer syncSetinges.Done()
var saveTarRepor []modelskpi.TargetReport
if len(operator) > 0 {
wherePost := publicmethod.MapOut[string]()
// wherePost["`state`"] = 1
wherePost["`type`"] = 2
wherePost["`department_id`"] = departmentId
wherePost["`target_id`"] = targetId
wherePost["`target_sun_id`"] = sonTargetId
wherePost["`post_id`"] = postId
for i := 0; i < len(operator); i++ {
var tarReporList []modelskpi.TargetReport
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(wherePost).Where("`man_key` = ?", operator[i]).Find(&tarReporList)
if len(tarReporList) > 0 {
for _, trlv := range tarReporList {
eidtSont := map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()}
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(map[string]interface{}{"`id`": trlv.Id}).Updates(&eidtSont)
}
} else {
var saveData modelskpi.TargetReport
saveData.Dimension = dimensionId //维度"`
saveData.TargetId = targetId //指标ID"`
saveData.TargetSunId = sonTargetId //子目标"`
saveData.TargetBylaws = 0 //指标细则"`
saveData.DepartmentId = departmentId //部门ID"`
postIdInt64, _ := strconv.ParseInt(postId, 10, 64)
saveData.PostId = postIdInt64 //岗位ID"`
saveData.Type = 2 //类型(1:公司级;2:部门级)"`
saveData.State = 1 //状态(1:启用;2:禁用;3:删除)"`
var manCont modelshr.PersonArchives
manCont.GetCont(map[string]interface{}{"`key`": operator[i]}, "`key`", "`admin_org`")
saveData.ReportPerson = manCont.Key //上报人"`
saveData.ManDepartment = manCont.AdminOrg //提报人所在部门"`
saveData.Time = time.Now().Unix() //写入时间"`
saveData.Class = 2 //定性考核;2:定量考核"`
saveData.Level = 2 //类型(1:指标;2:子目标;3:细则)"`
saveTarRepor = append(saveTarRepor, saveData)
}
}
//将不属于该指标细则的部门至禁用
otherSaveData := publicmethod.MapOut[string]()
otherSaveData["`state`"] = 2
otherSaveData["`time`"] = time.Now().Unix()
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where(wherePost).Not(map[string]interface{}{"man_key": operator}).Updates(&otherSaveData)
}
if len(saveTarRepor) > 0 {
overall.CONSTANT_DB_KPI.Create(&saveTarRepor)
}
}
// 删除子栏目
func (a *ApiMethod) DelSonTargetCont(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(1, receivedValue, c, "您输入的参数不正确!")
return
}
where := map[string]interface{}{"`id`": receivedValue.Id}
var sonTarCont modelskpi.PostSonTarget
err = sonTarCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
err = sonTarCont.EiteCont(map[string]interface{}{"`id`": sonTarCont.Id}, map[string]interface{}{"`state`": 3, "`time`": time.Now().Unix()})
if err != nil {
publicmethod.Result(108, err, c)
return
}
//处理指标细则
xiZeWhere := publicmethod.MapOut[string]()
xiZeWhere["`parentid`"] = sonTarCont.ParentId
xiZeWhere["`parentid_sun`"] = sonTarCont.Id
xiZeWhere["`paretment`"] = sonTarCont.Depart
var postTarDetaCont modelskpi.PostTargetDetails
postTarDetaCont.EiteCont(xiZeWhere, map[string]interface{}{"`state`": 3, "`time`": time.Now().Unix()})
publicmethod.Result(0, err, c)
}
// 添加单一定性指标细则
func (a *ApiMethod) AddOneTargetD(c *gin.Context) {
var receivedValue sonTargetAddDieastion
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "您输入的参数不正确!")
return
}
where := map[string]interface{}{"`id`": receivedValue.Id}
var sonTarCont modelskpi.PostSonTarget
err := sonTarCont.GetCont(where)
if err != nil {
publicmethod.Result(107, err, c)
return
}
if sonTarCont.State != 1 {
sonTarCont.EiteCont(where, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
}
if receivedValue.Title == "" {
publicmethod.Result(101, receivedValue, c, "请输入细则名称")
return
}
if receivedValue.PunishMode == 0 {
receivedValue.PunishMode = 1
}
var minScoreInt int64
var maxScoreInt int64
var minMoney int64 //罚款或奖励最高金额
var maxMoney int64 //罚款或奖励最新金额
switch receivedValue.PunishMode {
case 2:
if receivedValue.CashStandard == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核现金标准")
return
}
minMoney, maxMoney = caiFenStrint(receivedValue.CashStandard)
case 3:
if receivedValue.ReferenceScore == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核标准")
return
}
minScoreInt, maxScoreInt = caiFenStrint(receivedValue.ReferenceScore)
if receivedValue.CashStandard == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核现金标准")
return
}
minMoney, maxMoney = caiFenStrint(receivedValue.CashStandard)
if receivedValue.Unit == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核单位")
return
}
default:
receivedValue.PunishMode = 1
if receivedValue.ReferenceScore == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核标准")
return
}
if receivedValue.Unit == "" {
publicmethod.Result(101, receivedValue, c, "请输入考核单位")
return
}
minScoreInt, maxScoreInt = caiFenStrint(receivedValue.ReferenceScore)
}
if receivedValue.Class == 0 {
receivedValue.Class = 1
}
if len(receivedValue.Inspect) < 1 {
receivedValue.Inspect = append(receivedValue.Inspect, "1")
}
if receivedValue.Cycle == 0 {
receivedValue.Cycle = 4
}
if receivedValue.CycleAttr == 0 {
receivedValue.CycleAttr = 1
}
if receivedValue.Frequency == 0 {
receivedValue.Frequency = 1
}
var saveCont modelskpi.PostTargetDetails
saveCont.Title = receivedValue.Title //指标细则"`
saveCont.Content = receivedValue.Explain //备注说明"`
saveCont.ParentId = sonTarCont.ParentId //归属指标栏目"`
saveCont.ParentIdSun = sonTarCont.Id //归属指标子栏目"`
saveCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
saveCont.AddTime = time.Now().Unix() //制定时间"`
saveCont.MinScore = minScoreInt //最小分*100保存"`
saveCont.MaxScore = maxScoreInt //最大分*100保存"`
saveCont.Company = receivedValue.Unit //单位"`
saveCont.AddReduce = receivedValue.Class //1:减少;2:增加;3:无属性,现场确认加或减"`
saveCont.CensorType = strings.Join(receivedValue.Inspect, ",") //检查方式"`
saveCont.CensorCont = receivedValue.Evidence //客观证据"`
saveCont.CensorRate = receivedValue.Frequency //检查频次"`
saveCont.Cycles = receivedValue.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"`
saveCont.CycleAttres = receivedValue.CycleAttr //辅助计数"`
// saveCont.Paretment = strconv.FormatInt(sonTarCont.Depart, 10) //接受考核的部门"`
saveCont.Paretment = sonTarCont.Depart
// saveCont.ParetmentPost = strings.Join(requestData.PostId, ",") //接受考核的部门岗位"`
// saveCont.Reportary = strings.Join(receivedValue.ReportAry, ",") //接受考核的部门岗位"`
saveCont.Punishmode = receivedValue.PunishMode //处罚或奖励方式 1:分数;2:现金;3:分数加现金
saveCont.Minmoney = minMoney //最高罚款*100保存"`
saveCont.Maxmoney = maxMoney //最低罚款*100保存"`
//获取指标信息
var getTargetCont modelskpi.PostTarget
getTargetCont.GetCont(map[string]interface{}{"`id`": sonTarCont.ParentId})
departInt, _ := strconv.ParseInt(sonTarCont.Depart, 10, 64)
_, postPeople, _ := getTargetSonAboutPost(departInt, getTargetCont.Dimension, getTargetCont.Id, sonTarCont.Id, 2)
syncSeting.Add(1)
go addDetaonsCont(saveCont, receivedValue.RelevantPostsMan, postPeople, getTargetCont.Dimension)
syncSeting.Wait()
publicmethod.Result(0, receivedValue, c)
}
// 拆分细则标准或罚款
func caiFenStrint(str string) (minData, maxData int64) {
moneyAry := strings.Split(str, "-")
moneyAryLen := len(moneyAry)
if moneyAryLen > 0 {
if moneyAryLen == 1 {
maxMoneyEs, _ := strconv.ParseFloat(moneyAry[0], 64)
maxData, _ = strconv.ParseInt(strconv.FormatFloat(maxMoneyEs*100, 'f', -1, 64), 10, 64)
minData = 0
} else {
maxMoneyEs, _ := strconv.ParseFloat(moneyAry[moneyAryLen-1], 64)
maxData, _ = strconv.ParseInt(strconv.FormatFloat(maxMoneyEs*100, 'f', -1, 64), 10, 64)
minMoneyEs, _ := strconv.ParseFloat(moneyAry[0], 64)
minData, _ = strconv.ParseInt(strconv.FormatFloat(minMoneyEs*100, 'f', -1, 64), 10, 64)
}
} else {
minData = 0
maxData = 0
}
return
}
/*
获取岗位指标子栏目相关岗位
@departmentId 部门Id
@dimensionId 维度
@targetId 指标
@level 级别(1:部门级;2:岗位级)
func getTargetAboutPost(departmentId, dimensionId, targetId int64, level int) (postId []int64, postPeopleList []postPeople, err error)
*/
func getTargetSonAboutPost(departmentId, dimensionId, targetId, sonTargetId int64, level int) (postId []int64, postPeopleList []postPeople, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ?", level, departmentId, dimensionId, targetId, sonTargetId).Find(&postId).Error
if len(postId) > 0 {
for i := 0; i < len(postId); i++ {
var postmanCont postPeople
postmanCont.Id = strconv.FormatInt(postId[i], 10)
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": postId[i]}, "`name`")
postmanCont.Name = postCont.Name
_, postmanCont.Operator, _ = getSonTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId, sonTargetId, level)
if len(postmanCont.Operator) < 1 {
_, postmanCont.Operator, _ = getTargetAboutPostMan(departmentId, postId[i], dimensionId, targetId, level, 1)
}
postPeopleList = append(postPeopleList, postmanCont)
}
}
return
}
/*
获取岗位指标子栏目相关岗位提报人
@departmentId 部门Id
@postid 岗位
@dimensionId 维度
@targetId 指标
@level 级别(1:部门级;2:岗位级)
*/
func getSonTargetAboutPostMan(departmentId, postid, dimensionId, targetId, sonTargetId int64, level int) (peopleId []int64, postPeople []string, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = ? AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ?", level, departmentId, postid, dimensionId, targetId, sonTargetId).Find(&peopleId).Error
if len(peopleId) > 0 {
for i := 0; i < len(peopleId); i++ {
postPeople = append(postPeople, strconv.FormatInt(peopleId[i], 10))
}
}
return
}
// 删除指标细则
func (a *ApiMethod) EidtPostTarDetailsStrte(c *gin.Context) {
var requestData publicmethod.PublicState
c.ShouldBindJSON(&requestData)
if requestData.Id == "" {
publicmethod.Result(1, requestData, c, "请输入指标ID!")
return
}
if requestData.State == 0 {
requestData.State = 1
}
if requestData.IsTrue == 0 {
requestData.IsTrue = 2
}
where := publicmethod.MapOut[string]()
where["`id`"] = requestData.Id
var detaCont modelskpi.PostTargetDetails
detaErr := detaCont.GetCont(where)
if detaErr != nil {
publicmethod.Result(1, detaErr, c, "该指标细则不存在!")
return
}
if requestData.State != 3 {
saveData := publicmethod.MapOut[string]()
saveData["state"] = requestData.State
saveData["time"] = time.Now().Unix()
saveErr := detaCont.EiteCont(where, saveData)
if saveErr != nil {
publicmethod.Result(1, saveErr, c, "编辑失败!")
return
}
} else {
if requestData.IsTrue != 1 {
saveData := publicmethod.MapOut[string]()
saveData["state"] = requestData.State
saveData["time"] = time.Now().Unix()
saveErr := detaCont.EiteCont(where, saveData)
if saveErr != nil {
publicmethod.Result(1, saveErr, c, "编辑失败!")
return
}
} else {
saveErr := detaCont.DelCont(where)
if saveErr != nil {
publicmethod.Result(1, saveErr, c, "编辑失败!")
return
}
}
}
publicmethod.Result(0, detaCont, c)
}
// 编辑定性指标细则内容
func (a *ApiMethod) EditDeatilsCont(c *gin.Context) {
var receivedValue sonTargetAddDieastion
c.ShouldBindJSON(&receivedValue)
if receivedValue.Id == "" {
publicmethod.Result(1, receivedValue, c, "请输入指标ID!")
return
}
where := publicmethod.MapOut[string]()
where["`id`"] = receivedValue.Id
var detaCont modelskpi.PostTargetDetails
detaErr := detaCont.GetCont(where)
if detaErr != nil {
publicmethod.Result(1, detaErr, c, "该指标细则不存在!")
return
}
saveData := publicmethod.MapOut[string]()
if receivedValue.Title != "" && receivedValue.Title != detaCont.Title {
saveData["title"] = receivedValue.Title
}
if receivedValue.PunishMode == 0 {
receivedValue.PunishMode = 1
}
if receivedValue.Class != 0 && receivedValue.Class != detaCont.AddReduce {
saveData["add_reduce"] = receivedValue.Class
}
switch receivedValue.PunishMode {
case 2:
if receivedValue.CashStandard == "" {
minMoney, maxMoney := caiFenStrint(receivedValue.CashStandard)
if minMoney != detaCont.Minmoney {
saveData["minmoney"] = minMoney
}
if maxMoney != detaCont.Maxmoney {
saveData["maxmoney"] = maxMoney
}
}
if receivedValue.PunishMode != detaCont.Punishmode {
saveData["punishmode"] = receivedValue.PunishMode
}
case 3:
if receivedValue.PunishMode != detaCont.Punishmode {
saveData["punishmode"] = receivedValue.PunishMode
}
if receivedValue.ReferenceScore != "" {
minScoreInt, maxScoreInt := caiFenStrint(receivedValue.ReferenceScore)
if minScoreInt != detaCont.MinScore {
saveData["min_score"] = minScoreInt
}
if maxScoreInt != detaCont.MaxScore {
saveData["max_score"] = maxScoreInt
}
}
if receivedValue.CashStandard != "" {
minMoney, maxMoney := caiFenStrint(receivedValue.CashStandard)
if minMoney != detaCont.Minmoney {
saveData["minmoney"] = minMoney
}
if maxMoney != detaCont.Maxmoney {
saveData["maxmoney"] = maxMoney
}
}
if receivedValue.Unit == "" && receivedValue.Unit != detaCont.Company {
saveData["company"] = receivedValue.Unit
}
default:
receivedValue.PunishMode = 1
if receivedValue.ReferenceScore == "" {
minScoreInt, maxScoreInt := caiFenStrint(receivedValue.ReferenceScore)
if minScoreInt != detaCont.MinScore {
saveData["min_score"] = minScoreInt
}
if maxScoreInt != detaCont.MaxScore {
saveData["max_score"] = maxScoreInt
}
}
if receivedValue.Unit == "" && receivedValue.Unit != detaCont.Company {
saveData["company"] = receivedValue.Unit
}
if receivedValue.PunishMode != detaCont.Punishmode {
saveData["punishmode"] = receivedValue.PunishMode
}
}
if len(receivedValue.Inspect) > 0 {
inspectStr := strings.Join(receivedValue.Inspect, ",")
if inspectStr != detaCont.CensorType {
saveData["censor_type"] = inspectStr
}
}
if receivedValue.Cycle != 0 && receivedValue.Cycle != detaCont.Cycles {
saveData["cycle"] = receivedValue.Cycle
}
if receivedValue.CycleAttr != 0 && receivedValue.CycleAttr != detaCont.CycleAttres {
saveData["cycleattr"] = receivedValue.CycleAttr
}
if receivedValue.Frequency != 0 && receivedValue.Frequency != detaCont.CensorRate {
saveData["censor_rate"] = receivedValue.Frequency
}
if receivedValue.Evidence != "" && receivedValue.Evidence != detaCont.CensorCont {
saveData["censor_cont"] = receivedValue.Evidence
}
if receivedValue.Explain != "" && receivedValue.Explain != detaCont.Content {
saveData["content"] = receivedValue.Explain
}
if len(saveData) > 0 {
saveData["time"] = time.Now().Unix()
saveErr := detaCont.EiteCont(where, saveData)
if saveErr != nil {
publicmethod.Result(106, saveErr, c)
return
}
}
var postTarCont modelskpi.PostTarget
postTarCont.GetCont(map[string]interface{}{"`id`": detaCont.ParentId}, "`dimension`")
dimensionId := postTarCont.Dimension
paretmentIdInt, _ := strconv.ParseInt(detaCont.Paretment, 10, 64)
var departAny []string
for _, v := range receivedValue.RelevantPostsMan {
if publicmethod.IsInTrue[string](v.Id, departAny) == false {
departAny = append(departAny, v.Id)
}
postid, _ := strconv.ParseInt(v.Id, 10, 64)
if len(v.Operator) > 0 {
syncSetinges.Add(1)
go DepartAboutPostTargetReport(dimensionId, detaCont.ParentId, detaCont.ParentIdSun, detaCont.Id, paretmentIdInt, postid, v.Operator, 2, 1)
}
}
//关联部门岗位
if len(departAny) > 0 {
syncSetinges.Add(1)
go EditTargetTableDimenAboutPostOfDepart(dimensionId, detaCont.ParentId, detaCont.ParentIdSun, detaCont.Id, paretmentIdInt, departAny, 2, 1)
}
syncSetinges.Wait()
publicmethod.Result(0, receivedValue, c)
}
// 获取指标细则内容
func (a *ApiMethod) GetDetailsCont(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, err, c)
return
}
where := publicmethod.MapOut[string]()
where["`id`"] = receivedValue.Id
var detaCont modelskpi.PostTargetDetails
detaErr := detaCont.GetCont(where)
if detaErr != nil {
publicmethod.Result(1, detaErr, c, "该指标细则不存在!")
return
}
var sendData sonTargetAddDieastion
sendData.Id = strconv.FormatInt(detaCont.Id, 10)
if detaCont.MinScore != 0 {
sendData.ReferenceScore = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(float64(detaCont.MinScore)/100, 2), publicmethod.DecimalEs(float64(detaCont.MaxScore)/100, 2))
} else {
sendData.ReferenceScore = fmt.Sprintf("%v", publicmethod.DecimalEs(float64(detaCont.MaxScore)/100, 2))
}
if detaCont.Minmoney != 0 {
sendData.CashStandard = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(float64(detaCont.Minmoney)/100, 2), publicmethod.DecimalEs(float64(detaCont.Maxmoney)/100, 2))
} else {
sendData.CashStandard = fmt.Sprintf("%v", publicmethod.DecimalEs(float64(detaCont.Maxmoney)/100, 2))
}
paretmentIdInt, _ := strconv.ParseInt(detaCont.Paretment, 10, 64)
var postTarCont modelskpi.PostTarget
postTarCont.GetCont(map[string]interface{}{"`id`": detaCont.ParentId}, "`dimension`")
dimensionId := postTarCont.Dimension
sendData.Title = detaCont.Title
sendData.Unit = detaCont.Company //单位
sendData.Class = detaCont.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减
sendData.Inspect = strings.Split(detaCont.CensorType, ",") //检查方式(1:现场检查;2:资料检查;3:事件触发)
sendData.Cycle = detaCont.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年
sendData.CycleAttr = detaCont.CycleAttres //辅助计数
sendData.Frequency = detaCont.CensorRate //频次
sendData.Evidence = detaCont.CensorCont //客观证据
sendData.Explain = detaCont.Content //备注说明
_, sendData.RelevantPostsMan, _ = getTargetAboutPostDeta(paretmentIdInt, dimensionId, detaCont.ParentId, detaCont.ParentIdSun, detaCont.Id, 2) //相关岗位与提报人
sendData.PunishMode = detaCont.Punishmode //处罚方式 1:扣分;2:现金处罚;3:扣分加现金
publicmethod.Result(0, sendData, c)
}
/*
获取岗位指标子细则相关岗位
@departmentId 部门Id
@dimensionId 维度
@targetId 指标
@bylaws 指标细则
@level 级别(1:部门级;2:岗位级)
func getTargetAboutPost(departmentId, dimensionId, targetId int64, level int) (postId []int64, postPeopleList []postPeople, err error)
*/
func getTargetAboutPostDeta(departmentId, dimensionId, targetId, sonTargetId, bylaws int64, level int) (postId []int64, postPeopleList []postPeople, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `level` = ? AND `department_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", level, departmentId, dimensionId, targetId, sonTargetId, bylaws).Find(&postId).Error
if len(postId) > 0 {
for i := 0; i < len(postId); i++ {
var postmanCont postPeople
postmanCont.Id = strconv.FormatInt(postId[i], 10)
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": postId[i]}, "`name`")
postmanCont.Name = postCont.Name
_, postmanCont.Operator, _ = getTargetAboutPostDetalMan(departmentId, postId[i], dimensionId, targetId, sonTargetId, bylaws, level)
postPeopleList = append(postPeopleList, postmanCont)
}
}
return
}
/*
获取岗位指标细则相关岗位提报人
@departmentId 部门Id
@postid 岗位
@dimensionId 维度
@targetId 指标
@level 级别(1:部门级;2:岗位级)
*/
func getTargetAboutPostDetalMan(departmentId, postid, dimensionId, targetId, sonTargetId, bylaws int64, level int) (peopleId []int64, postPeople []string, err error) {
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = ? AND `department_id` = ? AND `post_id` = ? AND `dimension_id` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", level, departmentId, postid, dimensionId, targetId, sonTargetId, bylaws).Find(&peopleId).Error
if len(peopleId) > 0 {
for i := 0; i < len(peopleId); i++ {
postPeople = append(postPeople, strconv.FormatInt(peopleId[i], 10))
}
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-10 11:00:59
@ 功能: 获取岗位指标列表
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) GetPostTargetList(c *gin.Context) {
var receivedValue GetPostTargetContList
c.ShouldBindJSON(&receivedValue)
if receivedValue.PageSize == 0 {
receivedValue.PageSize = 20
}
if receivedValue.Page == 0 {
receivedValue.Page = 1
}
var postTargetCont modelskpi.PostTarget
gormDb := overall.CONSTANT_DB_KPI.Table(fmt.Sprintf("%s pt", postTargetCont.TableName())).Where("pt.`state` BETWEEN 1 AND 2")
if receivedValue.Title != "" {
gormDb = gormDb.Where("pt.`title` LIKE ?", "%"+receivedValue.Title+"%")
}
if receivedValue.Dimension != "" {
gormDb = gormDb.Where("pt.`dimension` = ?", receivedValue.Dimension)
}
if receivedValue.Attribute != 0 {
gormDb = gormDb.Where("pt.`type` = ?", receivedValue.Attribute)
}
if len(receivedValue.PostIdList) > 0 {
gormDb = gormDb.Joins("JOIN target_department td ON pt.`id` = td.`target_id` AND td.`target_sun_id` = 0 AND td.`target_bylaws` = 0 AND td.`type` = 1 AND td.`state` BETWEEN 1 AND 2 AND td.`level` = 2 AND td.`post_id` IN ?", receivedValue.PostIdList)
}
var total int64
gormDbTotal := gormDb.Distinct("pt.id")
totalErr := gormDbTotal.Count(&total).Error
if totalErr != nil {
total = 0
}
var targetIdAry []int64
gormDb = gormDb.Distinct("pt.id")
gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize)
err := gormDb.Order("pt.`id` DESC").Find(&targetIdAry).Error
if err != nil || len(targetIdAry) < 1 {
publicmethod.Result(105, err, c)
return
}
//获取指标信息列表
var postTargetList []modelskpi.PostTarget
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.PostTarget{}).Where("`id` IN ?", targetIdAry).Order("`id` DESC").Find(&postTargetList).Error
if err != nil {
publicmethod.Result(105, err, c)
return
}
var sendPostTargetContList []outPostTargetList
for _, v := range postTargetList {
var postTargetCont outPostTargetList
postTargetCont.Id = v.Id
postTargetCont.Title = v.Title //标题"`
postTargetCont.Type = v.Type //定性考核;2:定量考核"`
postTargetCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
postTargetCont.Time = v.Time //创建时间"`
postTargetCont.Share = v.Share //共用;2:私用"`
postTargetCont.ReleDepart = v.ReleDepart //相关部门"`
postTargetCont.DepartmentsPost = v.DepartmentsPost //相关岗位"`
postTargetCont.Dimension = v.Dimension //维度"`
postTargetCont.Key = v.Key //UUID"`
postTargetCont.Report = v.Report //上报人"`
postTargetCont.Unit = v.Unit //单位"`
postTargetCont.Cycle = v.Cycle //1:班;2:天;3:周;4:月;5:季度;6:年"`
postTargetCont.Cycleattr = v.Cycleattr //n辅助计数"`
postTargetCont.ScoringMethod = v.ScoringMethod //计分方式(1:自动;2:手动)"`
postTargetCont.VisibleRange = v.VisibleRange //可见范围"`
postTargetCont.VisibleGroup = v.VisibleGroup //可见范围(集团)"`
var dimCont modelskpi.DutyClass
dimCont.GetCont(map[string]interface{}{"`id`": v.Dimension}, "`title`")
postTargetCont.DimensionName = dimCont.Title
postTargetCont.PostAry = getSubimtPost(v.Id, 0, 0, 1, 2)
postTargetCont.ReportAry = getSubimtPostReport(v.Id, 0, 0, 2, 1)
sendPostTargetContList = append(sendPostTargetContList, postTargetCont)
}
publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(sendPostTargetContList)), sendPostTargetContList, c)
}
// 获取提报岗位
/*
#targetId 指标Id
#sunTargetId 栏目Id
#targetBylawsId 细则Id
#typeInt 类型(1:指标;2:子目标;3:细则)
#level 级别(1:部门级;2:岗位级)
*/
func getSubimtPost(targetId, sunTargetId, targetBylawsId int64, typeInt, level int) (postTargetListCont []idAndName) {
var postIdList []int64
err := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`post_id`").Where("`state` = 1 AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND `type` = ? AND `level` = ?", targetId, sunTargetId, targetBylawsId, typeInt, level).Find(&postIdList).Error
if err != nil {
return
}
if len(postIdList) > 0 {
for _, v := range postIdList {
var postTarInfo modelshr.Position
errPost := postTarInfo.GetCont(map[string]interface{}{"`id`": v}, "`name`")
if errPost == nil {
var contInfo idAndName
contInfo.Id = strconv.FormatInt(v, 10)
contInfo.Name = postTarInfo.Name
postTargetListCont = append(postTargetListCont, contInfo)
}
}
}
return
}
// 获取岗位指标提报人
/*
#targetId 指标Id
#sunTargetId 栏目Id
#targetBylawsId 细则Id
#typeInt 级别(1:部门级;2:岗位级)
#level 类型(1:指标;2:子目标;3:细则)
*/
func getSubimtPostReport(targetId, sunTargetId, targetBylawsId int64, typeInt, level int) (manContList []UserContList) {
var userKey []int64
err := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ? AND `type` = ? AND `type_level` = ?", targetId, sunTargetId, targetBylawsId, typeInt, level).Find(&userKey).Error
if err != nil {
return
}
if len(userKey) > 0 {
for _, v := range userKey {
var postTarInfo modelshr.PersonArchives
errPost := postTarInfo.GetCont(map[string]interface{}{"`key`": v}, "`number`", "`name`", "`icon`", "`icon_photo`")
if errPost == nil {
var contInfo UserContList
contInfo.Id = strconv.FormatInt(v, 10)
contInfo.Name = postTarInfo.Name
contInfo.Icon = postTarInfo.Icon
contInfo.IconImg = postTarInfo.IconPhoto
manContList = append(manContList, contInfo)
}
}
}
return
}
/*
*
@ 作者: 秦东
@ 时间: 2023-02-10 14:45:00
@ 功能: 设置岗位指标状态
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func (a *ApiMethod) SetPostTargetState(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["id"] = receivedValue.Id
var targetCont modelskpi.PostTarget
err := targetCont.GetCont(where, "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.PostWorkflowOrders{}).Select("`id`").Where("FIND_IN_SET(?,`target`)", receivedValue.Id).Find(&epIdList)
if len(epIdList) > 0 {
softDel = 1
} else {
softDel = 2
}
}
var editTargetState modelskpi.PostTarget
if softDel == 1 {
//软删除
editTargetState.EiteCont(where, map[string]interface{}{"`state`": receivedValue.State, "`time`": time.Now().Unix()})
} else {
//硬删除
editTargetState.DelCont(where)
}
syncSeting.Add(1)
go SunPostTargetState(targetCont.Id, receivedValue.State, softDel) //处理目标
syncSeting.Add(1)
go PostTargetDatailedState(targetCont.Id, 0, receivedValue.State, softDel) // 处理细则
syncSeting.Add(1)
go PostTarDepartState(targetCont.Id, 0, 0, receivedValue.State, softDel, 2, 1) // 处理关联部门
syncSeting.Add(1)
go PostTarAboutReport(targetCont.Id, 0, 0, receivedValue.State, softDel, 2, 1) // 处理相关提报人
syncSeting.Wait()
publicmethod.Result(0, err, c)
}
//处理相关提报人
/*
#parentId 指标ID
#sunID 栏目
#bylawsId 细则
#state 状态
#isTrue 1软删;非1:硬删除
#level 1:部门级;2:岗位级
#typeInt 1:指标;2:子目标;3:细则
*/
func PostTarAboutReport(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)
}
}
// 处理关联部门
/*
#parentId 指标ID
#sunID 栏目
#bylawsId 细则
#state 状态
#isTrue 1软删;非1:硬删除
#level 1:部门级;2:岗位级
#typeInt 1:指标;2:子目标;3:细则
*/
func PostTarDepartState(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 栏目
#state 状态
#isTrue 1软删;非1:硬删除
*/
func PostTargetDatailedState(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["parentid"] = ParentId
}
if SunID != 0 {
wheAry["parentid_sun"] = SunID
}
var tarDataCont modelskpi.PostTargetDetails
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.PostTargetDetails{}).Where("`state` BETWEEN 1 AND 2").Where(wheAry).Updates(map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
}
} else {
tarDataCont.DelCont(wheAry)
}
}
// 处理目标
/*
#ParentId 指标ID
#state 状态
#isTrue 1软删;非1:硬删除
*/
func SunPostTargetState(ParentId int64, state, isTrue int) {
defer syncSeting.Done()
if state == 0 {
state = 1
}
if isTrue == 0 {
isTrue = 1
}
var sunTargetCont modelskpi.PostSonTarget
if isTrue == 1 {
//软删除
if state != 1 {
sunTargetCont.EiteCont(map[string]interface{}{"`parent_id`": ParentId}, map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
} else {
overall.CONSTANT_DB_KPI.Model(&modelskpi.PostSonTarget{}).Where("`state` BETWEEN 1 AND 2 AND `parent_id` = ?", ParentId).Updates(map[string]interface{}{"`state`": state, "`time`": time.Now().Unix()})
}
} else {
sunTargetCont.DelCont(map[string]interface{}{"`parent_id`": ParentId})
}
}