package examtestpage import ( "fmt" "reflect" "strings" "time" "github.com/flipped-aurora/gin-vue-admin/server/commonus" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/flipped-aurora/gin-vue-admin/server/model/locationing" "github.com/gin-gonic/gin" ) //健康上报列表 func (h *HealthReportStat) PostReportAnswerListLimit(c *gin.Context) { var reportAnswer commonus.ReportAnswerStruct err := c.ShouldBindJSON(&reportAnswer) if err != nil { response.Result(101, reportAnswer, "参数错误!", c) return } if reportAnswer.JobId == "" { response.Result(102, err, "参数错误!", c) return } // if reportAnswer.Date == "" { // response.Result(103, err, "请输入要查询的日期!", c) // return // } tadayTime := commonus.GetYesterDay() if reportAnswer.Date != "" { tadayTime = reportAnswer.Date } if reportAnswer.PageSize == 0 { reportAnswer.PageSize = 100 } if reportAnswer.Page <= 0 { reportAnswer.Page = 1 } // tadayTime := reportAnswer.Date //判断日期是否已经统计 calCulTime := commonus.DateToTimeStamp(tadayTime + " 12:00:00") psge := (reportAnswer.Page - 1) * reportAnswer.PageSize var reportInfo locationing.ReportAddress errInfo := global.GVA_DB_HealthReport.Where("calcultime = ?", calCulTime).Limit(reportAnswer.PageSize).Offset(psge).First(&reportInfo).Error var reportInfoAry []locationing.ReportAddress if errInfo == nil { //当前日期存在,查询数据库 listErr := global.GVA_DB_HealthReport.Where("calcultime = ?", calCulTime).Limit(reportAnswer.PageSize).Offset(psge).Find(&reportInfoAry).Error if listErr != nil { response.Result(104, reportInfoAry, "数据获取失败!", c) return } var normalData []locationing.ReportAddress //正常数据 var abnormalData []locationing.ReportAddress //异常数据 for _, v := range reportInfoAry { if v.IsDbnormal == 1 { normalData = append(normalData, v) } else { abnormalData = append(abnormalData, v) } } returnData := commonus.MapOut() returnData["allData"] = reportInfoAry returnData["allData_quantity"] = len(reportInfoAry) returnData["normalData"] = normalData returnData["normalData_quantity"] = len(normalData) returnData["abnormalData"] = abnormalData returnData["abnormalData_quantity"] = len(abnormalData) response.Result(0, returnData, "查询成功!", c) return } else { //当前日期不存在,获取数据写入数据库 var legalAreaList []locationing.LegalArea addressListErr := global.GVA_DB_HealthReport.Where("la_state = ?", 1).Find(&legalAreaList).Error if addressListErr != nil { response.Result(105, legalAreaList, "未设置围栏地址!", c) return } weChatPage := reportAnswer.Page - 1 if weChatPage < 0 { weChatPage = 0 } _, reportAnswerInfoList, _, _ := commonus.GetUserWriteAnswer(reportAnswer.JobId, tadayTime, weChatPage, int64(reportAnswer.PageSize)) var writeInfo []locationing.ReportAddress var normalInfo []locationing.ReportAddress var abnormalInfo []locationing.ReportAddress for _, v := range reportAnswerInfoList.Answers { for _, v_sun := range v.ReportValues { // fmt.Printf("v_sun.Text ===========>%v\n", v_sun.Text) if v_sun.Text != "" { countSplit := strings.Split(v_sun.Text, "省") if len(countSplit) >= 2 { var writeInfoUser locationing.ReportAddress writeInfoUser.WechatId = v.Userid writeInfoUser.Userid = v.Userid writeInfoUser.AddTime = time.Now().Unix() writeInfoUser.Address = v_sun.Text writeInfoUser.CalCulTime = calCulTime writeInfoUser.Address = v_sun.Text writeInfoUser.Province = countSplit[0] + "省" countSplitSun := strings.Split(countSplit[1], "市") if len(countSplitSun) > 2 { writeInfoUser.City = countSplitSun[0] + "市" writeInfoUser.County = countSplitSun[1] + "市" } else { writeInfoUser.City = countSplitSun[0] + "市" if len(countSplitSun) == 2 { countSplitSunes := strings.Split(countSplitSun[1], "县") if len(countSplitSun) > 1 { writeInfoUser.County = countSplitSunes[0] + "县" } countSplitSunesi := strings.Split(countSplitSun[1], "区") if len(countSplitSunesi) > 1 { writeInfoUser.County = countSplitSunes[0] + "区" } } } abnormalIsTrue := false for _, expVal := range legalAreaList { if expVal.ProvinceName == writeInfoUser.Province { if expVal.CityName == writeInfoUser.City { abnormalIsTrue = true } } } if abnormalIsTrue == true { writeInfoUser.IsDbnormal = 1 // fmt.Printf("报警1=====>%v", abnormalIsTrue) // normalInfoUser = writeInfoUser } else { writeInfoUser.IsDbnormal = 2 // abnormalInfoUser = writeInfoUser // fmt.Printf("报警2=====>%v", abnormalIsTrue) } writeInfo = append(writeInfo, writeInfoUser) } } } } if reflect.DeepEqual(writeInfo, []locationing.ReportAddress{}) { response.Result(106, writeInfo, "没有要处理的数据!", c) return } errDb := global.GVA_DB_HealthReport.Create(&writeInfo).Error if errDb != nil { } for _, val := range writeInfo { if val.IsDbnormal == 1 { var normalInfoUser locationing.ReportAddress normalInfoUser.Id = val.Id normalInfoUser.WechatId = val.WechatId normalInfoUser.Province = val.Province normalInfoUser.City = val.City normalInfoUser.County = val.County normalInfoUser.Userid = val.Userid normalInfoUser.AddTime = val.AddTime normalInfoUser.CalCulTime = val.CalCulTime normalInfoUser.Address = val.Address normalInfoUser.IsDbnormal = val.IsDbnormal normalInfoUser.UserName = val.UserName normalInfoUser.UserTel = val.UserTel normalInfo = append(normalInfo, normalInfoUser) } else { var abnormalInfoUser locationing.ReportAddress abnormalInfoUser.Id = val.Id abnormalInfoUser.WechatId = val.WechatId abnormalInfoUser.Province = val.Province abnormalInfoUser.City = val.City abnormalInfoUser.County = val.County abnormalInfoUser.Userid = val.Userid abnormalInfoUser.AddTime = val.AddTime abnormalInfoUser.CalCulTime = val.CalCulTime abnormalInfoUser.Address = val.Address abnormalInfoUser.IsDbnormal = val.IsDbnormal abnormalInfoUser.UserName = val.UserName abnormalInfoUser.UserTel = val.UserTel abnormalInfo = append(abnormalInfo, abnormalInfoUser) } } returnData := commonus.MapOut() returnData["allData"] = writeInfo returnData["allData_quantity"] = len(writeInfo) returnData["normalData"] = normalInfo returnData["normalData_quantity"] = len(normalInfo) returnData["abnormalData"] = abnormalInfo returnData["abnormalData_quantity"] = len(abnormalInfo) response.Result(0, returnData, "查询成功!", c) return } } //向相关人员发送信息 func (h *HealthReportStat) SendRelevantPersonnelMsg(c *gin.Context) { tadayTime := commonus.GetYesterDay() //获取昨日信息 calCulTime := commonus.DateToTimeStamp(tadayTime + " 12:00:00") var reportInfoAry []locationing.ReportAddress //统计表模型 listErr := global.GVA_DB_HealthReport.Where("calcultime = ? and isabnormal = 2", calCulTime).Find(&reportInfoAry).Error if listErr != nil { response.Result(106, reportInfoAry, "没有异常人员信息数据!", c) return } //判断报警人是不是为空 if len(reportInfoAry) > 0 { var readBaoJinf []map[string]interface{} for _, v := range reportInfoAry { callPolice := commonus.MapOut() callPolice["id"] = v.Id callPolice["userid"] = v.WechatId callPolice["province"] = v.Province callPolice["city"] = v.City callPolice["county"] = v.County callPolice["userid"] = v.Userid callPolice["addtime"] = v.AddTime callPolice["calcultime"] = v.CalCulTime callPolice["address"] = v.Address callPolice["isabnormal"] = v.IsDbnormal callPolice["user_name"] = v.UserName callPolice["user_tel"] = v.UserTel readBaoJinf = append(readBaoJinf, callPolice) } //给相关人员发送信息 sendMessAgeAlarm(calCulTime, readBaoJinf) } else { fmt.Println("没有异常人员!") } }