12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- package controllers
-
- import (
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "XT_New/utils"
- "fmt"
- "github.com/astaxie/beego"
- "strconv"
- "strings"
- "time"
- )
-
- type StatisticsApiController struct {
- BaseAuthAPIController
- }
-
- func StatisticsApiRegistRouters() {
- beego.Router("/api/statistisc/index", &StatisticsApiController{}, "get:GetStatistics")
- beego.Router("/api/qc/statistiscall/get", &StatisticsApiController{}, "get:GetAllInspectionStatistisc")
- beego.Router("/api/qc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonInspectionStatistisc")
- beego.Router("/api/qc/statistiscperson/list", &StatisticsApiController{}, "get:GetInsepctionList")
- beego.Router("/api/qc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientInspectionStatistisc")
- beego.Router("/api/qc/patientinspectionstatistis/get", &StatisticsApiController{}, "get:GetFivePatientInspectionStatistisc")
-
- beego.Router("/api/commonqc/statistiscall/get", &StatisticsApiController{}, "get:GetAllCommonInspectionStatistisc")
- beego.Router("/api/commonqc/statistiscperson/get", &StatisticsApiController{}, "get:GetPersonCommonInspectionStatistisc")
- beego.Router("/api/commonqc/patientstatistiscall/get", &StatisticsApiController{}, "get:GetPatientCommonInspectionStatistisc")
-
- //透析总量统计
- beego.Router("/api/commonqc/dialysis/total", &StatisticsApiController{}, "get:GetDialysisTotal")
- beego.Router("/api/commonqc/dialysis/detail", &StatisticsApiController{}, "get:GetDialysisTotalDetail")
- beego.Router("/api/commonqc/dialysis/details", &StatisticsApiController{}, "get:GetDialysisTotalDetailInfo")
-
- beego.Router("/api/commonqc/anticoagulant", &StatisticsApiController{}, "get:GetAnticoagulant")
- beego.Router("/api/commonqc/anticoagulant/detail", &StatisticsApiController{}, "get:GetAnticoagulantDetail")
-
- beego.Router("/api/commonqc/dialyzer", &StatisticsApiController{}, "get:GetDialyzer")
- beego.Router("/api/commonqc/dialyzer/config", &StatisticsApiController{}, "get:GetDialyzerConfig")
- beego.Router("/api/commonqc/dialyzer/detail", &StatisticsApiController{}, "get:GetDialyzerDetail")
-
- beego.Router("/api/commonqc/dialysistreat/finish", &StatisticsApiController{}, "get:GetDialysisTreatFinsh")
- beego.Router("/api/commonqc/dialysistreat/detail", &StatisticsApiController{}, "get:GetDialysisTreatDetail")
-
- }
-
- func (c *StatisticsApiController) GetDialysisTreatFinsh() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- data, _ := service.GetDialysisCompletionRate(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- total, _ := service.GetDialysisCompletionTotal(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "data": data,
- "total": total,
- })
- }
- func (c *StatisticsApiController) GetDialysisTreatDetail() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- data, total, _ := service.GetDialysisCompletionDetail(c.GetAdminUserInfo().CurrentOrgId, startTime, endTime, mode, limit, page)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": data,
- "total": total,
- })
- }
-
- func (c *StatisticsApiController) GetDialysisTotal() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- origin, _ := c.GetInt64("origin")
- time_way, _ := c.GetInt64("time_way")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- if mode == 0 { //统计透析模式不限
- //获取总人数
- p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
- count_struct, _ := service.GetNewDialysisCountMode(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin, 0)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": p_total,
- "list": count_struct,
- })
- } else { //固定某个模式
- // 拆分日期范围
- dates, err := splitDateRange(start_date, end_date)
- if err != nil {
- fmt.Println("Error:", err)
- return
- }
-
- var cuss []models.CustomDialysisData
- p_total, _ := service.GetNewDialysiTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, origin)
- switch time_way {
- case 1:
- // 按周统计
- weeks := groupByWeek(dates)
- for _, week := range weeks {
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(week[0].Unix(), week[len(week)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(week[0].String(), " ")[0] + "~" + strings.Split(week[len(week)-1].String(), " ")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- }
-
- break
- case 2:
- startDate, err := time.Parse("2006-01-02", start_date)
- if err != nil {
- fmt.Println("Error parsing start date:", err)
- return
- }
-
- endDate, err := time.Parse("2006-01-02", end_date)
- if err != nil {
- fmt.Println("Error parsing end date:", err)
- return
- }
- dailyDates := splitByDay(startDate, endDate)
- for _, date := range dailyDates {
- //fmt.Println(date)
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(date.Unix(), date.Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = date.Format("2006-01-02")
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
-
- }
-
- break
- case 3:
- // 按月统计
- months := groupByMonth(dates)
- for _, month := range months {
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(month[0].Unix(), month[len(month)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(month[0].String(), " ")[0] + "~" + strings.Split(month[len(month)-1].String(), " ")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- //fmt.Println("Month:", month[0], "~", month[len(month)-1])
- }
- break
- case 4:
- // 按年统计
- years := groupByYear(dates)
- for _, year := range years {
- var cus models.CustomDialysisData
- counts, _ := service.GetNewDialysisCountModeTwo(year[0].Unix(), year[len(year)-1].Unix(), c.GetAdminUserInfo().CurrentOrgId, origin, mode)
- cus.Date = strings.Split(year[0].String(), " ")[0] + "~" + strings.Split(year[len(year)-1].String(), " ")[0]
- cus.Count = counts.Count
- cus.Total = p_total
- cuss = append(cuss, cus)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": cuss,
- })
- }
- break
- }
- }
-
- }
- func (c *StatisticsApiController) GetDialysisTotalDetail() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- mode, _ := c.GetInt64("mode")
- origin, _ := c.GetInt64("origin")
- time_way, _ := c.GetInt64("time_way")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- if origin == 1 {
- data, _ := service.GetDialysisStats(startTime, endTime, time_way, mode)
- c.ServeSuccessJSON(map[string]interface{}{
- "data": data,
- })
- } else {
- data, _ := service.GetScheduleStats(startTime, endTime, time_way, mode)
- c.ServeSuccessJSON(map[string]interface{}{
- "data": data,
- })
- }
- }
- func (c *StatisticsApiController) GetDialysisTotalDetailInfo() {
-
- }
-
- func (c *StatisticsApiController) GetAnticoagulant() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- total, err2 := service.GetAnticoagulantTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err2 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- anticoagulantData, err := service.GetAnticoagulantData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- type respData struct {
- Name string `json:"name"`
- Count int `json:"count"`
- Percentage float64 `json:"percentage"`
- }
- var respDatas []respData
- for anticoagulant, count := range anticoagulantData {
- var respData respData
- respData.Name = anticoagulant
- respData.Count = count
- respData.Percentage = float64(count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "data": respDatas,
- })
-
- }
- func (c *StatisticsApiController) GetAnticoagulantDetail() {
- anticoagulant, _ := c.GetInt64("anticoagulant")
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- prescriptions, total, _ := service.GetPrescriptionByAnticoagulant(page, limit, c.GetAdminUserInfo().CurrentOrgId, anticoagulant, startTime, endTime)
-
- c.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- "total": total,
- })
-
- }
-
- func (c *StatisticsApiController) GetDialyzer() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- total, err2 := service.GetDialyzerTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err2 != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- dialyzers, err := service.GetDialyzerData(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- type respData struct {
- Name string `json:"name"`
- Count int `json:"count"`
- Percentage float64 `json:"percentage"`
- }
- var respDatas []respData
- for _, item := range dialyzers {
- var respData respData
- respData.Name = item.Dialyzer
- respData.Count = item.Count
- respData.Percentage = float64(item.Count) / float64(total) * 100
- respDatas = append(respDatas, respData)
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "data": respDatas,
- })
-
- }
- func (c *StatisticsApiController) GetDialyzerDetail() {
- dialyzer := c.GetString("Dialyzer")
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- timeLayout := "2006-01-02"
- page, _ := c.GetInt64("page", 0)
- limit, _ := c.GetInt64("limit", 0)
- if page <= 0 {
- page = 1
- }
- if limit <= 0 {
- limit = 10
- }
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
- prescriptions, total, _ := service.GetPrescriptionByDialyzer(page, limit, c.GetAdminUserInfo().CurrentOrgId, dialyzer, startTime, endTime)
- c.ServeSuccessJSON(map[string]interface{}{
- "prescriptions": prescriptions,
- "total": total,
- })
-
- }
- func (c *StatisticsApiController) GetDialyzerConfig() {
- dialyzers, _ := service.GetDialyzerSummary(c.GetAdminUserInfo().CurrentOrgId)
- c.ServeSuccessJSON(map[string]interface{}{
- "dialyzers": dialyzers,
- })
- }
-
- // 配置检验数据查询
- func (this *StatisticsApiController) GetInsepctionList() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- configurationlist, err := service.GetInsepctionConfigurationList(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationlist": configurationlist,
- })
- }
- func (c *StatisticsApiController) GetAllCommonInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- //患者总数
- patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
- //获取配置
- reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- max, _ := strconv.ParseFloat(config.LargeRange, 64)
- min, _ := strconv.ParseFloat(config.MinRange, 64)
-
- normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取数值异常的总数
- unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- "reference": reference,
- "config": config,
- })
-
- }
- func (c *StatisticsApiController) GetPersonCommonInspectionStatistisc() {
- start_date := c.GetString("start_time")
- end_date := c.GetString("end_time")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
- patient_id, _ := c.GetInt64("patient_id")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
-
- //获取配置
- reference, _ := service.GetInspectionReferenceFour(config.InspectionMajor, config.InspectionMinor, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- }
- func (c *StatisticsApiController) GetPatientCommonInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
- item_type, _ := c.GetInt64("item_type")
- keyword := c.GetString("keyword")
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- //获取配置
- reference, _ := service.GetInspectionReferenceFour(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- //获取数值在正常范围内的总数
-
- config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
- max, _ := strconv.ParseFloat(config.LargeRange, 64)
- min, _ := strconv.ParseFloat(config.MinRange, 64)
-
- //max, _ := strconv.ParseFloat(reference.RangeMax, 64)
- //min, _ := strconv.ParseFloat(reference.RangeMin, 64)
- //config, _ := service.GetConfigurationById(project_id, item_id, c.GetAdminUserInfo().CurrentOrgId)
-
- switch item_type {
- case 1:
- list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- case 2:
- list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- case 3:
- list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- break
- }
- }
-
- func (c *StatisticsApiController) GetFivePatientInspectionStatistisc() {
- //start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- //keyword := c.GetString("keyword")
- //timeLayout := "2006-01-02"
- //loc, _ := time.LoadLocation("Local")
-
- dynamicFields := make([]map[string]interface{}, 0)
- list, _ := service.GetLatestInspectionValues(c.GetAdminUserInfo().CurrentOrgId, strings.Split(end_date, "-")[0]+"-"+strings.Split(end_date, "-")[1])
- fmt.Println(list)
-
- for _, result := range list {
- fmt.Println(result)
- // 打印患者ID
- nb := result["姓名"].([]byte)
- name := string(nb)
-
- //ynamicFields := make([]map[string]interface{})
-
- //var dynamicFields DynamicData
- ynamicField := make(map[string]interface{})
- ynamicField["姓名"] = name
- // 打印其他列的值
- for columnName, columnValue := range result {
- // 跳过患者ID列
-
- if columnName == "姓名" {
- continue
- }
- // 检查值是否为nil
- if columnValue == nil {
- fmt.Printf("Column: %s, Value: <nil>\n", columnName)
- continue
- }
-
- // 将字节切片转换为字符串
- byteValue, ok := columnValue.([]byte)
- if !ok {
- // 如果无法转换为[]byte,输出错误信息
- fmt.Printf("Error: Unable to convert value for column %s to []byte\n", columnName)
- continue
- }
-
- // 将字节切片转换为字符串
- strValue := string(byteValue)
-
- // 尝试将字符串转换为浮点数
- floatValue, err := strconv.ParseFloat(strValue, 64)
- if err != nil {
- // 如果转换失败,输出错误信息
- fmt.Printf("Error converting value for column %s: %v\n", columnName, err)
- } else {
- // 如果转换成功,输出列名和浮点数值
- fmt.Printf("Column: %s, Value: %f\n", columnName, floatValue)
- }
- ynamicField["年月"] = strings.Split(end_date, "-")[0] + "-" + strings.Split(end_date, "-")[1]
- ynamicField[columnName] = floatValue
- dynamicFields = append(dynamicFields, ynamicField)
- }
- }
-
- seen := make(map[interface{}]struct{})
- var uniqueFields []map[string]interface{}
-
- for _, field := range dynamicFields {
- value := field["姓名"]
- // 如果值未在map中出现过,则将其添加到新的切片中,并将其添加到map中
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- uniqueFields = append(uniqueFields, field)
- }
- }
-
- c.ServeSuccessJSON(map[string]interface{}{
- "list": uniqueFields,
- })
- //list, _ := service.GetPatientFiveInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, keyword)
- //
- //var names []string
- //
- //for _, item := range list {
- // names = append(names, item.ItemName)
- //}
- //
- //names = RemoveRepeatedNameElement(names)
- //fmt.Println(names)
- //
- //var tempList []models.InspectionTen
- //list_two := RemoveRepeatedInspectPatientElement(list)
- //for _, item := range list_two {
- // var temp models.InspectionTen
- // var temptwos []models.InspectionValue
- // temp.PatientId = item.PatientId
- // temp.Name = item.Name
- // for _, subitem := range list {
- // if item.PatientId == subitem.PatientId {
- // var temptwo models.InspectionValue
- // temptwo.Name = subitem.ItemName
- // temptwo.Value = subitem.InspectValue
- // temptwos = append(temptwos, temptwo)
- // }
- // }
- // temp.Values = temptwos
- // tempList = append(tempList, temp)
- //}
- //
- //var filtered []string
- //for _, item := range names {
- // if item != "a" {
- // filtered = append(filtered, item)
- // }
- //}
- //
- //for _, item := range tempList {
- // for _, subitem := range item.Values {
- // for _, name := range filtered {
- // if subitem.Name != name {
- // filtered = append(filtered, name)
- // }
- // }
- // }
- //}
- //
- ////// 将剩余字符串填充到 Inspection 数组中
- ////for _, name := range filtered {
- //// var temptwo models.InspectionValue
- //// temptwo.Name = subitem.ItemName
- //// temptwo.Value = subitem.InspectValue
- //// temptwos = append(temptwos, temptwo)
- ////}
- //
- //for _, item := range tempList {
- // //for _, subitem := range item.Values {
- // var temptwo models.InspectionValue
- // for _, name := range filtered {
- // temptwo.Name = name
- // temptwo.Value = ""
- // }
- // item.Values = append(item.Values, temptwo)
- // //}
- // fmt.Println(item.Values)
- //}
-
- }
- func (c *StatisticsApiController) GetPatientInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
- item_type, _ := c.GetInt64("item_type")
- //order_type, _ := c.GetInt64("order_type")
- keyword := c.GetString("keyword")
- s_type, _ := c.GetInt64("type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
- //获取数值在正常范围内的总数
-
- max, _ := strconv.ParseFloat(reference.RangeMax, 64)
- min, _ := strconv.ParseFloat(reference.RangeMin, 64)
-
- switch item_type {
- case 0:
-
- break
- case 1:
- if s_type == 2 { //KTV
- list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetUnusualKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
-
- list, _ := service.GetUnusualInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
-
- }
-
- break
- case 2:
- if s_type == 2 { //KTV
- list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetPatientNotKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
-
- list, _ := service.GetPatientNotInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- }
-
- break
- case 3:
- if s_type == 2 { //KTV
- list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 0, 1.2, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else if s_type == 3 { //URR
- list, _ := service.GetNormalKTVORURRInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 0, 65, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- })
- } else {
- list, _ := service.GetNormalInspectionPatientList(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min, keyword)
- c.ServeSuccessJSON(map[string]interface{}{
- "list": list,
- "reference": reference,
- })
- }
-
- break
- }
- }
- func (c *StatisticsApiController) GetAllInspectionStatistisc() {
- start_date := c.GetString("start_date")
- end_date := c.GetString("end_date")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
-
- s_type, _ := c.GetInt64("type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- //患者总数
- patientCount := service.GetPatientCount(c.GetAdminUserInfo().CurrentOrgId)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
- //获取数值在正常范围内的总数
-
- max, _ := strconv.ParseFloat(reference.RangeMax, 64)
- min, _ := strconv.ParseFloat(reference.RangeMin, 64)
-
- if s_type == 2 {
- normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
- //获取数值异常的总数
- unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, 1.2)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- })
-
- } else if s_type == 3 {
- normalTotal, _ := service.GetNormalKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
- //获取数值异常的总数
- //unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1.2)
- unusualTotal, _ := service.GetUnusualKTVORURRInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, 65)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotKTVORURRInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- })
- } else {
- normalTotal, _ := service.GetNormalInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取数值异常的总数
- unusualTotal, _ := service.GetUnusualInspectionTotalByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName, max, min)
- //获取没有检查的患者总数
- noCheckTotal, _ := service.GetPatientNotInspectionTotal(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "normal_total": normalTotal,
- "unusual_total": unusualTotal,
- "no_check_total": noCheckTotal,
- "reference": reference,
- })
- }
-
- }
- func (c *StatisticsApiController) GetPersonInspectionStatistisc() {
- start_date := c.GetString("start_time")
- end_date := c.GetString("end_time")
- project_id, _ := c.GetInt64("project_id")
- item_id, _ := c.GetInt64("item_id")
- patient_id, _ := c.GetInt64("patient_id")
- s_type, _ := c.GetInt64("type")
-
- timeLayout := "2006-01-02"
- loc, _ := time.LoadLocation("Local")
- var startTime int64
- if len(start_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_date+" 00:00:00", loc)
- fmt.Println("err-----------", err)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- startTime = theTime.Unix()
- }
- var endTime int64
- if len(end_date) > 0 {
- theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_date+" 23:59:59", loc)
- if err != nil {
- utils.ErrorLog(err.Error())
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- endTime = theTime.Unix()
- }
-
- if s_type == 2 {
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(1014, 10950)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10950, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- } else if s_type == 3 {
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(1014, 10951)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientKTVORURRInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, 1014, 10951, patient_id)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
-
- } else {
- patient, _ := service.GetFaPiaoPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
- //获取配置
- reference, _ := service.GetInspectionReferenceThree(project_id, item_id)
- //获取数值在正常范围内的总数
- inspections, _ := service.GetPatientInspectionByID(startTime, endTime, c.GetAdminUserInfo().CurrentOrgId, patient_id, reference.ItemName)
- c.ServeSuccessJSON(map[string]interface{}{
- "patient": patient,
- "reference": reference,
- "inspections": inspections,
- })
- }
-
- }
- func (c *StatisticsApiController) GetStatistics() {
- adminUserInfo := c.GetAdminUserInfo()
-
- // thisTime := time.Now()
- year, month, day := time.Now().Date()
- todayTime := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
- startYearTime := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
- endYearTime := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.Local)
-
- todayWeek := int(todayTime.Weekday())
- if todayWeek == 0 {
- todayWeek = 7
- }
-
- weekEnd := 7 - todayWeek
- weekStart := weekEnd - 6
- // endDay := todayTime.AddDate(0, 0, weekEnd)
- startDay := todayTime.AddDate(0, 0, weekStart)
- //患者总数
- patientCount := service.GetPatientCount(adminUserInfo.CurrentOrgId)
- //今日透析
- todayDialysisCount := service.GetDayDialysisCount(adminUserInfo.CurrentOrgId, todayTime.Unix())
-
- //本周透析
- weekDaylysisCount := service.GetTimebetweenDialysisCount(adminUserInfo.CurrentOrgId, startDay.Unix(), todayTime.Unix())
-
- //传染病
- diseaseCounts := service.GetPatientContagionCounts(adminUserInfo.CurrentOrgId)
-
- //性别分布
- genderCounts := service.GetPatientGenderCounts(adminUserInfo.CurrentOrgId)
-
- //年龄分布
- ageCounts := service.GetPatiendAgeBetweenCount(adminUserInfo.CurrentOrgId)
-
- //透析模式
- modeCounts := service.GetPatientDialysisModeBetweenCount(adminUserInfo.CurrentOrgId, startYearTime.Unix(), endYearTime.Unix())
-
- c.ServeSuccessJSON(map[string]interface{}{
- "patient_count": patientCount,
- "today_dialysis_count": todayDialysisCount,
- "week_daylysis_count": weekDaylysisCount,
- "disease_counts": diseaseCounts,
- "gender_counts": genderCounts,
- "age_counts": ageCounts,
- "mode_counts": modeCounts,
- })
-
- }
-
- func RemoveRepeatedInspectPatientElement(arr []models.InspectionTenOne) (newArr []models.InspectionTenOne) {
- newArr = make([]models.InspectionTenOne, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i].PatientId == arr[j].PatientId {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func RemoveRepeatedNameElement(arr []string) (newArr []string) {
- newArr = make([]string, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i] == arr[j] {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- // 根据指定的日期范围拆分成周、月、年
- func splitDateRange(startDate, endDate string) ([]time.Time, error) {
- startTime, err := time.Parse("2006-01-02", startDate)
- if err != nil {
- return nil, err
- }
-
- endTime, err := time.Parse("2006-01-02", endDate)
- if err != nil {
- return nil, err
- }
-
- var result []time.Time
-
- for date := startTime; date.Before(endTime) || date.Equal(endTime); date = date.AddDate(0, 0, 1) {
- result = append(result, date)
- }
-
- return result, nil
- }
-
- // 按周统计日期
- func groupByWeek(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentWeek []time.Time
-
- for _, date := range dates {
- currentWeek = append(currentWeek, date)
- if date.Weekday() == time.Sunday {
- result = append(result, currentWeek)
- currentWeek = nil
- }
- }
-
- if len(currentWeek) > 0 {
- result = append(result, currentWeek)
- }
-
- return result
- }
-
- // 按月统计日期
- func groupByMonth(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentMonth []time.Time
- lastMonth := dates[0].Month()
-
- for _, date := range dates {
- if date.Month() != lastMonth {
- result = append(result, currentMonth)
- currentMonth = nil
- lastMonth = date.Month()
- }
- currentMonth = append(currentMonth, date)
- }
-
- if len(currentMonth) > 0 {
- result = append(result, currentMonth)
- }
-
- return result
- }
-
- // 按年统计日期
- func groupByYear(dates []time.Time) [][]time.Time {
- var result [][]time.Time
- var currentYear []time.Time
- lastYear := dates[0].Year()
-
- for _, date := range dates {
- if date.Year() != lastYear {
- result = append(result, currentYear)
- currentYear = nil
- lastYear = date.Year()
- }
- currentYear = append(currentYear, date)
- }
-
- if len(currentYear) > 0 {
- result = append(result, currentYear)
- }
-
- return result
- }
-
- // 将日期拆分为按天统计
- func splitByDay(startDate, endDate time.Time) []time.Time {
- var dates []time.Time
- for d := startDate; !d.After(endDate); d = d.AddDate(0, 0, 1) {
- dates = append(dates, d)
- }
- return dates
- }
|