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.
257 lines
7.3 KiB
257 lines
7.3 KiB
|
4 years ago
|
package administrativeorganization
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"hr_server/models"
|
||
|
|
"hr_server/overall"
|
||
|
|
"hr_server/overall/overallhandle"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
//职务
|
||
|
|
func (o *OrganizationApi) DutiesList(c *gin.Context) {
|
||
|
|
var requestData dutiesListType
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
// err := c.ShouldBindJSON(&requestData)
|
||
|
|
// if err != nil {
|
||
|
|
// overallhandle.Result(100, err, c)
|
||
|
|
// return
|
||
|
|
// }
|
||
|
|
if requestData.Page < 0 {
|
||
|
|
requestData.Page = 1
|
||
|
|
}
|
||
|
|
if requestData.PageSize < 0 {
|
||
|
|
requestData.PageSize = 10
|
||
|
|
}
|
||
|
|
var dutiesList []dutiesOutCont
|
||
|
|
gormDb := overall.CONSTANT_DB_HR.Model(&models.Duties{}).Select("duties.*,job_class.name as classname").Joins("left join job_class on job_class.id = duties.job_type")
|
||
|
|
if requestData.Name != "" {
|
||
|
|
gormDb = gormDb.Where("duties.name LIKE ?", "%"+requestData.Name+"%")
|
||
|
|
}
|
||
|
|
if requestData.JobId != "" {
|
||
|
|
gormDb = gormDb.Where("duties.job_type = ?", requestData.JobId)
|
||
|
|
}
|
||
|
|
gormDb = gormDb.Where("duties.state IN ?", []int{1, 2})
|
||
|
|
var total int64
|
||
|
|
totalErr := gormDb.Count(&total).Error
|
||
|
|
if totalErr != nil {
|
||
|
|
total = 0
|
||
|
|
}
|
||
|
|
errGorm := gormDb.Limit(requestData.PageSize).Offset(overallhandle.LimitPage(requestData.Page, requestData.PageSize)).Find(&dutiesList).Error
|
||
|
|
if errGorm != nil {
|
||
|
|
overallhandle.Result(105, errGorm, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(dutiesList)), dutiesList, c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//添加职务
|
||
|
|
func (o *OrganizationApi) AddDutiesCont(c *gin.Context) {
|
||
|
|
var requestData addDutiesInfo
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
overallhandle.Result(100, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.Name == "" {
|
||
|
|
overallhandle.Result(101, err, c, "职务名称为空!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.JobType == "" {
|
||
|
|
overallhandle.Result(101, err, c, "请指定归属职务类型!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.Weight == 0 {
|
||
|
|
requestData.Weight = 1
|
||
|
|
}
|
||
|
|
var name string
|
||
|
|
judgeErr := overall.CONSTANT_DB_HR.Model(&models.Duties{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
|
||
|
|
if judgeErr == nil {
|
||
|
|
overallhandle.Result(103, name, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
var saveData models.Duties
|
||
|
|
saveData.Name = requestData.Name
|
||
|
|
jobTypeId, _ := strconv.ParseInt(requestData.JobType, 10, 64)
|
||
|
|
saveData.JobType = jobTypeId
|
||
|
|
saveData.Weight = requestData.Weight
|
||
|
|
saveData.Time = time.Now().Unix()
|
||
|
|
saveData.State = 1
|
||
|
|
if requestData.Number == "" {
|
||
|
|
requestData.Number = getDutiesNumber()
|
||
|
|
}
|
||
|
|
saveData.Number = requestData.Number
|
||
|
|
saveErr := overall.CONSTANT_DB_HR.Create(&saveData).Error
|
||
|
|
if saveErr == nil {
|
||
|
|
overallhandle.Result(0, saveData, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(104, saveErr, c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取职务编号
|
||
|
|
func getDutiesNumber() (number string) {
|
||
|
|
var countId int64
|
||
|
|
overall.CONSTANT_DB_HR.Model(&models.Duties{}).Select("`id`").Pluck("COALESCE(COUNT(`id`), 0) as countid", &countId)
|
||
|
|
versioNum := "0001"
|
||
|
|
if countId != 0 {
|
||
|
|
countId++
|
||
|
|
// chuShu := 10000
|
||
|
|
// if countId > 9999 {
|
||
|
|
// chuShu = 100000000
|
||
|
|
// }
|
||
|
|
// versioNumStr := strconv.FormatFloat(countId/float64(chuShu), 'f', -1, 64)
|
||
|
|
// versioNumAry := strings.Split(versioNumStr, ".")
|
||
|
|
// if len(versioNumAry) == 2 {
|
||
|
|
// versioNum = versioNumAry[1]
|
||
|
|
// }
|
||
|
|
if countId > 9999 {
|
||
|
|
versioNum = overallhandle.ZeroFillByStr(strconv.FormatInt(countId, 10), 8, true)
|
||
|
|
} else {
|
||
|
|
versioNum = overallhandle.ZeroFillByStr(strconv.FormatInt(countId, 10), 4, true)
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
number = fmt.Sprintf("ZW%v%v", overallhandle.UnixTimeToDay(time.Now().Unix(), 20), versioNum)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
//获取职务详情
|
||
|
|
func (o *OrganizationApi) GetDutiesCont(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 duriesCont dutiesOutCont
|
||
|
|
dbErr := overall.CONSTANT_DB_HR.Select("duties.*,job_class.name as classname").Where("duties.id = ?", requestData.Id).Joins("left join job_class on job_class.id = duties.job_type").First(&duriesCont).Error
|
||
|
|
if dbErr != nil {
|
||
|
|
overallhandle.Result(105, dbErr, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(0, duriesCont, c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//修改职务
|
||
|
|
func (o *OrganizationApi) EiteDutiesInfo(c *gin.Context) {
|
||
|
|
var requestData eiteDutiesCont
|
||
|
|
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
|
||
|
|
}
|
||
|
|
whereData := overallhandle.MapOut()
|
||
|
|
whereData["id"] = requestData.Id
|
||
|
|
//判断职务是否存在
|
||
|
|
var dutiesInfo models.Duties
|
||
|
|
judgeErr := overall.CONSTANT_DB_HR.Where(whereData).First(&dutiesInfo).Error
|
||
|
|
if judgeErr != nil {
|
||
|
|
overallhandle.Result(107, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
saveData := overallhandle.MapOut()
|
||
|
|
saveData["time"] = time.Now().Unix()
|
||
|
|
if requestData.Name != "" && requestData.Name != dutiesInfo.Name {
|
||
|
|
var name string
|
||
|
|
judgeErr := overall.CONSTANT_DB_HR.Model(&models.Duties{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
|
||
|
|
if judgeErr == nil {
|
||
|
|
overallhandle.Result(103, name, c, name)
|
||
|
|
return
|
||
|
|
} else {
|
||
|
|
saveData["name"] = requestData.Name
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if requestData.JobType != "" {
|
||
|
|
saveData["job_type"] = requestData.JobType
|
||
|
|
}
|
||
|
|
if requestData.Weight != 0 {
|
||
|
|
saveData["weight"] = requestData.Weight
|
||
|
|
}
|
||
|
|
saveDataErr := dutiesInfo.EiteCont(whereData, saveData)
|
||
|
|
if saveDataErr == nil {
|
||
|
|
overallhandle.Result(0, saveData, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(106, saveDataErr, c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//编辑状态或删除
|
||
|
|
func (o *OrganizationApi) EiteDutiesStatOrDel(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
|
||
|
|
}
|
||
|
|
whereMap := overallhandle.MapOut()
|
||
|
|
whereMap["id"] = requestData.Id
|
||
|
|
var joInfo models.Duties
|
||
|
|
//判断职务类型是否存在
|
||
|
|
judgeExist := overall.CONSTANT_DB_HR.Where(whereMap).First(&joInfo).Error
|
||
|
|
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 := joInfo.EiteCont(whereMap, saveData)
|
||
|
|
if eiteErr != nil {
|
||
|
|
overallhandle.Result(106, eiteErr, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(0, saveData, c)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if requestData.IsTrue != 1 {
|
||
|
|
//软删除
|
||
|
|
eiteErr := joInfo.EiteCont(whereMap, saveData)
|
||
|
|
if eiteErr != nil {
|
||
|
|
overallhandle.Result(106, eiteErr, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(0, saveData, c)
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
//硬删除
|
||
|
|
delErr := overall.CONSTANT_DB_HR.Where(whereMap).Delete(&joInfo)
|
||
|
|
if delErr == nil {
|
||
|
|
overallhandle.Result(0, saveData, c)
|
||
|
|
} else {
|
||
|
|
overallhandle.Result(108, delErr, c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|