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.
700 lines
23 KiB
700 lines
23 KiB
package administrativeorganization
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"hr_server/models"
|
|
"hr_server/overall"
|
|
"hr_server/overall/overallhandle"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 职位(岗位)列表
|
|
func (o *OrganizationApi) PositionList(c *gin.Context) {
|
|
var requestData lookPositionList
|
|
c.ShouldBindJSON(&requestData)
|
|
if requestData.Page < 0 {
|
|
requestData.Page = 1
|
|
}
|
|
if requestData.PageSize < 0 {
|
|
requestData.PageSize = 10
|
|
}
|
|
// gormDb := overall.CONSTANT_DB_HR.Model(&models.JobClass{}).Select("").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type")
|
|
var positionType models.Position
|
|
gormDb := overall.CONSTANT_DB_HR.Table(fmt.Sprintf("%s p", positionType.TableName())).Select("p.*,d.name as dutiesname,d.number as dutiesnumber,ao.name as aoname,ao.number as aonumber,j.name as jobname").Joins("left join duties as d on d.id = p.duties").Joins("left join administrative_organization as ao on ao.id = p.administrative_organization").Joins("left join job_class as j on j.id = d.job_type")
|
|
if requestData.Name != "" {
|
|
gormDb = gormDb.Where("p.name LIKE ?", "%"+requestData.Name+"%")
|
|
}
|
|
if requestData.Number != "" {
|
|
gormDb = gormDb.Where("p.number LIKE ?", "%"+requestData.Number+"%")
|
|
}
|
|
if requestData.Duties != "" {
|
|
gormDb = gormDb.Where("p.duties = ?", requestData.Duties)
|
|
}
|
|
if requestData.Organization != "" {
|
|
orgIdInt, _ := strconv.ParseInt(requestData.Organization, 10, 64)
|
|
// orgIdList := overallhandle.GetDepartmentSun(orgIdInt, []int64{})
|
|
// orgIdList = append(orgIdList, orgIdInt)
|
|
// gormDb = gormDb.Where("p.administrative_organization IN ?", orgIdList)
|
|
// fmt.Printf("所有子集--->%v\n", orgIdList)
|
|
|
|
var sunAry overallhandle.AllSunList[int64]
|
|
sunAry.GetAllSunOrg(orgIdInt)
|
|
sunAry.SunList = append(sunAry.SunList, orgIdInt)
|
|
gormDb = gormDb.Where("p.administrative_organization IN ?", sunAry.SunList)
|
|
}
|
|
if requestData.InCharge != 0 {
|
|
gormDb = gormDb.Where("p.person_in_charge = ?", requestData.InCharge)
|
|
}
|
|
if requestData.Department != "" {
|
|
gormDb = gormDb.Where("p.department = ?", requestData.Department)
|
|
}
|
|
gormDb = gormDb.Where("p.state IN ?", []int{1, 2})
|
|
var total int64
|
|
totalErr := gormDb.Count(&total).Error
|
|
if totalErr != nil {
|
|
total = 0
|
|
}
|
|
var positionAry []positionOutInfo
|
|
// errGorm := gormDb.Order("p.department DESC,p.duties DESC,p.duties ASC").Limit(requestData.PageSize).Offset(overallhandle.LimitPage(requestData.Page, requestData.PageSize)).Find(&positionAry).Error
|
|
errGorm := gormDb.Order("p.id DESC").Limit(requestData.PageSize).Offset(overallhandle.LimitPage(requestData.Page, requestData.PageSize)).Find(&positionAry).Error
|
|
for i, v := range positionAry {
|
|
var getSpur models.Position
|
|
getWhe := overallhandle.MapOut()
|
|
getWhe["id"] = v.Superior
|
|
// fmt.Printf("%v\n", v.Superior)
|
|
getSpur.GetCont(getWhe, "number", "name")
|
|
positionAry[i].SuperiorNumber = getSpur.Number
|
|
positionAry[i].SuperiorName = getSpur.Name
|
|
|
|
var getSpurDepart models.AdministrativeOrganization
|
|
getWheDepart := overallhandle.MapOut()
|
|
getWheDepart["id"] = v.Department
|
|
getSpurDepart.GetCont(getWheDepart, "name")
|
|
positionAry[i].DepartmentName = getSpurDepart.Name
|
|
|
|
positionAry[i].IdStr = strconv.FormatInt(v.Id, 10)
|
|
|
|
}
|
|
if errGorm != nil {
|
|
overallhandle.Result(105, errGorm, c)
|
|
} else {
|
|
overallhandle.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(positionAry)), positionAry, c)
|
|
}
|
|
}
|
|
|
|
// 添加职位(岗位)
|
|
func (o *OrganizationApi) AddPositionCont(c *gin.Context) {
|
|
var requestData addPositionInfo
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Number == "" {
|
|
overallhandle.Result(101, requestData.Number, c, "职位编码不能为空!")
|
|
return
|
|
}
|
|
if requestData.Name == "" {
|
|
overallhandle.Result(101, requestData.Name, c, "职位名称不能为空!")
|
|
return
|
|
}
|
|
var dutiesId int64 = 0
|
|
if requestData.Duties == "" {
|
|
overallhandle.Result(101, requestData.Duties, c, "请指定该职位的职务!")
|
|
return
|
|
} else {
|
|
dutiesId, _ = strconv.ParseInt(requestData.Duties, 10, 64)
|
|
}
|
|
var organizationId int64 = 0
|
|
if requestData.Organization == "" {
|
|
overallhandle.Result(101, requestData.Organization, c, "请指定该职位归属的行政组织!")
|
|
return
|
|
} else {
|
|
organizationId, _ = strconv.ParseInt(requestData.Organization, 10, 64)
|
|
}
|
|
var superiorInt int64 = 0
|
|
if requestData.Superior != "" {
|
|
superiorInt, _ = strconv.ParseInt(requestData.Superior, 10, 64)
|
|
}
|
|
if requestData.InCharge == 0 {
|
|
requestData.InCharge = 2
|
|
}
|
|
var departmentId int64 = 0
|
|
if requestData.Department == "" {
|
|
overallhandle.Result(101, requestData.Organization, c, "请指定该职位归属的部门!")
|
|
return
|
|
} else {
|
|
departmentId, _ = strconv.ParseInt(requestData.Department, 10, 64)
|
|
}
|
|
var positionCont models.Position
|
|
//判断编号是否已经存在
|
|
isNumExit := overallhandle.MapOut()
|
|
isNumExit["number"] = requestData.Number
|
|
judgeNumErr := positionCont.GetCont(isNumExit)
|
|
if judgeNumErr == nil {
|
|
overallhandle.Result(101, isNumExit, c, "该编号已经存在!请不要重复使用!")
|
|
return
|
|
}
|
|
//判断岗位名称是否已经存在
|
|
isExit := overallhandle.MapOut()
|
|
isExit["department"] = departmentId
|
|
isExit["name"] = requestData.Name
|
|
isExit["administrative_organization"] = organizationId
|
|
judgeErr := positionCont.GetCont(isExit)
|
|
if judgeErr == nil {
|
|
overallhandle.Result(101, isExit, c, "该职位在本部门下已经存在!请不要重复添加")
|
|
return
|
|
}
|
|
positionCont.Number = requestData.Number
|
|
positionCont.Name = requestData.Name
|
|
positionCont.Duties = dutiesId
|
|
positionCont.AdministrativeOrganization = organizationId
|
|
positionCont.Superior = superiorInt
|
|
positionCont.PersonInCharge = requestData.InCharge
|
|
positionCont.Department = departmentId
|
|
positionCont.State = 1
|
|
positionCont.Time = time.Now().Unix()
|
|
addDataErr := overall.CONSTANT_DB_HR.Create(&positionCont).Error
|
|
if addDataErr != nil {
|
|
overallhandle.Result(104, addDataErr, c)
|
|
} else {
|
|
overallhandle.Result(0, positionCont, c)
|
|
}
|
|
}
|
|
|
|
// 获取职位(岗位)详情
|
|
func (o *OrganizationApi) GetPositionCont(c *gin.Context) {
|
|
var requestData overallhandle.GetId
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == 0 && requestData.IdStr == "" {
|
|
overallhandle.Result(101, err, c, "职务分类Id不能为空!")
|
|
return
|
|
}
|
|
if requestData.IdStr != "" {
|
|
idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64)
|
|
requestData.Id = idInt64
|
|
}
|
|
var positionType models.Position
|
|
var postCont positionOutInfo
|
|
dbErr := overall.CONSTANT_DB_HR.Model(&positionType).Select("position.*,d.name as dutiesname,d.number as dutiesnumber,ao.name as aoname,ao.number as aonumber,j.name as jobname").Joins("left join duties as d on d.id = position.duties").Joins("left join administrative_organization as ao on ao.id = position.administrative_organization").Joins("left join job_class as j on j.id = d.job_type").Where("position.id = ?", requestData.Id).First(&postCont).Error
|
|
if dbErr != nil {
|
|
overallhandle.Result(105, dbErr, c)
|
|
} else {
|
|
var getSpur models.Position
|
|
getWhe := overallhandle.MapOut()
|
|
getWhe["id"] = postCont.Superior
|
|
fmt.Printf("%v\n", postCont.Superior)
|
|
getSpur.GetCont(getWhe, "number", "name")
|
|
postCont.SuperiorNumber = getSpur.Number
|
|
postCont.SuperiorName = getSpur.Name
|
|
if postCont.OrgList != "" {
|
|
json.Unmarshal([]byte(postCont.OrgList), postCont.OrgListAry)
|
|
} else {
|
|
groupId, companyId, departmentId, sunDepartId, workShopId := overallhandle.GetOrgStructure(postCont.AdministrativeOrganization)
|
|
if groupId != 0 && overallhandle.IsInTrue[int64](groupId, postCont.OrgListAry) == false {
|
|
postCont.OrgListAry = append(postCont.OrgListAry, groupId)
|
|
}
|
|
if companyId != 0 && overallhandle.IsInTrue[int64](companyId, postCont.OrgListAry) == false {
|
|
postCont.OrgListAry = append(postCont.OrgListAry, companyId)
|
|
}
|
|
if departmentId != 0 && overallhandle.IsInTrue[int64](departmentId, postCont.OrgListAry) == false {
|
|
postCont.OrgListAry = append(postCont.OrgListAry, departmentId)
|
|
}
|
|
if sunDepartId != 0 && overallhandle.IsInTrue[int64](sunDepartId, postCont.OrgListAry) == false {
|
|
postCont.OrgListAry = append(postCont.OrgListAry, sunDepartId)
|
|
}
|
|
if workShopId != 0 && overallhandle.IsInTrue[int64](workShopId, postCont.OrgListAry) == false {
|
|
postCont.OrgListAry = append(postCont.OrgListAry, workShopId)
|
|
}
|
|
}
|
|
|
|
overallhandle.Result(0, postCont, c)
|
|
}
|
|
}
|
|
|
|
// 编辑职位(岗位)
|
|
func (o *OrganizationApi) EitePositionCont(c *gin.Context) {
|
|
var requestData eitePositionInfo
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == 0 && requestData.IdStr == "" {
|
|
overallhandle.Result(101, err, c, "行政类别Id不能为空!")
|
|
return
|
|
}
|
|
if requestData.IdStr != "" {
|
|
idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64)
|
|
requestData.Id = idInt64
|
|
}
|
|
whereAry := overallhandle.MapOut()
|
|
whereAry["id"] = requestData.Id
|
|
var govCont models.Position
|
|
judgeErr := govCont.GetCont(whereAry)
|
|
if judgeErr != nil {
|
|
overallhandle.Result(107, judgeErr, c)
|
|
return
|
|
}
|
|
saveData := overallhandle.MapOut()
|
|
saveData["time"] = time.Now().Unix()
|
|
if requestData.Number != "" && requestData.Number != govCont.Number {
|
|
isNumExit := overallhandle.MapOut()
|
|
isNumExit["number"] = requestData.Number
|
|
var govContNum models.Position
|
|
judgeNumErr := govContNum.GetCont(isNumExit, "id", "number")
|
|
if judgeNumErr == nil {
|
|
overallhandle.Result(101, isNumExit, c, "该编号已经存在!请不要重复使用!")
|
|
return
|
|
}
|
|
saveData["number"] = requestData.Number
|
|
}
|
|
departIsTrue := false
|
|
if requestData.Department != "" && requestData.Department != strconv.FormatInt(govCont.Department, 10) {
|
|
departIsTrue = true
|
|
saveData["department"] = requestData.Department
|
|
}
|
|
|
|
if requestData.Name != "" && requestData.Name != govCont.Name {
|
|
if departIsTrue == true {
|
|
//判断岗位名称是否已经存在
|
|
departmentId, _ := strconv.ParseInt(requestData.Department, 10, 64)
|
|
isExit := overallhandle.MapOut()
|
|
isExit["department"] = departmentId
|
|
isExit["name"] = requestData.Name
|
|
var govContName models.Position
|
|
judgeErr := govContName.GetCont(isExit, "id", "department", "name")
|
|
if judgeErr == nil {
|
|
overallhandle.Result(101, isExit, c, "该职位在本部门下已经存在!请不要重复添加")
|
|
return
|
|
}
|
|
}
|
|
saveData["name"] = requestData.Name
|
|
}
|
|
if requestData.Duties != "" && requestData.Duties != strconv.FormatInt(govCont.Duties, 10) {
|
|
saveData["duties"] = requestData.Duties
|
|
}
|
|
if requestData.Organization != "" && requestData.Organization != strconv.FormatInt(govCont.AdministrativeOrganization, 10) {
|
|
saveData["administrative_organization"] = requestData.Organization
|
|
}
|
|
if requestData.Superior != "" && requestData.Superior != strconv.FormatInt(govCont.Superior, 10) {
|
|
saveData["superior"] = requestData.Superior
|
|
}
|
|
if requestData.InCharge != 0 {
|
|
saveData["person_in_charge"] = requestData.InCharge
|
|
}
|
|
eiteErr := govCont.EiteCont(whereAry, saveData)
|
|
if eiteErr != nil {
|
|
overallhandle.Result(106, eiteErr, c)
|
|
} else {
|
|
overallhandle.Result(0, saveData, c)
|
|
}
|
|
}
|
|
|
|
// 编辑职位(岗位)状态或删除
|
|
func (o *OrganizationApi) EitePositionStateOrDel(c *gin.Context) {
|
|
var requestData EiteJobStateDel
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == 0 && requestData.IdStr == "" {
|
|
overallhandle.Result(101, err, c, "行政类别Id不能为空!")
|
|
return
|
|
}
|
|
if requestData.IdStr != "" {
|
|
idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64)
|
|
requestData.Id = idInt64
|
|
}
|
|
if requestData.State == 0 {
|
|
requestData.State = 1
|
|
}
|
|
|
|
whereAry := overallhandle.MapOut()
|
|
whereAry["id"] = requestData.Id
|
|
|
|
var jobClassInfo models.Position
|
|
//判断行政组织是否存在
|
|
judgeExist := jobClassInfo.GetCont(whereAry)
|
|
if judgeExist != nil {
|
|
overallhandle.Result(107, judgeExist, c)
|
|
return
|
|
}
|
|
saveData := overallhandle.MapOut()
|
|
saveData["time"] = time.Now().Unix()
|
|
saveData["state"] = requestData.State
|
|
|
|
if requestData.State != 3 {
|
|
eiteErr := jobClassInfo.EiteCont(whereAry, saveData)
|
|
if eiteErr != nil {
|
|
overallhandle.Result(106, eiteErr, c)
|
|
} else {
|
|
overallhandle.Result(0, saveData, c)
|
|
}
|
|
} else {
|
|
if requestData.IsTrue != 1 {
|
|
//软删除
|
|
eiteErr := jobClassInfo.EiteCont(whereAry, saveData)
|
|
if eiteErr != nil {
|
|
overallhandle.Result(106, eiteErr, c)
|
|
} else {
|
|
overallhandle.Result(0, saveData, c)
|
|
}
|
|
} else {
|
|
//硬删除
|
|
delErr := overall.CONSTANT_DB_HR.Where(whereAry).Delete(&jobClassInfo)
|
|
if delErr == nil {
|
|
overallhandle.Result(0, saveData, c)
|
|
} else {
|
|
overallhandle.Result(108, delErr, c)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 获取职位权限配置清单
|
|
func (o *OrganizationApi) GetPositionRole(c *gin.Context) {
|
|
var requestData overallhandle.GetId
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, requestData, c)
|
|
return
|
|
}
|
|
if requestData.Id == 0 && requestData.IdStr == "" {
|
|
overallhandle.Result(101, requestData, c)
|
|
return
|
|
}
|
|
if requestData.IdStr != "" {
|
|
idInt, inIntErr := strconv.ParseInt(requestData.IdStr, 10, 64)
|
|
if inIntErr == nil {
|
|
requestData.Id = idInt
|
|
}
|
|
}
|
|
where := overallhandle.MapOut()
|
|
var positionRole models.Position
|
|
where["id"] = requestData.Id
|
|
inFoErr := positionRole.GetCont(where, "menu_permit", "button_permit")
|
|
if inFoErr != nil {
|
|
overallhandle.Result(105, requestData, c)
|
|
return
|
|
}
|
|
_, datahhh := GetMenuOperation(positionRole.MenuPermit, positionRole.ButtonPermit)
|
|
overallhandle.Result(0, datahhh, c)
|
|
}
|
|
|
|
// 遍历确权
|
|
func GetMenuOperation(menuStr, menuOperStr string) (isTrue bool, sendData []powerConfigList) {
|
|
isTrue = false
|
|
var menuStrMap []int64
|
|
var menuOperStrMap []int64
|
|
|
|
json.Unmarshal([]byte(menuStr), &menuStrMap)
|
|
json.Unmarshal([]byte(menuOperStr), &menuOperStrMap)
|
|
|
|
var systemMenuList []models.SystemMenu
|
|
menuOperErr := overall.CONSTANT_DB_Master.Where("`m_steat` IN ?", []int{1, 2}).Order("m_sort asc").Order("m_id desc").Find(&systemMenuList).Error
|
|
if menuOperErr != nil {
|
|
return
|
|
}
|
|
fmt.Printf("menuStr------>%v--------------->%v\n", menuStr, menuStrMap)
|
|
sendData = GetMenuPowerThree(1, 0, systemMenuList, menuStrMap, menuOperStrMap)
|
|
return
|
|
}
|
|
|
|
// 递归无限树
|
|
func GetMenuPowerThree(jurisd int, parentId int64, threeData []models.SystemMenu, menuStrMap, menuOperStrMap []int64) []powerConfigList {
|
|
// treeList := []SystemMenuThree{}
|
|
treeListPower := []powerConfigList{}
|
|
for _, v := range threeData {
|
|
if v.ParentId == parentId {
|
|
var powerConfigCont powerConfigList
|
|
powerConfigCont.Id = v.Id
|
|
powerConfigCont.Title = v.Title
|
|
powerConfigCont.IsTrue = overallhandle.JudgeInMap(v.Id, menuStrMap)
|
|
child := GetMenuPowerThree(jurisd, v.Id, threeData, menuStrMap, menuOperStrMap)
|
|
powerConfigCont.Child = child
|
|
isTrue, menuOper := MenuOperation(jurisd, v.Id)
|
|
if isTrue == true {
|
|
var operList []powerCont
|
|
for _, oper_val := range menuOper {
|
|
var operCont powerCont
|
|
operCont.Id = oper_val.OperId
|
|
operCont.Title = oper_val.OperTitle
|
|
operCont.IsTrue = overallhandle.JudgeInMap(oper_val.OperId, menuOperStrMap)
|
|
operList = append(operList, operCont)
|
|
}
|
|
powerConfigCont.MenuOperation = operList
|
|
}
|
|
|
|
treeListPower = append(treeListPower, powerConfigCont)
|
|
}
|
|
}
|
|
return treeListPower
|
|
}
|
|
|
|
// 获取菜单操作项目
|
|
func MenuOperation(jurisd int, menuId int64) (isTrue bool, operation []models.MenuOperation) {
|
|
isTrue = false
|
|
// if jurisd != 1 {
|
|
// operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ? AND oper_id IN ?", menuId, global.Gva_Authority_Authentication).Order("oper_id desc").Find(&operation).Error
|
|
// if operErr == nil {
|
|
// isTrue = true
|
|
// }
|
|
// } else {
|
|
// operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operation).Error
|
|
// if operErr == nil {
|
|
// isTrue = true
|
|
// }
|
|
// }
|
|
operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operation).Error
|
|
if operErr == nil {
|
|
isTrue = true
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-22 08:40:38
|
|
@ 功能: 根据行政组织获取岗位
|
|
@ 参数
|
|
|
|
#requestData 行政组织数组
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#func (o *OrganizationApi) BasisOrgGetPostList(c *gin.Context)
|
|
*/
|
|
func (o *OrganizationApi) BasisOrgGetPostList(c *gin.Context) {
|
|
var requestData OrgGivePost
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil || len(requestData.Id) < 1 {
|
|
overallhandle.Result(100, requestData, c)
|
|
return
|
|
}
|
|
orgList := []int64{312, 313}
|
|
groupId, companyId, departmentId, _, _ := overallhandle.GetOrgStructure(requestData.Id[len(requestData.Id)-1])
|
|
fmt.Printf("空间看到----->%v----->%v----->%v\n", groupId, companyId, departmentId)
|
|
if overallhandle.IsInTrue[int64](groupId, orgList) == false {
|
|
orgList = append(orgList, groupId)
|
|
}
|
|
if overallhandle.IsInTrue[int64](companyId, orgList) == false {
|
|
orgList = append(orgList, companyId)
|
|
}
|
|
var postList []models.Position
|
|
err = overall.CONSTANT_DB_HR.Model(&models.Position{}).Where("`state` = 1 AND `administrative_organization` IN ?", orgList).Or("`department` = ?", departmentId).Order("person_in_charge ASC").Find(&postList).Error
|
|
if err != nil {
|
|
overallhandle.Result(107, err, c)
|
|
return
|
|
}
|
|
overallhandle.Result(0, postList, c)
|
|
}
|
|
|
|
/**
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-22 10:04:48
|
|
@ 功能: 添加职位(岗位)新版
|
|
@ 参数
|
|
#
|
|
@ 返回值
|
|
#
|
|
@ 方法原型
|
|
#
|
|
*/
|
|
//
|
|
func (o *OrganizationApi) AddPositionContNew(c *gin.Context) {
|
|
var requestData addPositionInfoNew
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Number == "" {
|
|
overallhandle.Result(101, requestData.Number, c, "职位编码不能为空!")
|
|
return
|
|
}
|
|
if requestData.Name == "" {
|
|
overallhandle.Result(101, requestData.Name, c, "职位名称不能为空!")
|
|
return
|
|
}
|
|
if requestData.Duties == 0 {
|
|
overallhandle.Result(101, requestData.Duties, c, "请指定该职位的职务!")
|
|
return
|
|
}
|
|
if len(requestData.Organization) < 1 {
|
|
overallhandle.Result(101, requestData.Organization, c, "请指定该职位归属的行政组织!")
|
|
return
|
|
}
|
|
orgListJson, _ := json.Marshal(requestData.Organization)
|
|
if requestData.InCharge == 0 {
|
|
requestData.InCharge = 2
|
|
}
|
|
|
|
var positionCont models.Position
|
|
//判断编号是否已经存在
|
|
isNumExit := overallhandle.MapOut()
|
|
isNumExit["number"] = requestData.Number
|
|
judgeNumErr := positionCont.GetCont(isNumExit)
|
|
if judgeNumErr == nil {
|
|
overallhandle.Result(101, isNumExit, c, "该编号已经存在!请不要重复使用!")
|
|
return
|
|
}
|
|
organizationId := requestData.Organization[len(requestData.Organization)-1]
|
|
_, companyId, departmentId, _, _ := overallhandle.GetOrgStructure(organizationId)
|
|
|
|
if departmentId == 0 {
|
|
departmentId = companyId
|
|
}
|
|
|
|
//判断岗位名称是否已经存在
|
|
isExit := overallhandle.MapOut()
|
|
isExit["department"] = departmentId
|
|
isExit["name"] = requestData.Name
|
|
isExit["administrative_organization"] = organizationId
|
|
judgeErr := positionCont.GetCont(isExit)
|
|
if judgeErr == nil {
|
|
overallhandle.Result(101, isExit, c, "该职位在本行政组织下已经存在!请不要重复添加")
|
|
return
|
|
}
|
|
positionCont.Number = requestData.Number
|
|
positionCont.Name = requestData.Name
|
|
positionCont.Duties = requestData.Duties
|
|
positionCont.AdministrativeOrganization = organizationId
|
|
positionCont.Superior = requestData.Superior
|
|
positionCont.PersonInCharge = requestData.InCharge
|
|
positionCont.Department = departmentId
|
|
positionCont.State = 1
|
|
positionCont.Time = time.Now().Unix()
|
|
positionCont.OrgList = string(orgListJson)
|
|
addDataErr := overall.CONSTANT_DB_HR.Create(&positionCont).Error
|
|
if addDataErr != nil {
|
|
overallhandle.Result(104, addDataErr, c)
|
|
} else {
|
|
overallhandle.Result(0, addDataErr, c)
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-23 08:44:11
|
|
@ 功能: 编辑职位(岗位)
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (o *OrganizationApi) EitePositionContNew(c *gin.Context) {
|
|
var requestData eitePositionInfoNes
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
overallhandle.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.Id == 0 && requestData.IdStr == "" {
|
|
overallhandle.Result(101, err, c, "行政类别Id不能为空!")
|
|
return
|
|
}
|
|
if len(requestData.Organization) < 1 {
|
|
overallhandle.Result(101, requestData.Organization, c, "请指定该职位归属的行政组织!")
|
|
return
|
|
}
|
|
if requestData.IdStr != "" {
|
|
idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64)
|
|
requestData.Id = idInt64
|
|
}
|
|
whereAry := overallhandle.MapOut()
|
|
whereAry["id"] = requestData.Id
|
|
var govCont models.Position
|
|
judgeErr := govCont.GetCont(whereAry)
|
|
if judgeErr != nil {
|
|
overallhandle.Result(107, judgeErr, c)
|
|
return
|
|
}
|
|
saveData := overallhandle.MapOut()
|
|
|
|
if requestData.Number != "" && requestData.Number != govCont.Number {
|
|
isNumExit := overallhandle.MapOut()
|
|
isNumExit["number"] = requestData.Number
|
|
var govContNum models.Position
|
|
judgeNumErr := govContNum.GetCont(isNumExit, "id", "number")
|
|
if judgeNumErr == nil {
|
|
overallhandle.Result(101, isNumExit, c, "该编号已经存在!请不要重复使用!")
|
|
return
|
|
}
|
|
saveData["number"] = requestData.Number
|
|
}
|
|
|
|
organizationId := requestData.Organization[len(requestData.Organization)-1]
|
|
_, companyId, departmentId, _, _ := overallhandle.GetOrgStructure(organizationId)
|
|
if departmentId == 0 {
|
|
departmentId = companyId
|
|
}
|
|
departIsTrue := false
|
|
if departmentId != 0 && departmentId != govCont.Department {
|
|
departIsTrue = true
|
|
orgListJson, _ := json.Marshal(requestData.Organization)
|
|
saveData["department"] = departmentId
|
|
saveData["orglist"] = orgListJson
|
|
}
|
|
|
|
if requestData.Name != "" && requestData.Name != govCont.Name {
|
|
if departIsTrue == true {
|
|
//判断岗位名称是否已经存在
|
|
isExit := overallhandle.MapOut()
|
|
isExit["department"] = departmentId
|
|
isExit["name"] = requestData.Name
|
|
var govContName models.Position
|
|
judgeErr := govContName.GetCont(isExit, "id", "department", "name")
|
|
if judgeErr == nil {
|
|
overallhandle.Result(101, isExit, c, "该职位在本部门下已经存在!请不要重复添加")
|
|
return
|
|
}
|
|
}
|
|
saveData["name"] = requestData.Name
|
|
}
|
|
if requestData.Duties != 0 && requestData.Duties != govCont.Duties {
|
|
saveData["duties"] = requestData.Duties
|
|
}
|
|
if organizationId != 0 && organizationId != govCont.AdministrativeOrganization {
|
|
saveData["administrative_organization"] = organizationId
|
|
}
|
|
if requestData.Superior != 0 && requestData.Superior != govCont.Superior {
|
|
saveData["superior"] = requestData.Superior
|
|
}
|
|
if requestData.InCharge != 0 {
|
|
saveData["person_in_charge"] = requestData.InCharge
|
|
}
|
|
if len(saveData) < 1 {
|
|
overallhandle.Result(0, saveData, c)
|
|
return
|
|
}
|
|
saveData["time"] = time.Now().Unix()
|
|
eiteErr := govCont.EiteCont(whereAry, saveData)
|
|
if eiteErr != nil {
|
|
overallhandle.Result(106, eiteErr, c)
|
|
} else {
|
|
overallhandle.Result(0, saveData, c)
|
|
}
|
|
}
|
|
|