Browse Source

hr系统初始化

master
超级管理员 4 years ago
commit
5af29cb9f1
  1. 40
      README.md
  2. 256
      api/version1/administrativeorganization/duties.go
  3. 217
      api/version1/administrativeorganization/gov_class.go
  4. 265
      api/version1/administrativeorganization/govcont.go
  5. 209
      api/version1/administrativeorganization/job_class.go
  6. 321
      api/version1/administrativeorganization/position.go
  7. 165
      api/version1/administrativeorganization/type.go
  8. 9
      api/version1/inlet.go
  9. 11
      apirouter/inlet.go
  10. BIN
      apirouter/organization/__debug_bin.exe
  11. 47
      apirouter/organization/organization_group.go
  12. 4
      apirouter/organization/type.go
  13. 6
      config/configApp/appConfig.yaml
  14. 13
      config/configApp/server.go
  15. 71
      config/configDatabase/database.go
  16. 41
      config/configDatabase/database.yaml
  17. 37
      config/configNosql/redis.go
  18. 41
      config/configNosql/redis.yaml
  19. 48
      go.mod
  20. 163
      go.sum
  21. BIN
      hr_server.exe
  22. 19
      initialization/app/init_server.go
  23. 27
      initialization/app/run.go
  24. 33
      initialization/databaseinit/mysql.go
  25. 48
      initialization/init_viper.go
  26. 15
      initialization/nosql/redis.go
  27. 32
      initialization/route/route_entry.go
  28. 15
      main.go
  29. 26
      middleware/cross_domain.go
  30. 47
      models/administrative_organization.go
  31. 37
      models/administrative_organization_type.go
  32. 24
      models/duties.go
  33. 21
      models/job_class.go
  34. 48
      models/position.go
  35. 25
      overall/app_config_const.go
  36. 8
      overall/app_constant.go
  37. 11
      overall/database.go
  38. 13
      overall/overallhandle/errorcode.go
  39. 41
      overall/overallhandle/format_output.go
  40. 265
      overall/overallhandle/overall_handle.go
  41. 37
      overall/overallhandle/type.go

40
README.md

@ -0,0 +1,40 @@
## Hr Server项目结构
```Project
|—— api
| └── version1
|—— router
|—— initialization
| └── database
| └── nosql
| └── app
| └── route
|—— config
| └── database
| └── nosql
| └── app
|—— models
|—— overall
|—— middleware
```
## Hr 文件结构说明
| 文件夹 | 说明 | 描述|
|--------- |------ |-----|
| `api` | api相关业务 | api业务实现 |
| `--version1` | 业务版本文件夹 | 版本界定 |
| `router` | 路由器 | 业务路由设定 |
| `initialization` | 初始化相关业务 | 系统初始化方面的实现 |
| `--database` | 数据库业务 | 数据库业务初始化实现 |
| `--nosql` | nosql数据库业务 | nosql业务初始化实现(例:Redis) |
| `--app` | app数据库业务 | app业务初始化实现 |
| `--route` | 路由初始化 | 路由初始化 |
| `config` | 系统配置相关业务 | 系统系统配置方面的实现 |
| `--database` | 数据库业务 | 数据库业务系统配置实现 |
| `--nosql` | nosql数据库业务 | nosql业务系统配置实现(例:Redis) |
| `--app` | app数据库业务 | app业务系统配置实现 |
| `models` | 数据模型 | 数据库方面的配置 |
| `overall` | 全局对象 | 全局对象|
| `middleware` | 中间件 | 中间件 |
## Log

256
api/version1/administrativeorganization/duties.go

@ -0,0 +1,256 @@
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)
}
}
}
}

217
api/version1/administrativeorganization/gov_class.go

@ -0,0 +1,217 @@
package administrativeorganization
import (
"hr_server/models"
"hr_server/overall"
"hr_server/overall/overallhandle"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
//行政类型
func (o *OrganizationApi) GovClassList(c *gin.Context) {
var requestData selectNameOrState
c.ShouldBindJSON(&requestData)
if requestData.Page < 0 {
requestData.Page = 1
}
if requestData.PageSize < 0 {
requestData.PageSize = 10
}
var govClassMap []models.AdministrativeOrganizationType
gormDb := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganizationType{})
if requestData.State != 0 {
gormDb = gormDb.Where("state = ?", requestData.State)
} else {
gormDb = gormDb.Where("state IN ?", []int{1, 2})
}
if requestData.Name != "" {
gormDb = gormDb.Where("name LIKE ?", "%"+requestData.Name+"%")
}
if requestData.Level != 0 {
gormDb = gormDb.Where("`level` = ?", requestData.Level)
}
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(&govClassMap).Error
if errGorm != nil {
overallhandle.Result(105, errGorm, c)
} else {
overallhandle.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(govClassMap)), govClassMap, c)
}
}
//添加行政组织类别
func (o *OrganizationApi) AddGovClass(c *gin.Context) {
var requestData addGovClassInfo
err := c.ShouldBindJSON(&requestData)
if err != nil {
overallhandle.Result(100, err, c)
return
}
if requestData.Name == "" {
overallhandle.Result(101, err, c, "行政组织类别名称为空!")
return
}
if requestData.Level == 0 {
requestData.Level = 1
}
var name string
judgeErr := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganizationType{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
if judgeErr == nil {
overallhandle.Result(103, name, c)
return
}
var saveData models.AdministrativeOrganizationType
saveData.Name = requestData.Name
saveData.Level = requestData.Level
saveData.Time = time.Now().Unix()
saveData.State = 1
saveErr := overall.CONSTANT_DB_HR.Create(&saveData).Error
if saveErr == nil {
overallhandle.Result(0, saveData, c)
} else {
overallhandle.Result(104, saveErr, c)
}
}
//获取行政组织类别详情
func (o *OrganizationApi) GetGovClassCont(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 Contents models.AdministrativeOrganizationType
dbErr := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).First(&Contents).Error
if dbErr != nil {
overallhandle.Result(105, dbErr, c)
} else {
overallhandle.Result(0, Contents, c)
}
}
//修改行政组织类别详情
func (o *OrganizationApi) EiteGovClassCont(c *gin.Context) {
var requestData eiteGovClassInfo
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
}
gormDb := overall.CONSTANT_DB_HR
var jobClassInfo models.AdministrativeOrganizationType
//判断职务类型是否存在
judgeExist := gormDb.Where("`id` = ?", requestData.Id).First(&jobClassInfo).Error
if judgeExist != nil {
overallhandle.Result(107, judgeExist, c)
return
}
saveData := overallhandle.MapOut()
saveData["time"] = time.Now().Unix()
if requestData.Name != "" {
if requestData.Name != jobClassInfo.Name {
//查询一下修改的职务名称是否已经存在
var name string
judgeErr := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganizationType{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
if judgeErr == nil {
overallhandle.Result(103, name, c)
return
}
saveData["name"] = requestData.Name
}
}
if requestData.Level != 0 {
saveData["level"] = requestData.Level
}
whereMap := overallhandle.MapOut()
whereMap["id"] = requestData.Id
eiteErr := jobClassInfo.EiteCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
}
//修改行政类别状态或删除
func (o *OrganizationApi) EiteGovClassStateOrDel(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
}
var jobClassInfo models.AdministrativeOrganizationType
//判断职务类型是否存在
judgeExist := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).First(&jobClassInfo).Error
if judgeExist != nil {
overallhandle.Result(107, judgeExist, c)
return
}
saveData := overallhandle.MapOut()
saveData["time"] = time.Now().Unix()
saveData["state"] = requestData.State
whereMap := overallhandle.MapOut()
whereMap["id"] = requestData.Id
if requestData.State != 3 {
eiteErr := jobClassInfo.EiteCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
} else {
if requestData.IsTrue != 1 {
//软删除
eiteErr := jobClassInfo.EiteCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
} else {
//硬删除
delErr := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).Delete(&jobClassInfo)
if delErr == nil {
overallhandle.Result(0, saveData, c)
} else {
overallhandle.Result(108, delErr, c)
}
}
}
}

