Browse Source

获取健康上报

pull/1/head
超级管理员 4 years ago
parent
commit
2724a08c14
  1. 1
      server/api/v1/examtestpage/enter.go
  2. 255
      server/api/v1/examtestpage/grouphandle.go
  3. 153
      server/api/v1/examtestpage/healthreportstat.go
  4. 9910
      server/api/v1/examtestpage/wechat.json
  5. 34
      server/commonus/curlGetPost.go
  6. 65
      server/commonus/docker-compose.yml
  7. 158
      server/commonus/weChatDateType.go
  8. 508
      server/commonus/wechatapp.go
  9. 34
      server/config.yaml
  10. 36
      server/config/config.go
  11. 5
      server/config/redis.go
  12. 19
      server/config/wechat.go
  13. 2
      server/core/server.go
  14. 1
      server/go.mod
  15. 4
      server/initialize/gorm.go
  16. 3
      server/initialize/router.go
  17. 8
      server/log/server_error.log
  18. 1442
      server/log/server_info.log
  19. 7
      server/main.go
  20. BIN
      server/resource/excel/ExcelExport.xlsx
  21. 1
      server/router/examtestpage/enter.go
  22. 13
      server/router/examtestpage/grouphandle.go
  23. 21
      server/router/examtestpage/healthreporthandle.go
  24. 135
      server/utils/redishandel/myredis.go

1
server/api/v1/examtestpage/enter.go

@ -2,4 +2,5 @@ package examtestpage
type ApiGroup struct {
GroupHandleApi
HealthReportStat
}

255
server/api/v1/examtestpage/grouphandle.go

