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.
1586 lines
66 KiB
1586 lines
66 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"
|
|
)
|
|
|
|
// 部门指标列表
|
|
func (a *ApiMethod) DepartmentTargetList(c *gin.Context) {
|
|
var receivedValue departListQuery
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.Page == 0 {
|
|
receivedValue.Page = 1
|
|
}
|
|
if receivedValue.PageSize == 0 {
|
|
receivedValue.PageSize = 20
|
|
}
|
|
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{})
|
|
if receivedValue.State != 0 { //状态(1:启用;2:禁用;3:删除)
|
|
gormDb = gormDb.Where("et_state = ?", receivedValue.State)
|
|
} else {
|
|
gormDb = gormDb.Where("et_state BETWEEN ? AND ?", 1, 2)
|
|
}
|
|
if receivedValue.Title != "" { //指标名称
|
|
gormDb = gormDb.Where("et_state LIKE ?", "%"+receivedValue.Title+"%")
|
|
}
|
|
if receivedValue.Class != 0 { //1:定性考核;2:定量考核
|
|
gormDb = gormDb.Where("et_type = ?", receivedValue.Class)
|
|
}
|
|
if receivedValue.DepartmentId != "" { //部门ID
|
|
gormDb = gormDb.Where("FIND_IN_SET(?,`departments_post`)", receivedValue.DepartmentId)
|
|
}
|
|
if receivedValue.DimensionId != "" { //维度ID
|
|
gormDb = gormDb.Where("et_dimension = ?", receivedValue.DimensionId)
|
|
}
|
|
if receivedValue.ReportPerson != "" { //上报人
|
|
gormDb = gormDb.Where("FIND_IN_SET(?,`et_report`)", receivedValue.ReportPerson)
|
|
}
|
|
if receivedValue.ScoringMethod != 0 { //计分方式(1:自动;2:手动)
|
|
gormDb = gormDb.Where("et_scoring_method = ?", receivedValue.ScoringMethod)
|
|
}
|
|
if receivedValue.Cycle != 0 { //1:班;2:天;3:周;4:月;5:季度;6:年
|
|
gormDb = gormDb.Where("et_cycle = ?", receivedValue.Cycle)
|
|
}
|
|
|
|
var total int64
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
var departmentTargetList []modelskpi.EvaluationTarget
|
|
gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize)
|
|
err := gormDb.Order("`et_id` DESC").Find(&departmentTargetList).Error
|
|
if err != nil {
|
|
publicmethod.Result(105, err, c)
|
|
return
|
|
}
|
|
var targetList []printDepartmentTarget
|
|
for _, v := range departmentTargetList {
|
|
var targetCont printDepartmentTarget
|
|
targetCont.Id = v.Id
|
|
targetCont.Title = v.Title //指标名称"`
|
|
targetCont.Type = v.Type //1:定性考核;2:定量考核"`
|
|
targetCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
|
|
targetCont.AddTime = v.AddTime //制定时间"`
|
|
targetCont.Share = v.Share //1:共用;2:私用"`
|
|
targetCont.RelevantDepartments = v.RelevantDepartments //相关部门"`
|
|
targetCont.Dimension = v.Dimension //维度"`
|
|
targetCont.Key = v.Key //UUID"`
|
|
targetCont.Report = v.Report //上报人"`
|
|
targetCont.Uniteing = v.Uniteing //计量单位"`
|
|
targetCont.Cycles = v.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年"`
|
|
targetCont.CycleAttres = v.CycleAttres //辅助计数"`
|
|
targetCont.VisibleRange = v.VisibleRange //可见范围"`
|
|
targetCont.VisibleRangeGroup = v.VisibleRangeGroup //可见范围(集团)"`
|
|
targetCont.ScoringMethod = v.ScoringMethod //计分方式(1:自动;2:手动)"`
|
|
var dutyClassCont modelskpi.DutyClass
|
|
dutyClassCont.GetCont(map[string]interface{}{"`id`": v.Dimension}, "`title`")
|
|
targetCont.DimensionTitle = dutyClassCont.Title
|
|
targetList = append(targetList, targetCont)
|
|
}
|
|
publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(targetList)), targetList, c)
|
|
}
|
|
|
|
// 实验查询
|
|
func (a *ApiMethod) Shiyan(c *gin.Context) {
|
|
// var receivedValue departListQuery
|
|
// c.ShouldBindJSON(&receivedValue)
|
|
|
|
// if receivedValue.DepartmentId == "" {
|
|
// receivedValue.DepartmentId = "316"
|
|
// }
|
|
// if receivedValue.DimensionId == "" {
|
|
// receivedValue.DimensionId = "1"
|
|
// }
|
|
|
|
// var evalCont []modelskpi.EvaluationTarget
|
|
|
|
// // gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.EvaluationTarget{}).Select("evaluationtarget.*,(?) AS tdm", overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Select("id").Where("department_id = ? AND target_id = et_id ", receivedValue.DepartmentId).Find(&modelskpi.TargetDepartment{})).Having("tdm IS NOT NULL").Find(&evalCont).Error
|
|
// // fmt.Printf("gormDb----->%v----->%v\n", gormDb, evalCont)
|
|
// err := overall.CONSTANT_DB_KPI.Raw("SELECT e.*,(SELECT id FROM target_department td WHERE td.department_id = ? AND td.post_id = ? AND td.target_id = e.et_id) as tdm FROM evaluationtarget e HAVING tdm IS NOT NULL", receivedValue.DepartmentId, receivedValue.DimensionId).Scan(&evalCont).Error
|
|
// fmt.Printf("gormDb----->%v----->%v\n", err, evalCont)
|
|
//校正部门级考核
|
|
var dimeTargetList []modelskpi.DetailedTarget
|
|
err := overall.CONSTANT_DB_KPI.Where("dt_state = 1").Find(&dimeTargetList).Error
|
|
if err != nil || len(dimeTargetList) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
// fmt.Printf("总数---->%v\n", len(dimeTargetList))
|
|
// var xieChengChuli []modelskpi.DetailedTarget
|
|
// for i, v := range dimeTargetList {
|
|
// if (i+1)%100 == 0 {
|
|
// xieChengChuli = append(xieChengChuli, v)
|
|
// fmt.Printf("循环--%v-->%v\n", i, len(xieChengChuli))
|
|
// xieChengChuli = []modelskpi.DetailedTarget{}
|
|
// } else {
|
|
// xieChengChuli = append(xieChengChuli, v)
|
|
// }
|
|
// }
|
|
|
|
for _, v := range dimeTargetList {
|
|
xiaoZhengBuMen(v)
|
|
}
|
|
|
|
fmt.Printf("jieshu---->%v\n", len(dimeTargetList))
|
|
}
|
|
|
|
// 校正部门定性考核关联关系
|
|
func xiaoZhengBuMen(detaTar modelskpi.DetailedTarget) {
|
|
if detaTar.Paretment != "" {
|
|
bumenAry := strings.Split(detaTar.Paretment, ",")
|
|
if len(bumenAry) > 0 {
|
|
for _, v := range bumenAry {
|
|
zbLmXzBm(detaTar.ParentId, detaTar.ParentIdSun, detaTar.Id, 3, v)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
var assTar modelskpi.Assesstarget
|
|
assErr := overall.CONSTANT_DB_KPI.Where("`targetid` = ? AND `suntargetid` = ?", detaTar.ParentId, detaTar.ParentIdSun).First(&assTar).Error
|
|
if assErr == nil {
|
|
var reportAry []zhuanHuanMan
|
|
jsonErr := json.Unmarshal([]byte(assTar.Content), &reportAry)
|
|
if jsonErr == nil {
|
|
for _, mv := range reportAry {
|
|
if mv.Id == detaTar.Id {
|
|
if len(mv.Operator) > 0 {
|
|
for _, ov := range mv.Operator {
|
|
juadgeReport(detaTar.ParentId, detaTar.ParentIdSun, detaTar.Id, 1, ov)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 判断该指标细则是否已经存在上报人
|
|
/*
|
|
@tarId 指标
|
|
@sunId 栏目
|
|
@lawsId 细则
|
|
@class 类型(1:指标;2:子目标;3:细则)
|
|
@manKey 上报人
|
|
*/
|
|
func juadgeReport(tarId, sunId, lawsId int64, class int, manKey string) {
|
|
if class == 0 {
|
|
class = 1
|
|
}
|
|
var trCont modelskpi.TargetReport
|
|
err := trCont.GetCont(map[string]interface{}{`type`: class, `target_id`: tarId, `target_sun_id`: sunId, `target_bylaws`: lawsId, `man_key`: manKey})
|
|
if err == nil {
|
|
if trCont.State != 1 {
|
|
saveErr := trCont.EiteCont(map[string]interface{}{"`id`": trCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
|
|
fmt.Printf("编辑---->tarId----%v---->sunId----%v---->lawsId----%v---->class----%v---->bumenId----%v------>saveErr----->%v\n", tarId, sunId, lawsId, class, manKey, saveErr)
|
|
}
|
|
} else {
|
|
trCont.TargetId = tarId //指标ID"`
|
|
trCont.TargetSunId = sunId //子目标"`
|
|
trCont.TargetBylaws = lawsId //指标细则"`
|
|
trCont.DepartmentId = 0 //部门ID"`
|
|
trCont.PostId = 0 //岗位ID"`
|
|
trCont.Type = class //类型(1:公司级;2:部门级)"`
|
|
trCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
manKeyInt, _ := strconv.ParseInt(manKey, 10, 64)
|
|
trCont.ReportPerson = manKeyInt //上报人"`
|
|
trCont.Time = time.Now().Unix()
|
|
trCont.Class = 1
|
|
addErr := overall.CONSTANT_DB_KPI.Create(&trCont).Error
|
|
fmt.Printf("编辑---->tarId----%v---->sunId----%v---->lawsId----%v---->class----%v---->bumenId----%v------>saveErr----->%v\n", tarId, sunId, lawsId, class, manKey, addErr)
|
|
}
|
|
}
|
|
|
|
//编辑指标、栏目、细则关联部门
|
|
/*
|
|
@tarId 指标
|
|
@sunId 栏目
|
|
@lawsId 细则
|
|
@class 类型(1:指标;2:子目标;3:细则)
|
|
@bumenId 部门
|
|
*/
|
|
func zbLmXzBm(tarId, sunId, lawsId int64, class int, bumenId string) {
|
|
var tarDepCont modelskpi.TargetDepartment
|
|
where := publicmethod.MapOut[string]()
|
|
where["`target_id`"] = tarId
|
|
where["`target_sun_id`"] = sunId
|
|
where["`target_bylaws`"] = lawsId
|
|
where["`department_id`"] = bumenId
|
|
err := tarDepCont.GetCont(where, "`id`", "`state`")
|
|
if err == nil {
|
|
//存在,判断状态
|
|
if tarDepCont.State != 1 { //不是启用状态,改为启用
|
|
eidtWher := publicmethod.MapOut[string]()
|
|
eidtWher["``id``"] = tarDepCont.Id
|
|
saveErr := tarDepCont.EiteCont(eidtWher, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()})
|
|
|
|
fmt.Printf("编辑---->tarId----%v---->sunId----%v---->lawsId----%v---->class----%v---->bumenId----%v------>saveErr----->%v\n", tarId, sunId, lawsId, class, bumenId, saveErr)
|
|
}
|
|
} else {
|
|
tarDepCont.TargetId = tarId //指标ID"`
|
|
tarDepCont.TargetSunId = sunId //子目标"`
|
|
tarDepCont.TargetBylaws = lawsId //指标细则"`
|
|
tarDepCont.Type = class //类型(1:指标;2:子目标;3:细则)"`
|
|
bumenIdInt, _ := strconv.ParseInt(bumenId, 10, 64)
|
|
tarDepCont.DepartmentId = bumenIdInt //部门ID"`
|
|
tarDepCont.PostId = 0 //岗位ID"`
|
|
tarDepCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
tarDepCont.Time = time.Now().Unix() //写入时间"`
|
|
tarDepCont.Class = 1
|
|
addErr := overall.CONSTANT_DB_KPI.Create(&tarDepCont).Error
|
|
fmt.Printf("编辑---->tarId----%v---->sunId----%v---->lawsId----%v---->class----%v---->bumenId----%v------>saveErr----->%v\n", tarId, sunId, lawsId, class, bumenId, addErr)
|
|
}
|
|
}
|
|
|
|
// 获取部门定性考核部门关联列表
|
|
func (a *ApiMethod) GetDepartAboutTarget(c *gin.Context) {
|
|
var receivedValue publicmethod.PublicId
|
|
err := c.ShouldBindJSON(&receivedValue)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
var targetDepartmentID []int64
|
|
disrErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = 1 AND `target_id` = ?", receivedValue.Id).Find(&targetDepartmentID).Error
|
|
if disrErr != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var departmentList []modelshr.AdministrativeOrganization
|
|
departErr := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`superior`,`ispower`").Where("`id` IN ?", targetDepartmentID).Find(&departmentList).Error
|
|
if departErr != nil || len(departmentList) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var outList []departOutcome
|
|
for _, v := range departmentList {
|
|
var outCont departOutcome
|
|
outCont.Id = strconv.FormatInt(v.Id, 10)
|
|
outCont.Name = v.Name
|
|
outCont.Superior = strconv.FormatInt(v.Superior, 10)
|
|
outCont.Ispower = v.IsPower
|
|
outList = append(outList, outCont)
|
|
}
|
|
publicmethod.Result(0, outList, c)
|
|
}
|
|
|
|
// 获取部门指标相关执行人
|
|
func (a *ApiMethod) GetTargetReport(c *gin.Context) {
|
|
var receivedValue getAboutReportTarget
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.TargetId == "" {
|
|
publicmethod.Result(1, receivedValue, c, "指标不能为空!")
|
|
return
|
|
}
|
|
var userKey []int64
|
|
typeClass := 1
|
|
if receivedValue.DepartmentId != "" || receivedValue.PostId != "" {
|
|
typeClass = 2
|
|
}
|
|
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = ? AND `type` = ? AND `target_id` = ?", 1, typeClass, receivedValue.TargetId)
|
|
|
|
if receivedValue.TargetSunId != "" {
|
|
gormDb = gormDb.Where("`target_sun_id` = ?", receivedValue.TargetSunId)
|
|
}
|
|
if receivedValue.TargetBylaws != "" {
|
|
gormDb = gormDb.Where("`target_bylaws` = ?", receivedValue.TargetBylaws)
|
|
}
|
|
if receivedValue.DepartmentId != "" {
|
|
gormDb = gormDb.Where("`department_id` = ?", receivedValue.DepartmentId)
|
|
}
|
|
if receivedValue.PostId != "" {
|
|
gormDb = gormDb.Where("`post_id` = ?", receivedValue.PostId)
|
|
}
|
|
err := gormDb.Find(&userKey).Error
|
|
if err != nil || len(userKey) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
//上报人信息
|
|
var reportManList []modelshr.PersonArchives
|
|
rmlErr := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`number`,`name`,`icon`,`company`,`maindeparment`").Where("`key` IN ?", userKey).Find(&reportManList).Error
|
|
if rmlErr != nil && len(reportManList) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var reportListCont []printReportCont
|
|
for _, v := range reportManList {
|
|
var reportCont printReportCont
|
|
reportCont.Id = strconv.FormatInt(v.Id, 10)
|
|
reportCont.Name = v.Name
|
|
var groupConb modelshr.AdministrativeOrganization
|
|
groupConb.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
|
|
reportCont.GroupName = groupConb.Name
|
|
var departmentConb modelshr.AdministrativeOrganization
|
|
departmentConb.GetCont(map[string]interface{}{"`id`": v.MainDeparment}, "`name`")
|
|
reportCont.DepartmentName = departmentConb.Name
|
|
reportCont.Icon = v.Icon
|
|
reportCont.Number = v.Number
|
|
reportListCont = append(reportListCont, reportCont)
|
|
}
|
|
outData := publicmethod.MapOut[string]()
|
|
outData["userlist"] = userKey
|
|
outData["userlistary"] = reportListCont
|
|
publicmethod.Result(0, outData, c)
|
|
}
|
|
|
|
// 添加定性考核子栏目及细则
|
|
func (a *ApiMethod) AddSunTargetDetailed(c *gin.Context) {
|
|
var receivedValue AddQualEval
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if len(receivedValue.AcceptDepartmentId) <= 0 {
|
|
publicmethod.Result(1, receivedValue, c, "请选择接受考核的部门!")
|
|
return
|
|
}
|
|
if receivedValue.Target == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请选择考核指标")
|
|
return
|
|
}
|
|
if receivedValue.TargetSunTitle == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请输入栏目名称!")
|
|
return
|
|
}
|
|
if len(receivedValue.EvaluationList) <= 0 {
|
|
publicmethod.Result(1, receivedValue, c, "请添加测评详情!")
|
|
return
|
|
} else {
|
|
isWrite := true
|
|
for _, jv := range receivedValue.EvaluationList {
|
|
if jv.Title == "" || jv.Unit == "" || jv.ReferenceScore == "" {
|
|
isWrite = false
|
|
}
|
|
}
|
|
if isWrite == false {
|
|
publicmethod.Result(1, receivedValue, c, "指标细则有为填写的内容!请检查!")
|
|
return
|
|
}
|
|
}
|
|
tragetId, _ := strconv.ParseInt(receivedValue.Target, 10, 64)
|
|
//判断子目标是否存在
|
|
var judgeSunTarget modelskpi.QualitativeTarget
|
|
saveSunTarget := modelskpi.QualitativeTarget{
|
|
Title: receivedValue.TargetSunTitle, // 指标子栏目名称
|
|
ParentId: tragetId, //归属指标
|
|
State: 1, //状态(1:启用;2:禁用;3:删除)
|
|
AddTime: time.Now().Unix(), //制定时间"`
|
|
Depart: strings.Join(receivedValue.AcceptDepartmentId, ","), //关联部门"`
|
|
}
|
|
judgeSunTarErr := judgeSunTarget.JudgeIsTrue(map[string]interface{}{"q_title": receivedValue.TargetSunTitle, "q_parent_id": receivedValue.Target}, saveSunTarget)
|
|
if judgeSunTarErr != nil {
|
|
publicmethod.Result(106, judgeSunTarErr, c)
|
|
return
|
|
}
|
|
//子表细则处理
|
|
|
|
for _, v := range receivedValue.EvaluationList {
|
|
//判断指标细则是否已经存在
|
|
var judgeDetaCont modelskpi.DetailedTarget
|
|
judgeDetaErr := judgeDetaCont.GetCont(map[string]interface{}{"`dt_parentid`": receivedValue.Target, "`dt_parentid_sun`": judgeSunTarget.Id, "`dt_title`": v.Title})
|
|
if judgeDetaErr == nil {
|
|
editDetaAdd(judgeDetaCont.ParentId, judgeDetaCont.ParentIdSun, v, judgeDetaCont, receivedValue.AcceptDepartmentId)
|
|
} else {
|
|
addDetaInfo(tragetId, judgeSunTarget.Id, v, receivedValue.AcceptDepartmentId)
|
|
}
|
|
}
|
|
publicmethod.Result(0, receivedValue, c)
|
|
}
|
|
|
|
/*
|
|
添加指标细则
|
|
@targetId 指标ID
|
|
@sunTargetId 栏目ID
|
|
@qualEvalCont 提交的参数
|
|
@departmentAry 接受考核部门
|
|
*/
|
|
func addDetaInfo(targetId, sunTargetId int64, qualEvalCont QualEvalSunList, departmentAry []string) (err error) {
|
|
|
|
var minScoreInt int64 = 0
|
|
var maxScoreInt int64 = 0
|
|
scoreAry := strings.Split(qualEvalCont.ReferenceScore, "-")
|
|
scoreLen := len(scoreAry)
|
|
if scoreLen > 0 {
|
|
if scoreLen == 1 {
|
|
maxScore, _ := strconv.ParseFloat(scoreAry[0], 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)
|
|
}
|
|
}
|
|
var targetCont modelskpi.EvaluationTarget
|
|
targetCont.GetCont(map[string]interface{}{"et_id": targetId}, "et_unit", "et_cycle")
|
|
//单位
|
|
unitName := qualEvalCont.Unit
|
|
if unitName == "" {
|
|
unitName = targetCont.Uniteing
|
|
}
|
|
//计分属性
|
|
addOrReduce := qualEvalCont.AddOrReduce
|
|
if qualEvalCont.AddOrReduce == 0 {
|
|
addOrReduce = 1
|
|
}
|
|
//统计周期
|
|
cyclesInt := qualEvalCont.Cycles
|
|
if cyclesInt == 0 {
|
|
cyclesInt = 4
|
|
}
|
|
cycleAttresInt := qualEvalCont.CycleAttres
|
|
if cycleAttresInt == 0 {
|
|
cycleAttresInt = 1
|
|
}
|
|
//接受考核部门
|
|
if len(departmentAry) < 1 {
|
|
//获取指标所有关联部门
|
|
var aboutTarDepList []int64
|
|
aboutTDErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = 1 AND `target_id` = ?", targetId).Find(&aboutTarDepList).Error
|
|
if aboutTDErr == nil {
|
|
for _, atdv := range aboutTarDepList {
|
|
departmentAry = append(departmentAry, strconv.FormatInt(atdv, 10))
|
|
}
|
|
}
|
|
|
|
}
|
|
operatorList := qualEvalCont.Operator
|
|
//提报人
|
|
if len(operatorList) < 1 {
|
|
//获取指标所有关联部门
|
|
var aboutTarReportList []int64
|
|
aboutTDErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = 1 AND `target_id` = ?", targetId).Find(&aboutTarReportList).Error
|
|
if aboutTDErr == nil {
|
|
for _, atrv := range aboutTarReportList {
|
|
operatorList = append(operatorList, strconv.FormatInt(atrv, 10))
|
|
}
|
|
}
|
|
|
|
}
|
|
var detaildeTarInfo modelskpi.DetailedTarget
|
|
detaildeTarInfo.Title = qualEvalCont.Title //指标细则"`
|
|
detaildeTarInfo.Content = qualEvalCont.Content //指标说明"`
|
|
detaildeTarInfo.ParentId = targetId //归属指标栏目"`
|
|
detaildeTarInfo.ParentIdSun = sunTargetId //归属指标子栏目"`
|
|
detaildeTarInfo.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
detaildeTarInfo.AddTime = time.Now().Unix() //制定时间"`
|
|
detaildeTarInfo.MinScore = minScoreInt //最小分*100保存"`
|
|
detaildeTarInfo.MaxScore = maxScoreInt //最大分*100保存"`
|
|
detaildeTarInfo.Company = unitName //单位"`
|
|
detaildeTarInfo.AddReduce = addOrReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
|
|
detaildeTarInfo.CensorType = strings.Join(qualEvalCont.CensorType, ",") //检查方式"`
|
|
detaildeTarInfo.CensorCont = qualEvalCont.CensorCont //检查依据"`
|
|
detaildeTarInfo.CensorRate = qualEvalCont.CensorRate //检查频次"`
|
|
detaildeTarInfo.Cycles = cyclesInt //1:班;2:天;3:周;4:月;5:季度;6:年"`
|
|
detaildeTarInfo.CycleAttres = cycleAttresInt //辅助计数"`
|
|
detaildeTarInfo.Paretment = strings.Join(departmentAry, ",") //接受考核的部门"`
|
|
detaildeTarInfo.Reportary = strings.Join(operatorList, ",") //提报人"`
|
|
err = overall.CONSTANT_DB_KPI.Create(&detaildeTarInfo).Error
|
|
if err == nil {
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetDepart(targetId, sunTargetId, detaildeTarInfo.Id, departmentAry, 1)
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetRepart(targetId, sunTargetId, detaildeTarInfo.Id, operatorList, 1)
|
|
syncSeting.Wait()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
/*
|
|
编辑已经存在的指标细则
|
|
@targetId 指标ID
|
|
@sunTargetId 栏目ID
|
|
@qualEvalCont 提交的参数
|
|
@detailInfof 查询到的参数
|
|
@departmentAry 接受考核部门
|
|
*/
|
|
func editDetaAdd(targetId, sunTargetId int64, qualEvalCont QualEvalSunList, detailInfof modelskpi.DetailedTarget, departmentAry []string) (err error) {
|
|
saveData := publicmethod.MapOut[string]()
|
|
|
|
if targetId != detailInfof.ParentId {
|
|
saveData["dt_parentid"] = targetId
|
|
}
|
|
if sunTargetId != detailInfof.ParentIdSun {
|
|
saveData["dt_parentid_sun"] = sunTargetId
|
|
}
|
|
|
|
if qualEvalCont.Title != "" && qualEvalCont.Title != detailInfof.Title {
|
|
saveData["dt_title"] = qualEvalCont.Title
|
|
}
|
|
if qualEvalCont.Content != "" && qualEvalCont.Content != detailInfof.Content {
|
|
saveData["dt_content"] = qualEvalCont.Content
|
|
}
|
|
if qualEvalCont.Unit != "" && qualEvalCont.Unit != detailInfof.Company {
|
|
saveData["dt_company"] = qualEvalCont.Unit
|
|
}
|
|
if qualEvalCont.Cycles != 0 && qualEvalCont.Cycles != detailInfof.Cycles {
|
|
saveData["dt_cycle"] = qualEvalCont.Cycles
|
|
}
|
|
if qualEvalCont.CycleAttres != 0 && qualEvalCont.CycleAttres != detailInfof.CycleAttres {
|
|
saveData["dt_cycleattr"] = qualEvalCont.CycleAttres
|
|
}
|
|
if qualEvalCont.AddOrReduce != 0 && qualEvalCont.AddOrReduce != detailInfof.AddReduce {
|
|
saveData["dt_add_reduce"] = qualEvalCont.AddOrReduce
|
|
}
|
|
censStr := strings.Join(qualEvalCont.CensorType, ",")
|
|
if len(qualEvalCont.CensorType) > 0 {
|
|
if censStr != detailInfof.CensorType {
|
|
saveData["dt_censor_type"] = censStr
|
|
}
|
|
}
|
|
if qualEvalCont.CensorCont != "" && qualEvalCont.CensorCont != detailInfof.CensorCont {
|
|
saveData["dt_censor_cont"] = qualEvalCont.CensorCont
|
|
}
|
|
if qualEvalCont.CensorRate != 0 && qualEvalCont.CensorRate != detailInfof.CensorRate {
|
|
saveData["dt_censor_rate"] = qualEvalCont.CensorRate
|
|
}
|
|
|
|
var minScoreInt int64 = 0
|
|
var maxScoreInt int64 = 0
|
|
scoreAry := strings.Split(qualEvalCont.ReferenceScore, "-")
|
|
scoreLen := len(scoreAry)
|
|
if scoreLen > 0 {
|
|
if scoreLen == 1 {
|
|
maxScore, _ := strconv.ParseFloat(scoreAry[0], 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)
|
|
}
|
|
}
|
|
if minScoreInt != detailInfof.MinScore {
|
|
saveData["dt_min_score"] = minScoreInt
|
|
}
|
|
if maxScoreInt != detailInfof.MaxScore {
|
|
saveData["dt_max_score"] = maxScoreInt
|
|
}
|
|
departStr := strings.Join(departmentAry, ",")
|
|
if departStr != detailInfof.Paretment {
|
|
saveData["dt_paretment"] = departStr
|
|
}
|
|
reportStr := strings.Join(qualEvalCont.Operator, ",")
|
|
if reportStr != detailInfof.Reportary {
|
|
saveData["reportary"] = reportStr
|
|
}
|
|
if len(saveData) > 0 {
|
|
saveData["dt_time"] = time.Now().Unix()
|
|
var editCont modelskpi.DetailedTarget
|
|
err = editCont.EiteCont(map[string]interface{}{"`dt_id`": detailInfof.Id}, saveData)
|
|
}
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetDepart(targetId, sunTargetId, detailInfof.Id, departmentAry, 1)
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetRepart(targetId, sunTargetId, detailInfof.Id, qualEvalCont.Operator, 1)
|
|
syncSeting.Wait()
|
|
return nil
|
|
}
|
|
|
|
/*
|
|
处理指标细则关联部门
|
|
@targetId 指标ID
|
|
@targetSunId 栏目ID
|
|
@bylawsId 指标细则
|
|
@department 接受考核部门
|
|
@class 级别(1:部门级;2:岗位级)
|
|
*/
|
|
func handleDetarildTargetDepart(targetId, targetSunId, bylawsId int64, department []string, class int) {
|
|
defer syncSeting.Done()
|
|
//将不属于该指标细则的部门至禁用
|
|
otherSaveData := publicmethod.MapOut[string]()
|
|
otherSaveData["`state`"] = 2
|
|
otherSaveData["`time`"] = time.Now().Unix()
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Where("`level` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", class, targetId, targetSunId, bylawsId).Not(map[string]interface{}{"department_id": department}).Updates(&otherSaveData)
|
|
for _, v := range department {
|
|
var tarDepartCont modelskpi.TargetDepartment
|
|
saveErr := tarDepartCont.GetCont(map[string]interface{}{"`level`": class, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": bylawsId, "`department_id`": v}, "`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 && bylawsId == 0 {
|
|
xiZe = 2
|
|
} else if targetId != 0 && targetSunId == 0 && bylawsId == 0 {
|
|
xiZe = 1
|
|
}
|
|
|
|
tarDepartCont.TargetId = targetId //指标ID"`
|
|
tarDepartCont.TargetSunId = targetSunId //子目标"`
|
|
tarDepartCont.TargetBylaws = bylawsId //指标细则"`
|
|
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 = 1 //1:定性考核;2:定量考核"`
|
|
tarDepartCont.Level = class //级别(1:部门级;2:岗位级)"`
|
|
overall.CONSTANT_DB_KPI.Create(&tarDepartCont)
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
处理指标细则关联考核提交人
|
|
@targetId 指标ID
|
|
@targetSunId 栏目ID
|
|
@bylawsId 指标细则
|
|
@repart 考核提交人
|
|
@class 级别(1:部门级;2:岗位级)
|
|
*/
|
|
func handleDetarildTargetRepart(targetId, targetSunId, bylawsId int64, repart []string, class int) {
|
|
defer syncSeting.Done()
|
|
//将不属于该指标细则的部门至禁用
|
|
otherSaveData := publicmethod.MapOut[string]()
|
|
otherSaveData["`state`"] = 2
|
|
otherSaveData["`time`"] = time.Now().Unix()
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Where("`type` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", class, targetId, targetSunId, bylawsId).Not(map[string]interface{}{"man_key": repart}).Updates(&otherSaveData)
|
|
for _, v := range repart {
|
|
//获取评价人部门
|
|
var manCont modelshr.PersonArchives
|
|
manCont.GetCont(map[string]interface{}{"`key`": v}, "`maindeparment`")
|
|
|
|
var tarReportCont modelskpi.TargetReport
|
|
saveErr := tarReportCont.GetCont(map[string]interface{}{"`type`": class, "`target_id`": targetId, "`target_sun_id`": targetSunId, "`target_bylaws`": bylawsId, "`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()})
|
|
}
|
|
} else {
|
|
xiZe := 3
|
|
if targetId != 0 && targetSunId != 0 && bylawsId == 0 {
|
|
xiZe = 2
|
|
} else if targetId != 0 && targetSunId == 0 && bylawsId == 0 {
|
|
xiZe = 1
|
|
}
|
|
|
|
tarReportCont.TargetId = targetId //指标ID"`
|
|
tarReportCont.TargetSunId = targetSunId //子目标"`
|
|
tarReportCont.TargetBylaws = bylawsId //指标细则"`
|
|
tarReportCont.DepartmentId = 0 //部门ID"`
|
|
tarReportCont.PostId = 0 //岗位ID"`
|
|
tarReportCont.Type = class //类型(1:公司级;2:部门级)"`
|
|
tarReportCont.State = 1 //状态(1:启用;2:禁用;3:删除)"`
|
|
reportId, _ := strconv.ParseInt(v, 10, 64)
|
|
tarReportCont.ReportPerson = reportId //上报人"`
|
|
tarReportCont.ManDepartment = manCont.MainDeparment //提报人所在部门"`
|
|
tarReportCont.Time = time.Now().Unix() //写入时间"`
|
|
tarReportCont.Class = 1 //1:定性考核;2:定量考核"`
|
|
tarReportCont.Level = xiZe //1:指标;2:子目标;3:细则
|
|
overall.CONSTANT_DB_KPI.Create(&tarReportCont)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取定性考核指标列表内容
|
|
func (a *ApiMethod) GetDepartmentTragetContList(c *gin.Context) {
|
|
var receivedValue getDepartTargetContType
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.TargetId == "" {
|
|
publicmethod.Result(1, receivedValue, c, "未知指标ID!")
|
|
return
|
|
}
|
|
if receivedValue.Page == 0 {
|
|
receivedValue.Page = 1
|
|
}
|
|
if receivedValue.PageSize == 0 {
|
|
receivedValue.PageSize = 20
|
|
}
|
|
var detaildeList []modelskpi.DetailedTarget
|
|
var detCont modelskpi.DetailedTarget
|
|
gormDb := overall.CONSTANT_DB_KPI.Table(fmt.Sprintf("%s dt", detCont.TableName())).Select("dt.*").Where("dt.dt_state = 1 AND dt.dt_parentid = ?", receivedValue.TargetId)
|
|
//接受考核的部门
|
|
if receivedValue.DepartmentId != "" {
|
|
gormDb = gormDb.Joins("LEFT JOIN `target_department` `td` on td.target_id = dt.dt_parentid AND td.target_sun_id = dt.dt_parentid_sun AND td.target_bylaws = dt.dt_id").Where("td.department_id = ?", receivedValue.DepartmentId)
|
|
}
|
|
//提报人
|
|
if receivedValue.ReportPerson != "" {
|
|
gormDb = gormDb.Joins("LEFT JOIN `target_report` `tr` on tr.target_id = dt.dt_parentid AND tr.target_sun_id = dt.dt_parentid_sun AND tr.target_bylaws = dt.dt_id").Where("tr.man_key = ?", receivedValue.ReportPerson)
|
|
}
|
|
if receivedValue.Cycle != 0 {
|
|
gormDb = gormDb.Where("dt.dt_cycle = ?", receivedValue.Cycle)
|
|
}
|
|
if receivedValue.TargetSunId != "" {
|
|
gormDb = gormDb.Where("dt.dt_parentid_sun = ?", receivedValue.TargetSunId)
|
|
}
|
|
|
|
err := gormDb.Order("dt.dt_parentid desc, dt.dt_parentid_sun").Find(&detaildeList).Error
|
|
if err != nil || len(detaildeList) < 1 {
|
|
publicmethod.Result(107, receivedValue, c)
|
|
return
|
|
}
|
|
var total int64
|
|
totalErr := gormDb.Select("dt_id").Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
var outData []printDepartTargetCont
|
|
for _, v := range detaildeList {
|
|
var outCont printDepartTargetCont
|
|
outCont.Id = v.Id
|
|
outCont.Title = v.Title //指标细则"`
|
|
outCont.Content = v.Content //指标说明"`
|
|
outCont.ParentId = v.ParentId //归属指标栏目"`
|
|
outCont.ParentIdSun = v.ParentIdSun //归属指标子栏目"`
|
|
outCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
|
|
outCont.AddTime = v.AddTime //制定时间"`
|
|
outCont.MinScore = v.MinScore //最小分*100保存"`
|
|
outCont.MaxScore = v.MaxScore //100保存"`
|
|
outCont.Company = v.Company //单位"`
|
|
outCont.AddReduce = v.AddReduce //1:减少;2:增加;3:无属性,现场确认加或减"`
|
|
outCont.CensorType = v.CensorType //检查方式"`
|
|
outCont.CensorCont = v.CensorCont //检查依据"`
|
|
outCont.CensorRate = v.CensorRate //检查频次"`
|
|
outCont.Cycles = v.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年"`
|
|
outCont.CycleAttres = v.CycleAttres //辅助计数"`
|
|
outCont.Paretment = v.Paretment //接受考核的部门"`
|
|
outCont.Reportary = v.Reportary //提报人"`
|
|
|
|
standardStr := ""
|
|
if v.MinScore != 0 {
|
|
standardStr = fmt.Sprintf("%v-%v", publicmethod.DecimalEs(float64(v.MinScore)/100, 2), publicmethod.DecimalEs(float64(v.MaxScore)/100, 2))
|
|
} else {
|
|
standardStr = fmt.Sprintf("%v", publicmethod.DecimalEs(float64(v.MaxScore)/100, 2))
|
|
}
|
|
outCont.Standard = standardStr
|
|
outCont.CensorTypeList = strings.Split(v.CensorType, ",")
|
|
|
|
outData = append(outData, outCont)
|
|
}
|
|
publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(outData)), outData, c)
|
|
}
|
|
|
|
// 根据指标栏目新增指标细则
|
|
func (a *ApiMethod) BasisSonTargetAddDetailed(c *gin.Context) {
|
|
var receivedValue basisSonTargetAddDet
|
|
c.ShouldBindJSON(&receivedValue)
|
|
// var minScoreInt int64 = 0 //最低分
|
|
// var maxScoreInt int64 = 0 //最高分
|
|
if receivedValue.Id == "" {
|
|
publicmethod.Result(1, receivedValue, c, "未知指标子栏目ID!")
|
|
return
|
|
}
|
|
var sonTargetFatherInfo modelskpi.SonTargetFather
|
|
err := sonTargetFatherInfo.GetCont(map[string]interface{}{"q_id": receivedValue.Id})
|
|
if err != nil {
|
|
publicmethod.Result(1, err, c, "该子栏目不存在!")
|
|
return
|
|
}
|
|
if receivedValue.Title == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请输入考核细则名称!")
|
|
return
|
|
}
|
|
//判断指标细则是否符合规则
|
|
if receivedValue.ReferenceScore == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请输入考核细则相关考核标准!")
|
|
return
|
|
} else {
|
|
scoreAry := strings.Split(receivedValue.ReferenceScore, "-")
|
|
scoreLen := len(scoreAry)
|
|
if scoreLen < 1 {
|
|
publicmethod.Result(1, receivedValue, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
if scoreLen == 1 {
|
|
maxScore, maxErr := strconv.ParseFloat(scoreAry[0], 64)
|
|
if maxErr != nil {
|
|
publicmethod.Result(1, maxErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var maxIntErr error
|
|
_, maxIntErr = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
|
|
if maxIntErr != nil {
|
|
publicmethod.Result(1, maxIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
} else {
|
|
minScore, minErr := strconv.ParseFloat(scoreAry[0], 64)
|
|
if minErr != nil {
|
|
publicmethod.Result(1, minErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
maxScore, maxErr := strconv.ParseFloat(scoreAry[scoreLen-1], 64)
|
|
if maxErr != nil {
|
|
publicmethod.Result(1, maxErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var minIntErr error
|
|
_, minIntErr = strconv.ParseInt(strconv.FormatFloat(minScore*100, 'f', -1, 64), 10, 64)
|
|
if minIntErr != nil {
|
|
publicmethod.Result(1, minIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var maxIntErr error
|
|
_, maxIntErr = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
|
|
if maxIntErr != nil {
|
|
publicmethod.Result(1, maxIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
//获取子栏目接受考核部门
|
|
var sonAboutDeparment []string
|
|
|
|
var aboutTarDepList []int64
|
|
aboutTDErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = 1 AND `target_id` = ? AND `target_sun_id` = ?", sonTargetFatherInfo.ParentId, sonTargetFatherInfo.Id).Find(&aboutTarDepList).Error
|
|
if aboutTDErr == nil {
|
|
for _, atdv := range aboutTarDepList {
|
|
sonAboutDeparment = append(sonAboutDeparment, strconv.FormatInt(atdv, 10))
|
|
}
|
|
}
|
|
|
|
var qualEvalCont QualEvalSunList
|
|
qualEvalCont.Title = receivedValue.Title //考核内容
|
|
qualEvalCont.Content = receivedValue.Content //备注说明
|
|
qualEvalCont.Unit = receivedValue.Unit //单位
|
|
qualEvalCont.ReferenceScore = receivedValue.ReferenceScore //考核标准
|
|
qualEvalCont.Cycles = receivedValue.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年
|
|
qualEvalCont.CycleAttres = receivedValue.CycleAttres //辅助计数
|
|
qualEvalCont.Operator = receivedValue.Operator //考核执行人
|
|
qualEvalCont.AddOrReduce = receivedValue.AddOrReduce //操作类型 1:减少;2:增加;3:用户自定义
|
|
qualEvalCont.CensorType = receivedValue.CensorType //检查方式(1:现场检查;2:资料检查;3:事件触发)
|
|
qualEvalCont.CensorCont = receivedValue.CensorCont //客观证据
|
|
qualEvalCont.CensorRate = receivedValue.CensorRate //检查频次
|
|
//判断指标细则是否已经存在
|
|
var judgeDetaCont modelskpi.DetailedTarget
|
|
judgeDetaErr := judgeDetaCont.GetCont(map[string]interface{}{"`dt_parentid`": sonTargetFatherInfo.ParentId, "`dt_parentid_sun`": sonTargetFatherInfo.Id, "`dt_title`": receivedValue.Title})
|
|
if judgeDetaErr == nil {
|
|
judgeDetaErr = editDetaAdd(sonTargetFatherInfo.ParentId, sonTargetFatherInfo.Id, qualEvalCont, judgeDetaCont, sonAboutDeparment)
|
|
} else {
|
|
judgeDetaErr = addDetaInfo(sonTargetFatherInfo.ParentId, sonTargetFatherInfo.Id, qualEvalCont, sonAboutDeparment)
|
|
}
|
|
if judgeDetaErr != nil {
|
|
publicmethod.Result(106, judgeDetaErr, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, judgeDetaErr, c)
|
|
}
|
|
|
|
// 根据指标和部门获取相关岗位
|
|
func (a *ApiMethod) BasisTargetDearpetmentGetPost(c *gin.Context) {
|
|
var receivedValue bgdgp
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.TargetId == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
if receivedValue.DepartmentId == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
if receivedValue.Level == 0 {
|
|
receivedValue.Level = 2
|
|
}
|
|
var postId []int64
|
|
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("post_id").Where("`state` = 1 AND `level` = ? AND `target_id` = ? AND `department_id` = ?", receivedValue.Level, receivedValue.TargetId, receivedValue.DepartmentId)
|
|
if receivedValue.TargetSunId != "" {
|
|
gormDb = gormDb.Where("`target_sun_id` = ?", receivedValue.TargetSunId)
|
|
}
|
|
if receivedValue.TargetBylaws != "" {
|
|
gormDb = gormDb.Where("`target_bylaws` = ?", receivedValue.TargetBylaws)
|
|
}
|
|
err := gormDb.Find(&postId).Error
|
|
if err != nil || len(postId) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var postList []modelshr.Position
|
|
hrErr := overall.CONSTANT_DB_HR.Model(&modelshr.Position{}).Select("`id`,`name`").Where("`id` IN ?", postId).Find(&postList).Error
|
|
if hrErr != nil || len(postList) < 1 {
|
|
publicmethod.Result(107, hrErr, c)
|
|
return
|
|
}
|
|
outdata := publicmethod.MapOut[string]()
|
|
outdata["postid"] = postId
|
|
outdata["postlist"] = postList
|
|
publicmethod.Result(0, outdata, c)
|
|
}
|
|
|
|
// 获取部门指标岗位提交人
|
|
func (a *ApiMethod) BasisTaegetDeparmentReport(c *gin.Context) {
|
|
var receivedValue btdgr
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.TargetId == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
// if receivedValue.DepartmentId == "" {
|
|
// publicmethod.Result(101, receivedValue, c)
|
|
// return
|
|
// }
|
|
if receivedValue.Level == 0 {
|
|
receivedValue.Level = 2
|
|
}
|
|
var userKey []int64
|
|
gormDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("man_key").Where("`state` = 1 AND `type` = ? AND `target_id` = ?", receivedValue.Level, receivedValue.TargetId)
|
|
|
|
if receivedValue.DepartmentId != "" {
|
|
gormDb = gormDb.Where("`department_id` = ?", receivedValue.DepartmentId)
|
|
}
|
|
|
|
if receivedValue.TargetSunId != "" {
|
|
gormDb = gormDb.Where("`target_sun_id` = ?", receivedValue.TargetSunId)
|
|
}
|
|
if receivedValue.TargetBylaws != "" {
|
|
gormDb = gormDb.Where("`target_bylaws` = ?", receivedValue.TargetBylaws)
|
|
}
|
|
if receivedValue.PostId != "" {
|
|
gormDb = gormDb.Where("`post_id` = ?", receivedValue.PostId)
|
|
}
|
|
err := gormDb.Find(&userKey).Error
|
|
if err != nil || len(userKey) < 1 {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
|
|
var peopleList []modelshr.UserPostDuties
|
|
hrErr := overall.CONSTANT_DB_HR.Model(&modelshr.UserPostDuties{}).Where("`key` IN ?", userKey).Find(&peopleList).Error
|
|
if hrErr != nil || len(peopleList) < 1 {
|
|
publicmethod.Result(107, hrErr, c)
|
|
return
|
|
}
|
|
outdata := publicmethod.MapOut[string]()
|
|
outdata["postid"] = userKey
|
|
outdata["peoplelist"] = peopleList
|
|
publicmethod.Result(0, outdata, c)
|
|
}
|
|
|
|
// 修改子栏目标题名称级考核关联部门及提报人
|
|
func (a *ApiMethod) EditSonTargetDepartmentReport(c *gin.Context) {
|
|
var receivedValue editTarDepartReport
|
|
c.ShouldBindJSON(&receivedValue)
|
|
if receivedValue.TargetSunId == "" {
|
|
publicmethod.Result(101, receivedValue, c)
|
|
return
|
|
}
|
|
var sonTargetCont modelskpi.QualitativeTarget
|
|
err := sonTargetCont.GetCont(map[string]interface{}{"q_id": receivedValue.TargetSunId})
|
|
if err != nil {
|
|
publicmethod.Result(107, receivedValue, c)
|
|
return
|
|
}
|
|
if receivedValue.Title != "" && receivedValue.Title != sonTargetCont.Title {
|
|
var judgeIsFalse modelskpi.QualitativeTarget
|
|
judgeErr := judgeIsFalse.GetCont(map[string]interface{}{"q_title": sonTargetCont.Id, "q_parent_id": sonTargetCont.ParentId}, "q_id")
|
|
if judgeErr == nil {
|
|
publicmethod.Result(103, receivedValue, c)
|
|
return
|
|
}
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["q_title"] = receivedValue.Title
|
|
saveData["q_time"] = time.Now().Unix()
|
|
err = sonTargetCont.EiteCont(map[string]interface{}{"q_id": receivedValue.TargetSunId}, saveData)
|
|
}
|
|
if err != nil {
|
|
publicmethod.Result(106, receivedValue, c)
|
|
return
|
|
}
|
|
departmentAry := receivedValue.AcceptDepartmentId
|
|
operatorList := receivedValue.Operator
|
|
|
|
if len(departmentAry) < 1 {
|
|
var sonDepartmentAbouttargetId []int64
|
|
deparErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("department_id").Where("`state` = 1 AND `level` = 1 AND `target_id` = ? ", sonTargetCont.ParentId).Find(&sonDepartmentAbouttargetId).Error
|
|
if deparErr == nil && len(sonDepartmentAbouttargetId) > 0 {
|
|
for _, sdv := range sonDepartmentAbouttargetId {
|
|
departmentAry = append(departmentAry, strconv.FormatInt(sdv, 10))
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(operatorList) < 1 {
|
|
var sonReportAbouttargetId []int64
|
|
deparErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("man_key").Where("`state` = 1 AND `type` = 1 AND `target_id` = ? ", sonTargetCont.ParentId).Find(&sonReportAbouttargetId).Error
|
|
if deparErr == nil && len(sonReportAbouttargetId) > 0 {
|
|
for _, srv := range sonReportAbouttargetId {
|
|
operatorList = append(operatorList, strconv.FormatInt(srv, 10))
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取该指标下所有细则
|
|
var detaildId []int64
|
|
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.DetailedTarget{}).Select("dt_id").Where("`dt_state` = 1 AND `dt_parentid` = ? AND `dt_parentid_sun` = ?", sonTargetCont.ParentId, sonTargetCont.Id).Find(&detaildId).Error
|
|
if err == nil && len(detaildId) > 0 {
|
|
for _, v := range detaildId {
|
|
if len(departmentAry) > 0 {
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetDepart(sonTargetCont.ParentId, sonTargetCont.Id, v, departmentAry, 1)
|
|
}
|
|
if len(operatorList) > 0 {
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetRepart(sonTargetCont.ParentId, sonTargetCont.Id, v, operatorList, 1)
|
|
}
|
|
syncSeting.Wait()
|
|
}
|
|
}
|
|
//获取该子栏目所有的接受考核部门
|
|
|
|
saveData := publicmethod.MapOut[string]()
|
|
saveData["q_depart"] = strings.Join(departmentAry, ",")
|
|
saveData["q_time"] = time.Now().Unix()
|
|
err = sonTargetCont.EiteCont(map[string]interface{}{"q_id": receivedValue.TargetSunId}, saveData)
|
|
//修改指标的关联部门和关联人
|
|
var targetAboutDepartnebt []int64
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("department_id").Where("`state` = 1 AND `level` = 1 AND `target_id` = ? ", sonTargetCont.ParentId).Find(&targetAboutDepartnebt)
|
|
var targetAboutReport []int64
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("man_key").Where("`state` = 1 AND `type` = 1 AND `target_id` = ? ", sonTargetCont.ParentId).Find(&targetAboutReport)
|
|
if len(targetAboutDepartnebt) > 0 || len(targetAboutReport) > 0 {
|
|
tarSaveData := publicmethod.MapOut[string]()
|
|
if len(targetAboutDepartnebt) > 0 {
|
|
var departStr []string
|
|
for _, dsv := range targetAboutDepartnebt {
|
|
departStr = append(departStr, strconv.FormatInt(dsv, 10))
|
|
}
|
|
tarSaveData["et_relevant_departments"] = strings.Join(departStr, ",")
|
|
}
|
|
if len(targetAboutReport) > 0 {
|
|
var reportStr []string
|
|
for _, dsvr := range targetAboutReport {
|
|
reportStr = append(reportStr, strconv.FormatInt(dsvr, 10))
|
|
}
|
|
tarSaveData["et_report"] = strings.Join(reportStr, ",")
|
|
}
|
|
if len(tarSaveData) > 0 {
|
|
tarSaveData["et_time"] = time.Now().Unix()
|
|
var evalTarCont modelskpi.EvaluationTarget
|
|
evalTarCont.EiteCont(map[string]interface{}{"`et_id`": sonTargetCont.ParentId}, tarSaveData)
|
|
}
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 获取子栏目基础信息
|
|
func (a *ApiMethod) GetSonTargetCont(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)
|
|
return
|
|
}
|
|
where := publicmethod.MapOut[string]()
|
|
where["q_id"] = receivedValue.Id
|
|
var sonTargetCont modelskpi.QualitativeTarget
|
|
err = sonTargetCont.GetCont(where, "q_title", "q_parent_id")
|
|
if err != nil {
|
|
publicmethod.Result(107, receivedValue, c)
|
|
return
|
|
}
|
|
//获取关联部门
|
|
var targetAboutDepartnebt []int64
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("department_id").Where("`state` = 1 AND `level` = 1 AND `target_id` = ? AND `target_sun_id` = ?", sonTargetCont.ParentId, receivedValue.Id).Find(&targetAboutDepartnebt)
|
|
//获取关联提报人
|
|
var targetAboutReport []int64
|
|
overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("man_key").Where("`state` = 1 AND `type` = 1 AND `target_id` = ? AND `target_sun_id` = ?", sonTargetCont.ParentId, receivedValue.Id).Find(&targetAboutReport)
|
|
//部门列表
|
|
var departContList []modelshr.AdministrativeOrganization
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`").Where("`id` IN ?", targetAboutDepartnebt).Find(&departContList)
|
|
//人员列表
|
|
var reportContList []modelshr.PersonArchives
|
|
overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`key`,`name`").Where("`key` IN ?", targetAboutReport).Find(&reportContList)
|
|
|
|
var departArt []outCont
|
|
for _, darv := range departContList {
|
|
var departContArt outCont
|
|
departContArt.Id = strconv.FormatInt(darv.Id, 10)
|
|
departContArt.Name = darv.Name
|
|
departArt = append(departArt, departContArt)
|
|
}
|
|
|
|
var reportArt []outCont
|
|
for _, rclv := range reportContList {
|
|
var reportContArt outCont
|
|
reportContArt.Id = strconv.FormatInt(rclv.Key, 10)
|
|
reportContArt.Name = rclv.Name
|
|
reportArt = append(reportArt, reportContArt)
|
|
}
|
|
|
|
outData := publicmethod.MapOut[string]()
|
|
outData["title"] = sonTargetCont.Title
|
|
outData["departmentid"] = targetAboutDepartnebt
|
|
outData["userkey"] = targetAboutReport
|
|
outData["departmentcont"] = departArt
|
|
outData["usercont"] = reportArt
|
|
publicmethod.Result(0, outData, c)
|
|
}
|
|
|
|
// 删除子栏目
|
|
func (a *ApiMethod) DelSonTarget(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)
|
|
return
|
|
}
|
|
where := publicmethod.MapOut[string]()
|
|
where["q_id"] = receivedValue.Id
|
|
var sonTargetCont modelskpi.QualitativeTarget
|
|
err = sonTargetCont.GetCont(where, "q_id", "q_parent_id")
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
//预留判断该指标是否在使用中
|
|
|
|
delTime := time.Now().Unix()
|
|
//软删除所有此子栏目下的指标细则
|
|
syncSeting.Add(1)
|
|
go softDetaildeCont(sonTargetCont.ParentId, sonTargetCont.Id, delTime)
|
|
//软删除所有此子栏目相关的联部门
|
|
syncSeting.Add(1)
|
|
go softDelTargetDepartment(map[string]interface{}{"target_id": sonTargetCont.ParentId, "target_sun_id": sonTargetCont.Id, "`state`": 1}, delTime)
|
|
//软删除所有此子栏目相关联的提报人
|
|
syncSeting.Add(1)
|
|
go softDelTargetReport(map[string]interface{}{"`target_id`": sonTargetCont.ParentId, "`target_sun_id`": sonTargetCont.Id, "`state`": 1}, delTime)
|
|
//软删除此栏目
|
|
var delTargetSon modelskpi.QualitativeTarget
|
|
err = delTargetSon.EiteCont(map[string]interface{}{"`q_id`": sonTargetCont.Id}, map[string]interface{}{"`q_state`": 3, "`q_time`": delTime})
|
|
syncSeting.Wait()
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 软删除所有此子栏目下的指标细则
|
|
func softDetaildeCont(targetId, sonTargetId, delTime int64) {
|
|
defer syncSeting.Done()
|
|
var detaildeCont modelskpi.DetailedTarget
|
|
detaildeCont.EiteCont(map[string]interface{}{"dt_parentid": targetId, "dt_parentid_sun": sonTargetId, "dt_state": 1}, map[string]interface{}{"dt_state": 3, "dt_time": delTime})
|
|
}
|
|
|
|
// 软删除所有此子栏目相关联的提报人
|
|
func softDelTargetReport(where interface{}, delTime int64) {
|
|
defer syncSeting.Done()
|
|
var delTargetReport modelskpi.TargetReport
|
|
delTargetReport.EiteCont(where, map[string]interface{}{"`state`": 3, "`time`": delTime})
|
|
}
|
|
|
|
// 软删除所有此子栏目相关的联部门
|
|
func softDelTargetDepartment(where interface{}, delTime int64) {
|
|
defer syncSeting.Done()
|
|
var delTargetDepartment modelskpi.TargetDepartment
|
|
delTargetDepartment.EiteCont(where, map[string]interface{}{"`state`": 3, "`time`": delTime})
|
|
}
|
|
|
|
// 获取单一指标细则内容
|
|
func (a *ApiMethod) GetOneDetailedTarget(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)
|
|
return
|
|
}
|
|
where := publicmethod.MapOut[string]()
|
|
where["dt_id"] = receivedValue.Id
|
|
var detailedTargetCont modelskpi.DetailedTarget
|
|
err = detailedTargetCont.GetCont(where)
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
var outDataCont NewOutPutDetailedTarget
|
|
outDataCont.Id = strconv.FormatInt(detailedTargetCont.Id, 10)
|
|
outDataCont.Title = detailedTargetCont.Title //考核内容
|
|
outDataCont.Content = detailedTargetCont.Content //备注说明
|
|
outDataCont.Unit = detailedTargetCont.Company //单位
|
|
biaoZhun := ""
|
|
if detailedTargetCont.MinScore != 0 {
|
|
biaoZhun = fmt.Sprintf("%v-%v", detailedTargetCont.MinScore, detailedTargetCont.MaxScore)
|
|
} else {
|
|
biaoZhun = fmt.Sprintf("%v", detailedTargetCont.MaxScore)
|
|
}
|
|
outDataCont.ReferenceScore = biaoZhun //考核标准
|
|
outDataCont.Cycles = detailedTargetCont.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年
|
|
outDataCont.CycleAttres = detailedTargetCont.CycleAttres //辅助计数
|
|
outDataCont.Operator, outDataCont.ReportManList, _ = getDetailedReport(detailedTargetCont.ParentId, detailedTargetCont.ParentIdSun, detailedTargetCont.Id, 1) //考核执行人
|
|
outDataCont.AddOrReduce = detailedTargetCont.AddReduce //操作类型 1:减少;2:增加;3:用户自定义
|
|
outDataCont.CensorType = strings.Split(detailedTargetCont.CensorType, ",") //检查方式(1:现场检查;2:资料检查;3:事件触发)
|
|
outDataCont.CensorCont = detailedTargetCont.CensorCont //客观证据
|
|
outDataCont.CensorRate = detailedTargetCont.CensorRate //检查频次
|
|
outDataCont.DepartmentList, _, _ = getDetailedDepartment(detailedTargetCont.ParentId, detailedTargetCont.ParentIdSun, detailedTargetCont.Id, 1) //接受考核的部门
|
|
publicmethod.Result(0, outDataCont, c)
|
|
}
|
|
|
|
// 获取指标细则接受考核部门
|
|
func getDetailedDepartment(targetId, targetSunId, bylawsId int64, class int) (departmentStr []string, departmentInfo []departOutcome, err error) {
|
|
if class == 0 {
|
|
class = 1
|
|
}
|
|
var departmentId []int64
|
|
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", class, targetId, targetSunId, bylawsId).Find(&departmentId).Error
|
|
if err != nil || len(departmentId) < 1 {
|
|
return
|
|
}
|
|
var orgList []modelshr.AdministrativeOrganization
|
|
gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`superior`,`ispower`")
|
|
if len(departmentId) > 1 {
|
|
gormDb = gormDb.Where("`id` IN ?", departmentId)
|
|
} else {
|
|
gormDb = gormDb.Where("`id` = ?", departmentId)
|
|
}
|
|
|
|
err = gormDb.Find(&orgList).Error
|
|
if err != nil || len(orgList) < 1 {
|
|
return
|
|
}
|
|
for _, v := range orgList {
|
|
departIdStr := strconv.FormatInt(v.Id, 10)
|
|
if publicmethod.IsInTrue[string](departIdStr, departmentStr) == false {
|
|
var departCont departOutcome
|
|
departCont.Id = departIdStr
|
|
departCont.Name = v.Name
|
|
departCont.Superior = strconv.FormatInt(v.Superior, 10) //上级
|
|
departCont.Ispower = v.IsPower //是否为主部门
|
|
departmentStr = append(departmentStr, departIdStr)
|
|
departmentInfo = append(departmentInfo, departCont)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取指标细则执行人
|
|
func getDetailedReport(targetId, targetSunId, bylawsId int64, class int) (userKey []string, userCont []printReportCont, err error) {
|
|
if class == 0 {
|
|
class = 1
|
|
}
|
|
var userKeyInt []int64
|
|
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = ? AND `target_id` = ? AND `target_sun_id` = ? AND `target_bylaws` = ?", class, targetId, targetSunId, bylawsId).Find(&userKeyInt).Error
|
|
if err != nil || len(userKeyInt) < 1 {
|
|
return
|
|
}
|
|
var userContList []modelshr.PersonArchives
|
|
gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`number`,`name`,`icon`,`company`,`maindeparment`")
|
|
if len(userKeyInt) > 1 {
|
|
gormDb = gormDb.Where("`key` IN ?", userKeyInt)
|
|
} else {
|
|
gormDb = gormDb.Where("`key` = ?", userKeyInt)
|
|
}
|
|
err = gormDb.Find(&userContList).Error
|
|
if err != nil || len(userContList) < 1 {
|
|
return
|
|
}
|
|
for _, v := range userContList {
|
|
userKeyStr := strconv.FormatInt(v.Id, 10)
|
|
if publicmethod.IsInTrue[string](userKeyStr, userKey) == false {
|
|
var userInfo printReportCont
|
|
userInfo.Id = userKeyStr
|
|
userInfo.Name = v.Name
|
|
var groupCont modelshr.AdministrativeOrganization
|
|
groupCont.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
|
|
userInfo.GroupName = groupCont.Name
|
|
var deparHrCont modelshr.AdministrativeOrganization
|
|
deparHrCont.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
|
|
userInfo.DepartmentName = deparHrCont.Name
|
|
userInfo.Icon = v.Icon
|
|
userInfo.Number = v.Number
|
|
userKey = append(userKey, userKeyStr)
|
|
userCont = append(userCont, userInfo)
|
|
}
|
|
|
|
}
|
|
return
|
|
}
|
|
|
|
// 编辑单一指标细则内容
|
|
func (a *ApiMethod) EditOneDetailedTarget(c *gin.Context) {
|
|
var receivedValue editOneDetailedTargetInfo
|
|
c.ShouldBindJSON(&receivedValue)
|
|
|
|
var judgeDetaCont modelskpi.DetailedTarget
|
|
judgeDetaErr := judgeDetaCont.GetCont(map[string]interface{}{"`dt_id`": receivedValue.Id})
|
|
if judgeDetaErr != nil {
|
|
publicmethod.Result(107, receivedValue, c)
|
|
return
|
|
}
|
|
if receivedValue.Title == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请输入考核细则名称!")
|
|
return
|
|
}
|
|
//判断指标细则是否符合规则
|
|
if receivedValue.ReferenceScore == "" {
|
|
publicmethod.Result(1, receivedValue, c, "请输入考核细则相关考核标准!")
|
|
return
|
|
} else {
|
|
scoreAry := strings.Split(receivedValue.ReferenceScore, "-")
|
|
scoreLen := len(scoreAry)
|
|
if scoreLen < 1 {
|
|
publicmethod.Result(1, receivedValue, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
if scoreLen == 1 {
|
|
maxScore, maxErr := strconv.ParseFloat(scoreAry[0], 64)
|
|
if maxErr != nil {
|
|
publicmethod.Result(1, maxErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var maxIntErr error
|
|
_, maxIntErr = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
|
|
if maxIntErr != nil {
|
|
publicmethod.Result(1, maxIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
} else {
|
|
minScore, minErr := strconv.ParseFloat(scoreAry[0], 64)
|
|
if minErr != nil {
|
|
publicmethod.Result(1, minErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
maxScore, maxErr := strconv.ParseFloat(scoreAry[scoreLen-1], 64)
|
|
if maxErr != nil {
|
|
publicmethod.Result(1, maxErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var minIntErr error
|
|
_, minIntErr = strconv.ParseInt(strconv.FormatFloat(minScore*100, 'f', -1, 64), 10, 64)
|
|
if minIntErr != nil {
|
|
publicmethod.Result(1, minIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
var maxIntErr error
|
|
_, maxIntErr = strconv.ParseInt(strconv.FormatFloat(maxScore*100, 'f', -1, 64), 10, 64)
|
|
if maxIntErr != nil {
|
|
publicmethod.Result(1, maxIntErr, c, "考核标准不符合要求!请仔细填写!")
|
|
return
|
|
}
|
|
}
|
|
}
|
|
if len(receivedValue.DepartmentList) < 1 {
|
|
//获取子栏目接受考核部门
|
|
var aboutTarDepList []int64
|
|
aboutTDErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where("`state` = 1 AND `level` = 1 AND `target_id` = ? AND `target_sun_id` = ?", judgeDetaCont.ParentId, judgeDetaCont.ParentIdSun).Find(&aboutTarDepList).Error
|
|
if aboutTDErr == nil {
|
|
for _, atdv := range aboutTarDepList {
|
|
receivedValue.DepartmentList = append(receivedValue.DepartmentList, strconv.FormatInt(atdv, 10))
|
|
}
|
|
}
|
|
}
|
|
if len(receivedValue.QualEvalSunList.Operator) < 1 {
|
|
var aboutTarDepRepList []int64
|
|
aboutReTDErr := overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where("`state` = 1 AND `type` = 1 AND `target_id` = ? AND `target_sun_id` = ?", judgeDetaCont.ParentId, judgeDetaCont.ParentIdSun).Find(&aboutTarDepRepList).Error
|
|
if aboutReTDErr == nil {
|
|
for _, atdv := range aboutTarDepRepList {
|
|
receivedValue.QualEvalSunList.Operator = append(receivedValue.QualEvalSunList.Operator, strconv.FormatInt(atdv, 10))
|
|
}
|
|
}
|
|
}
|
|
err := editDetaAdd(judgeDetaCont.ParentId, judgeDetaCont.ParentIdSun, receivedValue.QualEvalSunList, judgeDetaCont, receivedValue.DepartmentList)
|
|
if err != nil {
|
|
publicmethod.Result(106, receivedValue, c)
|
|
return
|
|
}
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 删除单一指标细则
|
|
func (a *ApiMethod) DelOneDetailedTarget(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)
|
|
return
|
|
}
|
|
where := publicmethod.MapOut[string]()
|
|
where["dt_id"] = receivedValue.Id
|
|
var detailedTargetCont modelskpi.DetailedTarget
|
|
err = detailedTargetCont.GetCont(where)
|
|
if err != nil {
|
|
publicmethod.Result(107, err, c)
|
|
return
|
|
}
|
|
delTime := time.Now().Unix()
|
|
err = detailedTargetCont.EiteCont(where, map[string]interface{}{"dt_state": 3, "dt_time": delTime})
|
|
if err != nil {
|
|
publicmethod.Result(106, err, c)
|
|
return
|
|
}
|
|
|
|
//软删除所有此子栏目相关的联部门
|
|
syncSeting.Add(1)
|
|
go softDelTargetDepartment(map[string]interface{}{"target_id": detailedTargetCont.ParentId, "`target_sun_id`": detailedTargetCont.ParentIdSun, "target_bylaws": detailedTargetCont.Id, "`state`": 1}, delTime)
|
|
//软删除所有此子栏目相关联的提报人
|
|
syncSeting.Add(1)
|
|
go softDelTargetReport(map[string]interface{}{"`target_id`": detailedTargetCont.ParentId, "`target_sun_id`": detailedTargetCont.ParentIdSun, "target_bylaws": detailedTargetCont.Id, "`state`": 1}, delTime)
|
|
syncSeting.Wait()
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 添加部门指标
|
|
func (a *ApiMethod) AddDepartmentTarget(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 {
|
|
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
|
|
}
|
|
|
|
if len(receivedValue.AcceptDepartmentId) > 0 {
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetDepart(saveData.Id, 0, 0, receivedValue.AcceptDepartmentId, 1)
|
|
}
|
|
if len(receivedValue.Operator) > 0 {
|
|
syncSeting.Add(1)
|
|
go handleDetarildTargetRepart(saveData.Id, 0, 0, receivedValue.Operator, 1)
|
|
}
|
|
syncSeting.Wait()
|
|
|
|
publicmethod.Result(0, err, c)
|
|
}
|
|
|
|
// 获取关联部门
|
|
func GetAboutDepartment(where interface{}, level int) (departmentId []int64, departmentIdStr []string, err error) {
|
|
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetDepartment{}).Distinct("`department_id`").Where(where).Find(&departmentId).Error
|
|
if err == nil {
|
|
for _, v := range departmentId {
|
|
departmentIdStr = append(departmentIdStr, strconv.FormatInt(v, 10))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取关联提报人
|
|
func GetAboutReport(where interface{}, level int) (userKey []int64, userKeyStr []string, err error) {
|
|
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.TargetReport{}).Distinct("`man_key`").Where(where).Find(&userKey).Error
|
|
if err == nil {
|
|
for _, v := range userKey {
|
|
userKeyStr = append(userKeyStr, strconv.FormatInt(v, 10))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取单一指标详细内容
|
|
func (a *ApiMethod) GetOneTergetInfo(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)
|
|
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
|
|
}
|
|
var outCont printOneTargetCont
|
|
outCont.Id = strconv.FormatInt(targetCont.Id, 10)
|
|
outCont.Name = targetCont.Title
|
|
outCont.Share = targetCont.Share //1:共用;2:私用
|
|
outCont.AcceptDepartmentId = strings.Split(targetCont.RelevantDepartments, ",") //接受考核部门
|
|
outCont.Operator = strings.Split(targetCont.Report, ",") //考核执行人
|
|
outCont.Dimension = strconv.FormatInt(targetCont.Dimension, 10) //维度
|
|
outCont.Nature = targetCont.Type //性质 1:定性考核;2:定量考核
|
|
outCont.Unit = targetCont.Uniteing //单位
|
|
outCont.Cycles = targetCont.Cycles //1:班;2:天;3:周;4:月;5:季度;6:年
|
|
outCont.CycleAttres = targetCont.CycleAttres //辅助计数
|
|
outCont.ScoringMethod = targetCont.ScoringMethod //计分方式(1:自动;2:手动)'
|
|
outCont.VisibleRangeGroup = strings.Split(targetCont.VisibleRangeGroup, ",") //可见范围(集团)
|
|
outCont.VisibleRangeDepart = strings.Split(targetCont.VisibleRange, ",") //可见范围(分厂)
|
|
publicmethod.Result(0, outCont, c)
|
|
}
|
|
|