265
api/version1/administrativeorganization/govcont.go

@ -0,0 +1,265 @@
package administrativeorganization
import (
"hr_server/models"
"hr_server/overall"
"hr_server/overall/overallhandle"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
//行政组织
func (o *OrganizationApi) GovList(c *gin.Context) {
var requestData govListType
c.ShouldBindJSON(&requestData)
if requestData.Page < 0 {
requestData.Page = 1
}
if requestData.PageSize < 0 {
requestData.PageSize = 10
}
var govClassMap []outGovCont
gormDb := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("administrative_organization.*,aot.name as classname,aot.level").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type")
if requestData.State != 0 {
gormDb = gormDb.Where("administrative_organization.state = ?", requestData.State)
} else {
gormDb = gormDb.Where("administrative_organization.state IN ?", []int{1, 2})
}
if requestData.Name != "" {
gormDb = gormDb.Where("(administrative_organization.name LIKE ? OR administrative_organization.abbreviation LIKE ?)", "%"+requestData.Name+"%", "%"+requestData.Name+"%")
}
if requestData.Number != "" {
gormDb = gormDb.Where("administrative_organization.number LIKE ?", "%"+requestData.Number+"%")
}
if requestData.Level != 0 {
gormDb = gormDb.Where("aot.level = ?", requestData.Level)
}
if requestData.GovClass != "" {
gormDb = gormDb.Where("administrative_organization.organization_type = ?", requestData.GovClass)
}
if requestData.Superior != "" {
gormDb = gormDb.Where("administrative_organization.superior = ?", requestData.Superior)
}
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(&govClassMap).Error
if errGorm != nil {
overallhandle.Result(105, errGorm, c)
} else {
overallhandle.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(govClassMap)), govClassMap, c)
}
}
//添加行政组织
func (o *OrganizationApi) AddGovCont(c *gin.Context) {
var requestData addGovInfo
err := c.ShouldBindJSON(&requestData)
if err != nil {
overallhandle.Result(100, err, c)
return
}
if requestData.Name == "" {
overallhandle.Result(101, requestData.Name, c, "行政组织名称为空!")
return
}
var superiorId int64 = 0
if requestData.Superior != "" {
superiorInt, _ := strconv.ParseInt(requestData.Superior, 10, 64)
superiorId = superiorInt
} else {
overallhandle.Result(101, requestData.Superior, c, "请指定归属上级!")
return
}
var govClassId int64 = 0
if requestData.GovClass == "" {
overallhandle.Result(101, requestData.GovClass, c, "请指定归属行政组织类型!")
return
} else {
govClassIdInt, _ := strconv.ParseInt(requestData.GovClass, 10, 64)
govClassId = govClassIdInt
}
if requestData.WechatId == 0 {
requestData.WechatId = 1
}
var name string
judgeErr := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`name`").Where("`organization_type` IN ? AND `name` = ?", []int{1, 2}, requestData.Name).First(&name).Error
if judgeErr == nil {
overallhandle.Result(103, name, c)
return
}
var saveData models.AdministrativeOrganization
saveData.Name = requestData.Name
saveData.Superior = superiorId
saveData.OrganizationType = govClassId
saveData.Abbreviation = requestData.Abbreviation
saveData.Time = time.Now().Unix()
saveData.State = 1
saveData.WechatOrganizationId = int64(requestData.WechatId)
if requestData.Number != "" {
saveData.Number = requestData.Number
} else {
//获取首字母
govFirstWords := overallhandle.GetGovFirstWords(requestData.Name, requestData.Abbreviation, requestData.GovClass, requestData.Superior)
saveData.Number = overallhandle.CreateNumber(govFirstWords, requestData.Superior)
}
saveErr := overall.CONSTANT_DB_HR.Create(&saveData).Error
if saveErr == nil {
overallhandle.Result(0, saveData, c)
} else {
overallhandle.Result(104, saveErr, c)
}
}
//获取行政组织详情
func (o *OrganizationApi) GetGovCont(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
}
whereAry := overallhandle.MapOut()
whereAry["id"] = requestData.Id
var Contents models.AdministrativeOrganization
dbErr := Contents.GetCont(whereAry)
// dbErr := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).First(&Contents).Error
if dbErr != nil {
overallhandle.Result(105, dbErr, c)
} else {
overallhandle.Result(0, Contents, c)
}
}
//编辑行政组织
func (o *OrganizationApi) EiteGovCont(c *gin.Context) {
var requestData eiteGovInfo
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.AdministrativeOrganization
judgeErr := govCont.GetCont(whereAry)
if judgeErr != nil {
overallhandle.Result(107, judgeErr, c)
return
}
saveData := overallhandle.MapOut()
saveData["time"] = time.Now().Unix()
if requestData.Name != "" && requestData.Name != govCont.Name {
saveData["name"] = requestData.Name
}
if requestData.Superior != "" && requestData.Superior != strconv.FormatInt(govCont.Superior, 10) {
saveData["superior"] = requestData.Superior
}
if requestData.GovClass != "" && requestData.GovClass != strconv.FormatInt(govCont.OrganizationType, 10) {
saveData["organization_type"] = requestData.GovClass
}
if requestData.Abbreviation != "" && requestData.Abbreviation != govCont.Abbreviation {
saveData["abbreviation"] = requestData.Abbreviation
}
if requestData.WechatId != 0 && int64(requestData.WechatId) != govCont.WechatOrganizationId {
saveData["wechat_organization_id"] = requestData.WechatId
}
if requestData.Number != "" && requestData.Number != govCont.Number {
if requestData.Superior != "" && requestData.Superior != strconv.FormatInt(govCont.Superior, 10) {
//获取首字母
govFirstWords := overallhandle.GetGovFirstWords(requestData.Name, requestData.Abbreviation, requestData.GovClass, requestData.Superior)
saveData["number"] = overallhandle.CreateNumber(govFirstWords, requestData.Superior)
} else if requestData.Superior != "" {
saveData["number"] = requestData.Number
}
}
eiteErr := govCont.EiteCont(whereAry, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
}
//编辑行政组织状态或删除
func (o *OrganizationApi) EiteGovStateOrDel(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.AdministrativeOrganization
//判断行政组织是否存在
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)
}
}
}
}

209
api/version1/administrativeorganization/job_class.go

