@ -1,16 +1,27 @@
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
/ *
*
@ 作者 : 秦东
@ -412,3 +423,883 @@ func (g *GetSunMenus) GetSunMenusList(superior int) {
}
}
}
/ *
*
@ 作者 : 秦东
@ 时间 : 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 0 8 : 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 0 8 : 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 = fmt . Sprintf ( "%v(%v - %v)" , wtpInfo . Name , wtpInfo . StartTime , 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
}
//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 )
inDate := publicmethod . MapOut [ string ] ( )
inDate [ wv . Date ] = listAry
listSynv . List = append ( listSynv . List , inDate )
} else {
listAry := menuCont . TeamsRun ( 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)
publicmethod . Result ( 0 , sendMonthList , c )
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 01 - 18 0 9 : 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 )
var logInfo teamlog . TeamsLog
if isTrue {
json . Unmarshal ( [ ] byte ( logContent ) , & logInfo )
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 {
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 )
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 01 - 18 0 9 : 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 )
stepAll := xiangChaJitian * workTimeNum + lastStep //一共要走的步数
for i := 1 ; i <= stepAll ; i ++ {
startStep ++
if startStep > workTimeNum {
startStep = 1
}
// for _, zv := range zuoXiTime {
if i > lastStep {
for _ , v := range lunXunShiXu {
if v . Sort == startStep {
fmt . Printf ( "" )
workInfoDuan := PaiBanSunXu ( startStep , zuoXiTime )
var logInfo teamlog . TeamsLog
logInfo . GetCont ( map [ string ] interface { } { "`orgId`" : g . OrgId , "`years`" : timeVal . Years , "`months`" : timeVal . Months , "`days`" : timeVal . Days , "`ismId`" : g . TypeId , "`rulesId`" : g . PeriodId , "`teamsId`" : v . Teamid } )
if logInfo . Id != 0 {
editInfo := publicmethod . MapOut [ string ] ( )
editInfo [ "rulesName" ] = v . TeamName
editInfo [ "time" ] = time . Now ( ) . Unix ( )
logInfo . EiteCont ( map [ string ] interface { } { "`id`" : logInfo . Id } , editInfo )
// logList = append(logList, logInfo)
jsonVal , _ := json . Marshal ( logInfo )
valMap := publicmethod . MapOut [ string ] ( )
json . Unmarshal ( jsonVal , & valMap )
logMap = append ( logMap , valMap )
redisClient . SetRedisTime ( 5256000 )
// jsonVal, _ := json.Marshal(logInfo)
redisClient . Set ( dayRedisKey , string ( jsonVal ) )
} else {
logInfo . OrgId = g . OrgId //班组ID"`
logInfo . TeamsTime = timeVal . AllTime //日期"`
logInfo . IsmId = g . TypeId //制度ID"`
logInfo . RankId = workInfoDuan . Id //g.PeriodId //班次"`
logInfo . RulesId = g . Rules //轮询规则Id"`
logInfo . Days , _ = strconv . Atoi ( timeVal . Days ) //日"`
logInfo . Months , _ = strconv . Atoi ( timeVal . Months ) //月"`
logInfo . Years , _ = strconv . Atoi ( timeVal . Years ) //年"`
logInfo . Time = time . Now ( ) . Unix ( ) //编辑时间"`
logInfo . IsmName = g . TypeName
logInfo . RankName = fmt . Sprintf ( "%v(%v - %v)" , workInfoDuan . Name , workInfoDuan . StartTime , workInfoDuan . EndTime ) //workInfoDuan.Name //g.PeriodName
logInfo . RulesName = v . TeamName
logInfo . TeamsId = v . Teamid
logInfo . Sort = g . RulesSort
overall . CONSTANT_DB_TeamsLog . Create ( & logInfo )
// logList = append(logList, logInfo)
jsonVal , _ := json . Marshal ( logInfo )
valMap := publicmethod . MapOut [ string ] ( )
json . Unmarshal ( jsonVal , & valMap )
logMap = append ( logMap , valMap )
redisClient . SetRedisTime ( 5256000 )
// jsonVal, _ := json.Marshal(logInfo)
redisClient . Set ( dayRedisKey , string ( jsonVal ) )
}
}
}
}
// }
}
}
}
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 0 8 : 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
}