@ -1,8 +1,10 @@
package examtestpage
import (
"errors"
"fmt"
"strconv"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/global"
@ -10,6 +12,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/model/testpage"
"github.com/flipped-aurora/gin-vue-admin/server/model/wechat"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
//集团分厂管理模块
@ -22,7 +25,7 @@ type GroupMap struct {
Time int64 `json:"time" gorm:"column:g_time;type:bigint(20) unsigned;default:0;not null;comment:编辑时间"` //'编辑时间',
Parentid int64 `json:"parentid" gorm:"column:g_parentid;type:bigint(20) unsigned;default:0;not null;comment:父级栏目"`
Sate int8 `json:"state" gorm:"column:g_sate;type:tinyint(1) unsigned;default:1;not null;comment:状态"` //'状态',
JinDieId int64 `json:"jindieid" gorm:"column:g_jindie_id;type:bigint(20) unsigned;default:0;not null;comment:金蝶ID"` //金蝶ID
JinDieId string `json:"jindieid" gorm:"column:g_jindie_id;type:bigint(20) unsigned;default:0;not null;comment:金蝶ID"` //金蝶ID
}
type TableData struct {
@ -35,11 +38,14 @@ type TableData struct {
Sort int `json:"sort"`
Date string `json:"date"`
Children interface{} `json:"children"`
QueryId int `json:"queryid"`
SingId int `json:"singid"`
}
//POST提交参数
type postGroupCanshu struct {
Id int `json:"id" from:"id"`
Id int64 `json:"id" from:"id"`
TypeId int `json:"typeid" from:"typeid"`
}
//集团列表
@ -66,24 +72,27 @@ func (g *GroupHandleApi) GroupList(c *gin.Context) {
groupTypeStruct.Name = v.Name
groupTypeStruct.Address = true
groupTypeStruct.WxId = strconv.FormatInt(v.Id, 10)
groupTypeStruct.JdId = strconv.FormatInt(v.JinDieId, 10)
groupTypeStruct.JdId = v.JinDieId
groupTypeStruct.Attributes = 1
groupTypeStruct.Sort = i + 1
groupTypeStruct.QueryId = 1
groupTypeStruct.Date = commonus.TimeStampToDate(v.Time, 6)
groupTypeStruct.Children = openGroupMap(departList)
groupTypeStruct.Children = openGroupMap(i+1, departList)
groupTypeStruct.SingId = i + 1
// groupAry[i] = openGroupMap(departList)
groupMapStruct = append(groupMapStruct, groupTypeStruct)
}
}
sendMap := commonus.MapOut()
sendMap["list"] = groupMapStruct
// fmt.Printf("%v\n", groupMap)
// response.Ok(c)
response.Result(200, groupMapStruct, "获取成功", c)
response.Result(0, sendMap, "获取成功", c)
}
// //展开集团列表
func openGroupMap(data []testpage.BranchFactoryHasMany) []TableData {
func openGroupMap(singid int, data []testpage.BranchFactoryHasMany) []TableData {
// openMapData := map[int]interface{}{}
var mapStruct []TableData
for i, v := range data {
@ -98,6 +107,7 @@ func openGroupMap(data []testpage.BranchFactoryHasMany) []TableData {
kk.JdId = ""
kk.Attributes = v.Attribute
kk.Sort = i + 1
kk.QueryId = 2
kk.Date = commonus.TimeStampToDate(v.Time, 6)
var sunGroup []TableData
for ii, vv := range v.WorkshopSectionStruct {
@ -112,11 +122,14 @@ func openGroupMap(data []testpage.BranchFactoryHasMany) []TableData {
kk_i.JdId = ""
kk_i.Attributes = 0
kk_i.Sort = ii + 1
kk_i.QueryId = 3
kk_i.Date = commonus.TimeStampToDate(vv.Time, 6)
kk_i.SingId, _ = strconv.Atoi(strconv.Itoa(singid) + strconv.Itoa(i) + strconv.Itoa(ii))
// kk_i.Children = []map[string]interface{}{}
sunGroup = append(sunGroup, kk_i)
}
kk.Children = sunGroup
kk.SingId, _ = strconv.Atoi(strconv.Itoa(singid) + strconv.Itoa(i))
mapStruct = append(mapStruct, kk)
}
return mapStruct
@ -129,15 +142,20 @@ func openGroupMap(data []testpage.BranchFactoryHasMany) []TableData {
func (g *GroupHandleApi) GetGroupInfo(c *gin.Context) {
var id postGroupCanshu
_ = c.ShouldBindJSON(&id) //获取提交的参数
_ = c.ShouldBindJSON(&id) //获取提交的参数
if id.Id == 0 {
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
}
var groupStruct wechat.GroupForm //集团表结构
err := global.GVA_DB_WatchDate.Where("g_id = ?", id.Id).First(&groupStruct).Error //获取集团信息
if err != nil {
response.Result(100, groupStruct, "获取失败", c)
return
}
sendMap := commonus.MapOut()
sendMap["list"] = groupStruct
// fmt.Printf("====>%v\n", id.Id)
response.Result(200, groupStruct, "获取成功", c)
response.Result(0, groupStruct, "获取成功", c)
}
/*获取子公司信息
@ -145,14 +163,19 @@ func (g *GroupHandleApi) GetGroupInfo(c *gin.Context) {
*/
func (g *GroupHandleApi) GetSubsidiaryInfo(c *gin.Context) {
var id postGroupCanshu
_ = c.ShouldBindJSON(&id) //获取提交的参数
_ = c.ShouldBindJSON(&id) //获取提交的参数
if id.Id == 0 {
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
}
var subsidiaryStruct testpage.BranchFactory //子公司表结构
err := global.GVA_DB_Master.Where("bf_id = ?", id.Id).First(&subsidiaryStruct).Error //获取子公司信息
if err != nil {
response.Result(100, subsidiaryStruct, "获取失败", c)
return
}
response.Result(200, subsidiaryStruct, "获取成功", c)
sendMap := commonus.MapOut()
sendMap["list"] = subsidiaryStruct
response.Result(0, subsidiaryStruct, "获取成功", c)
}
/*获取工段信息
@ -161,7 +184,6 @@ func (g *GroupHandleApi) GetSubsidiaryInfo(c *gin.Context) {
func (g *GroupHandleApi) GetGroupPositionInfo(c *gin.Context) {
var id postGroupCanshu
_ = c.ShouldBindJSON(&id) //获取提交的参数
fmt.Printf("%v====>%T\n", id.Id, id)
if id.Id == 0 {
response.Result(101, id, "您的参数不正确!请检查您的提交!", c)
}
@ -171,5 +193,212 @@ func (g *GroupHandleApi) GetGroupPositionInfo(c *gin.Context) {
response.Result(100, workShopesStruct, "获取失败", c)
return
}
response.Result(200, workShopesStruct, "获取成功", c)
sendMap := commonus.MapOut()
sendMap["list"] = workShopesStruct
response.Result(0, workShopesStruct, "获取成功", c)
}
/*
删除操作
@id 要删除的ID
@type 要删除的类型
*/
func (g *GroupHandleApi) DelGroupInfo(c *gin.Context) {
var postInfo postGroupCanshu
err := c.ShouldBindJSON(&postInfo)
if err != nil {
response.Result(100, err, "您的参数不正确!请检查您的提交!", c)
return
}
if postInfo.Id == 0 {
response.Result(101, postInfo.Id, "您的参数不正确!请检查您的提交!", c)
return
}
var errSun error
switch postInfo.TypeId {
case 1:
// fmt.Println("A1")
errSun = DelDepartment(postInfo.Id)
case 2:
errSun = DelWorhPost(postInfo.Id)
default:
// fmt.Println("A2")
errSun = DelterGroup(postInfo.Id)
}
// fmt.Printf("%v===========>%T\n", postInfo.TypeId, postInfo.TypeId)
if errSun != nil {
msg := fmt.Sprintf("删除失败!%v", errSun)
response.Result(102, errSun, msg, c)
return
}
sendMap := commonus.MapOut()
sendMap["list"] = errSun
response.Result(0, errSun, "获取成功", c)
}
/*
软删除集团信息
@id 集团ID
*/
func DelterGroup(id int64) error {
assignErr := global.GVA_DB_WatchDate.Model(&wechat.GroupForm{}).Where("g_parentid = ? and g_id = ?", 1, id).First(&GroupMap{}).Error //获取集团信息
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
return errors.New("该集团不存在!")
}
err := global.GVA_DB_WatchDate.Where("g_id = ?", id).First(&wechat.GroupForm{}).Update("g_sate", 2).Error
return err
}
/*
软删除分厂信息
@id 分厂ID
*/
func DelDepartment(id int64) error {
assignErr := global.GVA_DB_Master.Where("bf_set = ? and bf_id = ?", 1, id).First(&testpage.BranchFactory{}).Error //获取分厂或部室信息
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
return errors.New("该分厂或部室不存在!")
}
err := global.GVA_DB_Master.Where("bf_id = ?", id).First(&testpage.BranchFactory{}).Update("bf_set", 3).Error
return err
}
/*
软删除分厂信息
@id 分厂ID
*/
func DelWorhPost(id int64) error {
assignErr := global.GVA_DB_Master.Where("ws_set = ? and ws_id = ?", 1, id).First(&testpage.WorkShopsection{}).Error //获取分厂或部室信息
if errors.Is(assignErr, gorm.ErrRecordNotFound) {
return errors.New("该工段不存在!")
}
err := global.GVA_DB_Master.Where("ws_id = ?", id).First(&testpage.WorkShopsection{}).Update("ws_set", 3).Error
return err
}
//添加组织架构(集团信息)
/*
@id 部门ID
@name 部门名称
@parentid 上级部门ID顶级部门的上级ID为1
@state 状态1启用2禁用
@jindieid 金蝶ID
*/
func (g *GroupHandleApi) AddGroupInfo(c *gin.Context) {
var groupInfo GroupMap
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
if groupInfo.Parentid == 0 {
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
return
}
if groupInfo.Name == "" {
response.Result(102, groupInfo, "您的参数不正确!请检查您的提交!", c)
return
}
var groupStruct wechat.GroupForm //集团表结构
var groupMap GroupMap //要获取的集团架构字段
err := global.GVA_DB_WatchDate.Model(&groupStruct).Where("g_name = ?", groupInfo.Name).First(&groupMap).Error //获取集团信息
if err == nil {
response.Result(103, groupMap, "该集团名称已经存在!请更换!", c)
return
}
var dep commonus.DePartMentInfo
addId, adderr := dep.AddDepartment(groupInfo.Parentid, groupInfo.Name)
if adderr != true {
response.Result(1003, groupInfo.Name, "该集团添加失败(企业微信通讯故障!)", c)
return
}
groupStruct.Id = addId
groupStruct.Name = groupInfo.Name
groupStruct.Parentid = groupInfo.Parentid
groupStruct.Orderes = 1
groupStruct.Time = time.Now().Unix()
groupStruct.Sate = 1
groupStruct.Group = ""
groupStruct.GroupSun = ""
groupStruct.JinDieId = 0
result := global.GVA_DB_WatchDate.Create(&groupStruct).Error
if result != nil {
commonus.DelDepartment(addId)
response.Result(1004, groupStruct, "该集团添加失败(写入数据库错误!)", c)
return
}
// redisClient := redishandel.RunRedis()
// redisClient.SetRedisTime(7200)
// redisClient.Set("kaifa", "1234565")
// jsh, _ := redisClient.Get("kaifa")
// fmt.Printf("%v ----------%v ********** %v\n", ton, add, id)
// fmt.Printf("%v ----------%v ********** %v\n", ton, err, jsh)
// jsonBytes, _ := json.Marshal(groupInfo)
// commonus.CurlPostJosn("111", jsonBytes)
// fmt.Printf("%v ----------%T ********** %v********** %v\n", jsonBytes, jsonBytes, addId, adderr)
sendMap := commonus.MapOut()
sendMap["list"] = groupStruct
response.Result(0, groupStruct, "添加成功", c)
}
/*
修改组织架构(集团信息)
@id 部门ID
@name 部门名称
@parentid 上级部门ID顶级部门的上级ID为1
@state 状态1启用2禁用
@jindieid 金蝶ID
*/
func (g *GroupHandleApi) EiteGroupInfo(c *gin.Context) {
var groupInfo GroupMap
_ = c.ShouldBindJSON(&groupInfo) //获取提交的参数
if groupInfo.Id == 0 {
response.Result(101, groupInfo, "您的参数不正确!请检查您的提交!", c)
return
}
var groupStruct wechat.GroupForm //集团表结构 //要获取的集团架构字段
judgeErr := global.GVA_DB_WatchDate.Where("g_id = ?", groupInfo.Id).First(&groupStruct).Error //获取集团信息
if judgeErr != nil {
response.Result(101, judgeErr, "该集团不存在!请检查你的数据!", c)
return
}
if groupInfo.Name == "" {
response.Result(102, groupInfo, "请提交修改后的集团名称!", c)
return
} else {
groupStruct.Name = groupInfo.Name
}
if groupInfo.Parentid != 0 {
groupStruct.Parentid = groupInfo.Parentid
}
if groupInfo.Sate != 0 {
groupStruct.Sate = groupInfo.Sate
}
if groupInfo.JinDieId != "" {
jinDieId, jinDeiErr := strconv.ParseInt(groupInfo.JinDieId, 10, 64)
if jinDeiErr != nil {
groupStruct.JinDieId = 0
} else {
groupStruct.JinDieId = jinDieId
}
}
groupStruct.Time = time.Now().Unix()
affairOperation := global.GVA_DB_WatchDate.Begin()
saveErr := affairOperation.Save(groupStruct).Error
if saveErr != nil {
affairOperation.Rollback()
response.Result(102, groupInfo, "数据写入失败!", c)
return
}
var dep commonus.DePartMentInfo
_, saveErrwe := dep.SaveDepartment(groupStruct.Id, groupStruct.Orderes, groupStruct.Parentid, groupStruct.Name, "")
if saveErrwe != true {
affairOperation.Rollback()
response.Result(102, groupInfo, "与企业微信通讯失败", c)
return
}
affairOperation.Commit()
sendMap := commonus.MapOut()
sendMap["list"] = groupStruct
response.Result(0, groupStruct, "修改成功", c)
}

153
server/api/v1/examtestpage/healthreportstat.go

@ -0,0 +1,153 @@
package examtestpage
import (
"fmt"
"strings"
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"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.Offset != 0 {
page = healthReport.Offset
}
if healthReport.Limit != 0 {
pageSize = healthReport.Limit
}
}
jobMap, isTrue, msg := commonus.GetRunHealthReportJobids(page, pageSize)
if isTrue != true {
response.Result(102, isTrue, msg, c)
return
}
// fmt.Printf("%v\n", jobMap)
response.Result(200, 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)
response.Result(200, strucr, 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.Offset != 0 {
page = reportAnswer.Offset
}
if reportAnswer.Limit != 0 {
pageSize = reportAnswer.Limit
}
_, reportAnswerInfoList, _, 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)
}
}
}
}
response.Result(200, reportAnswerInfoList, msg, c)
}