@ -0,0 +1,209 @@
package administrativeorganization
import (
"hr_server/models"
"hr_server/overall"
"hr_server/overall/overallhandle"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
//职务分类列表
func (o *OrganizationApi) DutiesClassList(c *gin.Context) {
var requestData JobClassPageSelect
c.ShouldBindJSON(&requestData)
if requestData.Page < 0 {
requestData.Page = 1
}
if requestData.PageSize < 0 {
requestData.PageSize = 10
}
var jobClassList []models.JobClass
gormDb := overall.CONSTANT_DB_HR.Model(&models.JobClass{})
if requestData.Name != "" {
// nameFactor := fmt.Sprintf("%%v%")
gormDb = gormDb.Where("`name` LIKE ?", "%"+requestData.Name+"%")
}
gormDb = gormDb.Where("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(&jobClassList).Error
if errGorm != nil {
overallhandle.Result(105, errGorm, c)
} else {
// overallhandle.Result(0, jobClassList, c)
overallhandle.ResultList(0, requestData.Page, requestData.PageSize, total, int64(len(jobClassList)), jobClassList, c)
}
}
//添加职务分类
func (o *OrganizationApi) AddDutiesClass(c *gin.Context) {
var requestData NameVal
err := c.ShouldBindJSON(&requestData)
if err != nil {
overallhandle.Result(100, err, c)
return
}
if requestData.Name == "" {
overallhandle.Result(101, err, c, "职务分类名称为空!")
return
}
//判断该职务分类是否已经存在
var name string
judgeErr := overall.CONSTANT_DB_HR.Model(&models.JobClass{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
if judgeErr == nil {
overallhandle.Result(103, name, c)
return
}
var jobClassCont models.JobClass
jobClassCont.Name = requestData.Name
jobClassCont.Time = time.Now().Unix()
jobClassCont.State = 1
addDataErr := overall.CONSTANT_DB_HR.Create(&jobClassCont).Error
if addDataErr != nil {
overallhandle.Result(104, addDataErr, c)
} else {
overallhandle.Result(0, jobClassCont, c)
}
}
//查看职务分类详情
func (o *OrganizationApi) GetDutiesClassInfo(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 jobClassCont models.JobClass
dbErr := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).First(&jobClassCont).Error
if dbErr != nil {
overallhandle.Result(105, dbErr, c)
} else {
overallhandle.Result(0, jobClassCont, c)
}
}
//修改职务分类详情
func (o *OrganizationApi) EiteDutiesClassInfo(c *gin.Context) {
var requestData EiteJobClassInfo
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
}
gormDb := overall.CONSTANT_DB_HR
var jobClassInfo models.JobClass
//判断职务类型是否存在
judgeExist := gormDb.Where("`id` = ?", requestData.Id).First(&jobClassInfo).Error
if judgeExist != nil {
overallhandle.Result(107, judgeExist, c)
return
}
saveData := overallhandle.MapOut()
saveData["time"] = time.Now().Unix()
if requestData.Name != "" {
if requestData.Name != jobClassInfo.Name {
//查询一下修改的职务名称是否已经存在
var name string
judgeErr := overall.CONSTANT_DB_HR.Model(&models.JobClass{}).Select("`name`").Where("`name` = ?", requestData.Name).First(&name).Error
if judgeErr == nil {
overallhandle.Result(103, name, c)
return
}
saveData["name"] = requestData.Name
}
}
if requestData.State != 0 {
saveData["state"] = requestData.State
}
whereMap := overallhandle.MapOut()
whereMap["id"] = requestData.Id
eiteErr := jobClassInfo.EiteJobClassCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
}
//删除职务分类
func (o *OrganizationApi) DelDutiesClassInfo(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
}
var jobClassInfo models.JobClass
//判断职务类型是否存在
judgeExist := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).First(&jobClassInfo).Error
if judgeExist != nil {
overallhandle.Result(107, judgeExist, c)
return
}
saveData := overallhandle.MapOut()
saveData["time"] = time.Now().Unix()
saveData["state"] = requestData.State
whereMap := overallhandle.MapOut()
whereMap["id"] = requestData.Id
if requestData.State != 3 {
eiteErr := jobClassInfo.EiteJobClassCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
} else {
if requestData.IsTrue != 1 {
//软删除
eiteErr := jobClassInfo.EiteJobClassCont(whereMap, saveData)
if eiteErr != nil {
overallhandle.Result(106, eiteErr, c)
} else {
overallhandle.Result(0, saveData, c)
}
} else {
//硬删除
delErr := overall.CONSTANT_DB_HR.Where("`id` = ?", requestData.Id).Delete(&jobClassInfo)
if delErr == nil {
overallhandle.Result(0, saveData, c)
} else {
overallhandle.Result(108, delErr, c)
}
}
}
}

321
api/version1/administrativeorganization/position.go

@ -0,0 +1,321 @@
package administrativeorganization
import (
"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 = ?", requestData.Number)
}
if requestData.Duties != "" {
gormDb = gormDb.Where("p.duties = ?", requestData.Duties)
}
if requestData.Organization != "" {
gormDb = gormDb.Where("p.administrative_organization = ?", requestData.Organization)
}
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.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
}
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
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
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)
}
}
}
}

165
api/version1/administrativeorganization/type.go

@ -0,0 +1,165 @@
package administrativeorganization
import (
"hr_server/models"
"hr_server/overall/overallhandle"
"github.com/gin-gonic/gin"
)
type OrganizationApi struct{}
//入口
func (o *OrganizationApi) Index(c *gin.Context) {
outputCont := overallhandle.MapOut()
overallhandle.Result(0, outputCont, c)
}
//名称
type NameVal struct {
Name string `json:"name"` //名称
}
//职务类型翻页
type JobClassPageSelect struct {
overallhandle.PageTurning
NameVal
}
//修改职务类型信息
type EiteJobClassInfo struct {
overallhandle.GetId
NameVal
overallhandle.StateOverall
}
//状态修改及删除操作
type EiteJobStateDel struct {
overallhandle.GetId
overallhandle.StateOverall
IsTrue int `json:"istrue"`
}
//获取职务列表
type dutiesListType struct {
JobClassPageSelect
JobId string `json:"jobid"`
}
//职务输出
type dutiesOutCont struct {
models.Duties
DutiesClassName string `json:"dutiesclassname" gorm:"column:classname;type:varchar(255) unsigned;default:'';not null;comment:职务分类名称"`
}
//添加职务
type addDutiesInfo struct {
NameVal
JobType string `json:"jobtype"` //归属职务类型
Weight int64 `json:weight` //权重
overallhandle.NmuberOverall
}
//职务详情输出
type getDutiesInfo struct {
dutiesOutCont
}
//修改职务详情
type eiteDutiesCont struct {
overallhandle.GetId
NameVal
JobType string `json:"jobtype"` //归属职务类型
Weight int64 `json:weight` //权重
}
//查询名称和状态
type selectNameOrState struct {
JobClassPageSelect
overallhandle.StateOverall
Level int `json:"level"`
}
//添加行政类型
type addGovClassInfo struct {
NameVal
Level int64 `json:"level"`
}
//修改行政类型内容
type eiteGovClassInfo struct {
overallhandle.GetId
addGovClassInfo
}
//获取行政组织列表
type govListType struct {
JobClassPageSelect
Number string `json:"number"`
Superior string `json:"superior"`
GovClass string `json:"govclass"`
overallhandle.StateOverall
Level int `json:"level"`
}
//输出行政组织信息
type outGovCont struct {
models.AdministrativeOrganization
ClassName string `json:"classname" gorm:"column:classname;type:varchar(255) unsigned;default:'';not null;comment:行政组织分类名称"`
Level int64 `json:"level" gorm:"column:level;type:int(5) unsigned;default:1;not null;comment:级别"`
}
//添加行政组织
type addGovInfo struct {
NameVal
Number string `json:"number"`
Superior string `json:"superior"`
GovClass string `json:"govclass"`
Abbreviation string `json:"abbreviation"`
WechatId int `json:"wechatid"`
}
//修改行政组织
type eiteGovInfo struct {
overallhandle.GetId
addGovInfo
}
//添加职位(岗位)
type addPositionInfo struct {
Number string `json:"number"` //职位编码
NameVal //职位名称
Duties string `json:"duties"` //职务
Organization string `json:"organization"` //归属行政组织
Superior string `json:"superior"` //上级
InCharge int `json:"incharge"` //是否为本部门负责人(1:是;2:否)
Department string `json:"department"` //部门
}
//编辑职位(岗位)
type eitePositionInfo struct {
overallhandle.GetId
addPositionInfo
}
//查看职位
type lookPositionList struct {
JobClassPageSelect
Number string `json:"number"` //职位编码
Duties string `json:"duties"` //职务
Organization string `json:"organization"` //归属行政组织
InCharge int `json:"incharge"` //是否为本部门负责人(1:是;2:否)
Department string `json:"department"` //部门
}
//职务列表输出
type positionOutInfo struct {
models.Position
DutiesName string `json:"dutiesname" gorm:"column:dutiesname;type:varchar(255) unsigned;default:'';not null;comment:职务名称"`
DutiesNumber string `json:"dutiesnumber" gorm:"column:dutiesnumber;type:varchar(255) unsigned;default:'';not null;comment:职务编号"`
AoName string `json:"aoname" gorm:"column:aoname;type:varchar(255) unsigned;default:'';not null;comment:组织名称"`
AoNumber string `json:"aonumber" gorm:"column:aonumber;type:varchar(50) unsigned;default:'';not null;comment:行政编码"`
JobName string `json:"jobname" gorm:"column:jobname;type:varchar(255) unsigned;default:'';not null;comment:职务类型"`
SuperiorName string `json:"superiorname"` //上级名称
SuperiorNumber string `json:"superiornumber"` //上级编号
}

9
api/version1/inlet.go

@ -0,0 +1,9 @@
package version1
import "hr_server/api/version1/administrativeorganization"
type ApiInlet struct {
OrganizationApi administrativeorganization.OrganizationApi
}
var AppApiInlet = new(ApiInlet)

11
apirouter/inlet.go

@ -0,0 +1,11 @@
package apirouter
import "hr_server/apirouter/organization"
//路由入口
type RouterGroup struct {
OrganizationApi organization.OrganizationRoute //组织架构
}
var RouterGroupInlet = new(RouterGroup)

BIN
apirouter/organization/__debug_bin.exe

Binary file not shown.

47
apirouter/organization/organization_group.go

@ -0,0 +1,47 @@
package organization
import (
"hr_server/api/version1"
"github.com/gin-gonic/gin"
)
//组织架构
func (o *OrganizationRoute) InitRouterGroup(route *gin.RouterGroup) {
apiRouter := route.Group("org")
var apiHandle = version1.AppApiInlet.OrganizationApi
{
apiRouter.GET("", apiHandle.Index) //入口
apiRouter.POST("", apiHandle.Index) //入口
//职务分类路由
apiRouter.POST("adddutiesclass", apiHandle.AddDutiesClass) //添加职务分类
apiRouter.POST("utiesclasslist", apiHandle.DutiesClassList) //职务分类列表
apiRouter.POST("getutiesclassinfo", apiHandle.GetDutiesClassInfo) //获取职务分类详情
apiRouter.POST("eiteutiesclassinfo", apiHandle.EiteDutiesClassInfo) //修改职务分类详情
apiRouter.POST("delutiesclassinfo", apiHandle.DelDutiesClassInfo) //删除职务分类
//职务路由
apiRouter.POST("dutieslist", apiHandle.DutiesList) //职务列表
apiRouter.POST("getdutiescont", apiHandle.GetDutiesCont) //获取职务详情
apiRouter.POST("adddutiescont", apiHandle.AddDutiesCont) //添加职务
apiRouter.POST("eitedutiescont", apiHandle.EiteDutiesInfo) //编辑职务
apiRouter.POST("eitedutiesstatordel", apiHandle.EiteDutiesStatOrDel) //编辑职务状态或删除
//行政组织类型
apiRouter.POST("govclasslist", apiHandle.GovClassList) //行政组织类型列表
apiRouter.POST("getgovclasscont", apiHandle.GetGovClassCont) //获取行政组织类型
apiRouter.POST("addgovclass", apiHandle.AddGovClass) //添加行政组织类型
apiRouter.POST("eitegovclasscont", apiHandle.EiteGovClassCont) //编辑行政组织类型
apiRouter.POST("eitegovclassstateordel", apiHandle.EiteGovClassStateOrDel) //编辑行政组织类型状态或删除
//行政组织
apiRouter.POST("govlist", apiHandle.GovList) //行政组织列表
apiRouter.POST("getgovcont", apiHandle.GetGovCont) //获取行政组织
apiRouter.POST("addgovcont", apiHandle.AddGovCont) //添加行政组织
apiRouter.POST("eitegovcont", apiHandle.EiteGovCont) //编辑行政组织
apiRouter.POST("eitegovstateordel", apiHandle.EiteGovStateOrDel) //编辑行政组织状态或删除
//职位(岗位)
apiRouter.POST("positionlist", apiHandle.PositionList) //职位(岗位)列表
apiRouter.POST("getpositioncont", apiHandle.GetPositionCont) //获取职位(岗位)
apiRouter.POST("addpositioncont", apiHandle.AddPositionCont) //添加职位(岗位)
apiRouter.POST("eitepositioncont", apiHandle.EitePositionCont) //编辑职位(岗位)
apiRouter.POST("eitepositionstateordel", apiHandle.EitePositionStateOrDel) //编辑职位(岗位)状态或删除
}
}

4
apirouter/organization/type.go

@ -0,0 +1,4 @@
package organization
//组织架构接口
type OrganizationRoute struct{}

6
config/configApp/appConfig.yaml

@ -0,0 +1,6 @@
#App主配置
appsetup:
port: 9999 #服务端口
readtime: 3600 #请求的读取操作在超时前的最大持续时间
writetime : 3600 #回复的写入操作在超时前的最大持续时间

13
config/configApp/server.go

@ -0,0 +1,13 @@
package configApp
//服务基础配置
type Server struct {
Appsetup appsetup `mapstructure:"appsetup" json:"appsetup" yaml:"appsetup"`
}
//服务配置详情
type appsetup struct {
Port int `mapstructure:"port" json:"port" yaml:"port"`
Readtime int `mapstructure:"readtime" json:"readtime" yaml:"readtime"`
Writetime int `mapstructure:"writetime" json:"writetime" yaml:"writetime"`
}

71
config/configDatabase/database.go

