package menus import ( "appPlatform/middleware/grocerystore" "appPlatform/models/modelAppPlatform" "appPlatform/models/modelshr" "appPlatform/models/modelssystempermission" "appPlatform/models/teamlog" "appPlatform/overall" "appPlatform/overall/publicmethod" "encoding/json" "errors" "fmt" "sort" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) // 全局变量 var allRulesLog teamlog.TeamsLog /* * @ 作者: 秦东 @ 时间: 2023-05-22 13:26:16 @ 功能: 获取路由树 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GetMenusThree(c *gin.Context) { var menusList []modelAppPlatform.Menus err := overall.CONSTANT_DB_AppPlatform.Where("`type` IN ? AND `visible` = ? AND `outside` IN ?", []int{1, 2, 3}, 1, []int{1, 3}).Order("sort ASC").Find(&menusList).Error if err != nil && len(menusList) < 1 { publicmethod.Result(1, err, c, "没有路由!") return } // sort.Slice(menusList, func(i, j int) bool { // return menusList[i].Sort > menusList[j].Sort // }) routerThree := publicmethod.GetMenuRouterThree(0, menusList) publicmethod.Result(0, routerThree, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-22 15:36:33 @ 功能: 获取菜单列表树 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GetMenusListTree(c *gin.Context) { // var requestData ShearMenu // c.ShouldBindJSON(&requestData) // c.ShouldBindQuery(&requestData) // id := c.Query("id") requestData := c.Query("keywords") fmt.Printf("没有路由!=====>%v\n", requestData) var menusList []modelAppPlatform.Menus gormDb := overall.CONSTANT_DB_AppPlatform.Where("visible IN ?", []int{1, 2}) if requestData != "" { gormDb = gormDb.Where("`name` LIKE ?", "%"+requestData+"%") } err := gormDb.Find(&menusList).Error if err != nil && len(menusList) < 1 { publicmethod.Result(1, err, c, "没有路由!") return } sort.Slice(menusList, func(i, j int) bool { return menusList[i].Sort < menusList[j].Sort }) routerThree := publicmethod.GetAppMenuThree(0, menusList) publicmethod.Result(0, routerThree, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-22 16:21:11 @ 功能: 菜单下拉列表 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) MenuOptions(c *gin.Context) { var menusList []modelAppPlatform.Menus err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Select("`id`,`name`,`parentId`").Where("visible IN ?", []int{1, 2}).Find(&menusList).Error if err != nil && len(menusList) < 1 { publicmethod.Result(1, err, c, "没有路由!") return } routerThree := publicmethod.GetMenuOptionsThree(0, menusList) publicmethod.Result(0, routerThree, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-22 16:40:42 @ 功能: 新增菜单 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) AddNewMenu(c *gin.Context) { var requestData AddNewMenuCont c.ShouldBindJSON(&requestData) if requestData.Name == "" { publicmethod.Result(1, requestData, c, "请输入菜单名称!") return } if requestData.Visible == 0 { requestData.Visible = 1 } if requestData.Sort == 0 { requestData.Sort = 50 } if requestData.Outside == 0 { requestData.Sort = 1 } types := publicmethod.MenuTypeToInt(requestData.Types) var menuCont modelAppPlatform.Menus menuCont.Name = requestData.Name //菜单名称"` menuCont.Types = types //菜单类型(1-菜单;2-目录;3-外链;4-按钮权限"` menuCont.Path = requestData.Path //路由路径"` if types == 2 { if requestData.ParentId == 0 { menuCont.Component = "Layout" //组件路径(vue页面完整路径,省略.vue后缀)"` } else { menuCont.Component = "public/index" //组件路径(vue页面完整路径,省略.vue后缀)"` } } else { menuCont.Component = requestData.Component //组件路径(vue页面完整路径,省略.vue后缀)"` } menuCont.Perm = publicmethod.GetUUid(3) //权限标识"` menuCont.Visible = requestData.Visible //显示状态(1:显示;2:隐藏,3:删除)"` menuCont.Sort = requestData.Sort //排序(数字越小排名越靠前))"` menuCont.Icon = requestData.Icon //菜单图标"` if types != 1 { menuCont.Redirect = requestData.Redirect //跳转路径"` } menuCont.ParentId = requestData.ParentId //父菜单ID"` menuCont.Time = time.Now().Unix() //创建时间"` menuCont.Outside = requestData.Outside //1:内部使用;2:外部使用;3:内外使用"` err := overall.CONSTANT_DB_AppPlatform.Create(&menuCont).Error if err != nil { publicmethod.Result(104, err, c) return } publicmethod.Result(0, err, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-23 16:21:32 @ 功能: 查看菜单 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GetOneMenuCont(c *gin.Context) { var requestData publicmethod.PublicId err := c.ShouldBindJSON(&requestData) if err != nil { publicmethod.Result(100, err, c) return } if requestData.Id == "" { publicmethod.Result(1, requestData, c, "未知菜单!") return } var menuCont modelAppPlatform.Menus err = menuCont.GetCont(map[string]interface{}{"`id`": requestData.Id}) if err != nil { publicmethod.Result(107, err, c) return } var sendCont EditMenuCont sendCont.Id = menuCont.Id sendCont.ParentId = menuCont.ParentId //父菜单ID sendCont.Name = menuCont.Name //菜单名称 sendCont.Visible = menuCont.Visible //菜单是否可见(1:是;2:否;) sendCont.Icon = menuCont.Icon //菜单图标 sendCont.Sort = menuCont.Sort //排序 sendCont.Component = menuCont.Component //组件路径 sendCont.Path = menuCont.Path //路由路径 sendCont.Redirect = menuCont.Redirect //跳转路由路径 sendCont.Types = publicmethod.MenuType(menuCont.Types) //菜单类型 sendCont.Outside = menuCont.Outside publicmethod.Result(0, sendCont, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-23 16:44:14 @ 功能: 修改菜单 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) EditMenusCont(c *gin.Context) { var requestData EditMenuCont c.ShouldBindJSON(&requestData) if requestData.Id == 0 { publicmethod.Result(1, requestData, c, "未知菜单!") return } if requestData.Name == "" { publicmethod.Result(1, requestData, c, "请输入菜单名称!") return } if requestData.Visible == 0 { requestData.Visible = 1 } if requestData.Sort == 0 { requestData.Sort = 50 } if requestData.Outside == 0 { requestData.Outside = 1 } whe := publicmethod.MapOut[string]() whe["`id`"] = requestData.Id var menuCont modelAppPlatform.Menus err := menuCont.GetCont(whe) if err != nil { publicmethod.Result(107, err, c) return } editCont := publicmethod.MapOut[string]() if requestData.Name != menuCont.Name { editCont["name"] = requestData.Name } types := publicmethod.MenuTypeToInt(requestData.Types) if types != menuCont.Types { editCont["type"] = types } if requestData.Path != menuCont.Path { editCont["path"] = requestData.Path } if requestData.Component != menuCont.Component { if types != menuCont.Types && types == 2 { if requestData.ParentId != 0 { editCont["component"] = "public/index" } else { editCont["component"] = "Layout" } } else { editCont["component"] = requestData.Component } } if requestData.Visible == 0 { requestData.Visible = 1 } if requestData.Visible != menuCont.Visible { editCont["visible"] = requestData.Visible } if requestData.Sort == 0 { requestData.Sort = 50 } if requestData.Sort != menuCont.Sort { editCont["sort"] = requestData.Sort } if requestData.Icon != menuCont.Icon { editCont["icon"] = requestData.Icon } if requestData.Redirect != menuCont.Redirect { editCont["redirect"] = requestData.Redirect } if requestData.ParentId != menuCont.ParentId { editCont["parentId"] = requestData.ParentId } if len(editCont) > 0 { editCont["time"] = time.Now().Unix() } if requestData.Outside != menuCont.Outside { editCont["outside"] = requestData.Outside } err = menuCont.EiteCont(whe, editCont) if err != nil { publicmethod.Result(106, err, c) return } publicmethod.Result(0, err, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-24 10:33:12 @ 功能: 删除菜单 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) DeltMenusCont(c *gin.Context) { var requestData publicmethod.PublicId err := c.ShouldBindJSON(&requestData) if err != nil { publicmethod.Result(100, err, c) return } if requestData.Id == "" { publicmethod.Result(1, requestData, c, "未知菜单!") return } var menuCont modelAppPlatform.Menus err = menuCont.GetCont(map[string]interface{}{"`id`": requestData.Id}) if err != nil { publicmethod.Result(107, err, c) return } editCont := publicmethod.MapOut[string]() editCont["`visible`"] = 3 editCont["`time`"] = time.Now().Unix() err = menuCont.EiteCont(map[string]interface{}{"`id`": requestData.Id}, editCont) if err != nil { publicmethod.Result(106, err, c) return } var sunMenus GetSunMenus sunMenus.GetSunMenusList(menuCont.Id) if len(sunMenus.Id) > 0 { overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Where("`id` IN ?", sunMenus.Id).Updates(editCont) } publicmethod.Result(0, err, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-24 10:52:12 @ 功能: 获取所有子菜单 @ 参数 #superior 上级菜单Id @ 返回值 # @ 方法原型 #func (g *GetSunMenus) GetSunMenusList(superior int) */ func (g *GetSunMenus) GetSunMenusList(superior int) { var menuId []int err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Select("`id`").Where("`visible` IN (1,2) AND `parentId` = ?", superior).Find(&menuId).Error if err != nil { return } if len(menuId) > 0 { for _, v := range menuId { if !publicmethod.IsInTrue[int](v, g.Id) { g.Id = append(g.Id, v) } g.GetSunMenusList(v) } } } /* * @ 作者: 秦东 @ 时间: 2025-01-15 14:33:47 @ 功能: 根据角色获取行政组织 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) AccordRoleGiveOrg(c *gin.Context) { context, _ := c.Get(overall.MyContJwt) var userMyCont modelshr.ManCont userMyCont.GetLoginCont(context) //当前操作人 var userCont MyLookOrg userCont.myInfo = userMyCont fmt.Printf("起始入口===>%v\n", userMyCont) syncSeting.Add(1) go userCont.RoleLookOrg() //角色 syncSeting.Add(1) go userCont.PostLookOrg() //职位岗位 syncSeting.Add(1) go userCont.PeopleIsCharge() //是不是部门负责人,获取其负责范围 syncSeting.Wait() maxLevel := 1 for _, v := range userCont.Level { if v >= maxLevel { maxLevel = v } } powerOrgId := publicmethod.RemoveDuplicate[int64](userCont.OrdId) var orgTree []RolePostIsChnature sendData := publicmethod.MapOut[string]() if len(powerOrgId) > 0 { var orgList []modelshr.AdministrativeOrganization overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Where("`state` = 1 AND `id` IN ?", powerOrgId).Find(&orgList) switch maxLevel { case 2: orgTree = GovOrgTree(userMyCont.MainDeparment, orgList) case 3: orgTree = GovOrgTree(userMyCont.Company, orgList) case 4: orgTree = GovOrgTree(313, orgList) case 5: orgTree = GovOrgTree(313, orgList) default: orgTree = GovOrgTree(userMyCont.AdminOrg, orgList) } sendData["companyName"] = gainOrgName(userMyCont.Company, orgList) sendData["maindeparmentName"] = gainOrgName(userMyCont.MainDeparment, orgList) sendData["orgName"] = gainOrgName(userMyCont.AdminOrg, orgList) } sendData["orgTree"] = orgTree sendData["company"] = userMyCont.Company sendData["maindeparment"] = userMyCont.MainDeparment sendData["orgId"] = userMyCont.AdminOrg publicmethod.Result(0, sendData, c) } /* * @ 作者: 秦东 @ 时间: 2025-01-16 10:22:46 @ 功能: 获取行政组织名称 */ func gainOrgName(orgId int64, orgAry []modelshr.AdministrativeOrganization) (orgName string) { for _, v := range orgAry { if v.Id == orgId { orgName = v.Name return } } return } /* * @ 作者: 秦东 @ 时间: 2025-01-16 08:57:31 @ 功能: 生成行政组织树 */ func GovOrgTree(parentId int64, govList []modelshr.AdministrativeOrganization) (govMap []RolePostIsChnature) { for i := 0; i < len(govList); i++ { if govList[i].Superior == parentId { var govCont RolePostIsChnature govCont.Id = govList[i].Id govCont.Number = govList[i].Number //行政编码"` govCont.Name = govList[i].Name //组织名称"` govCont.Superior = govList[i].Superior //上级ID"` govCont.OrganizationType = govList[i].OrganizationType //行政组织类型"` govCont.Abbreviation = govList[i].Abbreviation //行政组织简称"` govCont.Time = govList[i].Time //创建时间"` govCont.State = govList[i].State //状态(1:启用;2:禁用;3:删除)"` govCont.WechatOrganizationId = govList[i].WechatOrganizationId //微信组织架构对照码"` govCont.SuperiorSun = govList[i].SuperiorSun //级联ID"` govCont.Schoole = govList[i].Schoole //原知行学院对照码"` govCont.KingdeeId = govList[i].KingdeeId //金蝶对照ID"` govCont.IsPower = govList[i].IsPower //是否为实权部门"` govCont.Sort = govList[i].Sort //是否为实权部门"` govCont.Child = GovOrgTree(govList[i].Id, govList) govMap = append(govMap, govCont) } } return } /* * @ 作者: 秦东 @ 时间: 2025-01-16 08:17:34 @ 功能: 判断是不是部门负责人,获取其负责范围 */ func (m *MyLookOrg) PeopleIsCharge() { defer syncSeting.Done() if m.myInfo.PersonInCharge == 1 { if m.myInfo.ResponsibleDepartment != "" { resDepAry := strings.Split(m.myInfo.ResponsibleDepartment, ",") if len(resDepAry) > 0 { for _, v := range resDepAry { vInt, _ := strconv.ParseInt(v, 10, 64) m.OrdId = append(m.OrdId, vInt) } } } } } /* * @ 作者: 秦东 @ 时间: 2025-01-15 16:55:29 @ 功能: 根据岗位 */ func (m *MyLookOrg) PostLookOrg() { defer syncSeting.Done() if m.myInfo.Position != 0 { var postEmpower modelssystempermission.Empower overall.CONSTANT_DB_System_Permission.Where("`state` = 1 AND `system` = ? AND `post_id` = ?", "appsystem", m.myInfo.Position).First(&postEmpower) var managementScope []string //管理范围 if postEmpower.Organization != "" { orgAry := strings.Split(postEmpower.Organization, ",") if len(orgAry) > 0 { for _, ov := range orgAry { managementScope = append(managementScope, ov) } } } if len(managementScope) > 0 { for _, v := range managementScope { vInt, _ := strconv.ParseInt(v, 10, 64) m.OrdId = append(m.OrdId, vInt) } } m.Level = append(m.Level, postEmpower.Level) } } /* * @ 作者: 秦东 @ 时间: 2025-01-15 15:46:45 @ 功能: 根据角色权限获取可见行政组织 */ func (m *MyLookOrg) RoleLookOrg() { defer syncSeting.Done() if m.myInfo.Role != "" { roleAry := strings.Split(m.myInfo.Role, ",") if len(roleAry) > 0 { var managementScope []string //管理范围 var maxLevel int //最大授权等级 var roleEmpower []modelssystempermission.RoleEmpower overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.RoleEmpower{}).Where("`state` = 1 AND `system` = ? AND `role_id` IN ?", "appsystem", roleAry).First(&roleEmpower) for _, v := range roleEmpower { if v.Level >= maxLevel { maxLevel = v.Level } if v.Organization != "" { orgAry := strings.Split(v.Organization, ",") if len(orgAry) > 0 { for _, ov := range orgAry { managementScope = append(managementScope, ov) } } } } m.Level = append(m.Level, maxLevel) switch maxLevel { case 2: //本部门及下级单位 if m.myInfo.MainDeparment != 0 { var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(m.myInfo.MainDeparment) sunOrg.Id = append(sunOrg.Id, m.myInfo.MainDeparment) for _, v := range sunOrg.Id { if v != 0 { m.OrdId = append(m.OrdId, v) } } } case 3: //本分部及其下级 if m.myInfo.Company != 0 { var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(m.myInfo.Company) sunOrg.Id = append(sunOrg.Id, m.myInfo.Company) for _, v := range sunOrg.Id { if v != 0 { m.OrdId = append(m.OrdId, v) } } } case 4: //指定行政组织 for _, v := range managementScope { vInt, _ := strconv.ParseInt(v, 10, 64) if vInt != 0 { m.OrdId = append(m.OrdId, vInt) } } case 5: //所有 var ordidList []int64 overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1").Find(&ordidList) if len(ordidList) > 0 { for _, v := range ordidList { if v != 0 { m.OrdId = append(m.OrdId, v) } } } default: //本岗位及下级 if m.myInfo.AdminOrg != 0 { var sunOrg publicmethod.GetOrgAllParent sunOrg.GetOrgSun(m.myInfo.AdminOrg) sunOrg.Id = append(sunOrg.Id, m.myInfo.AdminOrg) for _, v := range sunOrg.Id { if v != 0 { m.OrdId = append(m.OrdId, v) } } } } } } } /* * @ 作者: 秦东 @ 时间: 2025-01-16 15:37:43 @ 功能: 获取排班制度及周期源点 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GainShiftRules(c *gin.Context) { var requestData publicmethod.PublicId err := c.ShouldBindJSON(&requestData) if err != nil { publicmethod.Result(100, err, c) return } if requestData.Id == "" { publicmethod.Result(1, requestData, c, "未知菜单!") return } // var menuCont GenesInfo // err = menuCont.GetCont(map[string]interface{}{"`orgId`": requestData.Id}) orgId, _ := strconv.ParseInt(requestData.Id, 10, 64) menuCont, _, err := CureeRunRules(orgId) if err != nil { publicmethod.Result(200, err, c) return } menuCont.TypeIdStr = strconv.FormatInt(menuCont.TypeId, 10) // menuCont.StartTimeStr menuCont.BegainTime = publicmethod.UnixTimeToDay(menuCont.StartTime, 14) //获取倒班规则 var paiBanType modelshr.WorkTimeType paiBanType.GetCont(map[string]interface{}{"`id`": menuCont.TypeId}, " `name`") menuCont.TypeName = paiBanType.Name //获取源点起始工作时间段 var startWorkTime modelshr.WorkingTimePeriod startWorkTime.GetCont(map[string]interface{}{"`id`": menuCont.PeriodId}, " `name`") menuCont.PeriodName = startWorkTime.Name //获取起始源点起始班组 var starTeam modelshr.PollingRules starTeam.GetCont(map[string]interface{}{"`id`": menuCont.Rules}, " `teamname`", " `sort`") menuCont.RulesTime = fmt.Sprintf("%v(%v)", starTeam.TeamName, starTeam.Sort) publicmethod.Result(0, menuCont, c) } /* * @ 作者: 秦东 @ 时间: 2025-01-16 16:26:39 @ 功能: 确定当前行政组织用哪一个轮询规则 */ func CureeRunRules(orgId int64) (rules GenesInfo, cureeOrgId int64, err error) { if orgId != 0 { err = rules.GetCont(map[string]interface{}{"`orgId`": orgId}) if err != nil || rules.TypeId == 0 { var supaerOrgId modelshr.AdministrativeOrganization supaerOrgId.GetCont(map[string]interface{}{"`id`": orgId}, "`superior`") if supaerOrgId.Superior != 0 { return CureeRunRules(supaerOrgId.Superior) } } else { cureeOrgId = orgId } } else { err = errors.New("没有相关设定") } return } /* * @ 作者: 秦东 @ 时间: 2025-01-17 10:12:34 @ 功能: 获取排班类别及轮询制度 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GainTemsTypeAndRuler(c *gin.Context) { var workTypeList []modelshr.WorkTimeType overall.CONSTANT_DB_HR.Model(&modelshr.WorkTimeType{}).Where("`state` = 1").Find(&workTypeList) var sendList []SendTemsTypeAndRuler for _, v := range workTypeList { var sendInfo SendTemsTypeAndRuler sendInfo.Id = strconv.FormatInt(v.Id, 10) sendInfo.Name = v.Name sendInfo.WorkingTimePeriod = GainWorkTimePer(v.Id) sendInfo.PollingRules = GainPolingRules(v.Id) sendList = append(sendList, sendInfo) } publicmethod.Result(0, sendList, c) } /* * @ 作者: 秦东 @ 时间: 2025-01-17 10:31:52 @ 功能: 获取工作时段 */ func GainPolingRules(id int64) (timeRulesList []RulerPublicInfo) { var timeRules []modelshr.PollingRules overall.CONSTANT_DB_HR.Model(&modelshr.PollingRules{}).Where("`state` = 1 AND `type_id` = ?", id).Order("sort ASC").Find(&timeRules) for _, v := range timeRules { var timeRulesInfo RulerPublicInfo timeRulesInfo.Id = strconv.FormatInt(v.Id, 10) timeRulesInfo.Name = v.TeamName timeRulesInfo.Sort = v.Sort timeRulesList = append(timeRulesList, timeRulesInfo) } return } /* * @ 作者: 秦东 @ 时间: 2025-01-17 10:31:52 @ 功能: 获取工作时段 */ func GainWorkTimePer(id int64) (timePeriodList []RulerPublicInfo) { var timePeriod []modelshr.WorkingTimePeriod overall.CONSTANT_DB_HR.Model(&modelshr.WorkingTimePeriod{}).Where("`state` = 1 AND `type_id` = ?", id).Order("sort ASC").Find(&timePeriod) for _, v := range timePeriod { var timePerInfo RulerPublicInfo timePerInfo.Id = strconv.FormatInt(v.Id, 10) timePerInfo.Name = v.Name timePerInfo.Sort = v.Sort timePerInfo.StartTime = v.StartTime timePerInfo.EndTime = v.EndTime timePeriodList = append(timePeriodList, timePerInfo) } return } /* * @ 作者: 秦东 @ 时间: 2025-01-17 18:10:05 @ 功能: 解析日历生成排班顺序 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) AnalysisMonthRulers(c *gin.Context) { var requestData AnYuePaiBan c.ShouldBindJSON(&requestData) // err := c.ShouldBindJSON(&requestData) // if err != nil { // publicmethod.Result(100, requestData, c) // return // } if requestData.OrgId == "" { publicmethod.Result(1, requestData, c, "未知行政单位") return } var sendMonthList []interface{} orgIdInt, _ := strconv.ParseInt(requestData.OrgId, 10, 64) menuCont, cureeOrgId, err := CureeRunRules(orgIdInt) if err != nil { // for _, v := range requestData.MonthAllDay { // var listSynv CalendarList // sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List)) // } publicmethod.Result(200, sendMonthList, c) return } isRedisTrue := true //Step 1:查看当前提交时间Redis中是否已经排班 for _, v := range requestData.MonthAllDay { weekIsRedisTrue := false var vDay []CalendarStructure for _, wv := range v { var wvTimeAll publicmethod.DateTimeTotimes wvTimeAll.BaisStrToTime(wv.Date) dayRedisKey := fmt.Sprintf("SchedulingTeam:Org_%v_%v_%v_%v", cureeOrgId, wvTimeAll.Years, wvTimeAll.Months, wvTimeAll.Days) redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2) isOk, dayRedisVal := redisClient.Get(dayRedisKey) if isOk { var vDayInfo CalendarStructure redisJsonErr := json.Unmarshal([]byte(dayRedisVal), &vDayInfo) if redisJsonErr == nil { vDay = append(vDay, vDayInfo) } weekIsRedisTrue = true } } isRedisTrue = weekIsRedisTrue if weekIsRedisTrue { sendMonthList = append(sendMonthList, vDay) } // } if isRedisTrue { publicmethod.Result(0, sendMonthList, c) return } //Step 2:若redis中没有响应数据,那么进行数据查询 // isDatabaseTrue := true // for _, v := range requestData.MonthAllDay { // weekIsDatabaseTrue := false // var vDay []CalendarStructure // for _, wv := range v { // var wvTimeAll publicmethod.DateTimeTotimes // wvTimeAll.BaisStrToTime(wv.Date) // var teamLogList teamlog.TeamsLog // teamLogList.GetCont(map[string]interface{}{"`orgId`": cureeOrgId, "`years`": wvTimeAll.Years, "`months`": wvTimeAll.Months, "`days`": wvTimeAll.Days, "`ismId`": menuCont.TypeId, "`rulesId`": menuCont.Rules}) // if teamLogList.Id != 0 { // weekIsDatabaseTrue = true // var vDayInfo CalendarStructure // vDayInfo.List = teamLogList // vDay = append(vDay, vDayInfo) // jsonVal, _ := json.Marshal(vDayInfo) // dayRedisKey := fmt.Sprintf("SchedulingTeam:Org_%v_%v_%v_%v", cureeOrgId, wvTimeAll.Years, wvTimeAll.Months, wvTimeAll.Days) // redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2) // redisClient.SetRedisTime(5256000) // redisClient.Set(dayRedisKey, string(jsonVal)) // } // } // isDatabaseTrue = weekIsDatabaseTrue // if weekIsDatabaseTrue { // sendMonthList = append(sendMonthList, vDay) // } // } // if isDatabaseTrue { // publicmethod.Result(0, sendMonthList, c) // return // } //Step 3:若redis和数据库中都没有相应数据,那么根据数据源点进行计算 //获取源点起始工作时间段 menuCont.BegainTime = publicmethod.UnixTimeToDay(menuCont.StartTime, 14) menuCont.TypeIdStr = strconv.FormatInt(menuCont.TypeId, 10) //获取倒班规则 var paiBanType modelshr.WorkTimeType paiBanType.GetCont(map[string]interface{}{"`id`": menuCont.TypeId}, " `name`") menuCont.TypeName = paiBanType.Name var starTeam modelshr.PollingRules starTeam.GetCont(map[string]interface{}{"`id`": menuCont.Rules}, " `teamname`", " `sort`") menuCont.RulesName = starTeam.TeamName menuCont.RulesSort = starTeam.Sort var wtpInfo modelshr.WorkingTimePeriod wtpInfo.GetCont(map[string]interface{}{"`id`": menuCont.PeriodId}, " `name`", " `sort`", "`start_time` ", "`end_time`") menuCont.PeriodName = wtpInfo.Name menuCont.StartTimeStr = wtpInfo.StartTime menuCont.EndTimeStr = wtpInfo.EndTime //作息时间 var zuoXiTime []modelshr.WorkingTimePeriod overall.CONSTANT_DB_HR.Model(&modelshr.WorkingTimePeriod{}).Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").Find(&zuoXiTime) //轮询时序 var lunXunShiXu []modelshr.PollingRules overall.CONSTANT_DB_HR.Model(&modelshr.PollingRules{}).Where("`state` = 1 AND `type_id` = ?", menuCont.TypeId).Order("`sort` ASC").Find(&lunXunShiXu) if len(zuoXiTime) < 1 || len(lunXunShiXu) < 1 { for _, v := range requestData.MonthAllDay { var listSynv CalendarList sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List)) } publicmethod.Result(200, sendMonthList, c) return } fmt.Printf("menuCont时间差:%v\n", menuCont) //Step 4: 计算当前时间段与原点关系 lastDayNumber := 0 var starTemasTime publicmethod.DateTimeTotimes starTemasTime.BaisStrToTime(menuCont.BegainTime) for _, v := range requestData.MonthAllDay { var listSynv CalendarList for _, wv := range v { var wvTimeAll publicmethod.DateTimeTotimes wvTimeAll.BaisStrToTime(wv.Date) sjc := wvTimeAll.AllTime - starTemasTime.AllTime // fmt.Printf("%v - %v - %v 时间差:%v\n", wv.Date, wvTimeAll.AllTime, starTemasTime.AllTime, sjc) if sjc >= 0 { if sjc == 0 { // listAry := menuCont.TeamsYuanDianRun(wv, wvTimeAll, zuoXiTime, lunXunShiXu) listAry := menuCont.TeamsYuanDianRunNew(wv, wvTimeAll, zuoXiTime, lunXunShiXu) inDate := publicmethod.MapOut[string]() inDate[wv.Date] = listAry listSynv.List = append(listSynv.List, inDate) } else { // listAry := menuCont.TeamsRun(wv, wvTimeAll, zuoXiTime, lunXunShiXu) listAry := menuCont.SpecifyDateTeams(wv, wvTimeAll, zuoXiTime, lunXunShiXu) inDate := publicmethod.MapOut[string]() inDate[wv.Date] = listAry listSynv.List = append(listSynv.List, inDate) } } else { lastDayNumber++ } } sendMonthList = append(sendMonthList, TimeHaveAry(v, listSynv.List)) } // cureeTime := publicmethod.UnixTimeToDay(time.Now().Unix(), 14) // if requestData.MonthAllDay[0][0].Date != "" { // cureeTime = requestData.MonthAllDay[0][0].Date // } // var creTimeAll publicmethod.DateTimeTotimes // creTimeAll.BaisStrToTime(cureeTime) //获取上个月最后一天 // lastMonthStart, lastMonthEnd := publicmethod.GetLastMonthStartEnd(creTimeAll.AllTimeString) // fmt.Printf("------------------>%v\n", allRulesLog) publicmethod.Result(0, sendMonthList, c) } /* * @ 作者: 秦东 @ 时间: 2025-01-18 09:26:03 @ 功能: 解析排班规则(当天是原点) @ 参数 #dataInfo 当前日期属性 #timeVal 当前时间 #zuoXiTime 作息时间段 #lunXunShiXu 轮询规则 */ func (g *GenesInfo) TeamsYuanDianRun(dataInfo CalendarStructure, timeVal publicmethod.DateTimeTotimes, zuoXiTime []modelshr.WorkingTimePeriod, lunXunShiXu []modelshr.PollingRules) (logMap []map[string]interface{}) { // var logList []teamlog.TeamsLog dayRedisKey := fmt.Sprintf("SchedulingTeam:StartingPoint_%v_%v_%v_%v", g.OrgId, g.TypeId, g.PeriodId, g.Rules) redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2) isTrue, logContent := redisClient.Get(dayRedisKey) isTrue = false if isTrue { json.Unmarshal([]byte(logContent), &logMap) valMap := publicmethod.MapOut[string]() json.Unmarshal([]byte(logContent), &valMap) // valueOfExample := reflect.ValueOf(logInfo) // if valueOfExample.Kind() == reflect.Struct { // for i := 0; i < valueOfExample.NumField(); i++ { // valMap[valueOfExample.Type().Field(i).Name] = valueOfExample.Field(i).Interface() // } // } // logList = append(logList, logInfo) // logMap = append(logMap, valMap) // allRulesLog = logInfo } else { // var logInfo teamlog.TeamsLog // logInfo.OrgId = g.OrgId //班组ID"` // logInfo.TeamsTime = timeVal.AllTime //日期"` // logInfo.IsmId = g.TypeId //制度ID"` // logInfo.RankId = g.PeriodId //班次"` // logInfo.RulesId = g.Rules //轮询规则Id"` // logInfo.Days, _ = strconv.Atoi(timeVal.Years) //日"` // logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"` // logInfo.Years, _ = strconv.Atoi(timeVal.Days) //年"` // logInfo.Time = time.Now().Unix() //编辑时间"` // logInfo.IsmName = g.TypeName // logInfo.RankName = g.PeriodName // logInfo.RulesName = g.RulesTime // logInfo.Sort = g.RulesSort // logInfo.TeamsId = g.Rules // overall.CONSTANT_DB_TeamsLog.Create(&logInfo) // logList = append(logList, logInfo) // allRulesLog = logInfo // redisClient.SetRedisTime(5256000) // jsonVal, _ := json.Marshal(logInfo) // redisClient.Set(dayRedisKey, string(jsonVal)) // valMap := publicmethod.MapOut[string]() // json.Unmarshal(jsonVal, &valMap) // logMap = append(logMap, valMap) //按时间排序 sort.Slice(zuoXiTime, func(i, j int) bool { return zuoXiTime[i].StartTime < zuoXiTime[j].StartTime }) fmt.Printf("更改排序后---------->%v\n", zuoXiTime) fmt.Printf("更改排序后----g------>%v\n", g) //判断起始地点前边有多少数据 tianZhenghouNum := 0 for i, v := range zuoXiTime { if v.Id == g.PeriodId { tianZhenghouNum = i + 1 } } //安排定点前边的排班结果 if tianZhenghouNum > 0 { for i := tianZhenghouNum - 1; i > 0; i-- { creeLunXun := LunXunGuiZe(lunXunShiXu, g.Rules, i, 1) var logInfo teamlog.TeamsLog logInfo.OrgId = g.OrgId //班组ID"` logInfo.TeamsTime = timeVal.AllTime //日期"` logInfo.IsmId = g.TypeId //制度ID"` logInfo.RankId = zuoXiTime[i].Id //班次"` logInfo.RulesId = creeLunXun.Id //轮询规则Id"` logInfo.Days, _ = strconv.Atoi(timeVal.Years) //日"` logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"` logInfo.Years, _ = strconv.Atoi(timeVal.Days) //年"` logInfo.Time = time.Now().Unix() //编辑时间"` logInfo.IsmName = g.TypeName logInfo.RankName = zuoXiTime[i].Name logInfo.RulesName = creeLunXun.TeamName logInfo.Sort = creeLunXun.Sort logInfo.TeamsId = creeLunXun.Id logInfo.StartTime = zuoXiTime[i].StartTime logInfo.EndTime = zuoXiTime[i].EndTime overall.CONSTANT_DB_TeamsLog.Create(&logInfo) jsonVal, _ := json.Marshal(logInfo) valMap := publicmethod.MapOut[string]() json.Unmarshal(jsonVal, &valMap) logMap = append(logMap, valMap) } } //计算原点位置 var logInfoYuan teamlog.TeamsLog logInfoYuan.OrgId = g.OrgId //班组ID"` logInfoYuan.TeamsTime = timeVal.AllTime //日期"` logInfoYuan.IsmId = g.TypeId //制度ID"` logInfoYuan.RankId = zuoXiTime[tianZhenghouNum-1].Id //班次"` logInfoYuan.RulesId = g.Rules //轮询规则Id"` logInfoYuan.Days, _ = strconv.Atoi(timeVal.Years) //日"` logInfoYuan.Months, _ = strconv.Atoi(timeVal.Months) //月"` logInfoYuan.Years, _ = strconv.Atoi(timeVal.Days) //年"` logInfoYuan.Time = time.Now().Unix() //编辑时间"` logInfoYuan.IsmName = g.TypeName logInfoYuan.RankName = zuoXiTime[tianZhenghouNum-1].Name logInfoYuan.RulesName = g.RulesTime logInfoYuan.Sort = g.RulesSort logInfoYuan.TeamsId = g.Rules logInfoYuan.StartTime = zuoXiTime[tianZhenghouNum-1].StartTime logInfoYuan.EndTime = zuoXiTime[tianZhenghouNum-1].EndTime overall.CONSTANT_DB_TeamsLog.Create(&logInfoYuan) jsonValYuan, _ := json.Marshal(logInfoYuan) valMapYuan := publicmethod.MapOut[string]() json.Unmarshal(jsonValYuan, &valMapYuan) logMap = append(logMap, valMapYuan) //计算后边有几个排班 lastNum := len(zuoXiTime) - (tianZhenghouNum) if lastNum > 0 { for i := 1; i <= lastNum; i++ { creeLunXun := LunXunGuiZe(lunXunShiXu, g.Rules, i, 2) var logInfo teamlog.TeamsLog logInfo.OrgId = g.OrgId //班组ID"` logInfo.TeamsTime = timeVal.AllTime //日期"` logInfo.IsmId = g.TypeId //制度ID"` logInfo.RankId = zuoXiTime[i].Id //班次"` logInfo.RulesId = creeLunXun.Id //轮询规则Id"` logInfo.Days, _ = strconv.Atoi(timeVal.Years) //日"` logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"` logInfo.Years, _ = strconv.Atoi(timeVal.Days) //年"` logInfo.Time = time.Now().Unix() //编辑时间"` logInfo.IsmName = g.TypeName logInfo.RankName = zuoXiTime[i].Name logInfo.RulesName = creeLunXun.TeamName logInfo.Sort = creeLunXun.Sort logInfo.TeamsId = creeLunXun.Id overall.CONSTANT_DB_TeamsLog.Create(&logInfo) jsonVal, _ := json.Marshal(logInfo) valMap := publicmethod.MapOut[string]() json.Unmarshal(jsonVal, &valMap) logMap = append(logMap, valMap) } } // allRulesLogMap := logMap[len(logMap)-1] // if lmStr,isOk := allRulesLogMap.(string);isOk { // } // json.Unmarshal() slogMapVal, _ := json.Marshal(logMap) redisClient.Set(dayRedisKey, string(slogMapVal)) } return } /* * @ 作者: 秦东 @ 时间: 2025-01-18 09:26:03 @ 功能: 解析排班规则 @ 参数 #dataInfo 当前日期属性 #timeVal 当前时间 #zuoXiTime 作息时间段 #lunXunShiXu 轮询规则 // */ // func (g *GenesInfo) TeamsRun(dataInfo CalendarStructure, timeVal publicmethod.DateTimeTotimes, zuoXiTime []modelshr.WorkingTimePeriod, lunXunShiXu []modelshr.PollingRules) (logMap []map[string]interface{}) { // // var logList []teamlog.TeamsLog // if len(zuoXiTime) < 1 && len(lunXunShiXu) < 1 { //没有设置工作时间段,也没有轮询规则 // return // } else if len(zuoXiTime) == 1 && len(lunXunShiXu) == 1 { //单一工作段,单一轮询规则 // if dataInfo.IsWorks { //判断当前是不是周末。是周末的话俺休班计算。 // for _, v := range zuoXiTime { // var logInfo teamlog.TeamsLog // logInfo.OrgId = g.OrgId //班组ID"` // logInfo.TeamsTime = timeVal.AllTime //日期"` // logInfo.IsmId = g.TypeId //制度ID"` // logInfo.RankId = v.Id //班次"` // logInfo.RulesId = 0 //轮询规则Id"` // logInfo.Days, _ = strconv.Atoi(timeVal.Years) //日"` // logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"` // logInfo.Years, _ = strconv.Atoi(timeVal.Days) //年"` // logInfo.Time = time.Now().Unix() //编辑时间"` // logInfo.IsmName = g.TypeName // logInfo.RankName = fmt.Sprintf("%v(%v - %v)", v.Name, v.StartTime, v.EndTime) //v.Name // logInfo.RulesName = "休" // logInfo.TeamsId = 0 // logInfo.Sort = 0 // // logList = append(logList, logInfo) // jsonVal, _ := json.Marshal(logInfo) // valMap := publicmethod.MapOut[string]() // json.Unmarshal(jsonVal, &valMap) // logMap = append(logMap, valMap) // } // } else { //不是周末正常上班 // for _, v := range zuoXiTime { // var logInfo teamlog.TeamsLog // logInfo.OrgId = g.OrgId //班组ID"` // logInfo.TeamsTime = timeVal.AllTime //日期"` // logInfo.IsmId = g.TypeId //制度ID"` // logInfo.RankId = v.Id //班次"` // logInfo.RulesId = zuoXiTime[0].Id //轮询规则Id"` // logInfo.Days, _ = strconv.Atoi(timeVal.Years) //日"` // logInfo.Months, _ = strconv.Atoi(timeVal.Months) //月"` // logInfo.Years, _ = strconv.Atoi(timeVal.Days) //年"` // logInfo.Time = time.Now().Unix() //编辑时间"` // logInfo.IsmName = g.TypeName // logInfo.RankName = fmt.Sprintf("%v(%v - %v)", v.Name, v.StartTime, v.EndTime) //v.Name // logInfo.RulesName = lunXunShiXu[0].TeamName // logInfo.TeamsId = lunXunShiXu[0].Teamid // logInfo.Sort = lunXunShiXu[0].Sort // // logList = append(logList, logInfo) // jsonVal, _ := json.Marshal(logInfo) // valMap := publicmethod.MapOut[string]() // json.Unmarshal(jsonVal, &valMap) // logMap = append(logMap, valMap) // } // } // } else { // //判断轮询规制(是两天一换还是一天一换) // var lunXunChuchong []int64 // maxSort := 0 //最大排序 // for _, v := range lunXunShiXu { // if !publicmethod.IsInTrue[int64](v.Teamid, lunXunChuchong) { // lunXunChuchong = append(lunXunChuchong, v.Teamid) // } // if maxSort <= v.Sort { // maxSort = v.Sort // } // } // //基于上个日期班组定位顺序 // lastStep := 0 // startStep := 0 //起始步伐 // workTimeNum := len(zuoXiTime) //一天拍几个班 // for _, v := range zuoXiTime { // if allRulesLog.RankId == v.Id { // lastStep = len(zuoXiTime) - v.Sort // startStep = v.Sort // } // } // if startStep <= 0 { // startStep = 1 // } // beiChuShu := 1 // if len(lunXunChuchong) > 0 { // beiChuShu = len(lunXunChuchong) // } // yuanDianDay := fmt.Sprintf("%v-%v-%v", allRulesLog.Years, allRulesLog.Months, allRulesLog.Days) // xiangChaJitian, err := publicmethod.DayBetweenDate(dataInfo.Date, yuanDianDay) //与上一个排班相差几天 // if err != nil { // xiangChaJitian = 1 // } // switch len(lunXunShiXu) / beiChuShu { // case 2: // case 3: // case 4: // case 5: // case 6: // case 7: // default: // dayRedisKey := fmt.Sprintf("SchedulingTeam:StartingPoint_%v_%v_%v_%v", g.OrgId, g.TypeId, g.PeriodId, g.Rules) // redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS2) // // , // } // } // return // } // 获取排班顺序 func PaiBanSunXu(step int, zuoXiTime []modelshr.WorkingTimePeriod) (zxsj modelshr.WorkingTimePeriod) { for _, v := range zuoXiTime { if v.Sort == step { zxsj = v return } } return } /** @ 作者: 秦东 @ 时间: 2025-01-17 19:42:50 @ 功能: 获取上个月最后一天 */ /* * @ 作者: 秦东 @ 时间: 2024-07-17 08:55:56 @ 功能: 结果与日期合并 @ 参数 # @ 返回值 # @ 方法原型 # */ func TimeHaveAry(dateList []CalendarStructure, listDate []map[string]interface{}) []CalendarStructure { for ti, tv := range dateList { // fmt.Printf("测试类型--->%v=============>%v\n", ti, tv) for _, v := range listDate { for mi, mv := range v { // fmt.Printf("测试类型--2->%v=============>%v\n", tv.Date, mi) if tv.Date == mi { // fmt.Printf("测试类型--1->%v=============>%v\n", tv.Date, mi) dateList[ti].List = mv } } } } return dateList }