绩效考核
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.
 
 
 

781 lines
25 KiB

package examtestpage
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"sync"
"time"
"gin_server_admin/commonus"
"gin_server_admin/global"
"gin_server_admin/model/common/response"
"gin_server_admin/model/locationing"
"gin_server_admin/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 int
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, int64(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
// fmt.Printf("时间是=》%v\n", reportAnswer.Date)
}
//判断日期是否已经统计
sendCalCulTime := tadayTime + " 12:00:00"
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, tadayTime, "该日期已经统计", 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
//获取全国风险等级
nationalRiskLevel, riskIsTrue := commonus.GetNationalRiskArea()
for i := 0; i < dateExcept; i++ {
myStatisWg.Add(1)
go dataStruct.getUserAnswerList(reportAnswer.JobId, tadayTime, sendCalCulTime, i, 100, legalAreaList, nationalRiskLevel, riskIsTrue)
}
myStatisWg.Wait()
returData := commonus.MapOut()
readDataMap, readBaoJinf := dataStruct.readMyDayData()
returData["alenda"] = len(readDataMap)
returData["alendalist"] = readDataMap
returData["baojing"] = len(readBaoJinf)
returData["baojinglist"] = readBaoJinf
//计算未上报人员
// CalculationNotReport(tadayTime, calCulTime, readDataMap)
//判断报警人是不是超员
if len(readBaoJinf) > 0 {
//给相关人员发送信息
// sendMessAgeAlarm(calCulTime, readBaoJinf)
}
response.Result(0, returData, msg, c)
}
/*
计算未上报人员
@time 计算日期
@decisionTime 判定时间
@reportedPeople 已经上报的人
*/
func CalculationNotReport(time string, decisionTime int64, reportedPeople []map[string]interface{}) {
userStruct, isTrues := commonus.GetMemberList()
if isTrues != true {
return
}
userDateCount := len(userStruct)
userCurlCount := len(reportedPeople)
fmt.Printf("%v==================>%v", userDateCount, userCurlCount)
}
// 向相关人员发送警报 https://docu.hxgk.group/images/2021_11/205c2d8d35491880a1ac9f03d6e879d3.jpg
func sendMessAgeAlarm(calCulTime int64, alarmUser []map[string]interface{}) (sendBakc map[string]interface{}) {
// fmt.Printf("%v\n", reflect.TypeOf(alarmUser))
var sendText string
sendText = fmt.Sprintf("异常上报地址人员(%v)\n<a href='https://www.hxgk.group/excereportaddress?time=%v'>查看详情</a>\n", commonus.TimeStampToDate(calCulTime, 4), calCulTime)
jiBuQi := 0
for i, v := range alarmUser {
jiBuQi++
// fmt.Printf("%v---------------------->%v\n", i, v["userid"])
userID := fmt.Sprintf("%v", v["userid"])
weChatUserCont := commonus.GetWechatUserInfo(userID)
// sendText = "异常上报地址人员\n<a href=\"http://work.weixin.qq.com?time=" + strconv.FormatInt(calCulTime, 10) + "\">产看详情</a>\n" + weChatUserCont.Name + v["province"] + v["city"] + v["county"]
sendText = sendText + fmt.Sprintf("%v、%v %v%v%v TEL:%v\n", i+1, weChatUserCont.Name, v["province"], v["city"], v["county"], weChatUserCont.Mobile)
}
var reportAnswerSet []locationing.NoticeUser
getNoticUserErr := global.GVA_DB_HealthReport.Where("n_state = ?", 1).Find(&reportAnswerSet).Error
if getNoticUserErr == nil {
sendUserKey := ""
for u_i, u_v := range reportAnswerSet {
if u_i == 0 {
sendUserKey = u_v.UserWechat
} else {
sendUserKey = sendUserKey + "|" + u_v.UserWechat
}
}
if sendUserKey != "" {
// var sendTxt commonus.SendText
// sendTxt.Touser = sendUserKey
// sendTxt.MsgType = "text"
// sendTxt.Text.Content = sendText
// appId, _ := strconv.ParseInt(global.GVA_CONFIG.WorkWechatSchool.AgentId, 10, 64)
// sendTxt.AgentId = appId
// sendTxt.DuplicateCheckInterval = 1800
// sendTxt.SendTextMessage()
var sendCont commonus.ArticlesStruct
sendCont.Title = "异常上报地址人员"
sendCont.Description = commonus.TimeStampToDate(calCulTime, 6) + fmt.Sprintf("共计(%v)异常上报地址人员", jiBuQi)
sendCont.URL = fmt.Sprintf("https://www.hxgk.group/excereportaddress?time=%v", calCulTime)
sendCont.Picurl = "https://docu.hxgk.group/images/2021_11/205c2d8d35491880a1ac9f03d6e879d3.jpg"
var sendContAry []commonus.ArticlesStruct
sendContAry = append(sendContAry, sendCont)
var sendImgMsg commonus.SendImgCont
sendImgMsg.Touser = sendUserKey
sendImgMsg.MsgType = "news"
appId, _ := strconv.ParseInt(global.GVA_CONFIG.WorkWechatSchool.AgentId, 10, 64)
sendImgMsg.AgentId = appId
sendImgMsg.News.Articles = sendContAry
sendImgMsg.DuplicateCheckInterval = 1800
callbakcMsg, isTrueCall, callBackCont := sendImgMsg.SendImgMessage()
fmt.Printf("发送信息返回:%v-----------%v----------->%v\n", string(callbakcMsg), isTrueCall, callBackCont)
sendBakcs := commonus.MapOut()
sendBakcs["callbakcMsg"] = string(callbakcMsg)
sendBakcs["isTrueCall"] = isTrueCall
sendBakcs["callBackCont"] = callBackCont
// sendBakcs["errmsg"] = "没有要通知的人"
sendBakc = sendBakcs
return
} else {
fmt.Println("没有要通知的人")
sendBakcs := commonus.MapOut()
sendBakcs["errmsg"] = "没有要通知的人"
sendBakc = sendBakcs
return
}
} else {
fmt.Println("没有要通知的人")
// sendBakc["errmsg"] = "没有要通知的人"
sendBakcs := commonus.MapOut()
sendBakcs["errmsg"] = "没有要通知的人"
sendBakc = sendBakcs
return
}
return
// fmt.Printf("%v---------------------->%v\n", sendText, sendText)
}
// 获取上报地址异常的数据人员信息
func (d *dataLockStatistics) getUserAnswerList(jobid, tadayTime, calCulTime string, page int, pageSize int64, legalAreaList []locationing.LegalArea, regionalRiskLevel []commonus.RegionalRiskLevel, isRiskYes bool) {
d.mutext.Lock()
defer d.mutext.Unlock()
// calCulTime := tadayTime
// calCulTime := tadayTime + " 12:00:00"
// fmt.Printf("page ------------> %v\n", page)
// timeStamp := commonus.DateToTimeStamp(calCulTime)
// var judgeWriteInfoUser locationing.ReportAddress
// getReportAddressErr := global.GVA_DB_HealthReport.Where("calcultime = ?", timeStamp).Take(&judgeWriteInfoUser).Error
// if getReportAddressErr != nil {
//设置redis数据
redisUserClient := redishandel.RunRedis()
redisUserClient.SetRedisTime(1123200)
_, 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 != "" && v_sun.QuestionId != 2 {
var writeInfoUser locationing.ReportAddress
var AdmDiv commonus.AdministrativeDivision
AdmDivMap := commonus.MapOut()
// writeInfoUser.Address = string(msgBtye)
countSplit := strings.Split(v_sun.Text, "省")
xieRuBaoJong := false
var groupIdCont int64
groupIdCont = 0
if len(countSplit) >= 2 {
writeInfoUser.WechatId = v.Userid
writeInfoUser.Userid = v.Userid
writeInfoUser.AddTime = time.Now().Unix()
writeInfoUser.Address = v_sun.Text
writeInfoUser.ItineraryCardType = v_sun.ItineraryCardType
writeInfoUser.HighRiskArea = v_sun.HighRiskArea
AdmDivMap["itinerary_card_type"] = v_sun.ItineraryCardType
AdmDivMap["high_risk_area"] = v_sun.HighRiskArea
AdmDivMap["riskLevel"] = 0
writeInfoUser.RiskLevel = 0
writeInfoUser.CalCulTime = commonus.DateToTimeStamp(calCulTime)
// fmt.Printf("时间值-----》%v @@@@@@@@@@@@@@@@@@@@ %v\n\n", v_sun.ItineraryCardType, v_sun)
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] + "市"
if isRiskYes == true { //判断是否要进行风险等级判定
for _, riskAre := range regionalRiskLevel {
if riskAre.ProvinceName == countSplit[0] {
if riskAre.CityName == countSplitSun[0] {
writeInfoUser.RiskLevel = riskAre.RiskLevel
AdmDivMap["riskLevel"] = riskAre.RiskLevel
// commonus.WriteInMan(v.Userid)
xieRuBaoJong = true
}
}
}
}
} else {
AdmDiv.City = countSplitSun[0] + "市"
writeInfoUser.City = countSplitSun[0] + "市"
AdmDivMap["city"] = countSplitSun[0] + "市"
if isRiskYes == true { //判断是否要进行风险等级判定
for _, riskAre := range regionalRiskLevel {
if riskAre.ProvinceName == countSplit[0] {
if riskAre.CityName == countSplitSun[0] {
writeInfoUser.RiskLevel = riskAre.RiskLevel
writeInfoUser.RiskLevel = riskAre.RiskLevel
AdmDivMap["riskLevel"] = riskAre.RiskLevel
// commonus.WriteInMan(v.Userid)
xieRuBaoJong = true
}
}
}
}
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 := commonus.GetWechatUserInfo(v.Userid)
writeInfoUser.UserName = weChatUserCont.Name
writeInfoUser.UserTel = weChatUserCont.Mobile
writeInfoUser.MainDepartment = int64(weChatUserCont.MainDepartment)
AdmDivMap["user_name"] = weChatUserCont.Name
AdmDivMap["user_tel"] = weChatUserCont.Name
AdmDivMap["main_department"] = weChatUserCont.MainDepartment
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)
}
isTrue, myDepartment := commonus.GetGroupInfo(int64(weChatUserCont.MainDepartment))
if isTrue == true {
var arrAy []int64
errdd := json.Unmarshal([]byte(myDepartment.Group), &arrAy)
if errdd == nil {
if len(arrAy) >= 2 {
if arrAy[0] == 1 {
writeInfoUser.GroupId = arrAy[1]
groupIdCont = arrAy[1]
if arrAy[1] != 0 {
isTrues, myDepartments := commonus.GetGroupInfo(arrAy[1])
if isTrues == true {
writeInfoUser.GroupName = fmt.Sprintf("%s", myDepartments.Name)
}
}
} else {
writeInfoUser.GroupId = arrAy[0]
groupIdCont = arrAy[0]
if arrAy[0] != 0 {
isTrues, myDepartments := commonus.GetGroupInfo(arrAy[0])
if isTrues == true {
writeInfoUser.GroupName = fmt.Sprintf("%s", myDepartments.Name)
}
}
}
}
}
}
if xieRuBaoJong == true {
commonus.WriteInMan(v.Userid, calCulTime, groupIdCont)
}
// writeInfoUser.MainDepartment =
AdmDivStruct = append(AdmDivStruct, AdmDiv)
d.dataMap = append(d.dataMap, AdmDivMap)
if v.Userid != "" {
redisUserClient.HashMsetAdd("epidemic:userInclude_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+v.Userid+"_"+tadayTime, 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 (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(&noticeUserStruct).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)
}
// 根据ID查询详情
func (h *HealthReportStat) LookNoticeUser(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
}
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
}
response.Result(0, reportAnswerSet, "获取成功!", c)
}
func (h *HealthReportStat) PostReportAnswerListTodayAll(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.GetToDay()
if reportAnswer.Date != "" {
tadayTime = reportAnswer.Date
// fmt.Printf("时间是=》%v\n", reportAnswer.Date)
}
//判断日期是否已经统计
sendCalCulTime := tadayTime + " 09:00:00"
calCulTime := commonus.DateToTimeStamp(sendCalCulTime)
var reportInfo locationing.ReportAddress
errInfo := global.GVA_DB_HealthReport.Where("calcultime = ?", calCulTime).First(&reportInfo).Error
if errInfo == nil {
response.Result(102, tadayTime, "该日期已经统计", 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
//获取全国风险等级
nationalRiskLevel, riskIsTrue := commonus.GetNationalRiskArea()
for i := 0; i < dateExcept; i++ {
myStatisWg.Add(1)
go dataStruct.getUserAnswerList(reportAnswer.JobId, tadayTime, sendCalCulTime, i, 100, legalAreaList, nationalRiskLevel, riskIsTrue)
}
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(0, returData, msg, c)
//计算未上报人员
// CalculationNotReport(tadayTime, calCulTime, readDataMap)
//判断报警人是不是超员
if len(readBaoJinf) > 0 {
//给相关人员发送信息
// sendMessAgeAlarm(calCulTime, readBaoJinf)
}
if len(readDataMap) > 0 {
reportDataWrittenToDatabase(readDataMap)
}
}
// 上报数据写入数据库
func reportDataWrittenToDatabase(saveAry []map[string]interface{}) {
if len(saveAry) > 0 {
for intdx, val := range saveAry {
fmt.Printf("写入数据:%v---->%v\n", intdx, val)
}
} else {
fmt.Printf("没有数据")
}
}