@ -0,0 +1,71 @@
package configDatabase
import (
"fmt"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type MysqlSetUp struct {
MasterMysql MasterMysqlSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库
//其他数据库依次添加
WechatMysql MasterMysqlSetUp `mapstructure:"wechat" json:"wechat" yaml:"wechat"` //微信数据库
HrMysql MasterMysqlSetUp `mapstructure:"hrdatabase" json:"hrdatabase" yaml:"hrdatabase"` //HR数据库
}
type MasterMysqlSetUp struct {
UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
Charset string `mapstructure:"charset" json:"charset" yaml:"charset"` // 编码方式
ParseTime bool `mapstructure:"parseTime" json:"parseTime" yaml:"parseTime"` // 是否自动转换时间
Loc string `mapstructure:"loc" json:"loc" yaml:"loc"` // 时区
Name string `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称
UserName string `mapstructure:"username" json:"username" yaml:"username"` // 账号
PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码
MaxIdleConns int `mapstructure:"max_idle_conns" json:"max_idle_conns" yaml:"max_idle_conns"` // 最大空闲数
MaxOpenConns int `mapstructure:"max_open_conns" json:"max_open_conns" yaml:"max_open_conns"` // 最大链接数
GormLog bool `mapstructure:"gorm_log" json:"gorm_log" yaml:"gorm_log"` // 是否开启Gorm全局日志
}
func (m *MasterMysqlSetUp) SqlDsn() (dsnStr string) {
dsnStr = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v", m.UserName, m.PassWord, m.UrlPath, m.Port, m.Name, m.Charset)
if m.ParseTime == true {
dsnStr = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v&parseTime=%v&loc=%v", m.UserName, m.PassWord, m.UrlPath, m.Port, m.Name, m.Charset, m.ParseTime, m.Loc)
}
return
}
func (m *MasterMysqlSetUp) OpenSql() *gorm.DB {
sqlConfig := mysql.Config{
DSN: m.SqlDsn(), // DSN
DefaultStringSize: 255, // string 类型字段的默认长度
DisableDatetimePrecision: true, // 禁用 datetime 精度,MySQL 5.6 之前的数据库不支持
DontSupportRenameIndex: true, // 重命名索引时采用删除并新建的方式,MySQL 5.7 之前的数据库和 MariaDB 不支持重命名索引
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
SkipInitializeWithVersion: false, // 根据版本自动配置
}
if m.GormLog == true {
if opDb, err := gorm.Open(mysql.New(sqlConfig), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
}); err != nil {
return nil
} else {
sqlDb, _ := opDb.DB()
sqlDb.SetMaxIdleConns(m.MaxIdleConns)
sqlDb.SetMaxOpenConns(m.MaxOpenConns)
return opDb
}
} else {
if opDb, err := gorm.Open(mysql.New(sqlConfig)); err != nil {
return nil
} else {
sqlDb, _ := opDb.DB()
sqlDb.SetMaxIdleConns(m.MaxIdleConns)
sqlDb.SetMaxOpenConns(m.MaxOpenConns)
return opDb
}
}
}

41
config/configDatabase/database.yaml

@ -0,0 +1,41 @@
#数据库配置
#主数据库
master:
url_path: '127.0.0.1' #数据库地址
port: 3306 #数据库端口
charset: 'utf8mb4' #数据库编码方式
parseTime: 'True' #是否自动转换时间
loc: 'Local' #时区
name: 'hengxingaoke_tes' #数据库名称
username: 'root' #数据库用户民
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量
max_open_conns: 1500 #最大打开数量
gorm_log: false #是否开启gorm日志
#微信数据库
wechat:
url_path: '127.0.0.1' #数据库地址
port: 3306 #数据库端口
charset: 'utf8mb4' #数据库编码方式
parseTime: 'True' #是否自动转换时间
loc: 'Local' #时区
name: 'wechatuser' #数据库名称
username: 'root' #数据库用户民
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量
max_open_conns: 1500 #最大打开数量
gorm_log: false #是否开启gorm日志
#HR数据库
hrdatabase:
url_path: '127.0.0.1' #数据库地址
port: 3306 #数据库端口
charset: 'utf8mb4' #数据库编码方式
parseTime: 'True' #是否自动转换时间
loc: 'Local' #时区
name: 'human_resources' #数据库名称
username: 'root' #数据库用户民
password: 'root' #数据库密码
max_idle_conns: 100 #最大空闲数量
max_open_conns: 1500 #最大打开数量
gorm_log: true #是否开启gorm日志

37
config/configNosql/redis.go

@ -0,0 +1,37 @@
package confignosql
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
)
type RedisSetUp struct {
MasterRedis RedisConfitSetUp `mapstructure:"master" json:"master" yaml:"master"` //主数据库
MasterRedis1 RedisConfitSetUp `mapstructure:"master1" json:"master1" yaml:"master1"` //主数据库
}
type RedisConfitSetUp struct {
UrlPath string `mapstructure:"url_path" json:"url_path" yaml:"url_path"` // 服务器地址
Port int `mapstructure:"port" json:"port" yaml:"port"` // 端口
Name int `mapstructure:"name" json:"name" yaml:"name"` // 数据库名称
PassWord string `mapstructure:"password" json:"password" yaml:"password"` // 密码
}
func (r *RedisConfitSetUp) OpenRedis() *redis.Client {
address := fmt.Sprintf("%v:%v", r.UrlPath, r.Port)
fmt.Printf("开启%v Redis库 %v\n", address, r.Name)
redisClient := redis.NewClient(&redis.Options{
Addr: address,
Password: r.PassWord,
DB: r.Name,
})
pingLink, err := redisClient.Ping(context.Background()).Result()
if err != nil {
fmt.Printf("%v Redis链接失败!原因:%v\n", r.Name, err)
} else {
fmt.Printf("%v Redis链接成功!=====>%v\n", r.Name, pingLink)
}
return redisClient
}

41
config/configNosql/redis.yaml

@ -0,0 +1,41 @@
#Redis配置文件
master:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 0
#Redis配置文件
master1:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 1
#Redis配置文件
master2:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 2
#Redis配置文件
master3:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 3
#Redis配置文件
master4:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 4
#Redis配置文件
master5:
url_path: '127.0.0.1'
port: 6379 #数据库端口
password: ""
name: 5

48
go.mod

@ -0,0 +1,48 @@
module hr_server
go 1.18
require (
github.com/fsnotify/fsnotify v1.5.1
github.com/gin-gonic/gin v1.7.7
github.com/go-redis/redis/v8 v8.11.5
github.com/mozillazg/go-pinyin v0.19.0
github.com/spf13/viper v1.10.1
gorm.io/driver/mysql v1.3.3
gorm.io/gorm v1.23.4
)
require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.1 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

163
go.sum

@ -0,0 +1,163 @@
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.10.1 h1:uA0+amWMiglNZKZ9FJRKUAe9U3RX91eVn1JYXMWt7ig=
github.com/go-playground/validator/v10 v10.10.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mozillazg/go-pinyin v0.19.0 h1:p+J8/kjJ558KPvVGYLvqBhxf8jbZA2exSLCs2uUVN8c=
github.com/mozillazg/go-pinyin v0.19.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461 h1:kHVeDEnfKn3T238CvrUcz6KeEsFHVaKh4kMTt6Wsysg=
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.66.2 h1:XfR1dOYubytKy4Shzc2LHrrGhU0lDCfDGG1yLPmpgsI=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.3.3 h1:jXG9ANrwBc4+bMvBcSl8zCfPBaVoPyBEBshA8dA93X8=
gorm.io/driver/mysql v1.3.3/go.mod h1:ChK6AHbHgDCFZyJp0F+BmVGb06PSIoh9uVYKAlRbb2U=
gorm.io/gorm v1.23.1/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.23.4 h1:1BKWM67O6CflSLcwGQR7ccfmC4ebOxQrTfOQGRE9wjg=
gorm.io/gorm v1.23.4/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=

BIN
hr_server.exe

Binary file not shown.

19
initialization/app/init_server.go

@ -0,0 +1,19 @@
package app
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
//设置服务启动
func InitServer(port string, handler *gin.Engine) server {
return &http.Server{
Addr: port, //监听的TCP地址,如果为空字符串会使用":http"
Handler: handler, //调用的处理器,如为nil会调用http.DefaultServeMux
ReadTimeout: 3600 * time.Second, //请求的读取操作在超时前的最大持续时间
WriteTimeout: 3600 * time.Second, //回复的写入操作在超时前的最大持续时间
MaxHeaderBytes: 1 << 40, //请求的头域最大长度,如为0则用DefaultMaxHeaderBytes
}
}

27
initialization/app/run.go

@ -0,0 +1,27 @@
package app
import (
"fmt"
"hr_server/initialization"
"hr_server/initialization/route"
"hr_server/overall"
)
type server interface {
ListenAndServe() error
}
//启动服务
func RunItem() {
//加载基础配置
// var appConfig configApp.Server
initialization.RunViper(&overall.CONSTANT_CONFIG)
// fmt.Printf("----------->%v", overall.CONSTANT_CONFIG)
routers := route.InitialRouter()
portStr := fmt.Sprintf(":%d", overall.CONSTANT_CONFIG.Appsetup.Port)
startUp := InitServer(portStr, routers)
fmt.Printf("\n\n默认API运行地址:http://127.0.0.1%s\n", portStr)
runErr := startUp.ListenAndServe().Error()
panic(fmt.Errorf(runErr))
}

33
initialization/databaseinit/mysql.go

@ -0,0 +1,33 @@
package databaseinit
import (
"fmt"
"hr_server/initialization"
"hr_server/overall"
)
func LoadDatabase() {
sqlConfig := overall.CONSTANT_MYSQL
initialization.RunViper(&sqlConfig, overall.ConfigDatabaseConstant)
//开启主数据库
overall.CONSTANT_DB_Master = sqlConfig.MasterMysql.OpenSql()
if overall.CONSTANT_DB_Master == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.MasterMysql.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.MasterMysql.Name)
}
//开启微信数据库
overall.CONSTANT_DB_Wechat = sqlConfig.WechatMysql.OpenSql()
if overall.CONSTANT_DB_Master == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.WechatMysql.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.WechatMysql.Name)
}
//开启Hr数据库
overall.CONSTANT_DB_HR = sqlConfig.HrMysql.OpenSql()
if overall.CONSTANT_DB_HR == nil {
fmt.Printf("%v数据库开启失败!\n", sqlConfig.HrMysql.Name)
} else {
fmt.Printf("%v数据库开启成功!\n", sqlConfig.HrMysql.Name)
}
}

48
initialization/init_viper.go

@ -0,0 +1,48 @@
package initialization
import (
"encoding/json"
"fmt"
"hr_server/overall"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
)
//使用viper 处理包解决配置读取问题
func RunViper(configInfo interface{}, path ...string) *viper.Viper {
var config string
if len(path) == 0 {
config = overall.ConfigFilePathConstant
fmt.Printf("你正在使用系统默认值。配置路径为:%v\n", config)
} else {
config = path[0]
fmt.Printf("你正在使用RunViper传值。配置路径为:%v\n", config)
}
v := viper.New()
// 设置配置文件信息
v.SetConfigFile(config)
v.SetConfigType("yaml")
//读取配置信息
err := v.ReadInConfig()
if err != nil {
panic(fmt.Errorf("配置文件读取失败?原因:%s\n", err))
}
// 监控配置和重新获取配置
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
fmt.Printf("配置文件已经更改:%v\n", e.Name)
if errSet := v.Unmarshal(&configInfo); errSet != nil {
fmt.Printf("新配置文件解析失败!系统继续使用原配置!失败原因:%s\n", errSet)
}
})
//解析配置映射到切片
if errStruct := v.Unmarshal(&configInfo); errStruct != nil {
fmt.Printf("配置解析失败!原因:%s\n", errStruct)
}
json.Marshal(configInfo)
// cfi, _ := json.Marshal(configInfo)
// fmt.Printf("============>%v\n", string(cfi))
return v
}

15
initialization/nosql/redis.go

@ -0,0 +1,15 @@
package nosql
import (
"hr_server/initialization"
"hr_server/overall"
)
//加载Redis
func LoadRedis() {
//读取Redis配置
redisConfig := overall.CONSTANT_Redis
initialization.RunViper(&redisConfig, overall.ConfigRedisConstant)
overall.CONSTANT_REDIS0 = redisConfig.MasterRedis.OpenRedis()
overall.CONSTANT_REDIS1 = redisConfig.MasterRedis1.OpenRedis()
}

32
initialization/route/route_entry.go

@ -0,0 +1,32 @@
package route
import (
"hr_server/apirouter"
"github.com/gin-gonic/gin"
)
//初始化主路由
func InitialRouter() *gin.Engine {
var router = gin.Default()
// 跨域设置
// router.Use(middleware.CrossDomainRequest()) // 如需跨域可以打开
//app默认相应
appLoadRouterGroup := router.Group("")
{
appLoadRouterGroup.GET("/", func(c *gin.Context) {
c.JSON(0, "通讯成功!")
})
appLoadRouterGroup.POST("/test", func(c *gin.Context) {
c.JSON(0, "通讯成功!")
})
}
//注册路由
organizationApi := apirouter.RouterGroupInlet.OrganizationApi //组织架构
{
organizationApi.InitRouterGroup(appLoadRouterGroup)
}
return router
}

15
main.go

@ -0,0 +1,15 @@
package main
import (
"hr_server/initialization/app"
"hr_server/initialization/databaseinit"
"hr_server/initialization/nosql"
)
func main() {
//加载数据库
databaseinit.LoadDatabase()
//加载Redis
nosql.LoadRedis()
app.RunItem()
}

26
middleware/cross_domain.go

@ -0,0 +1,26 @@
package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
)
// 处理跨域请求,支持options访问
func CrossDomainRequest() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
origin := c.Request.Header.Get("Origin")
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
// 放行所有OPTIONS方法
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
// 处理请求
c.Next()
}
}

47
models/administrative_organization.go

@ -0,0 +1,47 @@
package models
import (
"hr_server/overall"
"strings"
)
//行政组织
type AdministrativeOrganization struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"`
Number string `json:"number" gorm:"column:number;type:varchar(50) unsigned;default:'';not null;comment:行政编码"`
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:组织名称"`
Superior int64 `json:"superior" gorm:"column:superior;type:bigint(20) unsigned;default:0;not null;comment:上级ID"`
OrganizationType int64 `json:"organizationtype" gorm:"column:organization_type;type:bigint(20) unsigned;default:0;not null;comment:行政组织类型"`
Abbreviation string `json:"abbreviation" gorm:"column:abbreviation;type:varchar(255) unsigned;default:'';not null;comment:行政组织简称"`
Time int64 `json:"time" gorm:"column:time;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:删除)"`
WechatOrganizationId int64 `json:"wechatorganizationid" gorm:"column:wechat_organization_id;type:bigint(20) unsigned;default:0;not null;comment:微信组织架构对照码"`
}
func (AdministrativeOrganization *AdministrativeOrganization) TableName() string {
return "administrative_organization"
}
//编辑行政组织内容
func (cont *AdministrativeOrganization) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) {
err = overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Updates(saveData).Error
return
}
//获取行政组织内容
func (cont *AdministrativeOrganization) GetCont(whereMap map[string]interface{}, field ...string) (err error) {
gormDb := overall.CONSTANT_DB_HR.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 *AdministrativeOrganization) CountCont(whereMap map[string]interface{}) (countId int64) {
overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Count(&countId)
return
}

