Commit 63e35752 by zhangjiec

增加部分接口

parent f19d9418
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="SqlResolveInspection" enabled="false" level="ERROR" enabled_by_default="false" />
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/data_db_cache/dbcurd/u_we_customer.go" dialect="GenericSQL" />
<file url="PROJECT" dialect="PostgreSQL" />
</component>
</project>
\ No newline at end of file
package api_admin
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"github.com/gin-gonic/gin"
"net/http"
)
// CreateArea 创建一个学校
// @Tags 管理后台
// @Summary 创建一个学校
// @Description 目前仅用于填充数据,暂未做权限校验
// @Accept json
// @Produce json
// @Param data body dbcurd.TableBaseArea true "学校信息"
// @Success 0 {object} integer
// @Router /ad/area [POST]
// @Security ApiKeyAuth
func CreateArea(c *gin.Context) {
var reqData dbcurd.TableBaseArea
err := c.ShouldBindJSON(&reqData)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqParaFormat,
"message": api.CodeMsg[api.ErrorReqParaFormat],
})
return
}
if reqData.CountyID == 0 || reqData.CountyID < 543 || reqData.CountyID > 3423 { // todoN 这里最好改成动态调整的
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " county_id不正确",
})
return
}
// v,ok := c.Get("adminID")
// adminID := v.(uint32)
//if ok!=true || adminID == 0{
// c.JSON(http.StatusOK, gin.H{
// "code": api.ErrorSystemErr,
// "data": api.CodeMsg[api.ErrorSystemErr],
// })
// logger.Log.Error("strconv.Atoi(c.Param(\"userID\")",
// zap.String("c.Param(\"userID\")",c.Param("userID")),
// zap.Error(err))
// return
//}
insertRes := dbcurd.InsertBaseArea(&reqData) //插入数据库
if insertRes == 1 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqInsertDuplicate,
"data": api.CodeMsg[api.ErrorReqInsertDuplicate] + "(名字不可重复)",
})
return
} else if insertRes == 9 || reqData.ID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
return
}
areaList := cache.GetCountyAreaMap(reqData.CountyID)
areaList = append(areaList, reqData.ID)
cache.CountyAreaMap.Store(reqData.CountyID, areaList) // 更新CountyAreaMap
cache.AreaMap.Store(reqData.ID, model.CacheBAreaStruct{ // AreaMap缓存,添加该校区
Name: reqData.Name,
Longitude: reqData.Longitude,
Latitude: reqData.Latitude,
CountyID: reqData.CountyID,
Status: reqData.Status,
})
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": reqData.ID,
})
}
package api_cache
//// GetCacheBDistrictMap 获取行政区域缓存
//// @Tags 管理后台
//// @Summary 测试用
//// @Description 先返回所有数据再说
//// -- @Param provinceID path integer true "省份id"
//// @Product json
//// -- @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
//// @Router /base/city/{provinceID} [GET]
//// @Security ApiKeyAuth
//func GetCacheBDistrictMap(c *gin.Context) {
// para, _ := strconv.Atoi(c.Param("id"))
// v, _ := cache.CityMap.Load(uint32(para)) // 如果查不到就直接返回空data
// // data, _ := v.([]cache.DistrictStruct)
// c.JSON(http.StatusOK, gin.H{
// "code": api.Success,
// "data": v,
// })
//}
package api_cache
//// GetCacheBDistrictMap 获取行政区域缓存
//// @Tags 管理后台
//// @Summary 测试用
//// @Description 先返回所有数据再说
//// -- @Param provinceID path integer true "省份id"
//// @Product json
//// -- @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
//// @Router /base/city/{provinceID} [GET]
//// @Security ApiKeyAuth
//func GetCacheBDistrictMap(c *gin.Context) {
// para, _ := strconv.Atoi(c.Param("id"))
// v, _ := cache.CityMap.Load(uint32(para)) // 如果查不到就直接返回空data
// // data, _ := v.([]cache.DistrictStruct)
// c.JSON(http.StatusOK, gin.H{
// "code": api.Success,
// "data": v,
// })
//}
package api_cache
//// GetCountyAreaMap 获取行政区域缓存
//// @Tags 管理后台
//// @Summary 测试用
//// @Description 先返回所有数据再说
//// -- @Param provinceID path integer true "省份id"
//// @Product json
//// -- @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
//// @Router /base/city/{provinceID} [GET]
//// @Security ApiKeyAuth
//func GetCountyAreaMap(c *gin.Context) {
// para, _ := strconv.Atoi(c.Param("id"))
// v, _ := cache.CityMap.Load(uint32(para)) // 如果查不到就直接返回空data
// // data, _ := v.([]cache.DistrictStruct)
// c.JSON(http.StatusOK, gin.H{
// "code": api.Success,
// "data": v,
// })
//}
......@@ -102,8 +102,8 @@ func GetAreaByCounty(c *gin.Context) {
testRole, ok := cache.GetWechatCustomerTestRole(userID.(uint32))
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserTokenWrong,
"message": api.CodeMsg[api.ErrorUserTokenWrong],
"code": api.ErrorTokenWrong,
"message": api.CodeMsg[api.ErrorTokenWrong],
})
return
}
......
......@@ -18,16 +18,16 @@ type creatCardUserRes struct {
// CreateCardUser 创建一个学生
// @Tags 家长微信
// @Summary 创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)
// @Summary 创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]
// @Description 传新建学生信息至后台,后台返回学生id,以及对应校区的service
// @Accept json
// @Produce json
// @Param data body dbcurd.InsertTableUserCardUserStruct true "学生信息"
// @Param data body dbcurd.InsertTableUCardUserStruct true "学生信息"
// @Success 0 {object} creatCardUserRes
// @Router /we/carduser [POST]
// @Security ApiKeyAuth
func CreateCardUser(c *gin.Context) {
var reqData dbcurd.InsertTableUserCardUserStruct
var reqData dbcurd.InsertTableUCardUserStruct
err := c.ShouldBindJSON(&reqData)
if err != nil {
c.JSON(http.StatusOK, gin.H{
......@@ -44,11 +44,11 @@ func CreateCardUser(c *gin.Context) {
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("strconv.Atoi(c.Param(\"userID\")",
zap.String("c.Param(\"userID\")", c.Param("userID")))
zap.Reflect("c.Get(\"userID\")", v))
return
}
newID := dbcurd.InsertUserCardUserAndUserWeCardUser(reqData, weUserID) //插入数据库
newID := dbcurd.InsertUCardUserAndUserWeCardUser(&reqData, weUserID) //插入数据库
if newID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
......
......@@ -3,6 +3,7 @@ package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
......@@ -12,7 +13,7 @@ import (
// DeleteCardUser 主家长删除一个学生
// @Tags 家长微信
// @Summary 主家长删除一个学生,(当家长点删除时弹框二次确认)
// @Summary 主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
......@@ -20,7 +21,8 @@ import (
// @Router /we/carduser/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteCardUser(c *gin.Context) {
cardUserID, _ := strconv.Atoi(c.Param("id"))
cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
......@@ -33,7 +35,7 @@ func DeleteCardUser(c *gin.Context) {
if ok == false {
logger.Log.Error("userID在Context里面居然没填对,遇到鬼了",
zap.String("Src", "DeleteCardUser"),
zap.Int("cardUserID", cardUserID))
zap.Uint32("cardUserID", cardUserID))
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
......@@ -41,7 +43,7 @@ func DeleteCardUser(c *gin.Context) {
return
}
// 查出该学生信息
cardUserInfo, ok := cache.GetUCardUserInfo(uint32(cardUserID))
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
......@@ -57,10 +59,23 @@ func DeleteCardUser(c *gin.Context) {
return
}
// 软删除
// 先删库
// 先删库 软删除 事务处理u_card_user和u_we_card_user
if dbcurd.UpdateUCardUserAndUWeCardUserDeleteAt(cardUserID) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"message": api.CodeMsg[api.ErrorSystemBusy],
})
return
}
// 再删缓存
// 再删缓存 1.simInfoMap 2.WechatCustomerMap 3.cardUserTrendMap 4.CardUserMap
cache.CardUserMap.Delete(cardUserID)
cache.CardUserTrendMap.Delete(cardUserID)
cache.DeleteAStudentIDInWechatCustomerMap(cardUserInfo.MasterWechatUserID, cardUserID, true)
for _, v := range cardUserInfo.SlaveWechatUserID {
cache.DeleteAStudentIDInWechatCustomerMap(v, cardUserID, false)
}
cache.SimInfoMap.Delete(cardUserInfo.SimCardID)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
......
package api_we
import (
"dc_golang_server_1/api"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
type slaveWeUserRes struct {
// 微信UnionID
WeUserID uint32 `json:"weUserID"`
// 微信昵称
Nickname string `json:"nickname"`
// 头像URL
AvatarURL string `json:"avatarURL"`
// 手机号
Phone string `json:"phone"`
// 绑定时间
CreateAt time.Time `json:"createAt"`
}
//type getBindCardUserRes struct {
// // 副家长微信信息列表
// WeUser []slaveWeUserRes `json:"weUser"`
// // 学生的邀请码,长度固定16,若为空,则表示邀请码开关关闭
// ShareCode string `json:"shareCode"`
//}
// GetBindCardUser 获取学生副家长列表(仅主家长有权限)
// @Tags 家长微信
// @Summary 获取学生副家长列表(仅主家长有权限)
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} []slaveWeUserRes "副家长信息列表"
// @Router /we/bindcarduser/{id} [GET]
// @Security ApiKeyAuth
func GetBindCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": []slaveWeUserRes{},
})
}
package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
"strconv"
)
type GetCardUserAndTrendRes struct {
WeResUserInfoStruct
Service [6]uint8 `json:"service" example:"1,2,2,0,0,0"` // 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
Trend []model.CacheCardUserTrendStruct `json:"trend"`
}
// GetCardUserAndTrend 获取单个学生信息和最新动态
// @Tags 家长微信
// @Summary 获取单个学生信息和最新动态[complete]
// @Description 传学生的ID,后台返回学生信息和最新动态
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} GetCardUserAndTrendRes "学生信息和最新动态"
// @Router /we/cardusertrend/{id} [GET]
// @Security ApiKeyAuth
func GetCardUserAndTrend(c *gin.Context) {
cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " id不正确",
})
return
}
// 取出微信ID
weUserID, ok := c.Get("userID")
if ok == false {
logger.Log.Error("userID在Context里面居然没填对,遇到鬼了",
zap.String("Src", "DeleteCardUser"),
zap.Uint32("cardUserID", cardUserID))
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
// 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
if cardUserInfo.MasterWechatUserID != weUserID { // 用户根本没得这个学生的权限,有问题
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"message": api.CodeMsg[api.ErrorUserRole],
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": GetCardUserAndTrendRes{
WeResUserInfoStruct: WeResUserInfoStruct{
ID: cardUserID,
Name: cardUserInfo.Name,
Sex: cardUserInfo.Sex,
Grade: cardUserInfo.Grade,
Class: cardUserInfo.Class,
StuNum: cardUserInfo.StuNum,
},
Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取
},
})
}
package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
"strconv"
)
type GetCardUserInfoRes struct {
WeResUserInfoStruct
Service [6]uint8 `json:"service" example:"1,2,2,0,0,0"` // 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
}
// GetCardUser 获取单个学生信息
// @Tags 家长微信
// @Summary 获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态
// @Description 传学生的ID,后台返回学生信息
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} GetCardUserInfoRes "学生信息"
// @Router /we/carduser/{id} [GET]
// @Security ApiKeyAuth
func GetCardUser(c *gin.Context) {
cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " id不正确",
})
return
}
// 取出微信ID
weUserID, ok := c.Get("userID")
if ok == false {
logger.Log.Error("userID在Context里面居然没填对,遇到鬼了",
zap.String("Src", "DeleteCardUser"),
zap.Uint32("cardUserID", cardUserID))
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
// 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
if cardUserInfo.MasterWechatUserID != weUserID { // 用户根本没得这个学生的权限,有问题
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"message": api.CodeMsg[api.ErrorUserRole],
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": GetCardUserInfoRes{
WeResUserInfoStruct: WeResUserInfoStruct{
ID: cardUserID,
Name: cardUserInfo.Name,
Sex: cardUserInfo.Sex,
Grade: cardUserInfo.Grade,
Class: cardUserInfo.Class,
StuNum: cardUserInfo.StuNum,
},
Service: [6]uint8{1, 2, 2, 2, 2, 2},
},
})
}
package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/logger"
"dc_golang_server_1/util"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"math/rand"
"net/http"
"strconv"
"time"
)
// GetCardUserShareCode 获取邀请码(仅主家长有权限)
// @Tags 家长微信
// @Summary 获取邀请码(仅主家长有权限) [complete]
// @Description 主家长生成邀请码,有效时长可选1分钟~60分钟
// @Produce json
// @Param id path integer true "学生ID"
// @Param time query integer false "有效时长,1~60分钟,不填则为60分钟" default(60)
// @Success 0 {object} string "邀请码内容"
// @Router /we/sharestring/{id} [GET]
// @Security ApiKeyAuth
func GetCardUserShareCode(c *gin.Context) {
cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " id不正确",
})
return
}
// 取出微信ID
weUserID, ok := c.Get("userID")
if ok == false {
logger.Log.Error("userID在Context里面居然没填对,遇到鬼了",
zap.String("Src", "DeleteCardUser"),
zap.Uint32("cardUserID", cardUserID))
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
// 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
if cardUserInfo.MasterWechatUserID != weUserID { // 用户根本没得这个学生的权限,有问题
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"message": api.CodeMsg[api.ErrorUserRole],
})
return
}
timeMin, err := strconv.Atoi(c.Query("time"))
if err != nil {
timeMin = 30
}
if timeMin < 1 || timeMin > 60 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + "有效期应在1-60分钟范围内,为空则默认30分钟",
})
return
}
eTime := uint32(time.Now().Second() + timeMin*60)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
var clear = make([]byte, 11)
clear[0] = byte(eTime >> 16)
clear[1] = byte(eTime >> 8)
clear[2] = byte(r.Intn(256))
clear[3] = byte(eTime >> 24)
clear[4] = byte(cardUserID >> 8)
clear[5] = byte(eTime)
clear[6] = byte(cardUserID >> 16)
clear[7] = byte(cardUserID)
clear[8] = byte(cardUserID >> 24)
util.GetCRC(clear, 9)
clear[9] -= clear[2]
clear[10] += clear[2]
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": util.EncryptBytesToBase64URL(clear, "Password88OhYeah"),
})
}
type BindCardUserRes struct {
GetCardUserAndTrendRes
Master bool `json:"master" example:"false"` //true:本来就是主家长,false:已成功绑定成副家长
}
// BindCardUser 通过邀请码绑定学生
// @Tags 家长微信
// @Summary 通过邀请码绑定学生 [complete]
// @Description 传学生的邀请码,后台返回学生信息
// @Produce json
// @Param share_code path string true "学生的邀请码"
// @Success 0 {object} BindCardUserRes "学生信息"
// @Failure 30 "邀请码无效"
// @Failure 31 "邀请码已过期"
// @Router /we/bindcarduser/{share_code} [POST]
// @Security ApiKeyAuth
func BindCardUser(c *gin.Context) {
str := c.Param("share_code")
if len(str) == 16 {
// todo logger 有人在非法请求
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
}
clear, err := util.DecryptBase64URLToBytes(str, "Password88OhYeah")
if err != nil {
// todo logger 有人在非法请求
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
return
}
if len(clear) != 11 {
// todo logger 有人在非法请求
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
return
}
clear[9] += clear[2]
clear[10] -= clear[2]
if util.CheckCRC(clear) == false {
// todo logger 有人在非法请求
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
return
}
//clear[5] = byte(eTime)
//clear[1] = byte(eTime >> 8)
//clear[0] = byte(eTime >> 16)
//clear[3] = byte(eTime >> 24)
//clear[7] = byte(cardUserID)
//clear[4] = byte(cardUserID >> 8)
//clear[6] = byte(cardUserID >> 16)
//clear[8] = byte(cardUserID >> 24)
eTime := uint32(clear[5]) + (uint32(clear[1]) << 8) + (uint32(clear[0]) << 16) + (uint32(clear[3]) << 24)
if eTime > uint32(time.Now().Second()) {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCodeRunTime,
"message": api.CodeMsg[api.ErrorShareCodeRunTime],
})
return
}
cardUserID := uint32(clear[7]) + (uint32(clear[4]) << 8) + (uint32(clear[6]) << 16) + (uint32(clear[8]) << 24)
if cardUserID == 0 {
// todo logger 有人在非法请求
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
return
}
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode],
})
return
}
// 取微信用户
v, ok := c.Get("userID")
weUserID := v.(uint32)
if ok != true || weUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("BindCardUser",
zap.Reflect("c.Get(\"userID\")", v))
return
}
if cardUserInfo.MasterWechatUserID == weUserID { // 本来就是主家长
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": BindCardUserRes{
Master: true,
GetCardUserAndTrendRes: GetCardUserAndTrendRes{
WeResUserInfoStruct: WeResUserInfoStruct{
ID: cardUserID,
Name: cardUserInfo.Name,
Sex: cardUserInfo.Sex,
Grade: cardUserInfo.Grade,
Class: cardUserInfo.Class,
StuNum: cardUserInfo.StuNum,
},
Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取
},
},
})
return
}
for _, slave := range cardUserInfo.SlaveWechatUserID {
if weUserID == slave { // 本来就是副家长
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": BindCardUserRes{
Master: false,
GetCardUserAndTrendRes: GetCardUserAndTrendRes{
WeResUserInfoStruct: WeResUserInfoStruct{
ID: cardUserID,
Name: cardUserInfo.Name,
Sex: cardUserInfo.Sex,
Grade: cardUserInfo.Grade,
Class: cardUserInfo.Class,
StuNum: cardUserInfo.StuNum,
},
Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取
},
},
})
return
}
}
// 存数据库
if dbcurd.InsertOrUpdateUWeCardUserSlave(weUserID, cardUserID) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
}
// 存缓存
cache.InsertNewStudentIDToWechatCustomerMap(weUserID, cardUserID, false)
cache.InsertWechatAndCardUserRelationToCardUserMap(weUserID, cardUserID, false)
cardUserInfo, ok = cache.GetCardUserInfo(cardUserID)
if ok == false { // 刚才都有,在就没有了呢
logger.Log.Error("BindCardUser cache.GetCardUserInfo(cardUserID) 突然没有了",
zap.Uint32("cardUserID", cardUserID),
zap.Uint32("weUserID", weUserID))
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": BindCardUserRes{
Master: false,
GetCardUserAndTrendRes: GetCardUserAndTrendRes{
WeResUserInfoStruct: WeResUserInfoStruct{
ID: cardUserID,
Name: cardUserInfo.Name,
Sex: cardUserInfo.Sex,
Grade: cardUserInfo.Grade,
Class: cardUserInfo.Class,
StuNum: cardUserInfo.StuNum,
},
Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取
},
},
})
}
package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
"strconv"
)
// GetCardUserTrend 微信学生首页,获取近20条用户最新动态
// @Tags 家长微信
// @Summary 微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态
// @Description 微信学生首页,获取近20条用户最新动态
// @Param id path integer true "学生ID"
// @Product json
// @Success 200 {object} []model.CacheCardUserTrendStruct "学生动态信息"
// @Router /we/trend/{id} [GET]
// @Security ApiKeyAuth
func GetCardUserTrend(c *gin.Context) {
cardUserID, _ := strconv.Atoi(c.Param("id"))
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " id不正确",
})
return
}
// 取微信用户
v, ok := c.Get("userID")
weUserID := v.(uint32)
if ok != true || weUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("GetCardUserTrend",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(uint32(cardUserID), weUserID) < 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(uint32(cardUserID)), // todo 改成从缓存取
})
}
package api_we
import (
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
"strconv"
)
//type getPhoneCardStatusRes struct {
// Status uint8 // 状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失
// SimID string `json:"simID"` // 卡号
// ExpiryAt time.Time // 到期时间
// MonthMin uint16 `json:"monthMin"` // 月套餐使用分钟数
// MonthPack uint16 `json:"monthPack"` // 月套餐分钟数
// Changeable uint8 `json:"changeable"` // 本月可修改亲情号次数
// Family []familyNumStruct `json:"family"` // 亲情号列表
//}
type getPhoneCardStatusRes struct {
SimID string `json:"simID"` // 卡号
model.CacheSimInfoStruct
}
// GetPhoneCardStatus 获取学生公话卡状态
// @Tags 家长微信
// @Summary 获取学生公话卡状态(含亲情号信息) [complete]
// @Description 传学生ID至后台,后台返回卡状态
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} getPhoneCardStatusRes "公话卡状态信息"
// @Router /we/phonecardstatus/{id} [GET]
// @Security ApiKeyAuth
func GetPhoneCardStatus(c *gin.Context) {
cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " id不正确",
})
return
}
// 取微信用户
v, ok := c.Get("userID")
weUserID := v.(uint32)
if ok != true || weUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("GetCardUserTrend",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(cardUserID, weUserID) < 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
// 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
if cardUserInfo.SimCardID == "" {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserNotHavePhoneCard,
"message": api.CodeMsg[api.ErrorUserNotHavePhoneCard],
})
return
}
c.JSON(
http.StatusOK,
gin.H{
"code": api.Success,
"data": getPhoneCardStatusRes{
cardUserInfo.SimCardID,
cache.GetSimInfo(cardUserInfo.SimCardID),
},
},
)
}
......@@ -75,7 +75,7 @@ func WeLogin(c *gin.Context) {
}
}
}
var userInfo model.CacheUWeCustomerStruct
var userInfo model.CacheWeCustomerStruct
var haveInfo bool
if userID != 0 {
userInfo, haveInfo = cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, nowTime)
......@@ -85,7 +85,7 @@ func WeLogin(c *gin.Context) {
}
if haveInfo == false { // 微信服务器登录
unionID, err := tencent2.TencentCode2Session(reqData.Code) //也不去校验reqData.Code长度了,对半是对的
unionID, err := tencent2.WechatCode2Session(reqData.Code) //也不去校验reqData.Code长度了,对半是对的
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorTencentErr,
......@@ -131,7 +131,7 @@ func WeLogin(c *gin.Context) {
}
for _, cardUserID := range userInfo.MasterCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID
......@@ -151,7 +151,7 @@ func WeLogin(c *gin.Context) {
}
for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID
......@@ -208,7 +208,7 @@ func GetStudentList(c *gin.Context) {
var res weUserListStruct
for _, cardUserID := range userInfo.MasterCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID
......@@ -228,7 +228,7 @@ func GetStudentList(c *gin.Context) {
}
for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID
......
......@@ -7,129 +7,6 @@ import (
"time"
)
type bindCardUserRes struct {
Master bool `json:"master" example:"false"` //true:本来就是主家长,false:已成功绑定成副家长
ID uint32 `json:"id"` // 学生ID
Name string `json:"name"`
Sex uint8 `json:"sex"` // 0女 1男
Area string `json:"area" example:"四川省成都市温江区实验中学"` // 区域名字
Grade int8 `json:"grade"` // "1~9对应一年级~九年级,10~12对应高一~高三"
Class int8 `json:"class"`
StuNum string `json:"stuNum"`
Service []uint8 `json:"service" example:"1,2,2,0,0,0"` // 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
}
// BindCardUser 通过邀请码绑定学生
// @Tags 家长微信
// @Summary 通过邀请码绑定学生
// @Description 传学生的邀请码,后台返回学生信息
// @Produce json
// @Param share_code path string true "学生的邀请码"
// @Success 0 {object} bindCardUserRes "学生信息"
// @Failure 30 "邀请码无效"
// @Failure 31 "邀请码已过期"
// @Router /we/bindcarduser/{share_code} [POST]
// @Security ApiKeyAuth
func BindCardUser(c *gin.Context) {
res := bindCardUserRes{}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": res,
})
}
// DeleteBindCardUser 副家长解绑学生
// @Tags 家长微信
// @Summary 副家长解绑学生
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0
// @Router /we/bindcarduser/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteBindCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
type wechatCardUsersTrendType struct {
ServiceType uint8 `json:"service"` //服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
TrendName string `json:"title"` //显示在第一行
Content string `json:"content"` //显示在第二行
Time string `json:"time"` //显示在第三行
}
// GetCardUsersTrend 微信学生首页,获取近10条用户最新动态
// @Tags 家长微信
// @Summary 微信学生首页,获取近20条用户最新动态
// @Description 微信学生首页,获取近20条用户最新动态
// @Param id path integer true "学生ID"
// @Product json
// @Success 200 {object} wechatCardUsersTrendType "学生动态信息"
// @Router /we/trend/{id} [GET]
// @Security ApiKeyAuth
func GetCardUsersTrend(c *gin.Context) {
//id, _ := strconv.Atoi(c.Param("id"))
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": [20]wechatCardUsersTrendType{},
})
}
type slaveWeUserRes struct {
// 微信UnionID
WeUserID uint32 `json:"weUserID"`
// 微信昵称
Nickname string `json:"nickname"`
// 头像URL
AvatarURL string `json:"avatarURL"`
// 手机号
Phone string `json:"phone"`
// 绑定时间
CreateAt time.Time `json:"createAt"`
}
//type getBindCardUserRes struct {
// // 副家长微信信息列表
// WeUser []slaveWeUserRes `json:"weUser"`
// // 学生的邀请码,长度固定16,若为空,则表示邀请码开关关闭
// ShareCode string `json:"shareCode"`
//}
// GetBindCardUser 获取学生副家长列表(仅主家长有权限)
// @Tags 家长微信
// @Summary 获取学生副家长列表(仅主家长有权限)
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} []slaveWeUserRes "副家长信息列表"
// @Router /we/bindcarduser/{id} [GET]
// @Security ApiKeyAuth
func GetBindCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": []slaveWeUserRes{},
})
}
// CardUserShareCode 获取邀请码(仅主家长有权限)
// @Tags 家长微信
// @Summary 获取邀请码(仅主家长有权限)
// @Description 主家长生成邀请码,有效时长可选1分钟~60分钟
// @Produce json
// @Param id path integer true "学生ID"
// @Param time query integer false "有效时长,1~60分钟,不填则为60分钟" default(60)
// @Success 0 {object} string "邀请码内容"
// @Router /we/sharecode/{id} [GET]
// @Security ApiKeyAuth
func CardUserShareCode(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": "todo",
})
}
//// PutCardUserShareOn 打开邀请码开关(仅主家长有权限)
//// @Tags 家长微信
//// @Summary 打开邀请码开关(仅主家长有权限)
......@@ -277,32 +154,6 @@ type familyNumStruct struct {
Name string `json:"name"`
}
type getPhoneCardStatusRes struct {
Status uint8 `json:"status"` // 状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失
SimID string `json:"simID"` // 卡号
ExpiryAt time.Time `json:"expiryAt"` // 到期时间
MonthMin uint16 `json:"monthMin"` // 月套餐使用分钟数
MonthPack uint16 `json:"monthPack"` // 月套餐分钟数
Changeable uint8 `json:"changeable"` // 本月可修改亲情号次数
Family []familyNumStruct `json:"family"` // 亲情号列表
}
// GetPhoneCardStatus 获取学生公话卡状态
// @Tags 家长微信
// @Summary 获取学生公话卡状态
// @Description 传学生ID至后台,后台返回卡信息
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0 {object} getPhoneCardStatusRes "公话卡状态信息"
// @Router /we/phonecardstatus/{id} [GET]
// @Security ApiKeyAuth
func GetPhoneCardStatus(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": getPhoneCardStatusRes{},
})
}
type getCallRecordRes struct {
// 被叫号码
CalledNumber string `json:"number"`
......
......@@ -11,7 +11,7 @@ func Cors() gin.HandlerFunc {
if context.Request.Method == "OPTIONS" {
origin := context.Request.Header.Get("Origin")
var headerKeys []string
for k, _ := range context.Request.Header {
for k := range context.Request.Header {
headerKeys = append(headerKeys, k)
}
headerStr := strings.Join(headerKeys, ",")
......
package api
const (
Success = 0
ErrorTokenExist = 1
ErrorTokenWrong = 2
ErrorTokenRunTime = 3
ErrorTokenExit = 4
ErrorUserRole = 5
ErrorSystemErr = 6
ErrorTencentErr = 7
Success = 0
ErrorTokenExist = 1
ErrorTokenWrong = 2
ErrorTokenRunTime = 3
ErrorTokenExit = 4
ErrorUserRole = 5
ErrorSystemErr = 6
ErrorSystemBusy = 7
ErrorTencentErr = 8
ErrorUserNotHavePhoneCard = 9
ErrorReqParaFormat = 10
ErrorReqPara = 11
ErrorReqInsertDuplicate = 12
ErrorUserTokenWrong = 1001
ErrorWechatLogin = 1002
ErrorReq
//ERROR = 500
// code = 1000...用户模块的错误
//ERROR_USERNAME_USED = 1001
//ERROR_PASSWORD_WRONG = 1002
//ERROR_USER_NOT_EXIST = 1003
//ERROR_TOKEN_EXIST = 1004
//ERROR_TOKEN_RUNTIME = 1005
//ERROR_TOKEN_WRONG = 1006
//ERROR_TOKEN_TYPE_WRONG = 1007
//ERROR_USER_NO_RIGHT = 1008
// code = 2000...XXXXX模块的错误
// code = 3000...XXXXX模块的错误
ErrorShareCode = 30
ErrorShareCodeRunTime = 31
)
var CodeMsg = map[uint16]string{
ErrorTokenExist: "token不存在",
ErrorTokenWrong: "非法token",
ErrorTokenRunTime: "token过期",
ErrorTokenExit: "token已退出登录",
ErrorUserRole: "用户没有权限",
ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)",
ErrorTencentErr: "微信服务器返回的错误:",
ErrorTokenExist: "token不存在",
ErrorTokenWrong: "非法token",
ErrorTokenRunTime: "token过期",
ErrorTokenExit: "token已退出登录",
ErrorUserRole: "用户没有权限",
ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)",
ErrorSystemBusy: "服务器忙,请重试",
ErrorTencentErr: "微信服务器返回的错误:",
ErrorUserNotHavePhoneCard: "用户未绑定共话卡",
ErrorReqPara: "请求参数内容(取值)错误",
ErrorReqParaFormat: "请求参数格式错误",
ErrorReqInsertDuplicate: "内容重复,无法创建",
ErrorUserTokenWrong: "用户token错误,系统找不到用户信息,请重新登录",
ErrorWechatLogin: "微信登录错误:",
// Success: "OK",
// ERROR: "FAIL",
// ERROR_USERNAME_USED: "用户名已存在!",
// ERROR_PASSWORD_WRONG: "密码错误",
// ERROR_USER_NOT_EXIST: "用户不存在",
// ERROR_TOKEN_EXIST: "TOKEN不存在",
// ERROR_TOKEN_RUNTIME: "TOKEN已过期",
// ERROR_TOKEN_WRONG: "TOKEN不正确",
// ERROR_TOKEN_TYPE_WRONG: "TOKEN格式错误",
// ERROR_USER_NO_RIGHT: "用户没有权限",
ErrorShareCode: "邀请码无效,请联系主家长微信重新分享",
ErrorShareCodeRunTime: "邀请码已过期,请联系主家长微信重新分享",
}
......@@ -220,6 +220,46 @@ func JeffWTWechat() gin.HandlerFunc {
}
}
//// JeffWTWechatMasterID 校验toekn,同时校验path传入的学生ID,该TOKEN的微信用户是否为主权限
//func JeffWTWechatMasterID() gin.HandlerFunc {
// return func(c *gin.Context) {
// clearStruct := DecryptToken(c.Request.Header.Get("token"))
// if clearStruct.UserType != 1 {
// c.JSON(http.StatusOK, gin.H{
// "status": ErrorUserRole,
// "message": CodeMsg[ErrorUserRole],
// })
// c.Abort()
// return
// }
// if clearStruct.CheckResult == Success {
// CheckTokenExit(&clearStruct)
// }
// if clearStruct.CheckResult != Success {
// c.JSON(http.StatusOK, gin.H{
// "status": clearStruct.CheckResult,
// "message": CodeMsg[uint16(clearStruct.CheckResult)],
// })
// c.Abort()
// return
// }
// cardUserID, _ := strconv.Atoi(c.Param("id"))
// if cardUserID == 0 {
// c.JSON(http.StatusOK, gin.H{
// "status": ErrorReqPara,
// "message": CodeMsg[ErrorReqPara],
// })
// c.Abort()
// return
// }
//
// // +++++++++++++++根据cardUserMap查
//
// c.Set("userID", clearStruct.UserID)
// c.Next()
// }
//}
func JeffWTAdmin() gin.HandlerFunc {
return func(c *gin.Context) {
clearStruct := DecryptToken(c.Request.Header.Get("token"))
......
......@@ -40,18 +40,19 @@ func InitRouter() { //*gin.Engine{
wechat := r.Group("we/")
wechat.Use(api.JeffWTWechat())
{ // 需要token的stulist
wechat.GET("stulist", api_we.GetStudentList) //获取学生列表
wechat.POST("carduser", api_we.CreateCardUser) //创建学生
wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生
wechat.GET("trend/:id", api_we.GetCardUsersTrend) //获取学生最新动态
wechat.GET("bindcarduser/:id", api_we.GetBindCardUser) //获取学生副家长列表(仅主家长有权限)
wechat.GET("sharecode/id", api_we.CardUserShareCode) //获取邀请码(仅主家长有权限)
wechat.POST("bindcarduser/:share_code", api_we.BindCardUser) //副家长绑定学生
wechat.DELETE("bindcarduser/:id", api_we.DeleteBindCardUser) //副家长解绑学生
wechat.GET("stulist", api_we.GetStudentList) //获取学生列表
wechat.POST("carduser", api_we.CreateCardUser) //创建学生
wechat.GET("carduser/:id", api_we.GetCardUser) //读取单个学生信息
wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生
wechat.GET("trend/:id", api_we.GetCardUserTrend) //获取学生最新动态
wechat.GET("cardusertrend/:id", api_we.GetCardUserAndTrend) //获取单个学生信息和最新动态
wechat.GET("bindcarduser/:id", api_we.GetBindCardUser) //获取学生副家长列表(仅主家长有权限)
wechat.GET("sharestring/:id", api_we.GetCardUserShareCode) //获取邀请码(仅主家长有权限)
wechat.POST("bindcarduser/:share_code", api_we.BindCardUser) //副家长绑定学生
wechat.DELETE("bindcarduser/:id", api_we.DeleteSlaveBindCardUser) //副家长解绑学生
//wechat.PUT("cardusershareon/:id", api_we.PutCardUserShareOn) //打开邀请码开关(仅主家长有权限)
//wechat.PUT("cardusershareoff/:id", api_we.PutCardUserShareOff) //关闭邀请码开关(仅主家长有权限)
wechat.DELETE("slaveweuser", api_we.DeleteSlaveWeUser) //删除副家长(仅主家长有权限)
//wechat.DELETE("allslaveweuser", api_we.DeleteAllSlaveWeUser) //删除副家长(仅主家长有权限)
wechat.DELETE("slaveweuser/:id", api_we.DeleteSlaveWeUser) //删除副家长(仅主家长有权限)
wechat.PUT("carduser/:id", api_we.PutCardUser) //修改学生信息
wechat.PUT("cardloss/:id", api_we.CardLoss) //卡挂失/解挂
wechat.PUT("cardbind/:id", api_we.CardBind) //绑定卡
......
......@@ -3,7 +3,6 @@ package cache
import (
"dc_golang_server_1/data_db_cache/model"
"sync"
"time"
)
func Init() {
......@@ -11,12 +10,14 @@ func Init() {
initAreaMapAndCountyAreaMap()
initWechatCustomerMap()
initUCardUserMapAndSiminfoMapNoFamilyNum()
initCardUserMapAndSimInfoMapNoFamilyNum()
initWechatAndCardUserRelationToWechatCustomerMapAndCardUserMap()
initFamilyNumToSimInfoMap()
//initAreaServiceMap()
//initPhone20DeviceMap()
//initAdminMap()
//initOperatorMap()
initAreaServiceMap()
initPhone20DeviceMap()
// initAdminMap()
// initOperatorMap()
//initCardUserTrendMap()
}
// ProvinceMap /*********************************************************全国行政区域**/------------------------OK
......@@ -37,7 +38,7 @@ var CountyAreaMap sync.Map //map[uint32][[]uint32] 区县ID作为KEY,[]area_id
// AreaMap /******************************************************区域(校区)**/
var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE
//type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出,后续再加支付信息
//type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出
// Name string
// Longitude uint32
// Latitude uint32
......@@ -64,12 +65,12 @@ var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE
/******************************************************区域(校区)服务信息**/
var areaServiceMap sync.Map //area_service_id 作为KEY CacheBAreaStruct 作为VALUE
type AreaServiceStruct struct { //
AreaID uint32
ServiceID uint8 //服务项目 1公话 2定位 3饮水 4POS .........
OperatorID uint32 //运营商ID
Name string //服务名字(例宿舍135栋饮水)name
Status uint8 //状态 0无内容1正式2测试3暂停4暂未开放
type AreaServiceStruct struct { // 后续再加支付信息
AreaID uint32
ServiceType uint8 //服务项目 1公话 2定位 3饮水 4POS .........
//OperatorID uint32 //运营商ID
//Name string //服务名字(例宿舍135栋饮水)name
Status uint8 //状态 0无内容1正式2测试3暂停4暂未开放
}
/*---------------------------------------------------------------*/
......@@ -101,7 +102,7 @@ type AreaServiceStruct struct { //
/***************************************************微信用户(家长)**/ //------------------------OK
var WechatCustomerUnionIDToIDMAP sync.Map // UnionID作为KEY(string),微信用户ID作为VALUE(uint32)
var WechatCustomerMap sync.Map // 微信的WechatUserID(uint32)作为KEY
//type CacheUWeCustomerStruct struct {
//type CacheWeCustomerStruct struct {
// TokenCreatTime int64
// TestRole bool // 测试用户(可看到测试校区)
// WePhone string // 手机号
......@@ -133,15 +134,24 @@ var CardUserMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY
// IcCardID uint32
//}
// todo 加锁SlaveWechatUserID
//var CardUserWechatMap sync.Map
// CardUserTrendMap /***************************************************卡用户动态**/
var CardUserTrendMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY,[]CardUserTrendStruct作为VALUE
//type CacheCardUserTrendStruct struct {
// ServiceType uint8 //服务项目 UI图标及颜色等
// DeviceID uint32
// Content string
// Time time.Time
//}
/*---------------------------------------------------------------*/
/********************************************************Sim卡信息(仅存学生绑定了的)**/
var simInfoMap sync.Map //sim_id(string) 作为KEY
var SimInfoMap sync.Map //sim_id(string) 作为KEY
//type CacheSimInfoStruct struct {
// CardUserID uint32 //卡用户ID
// AreaServiceID uint32
// Status int8 //0无数据 1 正常使用 2 已挂失
// Status uint8 //0无数据 1 正常使用 2 已挂失
// MonthTalkMinutes uint16
// MonthPackageMinutes uint16
// ExpiryAt time.Time
......@@ -156,23 +166,12 @@ var simInfoMap sync.Map //sim_id(string) 作为KEY
/*---------------------------------------------------------------*/
/*******************************************************电话设备**/
var phone20DeviceMap sync.Map //device_id 作为KEY Phone20DeviceStruct 作为VALUE
type Phone20DeviceStruct struct {
AreaServiceID uint32
AllowCallTime uint8 //允许通话时长,255表示不限制时长
//Place string //安装位置
Status bool
}
/*---------------------------------------------------------------*/
/***************************************************卡用户动态**/
var cardUserTrendMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY,[]CardUserTrendType作为VALUE
type CardUserTrendType struct {
ServiceType uint8 //服务项目 UI图标及颜色等
DeviceID uint32
Content string
Time time.Time
}
var phone20DeviceMap sync.Map //device_id 作为KEY CachePhone20DeviceStruct 作为VALUE
//type CachePhone20DeviceStruct struct {
// AreaServiceID uint32
// AllowCallTime uint8 //允许通话时长,255表示不限制时长
// //Place string //安装位置
// Status bool
//}
/*---------------------------------------------------------------*/
......@@ -28,17 +28,16 @@ func initAreaMapAndCountyAreaMap() {
var areaID uint32
var temp model.CacheBAreaStruct
rows, err := dbcurd.PgDb.Query("SELECT id,county_id,name,longitude,latitude,status FROM b_area") //
defer rows.Close()
if err != nil {
log.Panicln("SelectAreaToMap rows", err)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&areaID, &temp.CountyID, &temp.Name, &temp.Longitude, &temp.Latitude, &temp.Status)
if err != nil {
log.Panicln("SelectAreaToMap rows.Scan", err)
}
fmt.Println(areaID, temp)
AreaMap.Store(areaID, temp)
if temp.CountyID != 0 {
var areaIDList []uint32
......@@ -47,7 +46,6 @@ func initAreaMapAndCountyAreaMap() {
}
areaIDList = append(areaIDList, areaID)
CountyAreaMap.Store(temp.CountyID, areaIDList)
fmt.Println(temp.CountyID, areaIDList)
}
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
......
......@@ -11,29 +11,29 @@ import (
)
func initAreaServiceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin")
var areaID int32
fmt.Println(time.Now(), "cache: initAreaServiceMap begin")
var areaServiceID uint32
var temp AreaServiceStruct
rows, err := dbcurd.PgDb.Query("SELECT id,name,status FROM b_area") //todo
defer rows.Close()
rows, err := dbcurd.PgDb.Query("SELECT id,service_type,area_id,status FROM b_area_service") //
if err != nil {
log.Panicln("SelectAreaToMap rows", err)
log.Panicln("initAreaServiceMap rows", err)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&areaID, &temp.Name, &temp.Status)
err = rows.Scan(&areaServiceID, &temp.ServiceType, &temp.AreaID, &temp.Status)
if err != nil {
log.Panicln("SelectAreaToMap rows.Scan", err)
log.Panicln("initAreaServiceMap rows.Scan", err)
}
phone20DeviceMap.Store(areaID, temp)
areaServiceMap.Store(areaServiceID, temp)
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
logger.Log.Error("rows.Err()",
zap.Error(err),
zap.String("src", "initAreaMap"))
fmt.Println(time.Now(), "initAreaMap rows.Err()", err)
fmt.Println(time.Now(), "initAreaServiceMap rows.Err()", err)
} else {
fmt.Println(time.Now(), "cache: initAreaMap end")
fmt.Println(time.Now(), "cache: initAreaServiceMap end")
}
}
......@@ -58,17 +58,17 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct
var err error
for i := 0; i < 10; i++ {
err = dbcurd.PgDb.QueryRow("SELECT name,status FROM b_area WHERE id=$1",
areaServiceID).Scan(&areaServiceInfo.Name, &areaServiceInfo.Status) //todo
err = dbcurd.PgDb.QueryRow("SELECT service_type,area_id,status FROM b_area_service WHERE id=$1",
areaServiceID).Scan(&areaServiceInfo.ServiceType, &areaServiceInfo.AreaID, &areaServiceInfo.Status)
if err != nil {
if strings.Contains(err.Error(), "no rows in result") {
logger.Log.Error("GetAreaServiceInfo SELECT operator_id,status FROM b_area WHERE id=$1", //todo
logger.Log.Error("GetAreaServiceInfo SELECT service_type,area_id,status FROM b_area_service WHERE id=$1",
zap.Uint32("areaServiceID", areaServiceID),
zap.Error(err),
zap.String("src", "GetAreaServiceInfo"))
return
}
fmt.Println("GetAreaInfo SELECT:", i, err)
fmt.Println("b_area_service SELECT:", i, err)
time.Sleep(3 * time.Millisecond)
continue
}
......
......@@ -11,29 +11,33 @@ import (
"time"
)
func initUCardUserMapAndSiminfoMapNoFamilyNum() {
fmt.Println(time.Now(), "cache: initUCardUserMapAndSiminfoMapNoFamilyNum begin")
//ServiceType uint8 `json:"service" example:"1"` // 服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
//Title string `json:"title" example:"公话机-教1楼3层"` // 显示在第一行 公话机-PlaceUser
//Content string `json:"content" example:"被叫:爸爸 时长:2分"` // 显示在第二行 nickname+talkTime
//Time time.Time `json:"time" example:"2021-10-23 17:00:00"` // 显示在第三行,呼叫起始时间
func initCardUserMapAndSimInfoMapNoFamilyNum() {
fmt.Println(time.Now(), "cache: initCardUserMapAndSimInfoMapNoFamilyNum begin")
var cardUserID uint32
var temp model.CacheCardUserStruct
// rows, err := dbcurd.PgDb.Query("SELECT id,role,name,sex,area_id,grade,class,student_num,first_topup_at is not null FROM u_card_user")
rows, err := dbcurd.PgDb.Query("SELECT id,name,sex,area_id,grade,class,student_num FROM u_card_user WHERE delete_at is null")
defer rows.Close()
if err != nil {
log.Panicln("Select u_card_user To Map rows", err)
}
defer rows.Close()
var simInfo model.CacheSimInfoStruct
for rows.Next() {
err = rows.Scan(&cardUserID, &temp.Name, &temp.Sex, &temp.AreaID, &temp.Grade, &temp.Class, &temp.StuNum)
if err != nil {
log.Panicln("initUCardUserMapAndSiminfoMapNoFamilyNum rows.Scan", err)
log.Panicln("initCardUserMapAndSimInfoMapNoFamilyNum rows.Scan", err)
}
err = dbcurd.PgDb.QueryRow("SELECT sim_id,area_service_id,month_talk_minutes,month_package_minutes,status,expiry_at FROM u_sim_info WHERE card_user_id=$1 AND area_service_id!=0 AND status!=0",
cardUserID).Scan(
// 查对应卡用户的卡信息
err = dbcurd.PgDb.QueryRow("SELECT sim_id,area_service_id,month_talk_minutes,month_package_minutes,status,family_change_count,expiry_at FROM u_sim_info WHERE card_user_id=$1 AND area_service_id!=0 AND status!=0", cardUserID).Scan(
&temp.SimCardID,
&simInfo.AreaServiceID,
&simInfo.MonthTalkMinutes,
&simInfo.MonthPackageMinutes,
&simInfo.Status,
&simInfo.FamilyChangeCount,
&simInfo.ExpiryAt)
if err != nil {
if strings.Contains(err.Error(), "no rows in result") {
......@@ -43,18 +47,45 @@ func initUCardUserMapAndSiminfoMapNoFamilyNum() {
log.Panicln("Select u_sim_info To temp.SimCardID", err)
}
// todo1 考虑校验area_service_id
simInfoMap.Store(temp.SimCardID, simInfo)
simInfo.CardUserID = cardUserID
SimInfoMap.Store(temp.SimCardID, simInfo)
CardUserMap.Store(cardUserID, temp)
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
log.Panicln(time.Now(), "initUCardUserMapAndSiminfoMapNoFamilyNum rows.Err()", err)
log.Panicln(time.Now(), "initCardUserMapAndSimInfoMapNoFamilyNum rows.Err()", err)
}
fmt.Println(time.Now(), "cache: initCardUserMapAndSimInfoMapNoFamilyNum OK")
}
// 将家长学生对应关系写入缓存
func initWechatAndCardUserRelationToWechatCustomerMapAndCardUserMap() {
// 查家长学生对应关系表u_we_card_user表,获得绑定的学生数据
rows, err := dbcurd.PgDb.Query("SELECT we_user_id,card_user_id,master FROM u_we_card_user WHERE delete_at is null order by create_at") //
if err != nil {
log.Panicln("Select u_we_card_user rows", err)
}
defer rows.Close()
fmt.Println(time.Now(), "cache: initUCardUserMapAndSiminfoMapNoFamilyNum OK")
var weUserID uint32
var cUserID uint32
var master bool
for rows.Next() {
err = rows.Scan(&weUserID, &cUserID, &master)
if err != nil {
log.Panicln("Select u_we_card_user rows.Scan", err)
}
InsertNewStudentIDToWechatCustomerMap(weUserID, cUserID, master)
InsertWechatAndCardUserRelationToCardUserMap(weUserID, cUserID, master)
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
log.Panicln(time.Now(), "Select u_we_card_user rows.Err()", err)
}
}
func GetUCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) {
func GetCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) {
if s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
return v, true
......@@ -62,15 +93,88 @@ func GetUCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) {
CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "GetUCardUserInfo"))
zap.String("src", "GetCardUserInfo"))
}
} else {
logger.Log.Error("CardUserMap 有问题,没数据",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "GetUCardUserInfo"))
zap.String("src", "GetCardUserInfo"))
}
var temp model.CacheCardUserStruct
// todo1 再去查一盘库
return temp, false
}
// CheckCardUserMaserAndSlaveWeID 0 没有这个卡用户 1 微信号在这个卡用户里啥都不是 2 主 3 从
func CheckCardUserMaserAndSlaveWeID(cardUserID uint32, weUserID uint32) uint8 {
if s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
if v.MasterWechatUserID == weUserID {
return 1
}
for _, slave := range v.SlaveWechatUserID {
if weUserID == slave {
return 2
}
}
return 0
} else { //类型断言失败
CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "CheckCardUserMaserAndSlaveWeID"))
}
} else {
logger.Log.Error("CardUserMap 有问题,没数据",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "CheckCardUserMaserAndSlaveWeID"))
}
// var temp model.CacheCardUserStruct
// todo1 再去查一盘库
return 0
}
// 并发不安全
func InsertWechatAndCardUserRelationToCardUserMap(weUserID uint32, cardUserID uint32, master bool) bool {
if s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
if master {
if v.MasterWechatUserID != 0 {
logger.Log.Error("CardUserMap 已经有MasterWechatUserID",
zap.Uint32("oldWeUserID", v.MasterWechatUserID),
zap.Uint32("newWeUserID:", weUserID),
zap.String("src", "InsertWechatAndCardUserRelationToCardUserMap"))
}
v.MasterWechatUserID = weUserID
} else {
for _, slaveID := range v.SlaveWechatUserID {
if slaveID == weUserID {
logger.Log.Error("CardUserMap SlaveWechatUserID 已经有了要加入的weUserID",
zap.Uint32("cardUserID", cardUserID),
zap.Reflect("weUserID", weUserID),
zap.String("src", "InsertWechatAndCardUserRelationToCardUserMap"))
return true
}
}
v.SlaveWechatUserID = append(v.SlaveWechatUserID, weUserID)
}
CardUserMap.Store(cardUserID, v)
return true
} else { //类型断言失败
CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "InsertWechatAndCardUserRelationToCardUserMap"))
}
} else {
logger.Log.Error("CardUserMap 有问题,没数据",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "InsertWechatAndCardUserRelationToCardUserMap"))
}
// var temp model.CacheCardUserStruct
// todo1 再去查一盘库
return false
}
package cache
import (
"dc_golang_server_1/data_db_cache/model"
"fmt"
)
//// initCardUserTrendMap 获取学生近20条动态,现在只有通话记录
//func initCardUserTrendMap(){
// fmt.Println(time.Now(), "cache: initCardUserTrendMap begin")
// var cardUserID uint32
// var ok bool
// CardUserMap.Range(func(k, _ interface{}) bool {
// cardUserID , ok = k.(uint32)
// if ok != true {
// log.Panicln(time.Now(), "initCardUserTrendMap k.(uint32) error", k)
// }
// trends := selectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID)
// if trends != nil {
// CardUserTrendMap.Store(cardUserID,trends)
// }
// return true
// })
// fmt.Println(time.Now(), "cache: initCardUserTrendMap OK")
//}
//
//func GetCardUserTrendByCardUserID(cardUserID uint32)(trends []model.CacheCardUserTrendStruct){
//
//}
func InsertCardUserTrendMap(cardUserID uint32, temp *model.CacheCardUserTrendStruct) { // 并发不安全,可改成channel传递
if v, ok := CardUserTrendMap.Load(cardUserID); ok {
if trends, ok := v.([]model.CacheCardUserTrendStruct); ok {
trends = append(trends, *temp)
length := len(trends)
if length > 20 {
trends = trends[length-20 : length]
}
CardUserTrendMap.Store(cardUserID, trends)
} else { // 类型断言错误
fmt.Println("InsertCardUserTrendMap CardUserTrendMap 类型断言错误")
CardUserTrendMap.Delete(cardUserID)
}
}
trends := make([]model.CacheCardUserTrendStruct, 1)
trends[1] = *temp
CardUserTrendMap.Store(cardUserID, trends)
}
......@@ -19,10 +19,10 @@ func initBDistrictMaps() {
ProvinceMap = []model.CacheBDistrictStruct{} //先清空原来的缓存
var temp model.CacheBDistrictStruct
rows, err := dbcurd.PgDb.Query("SELECT id,name,initial FROM b_district WHERE level=1 ORDER BY initial,sort")
defer rows.Close()
if err != nil {
log.Panicln("ProvinceMap SELECT b_district rows", err)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &temp.Initial)
if err != nil {
......@@ -52,10 +52,10 @@ func selectToDistrictMap(level uint8, tempMap *sync.Map) bool {
var parentID uint32
var temp model.CacheBDistrictStruct
rows, err := dbcurd.PgDb.Query("SELECT id,name,parent_id,initial FROM b_district WHERE level=$1 ORDER BY initial,sort", level)
defer rows.Close()
if err != nil {
log.Panicln("SELECT b_district rows", err, level)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &parentID, &temp.Initial)
if err != nil {
......
......@@ -2,6 +2,7 @@ package cache
import (
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -13,14 +14,14 @@ import (
func initPhone20DeviceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin")
var devID uint32
var temp Phone20DeviceStruct
rows, err := dbcurd.PgDb.Query("SELECT id,area_service_id,allow_call_time,status FROM d_device")
defer rows.Close()
var temp model.CachePhone20DeviceStruct
rows, err := dbcurd.PgDb.Query("SELECT device_id,area_service_id,allow_call_time,status,place_user FROM d_phone20")
if err != nil {
log.Panicln("SelectDeviceToMap rows", err)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&devID, &temp.AreaServiceID, &temp.AllowCallTime, &temp.Status)
err = rows.Scan(&devID, &temp.AreaServiceID, &temp.AllowCallTime, &temp.Status, &temp.PlaceUser)
if err != nil {
log.Panicln("SelectDeviceToMap rows.Scan", err)
}
......@@ -37,9 +38,9 @@ func initPhone20DeviceMap() {
}
}
func GetPhone20Info(devID uint32) Phone20DeviceStruct {
func GetPhone20Info(devID uint32) model.CachePhone20DeviceStruct {
if info, ok := phone20DeviceMap.Load(devID); ok { //map有
if v, ok2 := info.(Phone20DeviceStruct); ok2 { //类型断言正确
if v, ok2 := info.(model.CachePhone20DeviceStruct); ok2 { //类型断言正确
return v //,true
} else { //类型断言失败
phone20DeviceMap.Delete(devID)
......@@ -48,7 +49,7 @@ func GetPhone20Info(devID uint32) Phone20DeviceStruct {
zap.String("src", "getDeviceInfo"))
}
}
var temp Phone20DeviceStruct
var temp model.CachePhone20DeviceStruct
var err error
for i := 0; i < 5; i++ {
err = dbcurd.PgDb.QueryRow("SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE device_id=$1",
......
package cache
import (
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
"log"
"time"
)
func initFamilyNumToSimInfoMap() {
fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap begin")
var key string
var value model.CacheSimInfoStruct
var ok bool
SimInfoMap.Range(func(k, v interface{}) bool {
key, ok = k.(string)
if ok != true {
log.Panicln(time.Now(), "initFamilyNumToSimInfoMap k.(string) error", k, v)
}
value, ok = v.(model.CacheSimInfoStruct)
if ok != true {
log.Panicln(time.Now(), "initFamilyNumToSimInfoMap v.(model.CacheSimInfoStruct) error", k, v)
}
value.FamilyNum = dbcurd.SelectUSimFamilyNumBySimID(key)
SimInfoMap.Store(key, value)
return true
})
fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap end")
}
func GetSimInfo(cardId string) model.CacheSimInfoStruct {
if s, ok := simInfoMap.Load(cardId); ok { // map有
if family, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确
return family
func GetSimInfo(simId string) model.CacheSimInfoStruct {
if s, ok := SimInfoMap.Load(simId); ok { // map有
if info, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确
return info
} else { //类型断言失败
simInfoMap.Delete(cardId)
logger.Log.Error("simInfoMap 类型断言错误",
zap.String("cardId", cardId),
SimInfoMap.Delete(simId)
logger.Log.Error("SimInfoMap 类型断言错误",
zap.String("simId", simId),
zap.String("src", "GetSimInfo"))
}
} else {
logger.Log.Warn("simInfoMap 里面居然没有数据",
zap.String("cardId", cardId),
logger.Log.Warn("SimInfoMap 里面居然没有数据",
zap.String("simId", simId),
zap.String("src", "GetSimInfo"))
}
......@@ -36,6 +55,41 @@ func GetSimInfo(cardId string) model.CacheSimInfoStruct {
}
// AddSimMonthTalkMinutes 缓存里增加本月通话分钟数
func AddSimMonthTalkMinutes(AreaId int32, CardId string) {
func AddSimMonthTalkMinutes(simId string, min uint16) {
if s, ok := SimInfoMap.Load(simId); ok { // map有
if info, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确
info.MonthTalkMinutes += min
SimInfoMap.Store(simId, info)
if info.MonthTalkMinutes > info.MonthPackageMinutes {
logger.Log.Error("info.MonthTalkMinutes > info.MonthPackageMinutes",
zap.String("simId", simId),
zap.String("src", "AddSimMonthTalkMinutes"))
}
return
} else { //类型断言失败
SimInfoMap.Delete(simId)
logger.Log.Error("SimInfoMap 类型断言错误",
zap.String("simId", simId),
zap.String("src", "AddSimMonthTalkMinutes"))
}
} else {
logger.Log.Error("SimInfoMap 里面居然没有数据",
zap.String("simId", simId),
zap.String("src", "AddSimMonthTalkMinutes"))
}
var info model.CacheSimInfoStruct
if dbcurd.SelectUSimInfoBySimID(simId, &info) == false {
logger.Log.Error("严重错误:卡号来账单居然没查到卡信息",
zap.String("simId", simId),
zap.Uint16("min", min),
zap.String("src", "AddSimMonthTalkMinutes"))
fmt.Println("严重错误:AddSimMonthTalkMinutes卡号来账单居然没查到卡信息", simId, min)
return
}
info.FamilyNum = dbcurd.SelectUSimFamilyNumBySimID(simId)
SimInfoMap.Store(simId, info)
AddSimMonthTalkMinutes(simId, min)
}
// 学生绑卡时,如果原来绑卡的学生已经删除,则还是可以绑,若里面有正常的学生,则不准绑?
......@@ -14,99 +14,38 @@ func initWechatCustomerMap() {
fmt.Println(time.Now(), "cache: initWechatCustomerMap begin")
var weUserID uint32
var unionID string
var temp model.CacheUWeCustomerStruct
// 1. 查u_we_customer表获得基础数据
var temp model.CacheWeCustomerStruct
// 查u_we_customer表获得基础数据
rows, err := dbcurd.PgDb.Query("SELECT id,unionid,phone,nickname,avatarurl,test_role FROM u_we_customer") //
// defer rows.Close()
if err != nil {
rows.Close()
log.Panicln("SelectWechatCustomerMap rows", err)
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&weUserID, &unionID, &temp.WePhone, &temp.Nickname, &temp.AvatarURL, &temp.TestRole)
if err != nil {
rows.Close()
log.Panicln("SelectWechatCustomerMap rows.Scan", err)
}
if len(unionID) > 0 {
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, temp)
}
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
rows.Close()
log.Panicln(time.Now(), "initWechatCustomerMap rows.Err()", err)
}
rows.Close()
// 2. 查家长学生对应关系表u_we_card_user表,获得绑定的学生数据
rows, err = dbcurd.PgDb.Query("SELECT we_user_id,card_user_id,master FROM u_we_card_user order by create_at") //
defer rows.Close()
if err != nil {
log.Panicln("Select u_we_card_user rows", err)
}
var cUserID uint32
var master bool
for rows.Next() {
err = rows.Scan(&weUserID, &cUserID, &master)
if err != nil {
log.Panicln("Select u_we_card_user rows.Scan", err)
}
if master {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if value, ok := v.(model.CacheUWeCustomerStruct); ok {
value.MasterCardUserID = append(value.MasterCardUserID, cUserID)
WechatCustomerMap.Store(weUserID, value)
} else {
logger.Log.Error("u_we_card_user 表中的 we_user_id,在wechatCustomerMap类型断言错误",
zap.Uint32("weUserID", weUserID),
zap.Uint32("cUserID", cUserID),
zap.Bool("master", master),
zap.String("src", "initWechatCustomerMap"))
}
} else {
logger.Log.Error("u_we_card_user 表中的 we_user_id,在u_we_customer表中没有",
zap.Uint32("weUserID", weUserID),
zap.Uint32("cUserID", cUserID),
zap.Bool("master", master),
zap.String("src", "initWechatCustomerMap"))
}
} else {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if value, ok := v.(model.CacheUWeCustomerStruct); ok {
value.SlaveCardUserID = append(value.SlaveCardUserID, cUserID)
WechatCustomerMap.Store(weUserID, value)
} else {
logger.Log.Error("u_we_card_user 表中的 we_user_id,在wechatCustomerMap类型断言错误",
zap.Uint32("weUserID", weUserID),
zap.Uint32("cUserID", cUserID),
zap.Bool("master", master),
zap.String("src", "initWechatCustomerMap"))
}
} else {
logger.Log.Error("u_we_card_user 表中的 we_user_id,在u_we_customer表中没有",
zap.Uint32("weUserID", weUserID),
zap.Uint32("cUserID", cUserID),
zap.Bool("master", master),
zap.String("src", "initWechatCustomerMap"))
}
logger.Log.Error("initWechatCustomerMap 有weUserID空数据")
}
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
log.Panicln(time.Now(), "Select u_we_card_user rows.Err()", err)
log.Panicln(time.Now(), "initWechatCustomerMap rows.Err()", err)
}
fmt.Println(time.Now(), "cache: initWechatCustomerMap OK")
}
func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
var data model.CacheUWeCustomerStruct
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok {
return data.TokenCreatTime //正常情况
} else {
logger.Log.Error("WechatCustomerMap 类型断言错误",
......@@ -123,9 +62,9 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
}
func GetWechatCustomerTestRole(userID uint32) (bool, bool) {
var data model.CacheUWeCustomerStruct
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(userID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok {
return data.TestRole, true //正常情况
} else {
logger.Log.Error("WechatCustomerMap 类型断言错误",
......@@ -158,10 +97,10 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 {
return 0
}
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheUWeCustomerStruct, bool) {
var data model.CacheUWeCustomerStruct
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheWeCustomerStruct, bool) {
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok {
if newTime > 0 {
data.TokenCreatTime = newTime
WechatCustomerMap.Store(weUserID, data)
......@@ -190,7 +129,8 @@ func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64)
return data, true
}
func InsertWechatCustomerMap(unionID string, userInfo *model.CacheUWeCustomerStruct) uint32 {
// InsertWechatCustomerMap 注意:并发不安全
func InsertWechatCustomerMap(unionID string, userInfo *model.CacheWeCustomerStruct) uint32 {
userID, res := dbcurd.InsertUWeCustomerUnionID(unionID)
if res == dbcurd.InsertSysErr {
return 0
......@@ -206,11 +146,11 @@ func InsertWechatCustomerMap(unionID string, userInfo *model.CacheUWeCustomerStr
return userID
}
// InsertNewStudentIDToWechatCustomerMap 缓存定制方法:微信用户增加/绑定卡用户
// InsertNewStudentIDToWechatCustomerMap 注意这里并发不安全
func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool {
var data model.CacheUWeCustomerStruct
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok {
if master {
data.MasterCardUserID = append(data.MasterCardUserID, cardUserID)
} else {
......@@ -232,6 +172,53 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m
// 再查一遍库,库里面已经添加了学生数据了,就不用再添加了
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data)
if len(unionID) == 0 {
logger.Log.Error("数据库表u_we_customer 数据有问题",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID))
return false
}
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, data)
return true
}
// DeleteAStudentIDInWechatCustomerMap 注意这里并发并不安全
func DeleteAStudentIDInWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool {
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok {
if master {
for i, cID := range data.MasterCardUserID {
if cID == cardUserID {
data.MasterCardUserID = append(data.MasterCardUserID[:i], data.MasterCardUserID[i+1:]...)
}
}
} else {
for i, cID := range data.SlaveCardUserID {
if cID == cardUserID {
data.SlaveCardUserID = append(data.SlaveCardUserID[:i], data.SlaveCardUserID[i+1:]...)
}
}
}
WechatCustomerMap.Store(weUserID, data)
return true //正常的话就该这里
} else {
logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID))
// todoN 考虑查一遍库
}
} else {
logger.Log.Error("WechatCustomerMap 没数据",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID))
}
// 再查一遍库,库里面已经添加了学生数据了,就不用再添加了
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data)
if len(unionID) == 0 {
logger.Log.Error("数据库表u_we_customer 数据有问题",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID))
return false
}
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
......
package dbcurd
//CREATE TABLE IF NOT EXISTS public.d_device
//(
//id bigint NOT NULL,
//area_id integer,
//service_code smallint,
//version_code character varying(3) COLLATE pg_catalog."default",
//place character varying(32) COLLATE pg_catalog."default",
//rate_id integer,
//status boolean,
//create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
//update_at timestamp without time zone,
//CONSTRAINT d_device_pkey PRIMARY KEY (id)
//)
......@@ -29,7 +29,7 @@ func InsertDevCommandErr(devId uint32, ciphertext string, errMsg string) {
if err == nil {
return
}
fmt.Println("InsertDevCommandErr:", i, err)
fmt.Println("硬件问题 InsertDevCommandErr:", i, err)
time.Sleep(3 * time.Second)
}
logger.Log.Error("InsertDevCommandErr Err",
......
......@@ -30,7 +30,7 @@ type TableDevHexCommandRecord struct {
createAt time.Time
}
func InsertDevCommandRecord(insertData TableDevHexCommandRecord) {
func InsertDevCommandRecord(insertData *TableDevHexCommandRecord) {
var err error
for i := 0; i < 10; i++ {
// _, err = StmtDevHexRecord.Exec(rData.DevID, rData.TimeUtc, strconv.FormatUint(uint64(rData.CtrlCode), 16), rData.Length, hex.EncodeToString(rData.Data[:rData.Length]), ciphertext, direction)
......
......@@ -28,7 +28,7 @@ type TableDevHexResetRecord struct {
createAt time.Time
}
func InsertDevResetRecord(insertData TableDevHexResetRecord) {
func InsertDevResetRecord(insertData *TableDevHexResetRecord) {
var err error
for i := 0; i < 100; i++ {
_, err = stmtInsertDevResetRecord.Exec(
......
package dbcurd
import (
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
"strconv"
"strings"
"time"
)
type InsertTableUCallRecordStruct struct {
......@@ -19,9 +23,10 @@ type InsertTableUCallRecordStruct struct {
AreaServiceID uint32
OperatorId uint32
Status uint8
PlaceUser string
}
func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) uint8 { //0 成功 1 唯一约束重复 9 系统繁忙
func InsertUCallRecordAndUpdateUSimInfo(insertData *InsertTableUCallRecordStruct) uint8 { //0 成功 1 唯一约束重复 9 系统繁忙
tx, err := PgDb.Begin()
if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():",
......@@ -30,7 +35,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
}
defer clearTransaction(tx)
//先InsertUCallRecord
_, err = tx.Exec("INSERT INTO u_call_record(card_user_id,device_id,call_start_at,card_user_name,sim_id,called_number,called_nickname,talk_time,area_name,area_service_id,operator_id,status)VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)",
_, err = tx.Exec("INSERT INTO u_call_record(card_user_id,device_id,call_start_at,card_user_name,sim_id,called_number,called_nickname,talk_time,area_name,area_service_id,operator_id,status,place_user)VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)",
insertData.CardUserId,
insertData.DeviceId,
insertData.CallStartAt,
......@@ -43,6 +48,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
insertData.AreaServiceID,
insertData.OperatorId,
insertData.Status,
insertData.PlaceUser,
)
if err != nil {
if strings.Contains(err.Error(), "duplicate key value") { //todoN 这里应考虑去查出来看看内容是不是一样的
......@@ -60,7 +66,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
//}
//fmt.Println(rowAffected)
_, err = tx.Exec("UPDATE u_sim_info SET total_talk_minutes=total_talk_minutes+$1 WHERE card_id=$2", (insertData.TalkTime+59)/60, insertData.SimID)
_, err = tx.Exec("UPDATE u_sim_info SET total_talk_minutes=total_talk_minutes+$1,month_talk_minutes=month_talk_minutes+$1 WHERE sim_id=$2", (insertData.TalkTime+59)/60, insertData.SimID)
if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo UPDATE u_sim_info:",
zap.Error(err))
......@@ -81,3 +87,35 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
return InsertOK
}
func SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID uint32) (trends []model.CacheCardUserTrendStruct) {
rows, err := PgDb.Query("SELECT call_start_at, called_nickname, talk_time, place_user FROM u_call_record WHERE card_user_id=$1 ORDER BY id DESC LIMIT 20", cardUserID)
if err != nil {
fmt.Println("SELECT call_start_at, called_nickname, talk_time, place_user FROM u_call_record WHERE card_user_id=$1 ORDER BY id LIMIT 20", err)
return
}
defer rows.Close()
var place string
var nickname string
var talkTime int
var startAt time.Time
for rows.Next() {
err = rows.Scan(&startAt, &nickname, &talkTime, &place)
if err != nil {
fmt.Println("selectCardUserTrendsLimit20FromUCallRecordByCardUserID rows", err)
return
}
trends = append(trends, model.CacheCardUserTrendStruct{
ServiceType: 1,
Title: "公话机-" + place,
Content: "被叫:" + nickname + " 时长:" + strconv.Itoa((talkTime+59)/60) + "分",
Time: startAt.Format("2006-01-02 15:04:05"),
})
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
fmt.Println(time.Now(), "selectCardUserTrendsLimit20FromUCallRecordByCardUserID rows.Err()", err)
}
return
}
......@@ -3,6 +3,7 @@ package dbcurd
import (
"dc_golang_server_1/logger"
"go.uber.org/zap"
"time"
)
//id integer NOT NULL DEFAULT nextval('u_card_user_id_seq'::regclass),
......@@ -16,7 +17,7 @@ import (
//create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
//first_topup_at timestamp without time zone,
type InsertTableUserCardUserStruct struct {
type InsertTableUCardUserStruct struct {
Role uint8 `swaggerignore:"true"` // 后台添加选填,学生名字,角色:0学生,1教师,2职工
Name string `json:"name" example:"汤圆"` // 必填,学生名字,maxLen=16
AreaID uint32 `json:"areaID" example:"1"` // 必填,校区ID
......@@ -26,8 +27,8 @@ type InsertTableUserCardUserStruct struct {
StuNum string `json:"stuNum,omitempty"` // 选填,学号,字符串,maxLen=32
}
// InsertUserCardUserAndUserWeCardUser 事务处理两张表
func InsertUserCardUserAndUserWeCardUser(insertData InsertTableUserCardUserStruct, weUserID uint32) (cardUserID uint32) {
// InsertUCardUserAndUserWeCardUser 事务处理两张表
func InsertUCardUserAndUserWeCardUser(insertData *InsertTableUCardUserStruct, weUserID uint32) (cardUserID uint32) {
tx, err := PgDb.Begin()
if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():",
......@@ -46,23 +47,57 @@ func InsertUserCardUserAndUserWeCardUser(insertData InsertTableUserCardUserStruc
insertData.StuNum,
).Scan(&cardUserID)
if err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser INSERT u_card_user:",
logger.Log.Error("InsertUCardUserAndUserWeCardUser INSERT u_card_user:",
zap.Error(err))
return
}
_, err = tx.Exec("INSERT INTO u_we_card_user(we_user_id,card_user_id,master)VALUES($1,$2,true)", weUserID, cardUserID)
if err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser INSERT u_we_card_user:",
logger.Log.Error("InsertUCardUserAndUserWeCardUser INSERT u_we_card_user:",
zap.Error(err))
return 0
}
if err = tx.Commit(); err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser Commit:",
logger.Log.Error("InsertUCardUserAndUserWeCardUser Commit:",
zap.Error(err))
return 0
}
return
}
func UpdateUCardUserAndUWeCardUserDeleteAt(id uint32) bool {
tx, err := PgDb.Begin()
if err != nil {
logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt PgDb.Begin():",
zap.Error(err))
return false
}
defer clearTransaction(tx)
deleteAt := time.Now()
_, err = tx.Exec("UPDATE u_card_user SET delete_at=$1 WHERE id=$2", deleteAt, id)
if err != nil {
logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt 1",
zap.Uint32("id", id),
zap.Error(err))
return false
}
_, err = tx.Exec("UPDATE u_we_card_user SET delete_at=$1 WHERE card_user_id=$2", deleteAt, id)
if err != nil {
logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt 2",
zap.Uint32("card_user_id", id),
zap.Error(err))
return false
}
if err = tx.Commit(); err != nil {
logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt Commit:",
zap.Error(err))
return false
}
return true
}
package dbcurd
import (
"time"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"go.uber.org/zap"
)
//CREATE TABLE IF NOT EXISTS public.u_sim_family_num
//(
//card_id character varying(32) COLLATE pg_catalog."default" NOT NULL,
//phone character varying(12) COLLATE pg_catalog."default",
//nickname character varying(32) COLLATE pg_catalog."default",
//area_id integer NOT NULL,
//create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
//CONSTRAINT u_sim_family_num_pkey PRIMARY KEY (card_id, area_id)
//)
func SelectUSimFamilyNumBySimID(simID string) (familyNumbers []model.CacheFamilyOnePerson) {
var onePerson model.CacheFamilyOnePerson
familyNumbers = make([]model.CacheFamilyOnePerson, 0)
rows, err := PgDb.Query("SELECT phone,nickname FROM u_sim_family_num WHERE sim_id=$1 order by create_at", simID)
if err != nil {
logger.Log.Error("SelectUSimFamilyNumBySimID 1",
zap.String("simID", simID),
zap.Error(err))
return
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(&onePerson.Phone, &onePerson.Nickname)
if err != nil {
logger.Log.Error("SelectUSimFamilyNumBySimID 2",
zap.String("simID", simID),
zap.Error(err))
continue
}
familyNumbers = append(familyNumbers, onePerson)
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
logger.Log.Error("SelectUSimFamilyNumBySimID 3",
zap.String("simID", simID),
zap.Error(err))
}
type TableUserSimFamilyNum struct {
CardId string //character varying(32) COLLATE pg_catalog."default",
Phone string //character varying(12) COLLATE pg_catalog."default",
Nickname string //character varying(32) COLLATE pg_catalog."default",
AreaId int32
CreateAt time.Time //timestamp without time zone DEFAULT CURRENT_TIMESTAMP
return
}
package dbcurd
//CREATE TABLE IF NOT EXISTS public.u_sim_info
//(
//card_id character varying(20) COLLATE pg_catalog."default",
//total_talk_minutes integer,
//month_talk_minutes integer,
//month_package_minutes integer,
//status smallint
//)
import (
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
"strings"
"time"
)
//type TableUserSimInfo struct {
// CardID string
//
//}
func SelectUSimInfoBySimID(simId string, cacheData *model.CacheSimInfoStruct) bool {
var err error
for i := 0; i < 5; i++ {
err = PgDb.QueryRow("SELECT card_user_id,area_service_id,month_talk_minutes,month_package_minutes,status,expiry_at FROM u_sim_info WHERE sim_id=$1 AND area_service_id!=0 AND status!=0",
simId).Scan(
&cacheData.CardUserID,
&cacheData.AreaServiceID,
&cacheData.MonthTalkMinutes,
&cacheData.MonthPackageMinutes,
&cacheData.Status,
&cacheData.ExpiryAt)
if err == nil {
return true
}
if strings.Contains(err.Error(), "no rows in result") {
return false
}
fmt.Println("SelectUSimInfoBySimID:", i, err)
time.Sleep(2 * time.Millisecond)
}
logger.Log.Error("SelectUSimInfoBySimID Err",
zap.Error(err))
return false
}
package dbcurd
// InsertOrUpdateUWeCardUserSlave 副家长绑定学生
func InsertOrUpdateUWeCardUserSlave(weUserID, cardUserID uint32) bool {
_, err := PgDb.Exec("INSERT INTO u_we_card_user(we_user_id,card_user_id,master)VALUES($1,$2,false)ON CONFLICT ON CONSTRAINT u_we_card_user_pkey DO UPDATE SET delete_at=null,master=false", weUserID, cardUserID)
if err == nil {
return true
}
return false
}
......@@ -44,7 +44,7 @@ func InsertUWeCustomerUnionID(unionID string) (id uint32, res uint8) {
return 0, InsertSysErr
}
func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.CacheUWeCustomerStruct) (userID uint32) {
func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.CacheWeCustomerStruct) (userID uint32) {
// 1. 查u_we_customer表获得基础数据
err := PgDb.QueryRow("SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1", unionID).Scan(
&userID,
......@@ -60,7 +60,6 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
}
// 2. 查u_we_card_user表,获得绑定的学生数据
rows, err := PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
defer rows.Close()
if err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 2",
zap.Uint32("userID", userID),
......@@ -68,6 +67,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
fmt.Println(err)
return 0
}
defer rows.Close()
var cUserID uint32
var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0]
......@@ -95,7 +95,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
return
}
func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheUWeCustomerStruct) (unionID string) {
func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheWeCustomerStruct) (unionID string) {
// 1. 查u_we_customer表获得基础数据
err := PgDb.QueryRow("SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1", userID).Scan(
&unionID,
......@@ -111,13 +111,13 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheU
}
// 2. 查u_we_card_user表,获得绑定的学生数据
rows, err := PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
defer rows.Close()
if err != nil {
logger.Log.Error("SelectUWeCustomerByUserIDToCacheModel 2",
zap.Uint32("userID", userID),
zap.Error(err))
return ""
}
defer rows.Close()
var cUserID uint32
var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0]
......
package model
import "time"
type CacheBDistrictStruct struct {
Id uint32 `json:"id" example:"1"`
Name string `json:"name" example:"四川省"`
Initial string `json:"initial" example:"S"`
}
type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出,后续再加支付信息
Name string
Longitude uint32
Latitude uint32
CountyID uint32
AreaService []uint32
Status uint8 //校区状态 0 不展示 1展示 2测试校区
}
type CacheWeCustomerStruct struct {
TokenCreatTime int64
TestRole bool // 测试用户(可看到测试校区)
WePhone string // 手机号
Nickname string // 微信昵称
AvatarURL string // 头像链接
MasterCardUserID []uint32 // 自己创建的学生用户
SlaveCardUserID []uint32 // 被邀请查看的学生用户
}
type CacheCardUserStruct struct {
MasterWechatUserID uint32
SlaveWechatUserID []uint32
// Role uint8 //角色0学生,1教师,2职工,default0
AreaID uint32
Name string
Sex uint8 //0,无信息,1女,2男
// Birthday
Grade int8
Class int8
StuNum string
//Recharge bool //是否充过值
SimCardID string
LocationCardID uint32
IcCardID uint32
}
type CacheSimInfoStruct struct {
CardUserID uint32 `json:"-" swaggerignore:"true"` //卡用户ID
AreaServiceID uint32 `json:"-" swaggerignore:"true"`
Status uint8 `json:"status"` //0无数据 1 正常使用 2 已挂失
MonthTalkMinutes uint16 `json:"monthMin"` // 本月已使用分钟数
MonthPackageMinutes uint16 `json:"monthPack"` // 月套餐分钟数
ExpiryAt time.Time `json:"expiryAt"`
FamilyNum []CacheFamilyOnePerson `json:"family"` // 亲情号列表
FamilyChangeCount uint8 `json:"changeable"` // 本月可修改亲情号次数
}
type CacheFamilyOnePerson struct {
Phone string `json:"phone"`
Nickname string `json:"name"`
}
type CachePhone20DeviceStruct struct {
AreaServiceID uint32
AllowCallTime uint8 //允许通话时长,255表示不限制时长
PlaceUser string //位置,家长微信看到的
Status bool
}
type CacheCardUserTrendStruct struct {
ServiceType uint8 `json:"service" example:"1"` // 服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
Title string `json:"title" example:"公话机-教1楼3层"` // 显示在第一行 公话机-PlaceUser
Content string `json:"content" example:"被叫:爸爸 时长:2分"` // 显示在第二行 nickname+talkTime
Time string `json:"time" example:"2021-10-23 17:00:00"` // 显示在第三行,呼叫起始时间
}
File added
......@@ -37,7 +37,7 @@ type HexData struct {
}
func /*(d *DCLongTCPHex)*/ insertDevHexCommandRecord(data *HexData, ciphertext string, direction uint8) {
go dbcurd.InsertDevCommandRecord(dbcurd.TableDevHexCommandRecord{
go dbcurd.InsertDevCommandRecord(&dbcurd.TableDevHexCommandRecord{
DevID: data.DevID,
DevUtc: data.TimeUtc,
CtrlCode: strconv.FormatUint(uint64(data.CtrlCode), 16),
......
......@@ -3,6 +3,7 @@ package dcphone20
import (
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/devproduct"
"dc_golang_server_1/logger"
"fmt"
......@@ -357,7 +358,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
data.Length = uint8(len(data.Data))
return
}
if areaService.Status == 0 || areaService.ServiceID > 2 {
if areaService.Status == 0 || areaService.ServiceType > 2 {
data.Data[0] = 0xff
errMessage := enc.ConvertString("该区域暂未开通公话业务")
data.Data = append(data.Data, errMessage...)
......@@ -402,7 +403,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
} //用户卡暂停使用
// 服务已过期
if time.Now().Before(s.ExpiryAt) {
if time.Now().After(s.ExpiryAt) {
data.Data[0] = 0xff
errMessage := enc.ConvertString("卡已过期 请续费")
data.Data = append(data.Data, errMessage...)
......@@ -469,18 +470,18 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
if data.Length == 20 {
data.CtrlCode = ctrlCode | 0x80
enc := mahonia.NewEncoder("gbk")
data.Data = append(data.Data, 0xff)
// 1.根据设备编号查status和AreaServiceID
v := cache.GetPhone20Info(data.DevID)
if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册
data.Data[0] = 0xff
data.Data = append(data.Data, 0xff)
errMessage := enc.ConvertString("话机设备未注册")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
} // 后台没添加该设备,返回显示 话机设备未注册
if v.Status == false { //设备已停用,返回显示 设备暂停使用
data.Data[0] = 0xff
data.Data = append(data.Data, 0xff)
errMessage := enc.ConvertString("设备暂停使用")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
......@@ -489,15 +490,15 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// 2.根据IccID查卡信息
s := cache.GetSimInfo(string(data.Data))
data.Data = append(data.Data, 0xff)
if s.AreaServiceID != v.AreaServiceID { // 这张卡不属于这个校区服务
errMessage := enc.ConvertString("此卡在本设备不可用")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
logger.Log.Warn("卡绑定的校区服务与话机不符",
zap.String("Src", "TCP-SERVER-response"),
zap.String("IccID", string(data.Data[1:])),
zap.Uint32("DevID", data.DevID),
zap.Uint8s("RecvData", data.Data))
zap.String("IccID", string(data.Data[:20])),
zap.Uint32("DevID", data.DevID))
return
}
if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码
......@@ -519,16 +520,20 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
return
} // 卡未绑定
if time.Now().Before(s.ExpiryAt) { // 服务已过期
if time.Now().After(s.ExpiryAt) { // 服务已过期
errMessage := enc.ConvertString("卡已过期 请续费")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
errMessage := fmt.Sprintf("月套餐分钟数:%3d本月已拨打:%3d分服务到期时间: %s",
var temp uint16
if s.MonthTalkMinutes < s.MonthPackageMinutes {
temp = s.MonthPackageMinutes - s.MonthTalkMinutes
}
errMessage := fmt.Sprintf("月套餐:%3d分钟 本月剩余:%3d分钟服务到期时间: %s",
s.MonthPackageMinutes,
s.MonthTalkMinutes,
temp,
s.ExpiryAt.Format("2006-01-02"))
data.Data = append(data.Data, enc.ConvertString(errMessage)...)
data.Length = uint8(len(data.Data))
......@@ -543,42 +548,70 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
case 0x64: // 上报已读留言
data.CtrlCode = ctrlCode | 0x80
case 0x62: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID
if data.Length > 27 { //todo
//devInfo := cache.GetDeviceInfo(data.DevID)
//var areaInfo cache.CacheBAreaStruct
//if devInfo.AreaID > 0 {
// areaInfo = cache.GetAreaInfo(devInfo.AreaID)
//}
//familyInfo := cache.GetSimFamilyNum(devInfo.AreaID,string(data.Data[1:21]))
//calledNum := string(data.Data[27:])
//var nickname string
//for i:=0;i < len(familyInfo.Family);i++{
// if calledNum == familyInfo.Family[i].Phone {
// nickname = familyInfo.Family[i].Nickname
// break
// }
//}
//// 以事务方式存2张表
//if result := dbcurd.InsertUCallRecordAndUpdateUSimInfo(dbcurd.InsertTableUCallRecordStruct{
// //CustomerId:
// //CardUserId:
// //CardUserName:
// CardID: string(data.Data[1:21]),
// CardType:0,
// CalledNumber: calledNum,
// CalledNickname: nickname,
// CallStartAt: time.Unix(int64(data.Data[21]) + int64(data.Data[22])<<8 + int64(data.Data[23])<<16 + int64(data.Data[24])<<24,0).Format("2006-01-02 15:04:05"),
// TalkTime: int16(data.Data[25]) + int16(data.Data[26]<<8),
// AreaId: devInfo.AreaID,
// OperatorId: areaInfo.OperatorID,
// DeviceId: data.DevID,
// Status: data.Data[0],
//});result > 1 {
// return
//} else if result == 0 { //扣套餐分钟数
//
//}
data.CtrlCode = ctrlCode | 0x80
if data.Length > 27 {
iccID := string(data.Data[0:20])
// 1. 通过IccID查card_user_id和area_service_id
simInfo := cache.GetSimInfo(iccID)
var areaServiceInfo cache.AreaServiceStruct
// 2. 通过area_service_id查areaID
if simInfo.AreaServiceID > 0 {
areaServiceInfo = cache.GetAreaServiceInfo(simInfo.AreaServiceID)
}
// 通过areaID查areaName
var areaName string
if areaServiceInfo.AreaID > 0 {
areaName = cache.GetAreaMapName(areaServiceInfo.AreaID, true)
}
// 3. 通过card_user_id查name
var cardUserInfo model.CacheCardUserStruct
if simInfo.CardUserID > 0 {
cardUserInfo, _ = cache.GetCardUserInfo(simInfo.CardUserID)
}
// 通过simInfo查出called_nickname
calledNum := string(data.Data[27:])
var nickname string
for i := 0; i < len(simInfo.FamilyNum); i++ {
if calledNum == simInfo.FamilyNum[i].Phone {
nickname = simInfo.FamilyNum[i].Nickname
break
}
}
talkTime := uint16(data.Data[24]) + uint16(data.Data[25])<<8
// 以事务方式存2张表
if result := dbcurd.InsertUCallRecordAndUpdateUSimInfo(&dbcurd.InsertTableUCallRecordStruct{
CardUserId: simInfo.CardUserID,
DeviceId: data.DevID,
CallStartAt: time.Unix(int64(data.Data[20])+int64(data.Data[21])<<8+int64(data.Data[22])<<16+int64(data.Data[23])<<24, 0).Format("2006-01-02 15:04:05"),
CardUserName: cardUserInfo.Name,
SimID: iccID,
CalledNumber: calledNum,
CalledNickname: nickname,
TalkTime: talkTime,
AreaName: areaName,
AreaServiceID: simInfo.AreaServiceID,
OperatorId: 1, // todo
Status: data.Data[26],
PlaceUser: "", // todo
}); result == dbcurd.InsertDuplicate {
data.CtrlCode = ctrlCode | 0x80
fmt.Println("通话记录重复")
return
} else if result == dbcurd.InsertOK {
// todo 缓存添加学生动态
// 缓存扣套餐分钟数
if talkTime > 0 {
cache.AddSimMonthTalkMinutes(iccID, (talkTime+59)/60)
}
data.CtrlCode = ctrlCode | 0x80
}
} else {
data.CtrlCode = ctrlCode | 0x80 //还是回硬件
logger.Log.Error("data.Length error",
......@@ -647,7 +680,7 @@ func insertDevHexResetRecord(data *devproduct.HexData) {
}
firmwareVersion = strTemp[2] //
}
go dbcurd.InsertDevResetRecord(dbcurd.TableDevHexResetRecord{
go dbcurd.InsertDevResetRecord(&dbcurd.TableDevHexResetRecord{
DevId: data.DevID,
DevUtc: data.TimeUtc,
ResetReason: resetReason,
......
......@@ -313,7 +313,7 @@ var doc = `{
"tags": [
"家长微信"
],
"summary": "通过邀请码绑定学生",
"summary": "通过邀请码绑定学生 [complete]",
"parameters": [
{
"type": "string",
......@@ -327,7 +327,7 @@ var doc = `{
"0": {
"description": "学生信息",
"schema": {
"$ref": "#/definitions/api_we.bindCardUserRes"
"$ref": "#/definitions/api_we.BindCardUserRes"
}
},
"30": {
......@@ -552,7 +552,7 @@ var doc = `{
"tags": [
"家长微信"
],
"summary": "创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)",
"summary": "创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]",
"parameters": [
{
"description": "学生信息",
......@@ -560,7 +560,7 @@ var doc = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbcurd.InsertTableUserCardUserStruct"
"$ref": "#/definitions/dbcurd.InsertTableUCardUserStruct"
}
}
],
......@@ -575,6 +575,38 @@ var doc = `{
}
},
"/we/carduser/{id}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "传学生的ID,后台返回学生信息",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [
{
"type": "integer",
"description": "学生ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"0": {
"description": "学生信息",
"schema": {
"$ref": "#/definitions/api_we.GetCardUserInfoRes"
}
}
}
},
"put": {
"security": [
{
......@@ -629,7 +661,7 @@ var doc = `{
"tags": [
"家长微信"
],
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)",
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]",
"parameters": [
{
"type": "integer",
......@@ -646,6 +678,40 @@ var doc = `{
}
}
},
"/we/cardusertrend/{id}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "传学生的ID,后台返回学生信息和最新动态",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取单个学生信息和最新动态[complete]",
"parameters": [
{
"type": "integer",
"description": "学生ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"0": {
"description": "学生信息和最新动态",
"schema": {
"$ref": "#/definitions/api_we.GetCardUserAndTrendRes"
}
}
}
}
},
"/we/familynum": {
"put": {
"security": [
......@@ -811,14 +877,14 @@ var doc = `{
"ApiKeyAuth": []
}
],
"description": "传学生ID至后台,后台返回卡信息",
"description": "传学生ID至后台,后台返回卡状态",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取学生公话卡状态",
"summary": "获取学生公话卡状态(含亲情号信息) [complete]",
"parameters": [
{
"type": "integer",
......@@ -838,7 +904,7 @@ var doc = `{
}
}
},
"/we/sharecode/{id}": {
"/we/sharestring/{id}": {
"get": {
"security": [
{
......@@ -852,7 +918,7 @@ var doc = `{
"tags": [
"家长微信"
],
"summary": "获取邀请码(仅主家长有权限)",
"summary": "获取邀请码(仅主家长有权限) [complete]",
"parameters": [
{
"type": "integer",
......@@ -950,7 +1016,7 @@ var doc = `{
"tags": [
"家长微信"
],
"summary": "微信学生首页,获取近20条用户最新动态",
"summary": "微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [
{
"type": "integer",
......@@ -964,7 +1030,10 @@ var doc = `{
"200": {
"description": "学生动态信息",
"schema": {
"$ref": "#/definitions/api_we.wechatCardUsersTrendType"
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
}
......@@ -1002,33 +1071,66 @@ var doc = `{
}
}
},
"api_we.PutCardUserReq": {
"api_we.BindCardUserRes": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": {
"description": "选填,班级,number",
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": {
"description": "必填,学生名字,maxLen=16",
"type": "string",
"example": "汤圆"
"type": "string"
},
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": {
"description": "选填,0女1男",
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "选填,学号,字符串,maxLen=32",
"description": "\"\"无意义",
"type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
},
"api_we.WeResUserInfoStruct": {
"api_we.GetCardUserAndTrendRes": {
"type": "object",
"properties": {
"area": {
......@@ -1051,6 +1153,21 @@ var doc = `{
"name": {
"type": "string"
},
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": {
"description": "0无意义 1女 2男",
"type": "integer"
......@@ -1058,33 +1175,35 @@ var doc = `{
"stuNum": {
"description": "\"\"无意义",
"type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
},
"api_we.bindCardUserRes": {
"api_we.GetCardUserInfoRes": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "四川省成都市温江区实验中学"
"example": "温江实验中学"
},
"class": {
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": {
"type": "string"
},
......@@ -1104,10 +1223,70 @@ var doc = `{
]
},
"sex": {
"description": "0女 1男",
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "\"\"无意义",
"type": "string"
}
}
},
"api_we.PutCardUserReq": {
"type": "object",
"properties": {
"class": {
"description": "选填,班级,number",
"type": "integer"
},
"grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"name": {
"description": "必填,学生名字,maxLen=16",
"type": "string",
"example": "汤圆"
},
"sex": {
"description": "选填,0女1男",
"type": "integer"
},
"stuNum": {
"description": "选填,学号,字符串,maxLen=32",
"type": "string"
}
}
},
"api_we.WeResUserInfoStruct": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": {
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"name": {
"type": "string"
},
"sex": {
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "\"\"无意义",
"type": "string"
}
}
......@@ -1176,18 +1355,17 @@ var doc = `{
"type": "integer"
},
"expiryAt": {
"description": "到期时间",
"type": "string"
},
"family": {
"description": "亲情号列表",
"type": "array",
"items": {
"$ref": "#/definitions/api_we.familyNumStruct"
"$ref": "#/definitions/model.CacheFamilyOnePerson"
}
},
"monthMin": {
"description": "月套餐使用分钟数",
"description": "本月已使用分钟数",
"type": "integer"
},
"monthPack": {
......@@ -1199,7 +1377,7 @@ var doc = `{
"type": "string"
},
"status": {
"description": "状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失",
"description": "0无数据 1 正常使用 2 已挂失",
"type": "integer"
}
}
......@@ -1292,28 +1470,7 @@ var doc = `{
}
}
},
"api_we.wechatCardUsersTrendType": {
"type": "object",
"properties": {
"content": {
"description": "显示在第二行",
"type": "string"
},
"service": {
"description": "服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等",
"type": "integer"
},
"time": {
"description": "显示在第三行",
"type": "string"
},
"title": {
"description": "显示在第一行",
"type": "string"
}
}
},
"dbcurd.InsertTableUserCardUserStruct": {
"dbcurd.InsertTableUCardUserStruct": {
"type": "object",
"properties": {
"areaID": {
......@@ -1395,6 +1552,42 @@ var doc = `{
"example": "四川省"
}
}
},
"model.CacheCardUserTrendStruct": {
"type": "object",
"properties": {
"content": {
"description": "显示在第二行 nickname+talkTime",
"type": "string",
"example": "被叫:爸爸 时长:2分"
},
"service": {
"description": "服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等",
"type": "integer",
"example": 1
},
"time": {
"description": "显示在第三行,呼叫起始时间",
"type": "string",
"example": "2021-10-23 17:00:00"
},
"title": {
"description": "显示在第一行 公话机-PlaceUser",
"type": "string",
"example": "公话机-教1楼3层"
}
}
},
"model.CacheFamilyOnePerson": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
}
}
},
"securityDefinitions": {
......
......@@ -33,7 +33,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbdao.TableBaseArea"
"$ref": "#/definitions/dbcurd.TableBaseArea"
}
}
],
......@@ -298,7 +298,7 @@
"tags": [
"家长微信"
],
"summary": "通过邀请码绑定学生",
"summary": "通过邀请码绑定学生 [complete]",
"parameters": [
{
"type": "string",
......@@ -312,7 +312,7 @@
"0": {
"description": "学生信息",
"schema": {
"$ref": "#/definitions/api_we.bindCardUserRes"
"$ref": "#/definitions/api_we.BindCardUserRes"
}
},
"30": {
......@@ -537,7 +537,7 @@
"tags": [
"家长微信"
],
"summary": "创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)",
"summary": "创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]",
"parameters": [
{
"description": "学生信息",
......@@ -545,7 +545,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbdao.InsertTableUserCardUserStruct"
"$ref": "#/definitions/dbcurd.InsertTableUCardUserStruct"
}
}
],
......@@ -560,6 +560,38 @@
}
},
"/we/carduser/{id}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "传学生的ID,后台返回学生信息",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [
{
"type": "integer",
"description": "学生ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"0": {
"description": "学生信息",
"schema": {
"$ref": "#/definitions/api_we.GetCardUserInfoRes"
}
}
}
},
"put": {
"security": [
{
......@@ -614,7 +646,7 @@
"tags": [
"家长微信"
],
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)",
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]",
"parameters": [
{
"type": "integer",
......@@ -631,6 +663,40 @@
}
}
},
"/we/cardusertrend/{id}": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "传学生的ID,后台返回学生信息和最新动态",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取单个学生信息和最新动态[complete]",
"parameters": [
{
"type": "integer",
"description": "学生ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"0": {
"description": "学生信息和最新动态",
"schema": {
"$ref": "#/definitions/api_we.GetCardUserAndTrendRes"
}
}
}
}
},
"/we/familynum": {
"put": {
"security": [
......@@ -796,14 +862,14 @@
"ApiKeyAuth": []
}
],
"description": "传学生ID至后台,后台返回卡信息",
"description": "传学生ID至后台,后台返回卡状态",
"produces": [
"application/json"
],
"tags": [
"家长微信"
],
"summary": "获取学生公话卡状态",
"summary": "获取学生公话卡状态(含亲情号信息) [complete]",
"parameters": [
{
"type": "integer",
......@@ -823,7 +889,7 @@
}
}
},
"/we/sharecode/{id}": {
"/we/sharestring/{id}": {
"get": {
"security": [
{
......@@ -837,7 +903,7 @@
"tags": [
"家长微信"
],
"summary": "获取邀请码(仅主家长有权限)",
"summary": "获取邀请码(仅主家长有权限) [complete]",
"parameters": [
{
"type": "integer",
......@@ -935,7 +1001,7 @@
"tags": [
"家长微信"
],
"summary": "微信学生首页,获取近20条用户最新动态",
"summary": "微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [
{
"type": "integer",
......@@ -949,7 +1015,10 @@
"200": {
"description": "学生动态信息",
"schema": {
"$ref": "#/definitions/api_we.wechatCardUsersTrendType"
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
}
......@@ -987,33 +1056,66 @@
}
}
},
"api_we.PutCardUserReq": {
"api_we.BindCardUserRes": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": {
"description": "选填,班级,number",
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": {
"description": "必填,学生名字,maxLen=16",
"type": "string",
"example": "汤圆"
"type": "string"
},
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": {
"description": "选填,0女1男",
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "选填,学号,字符串,maxLen=32",
"description": "\"\"无意义",
"type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
},
"api_we.WeResUserInfoStruct": {
"api_we.GetCardUserAndTrendRes": {
"type": "object",
"properties": {
"area": {
......@@ -1036,6 +1138,21 @@
"name": {
"type": "string"
},
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": {
"description": "0无意义 1女 2男",
"type": "integer"
......@@ -1043,33 +1160,35 @@
"stuNum": {
"description": "\"\"无意义",
"type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
}
}
},
"api_we.bindCardUserRes": {
"api_we.GetCardUserInfoRes": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "四川省成都市温江区实验中学"
"example": "温江实验中学"
},
"class": {
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": {
"type": "string"
},
......@@ -1089,10 +1208,70 @@
]
},
"sex": {
"description": "0女 1男",
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "\"\"无意义",
"type": "string"
}
}
},
"api_we.PutCardUserReq": {
"type": "object",
"properties": {
"class": {
"description": "选填,班级,number",
"type": "integer"
},
"grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"name": {
"description": "必填,学生名字,maxLen=16",
"type": "string",
"example": "汤圆"
},
"sex": {
"description": "选填,0女1男",
"type": "integer"
},
"stuNum": {
"description": "选填,学号,字符串,maxLen=32",
"type": "string"
}
}
},
"api_we.WeResUserInfoStruct": {
"type": "object",
"properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": {
"description": "0无意义",
"type": "integer"
},
"grade": {
"description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer"
},
"id": {
"description": "学生ID",
"type": "integer"
},
"name": {
"type": "string"
},
"sex": {
"description": "0无意义 1女 2男",
"type": "integer"
},
"stuNum": {
"description": "\"\"无意义",
"type": "string"
}
}
......@@ -1161,18 +1340,17 @@
"type": "integer"
},
"expiryAt": {
"description": "到期时间",
"type": "string"
},
"family": {
"description": "亲情号列表",
"type": "array",
"items": {
"$ref": "#/definitions/api_we.familyNumStruct"
"$ref": "#/definitions/model.CacheFamilyOnePerson"
}
},
"monthMin": {
"description": "月套餐使用分钟数",
"description": "本月已使用分钟数",
"type": "integer"
},
"monthPack": {
......@@ -1184,7 +1362,7 @@
"type": "string"
},
"status": {
"description": "状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失",
"description": "0无数据 1 正常使用 2 已挂失",
"type": "integer"
}
}
......@@ -1277,28 +1455,7 @@
}
}
},
"api_we.wechatCardUsersTrendType": {
"type": "object",
"properties": {
"content": {
"description": "显示在第二行",
"type": "string"
},
"service": {
"description": "服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等",
"type": "integer"
},
"time": {
"description": "显示在第三行",
"type": "string"
},
"title": {
"description": "显示在第一行",
"type": "string"
}
}
},
"dbdao.InsertTableUserCardUserStruct": {
"dbcurd.InsertTableUCardUserStruct": {
"type": "object",
"properties": {
"areaID": {
......@@ -1329,7 +1486,7 @@
}
}
},
"dbdao.TableBaseArea": {
"dbcurd.TableBaseArea": {
"type": "object",
"properties": {
"county_id": {
......@@ -1380,6 +1537,42 @@
"example": "四川省"
}
}
},
"model.CacheCardUserTrendStruct": {
"type": "object",
"properties": {
"content": {
"description": "显示在第二行 nickname+talkTime",
"type": "string",
"example": "被叫:爸爸 时长:2分"
},
"service": {
"description": "服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等",
"type": "integer",
"example": 1
},
"time": {
"description": "显示在第三行,呼叫起始时间",
"type": "string",
"example": "2021-10-23 17:00:00"
},
"title": {
"description": "显示在第一行 公话机-PlaceUser",
"type": "string",
"example": "公话机-教1楼3层"
}
}
},
"model.CacheFamilyOnePerson": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"phone": {
"type": "string"
}
}
}
},
"securityDefinitions": {
......
......@@ -21,26 +21,51 @@ definitions:
example: 海科学校
type: string
type: object
api_we.PutCardUserReq:
api_we.BindCardUserRes:
properties:
area:
description: 区域名字
example: 温江实验中学
type: string
class:
description: 选填,班级,number
description: 0无意义
type: integer
grade:
description: 必填,"1~9对应一年级~九年级,10~12对应高一~高三"
description: 0无意义 "1~9对应一年级~九年级,10~12对应高一~高三"
type: integer
id:
description: 学生ID
type: integer
master:
description: true:本来就是主家长,false:已成功绑定成副家长
example: false
type: boolean
name:
description: 必填,学生名字,maxLen=16
example: 汤圆
type: string
service:
description: 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
example:
- 1
- 2
- 2
- 0
- 0
- 0
items:
type: integer
type: array
sex:
description: 选填,0女1
description: 0无意义 1女 2
type: integer
stuNum:
description: 选填,学号,字符串,maxLen=32
description: '""无意义'
type: string
trend:
items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
type: object
api_we.WeResUserInfoStruct:
api_we.GetCardUserAndTrendRes:
properties:
area:
description: 区域名字
......@@ -57,31 +82,44 @@ definitions:
type: integer
name:
type: string
service:
description: 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
example:
- 1
- 2
- 2
- 0
- 0
- 0
items:
type: integer
type: array
sex:
description: 0无意义 1女 2男
type: integer
stuNum:
description: '""无意义'
type: string
trend:
items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
type: object
api_we.bindCardUserRes:
api_we.GetCardUserInfoRes:
properties:
area:
description: 区域名字
example: 四川省成都市温江区实验中学
example: 温江实验中学
type: string
class:
description: 0无意义
type: integer
grade:
description: '"1~9对应一年级~九年级,10~12对应高一~高三"'
description: 0无意义 "1~9对应一年级~九年级,10~12对应高一~高三"
type: integer
id:
description: 学生ID
type: integer
master:
description: true:本来就是主家长,false:已成功绑定成副家长
example: false
type: boolean
name:
type: string
service:
......@@ -97,9 +135,53 @@ definitions:
type: integer
type: array
sex:
description: 0女 1男
description: 0无意义 1女 2男
type: integer
stuNum:
description: '""无意义'
type: string
type: object
api_we.PutCardUserReq:
properties:
class:
description: 选填,班级,number
type: integer
grade:
description: 必填,"1~9对应一年级~九年级,10~12对应高一~高三"
type: integer
name:
description: 必填,学生名字,maxLen=16
example: 汤圆
type: string
sex:
description: 选填,0女1男
type: integer
stuNum:
description: 选填,学号,字符串,maxLen=32
type: string
type: object
api_we.WeResUserInfoStruct:
properties:
area:
description: 区域名字
example: 温江实验中学
type: string
class:
description: 0无意义
type: integer
grade:
description: 0无意义 "1~9对应一年级~九年级,10~12对应高一~高三"
type: integer
id:
description: 学生ID
type: integer
name:
type: string
sex:
description: 0无意义 1女 2男
type: integer
stuNum:
description: '""无意义'
type: string
type: object
api_we.creatCardUserRes:
......@@ -148,15 +230,14 @@ definitions:
description: 本月可修改亲情号次数
type: integer
expiryAt:
description: 到期时间
type: string
family:
description: 亲情号列表
items:
$ref: '#/definitions/api_we.familyNumStruct'
$ref: '#/definitions/model.CacheFamilyOnePerson'
type: array
monthMin:
description: 月套餐使用分钟数
description: 本月已使用分钟数
type: integer
monthPack:
description: 月套餐分钟数
......@@ -165,7 +246,7 @@ definitions:
description: 卡号
type: string
status:
description: 状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失
description: 0无数据 1 正常使用 2 已挂失
type: integer
type: object
api_we.slaveWeUserRes:
......@@ -230,22 +311,7 @@ definitions:
$ref: '#/definitions/api_we.WeResUserInfoStruct'
type: array
type: object
api_we.wechatCardUsersTrendType:
properties:
content:
description: 显示在第二行
type: string
service:
description: 服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
type: integer
time:
description: 显示在第三行
type: string
title:
description: 显示在第一行
type: string
type: object
dbdao.InsertTableUserCardUserStruct:
dbcurd.InsertTableUCardUserStruct:
properties:
areaID:
description: 必填,校区ID
......@@ -268,7 +334,7 @@ definitions:
description: 选填,学号,字符串,maxLen=32
type: string
type: object
dbdao.TableBaseArea:
dbcurd.TableBaseArea:
properties:
county_id:
description: 必填,所属区县ID
......@@ -307,6 +373,32 @@ definitions:
example: 四川省
type: string
type: object
model.CacheCardUserTrendStruct:
properties:
content:
description: 显示在第二行 nickname+talkTime
example: 被叫:爸爸 时长:2分
type: string
service:
description: 服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
example: 1
type: integer
time:
description: 显示在第三行,呼叫起始时间
example: "2021-10-23 17:00:00"
type: string
title:
description: 显示在第一行 公话机-PlaceUser
example: 公话机-教1楼3层
type: string
type: object
model.CacheFamilyOnePerson:
properties:
name:
type: string
phone:
type: string
type: object
info:
contact: {}
description: 用于家长端微信小程序及web端管理后台
......@@ -324,7 +416,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/dbdao.TableBaseArea'
$ref: '#/definitions/dbcurd.TableBaseArea'
produces:
- application/json
responses:
......@@ -500,14 +592,14 @@ paths:
"0":
description: 学生信息
schema:
$ref: '#/definitions/api_we.bindCardUserRes'
$ref: '#/definitions/api_we.BindCardUserRes'
"30":
description: 邀请码无效
"31":
description: 邀请码已过期
security:
- ApiKeyAuth: []
summary: 通过邀请码绑定学生
summary: 通过邀请码绑定学生 [complete]
tags:
- 家长微信
/we/callrecord/{id}:
......@@ -648,7 +740,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/dbdao.InsertTableUserCardUserStruct'
$ref: '#/definitions/dbcurd.InsertTableUCardUserStruct'
produces:
- application/json
responses:
......@@ -658,7 +750,7 @@ paths:
$ref: '#/definitions/api_we.creatCardUserRes'
security:
- ApiKeyAuth: []
summary: 创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)
summary: 创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]
tags:
- 家长微信
/we/carduser/{id}:
......@@ -677,7 +769,27 @@ paths:
description: ""
security:
- ApiKeyAuth: []
summary: 主家长删除一个学生,(当家长点删除时弹框二次确认)
summary: 主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]
tags:
- 家长微信
get:
description: 传学生的ID,后台返回学生信息
parameters:
- description: 学生ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"0":
description: 学生信息
schema:
$ref: '#/definitions/api_we.GetCardUserInfoRes'
security:
- ApiKeyAuth: []
summary: 获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态
tags:
- 家长微信
put:
......@@ -706,6 +818,27 @@ paths:
summary: 修改学生信息
tags:
- 家长微信
/we/cardusertrend/{id}:
get:
description: 传学生的ID,后台返回学生信息和最新动态
parameters:
- description: 学生ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"0":
description: 学生信息和最新动态
schema:
$ref: '#/definitions/api_we.GetCardUserAndTrendRes'
security:
- ApiKeyAuth: []
summary: 获取单个学生信息和最新动态[complete]
tags:
- 家长微信
/we/familynum:
delete:
consumes:
......@@ -809,7 +942,7 @@ paths:
- 家长微信
/we/phonecardstatus/{id}:
get:
description: 传学生ID至后台,后台返回卡信息
description: 传学生ID至后台,后台返回卡状态
parameters:
- description: 学生ID
in: path
......@@ -825,10 +958,10 @@ paths:
$ref: '#/definitions/api_we.getPhoneCardStatusRes'
security:
- ApiKeyAuth: []
summary: 获取学生公话卡状态
summary: 获取学生公话卡状态(含亲情号信息) [complete]
tags:
- 家长微信
/we/sharecode/{id}:
/we/sharestring/{id}:
get:
description: 主家长生成邀请码,有效时长可选1分钟~60分钟
parameters:
......@@ -851,7 +984,7 @@ paths:
type: string
security:
- ApiKeyAuth: []
summary: 获取邀请码(仅主家长有权限)
summary: 获取邀请码(仅主家长有权限) [complete]
tags:
- 家长微信
/we/slaveweuser/{id}:
......@@ -904,10 +1037,12 @@ paths:
"200":
description: 学生动态信息
schema:
$ref: '#/definitions/api_we.wechatCardUsersTrendType'
items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
security:
- ApiKeyAuth: []
summary: 微信学生首页,获取近20条用户最新动态
summary: 微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态
tags:
- 家长微信
securityDefinitions:
......
......@@ -2,7 +2,7 @@ package tencent
import "errors"
func TencentCode2Session(code string) (string, error) {
func WechatCode2Session(code string) (string, error) {
var testTemp = map[string]string{
"codeTest1": "unionIDTest1",
"codeTest2": "unionIDTest2",
......
package util
import (
"math/rand"
"time"
)
func GetRandomString(len uint8) string {
const abcStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
result := make([]byte, len)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := uint8(0); i < len; i++ {
result[i] = abcStr[r.Intn(62)]
}
return string(result)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment