From 4c055d646995c399b8efcf6ec301375642d8d8ca Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Sat, 3 Feb 2024 14:41:22 +0800 Subject: [PATCH] 20240203 --- api/base/loginVerify/login.go | 8 +- api/version1/entry.go | 2 + api/version1/newsclass/type.go | 17 ++ api/version1/statistics/orgMonths.go | 231 ++++++++++++++++++ api/version1/statistics/pc.go | 9 +- api/version1/statistics/type.go | 54 ++++ apirouter/entry.go | 2 + apirouter/v1/newsclassrouter/apirouter.go | 18 ++ apirouter/v1/newsclassrouter/type.go | 4 + apirouter/v1/statisticsrouter/pc.go | 3 + initialization/route/initRoute.go | 4 +- main.go | 10 + .../modelshr/administrative_organization.go | 2 +- 13 files changed, 355 insertions(+), 9 deletions(-) create mode 100644 api/version1/newsclass/type.go create mode 100644 api/version1/statistics/orgMonths.go create mode 100644 apirouter/v1/newsclassrouter/apirouter.go create mode 100644 apirouter/v1/newsclassrouter/type.go diff --git a/api/base/loginVerify/login.go b/api/base/loginVerify/login.go index 1b6a24a..4f2b2ba 100644 --- a/api/base/loginVerify/login.go +++ b/api/base/loginVerify/login.go @@ -30,10 +30,10 @@ func (a *ApiMethod) ScanCodeLogin(c *gin.Context) { return } - // if store.Verify(requestData.CaptchaId, requestData.Captcha, true) != true { - // publicmethod.Result(1, requestData, c, "验证码不正确!") - // return - // } + if !store.Verify(requestData.CaptchaId, requestData.Captcha, true) { + publicmethod.Result(1, requestData, c, "验证码不正确!") + return + } // userAgent := c.Request.Header.Get("User-Agent") // 获取用户代理 // userAgent = "250" diff --git a/api/version1/entry.go b/api/version1/entry.go index 61c2c02..78db130 100644 --- a/api/version1/entry.go +++ b/api/version1/entry.go @@ -8,6 +8,7 @@ import ( "key_performance_indicators/api/version1/flowchart" "key_performance_indicators/api/version1/honoraryArchives" "key_performance_indicators/api/version1/jurisdiction/jurisdictionpc" + "key_performance_indicators/api/version1/newsclass" "key_performance_indicators/api/version1/postseting/postpc" "key_performance_indicators/api/version1/postseting/postweb" "key_performance_indicators/api/version1/statistics" @@ -26,6 +27,7 @@ type ApiEntry struct { WorkFlowChat flowchart.ApiMethod //工作流 SystemAppExamine systemapproval.ApiMethod //系统审批处理 StatisticsApi statistics.ApiMethod //指标统计 + NewsClassApi newsclass.ApiMethod //新闻类 } var AppApiEntry = new(ApiEntry) diff --git a/api/version1/newsclass/type.go b/api/version1/newsclass/type.go new file mode 100644 index 0000000..ea34186 --- /dev/null +++ b/api/version1/newsclass/type.go @@ -0,0 +1,17 @@ +package newsclass + +import ( + "key_performance_indicators/overall/publicmethod" + + "github.com/gin-gonic/gin" +) + +// 新闻类数据处理 +type ApiMethod struct{} + +// 系统内部审批处理 +func (a *ApiMethod) Index(c *gin.Context) { + outputCont := publicmethod.MapOut[string]() + outputCont["index"] = "新闻类数据处理入口" + publicmethod.Result(0, outputCont, c) +} diff --git a/api/version1/statistics/orgMonths.go b/api/version1/statistics/orgMonths.go new file mode 100644 index 0000000..ef23db7 --- /dev/null +++ b/api/version1/statistics/orgMonths.go @@ -0,0 +1,231 @@ +package statistics + +import ( + "encoding/json" + "fmt" + "key_performance_indicators/models/modelshr" + "key_performance_indicators/overall" + "key_performance_indicators/overall/publicmethod" + "sort" + "strconv" + "time" + + "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" + "github.com/gin-gonic/gin" +) + +/* +* +@ 作者: 秦东 +@ 时间: 2023-11-08 11:22:10 +@ 功能: 行政组织年度成绩单 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +func (a *ApiMethod) OrgTargetAnnualStatistics(c *gin.Context) { + //获取登录人信息 + context, _ := publicmethod.LoginMyCont(c) + var requestData OrgAnnualStatistics + c.ShouldBindJSON(&requestData) + //获取行政组织 + var orgList []modelshr.AdministrativeOrganization + gromDb := overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`,`name`,`sort`").Where("ispower = 1 AND state = 1 AND organization_type > 2") + if requestData.OrgId != "" { + gromDb = gromDb.Where("superior = ?", requestData.OrgId) + } else { + gromDb = gromDb.Where("superior = ?", context.Company) + } + err := gromDb.Find(&orgList).Error + if err != nil && len(orgList) < 1 { + response.Result(102, err, "没有查询到数据", c) + return + } + + var orgAry []modelshr.AdministrativeOrganization + for _, ov := range orgList { + if ov.Id != 163 && ov.Id != 281 { + //获取下级行政组织是否有主行政部门 + sunOrgList, orgSunErr := getSunOrgList(ov.Id, "`id`", "`name`", "`sort`") + if orgSunErr == nil && len(sunOrgList) > 0 { + orgAry = append(orgAry, sunOrgList...) + } else { + orgAry = append(orgAry, ov) + } + } + } + + //计算要查询的年份 + currentYear := publicmethod.ComputingTime(time.Now().Unix(), 1) //当前年 + todayYear := currentYear //今年 + if requestData.Years != "" { + yearInt64, _ := strconv.ParseInt(requestData.Years, 10, 64) + currentYear = yearInt64 + } + //计算月 + var monthTody []int64 + + if currentYear == todayYear { + monthTodyIng := publicmethod.ComputingTime(time.Now().Unix(), 3) + var montInt64 int64 + for montInt64 = 1; montInt64 <= monthTodyIng; montInt64++ { + monthTody = append(monthTody, montInt64) + } + } else { + var montInt64All int64 + for montInt64All = 1; montInt64All <= 12; montInt64All++ { + monthTody = append(monthTody, montInt64All) + } + } + + //保证月份不为负数 + if len(monthTody) < 1 { + monthTody = append(monthTody, 1) + } + var sendList SendOrgAnnualStatistics + var orgTranscriptList OrgTranscript + for _, v := range monthTody { + sendList.XAxis = append(sendList.XAxis, fmt.Sprintf("%v月", v)) + } + for _, v := range orgAry { + sendList.Legend = append(sendList.Legend, v.Name) + syncProcess.Add(1) + go orgTranscriptList.CalculateGrades(v, currentYear, monthTody) + } + syncProcess.Wait() + readStatisticsData := orgTranscriptList.readTranscriptData() //读取通道数据 + if len(readStatisticsData) > 0 { + sendList.MaxScore = readStatisticsData[0].MaxScore + sendList.MinScore = readStatisticsData[0].MinScore + } + //根据维度序号排序 + sort.Slice(readStatisticsData, func(i, j int) bool { + return readStatisticsData[i].Scort < readStatisticsData[j].Scort + }) + for _, v := range readStatisticsData { + if sendList.MaxScore <= v.MaxScore { + sendList.MaxScore = v.MaxScore + } + if sendList.MinScore >= v.MinScore { + sendList.MinScore = v.MinScore + } + } + if sendList.MaxScore > 0 { + if sendList.MaxScore > 1 { + sendList.MaxScore = sendList.MaxScore + 1 + } else { + sendList.MaxScore = sendList.MaxScore + 0.1 + } + } else { + if sendList.MaxScore < -1 { + sendList.MaxScore = sendList.MaxScore + 1 + } else { + sendList.MaxScore = sendList.MaxScore + 0.1 + } + } + if sendList.MinScore > 0 { + if sendList.MinScore > 1 { + sendList.MinScore = sendList.MinScore - 1 + } else { + sendList.MinScore = sendList.MinScore - 0.1 + } + } else { + if sendList.MinScore < -1 { + sendList.MinScore = sendList.MinScore - 1 + } else { + sendList.MinScore = sendList.MinScore - 0.1 + } + } + sendList.Series = readStatisticsData + + publicmethod.Result(0, sendList, c) +} +func (o *OrgTranscript) CalculateGrades(orgInfo modelshr.AdministrativeOrganization, currentYear int64, months []int64) { + //锁操作 + o.mutext.Lock() + defer o.mutext.Unlock() + + var orgSictesCont SeriesList + orgSictesCont.Name = orgInfo.Name + orgSictesCont.Scort = orgInfo.Sort + // var monthOrgScore OrgTranscriptScore + + var everyMonthScore countEveryDepartmentMonthScore + + for _, v := range months { + planCont, err := publicmethod.GetPlanVresion(orgInfo.Id, currentYear, v) + // fmt.Printf("planCont:%v\n%v\n", planCont, err) + if err == nil { + var planVersioInfo []AddDutyNewCont + jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo) + if jsonErr == nil { + syncProcessDepartTarget.Add(1) + //按月份计算 + go everyMonthScore.everyMonthCalculateNew(orgInfo.Id, currentYear, v, planVersioInfo) + } + } + } + syncProcessDepartTarget.Wait() + everyMonthScoreList := everyMonthScore.readMyDayData() + if len(everyMonthScoreList) > 0 { + orgSictesCont.MaxScore = everyMonthScoreList[0].Score + orgSictesCont.MinScore = everyMonthScoreList[0].Score + } + sort.Slice(everyMonthScoreList, func(i, j int) bool { + return everyMonthScoreList[i].MonthVal < everyMonthScoreList[j].MonthVal + }) + // fmt.Printf("层级:%v\n", everyMonthScoreList) + + for _, v := range everyMonthScoreList { + + if orgSictesCont.MaxScore <= v.Score { + orgSictesCont.MaxScore = v.Score + } + if orgSictesCont.MinScore > v.Score { + orgSictesCont.MinScore = v.Score + } + orgSictesCont.DataList = append(orgSictesCont.DataList, v.Score) + } + o.ScoreStatistics = append(o.ScoreStatistics, orgSictesCont) + syncProcess.Done() +} + +/* +* +@ 作者: 秦东 +@ 时间: 2023-11-08 13:09:27 +@ 功能: 计算行政组织每月成绩 +@ 参数 + + # + +@ 返回值 + + # + +@ 方法原型 + + # +*/ +// func (o *OrgTranscriptScore) CalculateGrades(orgId, years, months int64) { +// o.mutext.Lock() +// defer o.mutext.Unlock() +// var scoreInfo MonthOrgScore +// scoreInfo.Months = months +// planCont, err := publicmethod.GetPlanVresion(orgId, years, months) +// if err == nil { +// var planVersioInfo []AddDutyNewCont +// jsonErr := json.Unmarshal([]byte(planCont.Content), &planVersioInfo) +// } + +// o.ScoreList = append(o.ScoreList, scoreInfo) +// syncProcessDepartTarget.Done() +// } diff --git a/api/version1/statistics/pc.go b/api/version1/statistics/pc.go index 1ec3c45..2b8de6d 100644 --- a/api/version1/statistics/pc.go +++ b/api/version1/statistics/pc.go @@ -552,7 +552,7 @@ func (c *countEveryDepartmentMonthScore) everyMonthCalculateNew(orgId, year, mon zhiBiaoScore = zhiBiaoScore + float64(sv.ReferenceScore) if sv.Status == 3 { //为观察指标 sumScore = sumScore + float64(sv.ReferenceScore) - fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore) + // fmt.Printf("为观察指标--->%v--->%v--->%v\n", sv.Name, sv.Id, sv.ReferenceScore) } else { var targetInfo modelskpi.EvaluationTarget targetInfo.GetCont(map[string]interface{}{"et_id": sv.Id}, "et_type,et_cycle") @@ -560,7 +560,7 @@ func (c *countEveryDepartmentMonthScore) everyMonthCalculateNew(orgId, year, mon //定性考核 dingXingScore, _ := DingXingScoreCalculation(orgId, year, sv.ReferenceScore, []int64{month}, sv.Id) sumScore = sumScore + dingXingScore - fmt.Printf("定性考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore, sumScore) + // fmt.Printf("定性考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingXingScore, sumScore) } else { var dingLiangScore float64 @@ -841,7 +841,7 @@ func (c *countEveryDepartmentMonthScore) everyMonthCalculateNew(orgId, year, mon } dingLiangScoreGd, _ := publicmethod.DecimalNew(dingLiangScore, 2) sumScore = sumScore + dingLiangScoreGd - fmt.Printf("定量月度考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore, sumScore) + // fmt.Printf("定量月度考核得分--->%v--->%v--->%v--->%v\n", sv.Name, sv.Id, dingLiangScore, sumScore) } } @@ -1515,6 +1515,9 @@ func GetDingLiangLog(orgId, years, monthes int64, targetId, cont string) (sendLi if v.ScoringMethod != 1 { secondCont.Score = publicmethod.DecimalEs(float64(v.ScoringScore)/100, 2) } + + fmt.Printf("获取定量考核记录-1-->targetScore:%v\n--->attribute:%v\n--->Score:%v\n--->ScoringMethod:%v\n--->ScoringScore:%v\n", targetScore, attribute, secondCont.Score, v.ScoringMethod, v) + secondCont.MtOrAt = v.ScoringMethod secondCont.Cont = fmt.Sprintf("%v%v", v.Content, cont) secondCont.Nature = attribute diff --git a/api/version1/statistics/type.go b/api/version1/statistics/type.go index 604b0c3..481d5ce 100644 --- a/api/version1/statistics/type.go +++ b/api/version1/statistics/type.go @@ -227,3 +227,57 @@ type dingLiangKaoHeNew struct { MtOrAt int `json:"mtorat"` //手动还是自动 Nature int `json:"nature"` //1、使用;2:禁用;3:观察 } + +// 行政组织年度成绩单 +type OrgAnnualStatistics struct { + OrgId string `json:"orgid"` + Years string `json:"years"` +} + +// 输出行政组织年度统计成绩单 +type SendOrgAnnualStatistics struct { + Legend []string `json:"legend"` + XAxis []string `json:"xAxis"` + MaxScore float64 `json:"maxscore"` + MinScore float64 `json:"minscore"` + Series []SeriesList `json:"series"` +} +type SeriesList struct { + Name string `json:"name"` + Scort int `json:"scort"` + MaxScore float64 `json:"maxscore"` + MinScore float64 `json:"minscore"` + DataList []float64 `json:"datalist"` +} + +// 政组织年度统计成绩表 +type OrgTranscript struct { + ScoreStatistics []SeriesList + mutext sync.RWMutex +} + +// 读取政组织年度统计锁数据 +func (t *OrgTranscript) readTranscriptData() []SeriesList { + t.mutext.RLock() + defer t.mutext.RUnlock() + return t.ScoreStatistics +} + +// 计算月份结果 +type MonthOrgScore struct { + Months int64 + Score float64 +} + +// 计算月份结果(协程) +type OrgTranscriptScore struct { + ScoreList []MonthOrgScore + mutext sync.RWMutex +} + +// 读取政组织年度统计锁数据 +func (t *OrgTranscriptScore) readTranscriptData() []MonthOrgScore { + t.mutext.RLock() + defer t.mutext.RUnlock() + return t.ScoreList +} diff --git a/apirouter/entry.go b/apirouter/entry.go index 74d5b65..4dcc19d 100644 --- a/apirouter/entry.go +++ b/apirouter/entry.go @@ -8,6 +8,7 @@ import ( "key_performance_indicators/apirouter/v1/departmentseting" "key_performance_indicators/apirouter/v1/empowerrouter" honorsRoute "key_performance_indicators/apirouter/v1/honorsRoute" + "key_performance_indicators/apirouter/v1/newsclassrouter" "key_performance_indicators/apirouter/v1/postseting" "key_performance_indicators/apirouter/v1/statisticsrouter" "key_performance_indicators/apirouter/v1/systempower" @@ -33,6 +34,7 @@ type RouterGroup struct { ExamineSystemApp approvalsystem.ApiRouter MyWorkFlowRouter workflowrouter.ApiRouter StatisticsApiRouter statisticsrouter.ApiRouter + NewsClassApiRouter newsclassrouter.ApiRouter } var RouterGroupEntry = new(RouterGroup) diff --git a/apirouter/v1/newsclassrouter/apirouter.go b/apirouter/v1/newsclassrouter/apirouter.go new file mode 100644 index 0000000..ff99225 --- /dev/null +++ b/apirouter/v1/newsclassrouter/apirouter.go @@ -0,0 +1,18 @@ +package newsclassrouter + +import ( + "key_performance_indicators/api/version1" + + "github.com/gin-gonic/gin" +) + +// 新闻类接口路由 +func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { + apiRouter := router.Group("news") + var newsClassRouter = version1.AppApiEntry.NewsClassApi + { + apiRouter.GET("", newsClassRouter.Index) //入口 + apiRouter.POST("", newsClassRouter.Index) //入口 + + } +} diff --git a/apirouter/v1/newsclassrouter/type.go b/apirouter/v1/newsclassrouter/type.go new file mode 100644 index 0000000..4964ade --- /dev/null +++ b/apirouter/v1/newsclassrouter/type.go @@ -0,0 +1,4 @@ +package newsclassrouter + +//新闻类路由设定 +type ApiRouter struct{} diff --git a/apirouter/v1/statisticsrouter/pc.go b/apirouter/v1/statisticsrouter/pc.go index db346f7..42bc9bf 100644 --- a/apirouter/v1/statisticsrouter/pc.go +++ b/apirouter/v1/statisticsrouter/pc.go @@ -37,5 +37,8 @@ func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) { apiRouter.POST("summaryplanrecord", statisRouter.SummaryPlanRecord) //汇总方案定量指标详情历史记录(新版) apiRouter.POST("newsummarydetails", statisRouter.NewSummaryDetails) //方案得分明细(新版) apiRouter.POST("neworgtranscript", statisRouter.OrgTranscriptNew) //行政组织成绩单(新版) + + apiRouter.POST("org_target_annual_statistics", statisRouter.OrgTargetAnnualStatistics) //行政组织年度成绩单 + } } diff --git a/initialization/route/initRoute.go b/initialization/route/initRoute.go index 5c6263b..413d0f7 100644 --- a/initialization/route/initRoute.go +++ b/initialization/route/initRoute.go @@ -77,7 +77,9 @@ func InitialRouter() *gin.Engine { //统计 statisticsApiRouter := apirouter.RouterGroupEntry.StatisticsApiRouter statisticsApiRouter.RouterGroup(VerifyIdentity) - + //注册新闻类接口 + newsClassApiRouter := apirouter.RouterGroupEntry.NewsClassApiRouter + newsClassApiRouter.RouterGroup(VerifyIdentity) } //验证身份接口 无需鉴权Url(主要web端使用) VerifyIdentityWeb := router.Group("") diff --git a/main.go b/main.go index 9a4999c..a6b0015 100644 --- a/main.go +++ b/main.go @@ -4,9 +4,19 @@ import ( "key_performance_indicators/initialization/app" "key_performance_indicators/initialization/databaseinit" "key_performance_indicators/initialization/nosql" + "runtime" ) func main() { + var Ncpu = runtime.NumCPU() + // fmt.Printf("服务器核心数量:%v\n", Ncpu) + if Ncpu-1 <= 0 { + Ncpu = 1 + } else { + Ncpu = Ncpu - 1 + } + + runtime.GOMAXPROCS(Ncpu) //加载数据库 databaseinit.LoadDatabase() //加载Redis diff --git a/models/modelshr/administrative_organization.go b/models/modelshr/administrative_organization.go index 062450f..c56b989 100644 --- a/models/modelshr/administrative_organization.go +++ b/models/modelshr/administrative_organization.go @@ -20,7 +20,7 @@ type AdministrativeOrganization struct { Schoole int64 `json:"schoole" gorm:"column:schoole;type:bigint(20) unsigned;default:0;not null;comment:原知行学院对照码"` KingdeeId string `json:"kingdeeid" gorm:"column:kingdeeid;type:varchar(255) unsigned;default:'';comment:金蝶对照ID"` IsPower int `json:"ispower" gorm:"column:ispower;type:int(1) unsigned;default:2;not null;comment:是否为实权部门"` - Sort int `json:"sort" gorm:"column:sort;type:int(6) unsigned;default:100;not null;comment:是否为实权部门"` + Sort int `json:"sort" gorm:"column:sort;type:int(6) unsigned;default:100;not null;comment:排序"` } func (AdministrativeOrganization *AdministrativeOrganization) TableName() string {