37
models/administrative_organization_type.go

@ -0,0 +1,37 @@
package models
import (
"hr_server/overall"
"strings"
)
//行政组织类型
type AdministrativeOrganizationType struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"`
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:类型名称"`
Time int64 `json:"time" gorm:"column:time;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:删除)"`
Level int64 `json:"level" gorm:"column:level;type:int(5) unsigned;default:1;not null;comment:级别"`
}
func (AdministrativeOrganizationType *AdministrativeOrganizationType) TableName() string {
return "administrative_organization_type"
}
//编辑职务分类内容
func (cont *AdministrativeOrganizationType) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) {
err = overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Updates(saveData).Error
return
}
//获取详细内容
func (cont *AdministrativeOrganizationType) GetCont(whereMap map[string]interface{}, field ...string) (err error) {
gormDb := overall.CONSTANT_DB_HR.Model(&cont)
if len(field) > 0 {
fieldStr := strings.Join(field, ",")
gormDb = gormDb.Select(fieldStr)
}
gormDb = gormDb.Where(whereMap)
err = gormDb.First(&cont).Error
return
}

24
models/duties.go

@ -0,0 +1,24 @@
package models
import "hr_server/overall"
//职务
type Duties struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"`
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:职务名称"`
JobType int64 `json:"jobtype" gorm:"column:job_type;type:bigint(20) unsigned;default:0;not null;comment:归属职务类型"`
Weight int64 `json:"weight" gorm:"column:weight;type:bigint(20) unsigned;default:1;not null;comment:权重"`
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"`
Number string `json:"number" gorm:"column:number;type:varchar(50) unsigned;default:'';not null;comment:编码"`
State int `json:"state" gorm:"column:state;type:int(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"`
}
func (Duties *Duties) TableName() string {
return "duties"
}
//编辑职务分类内容
func (Duties *Duties) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) {
err = overall.CONSTANT_DB_HR.Model(&Duties).Where(whereMap).Updates(saveData).Error
return
}

