You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
496 lines
16 KiB
496 lines
16 KiB
package examtestpage
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
"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/flipped-aurora/gin-vue-admin/server/utils/redishandel"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
//健康上报
|
|
type HealthReportStat struct{}
|
|
|
|
func (h *HealthReportStat) HealthList(c *gin.Context) {
|
|
var healthReport commonus.GetHealthReport
|
|
err := c.ShouldBindJSON(&healthReport)
|
|
tadayTime := commonus.GetYesterDay()
|
|
if err == nil {
|
|
if healthReport.Date != "" {
|
|
tadayTime = healthReport.Date
|
|
}
|
|
}
|
|
// fmt.Printf("%v===>%v\n", tadayTime, healthReport)
|
|
pv, uv, isTrue, msg := commonus.GetHealthReportStat(tadayTime)
|
|
if isTrue != true {
|
|
response.Result(101, tadayTime, msg, c)
|
|
return
|
|
}
|
|
type outStruct struct {
|
|
Pv int64 `json:"pv"` //应用使用次数
|
|
Uv int64 `json:"uv"` //应用使用成员数
|
|
}
|
|
var healthReportInfo outStruct
|
|
healthReportInfo.Pv = pv
|
|
healthReportInfo.Uv = uv
|
|
// fmt.Printf("%v===>%v===>%v===>%v===>%v\n", tadayTime, pv, uv, isTrue, msg)
|
|
response.Result(200, healthReportInfo, msg, c)
|
|
}
|
|
|
|
//获取企业当前正在运行的上报任务ID列表
|
|
func (h *HealthReportStat) RunHealthList(c *gin.Context) {
|
|
var healthReport commonus.GetHealthReportRun
|
|
err := c.ShouldBindJSON(&healthReport)
|
|
var page int
|
|
var pageSize int64
|
|
page = 0
|
|
pageSize = 100
|
|
if err == nil {
|
|
if healthReport.Page != 0 {
|
|
page = healthReport.Page
|
|
}
|
|
if healthReport.PageSize != 0 {
|
|
pageSize = healthReport.PageSize
|
|
}
|
|
}
|
|
jobMap, isTrue, msg := commonus.GetRunHealthReportJobids(page, pageSize)
|
|
if isTrue != true {
|
|
response.Result(102, isTrue, msg, c)
|
|
return
|
|
}
|
|
// fmt.Printf("%v\n", jobMap)
|
|
response.Result(0, jobMap, msg, c)
|
|
}
|
|
|
|
//获取健康上报任务详情
|
|
func (h *HealthReportStat) PostReportJobInfo(c *gin.Context) {
|
|
var healthReportJob commonus.GetReportJobInfoDate
|
|
err := c.ShouldBindJSON(&healthReportJob)
|
|
if err != nil {
|
|
response.Result(101, healthReportJob, "参数错误!", c)
|
|
return
|
|
}
|
|
if healthReportJob.JobId == "" {
|
|
response.Result(102, err, "参数错误!", c)
|
|
return
|
|
}
|
|
tadayTime := commonus.GetYesterDay()
|
|
if healthReportJob.Date != "" {
|
|
tadayTime = healthReportJob.Date
|
|
}
|
|
strucr, _, _, msg := commonus.GetReportJobInfo(healthReportJob.JobId, tadayTime)
|
|
if strucr.Errcode != 0 {
|
|
response.Result(102, strucr.ErrMsg, "获取数据错误!", c)
|
|
return
|
|
}
|
|
response.Result(0, strucr.JobInfo, msg, c)
|
|
}
|
|
|
|
//获取用户填写答案列表
|
|
func (h *HealthReportStat) PostReportAnswerList(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
|
|
}
|
|
tadayTime := commonus.GetYesterDay()
|
|
if reportAnswer.Date != "" {
|
|
tadayTime = reportAnswer.Date
|
|
}
|
|
var page int
|
|
var pageSize int64
|
|
page = 0
|
|
pageSize = 100
|
|
if reportAnswer.Page != 0 {
|
|
page = reportAnswer.Page
|
|
}
|
|
if reportAnswer.PageSize != 0 {
|
|
pageSize = reportAnswer.PageSize
|
|
}
|
|
// fmt.Printf("pageSize = >%v\n", pageSize)
|
|
// jsonBtye, reportAnswerInfoList, _, msg := commonus.GetUserWriteAnswer(reportAnswer.JobId, tadayTime, page, pageSize)
|
|
_, reportAnswerInfoList, isTrue, msg := commonus.GetUserWriteAnswer(reportAnswer.JobId, tadayTime, page, pageSize)
|
|
// var reportAnswerJson commonus.ReportAnswerResult
|
|
// err = json.Unmarshal(reportByte, &reportAnswerJson)
|
|
// var AdmDivStruct []commonus.AdministrativeDivision
|
|
// for _, v := range reportAnswerInfoList.Answers {
|
|
// for _, v_sun := range v.ReportValues {
|
|
// if v_sun.Text != "" {
|
|
// var AdmDiv commonus.AdministrativeDivision
|
|
|
|
// countSplit := strings.Split(v_sun.Text, "省")
|
|
// if len(countSplit) >= 2 {
|
|
// AdmDiv.Userid = v.Userid
|
|
// AdmDiv.Province = countSplit[0] + "省"
|
|
// countSplitSun := strings.Split(countSplit[1], "市")
|
|
// if len(countSplitSun) > 2 {
|
|
// AdmDiv.City = countSplitSun[0] + "市"
|
|
// AdmDiv.County = countSplitSun[1] + "市"
|
|
// } else {
|
|
// AdmDiv.City = countSplitSun[0] + "市"
|
|
// if len(countSplitSun) == 2 {
|
|
// countSplitSunes := strings.Split(countSplitSun[1], "县")
|
|
// if len(countSplitSun) > 1 {
|
|
// AdmDiv.County = countSplitSunes[0] + "县"
|
|
// }
|
|
// countSplitSunesi := strings.Split(countSplitSun[1], "区")
|
|
// if len(countSplitSunesi) > 1 {
|
|
// AdmDiv.County = countSplitSunesi[0] + "区"
|
|
// }
|
|
|
|
// // fmt.Printf("%v切割地址%v-------------%v\n", v.Userid, countSplitSunes, len(countSplitSunes))
|
|
// }
|
|
|
|
// }
|
|
// AdmDivStruct = append(AdmDivStruct, AdmDiv)
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
|
|
// }
|
|
if isTrue == false {
|
|
response.Result(102, reportAnswerInfoList.ErrMsg, "获取数据错误!", c)
|
|
return
|
|
}
|
|
response.Result(200, reportAnswerInfoList.Answers, msg, c)
|
|
}
|
|
|
|
//获取用户填写答案列表 (全部)
|
|
|
|
//用户填写
|
|
var myStatisWg = sync.WaitGroup{}
|
|
|
|
type dataLockStatistics struct {
|
|
dataMap []map[string]interface{}
|
|
baoJing []map[string]interface{}
|
|
mutext sync.RWMutex
|
|
}
|
|
|
|
//读取锁数据
|
|
func (d *dataLockStatistics) readMyDayData() ([]map[string]interface{}, []map[string]interface{}) {
|
|
d.mutext.RLock()
|
|
defer d.mutext.RUnlock()
|
|
return d.dataMap, d.baoJing
|
|
}
|
|
|
|
func (h *HealthReportStat) PostReportAnswerListAll(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
|
|
}
|
|
tadayTime := commonus.GetYesterDay()
|
|
if reportAnswer.Date != "" {
|
|
tadayTime = reportAnswer.Date
|
|
}
|
|
//判断日期是否已经统计
|
|
calCulTime := commonus.DateToTimeStamp(tadayTime + " 12:00:00")
|
|
var reportInfo locationing.ReportAddress
|
|
errInfo := global.GVA_DB_HealthReport.Where("calcultime = ?", calCulTime).First(&reportInfo).Error
|
|
if errInfo == nil {
|
|
response.Result(102, errInfo, "该日期已经统计", c)
|
|
return
|
|
}
|
|
//获取围栏地址
|
|
var legalAreaList []locationing.LegalArea
|
|
addressListErr := global.GVA_DB_HealthReport.Where("la_state = ?", 1).Find(&legalAreaList).Error
|
|
|
|
if addressListErr != nil {
|
|
fmt.Printf("未设置围栏地址:%v\n", addressListErr)
|
|
}
|
|
// return
|
|
strucr, isTrue, _, msg := commonus.GetReportJobInfo(reportAnswer.JobId, tadayTime)
|
|
//strucr.JobInfo.FinishCnt
|
|
if isTrue != true {
|
|
response.Result(103, err, msg, c)
|
|
return
|
|
}
|
|
dateExcept := strucr.JobInfo.FinishCnt / 100
|
|
dateSurplus := strucr.JobInfo.FinishCnt % 100
|
|
if dateSurplus > 0 {
|
|
dateExcept = dateExcept + 1
|
|
}
|
|
// fmt.Printf("%v****************%v-------->%v\n", strucr.JobInfo.FinishCnt, dateExcept, dateSurplus)
|
|
var dataStruct dataLockStatistics
|
|
for i := 0; i < dateExcept; i++ {
|
|
myStatisWg.Add(1)
|
|
go dataStruct.getUserAnswerList(reportAnswer.JobId, tadayTime, i, 100, legalAreaList)
|
|
}
|
|
myStatisWg.Wait()
|
|
|
|
returData := commonus.MapOut()
|
|
readDataMap, readBaoJinf := dataStruct.readMyDayData()
|
|
|
|
returData["alenda"] = len(readDataMap)
|
|
returData["alendalist"] = readDataMap
|
|
|
|
returData["baojing"] = len(readBaoJinf)
|
|
returData["baojinglist"] = readBaoJinf
|
|
|
|
response.Result(200, returData, msg, c)
|
|
}
|
|
|
|
//获取上报地址异常的数据人员信息
|
|
func (d *dataLockStatistics) getUserAnswerList(jobid, tadayTime string, page int, pageSize int64, legalAreaList []locationing.LegalArea) {
|
|
d.mutext.Lock()
|
|
defer d.mutext.Unlock()
|
|
calCulTime := tadayTime + " 12:00:00"
|
|
timeStamp := commonus.DateToTimeStamp(calCulTime)
|
|
var judgeWriteInfoUser locationing.ReportAddress
|
|
getReportAddressErr := global.GVA_DB_HealthReport.Where("calcultime = ?", timeStamp).Take(&judgeWriteInfoUser).Error
|
|
if getReportAddressErr != nil {
|
|
|
|
_, reportAnswerInfoList, _, _ := commonus.GetUserWriteAnswer(jobid, tadayTime, page, pageSize)
|
|
var AdmDivStruct []commonus.AdministrativeDivision
|
|
var writeInfo []locationing.ReportAddress
|
|
for _, v := range reportAnswerInfoList.Answers {
|
|
for _, v_sun := range v.ReportValues {
|
|
if v_sun.Text != "" {
|
|
var writeInfoUser locationing.ReportAddress
|
|
var AdmDiv commonus.AdministrativeDivision
|
|
AdmDivMap := commonus.MapOut()
|
|
countSplit := strings.Split(v_sun.Text, "省")
|
|
if len(countSplit) >= 2 {
|
|
writeInfoUser.WechatId = v.Userid
|
|
writeInfoUser.Userid = v.Userid
|
|
writeInfoUser.AddTime = time.Now().Unix()
|
|
writeInfoUser.Address = v_sun.Text
|
|
|
|
writeInfoUser.CalCulTime = commonus.DateToTimeStamp(calCulTime)
|
|
|
|
AdmDiv.Userid = v.Userid
|
|
AdmDiv.Province = countSplit[0] + "省"
|
|
writeInfoUser.Province = countSplit[0] + "省"
|
|
AdmDivMap["userid"] = v.Userid
|
|
AdmDivMap["province"] = countSplit[0] + "省"
|
|
|
|
AdmDivMap["id"] = v.IdType
|
|
|
|
countSplitSun := strings.Split(countSplit[1], "市")
|
|
if len(countSplitSun) > 2 {
|
|
AdmDiv.City = countSplitSun[0] + "市"
|
|
AdmDiv.County = countSplitSun[1] + "市"
|
|
writeInfoUser.City = countSplitSun[0] + "市"
|
|
writeInfoUser.County = countSplitSun[1] + "市"
|
|
|
|
AdmDivMap["city"] = countSplitSun[0] + "市"
|
|
AdmDivMap["county"] = countSplitSun[1] + "市"
|
|
} else {
|
|
AdmDiv.City = countSplitSun[0] + "市"
|
|
writeInfoUser.City = countSplitSun[0] + "市"
|
|
AdmDivMap["city"] = countSplitSun[0] + "市"
|
|
if len(countSplitSun) == 2 {
|
|
countSplitSunes := strings.Split(countSplitSun[1], "县")
|
|
if len(countSplitSun) > 1 {
|
|
AdmDiv.County = countSplitSunes[0] + "县"
|
|
writeInfoUser.County = countSplitSunes[0] + "县"
|
|
AdmDivMap["county"] = countSplitSunes[0] + "县"
|
|
}
|
|
countSplitSunesi := strings.Split(countSplitSun[1], "区")
|
|
if len(countSplitSunesi) > 1 {
|
|
AdmDiv.County = countSplitSunesi[0] + "区"
|
|
writeInfoUser.County = countSplitSunes[0] + "区"
|
|
AdmDivMap["county"] = countSplitSunesi[0] + "区"
|
|
}
|
|
|
|
// fmt.Printf("%v切割地址%v-------------%v\n", v.Userid, countSplitSunes, len(countSplitSunes))
|
|
}
|
|
|
|
}
|
|
|
|
// //获取个人信息
|
|
// weChatUserCont := getWechatUserInfo(v.Userid)
|
|
|
|
// writeInfoUser.UserName = weChatUserCont.Name
|
|
// writeInfoUser.UserTel = weChatUserCont.Mobile
|
|
|
|
// AdmDivMap["user_name"] = weChatUserCont.Name
|
|
// AdmDivMap["user_tel"] = weChatUserCont.Name
|
|
|
|
abnormalIsTrue := false
|
|
for _, expVal := range legalAreaList {
|
|
if expVal.ProvinceName == AdmDiv.Province {
|
|
if expVal.CityName == AdmDiv.City {
|
|
abnormalIsTrue = true
|
|
}
|
|
}
|
|
}
|
|
AdmDivMap["abnormalIsTrue"] = abnormalIsTrue
|
|
if abnormalIsTrue == true {
|
|
writeInfoUser.IsDbnormal = 1
|
|
// fmt.Printf("报警1=====>%v", abnormalIsTrue)
|
|
} else {
|
|
writeInfoUser.IsDbnormal = 2
|
|
d.baoJing = append(d.baoJing, AdmDivMap)
|
|
// fmt.Printf("报警2=====>%v", abnormalIsTrue)
|
|
}
|
|
AdmDivStruct = append(AdmDivStruct, AdmDiv)
|
|
d.dataMap = append(d.dataMap, AdmDivMap)
|
|
writeInfo = append(writeInfo, writeInfoUser)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
errDb := global.GVA_DB_HealthReport.Create(&writeInfo).Error
|
|
if errDb != nil {
|
|
|
|
}
|
|
}
|
|
// fmt.Printf("%v切割地址%v-------------%v\n", page, jhs, len(AdmDivStruct))
|
|
myStatisWg.Done()
|
|
}
|
|
|
|
//获取成员信息
|
|
func getWechatUserInfo(weChatId string) (us commonus.UserListStruct) {
|
|
if weChatId == "" {
|
|
return
|
|
}
|
|
redisClient := redishandel.RunRedis()
|
|
isTrue, tokenInfo := redisClient.HashGet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+weChatId)
|
|
if isTrue != true {
|
|
userInfo, _, _ := commonus.GetOneAddressBookMember(weChatId)
|
|
// var callBackData commonus.WechatUserInfo
|
|
// json.Unmarshal(userInfo, &callBackData)
|
|
|
|
// var us commonus.UserListStruct
|
|
json.Unmarshal(userInfo, &us)
|
|
|
|
userMap := commonus.MapOut()
|
|
json.Unmarshal(userInfo, &userMap)
|
|
jsonUser, _ := json.Marshal(us)
|
|
redisClient.SetRedisTime(2678400)
|
|
redisClient.HashSet("deUserAry:wechat_"+global.GVA_CONFIG.RedisPrefix.Alias, "userinfo_"+"_"+weChatId, string(jsonUser))
|
|
fmt.Printf("未经过redis=====>%v\n", weChatId)
|
|
} else {
|
|
// var us commonus.UserListStruct
|
|
json.Unmarshal([]byte(tokenInfo), &us)
|
|
fmt.Printf("经过redis=====>%v\n", weChatId)
|
|
}
|
|
return
|
|
}
|
|
|
|
//添加报警信息通知人
|
|
func (h *HealthReportStat) NoticeUserList(c *gin.Context) {
|
|
// var reportAnswer commonus.GetHealthReportRun
|
|
// err := c.ShouldBindJSON(&reportAnswer)
|
|
// if err != nil {
|
|
// response.Result(101, reportAnswer, "参数错误!", c)
|
|
// return
|
|
// }
|
|
var noticeUserStruct locationing.NoticeUser
|
|
notUserErr := global.GVA_DB_HealthReport.Find(¬iceUserStruct).Error
|
|
if notUserErr != nil {
|
|
response.Result(101, noticeUserStruct, "未能获取到数据!", c)
|
|
return
|
|
}
|
|
response.Result(0, noticeUserStruct, "获取到数据成功!", c)
|
|
}
|
|
|
|
//添加报警人信息
|
|
func (h *HealthReportStat) AddNoticeUser(c *gin.Context) {
|
|
var reportAnswer locationing.NoticeUser
|
|
err := c.ShouldBindJSON(&reportAnswer)
|
|
if err != nil {
|
|
response.Result(101, reportAnswer, "参数错误!", c)
|
|
return
|
|
}
|
|
if reportAnswer.UserWechat == "" {
|
|
response.Result(102, reportAnswer, "请输入微信ID!", c)
|
|
return
|
|
}
|
|
if reportAnswer.UserName == "" {
|
|
response.Result(103, reportAnswer, "请输入被通知人姓名!", c)
|
|
return
|
|
}
|
|
reportAnswer.Time = time.Now().Unix()
|
|
|
|
var reportAnswerSet locationing.NoticeUser
|
|
getNoticUserErr := global.GVA_DB_HealthReport.Where("n_user_wechat = ?", reportAnswer.UserWechat).First(&reportAnswerSet).Error
|
|
if getNoticUserErr == nil {
|
|
response.Result(104, reportAnswerSet, "该通知人已经存在!请不要重复添加!", c)
|
|
return
|
|
}
|
|
notUserErr := global.GVA_DB_HealthReport.Create(&reportAnswer).Error
|
|
if notUserErr != nil {
|
|
response.Result(105, reportAnswer, "写入数据失败!", c)
|
|
return
|
|
}
|
|
response.Result(0, reportAnswer, "写入数据成功!", c)
|
|
}
|
|
|
|
//修改报警人信息
|
|
func (h *HealthReportStat) EiteNoticeUser(c *gin.Context) {
|
|
var reportAnswer locationing.NoticeUser
|
|
err := c.ShouldBindJSON(&reportAnswer)
|
|
if err != nil {
|
|
response.Result(101, reportAnswer, "参数错误!", c)
|
|
return
|
|
}
|
|
if reportAnswer.Id == 0 {
|
|
response.Result(102, reportAnswer, "参数错误!", c)
|
|
return
|
|
}
|
|
if reportAnswer.UserWechat == "" {
|
|
response.Result(103, reportAnswer, "请输入微信ID!", c)
|
|
return
|
|
}
|
|
if reportAnswer.UserName == "" {
|
|
response.Result(104, reportAnswer, "请输入被通知人姓名!", c)
|
|
return
|
|
}
|
|
|
|
var reportAnswerSet locationing.NoticeUser
|
|
getNoticUserErr := global.GVA_DB_HealthReport.Where("n_id = ?", reportAnswer.Id).First(&reportAnswerSet).Error
|
|
if getNoticUserErr != nil {
|
|
response.Result(104, reportAnswerSet, "该通知人不存在!请检查你的输入!", c)
|
|
return
|
|
}
|
|
|
|
reportAnswer.Time = time.Now().Unix()
|
|
notUserErr := global.GVA_DB_HealthReport.Where("n_id = ?", reportAnswer.Id).Save(&reportAnswer).Error
|
|
if notUserErr != nil {
|
|
response.Result(101, reportAnswer, "写入数据失败!", c)
|
|
return
|
|
}
|
|
response.Result(0, reportAnswer, "写入数据成功!", c)
|
|
}
|
|
|
|
//删除报警人信息
|
|
func (h *HealthReportStat) DelNoticeUser(c *gin.Context) {
|
|
var reportAnswer locationing.NoticeUser
|
|
err := c.ShouldBindJSON(&reportAnswer)
|
|
if err != nil {
|
|
response.Result(101, reportAnswer, "参数错误!", c)
|
|
return
|
|
}
|
|
if reportAnswer.Id == 0 {
|
|
response.Result(102, reportAnswer, "参数错误!", c)
|
|
return
|
|
}
|
|
delErr := global.GVA_DB_HealthReport.Where("n_id = ?", reportAnswer.Id).Delete(&reportAnswer).Error
|
|
if delErr != nil {
|
|
response.Result(103, reportAnswer, "删除失败!", c)
|
|
return
|
|
}
|
|
response.Result(0, reportAnswer, "删除成功!", c)
|
|
}
|
|
|