Browse Source

修改小版本

v2_dev
超级管理员 3 years ago
parent
commit
57a72d4ec4
  1. 41
      api/version1/administrativeorganization/govcont.go
  2. 194
      api/version1/personnelapi/staffarchives.go
  3. 12
      api/version1/personnelapi/type.go
  4. 6
      apirouter/organization/organization_group.go
  5. 40
      apirouter/personnel/people.go
  6. 27
      config/configApp/appConfig.yaml
  7. 33
      config/configApp/server.go
  8. 69
      grocerystore/redis.go
  9. 39
      models/system_role.go
  10. 61
      overall/overallhandle/overall_handle.go

41
api/version1/administrativeorganization/govcont.go

@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)
//行政组织
// 行政组织
func (o *OrganizationApi) GovList(c *gin.Context) {
var requestData govListType
c.ShouldBindJSON(&requestData)
@ -55,7 +55,7 @@ func (o *OrganizationApi) GovList(c *gin.Context) {
}
}
//添加行政组织
// 添加行政组织
func (o *OrganizationApi) AddGovCont(c *gin.Context) {
var requestData addGovInfo
err := c.ShouldBindJSON(&requestData)
@ -115,7 +115,7 @@ func (o *OrganizationApi) AddGovCont(c *gin.Context) {
}
}
//获取行政组织详情
// 获取行政组织详情
func (o *OrganizationApi) GetGovCont(c *gin.Context) {
var requestData overallhandle.GetId
err := c.ShouldBindJSON(&requestData)
@ -143,7 +143,7 @@ func (o *OrganizationApi) GetGovCont(c *gin.Context) {
}
}
//编辑行政组织
// 编辑行政组织
func (o *OrganizationApi) EiteGovCont(c *gin.Context) {
var requestData eiteGovInfo
err := c.ShouldBindJSON(&requestData)
@ -202,7 +202,7 @@ func (o *OrganizationApi) EiteGovCont(c *gin.Context) {
}
}
//编辑行政组织状态或删除
// 编辑行政组织状态或删除
func (o *OrganizationApi) EiteGovStateOrDel(c *gin.Context) {
var requestData EiteJobStateDel
err := c.ShouldBindJSON(&requestData)
@ -264,7 +264,7 @@ func (o *OrganizationApi) EiteGovStateOrDel(c *gin.Context) {
}
}
//行政组织树
// 行政组织树
func (o *OrganizationApi) GovThree(c *gin.Context) {
var requestData govThreeType
c.ShouldBindJSON(&requestData)
@ -295,3 +295,32 @@ func (o *OrganizationApi) GovThree(c *gin.Context) {
govMapThree := overallhandle.GovThreeList(requestData.Id, govMap)
overallhandle.Result(0, govMapThree, c)
}
// 获取当前行政组织的所有子类
func (o *OrganizationApi) GetOrgAllSun(c *gin.Context) {
var requestData overallhandle.GetId
c.ShouldBindJSON(&requestData)
if requestData.Id == 0 && requestData.IdStr == "" {
requestData.Id = 0
}
if requestData.IdStr != "" {
idInt64, _ := strconv.ParseInt(requestData.IdStr, 10, 64)
requestData.Id = idInt64
}
// fmt.Printf("\nrequestData---->%v\n", requestData)
var idAry []int64
idAry = overallhandle.GetDepartmentSun(requestData.Id, idAry)
idAry = append(idAry, requestData.Id)
//获取行政组织信息
var orgList []models.AdministrativeOrganization
if len(idAry) < 1 {
overallhandle.Result(101, orgList, c, "没有查询到信息!")
return
}
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Where("`state` = 1 AND `id` IN ?", idAry).Find(&orgList).Error
if err != nil {
overallhandle.Result(101, err, c, "没有查询到信息!")
return
}
overallhandle.Result(0, orgList, c)
}

194
api/version1/personnelapi/staffarchives.go

@ -2,6 +2,7 @@ package personnelapi
import (
"fmt"
"hr_server/grocerystore"
"hr_server/models"
"hr_server/overall"
"hr_server/overall/overallhandle"
@ -136,7 +137,6 @@ func (s *StaffApi) ArchivesList(c *gin.Context) {
}
// 获取单个人员档案
// 人员列表
func (s *StaffApi) ArchivesCon(c *gin.Context) {
var requestData overallhandle.GetId
c.ShouldBindJSON(&requestData)
@ -248,7 +248,7 @@ func (s *StaffApi) ArchivesCon(c *gin.Context) {
}()
synPro.Wait()
overallhandle.Result(0, staffCenter, c)
return
// return
}
// 获取双职工信息
@ -1607,3 +1607,193 @@ func (s *StaffApi) DoubleWorkerList(c *gin.Context) {
overallhandle.Result(0, insideWorkHistoryList, c)
}
}
/*
*
@ 作者: 秦东
@ 时间: 2022-10-19 09:40:32
@ 功能: 根据微信或企业微信UserId获取人员信息
@ 参数
#OpenId 微信或企业微信UserId
@ 返回值
#
*/
func (s *StaffApi) WeChatGiveUsCont(c *gin.Context) {
var requestData weChatUserId
err := c.ShouldBindJSON(&requestData)
if err != nil {
overallhandle.Result(100, requestData, c)
return
}
if requestData.OpenId == "" {
overallhandle.Result(101, requestData, c)
return
}
var userCont models.ManCont
staffErr := overall.CONSTANT_DB_HR.Where("`wechat` = ? OR `work_wechat` = ?", requestData.OpenId, requestData.OpenId).First(&userCont).Error
if staffErr != nil {
overallhandle.Result(105, staffErr, c)
return
}
switch userCont.State {
case 2:
overallhandle.Result(0, staffErr, c, "该账号已经被禁用!不可进行操作!")
return
case 3:
overallhandle.Result(0, staffErr, c, "该账号已经被离开企业!不可进行操作!")
return
default:
}
if userCont.EmpType >= 11 {
overallhandle.Result(0, staffErr, c, "该账号已经被离开企业!不可进行操作!")
return
}
userAgent := overall.CONSTANT_CONFIG.Appsetup.AppKey
var md5JiaMi overallhandle.Md5Encryption
md5JiaMi.Md5EncryptionInit(userAgent)
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
var md5JiaMiNumber overallhandle.Md5Encryption
// md5JiaMiNumber.Md5EncryptionInit(userCont.Number + uuIdValStr)
md5JiaMiNumber.Md5EncryptionInit(userCont.Number)
userKeyCode := md5JiaMiNumber.Md5EncryptionAlgorithm()
// sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token + uuIdValStr
sha1Str := userKeyCode + userCont.Number + userCont.Password + md5Token
sha1Token := overallhandle.Sha1Encryption(sha1Str)
fmt.Printf("token=========>\n%v\n---->%v\n---->%v\n---->%v\n---->%v\n---->%v\n", userKeyCode, userCont.Number, userCont.Password, md5Token, sha1Token, userAgent)
//返回值
saveData := overallhandle.MapOut()
saveData["key"] = userKeyCode
saveData["token"] = sha1Token
saveData["userinfo"] = userCont
menuoper, jurisdiction := getRoleSeat(userCont.Role)
writeRedisData := map[string]interface{}{
"userkey": userKeyCode,
"key": userCont.Key,
"usernumber": userCont.Number,
"userpwd": userCont.Password,
"usertoken": sha1Token,
"jurisdiction": jurisdiction,
"menuOper": menuoper,
"wand": 118,
}
//API Token数据
redisFileKey := fmt.Sprintf("ScanCode:Authentication:LoginApi_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userKeyCode)
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS5)
redisClient.SetRedisTime(10800)
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
//缓存写入个人信息
redisMyContKey := fmt.Sprintf("ScanCode:Authentication:UserCont_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, userCont.Number)
myCont := overallhandle.MapOut()
myCont["id"] = userCont.Id
myCont["number"] = userCont.Number //员工工号
myCont["name"] = userCont.Name //姓名
myCont["icon"] = userCont.Icon //头像
myCont["hireclass"] = userCont.HireClass //雇佣类型(1:雇佣入职;2:再入职;)
myCont["emptype"] = userCont.EmpType //用工关系(1:临时工 , 2:编外人员 ;3:实习&实习生;4:试用员工;5:待分配;6:待岗;7:临时调入;8:正式员工;9:长期病假;10:停薪留职;11:退休;12:辞职;13:辞退;14:离职)
myCont["company"] = userCont.Company //入职公司
myCont["maindeparment"] = userCont.MainDeparment //主部门
myCont["sunmaindeparment"] = userCont.SunMainDeparment //二级主部门
myCont["deparment"] = userCont.Deparment //部门
myCont["adminorg"] = userCont.AdminOrg //所属行政组织
myCont["teamid"] = userCont.TeamId //班组
myCont["position"] = userCont.Position //职位
myCont["jobclass"] = userCont.JobClass //职务分类
myCont["jobid"] = userCont.JobId //职务
myCont["jobleve"] = userCont.JobLeve //职务等级
myCont["wechat"] = userCont.Wechat //微信UserId
myCont["workwechat"] = userCont.WorkWechat //企业微信UserId
myCont["state"] = userCont.State //状态(1:启用;2:禁用;3:删除)
myCont["key"] = userCont.Key //key
myCont["isadmin"] = userCont.IsAdmin //是否为管理员(1:不是;2:分公司;3:集团管理员;4:超级管
myCont["password"] = userCont.Password //密码
myCont["role"] = userCont.Role //角色
myCont["idcardno"] = userCont.Idcardno //身份证号
myCont["passportno"] = userCont.Passportno //护照号码
myCont["globalroaming"] = userCont.Globalroaming //国际区号
myCont["mobilephone"] = userCont.Mobilephone //手机号码
myCont["email"] = userCont.Email //电子邮件
myCont["gender"] = userCont.Gender //性别(1:男性;2:女性;3:中性)
myCont["birthday"] = userCont.Birthday //birthday
myCont["myfolk"] = userCont.Myfolk //民族
myCont["nativeplace"] = userCont.Nativeplace //籍贯
myCont["idcardstartdate"] = userCont.Idcardstartdate //身份证有效期开始
myCont["idcardenddate"] = userCont.Idcardenddate //身份证有效期结束
myCont["idcardaddress"] = userCont.Idcardaddress //身份证地址
myCont["idcardIssued"] = userCont.IdcardIssued //身份证签发机关
myCont["health"] = userCont.Health //健康状况(1:良好;2:一般;3:较弱,4:有生理缺陷;5:残废)
myCont["maritalstatus"] = userCont.Maritalstatus //婚姻状况(1:未婚;2:已婚;3:丧偶;4:离异)
myCont["internaltelephone"] = userCont.Internaltelephone //内线电话
myCont["currentresidence"] = userCont.Currentresidence //现居住地址
myCont["constellationing"] = userCont.Constellation //星座(1:白羊座;2:金牛座;3:双子座;4:巨蟹座;5:狮子座;6:处女座;7:天枰座;8:天蝎座;9:射手座;10:摩羯座;11:水瓶座;12:双鱼座)
myCont["isdoubleworker"] = userCont.Isdoubleworker //是否双职工(1:是;2:否)
myCont["isveterans"] = userCont.Isveterans //是否为退役军人(1:是;2:否)
myCont["veteransnumber"] = userCont.Veteransnumber //退役证编号
myCont["jobstartdate"] = userCont.Jobstartdate //参加工作日期
myCont["entrydate"] = userCont.Entrydate //入职日期
myCont["probationperiod"] = userCont.Probationperiod //试用期
myCont["planformaldate"] = userCont.Planformaldate //预计转正日期
myCont["political_outlook"] = userCont.PoliticalOutlook //政治面貌(1:群众;2:无党派;3:台盟会员;4:九三社员;5:致公党员;6:农工党员;7:民进会员;8:民建会员;9:民盟盟员;10:民革会员,11:共青团员;12:预备党员;13:中共党员)
redisClient.HashMsetAdd(redisMyContKey, myCont)
// fmt.Printf("redisMyContKey------Login----->%v\n", redisMyContKey)
overallhandle.Result(0, saveData, c)
// return
}
// 获取权限点位
func getRoleSeat(roleId string) (menuStr, buttonStr string) {
var roleInfo models.SystemRole
err := roleInfo.GetCont(map[string]interface{}{"r_id": roleId}, "r_menu_oper", "r_jurisdiction")
if err != nil {
return
}
menuStr = roleInfo.MenuOper
buttonStr = roleInfo.Jurisdiction
return
}
/*
*
@ 作者: 秦东
@ 时间: 2022-10-19 09:51:50
@ 功能: 修改员工微信或企业微信UserId
@ 参数
#
@ 返回值
#
*/
func (s *StaffApi) EditUsWechatOpenId(c *gin.Context) {
var requestData EditweChatUserId
c.ShouldBindJSON(&requestData)
if requestData.Id == "" {
overallhandle.Result(101, requestData.Id, c, "参数错误")
return
}
if requestData.WechatId == "" && requestData.WorkWechatId == "" {
overallhandle.Result(101, requestData.Id, c, "微信OpenId或企业微信OpenId至少存在一个")
return
}
var usCont models.PersonArchives
err := usCont.GetCont(map[string]interface{}{"`id`": requestData.Id}, "`id`")
if err != nil {
overallhandle.Result(101, err, c, "该用户不存在!")
return
}
err = usCont.EiteCont(map[string]interface{}{"`id`": usCont.Id}, map[string]interface{}{"`wechat`": requestData.WechatId, "`work_wechat`": requestData.WorkWechatId, "`eite_time`": time.Now().Unix()})
if err != nil {
overallhandle.Result(106, err, c)
return
}
overallhandle.Result(0, err, c)
}

12
api/version1/personnelapi/type.go

@ -460,3 +460,15 @@ type editPws struct {
Pwd string `json:"pwd"`
Pwdes string `json:"pwdes"`
}
// 微信或企业微信UserId
type weChatUserId struct {
OpenId string `json:"openid"` //微信或企业微信OpenId
}
// 修改微信或企业微信UserId
type EditweChatUserId struct {
Id string `json:"id"`
WechatId string `json:"wechatid"` //微信OpenId
WorkWechatId string `json:"workwechatid"` //企业微信OpenId
}

6
apirouter/organization/organization_group.go

@ -38,7 +38,8 @@ func (o *OrganizationRoute) InitRouterGroup(route *gin.RouterGroup) {
apiRouter.POST("eitegovcont", apiHandle.EiteGovCont) //编辑行政组织
apiRouter.POST("eitegovstateordel", apiHandle.EiteGovStateOrDel) //编辑行政组织状态或删除
apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树
apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树
apiRouter.POST("getorgallsun", apiHandle.GetOrgAllSun) //获取当前行政组织的所有子类
//职位(岗位)
apiRouter.POST("positionlist", apiHandle.PositionList) //职位(岗位)列表
apiRouter.POST("getpositioncont", apiHandle.GetPositionCont) //获取职位(岗位)
@ -89,7 +90,8 @@ func (o *OrganizationRouteOpen) InitRouterGroup(route *gin.RouterGroup) {
apiRouter.POST("eitegovcont", apiHandle.EiteGovCont) //编辑行政组织
apiRouter.POST("eitegovstateordel", apiHandle.EiteGovStateOrDel) //编辑行政组织状态或删除
apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树
apiRouter.POST("govthree", apiHandle.GovThree) //行政组织树
apiRouter.POST("getorgallsun", apiHandle.GetOrgAllSun) //获取当前行政组织的所有子类
//职位(岗位)
apiRouter.POST("positionlist", apiHandle.PositionList) //职位(岗位)列表
apiRouter.POST("getpositioncont", apiHandle.GetPositionCont) //获取职位(岗位)

40
apirouter/personnel/people.go

@ -11,15 +11,17 @@ func (p *PersonnelRoute) InitRouterGroup(route *gin.RouterGroup) {
apiRouter := route.Group("staff")
var apiHandle = version1.AppApiInlet.StaffApi
{
apiRouter.GET("", apiHandle.Index) //入口
apiRouter.POST("", apiHandle.Index) //入口
apiRouter.POST("stafflist", apiHandle.StaffList) //人员列表
apiRouter.POST("addstaff", apiHandle.AddStaff) //添加人员档案
apiRouter.POST("allocationofrights", apiHandle.AllocationOfRights) //分配权限
apiRouter.POST("archiveslist", apiHandle.ArchivesList) //人员列表(新)
apiRouter.POST("archivescont", apiHandle.ArchivesCon) //个人档案
apiRouter.POST("kingdeehr", apiHandle.NewKingdee) //对接金蝶HR系统
apiRouter.POST("editpassword", apiHandle.EditPassWord) //修改密码
apiRouter.GET("", apiHandle.Index) //入口
apiRouter.POST("", apiHandle.Index) //入口
apiRouter.POST("stafflist", apiHandle.StaffList) //人员列表
apiRouter.POST("addstaff", apiHandle.AddStaff) //添加人员档案
apiRouter.POST("allocationofrights", apiHandle.AllocationOfRights) //分配权限
apiRouter.POST("archiveslist", apiHandle.ArchivesList) //人员列表(新)
apiRouter.POST("archivescont", apiHandle.ArchivesCon) //个人档案
apiRouter.POST("kingdeehr", apiHandle.NewKingdee) //对接金蝶HR系统
apiRouter.POST("editpassword", apiHandle.EditPassWord) //修改密码
apiRouter.POST("wechat_give_uscont", apiHandle.WeChatGiveUsCont) //根据微信OpenId获取个人档案
apiRouter.POST("edit_us_wechat_openid", apiHandle.EditUsWechatOpenId) //修改员工微信或企业微信UserId
//双职工
apiRouter.POST("doubleworkerlist", apiHandle.DoubleWorkerList) //双职工列表
apiRouter.POST("adddoubleworker", apiHandle.AddDoubleWorkerApi) //添加双职工
@ -60,15 +62,17 @@ func (p *PersonnelRouteKingdee) InitRouterGroup(route *gin.RouterGroup) {
apiRouter := route.Group("staffkingdee")
var apiHandle = version1.AppApiInlet.StaffApi
{
apiRouter.GET("", apiHandle.Index) //入口
apiRouter.POST("", apiHandle.Index) //入口
apiRouter.POST("stafflist", apiHandle.StaffList) //人员列表
apiRouter.POST("addstaff", apiHandle.AddStaff) //添加人员档案
apiRouter.POST("allocationofrights", apiHandle.AllocationOfRights) //分配权限
apiRouter.POST("archiveslist", apiHandle.ArchivesList) //人员列表(新)
apiRouter.POST("archivescont", apiHandle.ArchivesCon) //个人档案
apiRouter.POST("kingdeehr", apiHandle.NewKingdee) //对接金蝶HR系统
apiRouter.POST("editpassword", apiHandle.EditPassWord) //修改密码
apiRouter.GET("", apiHandle.Index) //入口
apiRouter.POST("", apiHandle.Index) //入口
apiRouter.POST("stafflist", apiHandle.StaffList) //人员列表
apiRouter.POST("addstaff", apiHandle.AddStaff) //添加人员档案
apiRouter.POST("allocationofrights", apiHandle.AllocationOfRights) //分配权限
apiRouter.POST("archiveslist", apiHandle.ArchivesList) //人员列表(新)
apiRouter.POST("archivescont", apiHandle.ArchivesCon) //个人档案
apiRouter.POST("kingdeehr", apiHandle.NewKingdee) //对接金蝶HR系统
apiRouter.POST("editpassword", apiHandle.EditPassWord) //修改密码
apiRouter.POST("wechat_give_uscont", apiHandle.WeChatGiveUsCont) //根据微信OpenId获取个人档案
apiRouter.POST("edit_us_wechat_openid", apiHandle.EditUsWechatOpenId) //修改员工微信或企业微信UserId
//双职工
apiRouter.POST("adddoubleworker", apiHandle.AddDoubleWorkerApi) //添加双职工
apiRouter.POST("eidtdoubleworker", apiHandle.EidtDoubleWorkerApi) //编辑双职工

27
config/configApp/appConfig.yaml

@ -9,3 +9,30 @@ appsetup:
prefix: 'HXJT' #系统字段前缀
logconfig:
path: 'log' #日志保存地址
#验证码相关设置
captcha:
key-long: 6
img-width: 240
img-height: 80
#Redis前缀
redisprefix:
prefix: "HXGK_GO_ZhixingCollege"
alias: "dev"
#企业微信相关配置
wechatcompany:
companyid: 'ww02f310301953277a' #企业ID
#知行学院
wechatschool:
agentid: 1000008
secret: 'YJOHrmHtvevAdctg-06TMLnPokIaLHdfrQMyQolZQC8'
token: 'kkUA3s2s3' #Token
encodingaeskey: 'ZI29of85mTgQPik8LLjDnYKlAECDbI23Pq886VJ9Azf' #EncodingAESKey
#绩效考核
wechatkpi:
agentid: 1000036
secret: 'J83SKVK9QCdQs_fTjPWUx3ouqucrHf_EwxtQUlY0fQk'
token: 'kkUA3s2s3' #Token
encodingaeskey: 'ZI29of85mTgQPik8LLjDnYKlAECDbI23Pq886VJ9Azf' #EncodingAESKey

33
config/configApp/server.go

@ -2,8 +2,13 @@ package configApp
//服务基础配置
type Server struct {
Appsetup appsetup `mapstructure:"appsetup" json:"appsetup" yaml:"appsetup"`
Logsetup logsetup `mapstructure:"logconfig" json:"logconfig" yaml:"logconfig"`
Appsetup appsetup `mapstructure:"appsetup" json:"appsetup" yaml:"appsetup"`
Logsetup logsetup `mapstructure:"logconfig" json:"logconfig" yaml:"logconfig"`
Captcha captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
RedisPrefixStr redisPrefixStr `mapstructure:"redisprefix" json:"redisprefix" yaml:"redisprefix"`
WechatCompany wechatCompany `mapstructure:"wechatcompany" json:"wechatcompany" yaml:"wechatcompany"` //企业ID
WechatSchool wechatConfig `mapstructure:"wechatschool" json:"wechatschool" yaml:"wechatschool"` //知行学院
WechatKpi wechatConfig `mapstructure:"wechatkpi" json:"wechatkpi" yaml:"wechatkpi"` //绩效考核
}
//服务配置详情
@ -20,3 +25,27 @@ type appsetup struct {
type logsetup struct {
Path string `mapstructure:"path" json:"path" yaml:"path"`
}
//验证码相关
type captcha struct {
KeyLong int `mapstructure:"key-long" json:"keyLong" yaml:"key-long"` // 验证码长度
ImgWidth int `mapstructure:"img-width" json:"imgWidth" yaml:"img-width"` // 验证码宽度
ImgHeight int `mapstructure:"img-height" json:"imgHeight" yaml:"img-height"` // 验证码高度
}
type redisPrefixStr struct {
PreFix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // redis键前缀
Alias string `mapstructure:"alias" json:"alias" yaml:"alias"` // redis键前缀
}
//企业微信基础配置
type wechatCompany struct {
CompanyId string `mapstructure:"companyid" json:"companyid" yaml:"companyid"` // 企业ID
}
type wechatConfig struct {
Agentid string `mapstructure:"agentid" json:"agentid" yaml:"agentid"` // Agentid
Secret string `mapstructure:"secret" json:"secret" yaml:"secret"` // Secret
Token string `mapstructure:"token" json:"token" yaml:"token"` // Token
Encodingaeskey string `mapstructure:"encodingaeskey" json:"encodingaeskey" yaml:"encodingaeskey"` // EncodingAESKey
}

69
grocerystore/redis.go

@ -9,7 +9,7 @@ import (
"github.com/go-redis/redis/v8"
)
//redis 基础设定
// redis 基础设定
type RedisStoreType struct {
Expiration time.Duration
PreKey string
@ -17,27 +17,27 @@ type RedisStoreType struct {
RedisDb *redis.Client
}
//启动redis
// 启动redis
func RunRedis(redisClient *redis.Client) *RedisStoreType {
var redisStoreType RedisStoreType
redisStoreType.Expiration = time.Second * 300
redisStoreType.PreKey = fmt.Sprintf("%v:", overall.CONSTANT_CONFIG.Appsetup.PreFix)
redisStoreType.PreKey = fmt.Sprintf("%v:", overall.CONSTANT_CONFIG.RedisPrefixStr.PreFix)
redisStoreType.Context = context.Background()
redisStoreType.RedisDb = redisClient
return &redisStoreType
}
//设置键前缀
// 设置键前缀
func (r *RedisStoreType) SetRedisPrefix(prefix string) {
r.PreKey = prefix
}
//设置过期时间
// 设置过期时间
func (r *RedisStoreType) SetRedisTime(timeDate int64) {
r.Expiration = time.Second * time.Duration(timeDate)
}
//设置字符串
// 设置字符串
func (r *RedisStoreType) Set(key string, value string) bool {
err := r.RedisDb.Set(r.Context, r.PreKey+key, value, r.Expiration).Err()
if err != nil {
@ -46,7 +46,7 @@ func (r *RedisStoreType) Set(key string, value string) bool {
return true
}
//获取字符串
// 获取字符串
func (r *RedisStoreType) Get(key string) (bool, string) {
err := r.RedisDb.Get(r.Context, r.PreKey+key)
if err.Err() != nil {
@ -55,7 +55,7 @@ func (r *RedisStoreType) Get(key string) (bool, string) {
return true, err.Val()
}
//删除键
// 删除键
func (r *RedisStoreType) DelKey(key string) bool {
err := r.RedisDb.Del(r.Context, r.PreKey+key).Err()
if err != nil {
@ -159,7 +159,8 @@ func (r *RedisStoreType) HashGetAll(hashName string) (map[string]string, bool) {
//Redis 列表(List)
/**
/*
*
Linsert 命令用于在列表的元素前或者后插入元素当指定元素不存在于列表中时不执行任何操作
当列表不存在时被视为空列表不执行任何操作
如果 key 不是列表类型返回一个错误
@ -180,7 +181,8 @@ func (r *RedisStoreType) Linsert(key string, op int, pivot, value interface{}) (
return linsert, true
}
/**
/*
*
Lindex 命令用于通过索引获取列表中的元素你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@key 列表
@index 索引
@ -190,7 +192,8 @@ func (r *RedisStoreType) Lindex(key string, index int64) (val string, err error)
return
}
/**
/*
*
Llen 命令用于返回列表的长度 如果列表 key 不存在 key 被解释为一个空列表返回 0 如果 key 不是列表类型返回一个错误
@key 列表
*/
@ -199,7 +202,8 @@ func (r *RedisStoreType) Llen(key string) (val int64, err error) {
return
}
/**
/*
*
Lpop 命令用于移除并返回列表的第一个元素
@key 列表
*/
@ -208,7 +212,8 @@ func (r *RedisStoreType) Lpop(key string) (val string, err error) {
return
}
/**
/*
*
Lpush 命令将一个或多个值插入到列表头部 如果 key 不存在一个空列表会被创建并执行 LPUSH 操作 key 存在但不是列表类型时返回一个错误
@key 列表
@value 要插入的字符串
@ -218,7 +223,8 @@ func (r *RedisStoreType) Lpush(key string, value ...interface{}) (val int64, err
return
}
/**
/*
*
Lpushx 将一个值插入到已存在的列表头部列表不存在时操作无效
@key 列表
@value 要插入的字符串
@ -228,7 +234,8 @@ func (r *RedisStoreType) Lpushx(key, value string) (val int64, err error) {
return
}
/**
/*
*
Lrange 返回列表中指定区间内的元素区间以偏移量 START END 指定 其中 0 表示列表的第一个元素 1 表示列表的第二个元素以此类推 你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@key 列表
@start 起始值
@ -239,12 +246,15 @@ func (r *RedisStoreType) Lrange(key string, start, stop int64) (val []string, er
return
}
/**
/*
*
Lrem 根据参数 COUNT 的值移除列表中与参数 VALUE 相等的元素
COUNT 的值可以是以下几种
count > 0 : 从表头开始向表尾搜索移除与 VALUE 相等的元素数量为 COUNT
count < 0 : 从表尾开始向表头搜索移除与 VALUE 相等的元素数量为 COUNT 的绝对值
count = 0 : 移除表中所有与 VALUE 相等的值
@start = COUNT
@key 列表
*/
@ -253,7 +263,8 @@ func (r *RedisStoreType) Lrem(key string, start int64, value ...interface{}) (va
return
}
/**
/*
*
Redis Lset 通过索引来设置元素的值
当索引参数超出范围或对一个空列表进行 LSET 返回一个错误
@ -265,7 +276,8 @@ func (r *RedisStoreType) Lset(key string, indexes int64, value ...interface{}) (
return
}
/**
/*
*
Ltrim 对一个列表进行修剪(trim)就是说让列表只保留指定区间内的元素不在指定区间之内的元素都将被删除
下标 0 表示列表的第一个元素 1 表示列表的第二个元素以此类推 你也可以使用负数下标 -1 表示列表的最后一个元素 -2 表示列表的倒数第二个元素以此类推
@ -278,7 +290,8 @@ func (r *RedisStoreType) Ltrim(key string, start, stop int64) (val string, err e
return
}
/**
/*
*
Rpop 命令用于移除列表的最后一个元素返回值为移除的元素
@key 列表
*/
@ -287,7 +300,8 @@ func (r *RedisStoreType) Rpop(key string) (val string, err error) {
return
}
/**
/*
*
Rpoplpush 命令用于移除列表的最后一个元素并将该元素添加到另一个列表并返回
@sourceKey 源列表
@newKey 目标列表
@ -297,7 +311,8 @@ func (r *RedisStoreType) Rpoplpush(sourceKey, newKey string) (val string, err er
return
}
/**
/*
*
Rpush 命令用于将一个或多个值插入到列表的尾部(最右边)
如果列表不存在一个空列表会被创建并执行 RPUSH 操作 当列表存在但不是列表类型时返回一个错误
@key 列表
@ -308,7 +323,8 @@ func (r *RedisStoreType) Rpush(key string, value ...interface{}) (val int64, err
return
}
/**
/*
*
Rpushx 命令用于将一个值插入到已存在的列表尾部(最右边)如果列表不存在操作无效
@key 列表
@value 要插入的字符串
@ -318,7 +334,8 @@ func (r *RedisStoreType) Rpushx(key string, value ...interface{}) (val int64, er
return
}
/**
/*
*
Blpop 命令移出并获取列表的第一个元素 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@key 列表
*/
@ -327,7 +344,8 @@ func (r *RedisStoreType) Blpop(key string) (val []string, err error) {
return
}
/**
/*
*
Brpop 命令移出并获取列表的最后一个元素 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@key 列表
*/
@ -336,7 +354,8 @@ func (r *RedisStoreType) Brpop(key string) (val []string, err error) {
return
}
/**
/*
*
Brpoplpush 命令从列表中取出最后一个元素并插入到另外一个列表的头部 如果列表没有元素会阻塞列表直到等待超时或发现可弹出元素为止
@source 源列表
@destination 目标列表

39
models/system_role.go

@ -0,0 +1,39 @@
package models
import "hr_server/overall"
type SystemRole struct {
Id int64 `json:"id" gorm:"column:r_id;type:bigint(20) unsigned;not null;comment:Id"`
Title string `json:"title" gorm:"column:r_title;type:varchar(36);not null;comment:角色名称"`
State int `json:"state" gorm:"column:r_set;type:tinyint(1) unsigned;default:1;not null;comment:是否启用(1:启用;2:禁用;3:删除)"`
Attribute int64 `json:"attribute" gorm:"column:r_attribute;type:bigint(20) unsigned;default:0;not null;comment:属性"`
Gode int `json:"gode" gorm:"column:r_gode;type:tinyint(1) unsigned;default:1;not null;comment:继承属性(1:系统管理员;2:分厂管理员)"`
Time int64 `json:"time" gorm:"column:r_time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"`
UserId int64 `json:"userId" gorm:"column:r_user_id;type:bigint(50) unsigned;default:0;not null;comment:写入人"`
Jurisdiction string `json:"jurisdiction" gorm:"column:r_jurisdiction;type:text;not null;comment:权限"`
MenuOper string `json:"menuoper" gorm:"column:r_menu_oper;type:text;not null;comment:权限"`
Wand int `json:"wand" gorm:"column:r_wand;type:tinyint(2) unsigned;default:0;not null;comment:权杖"`
Group int64 `json:"group" gorm:"column:r_group;type:bigint(20) unsigned;not null;default:3;comment:归属集团"`
}
func (SystemRole *SystemRole) TableName() string {
return "system_role"
}
// 获取详情
func (cont *SystemRole) GetCont(where interface{}, filed ...string) error {
gormDb := overall.CONSTANT_DB_Master.Where(where)
if len(filed) > 0 {
for _, v := range filed {
gormDb = gormDb.Select(v)
}
}
err := gormDb.First(&cont).Error
return err
}
// 编辑内容
func (cont *SystemRole) EiteCont(whereMap interface{}, saveData interface{}) (err error) {
err = overall.CONSTANT_DB_Master.Model(&cont).Where(whereMap).Updates(saveData).Error
return
}

61
overall/overallhandle/overall_handle.go

@ -17,8 +17,8 @@ import (
"github.com/mozillazg/go-pinyin"
)
//全局函数处理
//编号,纯数字
// 全局函数处理
// 编号,纯数字
func TableNumber(class ...string) (number int64) {
result, _ := rand.Int(rand.Reader, big.NewInt(8999))
numberTeam := result.Int64() + 1000
@ -32,7 +32,7 @@ func TableNumber(class ...string) (number int64) {
return
}
//初始化map
// 初始化map
func MapOut() (data map[string]interface{}) {
data = make(map[string]interface{}) //必可不少,分配内存
return data
@ -131,7 +131,7 @@ func DateToTimeStamp(dataStr string) (timeStamp int64, isTrue bool) {
return
}
//数据库查询翻页
// 数据库查询翻页
func LimitPage(page, pageSize int) (offSet int) {
if page < 1 {
page = 1
@ -143,7 +143,7 @@ func LimitPage(page, pageSize int) (offSet int) {
return
}
//中文首字母大写
// 中文首字母大写
func ChineseFirstWordCapitalize(wordStr string) (firstWord string) {
pinYinSub := pinyin.NewArgs()
rows := pinyin.Pinyin(wordStr, pinYinSub)
@ -180,7 +180,7 @@ func GetGovFirstWords(govName, abbreviation, govClass, parentId string) (firstWo
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
@ -215,7 +215,7 @@ func GetCompany(id []int64) (firstWord string) {
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)
@ -227,7 +227,7 @@ func GetGroupFramework(parentId string, father []int64) []int64 {
return father
}
//获取集团或第一实权部门
// 获取集团或第一实权部门
func GetGroupOrDepartPower(parentId int64, departId ...int64) int64 {
var orgCont models.AdministrativeOrganization
err := orgCont.GetCont(map[string]interface{}{"id": parentId}, "id", "organization_type", "superior", "ispower")
@ -260,14 +260,12 @@ func GetGroupOrDepartPower(parentId int64, departId ...int64) int64 {
return orgCont.Id
}
//
// ZeroFillByStr
// @Description: 字符串补零
// @param str :需要操作的字符串
// @param resultLen 结果字符串的长度
// @param reverse true 为前置补零,false 为后置补零
// @return string
//
// 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
@ -282,7 +280,7 @@ func ZeroFillByStr(str string, resultLen int, reverse bool) string {
return result
}
//生成编号
// 生成编号
func CreateNumber(firstWords, govClass string) (numberStr string) {
var orgCont models.AdministrativeOrganization
var orgClass models.AdministrativeOrganizationType
@ -316,7 +314,7 @@ func CreateNumber(firstWords, govClass string) (numberStr string) {
type MenuList []OutGovCont
//行政组织递归
// 行政组织递归
func (g *MenuList) GovRecursion(parentId, level int64) []govThree {
var govMap []govThree
@ -332,7 +330,7 @@ func (g *MenuList) GovRecursion(parentId, level int64) []govThree {
return govMap
}
//获取子集
// 获取子集
func (g *MenuList) findChildren(parentId int64) []OutGovCont {
child := []OutGovCont{}
@ -360,7 +358,7 @@ func GovThreeList(parentId int64, govAry []OutGovCont) []govThree {
return govMap
}
//菜单权限递归
// 菜单权限递归
func MenuThreePermit(parentId int64, menuAry []models.SystemMenuOperation) []MenuPermitThree {
var menuThree []MenuPermitThree
for _, v := range menuAry {
@ -479,13 +477,13 @@ func (m *Md5Encryption) Md5EncryptionAlgorithmFj() (md5Val string, outlog []stri
return
}
//初始化程序
// 初始化程序
func (m *Md5Encryption) Md5EncryptionInit(code string) {
m.AppKey = overall.CONSTANT_CONFIG.Appsetup.AppKey
m.Code = code
}
//sha1算法
// sha1算法
func Sha1Encryption(str string) string {
sha1 := sha1.New()
sha1.Write([]byte(str))
@ -513,7 +511,7 @@ func GetFutureMonthTime(timeStamp int64, futureTime, class int) (dateStr int64)
return
}
//判断字符串是否在切片中
// 判断字符串是否在切片中
func StringIsInMap(str string, strAry []string) bool {
if len(strAry) > 0 {
for _, v := range strAry {
@ -526,7 +524,7 @@ func StringIsInMap(str string, strAry []string) bool {
return false
}
//判断值是否在数组中
// 判断值是否在数组中
func JudeInArray(id int64, ary []string) (isTrue bool) {
// isTrue = false
// for _, val := range ary {
@ -553,7 +551,7 @@ func JudgeInMap(id int64, ary []int64) bool {
return false
}
//判断元素是否在切片中
// 判断元素是否在切片中
func IsInTrue[T GenericityVariable](key T, keyAry []T) (isTrue bool) {
isTrue = false
for _, v := range keyAry {
@ -564,7 +562,7 @@ func IsInTrue[T GenericityVariable](key T, keyAry []T) (isTrue bool) {
return
}
//获取两个切片得差集
// 获取两个切片得差集
func DifferenceSet[T GenericityVariable](one, two []T) []T {
var three []T
temp := map[T]struct{}{}
@ -651,7 +649,7 @@ func PolitiToString(emp int) string {
}
}
//递归查找
// 递归查找
func RecursionOrgLeve(superior int64, leve int64) (groupId int64) {
if leve == 0 {
leve = 1
@ -670,7 +668,7 @@ func RecursionOrgLeve(superior int64, leve int64) (groupId int64) {
return
}
//获取集团、公司、部门、二级部门、工段
// 获取集团、公司、部门、二级部门、工段
func GetOrgStructure(orgId int64) (groupId, companyId, departmentId, sunDepartId, workShopId int64) {
var orgContTypeInfo models.OrgContType
err := orgContTypeInfo.GetCont(map[string]interface{}{"`id`": orgId})
@ -709,15 +707,18 @@ func GetOrgStructure(orgId int64) (groupId, companyId, departmentId, sunDepartId
return
}
//获取指定行政组织id,所有子类
// 获取指定行政组织id,所有子类
func GetDepartmentSun(superior int64, idary []int64) (orgIdAry []int64) {
// if superior != 0 && IsInTrue[int64](superior, orgIdAry) == false {
// orgIdAry = append(orgIdAry, superior)
// }
var orgAry []models.AdministrativeOrganization
err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1 AND `superior` = ?", superior).Find(&orgAry).Error
if err != nil {
return
}
for _, v := range orgAry {
if IsInTrue[int64](v.Id, orgIdAry) == false {
if superior != 0 && IsInTrue[int64](v.Id, orgIdAry) == false {
orgIdAry = append(orgIdAry, v.Id)
GetDepartmentSun(v.Id, orgIdAry)
} else {

Loading…
Cancel
Save