21
models/job_class.go

@ -0,0 +1,21 @@
package models
import "hr_server/overall"
//职务分类
type JobClass struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"`
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:职务分类名称"`
Time int64 `json:"time" gorm:"column:time;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:删除)"`
}
func (JobClass *JobClass) TableName() string {
return "job_class"
}
//编辑职务分类内容
func (JobClass *JobClass) EiteJobClassCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) {
err = overall.CONSTANT_DB_HR.Model(&JobClass).Where(whereMap).Updates(saveData).Error
return
}

48
models/position.go

@ -0,0 +1,48 @@
package models
import (
"hr_server/overall"
"strings"
)
//职位(岗位)
type Position struct {
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"`
Number string `json:"number" gorm:"column:number;type:varchar(50) unsigned;default:'';not null;comment:职位编码"`
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:职位名称"`
Duties int64 `json:"duties" gorm:"column:duties;type:bigint(20) unsigned;default:0;not null;comment:职务"`
Time int64 `json:"time" gorm:"column:time;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:删除)"`
AdministrativeOrganization int64 `json:"administrativeorganization" gorm:"column:administrative_organization;type:bigint(20) unsigned;default:0;not null;comment:归属行政组织"`
Superior int64 `json:"superior" gorm:"column:superior;type:bigint(20) unsigned;default:0;not null;comment:上级ID"`
PersonInCharge int `json:"personincharge" gorm:"column:person_in_charge;type:int(1) unsigned;default:2;not null;comment:是否为本部门负责人(1:是;2:否)"`
Department int64 `json:"department" gorm:"column:department;type:bigint(20) unsigned;default:0;not null;comment:部门"`
}
func (Position *Position) TableName() string {
return "position"
}
//编辑职务分类内容
func (cont *Position) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) {
err = overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Updates(saveData).Error
return
}
//获取行政组织内容
func (cont *Position) GetCont(whereMap map[string]interface{}, field ...string) (err error) {
gormDb := overall.CONSTANT_DB_HR.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 *Position) CountCont(whereMap map[string]interface{}) (countId int64) {
overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Count(&countId)
return
}

25
overall/app_config_const.go

@ -0,0 +1,25 @@
package overall
import (
"hr_server/config/configApp"
"github.com/go-redis/redis/v8"
"gorm.io/gorm"
)
//全局配置
var (
//服务常量
CONSTANT_CONFIG configApp.Server
//
CONSTANT_DB_Master *gorm.DB //主数据库
CONSTANT_DB_Wechat *gorm.DB //微信数据库
CONSTANT_DB_HR *gorm.DB //微信数据库
//Redis
CONSTANT_REDIS0 *redis.Client
CONSTANT_REDIS1 *redis.Client
CONSTANT_REDIS2 *redis.Client
CONSTANT_REDIS3 *redis.Client
CONSTANT_REDIS4 *redis.Client
CONSTANT_REDIS5 *redis.Client
)

8
overall/app_constant.go

@ -0,0 +1,8 @@
package overall
//常量
var (
ConfigFilePathConstant = "./config/configApp/appConfig.yaml" //服务基础配置
ConfigDatabaseConstant = "./config/configDatabase/database.yaml"
ConfigRedisConstant = "./config/configNosql/redis.yaml"
)

11
overall/database.go

@ -0,0 +1,11 @@
package overall
import (
"hr_server/config/configDatabase"
confignosql "hr_server/config/configNosql"
)
var (
CONSTANT_MYSQL configDatabase.MysqlSetUp
CONSTANT_Redis confignosql.RedisSetUp
)

13
overall/overallhandle/errorcode.go

@ -0,0 +1,13 @@
package overallhandle
var ErrorCodeMsg = map[int]string{
0: "成功",
100: "提交的数据格式错误!",
101: "提交的数据不能为空误!",
103: "该数据已经存在!请不要重复添加",
104: "数据写入失败!",
105: "数据查询失败!",
106: "编辑失败!",
107: "未能查询到数据!",
108: "删除失败",
}

41
overall/overallhandle/format_output.go

@ -0,0 +1,41 @@
package overallhandle
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
func Result(code int, data interface{}, c *gin.Context, msgAry ...string) {
var msg string
if _, isTrue := ErrorCodeMsg[code]; isTrue {
msg = ErrorCodeMsg[code]
}
if len(msgAry) > 0 {
for _, v := range msgAry {
msg = fmt.Sprintf("%v。%v", msg, v)
}
}
c.JSON(http.StatusOK, Reply{code, msg, data}) //输出json格式数据
}
//列表输出标准格式
/*
@total 总数
@count 当前页总数
@page 页数
@pageSize 每页显示数量
@data 返回数据
*/
func ResultList(code, page, pageSize int, total, count int64, data interface{}, c *gin.Context) (printMap map[string]interface{}) {
outMap := MapOut()
outMap["count"] = count
outMap["total"] = total
outMap["page"] = page
outMap["pageSize"] = pageSize
outMap["list"] = data
printMap = outMap
Result(code, outMap, c)
return
}

265
overall/overallhandle/overall_handle.go