9910
server/api/v1/examtestpage/wechat.json

File diff suppressed because it is too large

34
server/commonus/curlGetPost.go

@ -0,0 +1,34 @@
package commonus
import (
"bytes"
"io/ioutil"
"net/http"
)
//Get请求
func CurlGet(getUrl string) []byte {
client := &http.Client{}
reqest, err := http.NewRequest("GET", getUrl, nil)
if err != nil {
panic(err)
}
response, _ := client.Do(reqest)
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
return body
}
//Post请求 json
func CurlPostJosn(postUrl string, jsonData []byte) []byte {
req, err := http.NewRequest("POST", postUrl, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json;charset=utf-8")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
return body
}

65
server/commonus/docker-compose.yml

@ -0,0 +1,65 @@
# mail@dongguochao.com
# llitfkitfk@gmail.com
# chibing.fy@alibaba-inc.com
version: "3"
services:
# frontend
dolores:
image: rapteam/rap2-dolores:latest
ports:
#冒号前可以自定义前端端口号,冒号后不要动
- 3899:38081
# backend
delos:
image: rapteam/rap2-delos:latest
ports:
# 这里的配置不要改哦
- 38080:38080
environment:
- SERVE_PORT=38080
# if you have your own mysql, config it here, and disable the 'mysql' config blow
- MYSQL_URL=mysql # links will maintain /etc/hosts, just use 'container_name'
- MYSQL_PORT=3306
- MYSQL_USERNAME=root
- MYSQL_PASSWD=
- MYSQL_SCHEMA=rap2
# redis config
- REDIS_URL=redis
- REDIS_PORT=6379
# production / development
- NODE_ENV=production
###### 'sleep 30 && node scripts/init' will drop the tables
###### RUN ONLY ONCE THEN REMOVE 'sleep 30 && node scripts/init'
command: /bin/sh -c 'node dispatch.js'
# init the databases
# command: sleep 30 && node scripts/init && node dispatch.js
# without init
# command: node dispatch.js
depends_on:
- redis
- mysql
redis:
image: redis:4
# disable this if you have your own mysql
mysql:
image: mysql:5.7
# expose 33306 to client (navicat)
#ports:
# - 33306:3306
volumes:
# change './docker/mysql/volume' to your own path
# WARNING: without this line, your data will be lost.
- "./docker/mysql/volume:/var/lib/mysql"
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES utf8mb4;' --innodb-flush-log-at-trx-commit=0
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
MYSQL_DATABASE: "rap2"
MYSQL_USER: "root"
MYSQL_PASSWORD: ""

158
server/commonus/weChatDateType.go

@ -0,0 +1,158 @@
package commonus
//获取Token类型设置
type getTokenType struct {
Type string `json:"type"`
}
//组织架构返回统类
type weChatCallBack struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Accesstoken string `json:"access_token"`
Expiresin int64 `json:"expires_in"`
}
//获取部门列表
type dePartMent struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
DePartMent []DePartMentInfo `json:"department"`
}
type DePartMentInfo struct {
Id int64 `json:"id"`
Name string `json:"name"`
NameEN string `json:"name_en"`
Parentid int64 `json:"parentid"`
Order int64 `json:"order"`
}
type dePartMentInfoStr struct {
Id string `json:"id"`
Name string `json:"name"`
NameEN string `json:"name_en"`
Parentid string `json:"parentid"`
Order string `json:"order"`
}
//添加部门列表
type DePartMentCallBack struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Id int64 `json:"id"`
}
//健康上报使用统计
type HealthReportStat struct {
Errcode int `json:"errcode"` //返回码
Errmsg string `json:"errmsg"` //对返回码的文本描述内容
Pv int64 `json:"pv"` //应用使用次数
Uv int64 `json:"uv"` //应用使用成员数
}
//获取参数样式健康上报使用统计
type GetHealthReport struct {
Date string `json:"date"`
}
//正在运行的上报任务ID列表。
type GetHealthReportRun struct {
Offset int `json:"offset"`
Limit int64 `json:"limit"`
}
//获取企业当前正在运行的上报任务ID列表。
type CallBackData struct {
Errcode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
Ending int `json:"ending"`
Jobids []interface{} `json:"jobids"`
}
//获取指定的健康上报任务详情。
type GetReportJobInfoDate struct {
JobId string `json:"jobid"`
Date string `json:"date"`
}
type CallBackReportJobInfo struct {
Errcode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
JobInfo ReportJobInfo `json:"job_info"`
}
type ReportJobInfo struct {
Title string `json:"title"`
Creator string `json:"creator"`
Type int `json:"type"`
ApplyRange ApplyRangeStruct `json:"apply_range"`
ReportTo ApplyRangeStruct `json:"report_to"`
// ReportTo ReportToStruct `json:"report_to"`
ReportType int `json:"report_type"`
SkipWeekend int `json:"skip_weekend"`
FinishCnt int `json:"finish_cnt"`
QuestionTemplates []QuestionTemplatesStruct `json:"question_templates"`
}
type ApplyRangeStruct struct {
UserIds []string `json:"userids"`
Partyids []int64 `json:"partyids"`
}
type ReportToStruct struct {
UserIds []string `json:"userids"`
}
type QuestionTemplatesStruct struct {
QuestionId int64 `json:"question_id"`
Title string `json:"title"`
QuestionType int `json:"question_type"`
IsRequired int `json:"is_required"`
OptionList []OptionListStruct `json:"option_list"`
}
type OptionListStruct struct {
OptionId int `json:"option_id"`
OptionText string `json:"option_text"`
}
//获取用户填写答案列表
type ReportAnswerStruct struct {
JobId string `json:"jobid"`
Date string `json:"date"`
Offset int `json:"offset"`
Limit int64 `json:"limit"`
}
//获取用户填写答案返回结果
type ReportAnswerResult struct {
Errcode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
Answers []AnswersStruct `json:"answers"`
}
type AnswersStruct struct {
IdType int `json:"id_type"`
Userid string `json:"userid"`
StudentUserid string `json:"student_userid"`
ParentUserid string `json:"parent_userid"`
ReportValues []ReportValuesStruct `json:"report_values"`
}
type ReportValuesStruct struct {
QuestionId int `json:"question_id"`
SingleChoice int `json:"single_choice"`
Text string `json:"text"`
MultiChoice []int `json:"multi_choice"`
Fileid []string `json:"fileid"`
}
//行政区域
type AdministrativeDivision struct {
Userid string `json:"userid"`
Province string `json:"province"`
City string `json:"city"`
County string `json:"county"`
}

