14 changed files with 1131 additions and 86 deletions
@ -0,0 +1,407 @@ |
|||
package postpc |
|||
|
|||
import ( |
|||
"key_performance_indicators/models/modelshr" |
|||
"key_performance_indicators/models/modelskpi" |
|||
"key_performance_indicators/overall" |
|||
"key_performance_indicators/overall/publicmethod" |
|||
"strconv" |
|||
"time" |
|||
|
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// 提交岗位定量目标设定
|
|||
func (a *ApiMethod) SetEvaluationObjectives(c *gin.Context) { |
|||
var requestData SetEvaluationObjectives |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "数据获取失败!") |
|||
return |
|||
} |
|||
if requestData.Year == 0 { |
|||
publicmethod.Result(1, err, c, "请填写年度") |
|||
return |
|||
} |
|||
if requestData.Group == "" { |
|||
publicmethod.Result(1, err, c, "请选择归属集团") |
|||
return |
|||
} |
|||
if requestData.DepartMent == "" { |
|||
publicmethod.Result(1, err, c, "请选择归属行政组织") |
|||
return |
|||
} |
|||
if requestData.PostId == "" { |
|||
publicmethod.Result(1, err, c, "请选择归属岗位") |
|||
return |
|||
} |
|||
if requestData.Dimension == "" { |
|||
publicmethod.Result(1, err, c, "请选择归属维度") |
|||
return |
|||
} |
|||
if requestData.Target == "" { |
|||
publicmethod.Result(1, err, c, "请选择归属指标") |
|||
return |
|||
} |
|||
switch requestData.Cycle { |
|||
case 1: |
|||
if len(requestData.CycleAdded) != 1 { |
|||
publicmethod.Result(1, err, c, "年度只可填写一条!") |
|||
return |
|||
} |
|||
case 2: |
|||
if len(requestData.CycleAdded) > 4 { |
|||
publicmethod.Result(1, err, c, "季度最多只可填写四条!") |
|||
return |
|||
} |
|||
if len(requestData.CycleAdded) < 1 { |
|||
publicmethod.Result(1, err, c, "季度至少填写一条!") |
|||
return |
|||
} |
|||
case 3: |
|||
if len(requestData.CycleAdded) > 12 { |
|||
publicmethod.Result(1, err, c, "月度最多只可填写十二条!") |
|||
return |
|||
} |
|||
if len(requestData.CycleAdded) < 1 { |
|||
publicmethod.Result(1, err, c, "月度至少填写一条!") |
|||
return |
|||
} |
|||
default: |
|||
publicmethod.Result(1, err, c, "请选择周期") |
|||
return |
|||
} |
|||
var timecopy []int64 |
|||
|
|||
gromDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.QuanPostConfig{}).Select("Timecopy").Where("`group` = ? AND `org_id` = ? AND `post_id` = ? AND `dimension` = ? AND `target` = ? AND `year` = ? ", requestData.Group, requestData.DepartMent, requestData.PostId, requestData.Dimension, requestData.Target, requestData.Year) |
|||
|
|||
judgeErr := gromDb.Find(&timecopy).Error |
|||
|
|||
if judgeErr == nil { |
|||
if len(timecopy) > 0 { |
|||
publicmethod.Result(1, judgeErr, c, "已经存在!不要重复添加!") |
|||
return |
|||
} |
|||
} |
|||
|
|||
var saveData []modelskpi.QuanPostConfig |
|||
var eiteAddData []int64 |
|||
for _, v := range requestData.CycleAdded { |
|||
if judgeErr != nil { |
|||
|
|||
var saveDataCont modelskpi.QuanPostConfig |
|||
orgId, _ := strconv.ParseInt(requestData.DepartMent, 10, 64) |
|||
_, saveDataCont.CompanyId, saveDataCont.DepartmentId, _, _ = publicmethod.GetOrgStructure(orgId) //公司部门
|
|||
saveDataCont.OrgId = orgId //行政组织
|
|||
postIdInt, _ := strconv.ParseInt(requestData.PostId, 10, 64) |
|||
saveDataCont.PostId = postIdInt //岗位
|
|||
dimensionId, _ := strconv.ParseInt(requestData.Dimension, 10, 64) |
|||
saveDataCont.Dimension = dimensionId //维度
|
|||
|
|||
targetId, _ := strconv.ParseInt(requestData.Target, 10, 64) |
|||
saveDataCont.Target = targetId //指标
|
|||
|
|||
saveDataCont.Type = int64(requestData.Cycle) |
|||
saveDataCont.Year = requestData.Year |
|||
saveDataCont.Timecopy = v.Id |
|||
if v.Zeroprize < 0 { |
|||
saveDataCont.Zeroprize = 0 |
|||
} else { |
|||
saveDataCont.Zeroprize = v.Zeroprize * 100 |
|||
} |
|||
if v.Allprize < 0 { |
|||
saveDataCont.Allprize = 0 |
|||
} else { |
|||
saveDataCont.Allprize = v.Allprize * 100 |
|||
} |
|||
if v.Capping > 0 { |
|||
saveDataCont.Capping = 1 |
|||
saveDataCont.CappingVal = v.Capping * 100 |
|||
} else { |
|||
saveDataCont.Capping = 2 |
|||
saveDataCont.CappingVal = 0 |
|||
} |
|||
saveDataCont.Time = time.Now().Unix() |
|||
saveDataCont.State = 1 |
|||
saveData = append(saveData, saveDataCont) |
|||
} else { |
|||
if len(timecopy) <= 0 { |
|||
var saveDataCont modelskpi.QuanPostConfig |
|||
orgId, _ := strconv.ParseInt(requestData.DepartMent, 10, 64) |
|||
_, saveDataCont.CompanyId, saveDataCont.DepartmentId, _, _ = publicmethod.GetOrgStructure(orgId) //公司部门
|
|||
saveDataCont.OrgId = orgId //行政组织
|
|||
postIdInt, _ := strconv.ParseInt(requestData.PostId, 10, 64) |
|||
saveDataCont.PostId = postIdInt //岗位
|
|||
dimensionId, _ := strconv.ParseInt(requestData.Dimension, 10, 64) |
|||
saveDataCont.Dimension = dimensionId //维度
|
|||
|
|||
targetId, _ := strconv.ParseInt(requestData.Target, 10, 64) |
|||
saveDataCont.Target = targetId //指标
|
|||
|
|||
saveDataCont.Type = int64(requestData.Cycle) |
|||
saveDataCont.Year = requestData.Year |
|||
saveDataCont.Timecopy = v.Id |
|||
if v.Zeroprize < 0 { |
|||
saveDataCont.Zeroprize = 0 |
|||
} else { |
|||
saveDataCont.Zeroprize = v.Zeroprize * 100 |
|||
} |
|||
if v.Allprize < 0 { |
|||
saveDataCont.Allprize = 0 |
|||
} else { |
|||
saveDataCont.Allprize = v.Allprize * 100 |
|||
} |
|||
if v.Capping > 0 { |
|||
saveDataCont.Capping = 1 |
|||
saveDataCont.CappingVal = v.Capping * 100 |
|||
} else { |
|||
saveDataCont.Capping = 2 |
|||
saveDataCont.CappingVal = 0 |
|||
} |
|||
saveDataCont.Time = time.Now().Unix() |
|||
saveDataCont.State = 1 |
|||
saveData = append(saveData, saveDataCont) |
|||
} else { |
|||
for _, s_v := range timecopy { |
|||
if s_v != v.Id { |
|||
var saveDataCont modelskpi.QuanPostConfig |
|||
orgId, _ := strconv.ParseInt(requestData.DepartMent, 10, 64) |
|||
_, saveDataCont.CompanyId, saveDataCont.DepartmentId, _, _ = publicmethod.GetOrgStructure(orgId) //公司部门
|
|||
saveDataCont.OrgId = orgId //行政组织
|
|||
postIdInt, _ := strconv.ParseInt(requestData.PostId, 10, 64) |
|||
saveDataCont.PostId = postIdInt //岗位
|
|||
dimensionId, _ := strconv.ParseInt(requestData.Dimension, 10, 64) |
|||
saveDataCont.Dimension = dimensionId //维度
|
|||
|
|||
targetId, _ := strconv.ParseInt(requestData.Target, 10, 64) |
|||
saveDataCont.Target = targetId //指标
|
|||
|
|||
saveDataCont.Type = int64(requestData.Cycle) |
|||
saveDataCont.Year = requestData.Year |
|||
saveDataCont.Timecopy = v.Id |
|||
if v.Zeroprize < 0 { |
|||
saveDataCont.Zeroprize = 0 |
|||
} else { |
|||
saveDataCont.Zeroprize = v.Zeroprize * 100 |
|||
} |
|||
if v.Allprize < 0 { |
|||
saveDataCont.Allprize = 0 |
|||
} else { |
|||
saveDataCont.Allprize = v.Allprize * 100 |
|||
} |
|||
if v.Capping > 0 { |
|||
saveDataCont.Capping = 1 |
|||
saveDataCont.CappingVal = v.Capping * 100 |
|||
} else { |
|||
saveDataCont.Capping = 2 |
|||
saveDataCont.CappingVal = 0 |
|||
} |
|||
saveDataCont.Time = time.Now().Unix() |
|||
saveDataCont.State = 1 |
|||
saveData = append(saveData, saveDataCont) |
|||
} else { |
|||
eiteDataMap := publicmethod.MapOut[string]() |
|||
eiteDataMap["type"] = requestData.Cycle |
|||
eiteDataMap["timecopy"] = v.Id |
|||
if v.Zeroprize < 0 { |
|||
eiteDataMap["zeroprize"] = 0 |
|||
} else { |
|||
|
|||
eiteDataMap["zeroprize"] = v.Zeroprize * 100 |
|||
} |
|||
if v.Allprize < 0 { |
|||
eiteDataMap["allprize"] = 0 |
|||
} else { |
|||
|
|||
eiteDataMap["allprize"] = v.Allprize * 100 |
|||
} |
|||
if v.Capping > 0 { |
|||
|
|||
eiteDataMap["capping"] = 1 |
|||
eiteDataMap["capping_val"] = v.Capping * 100 |
|||
} else { |
|||
eiteDataMap["capping"] = 2 |
|||
eiteDataMap["capping_val"] = 0 |
|||
} |
|||
eiteDataMap["time"] = time.Now().Unix() |
|||
gromDb := overall.CONSTANT_DB_KPI.Model(&modelskpi.QuanPostConfig{}).Select("Timecopy").Where("`company_id` = ? AND `org_id` = ? AND `post_id` = ? AND `dimension` = ? AND `target` = ? AND `year` = ? AND `type` = ?", requestData.Group, requestData.DepartMent, requestData.PostId, requestData.Dimension, requestData.Target, requestData.Year, requestData.Cycle) |
|||
|
|||
gromDb.Updates(eiteDataMap) |
|||
eiteAddData = append(eiteAddData, 1) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if len(saveData) <= 0 && len(eiteAddData) <= 0 { |
|||
publicmethod.Result(1, err, c, "没有要添加的数据!") |
|||
return |
|||
} |
|||
if len(saveData) > 0 { |
|||
saveErr := overall.CONSTANT_DB_KPI.Create(&saveData).Error |
|||
if saveErr != nil { |
|||
publicmethod.Result(1, err, c, "数据添加失败!") |
|||
return |
|||
} |
|||
} |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
|
|||
// 岗位定量考核目标列表
|
|||
func (a *ApiMethod) PostConfigList(c *gin.Context) { |
|||
var requestData SelectQuantitativeConfig |
|||
c.ShouldBindJSON(&requestData) |
|||
// if err != nil {
|
|||
// publicmethod.Result(1, err, c, "数据获取失败!")
|
|||
// return
|
|||
// }
|
|||
// var qualConfigList []assessmentmodel.QuantitativeConfig
|
|||
var qualConfigList []modelskpi.QuanPostConfigTarget |
|||
gormDb := overall.CONSTANT_DB_KPI |
|||
if requestData.GroupId != "" { |
|||
gormDb = gormDb.Where("`company_id` = ?", requestData.GroupId) |
|||
} |
|||
if requestData.DepartmentID != "" { |
|||
gormDb = gormDb.Where("`org_id` = ?", requestData.DepartmentID) |
|||
} |
|||
if requestData.PostId != "" { |
|||
gormDb = gormDb.Where("`post_id` = ?", requestData.PostId) |
|||
} |
|||
if requestData.Dimension != "" { |
|||
gormDb = gormDb.Where("`dimension` = ?", requestData.Dimension) |
|||
} |
|||
if requestData.Target != "" { |
|||
gormDb = gormDb.Where("`target` = ?", requestData.Target) |
|||
} |
|||
|
|||
switch requestData.Type { |
|||
case 1: |
|||
gormDb = gormDb.Where("`type` = ?", requestData.Type) |
|||
case 2: |
|||
gormDb = gormDb.Where("`type` = ?", requestData.Type) |
|||
if requestData.Class != 0 { |
|||
gormDb = gormDb.Where("`timecopy` = ?", requestData.Class) |
|||
} |
|||
case 3: |
|||
gormDb = gormDb.Where("`type` = ?", requestData.Type) |
|||
if requestData.Class != 0 { |
|||
gormDb = gormDb.Where("`timecopy` = ?", requestData.Class) |
|||
} |
|||
default: |
|||
} |
|||
if requestData.Year != 0 { |
|||
gormDb = gormDb.Where("`year` = ?", requestData.Year) |
|||
} |
|||
if requestData.State != 0 { |
|||
gormDb = gormDb.Where("`state` = ?", requestData.State) |
|||
} |
|||
if requestData.Title != "" { |
|||
gormDb = gormDb.Where("`title` LIKE ?", "%"+requestData.Title+"%") |
|||
} |
|||
// gormDb = gormDb.Order("group ASC,departmentid ASC,dimension ASC,target ASC,targetconfig ASC").Order("year DESC").Order("timecopy ASC,id ASC")
|
|||
gormDb = gormDb.Order("`company_id` ASC").Order("`department_id` ASC").Order("`org_id` ASC").Order("`post_id` ASC").Order("`dimension` ASC").Order("`target` ASC").Order("`year` DESC").Order("`timecopy` ASC").Order("`id` ASC") |
|||
contErr := gormDb.Find(&qualConfigList).Error |
|||
if contErr != nil { |
|||
publicmethod.Result(1, contErr, c, "没有数据!") |
|||
return |
|||
} |
|||
var outList []OutQuantitativeConfig |
|||
for _, v := range qualConfigList { |
|||
var outCont OutQuantitativeConfig |
|||
outCont.Id = v.Id |
|||
outCont.Title = v.Title |
|||
outCont.CompanyId = v.CompanyId |
|||
outCont.DepartmentId = v.DepartmentId |
|||
outCont.OrgId = v.OrgId |
|||
outCont.PostId = v.PostId |
|||
|
|||
outCont.Dimension = v.Dimension |
|||
outCont.Target = v.Target |
|||
|
|||
outCont.Type = v.Type |
|||
outCont.Year = v.Year |
|||
outCont.Timecopy = v.Timecopy |
|||
outCont.Zeroprize = v.Zeroprize / 100 |
|||
outCont.Allprize = v.Allprize / 100 |
|||
outCont.Capping = v.Capping |
|||
outCont.CappingVal = v.CappingVal / 100 |
|||
outCont.Time = v.Time |
|||
outCont.State = v.State |
|||
outCont.DimensionId = strconv.FormatInt(v.Dimension, 10) |
|||
|
|||
var companyCont modelshr.AdministrativeOrganization |
|||
companyCont.GetCont(map[string]interface{}{"`id`": v.CompanyId}, "id", "name") |
|||
outCont.GroupTitle = companyCont.Name |
|||
|
|||
var departmenCont modelshr.AdministrativeOrganization |
|||
departmenCont.GetCont(map[string]interface{}{"`id`": v.DepartmentId}, "id", "name") |
|||
outCont.DepartmentTitle = departmenCont.Name |
|||
|
|||
var postCont modelshr.Position |
|||
postCont.GetCont(map[string]interface{}{"`id`": v.PostId}, "id", "name") |
|||
outCont.PostTitle = postCont.Name |
|||
|
|||
var dimensionCont modelskpi.DutyClass |
|||
dimensionCont.GetCont(map[string]interface{}{"`id`": v.Dimension}, "id", "title") |
|||
outCont.DimensionTitle = dimensionCont.Title |
|||
|
|||
outCont.TargetTitle = v.Title |
|||
// dErr, departmentInfo := commonus.GetBranchFactory(v.DepartmentId)
|
|||
// if dErr == true {
|
|||
// outCont.DimensionTitle = departmentInfo.Name
|
|||
// }
|
|||
// targetInfo, tErr := commonus.GetTargetInfo(v.Target)
|
|||
// if tErr == true {
|
|||
// outCont.TargetTitle = targetInfo.Title
|
|||
// }
|
|||
|
|||
outList = append(outList, outCont) |
|||
} |
|||
publicmethod.Result(0, outList, c) |
|||
} |
|||
|
|||
// 修改考核目标设置
|
|||
func (a *ApiMethod) EiteQuantitativeConfig(c *gin.Context) { |
|||
var requestData []EiteQuantConfig |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "数据获取失败!") |
|||
return |
|||
} |
|||
if len(requestData) < 1 { |
|||
publicmethod.Result(1, err, c, "数据获取失败!") |
|||
return |
|||
} |
|||
for _, v := range requestData { |
|||
eiteCont := publicmethod.MapOut[string]() |
|||
eiteCont["allprize"] = v.Allprize * 100 |
|||
eiteCont["zeroprize"] = v.Zeroprize * 100 |
|||
eiteCont["capping_val"] = v.Capping * 100 |
|||
err = overall.CONSTANT_DB_KPI.Model(&modelskpi.QuanPostConfig{}).Where("`id` = ?", v.Id).Updates(eiteCont).Error |
|||
} |
|||
if err != nil { |
|||
publicmethod.Result(104, err, c) |
|||
} else { |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
} |
|||
|
|||
// 删除考核目标设置
|
|||
func (a *ApiMethod) DelQuantitativeConfig(c *gin.Context) { |
|||
var requestData []string |
|||
err := c.ShouldBindJSON(&requestData) |
|||
if err != nil { |
|||
publicmethod.Result(1, err, c, "数据获取失败!") |
|||
return |
|||
} |
|||
if len(requestData) < 1 { |
|||
publicmethod.Result(1, err, c, "数据获取失败!") |
|||
return |
|||
} |
|||
err = overall.CONSTANT_DB_KPI.Where("`id` IN ?", requestData).Delete(&modelskpi.QuanPostConfig{}).Error |
|||
if err != nil { |
|||
publicmethod.Result(108, err, c) |
|||
} else { |
|||
publicmethod.Result(0, err, c) |
|||
} |
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
package modelskpi |
|||
|
|||
//
|
|||
|
|||
import ( |
|||
"key_performance_indicators/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 岗位定量考核目标设定
|
|||
type QuanPostConfigTarget struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
Title string `json:"title" gorm:"column:title;type:varchar(255) unsigned;default:'';not null;comment:标题"` |
|||
CompanyId int64 `json:"companyid" gorm:"column:company_id;type:bigint(20) unsigned;default:0;not null;comment:公司"` |
|||
DepartmentId int64 `json:"departmentid" gorm:"column:department_id;type:bigint(20) unsigned;default:0;not null;comment:部门ID"` |
|||
OrgId int64 `json:"orgid" gorm:"column:org_id;type:bigint(20) unsigned;default:0;not null;comment:行政组织"` |
|||
PostId int64 `json:"postid" gorm:"column:post_id;type:bigint(20) unsigned;default:0;not null;comment:岗位"` |
|||
Dimension int64 `json:"dimension" gorm:"column:dimension;type:bigint(20) unsigned;default:0;not null;comment:维度"` |
|||
Target int64 `json:"target" gorm:"column:target;type:bigint(20) unsigned;default:0;not null;comment:指标"` |
|||
Detailed int64 `json:"detailed" gorm:"column:detailed;type:bigint(20) unsigned;default:0;not null;comment:指标细则"` |
|||
Type int64 `json:"type" gorm:"column:type;type:tinyint(1) unsigned;default:0;not null;comment:1、年度;2、季度;3、月度"` |
|||
Year int64 `json:"year" gorm:"column:year;type:bigint(20) unsigned;default:0;not null;comment:年度"` |
|||
Timecopy int64 `json:"timecopy" gorm:"column:timecopy;type:int(3) unsigned;default:0;not null;comment:季度与月度辅助值"` |
|||
Zeroprize float64 `json:"zeroprize" gorm:"column:zeroprize;type:int(7) unsigned;default:0;not null;comment:零奖值"` |
|||
Allprize float64 `json:"allprize" gorm:"column:allprize;type:int(7) unsigned;default:0;not null;comment:全奖值"` |
|||
Capping int `json:"capping" gorm:"column:capping;type:int(1) unsigned;default:2;not null;comment:是否封顶(1、是;2:否)"` |
|||
CappingVal float64 `json:"cappingval" gorm:"column:capping_val;type:bigint(20) unsigned;default:0;not null;comment:封顶值"` |
|||
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
} |
|||
|
|||
func (QuanPostConfigTarget *QuanPostConfigTarget) TableName() string { |
|||
return "quan_post_config_target" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *QuanPostConfigTarget) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *QuanPostConfigTarget) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *QuanPostConfigTarget) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_KPI.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *QuanPostConfigTarget) ContMap(whereMap interface{}, field ...string) (countAry []QuanPostConfigTarget, err error) { |
|||
gormDb := overall.CONSTANT_DB_KPI.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *QuanPostConfigTarget) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_KPI.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
Loading…
Reference in new issue