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.
267 lines
8.7 KiB
267 lines
8.7 KiB
package assessment
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
|
|
"gin_server_admin/commonus"
|
|
"gin_server_admin/global"
|
|
"gin_server_admin/model/assessmentmodel"
|
|
"gin_server_admin/model/common/response"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
考核方案制定
|
|
*/
|
|
func (a *EvaluationScheme) Index(c *gin.Context) {
|
|
outPut := commonus.MapOut()
|
|
response.Result(0, outPut, "测评方案获取成功", c)
|
|
}
|
|
|
|
// 添加考核方案
|
|
func (a *EvaluationScheme) AddEvaluationScheme(c *gin.Context) {
|
|
var requestData AddScheme
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
response.Result(101, err, "参数错误!请重新提交!", c)
|
|
return
|
|
}
|
|
if requestData.Title == "" {
|
|
response.Result(102, err, "请输入考核名称!", c)
|
|
return
|
|
}
|
|
if requestData.Group == 0 {
|
|
response.Result(103, err, "请选择归属集团!", c)
|
|
return
|
|
}
|
|
// if requestData.Department == "" {
|
|
// response.Result(104, err, "请选择被考核的部门(分厂)!", c)
|
|
// return
|
|
// }
|
|
if requestData.Dimension == "" {
|
|
response.Result(105, err, "请选择考核维度!", c)
|
|
return
|
|
}
|
|
if requestData.Project == "" {
|
|
response.Result(106, err, "请选择考核项目!", c)
|
|
return
|
|
}
|
|
if requestData.Weight == 0 {
|
|
response.Result(107, err, "请输入权重!", c)
|
|
return
|
|
}
|
|
if len(requestData.Content) < 1 {
|
|
response.Result(108, err, "请输入方案内容!", c)
|
|
return
|
|
}
|
|
if requestData.ExecutiveDepartment == 0 {
|
|
response.Result(109, err, "请选择执行部门(分厂)!", c)
|
|
return
|
|
}
|
|
|
|
if len(requestData.Department) < 1 {
|
|
response.Result(111, err, "请选择被考核的部门(分厂)!", c)
|
|
return
|
|
}
|
|
var dataStruct dataLockStatistics
|
|
for _, departId := range requestData.Department {
|
|
syncProcess.Add(1)
|
|
go dataStruct.addEvaluationSchemeHandel(departId, requestData)
|
|
}
|
|
syncProcess.Wait()
|
|
returData := commonus.MapOut()
|
|
readDataMap, readBaoJinf := dataStruct.readMyDayData()
|
|
|
|
returData["istrue"] = readDataMap
|
|
returData["isfalse"] = readBaoJinf
|
|
if len(readBaoJinf) > 0 {
|
|
response.Result(112, returData, "有未处理失败的数据!请检查", c)
|
|
} else {
|
|
response.Result(0, returData, "数据处理完成!", c)
|
|
}
|
|
|
|
}
|
|
|
|
// 并发写入考核方案
|
|
func (d *dataLockStatistics) addEvaluationSchemeHandel(departId int64, addData AddScheme) {
|
|
d.mutext.Lock()
|
|
defer d.mutext.Unlock()
|
|
// fmt.Printf("%v\n", departId)
|
|
juadgeOut := commonus.MapOut()
|
|
juadeIsTrue := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.EvaluationScheme{}).Where("`es_evaluation_department` = ? AND `es_title` = ?", departId, addData.Title).First(&juadgeOut).Error
|
|
if juadeIsTrue == nil {
|
|
errMap := commonus.MapOut()
|
|
errMap["departid"] = departId
|
|
bfErr, bfCont := commonus.GetBranchFactory(departId)
|
|
if bfErr == true {
|
|
errMap["departmentname"] = bfCont.Name
|
|
} else {
|
|
errMap["departmentname"] = ""
|
|
}
|
|
errMap["title"] = addData.Title
|
|
errMap["msg"] = fmt.Sprintf("在%v中已经存在《%v》考核方案!请不要重复添加!", errMap["departmentname"], addData.Title)
|
|
d.dataErrMap = append(d.dataErrMap, errMap)
|
|
} else {
|
|
var saveData assessmentmodel.EvaluationScheme
|
|
saveData.Id = commonus.GetFileNumberEs()
|
|
saveData.Title = addData.Title
|
|
saveData.Group = addData.Group
|
|
saveData.EvaluationDepartment = departId
|
|
dimensionId, dimensionIdErr := strconv.ParseInt(addData.Dimension, 10, 64)
|
|
if dimensionIdErr == nil {
|
|
saveData.Dimension = dimensionId
|
|
}
|
|
projectId, projectIdErr := strconv.ParseInt(addData.Project, 10, 64)
|
|
if projectIdErr == nil {
|
|
saveData.Project = projectId
|
|
}
|
|
saveData.Weight = addData.Weight
|
|
saveData.ExecutiveDepartment = addData.ExecutiveDepartment
|
|
jsonCont, jsonContErr := json.Marshal(addData.Content)
|
|
if jsonContErr == nil {
|
|
saveData.Content = string(jsonCont)
|
|
}
|
|
saveData.AddTime = time.Now().Unix()
|
|
saveData.EiteTime = time.Now().Unix()
|
|
saveData.Maker = 1
|
|
|
|
saveDataes, isError := d.NewsAddRules(projectId, addData.Content)
|
|
if isError != true {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = saveData.Id
|
|
msg["title"] = saveData.Title
|
|
msg["msg"] = "此考核方案的细则录入失败!请重新处理此方案"
|
|
d.dataMap = append(d.dataMap, msg)
|
|
} else {
|
|
jsonSection, jsonErr := json.Marshal(saveDataes)
|
|
if jsonErr != nil {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = saveData.Id
|
|
msg["title"] = saveData.Title
|
|
msg["msg"] = "此考核方案的细则录入失败!请重新处理此方案"
|
|
d.dataMap = append(d.dataMap, msg)
|
|
} else {
|
|
saveData.Content = string(jsonSection)
|
|
juSaveDataErr := global.GVA_DB_Performanceappraisal.Create(&saveData)
|
|
if juSaveDataErr == nil {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = saveData.Id
|
|
msg["title"] = saveData.Title
|
|
msg["msg"] = "此考核方案录入成功!"
|
|
d.dataMap = append(d.dataMap, msg)
|
|
} else {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = saveData.Id
|
|
msg["title"] = saveData.Title
|
|
msg["msg"] = "此考核方案录入失败!"
|
|
d.dataMap = append(d.dataMap, msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
syncProcess.Done()
|
|
}
|
|
|
|
// 判断要新增的考核细则
|
|
func (d *dataLockStatistics) NewsAddRules(parentId int64, dataAry []schemeContent) (rulesSaveData []map[string]interface{}, isTrue bool) {
|
|
isTrue = false
|
|
for _, val := range dataAry {
|
|
writeData := commonus.MapOut()
|
|
if val.Id == "" {
|
|
writeId := commonus.GetFileNumberEs()
|
|
writeData["dc_id"] = writeId
|
|
writeData["dc_title"] = val.Title
|
|
writeData["dc_time"] = time.Now().Unix()
|
|
writeData["dc_state"] = 1
|
|
writeData["dc_parent"] = parentId
|
|
writeData["dc_user_type"] = 1
|
|
writeData["dc_dump"] = val.Section
|
|
writeData["dc_type"] = val.Type
|
|
writeData["dc_unit"] = val.Unittitle
|
|
writeData["dc_cycle"] = val.Cycle
|
|
writeData["dc_cycleattr"] = val.Cycleattr
|
|
writeData["dc_cont"] = val.Content
|
|
juadgeOut := commonus.MapOut()
|
|
juadgeAddDataErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DutyContent{}).Where("`dc_parent` = ? AND `dc_title` = ?", parentId, val.Title).First(&juadgeOut).Error
|
|
if juadgeAddDataErr == nil {
|
|
rulesSaveData = append(rulesSaveData, juadgeOut)
|
|
} else {
|
|
saveDataErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DutyContent{}).Create(&writeData).Error
|
|
if saveDataErr == nil {
|
|
rulesSaveData = append(rulesSaveData, writeData)
|
|
} else {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = val.Id
|
|
msg["title"] = val.Title
|
|
msg["msg"] = "此考核细则写入失败!请重新处理此细则"
|
|
d.dataErrMap = append(d.dataErrMap, msg)
|
|
}
|
|
|
|
}
|
|
} else {
|
|
dataOut := commonus.MapOut()
|
|
juadgeErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DutyContent{}).Where("`dc_id` = ?", val.Id).First(&dataOut).Error
|
|
if juadgeErr == nil {
|
|
rulesSaveData = append(rulesSaveData, dataOut)
|
|
} else {
|
|
writeId := commonus.GetFileNumberEs()
|
|
writeData["dc_id"] = writeId
|
|
writeData["dc_title"] = val.Title
|
|
writeData["dc_time"] = time.Now().Unix()
|
|
writeData["dc_state"] = 1
|
|
writeData["dc_parent"] = parentId
|
|
writeData["dc_user_type"] = 1
|
|
writeData["dc_dump"] = val.Section
|
|
writeData["dc_type"] = val.Type
|
|
writeData["dc_unit"] = val.Unittitle
|
|
writeData["dc_cycle"] = val.Cycle
|
|
writeData["dc_cycleattr"] = val.Cycleattr
|
|
writeData["dc_cont"] = val.Content
|
|
|
|
saveDataErr := global.GVA_DB_Performanceappraisal.Model(&assessmentmodel.DutyContent{}).Create(&writeData).Error
|
|
if saveDataErr == nil {
|
|
rulesSaveData = append(rulesSaveData, writeData)
|
|
} else {
|
|
msg := commonus.MapOut()
|
|
msg["id"] = val.Id
|
|
msg["title"] = val.Title
|
|
msg["msg"] = "此考核细则写入失败!请重新处理此细则"
|
|
d.dataErrMap = append(d.dataErrMap, msg)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if len(rulesSaveData) > 0 {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
// {
|
|
// "title": "2022年恒信高科01号考核方案",
|
|
// "group": 3,
|
|
// "department": "[1,2,3,4]",
|
|
// "dimension": "1644884869457674",
|
|
// "project": "16448868625724229",
|
|
// "weight": 30,
|
|
// "ExecutiveDepartment": 15,
|
|
// "content": [
|
|
// {
|
|
// "id": "16448933707009289",
|
|
// "title": "各区域卫生保持情况;",
|
|
// "type": 1,
|
|
// "parentId": "16448868625724229",
|
|
// "section": "15",
|
|
// "unittitle": "分",
|
|
// "cycle": 3,
|
|
// "cycleattr": 1,
|
|
// "content": "区域卫生保持不到位、打扫不及时根据情况扣除0.1-0.3分。"
|
|
// }
|
|
// ]
|
|
// }
|
|
|
|
// {"title":"2022年恒信高科01号考核方案","group":3,"department":[1,2,3,4],"dimension":"1644884869457674","project":"16448868625724229","weight":30,"ExecutiveDepartment":15,"content":[{"id":"16448933707009289","title":"各区域卫生保持情况;","type":1,"parentId":"16448868625724229","section":"15","unittitle":"\u5206","cycle":3,"cycleattr":1,"content":"区域卫生保持不到位、打扫不及时根据情况扣除0.1-0.3分。"}]}
|
|
|