@ -0,0 +1,265 @@
package overallhandle
import (
"bytes"
"fmt"
"hr_server/models"
"hr_server/overall"
"math"
"strconv"
"time"
"github.com/mozillazg/go-pinyin"
)
//全局函数处理
//初始化map
func MapOut() (data map[string]interface{}) {
data = make(map[string]interface{}) //必可不少,分配内存
return data
}
func MapOutint() (data map[int]interface{}) {
data = make(map[int]interface{}) //必可不少,分配内存
return data
}
func MapOutint64() (data map[int64]interface{}) {
data = make(map[int64]interface{}) //必可不少,分配内存
return data
}
func MapOutFloat64() (data map[float64]interface{}) {
data = make(map[float64]interface{}) //必可不少,分配内存
return data
}
func MapOutString() (data map[string]string) {
data = make(map[string]string) //必可不少,分配内存
return data
}
//时间搓转换成日期
/*
@timestamp 待转换的时间戳
@timeType 转换类型
*/
func UnixTimeToDay(timeStamp int64, timeType int) (dateStr string) {
timeTemplate := "2006-01-02 15:04:05" //常规类型
switch timeType {
case 1:
timeTemplate = "2006/01/02 15:04:05"
case 2:
timeTemplate = "2006/01/02 15:04"
case 3:
timeTemplate = "2006/01/02 15"
case 4:
timeTemplate = "2006/01/02"
case 5:
timeTemplate = "15:04:05"
case 6:
timeTemplate = "15:04"
case 7:
timeTemplate = "15"
case 8:
timeTemplate = "04:05"
case 9:
timeTemplate = "04"
case 10:
timeTemplate = "05"
case 11:
timeTemplate = "2006-01-02 15:04:05"
case 12:
timeTemplate = "2006-01-02 15:04"
case 13:
timeTemplate = "2006-01-02 15"
case 14:
timeTemplate = "2006-01-02"
case 15:
timeTemplate = "2006-01" //年月
case 16:
timeTemplate = "2006" //年
case 17:
timeTemplate = "01" //月
case 18:
timeTemplate = "02" //日
case 19: //季度
dayMonth := time.Unix(timeStamp, 0).Format("01")
datMonthFloat, datMonthFloatErr := strconv.ParseFloat(dayMonth, 10)
if datMonthFloatErr == nil {
dateStr = strconv.FormatFloat(math.Ceil(datMonthFloat/3), 'f', -1, 64)
}
dateStr = "1"
case 20:
timeTemplate = "20060102"
default:
timeTemplate = "2006-01-02 15:04:05" //常规类型
}
dateStr = time.Unix(timeStamp, 0).Format(timeTemplate)
return
}
/*
日期转时间戳
*/
func DateToTimeStamp(dataStr string) (timeStamp int64, isTrue bool) {
isTrue = false
tmp := "2006-01-02 15:04:05"
res, err := time.ParseInLocation(tmp, dataStr, time.Local)
timeStamp = res.Unix()
if err == nil {
isTrue = true
}
return
}
//数据库查询翻页
func LimitPage(page, pageSize int) (offSet int) {
if page < 1 {
page = 1
}
offSet = pageSize * (page - 1)
if offSet < 0 {
offSet = 0
}
return
}
//中文首字母大写
func ChineseFirstWordCapitalize(wordStr string) (firstWord string) {
pinYinSub := pinyin.NewArgs()
rows := pinyin.Pinyin(wordStr, pinYinSub)
for i := 0; i < len(rows); i++ {
if len(rows[i]) != 0 {
str := rows[i][0]
pi := str[0:1]
firstWord += string(bytes.ToUpper([]byte(pi)))
}
}
return
}
//获取行政组织首字母
/*
@govName 全称
@abbreviation 简称
@govClass 部门类型
@parentId 上级
*/
func GetGovFirstWords(govName, abbreviation, govClass, parentId string) (firstWord string) {
var lev int = 0
overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganizationType{}).Select("`level`").Where("`id` = ?", govClass).First(&lev)
if lev <= 2 {
if abbreviation != "" {
firstWord = ChineseFirstWordCapitalize(abbreviation)
} else {
firstWord = ChineseFirstWordCapitalize(govName)
}
} else {
var idAry []int64
firstWord = GetCompany(GetGroupFramework(parentId, idAry))
}
return
}
//获取行政级别公司
func GetCompany(id []int64) (firstWord string) {
var govClass []outGovToClass
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("administrative_organization.name,administrative_organization.abbreviation,aot.level").Joins("left join administrative_organization_type as aot on aot.id = administrative_organization.organization_type").Where("administrative_organization.state IN ? AND administrative_organization.id IN ?", []int{1, 2}, id).Find(&govClass).Error
if err != nil {
return
}
levelOne := ""
levelTwo := ""
for _, v := range govClass {
if v.Level == 2 {
if v.Abbreviation != "" {
levelTwo = ChineseFirstWordCapitalize(v.Abbreviation)
} else {
levelTwo = ChineseFirstWordCapitalize(v.Name)
}
firstWord = levelTwo
return
}
if v.Level == 1 {
if v.Abbreviation != "" {
levelOne = ChineseFirstWordCapitalize(v.Abbreviation)
} else {
levelOne = ChineseFirstWordCapitalize(v.Name)
}
}
}
if levelTwo != "" {
firstWord = levelTwo
} else {
firstWord = levelOne
}
return
}
//获取架构
func GetGroupFramework(parentId string, father []int64) []int64 {
var id int64
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`").Where("`superior` = ?", parentId).First(&id)
if err != nil {
return father
}
father = append(father, id)
GetGroupFramework(strconv.FormatInt(id, 10), father)
return father
}
//
// ZeroFillByStr
// @Description: 字符串补零
// @param str :需要操作的字符串
// @param resultLen 结果字符串的长度
// @param reverse true 为前置补零,false 为后置补零
// @return string
//
func ZeroFillByStr(str string, resultLen int, reverse bool) string {
if len(str) > resultLen || resultLen <= 0 {
return str
}
if reverse {
return fmt.Sprintf("%0*s", resultLen, str) //不足前置补零
}
result := str
for i := 0; i < resultLen-len(str); i++ {
result += "0"
}
return result
}
//生成编号
func CreateNumber(firstWords, govClass string) (numberStr string) {
var orgCont models.AdministrativeOrganization
var orgClass models.AdministrativeOrganizationType
whereAry := MapOut()
whereAry["superior"] = govClass
countId := orgCont.CountCont(whereAry)
whereOrgAry := MapOut()
whereOrgAry["id"] = govClass
orgCont.GetCont(whereOrgAry)
orgWhere := MapOut()
orgWhere["id"] = orgCont.OrganizationType
orgClass.GetCont(orgWhere)
// fmt.Printf("---11---------->%v------>%v\n", orgWhere, orgClass)
if orgClass.Level < 2 {
numberVal := ZeroFillByStr(strconv.FormatInt(countId, 10), 2, true)
numberStr = fmt.Sprintf("%v%v", firstWords, numberVal)
} else {
countId++
numberVal := ZeroFillByStr(strconv.FormatInt(countId, 10), 2, true)
// fmt.Printf("------------->%v------>%v\n", whereOrgAry, orgCont)
numberStr = fmt.Sprintf("%v%v", orgCont.Number, numberVal)
}
return
}
// //获取行政组织的部门
// func GetOrgDepartment()

37
overall/overallhandle/type.go

@ -0,0 +1,37 @@
package overallhandle
//格式化输出
type Reply struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
//取ID
type GetId struct {
Id int64 `json:"id"`
IdStr string `json:"idstr"`
}
//翻页格式化
type PageTurning struct {
Page int `json:"page" form:"page"` // 页码
PageSize int `json:"pagesize" form:"pagesize"` // 每页大小
}
//状态
type StateOverall struct {
State int `json:"state"` //状态
}
//状态
type NmuberOverall struct {
Number string `json:"number"` //编码
}
//输出行政组织关系
type outGovToClass struct {
Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:组织名称"`
Abbreviation string `json:"abbreviation" gorm:"column:abbreviation;type:varchar(255) unsigned;default:'';not null;comment:行政组织简称"`
Level int64 `json:"level" gorm:"column:level;type:int(5) unsigned;default:1;not null;comment:级别"`
}
Loading…
Cancel
Save