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.
353 lines
12 KiB
353 lines
12 KiB
|
3 years ago
|
package positionkpi
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/assessmentmodel"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/hrsystem"
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
//岗位定性指标及指标细则
|
||
|
|
|
||
|
|
// 获取指标关联的岗位
|
||
|
|
func (a *ApiMethod) TargetOrgList(c *gin.Context) {
|
||
|
|
var requestData idType
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
response.Result(100, err, "参数错误!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var targetPostCont assessmentmodel.PostTarget
|
||
|
|
tarErr := targetPostCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "rele_depart", "departments_post")
|
||
|
|
if tarErr != nil {
|
||
|
|
response.Result(100, err, "该指标不存在", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
postAry := strings.Split(targetPostCont.DepartmentsPost, ",")
|
||
|
|
|
||
|
|
var outList postTargetDepart
|
||
|
|
outList.DepartmentId = strconv.FormatInt(targetPostCont.ReleDepart, 10)
|
||
|
|
var postContAry []hrsystem.AdministrativeOrganization
|
||
|
|
var postContAryErr error
|
||
|
|
if len(postAry) > 0 {
|
||
|
|
postContAry, postContAryErr = getOrgList(postAry)
|
||
|
|
if postContAryErr != nil {
|
||
|
|
postContAry, postContAryErr = getOrgList(targetPostCont.ReleDepart)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
postContAry, postContAryErr = getOrgList(targetPostCont.ReleDepart)
|
||
|
|
}
|
||
|
|
for _, v := range postContAry {
|
||
|
|
var outOrgCont idAndName
|
||
|
|
outOrgCont.Id = strconv.FormatInt(v.Id, 10)
|
||
|
|
outOrgCont.Name = v.Name
|
||
|
|
outList.PostList = append(outList.PostList, outOrgCont)
|
||
|
|
}
|
||
|
|
response.Result(0, outList, "查询成功!", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取行政组织岗位
|
||
|
|
func getOrgList(wher interface{}) (orgCont []hrsystem.AdministrativeOrganization, err error) {
|
||
|
|
switch wher.(type) {
|
||
|
|
case []string:
|
||
|
|
err = global.GVA_DB_HrDataBase.Model(&hrsystem.AdministrativeOrganization{}).Select("`id`,`name`").Where("`id` IN ?", wher).Find(&orgCont).Error
|
||
|
|
case int64:
|
||
|
|
err = global.GVA_DB_HrDataBase.Model(&hrsystem.AdministrativeOrganization{}).Select("`id`,`name`").Where("`superior` = ?", wher).Find(&orgCont).Error
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// 添加岗位细则
|
||
|
|
func (a *ApiMethod) AddPostTargetCont(c *gin.Context) {
|
||
|
|
var requestData addPostContTarget
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
if requestData.TargetId == "" {
|
||
|
|
response.Result(100, requestData, "请选择岗位指标!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.DepartmentId == "" {
|
||
|
|
response.Result(101, requestData, "请选择行政组织!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.TargetSunTitle == "" {
|
||
|
|
response.Result(102, requestData, "请输入子栏目名称!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(requestData.PostId) < 1 {
|
||
|
|
response.Result(103, requestData, "请选择岗位!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(requestData.List) < 1 {
|
||
|
|
response.Result(104, requestData, "请输入指标细则!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
xiZeIsTrue := 1
|
||
|
|
for _, v := range requestData.List {
|
||
|
|
if v.Title == "" {
|
||
|
|
xiZeIsTrue = 2
|
||
|
|
break
|
||
|
|
}
|
||
|
|
if v.ReferenceScore == "" {
|
||
|
|
xiZeIsTrue = 2
|
||
|
|
break
|
||
|
|
}
|
||
|
|
if v.Unit == "" {
|
||
|
|
xiZeIsTrue = 2
|
||
|
|
break
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if xiZeIsTrue != 1 {
|
||
|
|
response.Result(105, requestData, "请检查你输入的指标细则!其中有不符合标准的细则!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
targetSunIdInt, _ := strconv.ParseInt(requestData.TargetId, 10, 64)
|
||
|
|
deartmentIdInt, _ := strconv.ParseInt(requestData.DepartmentId, 10, 64)
|
||
|
|
//指标子栏目
|
||
|
|
var sunTargetCont assessmentmodel.PostSunTarget
|
||
|
|
sunErr := sunTargetCont.GetCont(map[string]interface{}{"`title`": requestData.TargetSunTitle, "`parent_id`": requestData.TargetId, "depart": requestData.DepartmentId}, "`id`")
|
||
|
|
if sunErr != nil {
|
||
|
|
sunTargetCont.Title = requestData.TargetSunTitle //标题"`
|
||
|
|
|
||
|
|
sunTargetCont.ParentId = targetSunIdInt //归属指标"`
|
||
|
|
sunTargetCont.Time = time.Now().Unix() //创建时间"`
|
||
|
|
sunTargetCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
||
|
|
|
||
|
|
sunTargetCont.Depart = deartmentIdInt //关联部门"`
|
||
|
|
sunTargetCont.DepartPost = strings.Join(requestData.PostId, ",")
|
||
|
|
sunTargetErr := global.GVA_DB_Performanceappraisal.Create(&sunTargetCont).Error
|
||
|
|
if sunTargetErr != nil {
|
||
|
|
response.Result(108, sunTargetCont, "数据写入失败!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if sunTargetCont.Id == 0 {
|
||
|
|
response.Result(109, sunErr, "数据写入失败!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var saveData []assessmentmodel.PostTargetDetails
|
||
|
|
for _, lv := range requestData.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 = 4
|
||
|
|
}
|
||
|
|
if lv.CycleAttr == 0 {
|
||
|
|
lv.CycleAttr = 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 saveCont assessmentmodel.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.Cycle //检查频次"`
|
||
|
|
saveCont.Cycles = lv.CycleAttr //1:班;2:天;3:周;4:月;5:季度;6:年"`
|
||
|
|
saveCont.CycleAttres = lv.CycleAttr //辅助计数"`
|
||
|
|
saveCont.Paretment = deartmentIdInt //接受考核的部门"`
|
||
|
|
saveCont.ParetmentPost = strings.Join(requestData.PostId, ",") //接受考核的部门岗位"`
|
||
|
|
saveData = append(saveData, saveCont)
|
||
|
|
}
|
||
|
|
if len(saveData) < 1 {
|
||
|
|
response.Result(106, sunErr, "数据写入失败!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
saveErr := global.GVA_DB_Performanceappraisal.Create(&saveData).Error
|
||
|
|
if saveErr != nil {
|
||
|
|
response.Result(107, sunErr, "数据写入失败!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
//获取该子栏目关联到的岗位
|
||
|
|
var tarPostDetaList []assessmentmodel.PostTargetDetails
|
||
|
|
tarErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.PostTargetDetails{}).Select("paretment_post").Where("`state` = 1 AND `parentid` = ? AND `parentid_sun` = ? AND `paretment` =?", requestData.TargetId, targetSunIdInt, deartmentIdInt).Find(&tarPostDetaList).Error
|
||
|
|
if tarErr == nil {
|
||
|
|
var postIdStr []string
|
||
|
|
for _, tarv := range tarPostDetaList {
|
||
|
|
if tarv.ParetmentPost != "" {
|
||
|
|
detPost := strings.Split(tarv.ParetmentPost, ",")
|
||
|
|
if len(detPost) > 0 {
|
||
|
|
for _, detv := range detPost {
|
||
|
|
if commonus.IsInTrue[string](detv, postIdStr) == false {
|
||
|
|
postIdStr = append(postIdStr, detv)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(postIdStr) > 0 {
|
||
|
|
var sunTargetContInfo assessmentmodel.PostSunTarget
|
||
|
|
sunTargetContInfo.EditCont(map[string]interface{}{"`id`": sunTargetCont.Id}, map[string]interface{}{"depart_post": strings.Join(postIdStr, ",")})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
response.Result(0, saveErr, "数据写入成功!", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 岗位定性考核列表
|
||
|
|
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 []assessmentmodel.PostTargetDetails
|
||
|
|
gormDb := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.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 commonus.IsItTrueString(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 commonus.IsItTrueString(findWherType, findInSetType) == false {
|
||
|
|
findInSetType = append(findInSetType, findWherType)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if len(findInSetType) > 0 {
|
||
|
|
gormDb = gormDb.Where(strings.Join(findInSetType, " OR "))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
var total int64
|
||
|
|
totalErr := gormDb.Count(&total).Error
|
||
|
|
if totalErr != nil {
|
||
|
|
total = 0
|
||
|
|
}
|
||
|
|
|
||
|
|
err := gormDb.Order("`id` desc").Limit(requestData.PageSize).Offset(commonus.CalculatePages(requestData.Page, requestData.PageSize)).Find(&postDetails).Error
|
||
|
|
if err != nil {
|
||
|
|
response.Result(103, err.Error(), "没有数据!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
countSum := len(postDetails)
|
||
|
|
printData := commonus.OutPutList(total, int64(countSum), requestData.Page, requestData.PageSize, postDetails)
|
||
|
|
response.Result(0, printData, "查询成功!", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取岗位定性指标关联岗位列表
|
||
|
|
func (a *ApiMethod) GetPostTargetPost(c *gin.Context) {
|
||
|
|
var requestData idType
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
response.Result(100, err, "您的请求数据不合法", c)
|
||
|
|
}
|
||
|
|
var postTargetCont assessmentmodel.PostTarget
|
||
|
|
postErr := postTargetCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`id`", "`rele_depart`", "`departments_post`", "`key`")
|
||
|
|
if postErr != nil {
|
||
|
|
response.Result(100, postErr, "没有该数据!", c)
|
||
|
|
}
|
||
|
|
var outData getTargetPost
|
||
|
|
outData.Id = requestData.Id
|
||
|
|
outData.DepartmentId = strconv.FormatInt(postTargetCont.ReleDepart, 10)
|
||
|
|
postId := strings.Split(postTargetCont.DepartmentsPost, ",")
|
||
|
|
if len(postId) < 1 {
|
||
|
|
response.Result(0, outData, "查询成功!", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
for _, v := range postId {
|
||
|
|
if commonus.IsInTrue[string](v, outData.PostId) == false {
|
||
|
|
var postContAry hrsystem.Position
|
||
|
|
posErr := postContAry.GetCont(map[string]interface{}{"`id`": v}, "`name`")
|
||
|
|
if posErr == nil {
|
||
|
|
outData.PostId = append(outData.PostId, v)
|
||
|
|
var ordPostCont departmentmap
|
||
|
|
ordPostCont.Parentid = v
|
||
|
|
ordPostCont.Parentname = postContAry.Name
|
||
|
|
outData.Departmentmap = append(outData.Departmentmap, ordPostCont)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
response.Result(0, outData, "查询成功!", c)
|
||
|
|
}
|
||
|
|
|
||
|
|
// 修改定性指标关联岗位
|
||
|
|
func (a *ApiMethod) EditPostTargetQual(c *gin.Context) {
|
||
|
|
var requestData editTargetPostData
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
response.Result(100, err, "您的请求数据不合法", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.Id == "" {
|
||
|
|
response.Result(100, err, "您的请求数据不合法", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(requestData.PostId) < 1 {
|
||
|
|
response.Result(100, err, "请指定要关联的岗位", c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
// postAryStr := strings.Join(, ",")
|
||
|
|
// where := commonus.MapOut()
|
||
|
|
// where["`id`"] = requestData.Id
|
||
|
|
|
||
|
|
}
|