24 changed files with 12782 additions and 35 deletions
@ -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) |
||||
|
} |
||||
File diff suppressed because it is too large
@ -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 |
||||
|
} |
||||
@ -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: "" |
||||
@ -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"` |
||||
|
} |
||||
@ -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 |
||||
|
} |
||||
@ -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
|
||||
|
} |
||||
File diff suppressed because it is too large
Binary file not shown.
@ -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 |
||||
|
} |
||||
@ -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…
Reference in new issue