508
server/commonus/wechatapp.go

@ -0,0 +1,508 @@
package commonus
//企业微信相关操作
import (
"encoding/json"
"fmt"
"strconv"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel"
"github.com/mitchellh/mapstructure"
)
//获取企业微信token
func GetWechatTokenType(types string) (tokenInfo string, redisClient *redishandel.RedisStoreType, err error) {
redisClient = redishandel.RunRedis()
isTrue := false
redisPrefix := "workWeChatToken_"
companyId := global.GVA_CONFIG.WorkWechatId.CompanyId
secretStr := global.GVA_CONFIG.WorkWechatMailList.SecretStr
switch types {
case "maillist":
redisPrefix = redisPrefix + "_mail_"
secretStr = global.GVA_CONFIG.WorkWechatMailList.SecretStr
case "health":
redisPrefix = redisPrefix + "_health_"
secretStr = global.GVA_CONFIG.WorkHealthReport.SecretStr
default:
secretStr = global.GVA_CONFIG.WorkWechatSchool.SecretStr
}
isTrue, tokenInfo = redisClient.Get(redisPrefix + global.GVA_CONFIG.RedisPrefix.Alias)
if isTrue == true {
return
} else {
// getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + global.GVA_CONFIG.WorkWechatIds.CompanyId + "&corpsecret=" + global.GVA_CONFIG.WorkWechatMailLists.SecretStr
getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + companyId + "&corpsecret=" + secretStr
// fmt.Printf("getTokenUrl:%v\n", getTokenUrl)
token := CurlGet(getTokenUrl)
var callBackData weChatCallBack
err = json.Unmarshal(token, &callBackData)
if err != nil {
return
}
if callBackData.Errcode != 0 {
return
}
// fmt.Printf("%v\n", callBackData)
tokenInfo = callBackData.Accesstoken
redisClient.SetRedisTime(7200)
// redisClient.Set("workWeChatToken_"+global.GVA_CONFIG.RedisPrefix.Alias, tokenInfo)
redisClient.Set(redisPrefix+global.GVA_CONFIG.RedisPrefix.Alias, tokenInfo)
}
return
}
//获取企业微信token
func GetWechatToken() (tokenInfo string, redisClient *redishandel.RedisStoreType, err error) {
redisClient = redishandel.RunRedis()
isTrue, tokenInfo := redisClient.Get("workWeChatToken_" + global.GVA_CONFIG.RedisPrefix.Alias)
if isTrue == true {
return
} else {
// getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + global.GVA_CONFIG.WorkWechatIds.CompanyId + "&corpsecret=" + global.GVA_CONFIG.WorkWechatMailLists.SecretStr
getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + global.GVA_CONFIG.WorkWechatId.CompanyId + "&corpsecret=" + global.GVA_CONFIG.WorkWechatMailList.SecretStr
fmt.Printf("getTokenUrl:%v\n", getTokenUrl)
token := CurlGet(getTokenUrl)
var callBackData weChatCallBack
err = json.Unmarshal(token, &callBackData)
if err != nil {
return
}
if callBackData.Errcode != 0 {
return
}
// fmt.Printf("%v\n", callBackData)
tokenInfo = callBackData.Accesstoken
redisClient.SetRedisTime(7200)
redisClient.Set("workWeChatToken_"+global.GVA_CONFIG.RedisPrefix.Alias, tokenInfo)
}
return
}
func GetDepartment(dePartMentId int) (departmentlist *[]DePartMentInfo, isTrue bool) {
isTrue = false
ton, redisClient, err := GetWechatToken()
if err != nil {
return
}
dePartMentIdStr := strconv.Itoa(dePartMentId)
isTrue, dePartMentMapJson := redisClient.Get("dePartMentList:list_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + dePartMentIdStr)
if isTrue == true {
//json转换成Struct
err := json.Unmarshal([]byte(dePartMentMapJson), &departmentlist)
if err != nil {
fmt.Println("JsonToMapDemo err: ", err)
return departmentlist, false
}
// fmt.Printf("Map => %v", departmentlist)
// if errMap := mapstructure.Decode(dePartMentMapJson, &departmentlist); errMap != nil {
// // redisClient.HashMsetAdd("dePartMentAry_ment_dev_"+dePartMentIdStr, departmentlist)
// return departmentlist, false
// }
return departmentlist, true
// fmt.Printf("Key_jia1 ==> %v ------ Val_jia1 ==> %v\n", dePartMentMap, isTrue)
// var dePartMentStruct dePartMentInfoStr
// if errMap := mapstructure.Decode(dePartMentMap, &dePartMentStruct); errMap != nil {
// fmt.Printf("Key_jia2 ==> %v ------ Val_jia2 ==> %v\n", dePartMentMap, errMap)
// return departmentlist, false
// }
// var ksjdes []dePartMentInfo
// var ksjd dePartMentInfo
// ksjd.Id, _ = strconv.Atoi(dePartMentStruct.Id)
// ksjd.Name = dePartMentStruct.Name
// ksjd.NameEN = dePartMentStruct.NameEN
// ksjd.Parentid, _ = strconv.Atoi(dePartMentStruct.Parentid)
// ksjd.Order, _ = strconv.Atoi(dePartMentStruct.Order)
// ksjdes = append(ksjdes, ksjd)
// departmentlist = &ksjdes
// fmt.Printf("Key ==> %v ------ Val ==> %v\n", dePartMentMap, departmentlist)
// return departmentlist, true
} else {
//获取企业微信部门列表
getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + ton + "&id=" + dePartMentIdStr
// fmt.Printf("URL ===> %v\n", getTokenUrl)
callBackList := CurlGet(getTokenUrl)
var callBackData dePartMent
err = json.Unmarshal(callBackList, &callBackData)
if err != nil {
return departmentlist, false
}
// fmt.Printf("%+v\n", callBackData)
// departmentlist = &callBackData.DePartMent
// return callBackData.DePartMent
redisClient.SetRedisTime(604800)
if callBackData.Errcode == 0 {
if errMap := mapstructure.Decode(callBackData.DePartMent, &departmentlist); errMap != nil {
// redisClient.HashMsetAdd("dePartMentAry_ment_dev_"+dePartMentIdStr, departmentlist)
return departmentlist, false
}
for _, val := range callBackData.DePartMent {
// fmt.Printf("Key ==> %v ------ Val ==> %v\n", key, val)
writeRedisData := map[string]interface{}{
"id": val.Id,
"name": val.Name,
"name_en": val.NameEN,
"parentid": val.Parentid,
"order": val.Order,
}
departId := strconv.FormatInt(val.Id, 10)
redisClient.HashMsetAdd("dePartMentAry:ment_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+departId, writeRedisData)
}
dePartMentJson, _ := json.Marshal(callBackData.DePartMent)
redisClient.Set("dePartMentList:list_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+dePartMentIdStr, string(dePartMentJson))
} else {
return departmentlist, false
}
}
return departmentlist, true
}
//获取单个部门信息
func GetOneDePartMent(dePartMentId int) (departmentlist *DePartMentInfo, isTrue bool) {
isTrue = false
_, redisClient, err := GetWechatToken()
if err != nil {
return
}
dePartMentIdStr := strconv.Itoa(dePartMentId)
dePartMentMapJson, isTrue := redisClient.HashGetAll("dePartMentAry:ment_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + dePartMentIdStr)
if isTrue == true {
var departmentinfo dePartMentInfoStr
err := mapstructure.Decode(dePartMentMapJson, &departmentinfo)
if err != nil {
return departmentlist, false
}
var jjks DePartMentInfo
jjks.Id, _ = strconv.ParseInt(departmentinfo.Id, 10, 64)
jjks.Name = departmentinfo.Name
jjks.NameEN = departmentinfo.NameEN
jjks.Parentid, _ = strconv.ParseInt(departmentinfo.Parentid, 10, 64)
jjks.Order, _ = strconv.ParseInt(departmentinfo.Order, 10, 64)
departmentlist = &jjks
return departmentlist, true
} else {
_, _ = GetDepartment(dePartMentId)
dePartMentMapJson, isTrue := redisClient.HashGetAll("dePartMentAry:ment_" + global.GVA_CONFIG.RedisPrefix.Alias + "_" + dePartMentIdStr)
if isTrue == true {
var departmentinfo dePartMentInfoStr
err := mapstructure.Decode(dePartMentMapJson, &departmentinfo)
if err != nil {
return departmentlist, false
}
var jjks DePartMentInfo
jjks.Id, _ = strconv.ParseInt(departmentinfo.Id, 10, 64)
jjks.Name = departmentinfo.Name
jjks.NameEN = departmentinfo.NameEN
jjks.Parentid, _ = strconv.ParseInt(departmentinfo.Parentid, 10, 64)
jjks.Order, _ = strconv.ParseInt(departmentinfo.Order, 10, 64)
departmentlist = &jjks
return departmentlist, true
}
}
return departmentlist, true
}
/*
创建部门
*/
func (d *DePartMentInfo) AddDepartment(parentid int64, name string) (int64, bool) {
d.InstDepartMentInfo()
if parentid <= 0 {
return 0, false
}
if name == "" {
return 0, false
}
d.Parentid = parentid
d.Name = name
// jsonBytes, _ := json.Marshal(d)
weChatPart := MapOut()
weChatPart["parentid"] = d.Parentid
weChatPart["name"] = d.Name
if d.NameEN != "" {
weChatPart["name_en"] = d.NameEN
}
if d.Id != 0 {
weChatPart["id"] = d.Id
}
if d.Order != 0 {
weChatPart["order"] = d.Order
}
sendJsonData, _ := json.Marshal(weChatPart)
tonken, _, err := GetWechatToken() //获取token
if err != nil {
return 0, false
}
weChatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token=" + tonken
addDePartMent := CurlPostJosn(weChatApiUrl, sendJsonData)
var callBackData DePartMentCallBack
err = json.Unmarshal(addDePartMent, &callBackData)
if callBackData.Errcode != 0 {
return 0, false
}
// fmt.Printf("%v=================>&&&&&&&&&& %v ------------>%v#################3%v\n", d, jsonBytes, string(addDePartMent), callBackData)
return callBackData.Id, true
}
/*
更新部门
*/
func (d *DePartMentInfo) SaveDepartment(id, order, parentid int64, name, name_en string) (int64, bool) {
d.InstDepartMentInfo()
if id <= 0 {
return 0, false
}
if parentid <= 0 {
return 0, false
}
if name == "" {
return 0, false
}
d.Id = id
d.Parentid = parentid
d.Name = name
if order > 0 {
d.Order = order
}
if name_en != "" {
d.NameEN = name_en
}
weChatPart := MapOut()
weChatPart["parentid"] = d.Parentid
weChatPart["name"] = d.Name
if d.NameEN != "" {
weChatPart["name_en"] = d.NameEN
}
if d.Id != 0 {
weChatPart["id"] = d.Id
}
if d.Order != 0 {
weChatPart["order"] = d.Order
}
sendJsonData, _ := json.Marshal(weChatPart)
tonken, _, err := GetWechatToken() //获取token
if err != nil {
return 0, false
}
weChatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/department/update?access_token=" + tonken
addDePartMent := CurlPostJosn(weChatApiUrl, sendJsonData)
var callBackData DePartMentCallBack
err = json.Unmarshal(addDePartMent, &callBackData)
fmt.Printf("json ===>%v\n", callBackData)
if callBackData.Errcode != 0 {
return 0, false
}
return d.Id, true
}
func (d *DePartMentInfo) InstDepartMentInfo() (departmentinfo *DePartMentInfo) {
var dep DePartMentInfo
dep.Id = 0
dep.Name = ""
dep.NameEN = ""
dep.Parentid = 0
dep.Order = 0
departmentinfo = &dep
return
}
/*
删除部门
*/
func DelDepartment(id int64) bool {
isTrue := false
ton, _, err := GetWechatToken()
if err != nil {
return isTrue
}
delIdStr := strconv.FormatInt(id, 10)
//删除部门
getTokenUrl := "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + ton + "&id=" + delIdStr
// fmt.Printf("URL ===> %v\n", getTokenUrl)
callBackList := CurlGet(getTokenUrl)
var callBackData dePartMent
err = json.Unmarshal(callBackList, &callBackData)
if err != nil {
return isTrue
}
if callBackData.Errcode != 0 {
return isTrue
}
isTrue = true
return isTrue
}
//健康上报相关操作
/*
获取健康上报使用统计
*/
func GetHealthReportStat(dateTime string) (pv, uv int64, isTrue bool, msg string) {
isTrue = false
pv = 0
uv = 0
msg = "获取失败!"
if dateTime == "" {
return
}
ton, _, err := GetWechatTokenType("health")
if err != nil {
msg = "获取Token失败!"
return
}
getWechatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/health/get_health_report_stat?access_token=" + ton
weChatPart := MapOut()
weChatPart["date"] = dateTime
sendJsonData, jsonErr := json.Marshal(weChatPart)
if jsonErr != nil {
msg = "提交数据转换失败!"
return
}
addDePartMent := CurlPostJosn(getWechatApiUrl, sendJsonData)
var callBackData HealthReportStat
err = json.Unmarshal(addDePartMent, &callBackData)
// fmt.Printf("json ===>%v------>%v\n", weChatPart, string(addDePartMent))
if callBackData.Errcode != 0 {
return
}
isTrue = true
pv = callBackData.Pv
uv = callBackData.Uv
msg = callBackData.Errmsg
return
}
/*
企业当前正在运行的上报任务ID列表
ANIAyAd9-A4AHAAEwZhACsvfrYYfjcTz
*/
func GetRunHealthReportJobids(page int, pageSize int64) (dateAry []string, isTrue bool, msg string) {
isTrue = false
if pageSize == 0 {
pageSize = 100
}
ton, _, err := GetWechatTokenType("health")
if err != nil {
msg = "获取Token失败!"
return
}
getWechatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/health/get_report_jobids?access_token=" + ton
weChatPart := MapOut()
weChatPart["offset"] = page
weChatPart["limit"] = pageSize
sendJsonData, jsonErr := json.Marshal(weChatPart)
if jsonErr != nil {
msg = "提交数据转换失败!"
return
}
addDePartMent := CurlPostJosn(getWechatApiUrl, sendJsonData)
var callBackData CallBackData
err = json.Unmarshal(addDePartMent, &callBackData)
// fmt.Printf("json ===>%v------>%v\n", weChatPart, string(addDePartMent))
// return
if callBackData.Errcode != 0 {
return
}
isTrue = true
msg = callBackData.ErrMsg
var mspStructAry []string
for _, val := range callBackData.Jobids {
mspStructAry = append(mspStructAry, val.(string))
}
// fmt.Printf("json3 ===>%v------>%v\n", mspStructAry, string(addDePartMent))
dateAry = mspStructAry
// fmt.Printf("json2 ===>%v------>%v\n", dateAry, string(addDePartMent))
// fmt.Printf("%v", callBackData)
return
}
//获取指定的健康上报任务详情
func GetReportJobInfo(jobid, date string) (ca *CallBackReportJobInfo, isTrue bool, kk, msg string) {
isTrue = false
if jobid == "" {
msg = "请输入任务ID"
return
}
if date == "" {
msg = "请输入要查询的日期"
return
}
ton, _, err := GetWechatTokenType("health")
if err != nil {
msg = "获取Token失败!"
return
}
getWechatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/health/get_report_job_info?access_token=" + ton
weChatPart := MapOut()
weChatPart["jobid"] = jobid
weChatPart["date"] = date
sendJsonData, jsonErr := json.Marshal(weChatPart)
if jsonErr != nil {
msg = "提交数据转换失败!"
return
}
addDePartMent := CurlPostJosn(getWechatApiUrl, sendJsonData)
// fmt.Printf("json2 ===>%v------>%v\n", weChatPart, string(addDePartMent))
kk = string(addDePartMent)
var sendCallBackDate CallBackReportJobInfo
err = json.Unmarshal(addDePartMent, &sendCallBackDate)
// fmt.Printf("json23 ===>%v------>%v\n", sendCallBackDate, string(addDePartMent))
ca = &sendCallBackDate
return
}
//获取用户填写答案
func GetUserWriteAnswer(jobid, date string, page int, pageSize int64) (btyDate []byte, r *ReportAnswerResult, isTrue bool, msg string) {
isTrue = false
if jobid == "" {
msg = "请输入任务ID"
return
}
if date == "" {
msg = "请输入要查询的日期"
return
}
if pageSize == 0 {
pageSize = 100
}
ton, _, err := GetWechatTokenType("health")
if err != nil {
msg = "获取Token失败!"
return
}
getWechatApiUrl := "https://qyapi.weixin.qq.com/cgi-bin/health/get_report_answer?access_token=" + ton
weChatPart := MapOut()
weChatPart["jobid"] = jobid
weChatPart["date"] = date
weChatPart["offset"] = page
weChatPart["limit"] = pageSize
sendJsonData, jsonErr := json.Marshal(weChatPart)
if jsonErr != nil {
msg = "提交数据转换失败!"
return
}
addDePartMent := CurlPostJosn(getWechatApiUrl, sendJsonData)
btyDate = addDePartMent
// fmt.Printf("json2 ===>%v------>%v\n", weChatPart, string(addDePartMent))
var reportAnswerJson ReportAnswerResult
err = json.Unmarshal(addDePartMent, &reportAnswerJson)
r = &reportAnswerJson
isTrue = true
return
}

34
server/config.yaml

@ -64,12 +64,16 @@ redis:
db: 0
addr: 127.0.0.1:6379
password: ""
redisprefix:
prefix: "HXGK_GO_ZhixingCollege"
alias: "dev"
system:
env: public
addr: 8888
db-type: mysql
oss-type: local
use-multipoint: false
use-multipoint: true
iplimit-count: 15000
iplimit-time: 3600
tencent-cos:
@ -209,3 +213,31 @@ mysqlBillboardDate:
max-open-conns: 100
log-mode: false
log-zap: ""
#企业微信相关设置
workwechatid:
companyid: 'ww02f310301953277a' #企业ID
workwechatschool: #知行学院
agentid: 1000008
secretstr: 'YJOHrmHtvevAdctg-06TMLnPokIaLHdfrQMyQolZQC8'
workwechatappmaillist: #通讯录
secretstr: 'yjcQXkh6_116QKjfZfbRSyzdrFFZ9jbVlKJtL2tn3OU'
healthreport: #健康上报
secretstr: 'smjpGmFo5wp18BZGiLaECFr84Blv429v_GFdKp4_0YQ'
#测试企业
workwechatids:
companyid: 'ww708746402de33ba7' #企业ID
workwechatschools: #测试
agentid: 1000021
secretstr: 'rbqos2un6vVY5k_c2aOFK6HUuONeJsiBqwRZXTDVBKU'
workwechatappmaillists: #通讯录
secretstr: 'TSSsJXiqh3RKl0NYIoB-sPc43MUIRJ1ppALWtzyLY94'
healthreports: #健康上报
secretstr: 'smjpGmFo5wp18BZGiLaECFr84Blv429v_GFdKp4_0YQ'

36
server/config/config.go

@ -1,13 +1,14 @@
package config
type Server struct {
JWT JWT `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Zap Zap `mapstructure:"zap" json:"zap" yaml:"zap"`
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
Email Email `mapstructure:"email" json:"email" yaml:"email"`
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
System System `mapstructure:"system" json:"system" yaml:"system"`
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
JWT JWT `mapstructure:"jwt" json:"jwt" yaml:"jwt"`
Zap Zap `mapstructure:"zap" json:"zap" yaml:"zap"`
Redis Redis `mapstructure:"redis" json:"redis" yaml:"redis"`
RedisPrefix RedisPrefixStr `mapstructure:"redisprefix" json:"redisprefix" yaml:"redisprefix"` //redis键浅醉
Email Email `mapstructure:"email" json:"email" yaml:"email"`
Casbin Casbin `mapstructure:"casbin" json:"casbin" yaml:"casbin"`
System System `mapstructure:"system" json:"system" yaml:"system"`
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
// auto
AutoCode Autocode `mapstructure:"autoCode" json:"autoCode" yaml:"autoCode"`
// gorm
@ -23,10 +24,19 @@ type Server struct {
MysqlQADate Mysql `mapstructure:"mysqlQADate" json:"mysqlQADate" yaml:"mysqlQADate"`
MysqlBillboardDate Mysql `mapstructure:"mysqlBillboardDate" json:"mysqlBillboardDate" yaml:"mysqlBillboardDate"`
// oss
Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
AliyunOSS AliyunOSS `mapstructure:"aliyun-oss" json:"aliyunOSS" yaml:"aliyun-oss"`
TencentCOS TencentCOS `mapstructure:"tencent-cos" json:"tencentCOS" yaml:"tencent-cos"`
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
WorkWechatId workWechatId `mapstructure:"workwechatid" json:"workwechatid" yaml:"workwechatid"`
WorkWechatSchool workWechatApplication `mapstructure:"workwechatschool" json:"workwechatschool" yaml:"workwechatschool"`
WorkWechatMailList workWechatSecret `mapstructure:"workwechatappmaillist" json:"workwechatappmaillist" yaml:"workwechatappmaillist"`
WorkHealthReport workWechatSecret `mapstructure:"healthreport" json:"healthreport" yaml:"healthreport"`
WorkWechatIds workWechatId `mapstructure:"workwechatids" json:"workwechatids" yaml:"workwechatids"`
WorkWechatSchools workWechatApplication `mapstructure:"workwechatschools" json:"workwechatschools" yaml:"workwechatschools"`
WorkWechatMailLists workWechatSecret `mapstructure:"workwechatappmaillists" json:"workwechatappmaillists" yaml:"workwechatappmaillists"`
WorkHealthReports workWechatSecret `mapstructure:"healthreports" json:"healthreports" yaml:"healthreports"`
}

5
server/config/redis.go

@ -5,3 +5,8 @@ type Redis struct {
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` // 服务器地址:端口
Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
}
type RedisPrefixStr struct {
PreFix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // redis键前缀
Alias string `mapstructure:"alias" json:"alias" yaml:"alias"` // redis键前缀
}

19
server/config/wechat.go

@ -0,0 +1,19 @@
package config
//微信配置相关
//企业微信ID
type workWechatId struct {
CompanyId string `json:id` //企业ID
}
//企业微信应用配置
type workWechatApplication struct {
AgentId string `json:agentid` //应用ID
SecretStr string `json:secretstr` //应用Secret
}
//企业微信内置应用
type workWechatSecret struct {
SecretStr string `json:secretstr` //应用Secret
}

2
server/core/server.go

@ -40,5 +40,7 @@ func RunWindowsServer() {
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
默认前端文件运行地址:http://127.0.0.1:8080
`, address)
// fmt.Printf("%v------%T\n", global.GVA_REDIS, global.GVA_REDIS)
// global.GVA_REDIS.Set()
global.GVA_LOG.Error(s.ListenAndServe().Error())
}

1
server/go.mod

@ -17,6 +17,7 @@ require (
github.com/go-sql-driver/mysql v1.5.0
github.com/gookit/color v1.3.1
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
github.com/mitchellh/mapstructure v1.2.2
github.com/mojocn/base64Captcha v1.3.1
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/qiniu/api.v7/v7 v7.4.1

4
server/initialize/gorm.go

@ -101,7 +101,7 @@ func GormMysql() *gorm.DB {
//@return: *gorm.Config
func gormConfig() *gorm.Config {
config := &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true}
config := &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true, SkipDefaultTransaction: true}
switch global.GVA_CONFIG.Mysql.LogMode {
case "silent", "Silent":
config.Logger = internal.Default.LogMode(logger.Silent)
@ -149,7 +149,7 @@ func GormMysqlChange(setDataBaseName string) *gorm.DB {
case "mysqlQADate":
m = global.GVA_CONFIG.MysqlQADate
case "mysqlBillboardDate":
m = global.GVA_CONFIG.MysqlQADate
m = global.GVA_CONFIG.MysqlBillboardDate
default:
m = global.GVA_CONFIG.Mysql
}

3
server/initialize/router.go

@ -54,6 +54,8 @@ func Routers() *gin.Engine {
{
systemRouter.InitBaseRouter(PublicGroup) // 注册基础功能路由 不做鉴权
systemRouter.InitInitRouter(PublicGroup) // 自动初始化相关
groupHandleRouter.InitHealthReporRouter(PublicGroup) //健康上报
}
PrivateGroup := Router.Group("")
PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
@ -76,6 +78,7 @@ func Routers() *gin.Engine {
shiyanRouter.InitShiyanRouter(PrivateGroup) // 实验路由
groupHandleRouter.InitGroupRouter(PrivateGroup) //集团架构
// groupHandleRouter.InitHealthReporRouter(PrivateGroup) //健康上报
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
autocodeRouter.InitSysAutoCodeExampleRouter(PrivateGroup)

8
server/log/server_error.log

@ -3,3 +3,11 @@
[github.com/flipped-aurora/gin-vue-admin/server]2021/10/28 - 10:28:42.301 error l:/任官钰/代码/gin-vue-admin-master/gin-vue-admin-master/server/api/v1/system/sys_initdb.go:34 自动创建数据库失败! {"err": "Error 1045: Access denied for user 'root'@'localhost' (using password: YES)"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/03 - 14:15:50.055 error G:/goobject/src/git_public/gin-vue-admin/server/core/server.go:47 listen tcp :8888: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/03 - 15:17:19.679 error G:/goobject/src/git_public/gin-vue-admin/server/core/server.go:47 listen tcp :8888: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/10 - 08:05:32.159 error G:/goobject/src/git_public/gin-vue-admin/server/middleware/jwt.go:61 get redis jwt failed {"err": "redis: nil"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 09:57:57.698 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 10:13:41.352 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 10:20:19.231 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 10:22:20.223 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 10:24:27.197 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/12 - 10:25:10.844 error G:/goobject/src/git_public/gin-vue-admin/server/api/v1/system/sys_api.go:35 创建失败! {"err": "存在相同api"}
[github.com/flipped-aurora/gin-vue-admin/server]2021/11/16 - 12:59:29.413 error G:/goobject/src/git_public/gin-vue-admin/server/middleware/jwt.go:61 get redis jwt failed {"err": "redis: nil"}

1442
server/log/server_info.log

File diff suppressed because it is too large

7
server/main.go

@ -24,6 +24,10 @@ func main() {
global.GVA_VP = core.Viper() // 初始化Viper
global.GVA_LOG = core.Zap() // 初始化zap日志库
global.GVA_DB = initialize.Gorm() // gorm连接数据库
// initialize.Redis() //Redis初始化
// Redis
initialize.Timer()
if global.GVA_DB != nil {
initialize.MysqlTables(global.GVA_DB) // 初始化表
@ -67,5 +71,8 @@ func main() {
if global.GVA_DB_BillboardDate != nil {
fmt.Printf("%v==>数据库mysqlBillboardDate初始化失败\n", global.GVA_DB_BillboardDate)
}
// fmt.Printf("%v===>%v----->%v\n", global.GVA_CONFIG.WorkWechatId, global.GVA_CONFIG.WorkWechatSchool, global.GVA_CONFIG.WorkWechatMailList)
// fmt.Printf("%v===>%v----->%v\n", global.GVA_CONFIG.WorkWechatIds, global.GVA_CONFIG.WorkWechatSchools, global.GVA_CONFIG.WorkWechatMailLists)
core.RunWindowsServer()
}

BIN
server/resource/excel/ExcelExport.xlsx

Binary file not shown.

1
server/router/examtestpage/enter.go

@ -2,4 +2,5 @@ package examtestpage
type RouterGroup struct {
GroupHandleRouter
HealthReportHandleRouter
}

13
server/router/examtestpage/grouphandle.go

@ -9,12 +9,15 @@ import (
type GroupHandleRouter struct{}
func (g *GroupHandleRouter) InitGroupRouter(Router *gin.RouterGroup) {
shiyanCodeRouter := Router.Group("group")
groupCodeRouter := Router.Group("group")
var authorityApi = v1.ApiGroupApp.GroupHandleApiGroup.GroupHandleApi
{
shiyanCodeRouter.GET("/grouplist", authorityApi.GroupList) // 获取集团架构列表
shiyanCodeRouter.POST("/getgroupinfo", authorityApi.GetGroupInfo) // 获取集团详细信息
shiyanCodeRouter.POST("/getsubsidiaryinfo", authorityApi.GetSubsidiaryInfo) // 获取子公司详细信息
shiyanCodeRouter.POST("/getgrouppositioninfo", authorityApi.GetGroupPositionInfo) // 获取工段详细信息
groupCodeRouter.GET("/grouplist", authorityApi.GroupList) // 获取集团架构列表
groupCodeRouter.POST("/getgroupinfo", authorityApi.GetGroupInfo) // 获取集团详细信息
groupCodeRouter.POST("/getsubsidiaryinfo", authorityApi.GetSubsidiaryInfo) // 获取子公司详细信息
groupCodeRouter.POST("/getgrouppositioninfo", authorityApi.GetGroupPositionInfo) // 获取工段详细信息
groupCodeRouter.POST("/delgroupinfo", authorityApi.DelGroupInfo) // 删除集团相应信息
groupCodeRouter.POST("/addgroupinfo", authorityApi.AddGroupInfo) // 添加集团相应信息
groupCodeRouter.POST("/eitegroupinfo", authorityApi.EiteGroupInfo) // 添加集团相应信息
}
}

21
server/router/examtestpage/healthreporthandle.go

@ -0,0 +1,21 @@
package examtestpage
import (
v1 "github.com/flipped-aurora/gin-vue-admin/server/api/v1"
"github.com/gin-gonic/gin"
)
//集团框架相关处理数据
type HealthReportHandleRouter struct{}
func (g *GroupHandleRouter) InitHealthReporRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
groupCodeRouter := Router.Group("wechathealth")
var authorityApi = v1.ApiGroupApp.GroupHandleApiGroup.HealthReportStat
{
groupCodeRouter.GET("/healthlist", authorityApi.HealthList) // 获取健康上报使用统计
groupCodeRouter.GET("/runhealthlist", authorityApi.RunHealthList) //获取健康上报任务ID列表
groupCodeRouter.GET("/posthealthlist", authorityApi.PostReportJobInfo) //获取指定的健康上报任务详情。
groupCodeRouter.POST("/postreportanswerlist", authorityApi.PostReportAnswerList)
}
return groupCodeRouter
}

135
server/utils/redishandel/myredis.go

@ -0,0 +1,135 @@
package redishandel
import (
"context"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
//redis 基础设定
type RedisStoreType struct {
Expiration time.Duration
PreKey string
Context context.Context
}
//启动redis
func RunRedis() *RedisStoreType {
var redisStoreType RedisStoreType
// contextBackground := context.Background()
redisStoreType.Expiration = time.Second * 300
redisStoreType.PreKey = global.GVA_CONFIG.RedisPrefix.PreFix + ":"
redisStoreType.Context = context.Background()
return &redisStoreType
// return &RedisStoreType{
// Expiration: time.Second * 300,
// PreKey: global.GVA_CONFIG.RedisPrefix.PreFix + ":",
// Context: contextBackground
// }
}
//设置键前缀
func (r *RedisStoreType) SetRedisPrefix(prefix string) {
r.PreKey = prefix
}
//设置过期时间
func (r *RedisStoreType) SetRedisTime(timeDate int64) {
r.Expiration = time.Second * time.Duration(timeDate)
}
//设置字符串
func (r *RedisStoreType) Set(key string, value string) bool {
err := global.GVA_REDIS.Set(r.Context, r.PreKey+key, value, r.Expiration).Err()
if err != nil {
return false
}
return true
}
//获取字符串
func (r *RedisStoreType) Get(key string) (bool, string) {
err := global.GVA_REDIS.Get(r.Context, r.PreKey+key)
if err.Err() != nil {
return false, ""
}
return true, err.Val()
}
//哈希操作
/*
获取单个哈希键值
@hashName 集合名称
@hashKey 哈希键
callback
errs 状态
hashVal 获得值
*/
func (r *RedisStoreType) HashGet(hashName, hashKey string) (errs bool, hashVal string) {
err := global.GVA_REDIS.HGet(r.Context, r.PreKey+hashName, hashKey)
if err.Err() != nil {
return false, ""
}
return true, err.Val()
}
/*
为哈希表中的字段赋值 单一设置
@hashName 集合名称
@hashKey 哈希键
@hashVal 要添加的值
*/
func (r *RedisStoreType) HashSet(hashName, hashKey, hashVal string) bool {
err := global.GVA_REDIS.HSet(r.Context, r.PreKey+hashName, hashKey, hashVal).Err()
if err != nil {
return false
}
global.GVA_REDIS.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
return true
}
/*
同时将多个 field-value (字段-)对设置到哈希表中
@hashName 集合名称
@hashVal 要添加的键与值
*/
func (r *RedisStoreType) HashMsetAdd(hashName string, hashVal map[string]interface{}) bool {
// rdb := RedisInit()
err := global.GVA_REDIS.HMSet(r.Context, r.PreKey+hashName, hashVal).Err()
// err := rdb.HMSet(ctx, "userfg", hashVal).Err()
if err != nil {
return false
}
global.GVA_REDIS.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
// fmt.Printf("错误sss=========》%v\n", hashVal)
return true
}
func (r *RedisStoreType) HashMsetAddAry(hashName string, hashVal []map[string]interface{}) bool {
// rdb := RedisInit()
err := global.GVA_REDIS.HMSet(r.Context, r.PreKey+hashName, hashVal).Err()
// err := rdb.HMSet(ctx, "userfg", hashVal).Err()
if err != nil {
return false
}
global.GVA_REDIS.PExpire(r.Context, r.PreKey+hashName, r.Expiration)
// fmt.Printf("错误sss=========》%v\n", hashVal)
return true
}
/*
返回哈希表中所有的字段和值
@hashName 集合名称
@hashKey 哈希键
*/
func (r *RedisStoreType) HashGetAll(hashName string) (map[string]string, bool) {
// rdb := RedisInit()
val, err := global.GVA_REDIS.HGetAll(r.Context, r.PreKey+hashName).Result()
if err != nil {
return val, false
}
if len(val) == 0 {
return val, false
}
return val, true
}
Loading…
Cancel
Save