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.
370 lines
11 KiB
370 lines
11 KiB
package postpc
|
|
|
|
import (
|
|
"fmt"
|
|
"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-01-12 15:21:20
|
|
@ 功能: 搜索行政组织岗位列表
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) SearchOrgPostList(c *gin.Context) {
|
|
var receivedValue SearchOrgPost
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if receivedValue.Name == "" {
|
|
publicmethod.Result(1, err, c, "请输入要查询得岗位名称!")
|
|
return
|
|
}
|
|
var companyId int64 = 0
|
|
if receivedValue.OrgId != "" {
|
|
orgIdInt, _ := strconv.ParseInt(receivedValue.OrgId, 10, 64)
|
|
_, companyId, _, _, _ = publicmethod.GetOrgStructure(orgIdInt)
|
|
}
|
|
var postList []modelshr.Position
|
|
err = overall.CONSTANT_DB_HR.Where("`state` = 1 AND `name` LIKE ?", "%"+receivedValue.Name+"%").Find(&postList).Error
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c, "没有相关岗位!")
|
|
return
|
|
}
|
|
var sendList []SendSearPost
|
|
for _, v := range postList {
|
|
_, companyIdPost, minDer, sunDer, workId := publicmethod.GetOrgStructure(v.AdministrativeOrganization)
|
|
var orgAry []int64
|
|
// if companyIdPost != 0 && publicmethod.IsInTrue[int64](companyIdPost, orgAry) == false {
|
|
// orgAry = append(orgAry, companyIdPost)
|
|
// }
|
|
if minDer != 0 && publicmethod.IsInTrue[int64](minDer, orgAry) == false {
|
|
orgAry = append(orgAry, minDer)
|
|
}
|
|
if sunDer != 0 && publicmethod.IsInTrue[int64](sunDer, orgAry) == false {
|
|
orgAry = append(orgAry, sunDer)
|
|
}
|
|
if workId != 0 && publicmethod.IsInTrue[int64](workId, orgAry) == false {
|
|
orgAry = append(orgAry, workId)
|
|
}
|
|
if v.AdministrativeOrganization != 0 && publicmethod.IsInTrue[int64](v.AdministrativeOrganization, orgAry) == false {
|
|
orgAry = append(orgAry, v.AdministrativeOrganization)
|
|
}
|
|
if companyId != 0 {
|
|
|
|
if companyIdPost == companyId {
|
|
var sendCont SendSearPost
|
|
sendCont.OrgId = orgAry
|
|
sendCont.PostId = v.Id
|
|
sendCont.PostList = GetWithOrgList(v.AdministrativeOrganization)
|
|
sendList = append(sendList, sendCont)
|
|
}
|
|
} else {
|
|
var sendCont SendSearPost
|
|
sendCont.OrgId = orgAry
|
|
sendCont.PostId = v.Id
|
|
sendCont.PostList = GetWithOrgList(v.AdministrativeOrganization)
|
|
sendList = append(sendList, sendCont)
|
|
}
|
|
|
|
}
|
|
// fmt.Printf("总数--->%v\n", len(sendList))
|
|
publicmethod.Result(0, sendList, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-12 15:21:30
|
|
@ 功能: 获取同行政组织岗位
|
|
@ 参数
|
|
|
|
#orgId 行政组织ID
|
|
|
|
@ 返回值
|
|
|
|
#postList 岗位列表
|
|
|
|
@ 方法原型
|
|
|
|
#func GetWithOrgList(orgId int64) (postList []PostListCont)
|
|
*/
|
|
func GetWithOrgList(orgId int64) (postList []PostListCont) {
|
|
var postListCont []modelshr.Position
|
|
err := overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Select("`id`,`name`").Where("`state` = 1 AND `administrative_organization` = ?", orgId).Find(&postListCont).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range postListCont {
|
|
var postCont PostListCont
|
|
postCont.Id = v.Id
|
|
postCont.Name = v.Name
|
|
postList = append(postList, postCont)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-13 10:44:16
|
|
@ 功能: 获取行政组织级联数组
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GetOrgAry(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, err, c, "参数错误!")
|
|
return
|
|
}
|
|
idInt, _ := strconv.ParseInt(receivedValue.Id, 10, 64)
|
|
_, _, minDer, sunDer, workId := publicmethod.GetOrgStructure(idInt)
|
|
var orgAry []int64
|
|
if minDer != 0 && publicmethod.IsInTrue[int64](minDer, orgAry) == false {
|
|
orgAry = append(orgAry, minDer)
|
|
}
|
|
if sunDer != 0 && publicmethod.IsInTrue[int64](sunDer, orgAry) == false {
|
|
orgAry = append(orgAry, sunDer)
|
|
}
|
|
if workId != 0 && publicmethod.IsInTrue[int64](workId, orgAry) == false {
|
|
orgAry = append(orgAry, workId)
|
|
}
|
|
if idInt != 0 && publicmethod.IsInTrue[int64](idInt, orgAry) == false {
|
|
orgAry = append(orgAry, idInt)
|
|
}
|
|
publicmethod.Result(0, orgAry, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-13 11:00:48
|
|
@ 功能: 添加岗位指标
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) NewAddPostTarget(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.OtherPostTarget) < 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
|
|
}
|
|
|
|
orgPostManList := HandlingRelations(receivedValue.OtherPostTarget)
|
|
if len(orgPostManList) < 1 {
|
|
publicmethod.Result(1, receivedValue, c, "请选择该指标归属岗位!")
|
|
return
|
|
}
|
|
|
|
for _, v := range orgPostManList {
|
|
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:私用"`
|
|
dimensionId, _ := strconv.ParseInt(receivedValue.Dimension, 10, 64)
|
|
saveData.Dimension = dimensionId //维度"`
|
|
saveData.Key = publicmethod.GetUUid(1) //UUID"`
|
|
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, ",") //可见范围(集团)"`
|
|
saveData.ReleDepart = v.OrgId //相关部门"`
|
|
var postList []string
|
|
var manList []string
|
|
for _, vp := range v.PostPeople {
|
|
postId := strconv.FormatInt(vp.PostId, 10)
|
|
if publicmethod.IsInTrue[string](postId, postList) == false {
|
|
postList = append(postList, postId)
|
|
}
|
|
for _, vm := range vp.PeopleList {
|
|
if publicmethod.IsInTrue[string](vm, manList) == false {
|
|
manList = append(manList, vm)
|
|
}
|
|
}
|
|
|
|
}
|
|
saveData.DepartmentsPost = strings.Join(postList, ",") //相关岗位"`
|
|
saveData.Report = strings.Join(manList, ",") //上报人"`
|
|
overall.CONSTANT_DB_KPI.Create(&saveData)
|
|
for _, vps := range v.PostPeople {
|
|
syncSetinges.Add(1)
|
|
go DepartAboutPostTargetReport(dimensionId, saveData.Id, 0, 0, v.OrgId, vps.PostId, vps.PeopleList, 2, receivedValue.Type)
|
|
}
|
|
//关联部门岗位
|
|
if len(postList) > 0 {
|
|
syncSetinges.Add(1)
|
|
go EditTargetTableDimenAboutPostOfDepart(dimensionId, saveData.Id, 0, 0, v.OrgId, postList, 2, receivedValue.Type)
|
|
}
|
|
|
|
}
|
|
syncSetinges.Wait()
|
|
publicmethod.Result(0, orgPostManList, c)
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-13 13:40:21
|
|
@ 功能: 判断岗位指标是否存在
|
|
@ 参数
|
|
|
|
#targetTitle 指标名称
|
|
#Attribute 1:定性考核;2:定量考核
|
|
#dimId 维度Key
|
|
#departId 部门ID
|
|
#postId 岗位ID
|
|
|
|
@ 返回值
|
|
|
|
#targetCont 岗位指标
|
|
#err 状态
|
|
|
|
@ 方法原型
|
|
|
|
#JudgePostTargetIsTrue(targetTitle string, Attribute int, dimId, departId, postId int64) (targetCont modelskpi.PostTarget, err error)
|
|
*/
|
|
func JudgePostTargetIsTrue(targetTitle string, Attribute int, dimId, departId, postId int64) (targetCont modelskpi.PostTarget, err error) {
|
|
err = overall.CONSTANT_DB_KPI.Model(targetCont).Select("`id`").Where("`rele_depart` = ? AND `dimension` = ? AND `type` = ? AND `title` = ? AND FIND_IN_SET(?,`departments_post`)", departId, dimId, Attribute, targetTitle, postId).First(&targetCont).Error
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-01-13 11:10:25
|
|
@ 功能: 处理行政组织与岗位和相关提报人关系
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func HandlingRelations(orgPostPeo []OtherPostTargetCont) (orgHandPost []OrgPostPeople) {
|
|
fmt.Printf("orgPostPeo---->%v\n", orgPostPeo)
|
|
if len(orgPostPeo) < 1 {
|
|
return
|
|
}
|
|
for _, ov := range orgPostPeo { //循环提交得行政组织与岗位和提报人
|
|
isInAry := false
|
|
for hi, hv := range orgHandPost { //循环已经处理得数据
|
|
if ov.OrgId == hv.OrgId { //判断此行政组织是否已经存在
|
|
isInAry = true
|
|
for hvpi, hvp := range hv.PostPeople { //循环已经处理后的岗位及提报人
|
|
if hvp.PostId == ov.PostId { //判断岗位数据是否已经处理过类是得岗位
|
|
var manList []string
|
|
for _, hvpm := range hvp.PeopleList { //已经添加了的岗位提报人
|
|
manList = append(manList, hvpm)
|
|
}
|
|
for _, ovm := range ov.Operator {
|
|
if publicmethod.IsInTrue[string](ovm, manList) == false {
|
|
manList = append(manList, ovm)
|
|
}
|
|
} //新提报人
|
|
|
|
orgHandPost[hi].PostPeople[hvpi].PeopleList = manList
|
|
} else { //此行政组织为处理过相关岗位则新增
|
|
var postAndMan PostPeopleList
|
|
postAndMan.PostId = ov.PostId
|
|
postAndMan.PeopleList = ov.Operator
|
|
orgHandPost[hi].PostPeople = append(orgHandPost[hi].PostPeople, postAndMan)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//次行政组织不存在,执行新增操作
|
|
if isInAry == false {
|
|
var orgHandPostCont OrgPostPeople
|
|
orgHandPostCont.OrgId = ov.OrgId
|
|
var postAndMan PostPeopleList
|
|
postAndMan.PostId = ov.PostId
|
|
postAndMan.PeopleList = ov.Operator
|
|
orgHandPostCont.PostPeople = append(orgHandPostCont.PostPeople, postAndMan)
|
|
orgHandPost = append(orgHandPost, orgHandPostCont)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|