KPI绩效考核系统
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.

445 lines
12 KiB

package jurisdictionpc
import (
"fmt"
"key_performance_indicators/models/modelshr"
"key_performance_indicators/models/modelssystempermission"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"strconv"
"strings"
"time"
"github.com/gin-gonic/gin"
)
//系统角色处理
func (a *ApiMethod) AddSystemRole(c *gin.Context) {
var receivedValue systemRole
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Sort == 0 {
receivedValue.Sort = 50
}
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`")
if err == nil {
publicmethod.Result(103, systemRoleCont, c)
return
}
systemRoleCont.Name = receivedValue.Name
systemRoleCont.Sort = receivedValue.Sort
systemRoleCont.State = 1
systemRoleCont.Time = time.Now().Unix()
err = overall.CONSTANT_DB_System_Permission.Create(&systemRoleCont).Error
if err != nil {
publicmethod.Result(104, err, c)
return
}
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:30:04
@ 功能: 系统角色编辑
@ 参数
#Id 项目ID
#Name 角色名称
#Sort 角色排序
@ 返回值
#
*/
func (a *ApiMethod) EditSystemRole(c *gin.Context) {
var receivedValue editSystemRoleCont
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Name == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.Sort == 0 {
receivedValue.Sort = 50
}
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(map[string]interface{}{"`id`": receivedValue.Id}, "`name`")
if err != nil {
publicmethod.Result(107, err, c)
return
}
editCont := publicmethod.MapOut[string]()
if receivedValue.Sort != systemRoleCont.Sort {
editCont["`sort`"] = receivedValue.Sort
}
if systemRoleCont.Name != receivedValue.Name {
err = systemRoleCont.GetCont(map[string]interface{}{"`name`": receivedValue.Name}, "`id`")
if err == nil {
publicmethod.Result(103, systemRoleCont, c)
return
}
editCont["`name`"] = receivedValue.Name
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
editCont["`state`"] = 1
err = systemRoleCont.EiteCont(map[string]interface{}{"`id`": receivedValue.Id}, editCont)
if err != nil {
publicmethod.Result(106, err, c)
return
}
}
publicmethod.Result(0, systemRoleCont, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:41:20
@ 功能: 角色列表
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) SystemRoleList(c *gin.Context) {
var receivedValue systemRoleContList
c.ShouldBindJSON(&receivedValue)
var systemRoleInfoList []modelssystempermission.SystemRole
gormDb := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Where("`state` BETWEEN ? AND ?", 1, 2)
if receivedValue.Name != "" {
gormDb = gormDb.Where("`name` LIKE ?", "%"+receivedValue.Name+"%")
}
err := gormDb.Order("`sort` ASC").Order("`id` DESC").Find(&systemRoleInfoList).Error
if err != nil {
publicmethod.Result(107, err, c)
return
}
var sendList []sendSystemRoleList
for _, v := range systemRoleInfoList {
var sendCont sendSystemRoleList
sendCont.Id = v.Id
sendCont.Name = v.Name //角色名称"`
sendCont.State = v.State //状态(1:启用;2:禁用;3:删除)"`
sendCont.Time = v.Time //创建时间"`
sendCont.Sort = v.Sort //排序"`
if v.State == 1 {
sendCont.IsTrue = true
} else {
sendCont.IsTrue = false
}
sendList = append(sendList, sendCont)
}
publicmethod.Result(0, sendList, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-09 08:52:56
@ 功能: 编辑角色状态
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) EditSystemRoleState(c *gin.Context) {
var receivedValue publicmethod.PublicState
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if receivedValue.State == 0 {
receivedValue.State = 2
}
wheAry := publicmethod.MapOut[string]()
wheAry["`id`"] = receivedValue.Id
var systemRoleCont modelssystempermission.SystemRole
err = systemRoleCont.GetCont(wheAry, "`state`")
if err != nil {
publicmethod.Result(107, err, c)
return
}
if receivedValue.State != 3 {
editCont := publicmethod.MapOut[string]()
if receivedValue.State != systemRoleCont.State {
editCont["`state`"] = receivedValue.State
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
err = systemRoleCont.EiteCont(wheAry, editCont)
}
} else {
if receivedValue.IsTrue != 1 {
editCont := publicmethod.MapOut[string]()
if receivedValue.State != systemRoleCont.State {
editCont["`state`"] = receivedValue.State
}
if len(editCont) > 0 {
editCont["`time`"] = time.Now().Unix()
err = systemRoleCont.EiteCont(wheAry, editCont)
}
} else {
err = systemRoleCont.DelCont(wheAry)
}
}
if err != nil {
publicmethod.Result(106, err, c)
return
}
publicmethod.Result(0, err, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-16 08:02:47
@ 功能: 角色相关人员
@ 参数
#id 角色ID
#name 姓名或工号
@ 返回值
#
*/
func (a *ApiMethod) RoleAboutPeopleList(c *gin.Context) {
var receivedValue SystemRoleAboutPeopleList
c.ShouldBindJSON(&receivedValue)
if receivedValue.Page == 0 {
receivedValue.Page = 1
}
if receivedValue.PageSize == 0 {
receivedValue.PageSize = 20
}
if receivedValue.Id == "" {
publicmethod.Result(1, nil, c, "未知角色")
return
}
gormDb := overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`number`,`name`,`icon`,`company`,`maindeparment`,`admin_org`,`position`,`job_id`,`key`,`wechat`,`work_wechat`").Where("`state` = 1 AND FIND_IN_SET(?,`role`)", receivedValue.Id)
if receivedValue.Name != "" {
gormDb = gormDb.Where("`name` LIKE ? OR `number` LIKE ?", "%"+receivedValue.Name+"%", "%"+receivedValue.Name+"%")
}
var total int64
totalErr := gormDb.Count(&total).Error
if totalErr != nil {
total = 0
}
gormDb = publicmethod.PageTurningSettings(gormDb, receivedValue.Page, receivedValue.PageSize)
var RoleManList []modelshr.PersonArchives
err := gormDb.Find(&RoleManList).Error
if err != nil {
publicmethod.Result(105, err, c)
return
}
if len(RoleManList) < 1 {
publicmethod.Result(105, RoleManList, c)
return
}
var sendData []SendSystemRoleAboutPeopleList
for _, v := range RoleManList {
var sendDataInfo SendSystemRoleAboutPeopleList
sendDataInfo.Id = strconv.FormatInt(v.Id, 10)
sendDataInfo.Number = v.Number
sendDataInfo.Name = v.Name
sendDataInfo.Company = strconv.FormatInt(v.Company, 10)
var comInfo modelshr.AdministrativeOrganization
comInfo.GetCont(map[string]interface{}{"`id`": v.Company}, "`name`")
sendDataInfo.CompanyName = comInfo.Name
sendDataInfo.Department = strconv.FormatInt(v.MainDeparment, 10)
var deparInfo modelshr.AdministrativeOrganization
deparInfo.GetCont(map[string]interface{}{"`id`": v.MainDeparment}, "`name`")
sendDataInfo.DepartmentName = deparInfo.Name
sendDataInfo.OrgId = strconv.FormatInt(v.AdminOrg, 10)
var orderInfo modelshr.AdministrativeOrganization
orderInfo.GetCont(map[string]interface{}{"`id`": v.AdminOrg}, "`name`")
sendDataInfo.OrgName = orderInfo.Name
sendDataInfo.DutiesId = strconv.FormatInt(v.Position, 10)
var postCont modelshr.Position
postCont.GetCont(map[string]interface{}{"`id`": v.Position}, "`name`")
sendDataInfo.DutiesName = postCont.Name
sendDataInfo.Wechat = v.Wechat
if v.WorkWechat != "" {
sendDataInfo.Wechat = v.WorkWechat
}
sendDataInfo.Key = strconv.FormatInt(v.Key, 10)
if v.MainDeparment != v.AdminOrg {
sendDataInfo.DepartMentTitle = fmt.Sprintf("%v/%v/%v", comInfo.Name, deparInfo.Name, orderInfo.Name)
} else {
sendDataInfo.DepartMentTitle = fmt.Sprintf("%v/%v", comInfo.Name, deparInfo.Name)
}
sendData = append(sendData, sendDataInfo)
}
publicmethod.ResultList(0, receivedValue.Page, receivedValue.PageSize, total, int64(len(sendData)), sendData, c)
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-16 11:53:58
@ 功能: 批量删除角色关联人员
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) BatchDeletToRoleAboutMan(c *gin.Context) {
var receivedValue BatchDeletAllRoleMan
err := c.ShouldBindJSON(&receivedValue)
if err != nil {
publicmethod.Result(100, err, c)
return
}
if receivedValue.Id == "" {
publicmethod.Result(101, receivedValue, c)
return
}
if len(receivedValue.ManKey) < 1 {
publicmethod.Result(101, receivedValue, c)
return
}
var manList []modelshr.PersonArchives
err = overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`id`,`role`").Where("`key` IN ?", receivedValue.ManKey).Find(&manList).Error
if err != nil {
publicmethod.Result(107, err, c)
return
}
if len(manList) < 1 {
publicmethod.Result(107, manList, c)
return
}
for _, v := range manList {
syncSeting.Add(1)
go EditManRoleCont(receivedValue.Id, v)
}
syncSeting.Wait()
publicmethod.Result(0, nil, c)
}
// 编辑批量删除角色人员信息处理
func EditManRoleCont(roleId string, manCont modelshr.PersonArchives) {
defer syncSeting.Done()
roleList := strings.Split(manCont.Role, ",")
if publicmethod.IsInTrue[string](roleId, roleList) == true {
var editRoleList []string
for i := 0; i < len(roleList); i++ {
if roleList[i] != roleId {
editRoleList = append(editRoleList, roleList[i])
}
}
saveData := publicmethod.MapOut[string]()
if len(editRoleList) > 0 {
saveData["`role`"] = strings.Join(editRoleList, ",")
} else {
saveData["`role`"] = ""
}
saveData["`eite_time`"] = time.Now().Unix()
manCont.EiteCont(map[string]interface{}{"`id`": manCont.Id}, saveData)
}
}
/*
*
@ 作者: 秦东
@ 时间: 2022-11-19 08:30:26
@ 功能: 添加角色使用人员
@ 参数
#
@ 返回值
#
*/
func (a *ApiMethod) AddRoleUser(c *gin.Context) {
var receivedValue ReceiveRoleAndPeople
c.ShouldBindJSON(&receivedValue)
if receivedValue.RoleId == "" {
publicmethod.Result(1, nil, c, "未知角色1")
return
}
if len(receivedValue.PeopleList) < 1 {
publicmethod.Result(1, nil, c, "请选择关联人员2")
return
}
var roleCont modelssystempermission.SystemRole
err := roleCont.GetCont(map[string]interface{}{"`id`": receivedValue.RoleId}, "`id`")
if err != nil {
publicmethod.Result(1, nil, c, "角色不存在")
return
}
var peopleId []string
for _, v := range receivedValue.PeopleList {
if v.IsMan == 2 && publicmethod.IsInTrue[string](v.Id, peopleId) == false {
peopleId = append(peopleId, v.Id)
}
}
if len(peopleId) < 1 {
publicmethod.Result(0, receivedValue.PeopleList, c, "数据处理完成!3")
return
}
var manList []modelshr.PersonArchives
err = overall.CONSTANT_DB_HR.Model(&modelshr.PersonArchives{}).Select("`key`,`role`").Where("`key` IN ?", peopleId).Find(&manList).Error
if err != nil || len(manList) < 1 {
publicmethod.Result(107, nil, c, "数据处理失败!4")
return
}
for _, m := range manList {
saveData := publicmethod.MapOut[string]()
if m.Role == "" {
saveData["`role`"] = receivedValue.RoleId
} else {
oldRoleList := strings.Split(m.Role, ",")
if publicmethod.IsInTrue[string](receivedValue.RoleId, oldRoleList) == false {
oldRoleList = append(oldRoleList, receivedValue.RoleId)
saveData["`role`"] = strings.Join(oldRoleList, ",")
}
}
if len(saveData) > 0 {
saveData["`eite_time`"] = time.Now().Unix()
var saveCont modelshr.PersonArchives
saveCont.EiteCont(map[string]interface{}{"`key`": m.Key}, saveData)
}
}
publicmethod.Result(0, nil, c)
}