diff --git a/api/version1/administrativeorganization/position.go b/api/version1/administrativeorganization/position.go index 7d6dd66..02c0532 100644 --- a/api/version1/administrativeorganization/position.go +++ b/api/version1/administrativeorganization/position.go @@ -1,6 +1,7 @@ package administrativeorganization import ( + "encoding/json" "fmt" "hr_server/models" "hr_server/overall" @@ -327,3 +328,104 @@ func (o *OrganizationApi) EitePositionStateOrDel(c *gin.Context) { } } } + +//获取职位权限配置清单 +func (o *OrganizationApi) GetPositionRole(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, requestData, c) + return + } + if requestData.IdStr != "" { + idInt, inIntErr := strconv.ParseInt(requestData.IdStr, 10, 64) + if inIntErr == nil { + requestData.Id = idInt + } + } + where := overallhandle.MapOut() + var positionRole models.Position + where["id"] = requestData.Id + inFoErr := positionRole.GetCont(positionRole, "menu_permit", "button_permit") + if inFoErr != nil { + overallhandle.Result(105, requestData, c) + return + } + _, datahhh := GetMenuOperation(positionRole.MenuPermit, positionRole.ButtonPermit) + overallhandle.Result(0, datahhh, c) +} + +//遍历确权 +func GetMenuOperation(menuStr, menuOperStr string) (isTrue bool, sendData []powerConfigList) { + isTrue = false + var menuStrMap []string + var menuOperStrMap []string + + json.Unmarshal([]byte(menuStr), &menuStrMap) + json.Unmarshal([]byte(menuOperStr), &menuOperStrMap) + + var systemMenuList []models.SystemMenu + menuOperErr := overall.CONSTANT_DB_Master.Where("`m_steat` IN ?", []int{1, 2}).Order("m_sort asc").Order("m_id desc").Find(&systemMenuList).Error + if menuOperErr != nil { + return + } + + sendData = GetMenuPowerThree(1, 0, systemMenuList, menuStrMap, menuOperStrMap) + return +} + +//递归无限树 +func GetMenuPowerThree(jurisd int, parentId int64, threeData []models.SystemMenu, menuStrMap, menuOperStrMap []string) []powerConfigList { + // treeList := []SystemMenuThree{} + treeListPower := []powerConfigList{} + for _, v := range threeData { + if v.ParentId == parentId { + var powerConfigCont powerConfigList + powerConfigCont.Id = v.Id + powerConfigCont.Title = v.Title + powerConfigCont.IsTrue = overallhandle.JudeInArray(v.Id, menuStrMap) + child := GetMenuPowerThree(jurisd, v.Id, threeData, menuStrMap, menuOperStrMap) + powerConfigCont.Child = child + isTrue, menuOper := MenuOperation(jurisd, v.Id) + if isTrue == true { + var operList []powerCont + for _, oper_val := range menuOper { + var operCont powerCont + operCont.Id = oper_val.OperId + operCont.Title = oper_val.OperTitle + operCont.IsTrue = overallhandle.JudeInArray(oper_val.OperId, menuOperStrMap) + operList = append(operList, operCont) + } + powerConfigCont.MenuOperation = operList + } + + treeListPower = append(treeListPower, powerConfigCont) + } + } + return treeListPower +} + +//获取菜单操作项目 +func MenuOperation(jurisd int, menuId int64) (isTrue bool, operation []models.MenuOperation) { + isTrue = false + // if jurisd != 1 { + // operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ? AND oper_id IN ?", menuId, global.Gva_Authority_Authentication).Order("oper_id desc").Find(&operation).Error + // if operErr == nil { + // isTrue = true + // } + // } else { + // operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operation).Error + // if operErr == nil { + // isTrue = true + // } + // } + operErr := overall.CONSTANT_DB_Master.Where("`menu_id` = ?", menuId).Order("oper_id desc").Find(&operation).Error + if operErr == nil { + isTrue = true + } + return +} diff --git a/api/version1/administrativeorganization/type.go b/api/version1/administrativeorganization/type.go index b294ecb..9eb272b 100644 --- a/api/version1/administrativeorganization/type.go +++ b/api/version1/administrativeorganization/type.go @@ -171,3 +171,20 @@ type govThreeType struct { overallhandle.GetId Level int `json:"level"` } + +/* +配置系统角色 +*/ +//权限列表基础字段 +type powerCont struct { + Id int64 `json:"id"` + Title string `json:"title"` + IsTrue bool `json:"istrue"` +} + +//权限树 +type powerConfigList struct { + powerCont + Child []powerConfigList `json:"child"` + MenuOperation []powerCont `json:"menuOperation"` +} diff --git a/api/version1/personnelapi/staff.go b/api/version1/personnelapi/staff.go index 2139e3a..3d36440 100644 --- a/api/version1/personnelapi/staff.go +++ b/api/version1/personnelapi/staff.go @@ -62,6 +62,7 @@ func (s *StaffApi) StaffList(c *gin.Context) { } var positionAry []peopleOutList errGorm := gormDb.Order("p.company ASC,p.deparment ASC,p.admin_org ASC,p.position ASC").Limit(requestData.PageSize).Offset(overallhandle.LimitPage(requestData.Page, requestData.PageSize)).Find(&positionAry).Error + fmt.Printf("%v\n", positionAry) for i, v := range positionAry { var getSpur models.Position getWhe := overallhandle.MapOut() @@ -223,6 +224,7 @@ func (s *StaffApi) AddStaff(c *gin.Context) { md5Token := md5JiaMi.Md5EncryptionAlgorithm() staffInfo.Password = md5Token + staffInfo.Key = overallhandle.TableNumber() peopleMasterErr := overall.CONSTANT_DB_HR.Create(&staffInfo).Error if peopleMasterErr != nil { overallhandle.Result(104, staffInfo, c) @@ -440,3 +442,57 @@ func familyPeople(number string, contAry []memberOfFamily) { overall.CONSTANT_DB_HR.Create(&familyAry) } } + +//分配权限 +func (s *StaffApi) AllocationOfRights(c *gin.Context) { + var requestData allocationOfRightsToRole + err := c.ShouldBindJSON(&requestData) + if err != nil { + overallhandle.Result(1, requestData.Id, c, "数据格式错误!") + return + } + if requestData.Id == "" { + overallhandle.Result(1, requestData.Id, c, "ID不能为空!") + return + } + if requestData.RoleId == "" { + overallhandle.Result(1, requestData.RoleId, c, "请选择角色!") + return + } + var setUserRole models.Personnel + judgeIsTrueWhere := overallhandle.MapOut() + judgeIsTrueWhere["id"] = requestData.Id + getUserErr := setUserRole.GetCont(judgeIsTrueWhere, "role") + if getUserErr != nil { + overallhandle.Result(105, getUserErr, c) + return + } + if setUserRole.Role != "" { + roleAry := strings.Split(setUserRole.Role, ",") + + if overallhandle.StringIsInMap(requestData.RoleId, roleAry) == false { + roleAry = append(roleAry, requestData.RoleId) + saveData := overallhandle.MapOut() + saveData["eite_time"] = time.Now().Unix() + saveData["role"] = strings.Join(roleAry, ",") + saveErr := setUserRole.EiteCont(judgeIsTrueWhere, saveData) + if saveErr != nil { + overallhandle.Result(106, saveErr, c) + return + } + overallhandle.Result(0, setUserRole, c) + } else { + overallhandle.Result(0, setUserRole, c) + } + } else { + saveData := overallhandle.MapOut() + saveData["eite_time"] = time.Now().Unix() + saveData["role"] = requestData.RoleId + saveErr := setUserRole.EiteCont(judgeIsTrueWhere, saveData) + if saveErr != nil { + overallhandle.Result(106, saveErr, c) + return + } + overallhandle.Result(0, setUserRole, c) + } +} diff --git a/api/version1/personnelapi/type.go b/api/version1/personnelapi/type.go index ef23224..8ea9b09 100644 --- a/api/version1/personnelapi/type.go +++ b/api/version1/personnelapi/type.go @@ -135,3 +135,9 @@ type jobAttber struct { Jobid int64 `json:"jobid" gorm:"column:jobid;type:bigint(20) unsigned;default:0;not null;comment:职务分类Id"` JobName string `json:"jobname" gorm:"column:jobname;type:varchar(255) unsigned;default:'';not null;comment:职务分类名称"` } + +//配权 +type allocationOfRightsToRole struct { + Id string `json:"id"` + RoleId string `json:"roleid"` +} diff --git a/api/version1/shiyan/shiyan.go b/api/version1/shiyan/shiyan.go index 8f2b40f..a7eae85 100644 --- a/api/version1/shiyan/shiyan.go +++ b/api/version1/shiyan/shiyan.go @@ -2,6 +2,8 @@ package shiyan import ( "fmt" + "hr_server/models" + "hr_server/overall" "hr_server/overall/overallhandle" "time" @@ -9,18 +11,276 @@ import ( ) func (s *ShiYan) ShiyanCont(c *gin.Context) { - var requestData Jieshou - c.ShouldBindJSON(&requestData) - if requestData.Time == "" { - requestData.Time = overallhandle.UnixTimeToDay(time.Now().Unix(), 11) - } - entryData, _ := overallhandle.DateToTimeStamp(fmt.Sprintf("%v 00:00:00", requestData.Time)) - planformalData := overallhandle.GetFutureMonthTime(entryData, requestData.ProbationPeriod, 2) + // var requestData Jieshou + // c.ShouldBindJSON(&requestData) + // if requestData.Time == "" { + // requestData.Time = overallhandle.UnixTimeToDay(time.Now().Unix(), 11) + // } + // entryData, _ := overallhandle.DateToTimeStamp(fmt.Sprintf("%v 00:00:00", requestData.Time)) + // planformalData := overallhandle.GetFutureMonthTime(entryData, requestData.ProbationPeriod, 2) - timeStr := overallhandle.UnixTimeToDay(planformalData, 11) + // timeStr := overallhandle.UnixTimeToDay(planformalData, 11) + number := overallhandle.TableNumber() out := overallhandle.MapOut() - out["time"] = requestData.Time - out["entryData"] = entryData - out["timeStr"] = timeStr - overallhandle.Result(0, out, c) + out["time"] = number + fmt.Printf("Number ----->%v\n", number) + // out["time"] = requestData.Time + // out["entryData"] = entryData + // out["timeStr"] = timeStr + + var eitePersonnel models.Personnel + eiteCont := overallhandle.MapOut() + eiteCont["role"] = 58 + eiteCont["eite_time"] = time.Now().Unix() + eiteErr := eitePersonnel.EiteCont("`role` = ''", eiteCont) + overallhandle.Result(0, eiteErr, c) +} + +//人员迁移 +func (s *ShiYan) PersonnelMigration(c *gin.Context) { + var oldManCount int64 + err := overall.CONSTANT_DB_Master.Model(&models.WorkMan{}).Where("wm_group = 3").Pluck("COALESCE(COUNT(wm_id), 0) as countid", &oldManCount).Error + if err != nil { + overallhandle.Result(1, err, c, "没有要迁移的人员!") + return + } + //分片 + var pian int64 = 0 + pian = oldManCount / 100 + if oldManCount%100 > 0 { + pian++ + } + var writePeople peopleQianyi + for i := 1; int64(i) <= pian+1; i++ { + synPro.Add(1) + go writePeople.writeUser(i, 100) + // if i > 1 { + // break + // } + } + synPro.Wait() + + readDataMap, allUser := writePeople.readMyDayData() + outMap := overallhandle.MapOut() + outMap["count"] = len(readDataMap) + outMap["list"] = readDataMap + outMap["allUser"] = allUser + overallhandle.Result(0, outMap, c) +} + +//分片写入人员 +func (p *peopleQianyi) writeUser(page, pagesize int) { + // p.mutext.Lock() + // defer p.mutext.Unlock() + + offsetVal := overallhandle.LimitPage(page, pagesize) + var oldUser []models.PersonalDetails + err := overall.CONSTANT_DB_Master.Model(&models.WorkMan{}).Select("worker_man.*,wmd.*").Joins("left join worker_man_data as wmd on wmd.wmd_key = worker_man.wm_key").Where("wm_group = 3").Limit(pagesize).Offset(offsetVal).Find(&oldUser).Error + if err != nil { + return + } + // jsonVal, _ := json.Marshal(oldUser) + fmt.Printf("page=======>%v=====>%v\n", page, offsetVal) + //员工主表 + var staffAry []models.Personnel //主资料库 + var staffAttributeAry []models.PersonnelContent //人物属性库 + for _, v := range oldUser { + if len(v.Number) > 4 { + company, adminOrg, positionId, deparment := getUserOrgSchool(v.Group, v.DepartmentId, v.WorkshopId, v.PostId) + var staffInfo models.Personnel + staffInfo.Number = v.Number //员工工号 + staffInfo.Name = v.Name //姓名 + staffInfo.HireClass = 1 //雇佣类型(1:雇佣入职;2:再入职;) + staffInfo.Position = positionId //职位 + // //获取职务信息 + jobCont, jobErr := getJobInfo(positionId) + if jobErr == nil { + staffInfo.PositionLevel = jobCont.Dutid //职位等级 + staffInfo.JobClass = jobCont.Jobid //职务分类 + } + staffInfo.AdminOrg = adminOrg //所属行政组织 + staffInfo.Company = company //入职公司 + staffInfo.EmpType = 4 //用工关系(1:实习生;2:待分配;3:试用员工;4:正式员工;5:停薪留职;6:退休;7:辞退;8:离职) + staffInfo.Deparment = deparment //部门 + staffInfo.Time = time.Now().Unix() + staffInfo.EiteTime = time.Now().Unix() + // staffInfo.PositionGrade = v.PositionGrade //入职职等 + staffInfo.Icon = v.Icon //头像 + + // staffInfo.Password = v.Password + + staffInfo.Wechat = v.WechatId + staffInfo.WorkWechat = v.WorkWechatId + + weChatOpenId := v.WechatId + if v.WorkWechatId != "" { + weChatOpenId = v.WorkWechatId + } + //获取微信头像 + wechatCont, _ := GetWorkWechatDuiZhao(weChatOpenId) + staffInfo.Icon = wechatCont.Avatar //头像 + + staffInfo.Password = v.Password //密码 + staffInfo.State = v.State + staffInfo.Key = v.Key + staffAry = append(staffAry, staffInfo) + + var staffAttribute models.PersonnelContent + staffAttribute.Number = v.Number + staffAttribute.Idcardno = v.CertificatesNum + staffAttribute.Mobilephone = v.Tel + staffAttribute.Gender = v.Gender + staffAttribute.Birthday = v.Birthday + // staffAttribute.Myfolk = contData.Nation + // staffAttribute.Nativeplace = contData.NativePlace + staffAttribute.Health = 1 + staffAttribute.Maritalstatus = 1 + staffAttribute.Currentresidence = v.Addrest + staffAttribute.Time = time.Now().Unix() + staffAttribute.Constellation = 1 + staffAttribute.Isdoubleworker = 2 + staffAttribute.Isveterans = 2 + // staffAttribute.Veteransnumber = contData.Veteransnumber + staffAttribute.Jobstartdate = time.Now().Unix() + staffAttribute.Entrydate = v.EntryTime + staffAttribute.Probationperiod = 3 + staffAttribute.Planformaldate = time.Now().Unix() + staffAttribute.PoliticalOutlook = 1 + + staffAttributeAry = append(staffAttributeAry, staffAttribute) + } + + // p.dataMap = append(p.dataMap, staffInfo) + // p.userAll = append(p.userAll, staffAttribute) + // break + } + if len(staffAry) > 0 { + addErrMaster := overall.CONSTANT_DB_HR.Model(&models.Personnel{}).Create(&staffAry).Error + if addErrMaster == nil { + if len(staffAttributeAry) > 0 { + overall.CONSTANT_DB_HR.Model(&models.PersonnelContent{}).Create(&staffAttributeAry) + } + } + } + // fmt.Printf("%v\n", staffAry) + synPro.Done() +} + +//获取企业微信对照表 +func GetWorkWechatDuiZhao(openid string) (userInfoStruct models.WechatUsers, isTrue bool) { + isTrue = false + myErr := overall.CONSTANT_DB_Wechat.Where("userid = ?", openid).First(&userInfoStruct).Error + if myErr == nil { + isTrue = true + } + return +} + +//获取人员组织架构信息 +func getUserOrgSchool(group, depart, workid, position int64) (gro, org, positionId int64, department string) { + groupAry := map[int64]int64{3: 2} + for gi, gv := range groupAry { + if gi == group { + gro = gv + break + } + } + //部门对照 + //部门 + var buMen string + // departAry := map[int64]string{ + // 11: "3", + // 12: "4", + // 9: "5", + // 14: "6", + // 13: "7", + // 15: "8", + // 5: "9", + // 6: "10", + // 8: "11", + // 2: "13", + // 1: "14", + // 3: "15", + // 16: "16", + // 17: "17", + // 39: "19", + // 50: "20", + // 7: "12,41", + // 4: "12,42", + // } + departAry := map[int64]string{ + 11: "3", + 12: "4", + 9: "5", + 14: "6", + 13: "7", + 15: "8", + 5: "9", + 6: "10", + 8: "11", + 2: "13", + 1: "14", + 3: "15", + 16: "16", + 17: "17", + 39: "19", + 50: "20", + 7: "41", + 4: "42", + } + for di, dv := range departAry { + if depart == di { + buMen = dv + break + } + } + _, org = getOrgSchool(workid) + // departId, org := getOrgSchool(workid) + // if departId != 0 { + // buMen = fmt.Sprintf("%v,%v", buMen, departId) + // } + department = buMen + + positionId = getHrPosition(position) + return +} + +//获取组织架构对照 +func getOrgSchool(id int64) (deparmentId, orgId int64) { + var orgInfo outOrgCont + err := overall.CONSTANT_DB_HR.Model(&models.AdministrativeOrganization{}).Select("id,organization_type,superior").Where("schoole = ?", id).First(&orgInfo).Error + if err != nil { + deparmentId = 0 + orgId = 0 + return + } + if orgInfo.OrganizationType == 5 { + var suoOrgInfo models.AdministrativeOrganization + whereAry := overallhandle.MapOut() + whereAry["id"] = orgInfo.Superior + supErr := suoOrgInfo.GetCont(whereAry) + if supErr == nil { + deparmentId = suoOrgInfo.Id + } + } + orgId = orgInfo.Id + return +} + +//获取hr系统中的职务 +func getHrPosition(posId int64) int64 { + var id int64 + err := overall.CONSTANT_DB_HR.Model(&models.Position{}).Select("id").Where("`school` = ?", posId).First(&id).Error + if err == nil { + return id + } + return 0 +} + +//获取职务相关属性 +func getJobInfo(jobId int64) (cont jobAttber, err error) { + var positionInfo models.Position + // err = overall.CONSTANT_DB_HR.Table(fmt.Sprintf("%s p", positionInfo.TableName())).Select("p.id,p.number,p.name,p.person_in_charge,d.id as dutid,d.name as dutname,d.number as dutnumber,j.id as jobid,j.name as jobname").Joins("left join duties as d on d.id = p.duties").Joins("left join job_class as j on j.id = d.job_type").Where("`p`.`id` = ?", jobId).First(&cont).Error + err = overall.CONSTANT_DB_HR.Model(&positionInfo).Select("position.id,position.number,position.name,position.person_in_charge,d.id as dutid,d.name as dutname,d.number as dutnumber,j.id as jobid,j.name as jobname").Joins("left join duties as d on d.id = position.duties").Joins("left join job_class as j on j.id = d.job_type").Where("`position`.`id` = ?", jobId).First(&cont).Error + return } diff --git a/api/version1/shiyan/type.go b/api/version1/shiyan/type.go index 2464c75..eee12df 100644 --- a/api/version1/shiyan/type.go +++ b/api/version1/shiyan/type.go @@ -1,11 +1,15 @@ package shiyan import ( + "hr_server/models" "hr_server/overall/overallhandle" + "sync" "github.com/gin-gonic/gin" ) +var synPro = sync.WaitGroup{} + //人员API type ShiYan struct{} @@ -20,3 +24,41 @@ type Jieshou struct { Time string `json:"time"` ProbationPeriod int `json:"probationperiod"` //试用期(月) } + +//输出知行学院的人员信息 +type schoolUser struct { + models.WorkMan +} + +//输出迁移组织架构 +type outOrgCont struct { + Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` + 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:行政组织类型"` +} + +type peopleQianyi struct { + dataMap []models.Personnel + userAll []models.PersonnelContent + mutext sync.RWMutex +} + +//读取锁数据 +func (d *peopleQianyi) readMyDayData() ([]models.Personnel, []models.PersonnelContent) { + d.mutext.RLock() + defer d.mutext.RUnlock() + return d.dataMap, d.userAll +} + +//职务相关 +type jobAttber 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(255) unsigned;default:'';not null;comment:编号"` + Name string `json:"name" gorm:"column:name;type:varchar(255) unsigned;default:'';not null;comment:名称"` + PersonInCharge int `json:"personincharge" gorm:"column:person_in_charge;type:tinyint(1) unsigned;default:0;not null;comment:是否为本部门负责人"` + Dutid int64 `json:"dutid" gorm:"column:dutid;type:bigint(20) unsigned;default:0;not null;comment:职务Id"` + Dutname string `json:"dutname" gorm:"column:dutname;type:varchar(255) unsigned;default:'';not null;comment:职务名称"` + DutNumber string `json:"dutnumber" gorm:"column:dutnumber;type:varchar(255) unsigned;default:'';not null;comment:职务编号"` + Jobid int64 `json:"jobid" gorm:"column:jobid;type:bigint(20) unsigned;default:0;not null;comment:职务分类Id"` + JobName string `json:"jobname" gorm:"column:jobname;type:varchar(255) unsigned;default:'';not null;comment:职务分类名称"` +} diff --git a/apirouter/personnel/people.go b/apirouter/personnel/people.go index 96dc577..8070e7a 100644 --- a/apirouter/personnel/people.go +++ b/apirouter/personnel/people.go @@ -11,9 +11,10 @@ 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.GET("", apiHandle.Index) //入口 + apiRouter.POST("", apiHandle.Index) //入口 + apiRouter.POST("stafflist", apiHandle.StaffList) //人员列表 + apiRouter.POST("addstaff", apiHandle.AddStaff) //添加人员档案 + apiRouter.POST("allocationofrights", apiHandle.AllocationOfRights) //分配权限 } } diff --git a/apirouter/shiyanrouter/shiyan.go b/apirouter/shiyanrouter/shiyan.go index dfbcc53..c9d1b31 100644 --- a/apirouter/shiyanrouter/shiyan.go +++ b/apirouter/shiyanrouter/shiyan.go @@ -11,8 +11,9 @@ func (p *ShiyanApiRouter) InitRouterGroup(route *gin.RouterGroup) { apiRouter := route.Group("shiyan") var apiHandle = version1.AppApiInlet.ShiyanApi { - apiRouter.GET("", apiHandle.Index) //入口 - apiRouter.POST("", apiHandle.Index) //入口 - apiRouter.POST("shiyan", apiHandle.ShiyanCont) //人员列表 + apiRouter.GET("", apiHandle.Index) //入口 + apiRouter.POST("", apiHandle.Index) //入口 + apiRouter.POST("shiyan", apiHandle.ShiyanCont) //人员列表 + apiRouter.POST("personnelmigration", apiHandle.PersonnelMigration) //人员迁移 } } diff --git a/hr_server.exe b/hr_server.exe index 4d4f48b..c24c4dd 100644 Binary files a/hr_server.exe and b/hr_server.exe differ diff --git a/models/administrative_organization.go b/models/administrative_organization.go index ea1e8da..960f6fc 100644 --- a/models/administrative_organization.go +++ b/models/administrative_organization.go @@ -16,6 +16,8 @@ type AdministrativeOrganization struct { 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:微信组织架构对照码"` + SuperiorSun string `json:"superiorsun" gorm:"column:superior_sun;type:mediumtext;comment:级联ID"` + Schoole int64 `json:"schoole" gorm:"column:schoole;type:bigint(20) unsigned;default:0;not null;comment:原知行学院对照码"` } func (AdministrativeOrganization *AdministrativeOrganization) TableName() string { @@ -23,13 +25,13 @@ func (AdministrativeOrganization *AdministrativeOrganization) TableName() string } //编辑行政组织内容 -func (cont *AdministrativeOrganization) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) { +func (cont *AdministrativeOrganization) EiteCont(whereMap interface{}, saveData 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) { +func (cont *AdministrativeOrganization) GetCont(whereMap interface{}, field ...string) (err error) { gormDb := overall.CONSTANT_DB_HR.Model(&cont) if len(field) > 0 { fieldStr := strings.Join(field, ",") @@ -41,7 +43,7 @@ func (cont *AdministrativeOrganization) GetCont(whereMap map[string]interface{}, } //根据条件获取总数 -func (cont *AdministrativeOrganization) CountCont(whereMap map[string]interface{}) (countId int64) { +func (cont *AdministrativeOrganization) CountCont(whereMap interface{}) (countId int64) { overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Count(&countId) return } diff --git a/models/myuser.go b/models/myuser.go new file mode 100644 index 0000000..08783db --- /dev/null +++ b/models/myuser.go @@ -0,0 +1,73 @@ +package models + +//个人信息主表 +type WorkMan struct { + Id int64 `json:"id" gorm:"column:wm_id;type:bigint(20);;primaryKey;unique;not null;autoIncrement;index"` + Number string `json:"number" gorm:"column:wm_number;type:varchar(10);not null;comment:员工编号"` + Password string `json:"pwd" gorm:"column:wm_pwd;type:varchar(50);not null;comment:密码"` + DepartmentId int64 `json:"departmentid" gorm:"column:wm_bf_id;type:bigint(20) unsigned;default:0;not null;comment:分厂"` + WorkshopId int64 `json:"workshopid" gorm:"column:wm_ws_id;type:bigint(20) unsigned;default:0;not null;comment:工段"` + PostId int64 `json:"postid" gorm:"column:wm_pt_id;type:bigint(20) unsigned;default:0;not null;comment:职务"` + Key int64 `json:"key" gorm:"column:wm_key;type:bigint(50) unsigned;default:0;not null;comment:唯一识别码"` + State int `json:"state" gorm:"column:wm_set;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` + HireSet int `json:"hireset" gorm:"column:wm_hire_set;type:tinyint(1) unsigned;default:1;not null;comment:雇佣状态(1:在职;2:离职)"` + Time int64 `json:"time" gorm:"column:wm_time;type:bigint(20) unsigned;default:0;not null;comment:添加事件"` + EiteTime int64 `json:"eitetime" gorm:"column:wm_eite_time;type:bigint(20) unsigned;default:0;not null;comment:修改事件"` + UserId int64 `json:"userid" gorm:"column:wm_user_id;type:bigint(50) unsigned;default:0;not null;comment:录入人"` + QuitTime int64 `json:"quitime" gorm:"column:wm_quit_time;type:bigint(20) unsigned;default:0;not null"` + Group int64 `json:"group" gorm:"column:wm_group;type:bigint(20) unsigned;default:0;not null;comment:集团公司"` + Soptcheck int `json:"soptcheck" gorm:"column:wm_soptcheck;type:tinyint(1) unsigned;default:1;not null"` + Tema int64 `json:"tema" gorm:"column:wm_tema;type:bigint(20) unsigned;default:0;not null;comment:班组"` + IsOne int `json:"isone" gorm:"column:wm_one;type:tinyint(1) unsigned;default:1;not null;comment:第一次登陆"` + WorkWechatId string `json:"workwechatid" gorm:"column:qywx_key;type:varchar(255);not null;comment:企业微信KEY"` + WechatId string `json:"wechatid" gorm:"column:wx_key;type:varchar(255);not null;comment:微信KEY"` +} + +func (WorkMan *WorkMan) TableName() string { + return "worker_man" +} + +//个人信息附表 +type WorkManAttribute struct { + KeyAttr int64 `json:"key" gorm:"column:wmd_key;type:bigint(50) unsigned;default:0;not null;comment:唯一识别符"` + Name string `json:"name" gorm:"column:wmd_name;type:varchar(50);not null;comment:姓名"` + Gender int `json:"gender" gorm:"column:wmd_gender;type:tinyint(1) unsigned;default:1;not null;comment:性别(1:男;2:女)"` + Age int `json:"age" gorm:"column:wmd_age;type:tinyint(3) unsigned;default:1;not null;comment:年龄"` + Tel string `json:"tel" gorm:"column:wmd_tel;type:varchar(25);not null;comment:联系方式"` + Category int `json:"category" gorm:"column:wmd_category;type:tinyint(1) unsigned;default:1;not null;comment:人员类别(1:正式工;2:合同工;3:实习生)"` + CertificatesType int `json:"certificatesType" gorm:"column:wmd_certificates_type;type:tinyint(1) unsigned;default:1;not null;comment:证件类型(1:身份证;2:驾驶证;3:军人证;4:护照;5:居住证)"` + CertificatesNum string `json:"certificatesNum" gorm:"column:wmd_certificates_number;type:varbinary(50);comment:证件编号"` + Birthday int64 `json:"birthday" gorm:"column:wmd_birthday;type:bigint(20) unsigned;default:0;not null;comment:出生日期"` + EntryTime int64 `json:"entryTime" gorm:"column:wmd_entry_time;type:bigint(20) unsigned;default:0;not null;comment:入职日期"` + QuitTimeAttr int64 `json:"quitTime" gorm:"column:wmd_quit_time;type:bigint(20) unsigned;default:0;not null;comment:离职日期"` + EiteTimeAttr int64 `json:"eiteTime" gorm:"column:wmd_eite_time;type:bigint(20) unsigned;default:0;not null;comment:修改时间"` + Addrest string `json:"addrest" gorm:"column:wmd_addrest;type:varchar(255);comment:家庭住址"` + Icon string `json:"icon" gorm:"column:wmd_icon;type:varchar(255);comment:照片"` + NickName string `json:"nickName" gorm:"column:wmd_nickname;type:varchar(255);comment:昵称"` +} + +func (WorkManAttribute *WorkManAttribute) TableName() string { + return "worker_man_data" +} + +//个人详细信息 +type PersonalDetails struct { + WorkMan + WorkManAttribute +} + +//Redis身份识别 +type RedisUserInfo struct { + Id string `json:"id"` + Number string `json:"number"` + DepartmentId string `json:"departmentid"` + WorkshopId string `json:"workshopid"` + PostId string `json:"postid"` + Key string `json:"key"` + Group string `json:"group"` + Tema string `json:"tema"` + WorkWechatId string `json:"workwechatid"` + WechatId string `json:"wechatid"` + Name string `json:"name"` + NickName string `json:"nickname"` +} diff --git a/models/personnel.go b/models/personnel.go index 1fec48c..57794c8 100644 --- a/models/personnel.go +++ b/models/personnel.go @@ -21,11 +21,13 @@ type Personnel struct { EiteTime int64 `json:"eitetime" gorm:"column:eite_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` JobClass int64 `json:"jobclass" gorm:"column:job_class;type:bigint(20) unsigned;default:2;not null;comment:职务分类"` PositionGrade int64 `json:"positiongrade" gorm:"column:position_grade;type:bigint(20) unsigned;default:0;not null;comment:入职职等"` - Role string `json:"role" gorm:"column:role;type:longtext;comment:变动原因"` + Role string `json:"role" gorm:"column:role;type:longtext;comment:角色"` Wechat string `json:"wechat" gorm:"column:wechat;type:varchar(255) unsigned;default:'';not null;comment:微信UserId"` WorkWechat string `json:"workwechat" gorm:"column:work_wechat;type:varchar(255) unsigned;default:'';not null;comment:企业微信UserId"` Icon string `json:"icon" gorm:"column:icon;type:varchar(255) unsigned;default:'';not null;comment:头像"` Password string `json:"password" gorm:"column:password;type:varchar(255) unsigned;default:'';not null;comment:密码"` + State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)` + Key int64 `json:"key" gorm:"column:key;type:bigint(50) unsigned;default:0;not null;comment:key"` } func (Personnel *Personnel) TableName() string { diff --git a/models/position.go b/models/position.go index dcd0d84..ed82900 100644 --- a/models/position.go +++ b/models/position.go @@ -17,6 +17,9 @@ type Position struct { 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:部门"` + MenuPermit string `json:"menupermit" gorm:"column:menu_permit;type:longtext;comment:菜单许可证"` + ButtonPermit string `json:"buttonpermit" gorm:"column:button_permit;type:longtext;comment:按钮许可"` + School int64 `json:"school" gorm:"column:school;type:bigint(20) unsigned;default:0;not null;comment:部门"` } func (Position *Position) TableName() string { @@ -24,13 +27,13 @@ func (Position *Position) TableName() string { } //编辑职务分类内容 -func (cont *Position) EiteCont(whereMap map[string]interface{}, saveData map[string]interface{}) (err error) { +func (cont *Position) EiteCont(whereMap 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) { +func (cont *Position) GetCont(whereMap interface{}, field ...string) (err error) { gormDb := overall.CONSTANT_DB_HR.Model(&cont) if len(field) > 0 { fieldStr := strings.Join(field, ",") @@ -42,7 +45,7 @@ func (cont *Position) GetCont(whereMap map[string]interface{}, field ...string) } //根据条件获取总数 -func (cont *Position) CountCont(whereMap map[string]interface{}) (countId int64) { +func (cont *Position) CountCont(whereMap interface{}) (countId int64) { overall.CONSTANT_DB_HR.Model(&cont).Where(whereMap).Count(&countId) return } diff --git a/models/wechatUsers.go b/models/wechatUsers.go new file mode 100644 index 0000000..85b6a4a --- /dev/null +++ b/models/wechatUsers.go @@ -0,0 +1,34 @@ +package models + +//企业微信人员架构 +type WechatUsers struct { + Uid int64 `json:"uid" gorm:"column:u_id;type:bigint(20) unsigned;default:0;not null;comment:id"` + Userid string `json:"userid" gorm:"column:userid;type:varchar(255);not null;comment:wechat user id企业微信用户ID"` + Name string `json:"name" gorm:"column:name;type:varchar(100);not null;comment:姓名"` + Department string `json:"department" gorm:"column:department;type:text;comment:归属部门json"` + Position string `json:"position" gorm:"column:position;type:varchar(255);not null;comment:企业微信职务"` + Mobile string `json:"mobile" gorm:"column:mobile;type:varchar(100);not null;comment:企业微信电话"` + Gender int `json:"gender" gorm:"column:gender;type:tinyint(1) unsigned;default:1;not null;comment:性别。1表示男性,2表示女性"` + Email string `json:"email" gorm:"column:email;type:varchar(255);not null;comment:邮箱"` + Avatar string `json:"avatar" gorm:"column:avatar;type:varchar(255);not null;comment:员工头像"` + Status int `json:"status" gorm:"column:status;type:tinyint(1) unsigned;default:1;not null;comment:激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。"` + Extattr string `json:"extattr" gorm:"column:extattr;type:mediumtext;comment:企业微信员工扩展属性"` + MainDepartment int64 `json:"main_department" gorm:"column:main_department;type:int(8) unsigned;default:0;not null;comment:主部门"` + QrCode string `json:"qr_code" gorm:"column:qr_code;type:text;comment:员工个人二维码,扫描可添加为外部联系人(注意返回的是一个url,可在浏览器上打开该url以展示二维码);第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取"` + IsLeaderInDept string `json:"is_leader_in_dept" gorm:"column:is_leader_in_dept;type:text;comment:表示在所在的部门内是否为上级。0-否;1-是。是一个列表,数量必须与department一致。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取"` + ThumbAvatar string `json:"thumb_avatar" gorm:"column:thumb_avatar;type:varchar(255);not null;comment:头像缩略图url"` + UserNumber string `json:"user_number" gorm:"column:user_number;type:varchar(8);not null;comment:工号"` + SysBf int64 `json:"sys_bf" gorm:"column:sys_bf;type:int(20) unsigned;default:0;not null;comment:系统分厂"` + SysWs int64 `json:"sys_ws" gorm:"column:sys_ws;type:int(20) unsigned;default:0;not null;comment:系统工段"` + SysPs int64 `json:"sys_ps" gorm:"column:sys_ps;type:int(20) unsigned;default:0;not null;comment:系统职务"` + WmTema int64 `json:"wm_tema" gorm:"column:wm_tema;type:int(20) unsigned;default:0;not null;comment:系统班组"` + IsAdmin int `json:"is_admin" gorm:"column:is_admin;type:tinyint(1) unsigned;default:1;not null;comment:管理员1、否;2:是"` + IsRole int64 `json:"is_role" gorm:"column:is_role;type:int(20) unsigned;default:0;not null;comment:角色"` + Pwd string `json:"pwd" gorm:"column:pwd;type:varchar(255);not null;comment:密码"` + Time int64 `json:"time" gorm:"column:time;type:int(20) unsigned;default:0;not null;comment:写入时间"` +} + +func (WechatUsers *WechatUsers) TableName() string { + // return "wechatusers_es" + return "wechatusers" +} diff --git a/overall/overallhandle/overall_handle.go b/overall/overallhandle/overall_handle.go index 9ed5241..30a764c 100644 --- a/overall/overallhandle/overall_handle.go +++ b/overall/overallhandle/overall_handle.go @@ -3,12 +3,14 @@ package overallhandle import ( "bytes" "crypto/md5" + "crypto/rand" "crypto/sha1" "encoding/hex" "fmt" "hr_server/models" "hr_server/overall" "math" + "math/big" "strconv" "time" @@ -16,6 +18,19 @@ import ( ) //全局函数处理 +//编号,纯数字 +func TableNumber(class ...string) (number int64) { + result, _ := rand.Int(rand.Reader, big.NewInt(8999)) + numberTeam := result.Int64() + 1000 + numberStr := fmt.Sprintf("%v%v", time.Now().Unix(), numberTeam) + if len(class) > 0 { + resultLong, _ := rand.Int(rand.Reader, big.NewInt(8999999)) + numberTeamLong := resultLong.Int64() + 1000000 + numberStr = fmt.Sprintf("%v%v", time.Now().Unix(), numberTeamLong) + } + number, _ = strconv.ParseInt(numberStr, 10, 64) + return +} //初始化map func MapOut() (data map[string]interface{}) { @@ -391,3 +406,29 @@ func GetFutureMonthTime(timeStamp int64, futureTime, class int) (dateStr int64) dateStr = addDate.Unix() return } + +//判断字符串是否在切片中 +func StringIsInMap(str string, strAry []string) bool { + if len(strAry) > 0 { + for _, v := range strAry { + if v == str { + return true + } + } + } + return false +} + +//判断值是否在数组中 +func JudeInArray(id int64, ary []string) (isTrue bool) { + isTrue = false + for _, val := range ary { + valint64, err := strconv.ParseInt(val, 10, 64) + if err == nil { + if id == valint64 { + isTrue = true + } + } + } + return +}