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) { ...@@ -102,8 +102,8 @@ func GetAreaByCounty(c *gin.Context) {
testRole, ok := cache.GetWechatCustomerTestRole(userID.(uint32)) testRole, ok := cache.GetWechatCustomerTestRole(userID.(uint32))
if ok == false { if ok == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserTokenWrong, "code": api.ErrorTokenWrong,
"message": api.CodeMsg[api.ErrorUserTokenWrong], "message": api.CodeMsg[api.ErrorTokenWrong],
}) })
return return
} }
......
...@@ -18,16 +18,16 @@ type creatCardUserRes struct { ...@@ -18,16 +18,16 @@ type creatCardUserRes struct {
// CreateCardUser 创建一个学生 // CreateCardUser 创建一个学生
// @Tags 家长微信 // @Tags 家长微信
// @Summary 创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全) // @Summary 创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]
// @Description 传新建学生信息至后台,后台返回学生id,以及对应校区的service // @Description 传新建学生信息至后台,后台返回学生id,以及对应校区的service
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param data body dbcurd.InsertTableUserCardUserStruct true "学生信息" // @Param data body dbcurd.InsertTableUCardUserStruct true "学生信息"
// @Success 0 {object} creatCardUserRes // @Success 0 {object} creatCardUserRes
// @Router /we/carduser [POST] // @Router /we/carduser [POST]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func CreateCardUser(c *gin.Context) { func CreateCardUser(c *gin.Context) {
var reqData dbcurd.InsertTableUserCardUserStruct var reqData dbcurd.InsertTableUCardUserStruct
err := c.ShouldBindJSON(&reqData) err := c.ShouldBindJSON(&reqData)
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
...@@ -44,11 +44,11 @@ func CreateCardUser(c *gin.Context) { ...@@ -44,11 +44,11 @@ func CreateCardUser(c *gin.Context) {
"data": api.CodeMsg[api.ErrorSystemErr], "data": api.CodeMsg[api.ErrorSystemErr],
}) })
logger.Log.Error("strconv.Atoi(c.Param(\"userID\")", logger.Log.Error("strconv.Atoi(c.Param(\"userID\")",
zap.String("c.Param(\"userID\")", c.Param("userID"))) zap.Reflect("c.Get(\"userID\")", v))
return return
} }
newID := dbcurd.InsertUserCardUserAndUserWeCardUser(reqData, weUserID) //插入数据库 newID := dbcurd.InsertUCardUserAndUserWeCardUser(&reqData, weUserID) //插入数据库
if newID == 0 { if newID == 0 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr, "code": api.ErrorSystemErr,
......
...@@ -3,6 +3,7 @@ package api_we ...@@ -3,6 +3,7 @@ package api_we
import ( import (
"dc_golang_server_1/api" "dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache" "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/logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -12,7 +13,7 @@ import ( ...@@ -12,7 +13,7 @@ import (
// DeleteCardUser 主家长删除一个学生 // DeleteCardUser 主家长删除一个学生
// @Tags 家长微信 // @Tags 家长微信
// @Summary 主家长删除一个学生,(当家长点删除时弹框二次确认) // @Summary 主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]
// @Description 传学生ID至后台,后台返回成功失败 // @Description 传学生ID至后台,后台返回成功失败
// @Produce json // @Produce json
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
...@@ -20,7 +21,8 @@ import ( ...@@ -20,7 +21,8 @@ import (
// @Router /we/carduser/{id} [DELETE] // @Router /we/carduser/{id} [DELETE]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func DeleteCardUser(c *gin.Context) { func DeleteCardUser(c *gin.Context) {
cardUserID, _ := strconv.Atoi(c.Param("id")) cardUserIDInt, _ := strconv.Atoi(c.Param("id"))
cardUserID := uint32(cardUserIDInt)
if cardUserID == 0 { if cardUserID == 0 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara, "code": api.ErrorReqPara,
...@@ -33,7 +35,7 @@ func DeleteCardUser(c *gin.Context) { ...@@ -33,7 +35,7 @@ func DeleteCardUser(c *gin.Context) {
if ok == false { if ok == false {
logger.Log.Error("userID在Context里面居然没填对,遇到鬼了", logger.Log.Error("userID在Context里面居然没填对,遇到鬼了",
zap.String("Src", "DeleteCardUser"), zap.String("Src", "DeleteCardUser"),
zap.Int("cardUserID", cardUserID)) zap.Uint32("cardUserID", cardUserID))
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr, "code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr], "message": api.CodeMsg[api.ErrorSystemErr],
...@@ -41,7 +43,7 @@ func DeleteCardUser(c *gin.Context) { ...@@ -41,7 +43,7 @@ func DeleteCardUser(c *gin.Context) {
return return
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetUCardUserInfo(uint32(cardUserID)) cardUserInfo, ok := cache.GetCardUserInfo(cardUserID)
if ok == false { if ok == false {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr, "code": api.ErrorSystemErr,
...@@ -57,10 +59,23 @@ func DeleteCardUser(c *gin.Context) { ...@@ -57,10 +59,23 @@ func DeleteCardUser(c *gin.Context) {
return 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{ c.JSON(http.StatusOK, gin.H{
"code": api.Success, "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) { ...@@ -75,7 +75,7 @@ func WeLogin(c *gin.Context) {
} }
} }
} }
var userInfo model.CacheUWeCustomerStruct var userInfo model.CacheWeCustomerStruct
var haveInfo bool var haveInfo bool
if userID != 0 { if userID != 0 {
userInfo, haveInfo = cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, nowTime) userInfo, haveInfo = cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, nowTime)
...@@ -85,7 +85,7 @@ func WeLogin(c *gin.Context) { ...@@ -85,7 +85,7 @@ func WeLogin(c *gin.Context) {
} }
if haveInfo == false { // 微信服务器登录 if haveInfo == false { // 微信服务器登录
unionID, err := tencent2.TencentCode2Session(reqData.Code) //也不去校验reqData.Code长度了,对半是对的 unionID, err := tencent2.WechatCode2Session(reqData.Code) //也不去校验reqData.Code长度了,对半是对的
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorTencentErr, "code": api.ErrorTencentErr,
...@@ -131,7 +131,7 @@ func WeLogin(c *gin.Context) { ...@@ -131,7 +131,7 @@ func WeLogin(c *gin.Context) {
} }
for _, cardUserID := range userInfo.MasterCardUserID { for _, cardUserID := range userInfo.MasterCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok { if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
...@@ -151,7 +151,7 @@ func WeLogin(c *gin.Context) { ...@@ -151,7 +151,7 @@ func WeLogin(c *gin.Context) {
} }
for _, cardUserID := range userInfo.SlaveCardUserID { for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok { if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
...@@ -208,7 +208,7 @@ func GetStudentList(c *gin.Context) { ...@@ -208,7 +208,7 @@ func GetStudentList(c *gin.Context) {
var res weUserListStruct var res weUserListStruct
for _, cardUserID := range userInfo.MasterCardUserID { for _, cardUserID := range userInfo.MasterCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok { if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
...@@ -228,7 +228,7 @@ func GetStudentList(c *gin.Context) { ...@@ -228,7 +228,7 @@ func GetStudentList(c *gin.Context) {
} }
for _, cardUserID := range userInfo.SlaveCardUserID { for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetUCardUserInfo(cardUserID); ok { if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok {
var areaInfo model.CacheBAreaStruct var areaInfo model.CacheBAreaStruct
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
......
...@@ -7,129 +7,6 @@ import ( ...@@ -7,129 +7,6 @@ import (
"time" "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 打开邀请码开关(仅主家长有权限) //// PutCardUserShareOn 打开邀请码开关(仅主家长有权限)
//// @Tags 家长微信 //// @Tags 家长微信
//// @Summary 打开邀请码开关(仅主家长有权限) //// @Summary 打开邀请码开关(仅主家长有权限)
...@@ -277,32 +154,6 @@ type familyNumStruct struct { ...@@ -277,32 +154,6 @@ type familyNumStruct struct {
Name string `json:"name"` 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 { type getCallRecordRes struct {
// 被叫号码 // 被叫号码
CalledNumber string `json:"number"` CalledNumber string `json:"number"`
......
...@@ -11,7 +11,7 @@ func Cors() gin.HandlerFunc { ...@@ -11,7 +11,7 @@ func Cors() gin.HandlerFunc {
if context.Request.Method == "OPTIONS" { if context.Request.Method == "OPTIONS" {
origin := context.Request.Header.Get("Origin") origin := context.Request.Header.Get("Origin")
var headerKeys []string var headerKeys []string
for k, _ := range context.Request.Header { for k := range context.Request.Header {
headerKeys = append(headerKeys, k) headerKeys = append(headerKeys, k)
} }
headerStr := strings.Join(headerKeys, ",") headerStr := strings.Join(headerKeys, ",")
......
package api package api
const ( const (
Success = 0 Success = 0
ErrorTokenExist = 1 ErrorTokenExist = 1
ErrorTokenWrong = 2 ErrorTokenWrong = 2
ErrorTokenRunTime = 3 ErrorTokenRunTime = 3
ErrorTokenExit = 4 ErrorTokenExit = 4
ErrorUserRole = 5 ErrorUserRole = 5
ErrorSystemErr = 6 ErrorSystemErr = 6
ErrorTencentErr = 7 ErrorSystemBusy = 7
ErrorTencentErr = 8
ErrorUserNotHavePhoneCard = 9
ErrorReqParaFormat = 10 ErrorReqParaFormat = 10
ErrorReqPara = 11 ErrorReqPara = 11
ErrorReqInsertDuplicate = 12 ErrorReqInsertDuplicate = 12
ErrorUserTokenWrong = 1001 ErrorShareCode = 30
ErrorWechatLogin = 1002 ErrorShareCodeRunTime = 31
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模块的错误
) )
var CodeMsg = map[uint16]string{ var CodeMsg = map[uint16]string{
ErrorTokenExist: "token不存在", ErrorTokenExist: "token不存在",
ErrorTokenWrong: "非法token", ErrorTokenWrong: "非法token",
ErrorTokenRunTime: "token过期", ErrorTokenRunTime: "token过期",
ErrorTokenExit: "token已退出登录", ErrorTokenExit: "token已退出登录",
ErrorUserRole: "用户没有权限", ErrorUserRole: "用户没有权限",
ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)", ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)",
ErrorTencentErr: "微信服务器返回的错误:", ErrorSystemBusy: "服务器忙,请重试",
ErrorTencentErr: "微信服务器返回的错误:",
ErrorUserNotHavePhoneCard: "用户未绑定共话卡",
ErrorReqPara: "请求参数内容(取值)错误", ErrorReqPara: "请求参数内容(取值)错误",
ErrorReqParaFormat: "请求参数格式错误", ErrorReqParaFormat: "请求参数格式错误",
ErrorReqInsertDuplicate: "内容重复,无法创建", ErrorReqInsertDuplicate: "内容重复,无法创建",
ErrorUserTokenWrong: "用户token错误,系统找不到用户信息,请重新登录", ErrorShareCode: "邀请码无效,请联系主家长微信重新分享",
ErrorWechatLogin: "微信登录错误:", ErrorShareCodeRunTime: "邀请码已过期,请联系主家长微信重新分享",
// 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: "用户没有权限",
} }
...@@ -220,6 +220,46 @@ func JeffWTWechat() gin.HandlerFunc { ...@@ -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 { func JeffWTAdmin() gin.HandlerFunc {
return func(c *gin.Context) { return func(c *gin.Context) {
clearStruct := DecryptToken(c.Request.Header.Get("token")) clearStruct := DecryptToken(c.Request.Header.Get("token"))
......
...@@ -40,18 +40,19 @@ func InitRouter() { //*gin.Engine{ ...@@ -40,18 +40,19 @@ func InitRouter() { //*gin.Engine{
wechat := r.Group("we/") wechat := r.Group("we/")
wechat.Use(api.JeffWTWechat()) wechat.Use(api.JeffWTWechat())
{ // 需要token的stulist { // 需要token的stulist
wechat.GET("stulist", api_we.GetStudentList) //获取学生列表 wechat.GET("stulist", api_we.GetStudentList) //获取学生列表
wechat.POST("carduser", api_we.CreateCardUser) //创建学生 wechat.POST("carduser", api_we.CreateCardUser) //创建学生
wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生 wechat.GET("carduser/:id", api_we.GetCardUser) //读取单个学生信息
wechat.GET("trend/:id", api_we.GetCardUsersTrend) //获取学生最新动态 wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生
wechat.GET("bindcarduser/:id", api_we.GetBindCardUser) //获取学生副家长列表(仅主家长有权限) wechat.GET("trend/:id", api_we.GetCardUserTrend) //获取学生最新动态
wechat.GET("sharecode/id", api_we.CardUserShareCode) //获取邀请码(仅主家长有权限) wechat.GET("cardusertrend/:id", api_we.GetCardUserAndTrend) //获取单个学生信息和最新动态
wechat.POST("bindcarduser/:share_code", api_we.BindCardUser) //副家长绑定学生 wechat.GET("bindcarduser/:id", api_we.GetBindCardUser) //获取学生副家长列表(仅主家长有权限)
wechat.DELETE("bindcarduser/:id", api_we.DeleteBindCardUser) //副家长解绑学生 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("cardusershareon/:id", api_we.PutCardUserShareOn) //打开邀请码开关(仅主家长有权限)
//wechat.PUT("cardusershareoff/:id", api_we.PutCardUserShareOff) //关闭邀请码开关(仅主家长有权限) //wechat.PUT("cardusershareoff/:id", api_we.PutCardUserShareOff) //关闭邀请码开关(仅主家长有权限)
wechat.DELETE("slaveweuser", api_we.DeleteSlaveWeUser) //删除副家长(仅主家长有权限) wechat.DELETE("slaveweuser/:id", api_we.DeleteSlaveWeUser) //删除副家长(仅主家长有权限)
//wechat.DELETE("allslaveweuser", api_we.DeleteAllSlaveWeUser) //删除副家长(仅主家长有权限)
wechat.PUT("carduser/:id", api_we.PutCardUser) //修改学生信息 wechat.PUT("carduser/:id", api_we.PutCardUser) //修改学生信息
wechat.PUT("cardloss/:id", api_we.CardLoss) //卡挂失/解挂 wechat.PUT("cardloss/:id", api_we.CardLoss) //卡挂失/解挂
wechat.PUT("cardbind/:id", api_we.CardBind) //绑定卡 wechat.PUT("cardbind/:id", api_we.CardBind) //绑定卡
......
...@@ -3,7 +3,6 @@ package cache ...@@ -3,7 +3,6 @@ package cache
import ( import (
"dc_golang_server_1/data_db_cache/model" "dc_golang_server_1/data_db_cache/model"
"sync" "sync"
"time"
) )
func Init() { func Init() {
...@@ -11,12 +10,14 @@ func Init() { ...@@ -11,12 +10,14 @@ func Init() {
initAreaMapAndCountyAreaMap() initAreaMapAndCountyAreaMap()
initWechatCustomerMap() initWechatCustomerMap()
initUCardUserMapAndSiminfoMapNoFamilyNum() initCardUserMapAndSimInfoMapNoFamilyNum()
initWechatAndCardUserRelationToWechatCustomerMapAndCardUserMap()
initFamilyNumToSimInfoMap() initFamilyNumToSimInfoMap()
//initAreaServiceMap() initAreaServiceMap()
//initPhone20DeviceMap() initPhone20DeviceMap()
//initAdminMap() // initAdminMap()
//initOperatorMap() // initOperatorMap()
//initCardUserTrendMap()
} }
// ProvinceMap /*********************************************************全国行政区域**/------------------------OK // ProvinceMap /*********************************************************全国行政区域**/------------------------OK
...@@ -37,7 +38,7 @@ var CountyAreaMap sync.Map //map[uint32][[]uint32] 区县ID作为KEY,[]area_id ...@@ -37,7 +38,7 @@ var CountyAreaMap sync.Map //map[uint32][[]uint32] 区县ID作为KEY,[]area_id
// AreaMap /******************************************************区域(校区)**/ // AreaMap /******************************************************区域(校区)**/
var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE
//type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出,后续再加支付信息 //type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出
// Name string // Name string
// Longitude uint32 // Longitude uint32
// Latitude uint32 // Latitude uint32
...@@ -64,12 +65,12 @@ var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE ...@@ -64,12 +65,12 @@ var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE
/******************************************************区域(校区)服务信息**/ /******************************************************区域(校区)服务信息**/
var areaServiceMap sync.Map //area_service_id 作为KEY CacheBAreaStruct 作为VALUE var areaServiceMap sync.Map //area_service_id 作为KEY CacheBAreaStruct 作为VALUE
type AreaServiceStruct struct { // type AreaServiceStruct struct { // 后续再加支付信息
AreaID uint32 AreaID uint32
ServiceID uint8 //服务项目 1公话 2定位 3饮水 4POS ......... ServiceType uint8 //服务项目 1公话 2定位 3饮水 4POS .........
OperatorID uint32 //运营商ID //OperatorID uint32 //运营商ID
Name string //服务名字(例宿舍135栋饮水)name //Name string //服务名字(例宿舍135栋饮水)name
Status uint8 //状态 0无内容1正式2测试3暂停4暂未开放 Status uint8 //状态 0无内容1正式2测试3暂停4暂未开放
} }
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
...@@ -101,7 +102,7 @@ type AreaServiceStruct struct { // ...@@ -101,7 +102,7 @@ type AreaServiceStruct struct { //
/***************************************************微信用户(家长)**/ //------------------------OK /***************************************************微信用户(家长)**/ //------------------------OK
var WechatCustomerUnionIDToIDMAP sync.Map // UnionID作为KEY(string),微信用户ID作为VALUE(uint32) var WechatCustomerUnionIDToIDMAP sync.Map // UnionID作为KEY(string),微信用户ID作为VALUE(uint32)
var WechatCustomerMap sync.Map // 微信的WechatUserID(uint32)作为KEY var WechatCustomerMap sync.Map // 微信的WechatUserID(uint32)作为KEY
//type CacheUWeCustomerStruct struct { //type CacheWeCustomerStruct struct {
// TokenCreatTime int64 // TokenCreatTime int64
// TestRole bool // 测试用户(可看到测试校区) // TestRole bool // 测试用户(可看到测试校区)
// WePhone string // 手机号 // WePhone string // 手机号
...@@ -133,15 +134,24 @@ var CardUserMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY ...@@ -133,15 +134,24 @@ var CardUserMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY
// IcCardID uint32 // 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卡信息(仅存学生绑定了的)**/ /********************************************************Sim卡信息(仅存学生绑定了的)**/
var simInfoMap sync.Map //sim_id(string) 作为KEY var SimInfoMap sync.Map //sim_id(string) 作为KEY
//type CacheSimInfoStruct struct { //type CacheSimInfoStruct struct {
// CardUserID uint32 //卡用户ID // CardUserID uint32 //卡用户ID
// AreaServiceID uint32 // AreaServiceID uint32
// Status int8 //0无数据 1 正常使用 2 已挂失 // Status uint8 //0无数据 1 正常使用 2 已挂失
// MonthTalkMinutes uint16 // MonthTalkMinutes uint16
// MonthPackageMinutes uint16 // MonthPackageMinutes uint16
// ExpiryAt time.Time // ExpiryAt time.Time
...@@ -156,23 +166,12 @@ var simInfoMap sync.Map //sim_id(string) 作为KEY ...@@ -156,23 +166,12 @@ var simInfoMap sync.Map //sim_id(string) 作为KEY
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
/*******************************************************电话设备**/ /*******************************************************电话设备**/
var phone20DeviceMap sync.Map //device_id 作为KEY Phone20DeviceStruct 作为VALUE var phone20DeviceMap sync.Map //device_id 作为KEY CachePhone20DeviceStruct 作为VALUE
type Phone20DeviceStruct struct { //type CachePhone20DeviceStruct struct {
AreaServiceID uint32 // AreaServiceID uint32
AllowCallTime uint8 //允许通话时长,255表示不限制时长 // AllowCallTime uint8 //允许通话时长,255表示不限制时长
//Place string //安装位置 // //Place string //安装位置
Status bool // 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
}
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
...@@ -28,17 +28,16 @@ func initAreaMapAndCountyAreaMap() { ...@@ -28,17 +28,16 @@ func initAreaMapAndCountyAreaMap() {
var areaID uint32 var areaID uint32
var temp model.CacheBAreaStruct var temp model.CacheBAreaStruct
rows, err := dbcurd.PgDb.Query("SELECT id,county_id,name,longitude,latitude,status FROM b_area") // rows, err := dbcurd.PgDb.Query("SELECT id,county_id,name,longitude,latitude,status FROM b_area") //
defer rows.Close()
if err != nil { if err != nil {
log.Panicln("SelectAreaToMap rows", err) log.Panicln("SelectAreaToMap rows", err)
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&areaID, &temp.CountyID, &temp.Name, &temp.Longitude, &temp.Latitude, &temp.Status) err = rows.Scan(&areaID, &temp.CountyID, &temp.Name, &temp.Longitude, &temp.Latitude, &temp.Status)
if err != nil { if err != nil {
log.Panicln("SelectAreaToMap rows.Scan", err) log.Panicln("SelectAreaToMap rows.Scan", err)
} }
fmt.Println(areaID, temp)
AreaMap.Store(areaID, temp) AreaMap.Store(areaID, temp)
if temp.CountyID != 0 { if temp.CountyID != 0 {
var areaIDList []uint32 var areaIDList []uint32
...@@ -47,7 +46,6 @@ func initAreaMapAndCountyAreaMap() { ...@@ -47,7 +46,6 @@ func initAreaMapAndCountyAreaMap() {
} }
areaIDList = append(areaIDList, areaID) areaIDList = append(areaIDList, areaID)
CountyAreaMap.Store(temp.CountyID, areaIDList) CountyAreaMap.Store(temp.CountyID, areaIDList)
fmt.Println(temp.CountyID, areaIDList)
} }
} }
// 处理完毕后,需要判断一次遍历过程中是否有错误产生 // 处理完毕后,需要判断一次遍历过程中是否有错误产生
......
...@@ -11,29 +11,29 @@ import ( ...@@ -11,29 +11,29 @@ import (
) )
func initAreaServiceMap() { func initAreaServiceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin") fmt.Println(time.Now(), "cache: initAreaServiceMap begin")
var areaID int32 var areaServiceID uint32
var temp AreaServiceStruct var temp AreaServiceStruct
rows, err := dbcurd.PgDb.Query("SELECT id,name,status FROM b_area") //todo rows, err := dbcurd.PgDb.Query("SELECT id,service_type,area_id,status FROM b_area_service") //
defer rows.Close()
if err != nil { if err != nil {
log.Panicln("SelectAreaToMap rows", err) log.Panicln("initAreaServiceMap rows", err)
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&areaID, &temp.Name, &temp.Status) err = rows.Scan(&areaServiceID, &temp.ServiceType, &temp.AreaID, &temp.Status)
if err != nil { 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 { if err = rows.Err(); err != nil {
logger.Log.Error("rows.Err()", logger.Log.Error("rows.Err()",
zap.Error(err), zap.Error(err),
zap.String("src", "initAreaMap")) zap.String("src", "initAreaMap"))
fmt.Println(time.Now(), "initAreaMap rows.Err()", err) fmt.Println(time.Now(), "initAreaServiceMap rows.Err()", err)
} else { } 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 ...@@ -58,17 +58,17 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct
var err error var err error
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
err = dbcurd.PgDb.QueryRow("SELECT name,status FROM b_area WHERE id=$1", err = dbcurd.PgDb.QueryRow("SELECT service_type,area_id,status FROM b_area_service WHERE id=$1",
areaServiceID).Scan(&areaServiceInfo.Name, &areaServiceInfo.Status) //todo areaServiceID).Scan(&areaServiceInfo.ServiceType, &areaServiceInfo.AreaID, &areaServiceInfo.Status)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "no rows in result") { 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.Uint32("areaServiceID", areaServiceID),
zap.Error(err), zap.Error(err),
zap.String("src", "GetAreaServiceInfo")) zap.String("src", "GetAreaServiceInfo"))
return return
} }
fmt.Println("GetAreaInfo SELECT:", i, err) fmt.Println("b_area_service SELECT:", i, err)
time.Sleep(3 * time.Millisecond) time.Sleep(3 * time.Millisecond)
continue continue
} }
......
...@@ -11,29 +11,33 @@ import ( ...@@ -11,29 +11,33 @@ import (
"time" "time"
) )
func initUCardUserMapAndSiminfoMapNoFamilyNum() { //ServiceType uint8 `json:"service" example:"1"` // 服务项目 1公话2定位3饮水4卡消费5洗浴6洗衣机 决定UI图标及颜色等
fmt.Println(time.Now(), "cache: initUCardUserMapAndSiminfoMapNoFamilyNum begin") //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 cardUserID uint32
var temp model.CacheCardUserStruct 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") 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 { if err != nil {
log.Panicln("Select u_card_user To Map rows", err) log.Panicln("Select u_card_user To Map rows", err)
} }
defer rows.Close()
var simInfo model.CacheSimInfoStruct var simInfo model.CacheSimInfoStruct
for rows.Next() { for rows.Next() {
err = rows.Scan(&cardUserID, &temp.Name, &temp.Sex, &temp.AreaID, &temp.Grade, &temp.Class, &temp.StuNum) err = rows.Scan(&cardUserID, &temp.Name, &temp.Sex, &temp.AreaID, &temp.Grade, &temp.Class, &temp.StuNum)
if err != nil { 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, &temp.SimCardID,
&simInfo.AreaServiceID, &simInfo.AreaServiceID,
&simInfo.MonthTalkMinutes, &simInfo.MonthTalkMinutes,
&simInfo.MonthPackageMinutes, &simInfo.MonthPackageMinutes,
&simInfo.Status, &simInfo.Status,
&simInfo.FamilyChangeCount,
&simInfo.ExpiryAt) &simInfo.ExpiryAt)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "no rows in result") { if strings.Contains(err.Error(), "no rows in result") {
...@@ -43,18 +47,45 @@ func initUCardUserMapAndSiminfoMapNoFamilyNum() { ...@@ -43,18 +47,45 @@ func initUCardUserMapAndSiminfoMapNoFamilyNum() {
log.Panicln("Select u_sim_info To temp.SimCardID", err) log.Panicln("Select u_sim_info To temp.SimCardID", err)
} }
// todo1 考虑校验area_service_id // todo1 考虑校验area_service_id
simInfoMap.Store(temp.SimCardID, simInfo) simInfo.CardUserID = cardUserID
SimInfoMap.Store(temp.SimCardID, simInfo)
CardUserMap.Store(cardUserID, temp) CardUserMap.Store(cardUserID, temp)
} }
// 处理完毕后,需要判断一次遍历过程中是否有错误产生 // 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil { 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 s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确 if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
return v, true return v, true
...@@ -62,15 +93,88 @@ func GetUCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) { ...@@ -62,15 +93,88 @@ func GetUCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) {
CardUserMap.Delete(cardUserID) CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误", logger.Log.Error("CardUserMap 类型断言错误",
zap.Uint32("cardUserID", cardUserID), zap.Uint32("cardUserID", cardUserID),
zap.String("src", "GetUCardUserInfo")) zap.String("src", "GetCardUserInfo"))
} }
} else { } else {
logger.Log.Error("CardUserMap 有问题,没数据", logger.Log.Error("CardUserMap 有问题,没数据",
zap.Uint32("cardUserID", cardUserID), zap.Uint32("cardUserID", cardUserID),
zap.String("src", "GetUCardUserInfo")) zap.String("src", "GetCardUserInfo"))
} }
var temp model.CacheCardUserStruct var temp model.CacheCardUserStruct
// todo1 再去查一盘库 // todo1 再去查一盘库
return temp, false 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() { ...@@ -19,10 +19,10 @@ func initBDistrictMaps() {
ProvinceMap = []model.CacheBDistrictStruct{} //先清空原来的缓存 ProvinceMap = []model.CacheBDistrictStruct{} //先清空原来的缓存
var temp 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") 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 { if err != nil {
log.Panicln("ProvinceMap SELECT b_district rows", err) log.Panicln("ProvinceMap SELECT b_district rows", err)
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &temp.Initial) err = rows.Scan(&temp.Id, &temp.Name, &temp.Initial)
if err != nil { if err != nil {
...@@ -52,10 +52,10 @@ func selectToDistrictMap(level uint8, tempMap *sync.Map) bool { ...@@ -52,10 +52,10 @@ func selectToDistrictMap(level uint8, tempMap *sync.Map) bool {
var parentID uint32 var parentID uint32
var temp model.CacheBDistrictStruct 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) 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 { if err != nil {
log.Panicln("SELECT b_district rows", err, level) log.Panicln("SELECT b_district rows", err, level)
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &parentID, &temp.Initial) err = rows.Scan(&temp.Id, &temp.Name, &parentID, &temp.Initial)
if err != nil { if err != nil {
......
...@@ -2,6 +2,7 @@ package cache ...@@ -2,6 +2,7 @@ package cache
import ( import (
"dc_golang_server_1/data_db_cache/dbcurd" "dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -13,14 +14,14 @@ import ( ...@@ -13,14 +14,14 @@ import (
func initPhone20DeviceMap() { func initPhone20DeviceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin") fmt.Println(time.Now(), "cache: initDeviceMap begin")
var devID uint32 var devID uint32
var temp Phone20DeviceStruct var temp model.CachePhone20DeviceStruct
rows, err := dbcurd.PgDb.Query("SELECT id,area_service_id,allow_call_time,status FROM d_device") rows, err := dbcurd.PgDb.Query("SELECT device_id,area_service_id,allow_call_time,status,place_user FROM d_phone20")
defer rows.Close()
if err != nil { if err != nil {
log.Panicln("SelectDeviceToMap rows", err) log.Panicln("SelectDeviceToMap rows", err)
} }
defer rows.Close()
for rows.Next() { 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 { if err != nil {
log.Panicln("SelectDeviceToMap rows.Scan", err) log.Panicln("SelectDeviceToMap rows.Scan", err)
} }
...@@ -37,9 +38,9 @@ func initPhone20DeviceMap() { ...@@ -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 info, ok := phone20DeviceMap.Load(devID); ok { //map有
if v, ok2 := info.(Phone20DeviceStruct); ok2 { //类型断言正确 if v, ok2 := info.(model.CachePhone20DeviceStruct); ok2 { //类型断言正确
return v //,true return v //,true
} else { //类型断言失败 } else { //类型断言失败
phone20DeviceMap.Delete(devID) phone20DeviceMap.Delete(devID)
...@@ -48,7 +49,7 @@ func GetPhone20Info(devID uint32) Phone20DeviceStruct { ...@@ -48,7 +49,7 @@ func GetPhone20Info(devID uint32) Phone20DeviceStruct {
zap.String("src", "getDeviceInfo")) zap.String("src", "getDeviceInfo"))
} }
} }
var temp Phone20DeviceStruct var temp model.CachePhone20DeviceStruct
var err error var err error
for i := 0; i < 5; i++ { 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", err = dbcurd.PgDb.QueryRow("SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE device_id=$1",
......
package cache package cache
import ( import (
"dc_golang_server_1/data_db_cache/dbcurd"
"dc_golang_server_1/data_db_cache/model" "dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
"log"
"time" "time"
) )
func initFamilyNumToSimInfoMap() { func initFamilyNumToSimInfoMap() {
fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap begin") 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") fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap end")
} }
func GetSimInfo(cardId string) model.CacheSimInfoStruct { func GetSimInfo(simId string) model.CacheSimInfoStruct {
if s, ok := simInfoMap.Load(cardId); ok { // map有 if s, ok := SimInfoMap.Load(simId); ok { // map有
if family, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确 if info, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确
return family return info
} else { //类型断言失败 } else { //类型断言失败
simInfoMap.Delete(cardId) SimInfoMap.Delete(simId)
logger.Log.Error("simInfoMap 类型断言错误", logger.Log.Error("SimInfoMap 类型断言错误",
zap.String("cardId", cardId), zap.String("simId", simId),
zap.String("src", "GetSimInfo")) zap.String("src", "GetSimInfo"))
} }
} else { } else {
logger.Log.Warn("simInfoMap 里面居然没有数据", logger.Log.Warn("SimInfoMap 里面居然没有数据",
zap.String("cardId", cardId), zap.String("simId", simId),
zap.String("src", "GetSimInfo")) zap.String("src", "GetSimInfo"))
} }
...@@ -36,6 +55,41 @@ func GetSimInfo(cardId string) model.CacheSimInfoStruct { ...@@ -36,6 +55,41 @@ func GetSimInfo(cardId string) model.CacheSimInfoStruct {
} }
// AddSimMonthTalkMinutes 缓存里增加本月通话分钟数 // 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() { ...@@ -14,99 +14,38 @@ func initWechatCustomerMap() {
fmt.Println(time.Now(), "cache: initWechatCustomerMap begin") fmt.Println(time.Now(), "cache: initWechatCustomerMap begin")
var weUserID uint32 var weUserID uint32
var unionID string var unionID string
var temp model.CacheUWeCustomerStruct var temp model.CacheWeCustomerStruct
// 1. 查u_we_customer表获得基础数据 // 查u_we_customer表获得基础数据
rows, err := dbcurd.PgDb.Query("SELECT id,unionid,phone,nickname,avatarurl,test_role FROM 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 { if err != nil {
rows.Close()
log.Panicln("SelectWechatCustomerMap rows", err) log.Panicln("SelectWechatCustomerMap rows", err)
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&weUserID, &unionID, &temp.WePhone, &temp.Nickname, &temp.AvatarURL, &temp.TestRole) err = rows.Scan(&weUserID, &unionID, &temp.WePhone, &temp.Nickname, &temp.AvatarURL, &temp.TestRole)
if err != nil { if err != nil {
rows.Close()
log.Panicln("SelectWechatCustomerMap rows.Scan", err) log.Panicln("SelectWechatCustomerMap rows.Scan", err)
} }
if len(unionID) > 0 { if len(unionID) > 0 {
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID) WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, temp) 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 { } else {
if v, ok := WechatCustomerMap.Load(weUserID); ok { logger.Log.Error("initWechatCustomerMap 有weUserID空数据")
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"))
}
} }
} }
// 处理完毕后,需要判断一次遍历过程中是否有错误产生 // 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil { 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") fmt.Println(time.Now(), "cache: initWechatCustomerMap OK")
} }
func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 { func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
var data model.CacheUWeCustomerStruct var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok { if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok { if data, ok = v.(model.CacheWeCustomerStruct); ok {
return data.TokenCreatTime //正常情况 return data.TokenCreatTime //正常情况
} else { } else {
logger.Log.Error("WechatCustomerMap 类型断言错误", logger.Log.Error("WechatCustomerMap 类型断言错误",
...@@ -123,9 +62,9 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 { ...@@ -123,9 +62,9 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
} }
func GetWechatCustomerTestRole(userID uint32) (bool, bool) { func GetWechatCustomerTestRole(userID uint32) (bool, bool) {
var data model.CacheUWeCustomerStruct var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(userID); ok { 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 //正常情况 return data.TestRole, true //正常情况
} else { } else {
logger.Log.Error("WechatCustomerMap 类型断言错误", logger.Log.Error("WechatCustomerMap 类型断言错误",
...@@ -158,10 +97,10 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 { ...@@ -158,10 +97,10 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 {
return 0 return 0
} }
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheUWeCustomerStruct, bool) { func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheWeCustomerStruct, bool) {
var data model.CacheUWeCustomerStruct var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok { if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok { if data, ok = v.(model.CacheWeCustomerStruct); ok {
if newTime > 0 { if newTime > 0 {
data.TokenCreatTime = newTime data.TokenCreatTime = newTime
WechatCustomerMap.Store(weUserID, data) WechatCustomerMap.Store(weUserID, data)
...@@ -190,7 +129,8 @@ func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) ...@@ -190,7 +129,8 @@ func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64)
return data, true 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) userID, res := dbcurd.InsertUWeCustomerUnionID(unionID)
if res == dbcurd.InsertSysErr { if res == dbcurd.InsertSysErr {
return 0 return 0
...@@ -206,11 +146,11 @@ func InsertWechatCustomerMap(unionID string, userInfo *model.CacheUWeCustomerStr ...@@ -206,11 +146,11 @@ func InsertWechatCustomerMap(unionID string, userInfo *model.CacheUWeCustomerStr
return userID return userID
} }
// InsertNewStudentIDToWechatCustomerMap 缓存定制方法:微信用户增加/绑定卡用户 // InsertNewStudentIDToWechatCustomerMap 注意这里并发不安全
func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool { 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 v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok { if data, ok = v.(model.CacheWeCustomerStruct); ok {
if master { if master {
data.MasterCardUserID = append(data.MasterCardUserID, cardUserID) data.MasterCardUserID = append(data.MasterCardUserID, cardUserID)
} else { } else {
...@@ -232,6 +172,53 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m ...@@ -232,6 +172,53 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m
// 再查一遍库,库里面已经添加了学生数据了,就不用再添加了 // 再查一遍库,库里面已经添加了学生数据了,就不用再添加了
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data) unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data)
if len(unionID) == 0 { 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 return false
} }
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID) 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) { ...@@ -29,7 +29,7 @@ func InsertDevCommandErr(devId uint32, ciphertext string, errMsg string) {
if err == nil { if err == nil {
return return
} }
fmt.Println("InsertDevCommandErr:", i, err) fmt.Println("硬件问题 InsertDevCommandErr:", i, err)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
} }
logger.Log.Error("InsertDevCommandErr Err", logger.Log.Error("InsertDevCommandErr Err",
......
...@@ -30,7 +30,7 @@ type TableDevHexCommandRecord struct { ...@@ -30,7 +30,7 @@ type TableDevHexCommandRecord struct {
createAt time.Time createAt time.Time
} }
func InsertDevCommandRecord(insertData TableDevHexCommandRecord) { func InsertDevCommandRecord(insertData *TableDevHexCommandRecord) {
var err error var err error
for i := 0; i < 10; i++ { 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) // _, 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 { ...@@ -28,7 +28,7 @@ type TableDevHexResetRecord struct {
createAt time.Time createAt time.Time
} }
func InsertDevResetRecord(insertData TableDevHexResetRecord) { func InsertDevResetRecord(insertData *TableDevHexResetRecord) {
var err error var err error
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
_, err = stmtInsertDevResetRecord.Exec( _, err = stmtInsertDevResetRecord.Exec(
......
package dbcurd package dbcurd
import ( import (
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap" "go.uber.org/zap"
"strconv"
"strings" "strings"
"time"
) )
type InsertTableUCallRecordStruct struct { type InsertTableUCallRecordStruct struct {
...@@ -19,9 +23,10 @@ type InsertTableUCallRecordStruct struct { ...@@ -19,9 +23,10 @@ type InsertTableUCallRecordStruct struct {
AreaServiceID uint32 AreaServiceID uint32
OperatorId uint32 OperatorId uint32
Status uint8 Status uint8
PlaceUser string
} }
func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) uint8 { //0 成功 1 唯一约束重复 9 系统繁忙 func InsertUCallRecordAndUpdateUSimInfo(insertData *InsertTableUCallRecordStruct) uint8 { //0 成功 1 唯一约束重复 9 系统繁忙
tx, err := PgDb.Begin() tx, err := PgDb.Begin()
if err != nil { if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():", logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():",
...@@ -30,7 +35,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) ...@@ -30,7 +35,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
} }
defer clearTransaction(tx) defer clearTransaction(tx)
//先InsertUCallRecord //先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.CardUserId,
insertData.DeviceId, insertData.DeviceId,
insertData.CallStartAt, insertData.CallStartAt,
...@@ -43,6 +48,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) ...@@ -43,6 +48,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
insertData.AreaServiceID, insertData.AreaServiceID,
insertData.OperatorId, insertData.OperatorId,
insertData.Status, insertData.Status,
insertData.PlaceUser,
) )
if err != nil { if err != nil {
if strings.Contains(err.Error(), "duplicate key value") { //todoN 这里应考虑去查出来看看内容是不是一样的 if strings.Contains(err.Error(), "duplicate key value") { //todoN 这里应考虑去查出来看看内容是不是一样的
...@@ -60,7 +66,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) ...@@ -60,7 +66,7 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
//} //}
//fmt.Println(rowAffected) //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 { if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo UPDATE u_sim_info:", logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo UPDATE u_sim_info:",
zap.Error(err)) zap.Error(err))
...@@ -81,3 +87,35 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct) ...@@ -81,3 +87,35 @@ func InsertUCallRecordAndUpdateUSimInfo(insertData InsertTableUCallRecordStruct)
return InsertOK 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 ...@@ -3,6 +3,7 @@ package dbcurd
import ( import (
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"go.uber.org/zap" "go.uber.org/zap"
"time"
) )
//id integer NOT NULL DEFAULT nextval('u_card_user_id_seq'::regclass), //id integer NOT NULL DEFAULT nextval('u_card_user_id_seq'::regclass),
...@@ -16,7 +17,7 @@ import ( ...@@ -16,7 +17,7 @@ import (
//create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP, //create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
//first_topup_at timestamp without time zone, //first_topup_at timestamp without time zone,
type InsertTableUserCardUserStruct struct { type InsertTableUCardUserStruct struct {
Role uint8 `swaggerignore:"true"` // 后台添加选填,学生名字,角色:0学生,1教师,2职工 Role uint8 `swaggerignore:"true"` // 后台添加选填,学生名字,角色:0学生,1教师,2职工
Name string `json:"name" example:"汤圆"` // 必填,学生名字,maxLen=16 Name string `json:"name" example:"汤圆"` // 必填,学生名字,maxLen=16
AreaID uint32 `json:"areaID" example:"1"` // 必填,校区ID AreaID uint32 `json:"areaID" example:"1"` // 必填,校区ID
...@@ -26,8 +27,8 @@ type InsertTableUserCardUserStruct struct { ...@@ -26,8 +27,8 @@ type InsertTableUserCardUserStruct struct {
StuNum string `json:"stuNum,omitempty"` // 选填,学号,字符串,maxLen=32 StuNum string `json:"stuNum,omitempty"` // 选填,学号,字符串,maxLen=32
} }
// InsertUserCardUserAndUserWeCardUser 事务处理两张表 // InsertUCardUserAndUserWeCardUser 事务处理两张表
func InsertUserCardUserAndUserWeCardUser(insertData InsertTableUserCardUserStruct, weUserID uint32) (cardUserID uint32) { func InsertUCardUserAndUserWeCardUser(insertData *InsertTableUCardUserStruct, weUserID uint32) (cardUserID uint32) {
tx, err := PgDb.Begin() tx, err := PgDb.Begin()
if err != nil { if err != nil {
logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():", logger.Log.Error("InsertUCallRecordAndUpdateUSimInfo PgDb.Begin():",
...@@ -46,23 +47,57 @@ func InsertUserCardUserAndUserWeCardUser(insertData InsertTableUserCardUserStruc ...@@ -46,23 +47,57 @@ func InsertUserCardUserAndUserWeCardUser(insertData InsertTableUserCardUserStruc
insertData.StuNum, insertData.StuNum,
).Scan(&cardUserID) ).Scan(&cardUserID)
if err != nil { if err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser INSERT u_card_user:", logger.Log.Error("InsertUCardUserAndUserWeCardUser INSERT u_card_user:",
zap.Error(err)) zap.Error(err))
return return
} }
_, err = tx.Exec("INSERT INTO u_we_card_user(we_user_id,card_user_id,master)VALUES($1,$2,true)", weUserID, cardUserID) _, 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 { if err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser INSERT u_we_card_user:", logger.Log.Error("InsertUCardUserAndUserWeCardUser INSERT u_we_card_user:",
zap.Error(err)) zap.Error(err))
return 0 return 0
} }
if err = tx.Commit(); err != nil { if err = tx.Commit(); err != nil {
logger.Log.Error("InsertUserCardUserAndUserWeCardUser Commit:", logger.Log.Error("InsertUCardUserAndUserWeCardUser Commit:",
zap.Error(err)) zap.Error(err))
return 0 return 0
} }
return 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 package dbcurd
import ( 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 func SelectUSimFamilyNumBySimID(simID string) (familyNumbers []model.CacheFamilyOnePerson) {
//( var onePerson model.CacheFamilyOnePerson
//card_id character varying(32) COLLATE pg_catalog."default" NOT NULL, familyNumbers = make([]model.CacheFamilyOnePerson, 0)
//phone character varying(12) COLLATE pg_catalog."default", rows, err := PgDb.Query("SELECT phone,nickname FROM u_sim_family_num WHERE sim_id=$1 order by create_at", simID)
//nickname character varying(32) COLLATE pg_catalog."default", if err != nil {
//area_id integer NOT NULL, logger.Log.Error("SelectUSimFamilyNumBySimID 1",
//create_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP, zap.String("simID", simID),
//CONSTRAINT u_sim_family_num_pkey PRIMARY KEY (card_id, area_id) 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 { return
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
} }
package dbcurd package dbcurd
//CREATE TABLE IF NOT EXISTS public.u_sim_info import (
//( "dc_golang_server_1/data_db_cache/model"
//card_id character varying(20) COLLATE pg_catalog."default", "dc_golang_server_1/logger"
//total_talk_minutes integer, "fmt"
//month_talk_minutes integer, "go.uber.org/zap"
//month_package_minutes integer, "strings"
//status smallint "time"
//) )
//type TableUserSimInfo struct { func SelectUSimInfoBySimID(simId string, cacheData *model.CacheSimInfoStruct) bool {
// CardID string 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) { ...@@ -44,7 +44,7 @@ func InsertUWeCustomerUnionID(unionID string) (id uint32, res uint8) {
return 0, InsertSysErr 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表获得基础数据 // 1. 查u_we_customer表获得基础数据
err := PgDb.QueryRow("SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1", unionID).Scan( err := PgDb.QueryRow("SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1", unionID).Scan(
&userID, &userID,
...@@ -60,7 +60,6 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach ...@@ -60,7 +60,6 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
} }
// 2. 查u_we_card_user表,获得绑定的学生数据 // 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) 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 { if err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 2", logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 2",
zap.Uint32("userID", userID), zap.Uint32("userID", userID),
...@@ -68,6 +67,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach ...@@ -68,6 +67,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
fmt.Println(err) fmt.Println(err)
return 0 return 0
} }
defer rows.Close()
var cUserID uint32 var cUserID uint32
var master bool var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0] userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0]
...@@ -95,7 +95,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach ...@@ -95,7 +95,7 @@ func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.Cach
return return
} }
func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheUWeCustomerStruct) (unionID string) { func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheWeCustomerStruct) (unionID string) {
// 1. 查u_we_customer表获得基础数据 // 1. 查u_we_customer表获得基础数据
err := PgDb.QueryRow("SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1", userID).Scan( err := PgDb.QueryRow("SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1", userID).Scan(
&unionID, &unionID,
...@@ -111,13 +111,13 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheU ...@@ -111,13 +111,13 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheU
} }
// 2. 查u_we_card_user表,获得绑定的学生数据 // 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) 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 { if err != nil {
logger.Log.Error("SelectUWeCustomerByUserIDToCacheModel 2", logger.Log.Error("SelectUWeCustomerByUserIDToCacheModel 2",
zap.Uint32("userID", userID), zap.Uint32("userID", userID),
zap.Error(err)) zap.Error(err))
return "" return ""
} }
defer rows.Close()
var cUserID uint32 var cUserID uint32
var master bool var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0] 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 { ...@@ -37,7 +37,7 @@ type HexData struct {
} }
func /*(d *DCLongTCPHex)*/ insertDevHexCommandRecord(data *HexData, ciphertext string, direction uint8) { func /*(d *DCLongTCPHex)*/ insertDevHexCommandRecord(data *HexData, ciphertext string, direction uint8) {
go dbcurd.InsertDevCommandRecord(dbcurd.TableDevHexCommandRecord{ go dbcurd.InsertDevCommandRecord(&dbcurd.TableDevHexCommandRecord{
DevID: data.DevID, DevID: data.DevID,
DevUtc: data.TimeUtc, DevUtc: data.TimeUtc,
CtrlCode: strconv.FormatUint(uint64(data.CtrlCode), 16), CtrlCode: strconv.FormatUint(uint64(data.CtrlCode), 16),
......
...@@ -3,6 +3,7 @@ package dcphone20 ...@@ -3,6 +3,7 @@ package dcphone20
import ( import (
"dc_golang_server_1/data_db_cache/cache" "dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbcurd" "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/devproduct"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"fmt" "fmt"
...@@ -357,7 +358,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -357,7 +358,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
return return
} }
if areaService.Status == 0 || areaService.ServiceID > 2 { if areaService.Status == 0 || areaService.ServiceType > 2 {
data.Data[0] = 0xff data.Data[0] = 0xff
errMessage := enc.ConvertString("该区域暂未开通公话业务") errMessage := enc.ConvertString("该区域暂未开通公话业务")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
...@@ -402,7 +403,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -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 data.Data[0] = 0xff
errMessage := enc.ConvertString("卡已过期 请续费") errMessage := enc.ConvertString("卡已过期 请续费")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
...@@ -469,18 +470,18 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -469,18 +470,18 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
if data.Length == 20 { if data.Length == 20 {
data.CtrlCode = ctrlCode | 0x80 data.CtrlCode = ctrlCode | 0x80
enc := mahonia.NewEncoder("gbk") enc := mahonia.NewEncoder("gbk")
data.Data = append(data.Data, 0xff)
// 1.根据设备编号查status和AreaServiceID // 1.根据设备编号查status和AreaServiceID
v := cache.GetPhone20Info(data.DevID) v := cache.GetPhone20Info(data.DevID)
if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册 if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册
data.Data[0] = 0xff data.Data = append(data.Data, 0xff)
errMessage := enc.ConvertString("话机设备未注册") errMessage := enc.ConvertString("话机设备未注册")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
return return
} // 后台没添加该设备,返回显示 话机设备未注册 } // 后台没添加该设备,返回显示 话机设备未注册
if v.Status == false { //设备已停用,返回显示 设备暂停使用 if v.Status == false { //设备已停用,返回显示 设备暂停使用
data.Data[0] = 0xff data.Data = append(data.Data, 0xff)
errMessage := enc.ConvertString("设备暂停使用") errMessage := enc.ConvertString("设备暂停使用")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
...@@ -489,15 +490,15 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -489,15 +490,15 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// 2.根据IccID查卡信息 // 2.根据IccID查卡信息
s := cache.GetSimInfo(string(data.Data)) s := cache.GetSimInfo(string(data.Data))
data.Data = append(data.Data, 0xff)
if s.AreaServiceID != v.AreaServiceID { // 这张卡不属于这个校区服务 if s.AreaServiceID != v.AreaServiceID { // 这张卡不属于这个校区服务
errMessage := enc.ConvertString("此卡在本设备不可用") errMessage := enc.ConvertString("此卡在本设备不可用")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
logger.Log.Warn("卡绑定的校区服务与话机不符", logger.Log.Warn("卡绑定的校区服务与话机不符",
zap.String("Src", "TCP-SERVER-response"), zap.String("Src", "TCP-SERVER-response"),
zap.String("IccID", string(data.Data[1:])), zap.String("IccID", string(data.Data[:20])),
zap.Uint32("DevID", data.DevID), zap.Uint32("DevID", data.DevID))
zap.Uint8s("RecvData", data.Data))
return return
} }
if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码 if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码
...@@ -519,16 +520,20 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -519,16 +520,20 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
return return
} // 卡未绑定 } // 卡未绑定
if time.Now().Before(s.ExpiryAt) { // 服务已过期 if time.Now().After(s.ExpiryAt) { // 服务已过期
errMessage := enc.ConvertString("卡已过期 请续费") errMessage := enc.ConvertString("卡已过期 请续费")
data.Data = append(data.Data, errMessage...) data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
return 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.MonthPackageMinutes,
s.MonthTalkMinutes, temp,
s.ExpiryAt.Format("2006-01-02")) s.ExpiryAt.Format("2006-01-02"))
data.Data = append(data.Data, enc.ConvertString(errMessage)...) data.Data = append(data.Data, enc.ConvertString(errMessage)...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
...@@ -543,42 +548,70 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -543,42 +548,70 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
case 0x64: // 上报已读留言 case 0x64: // 上报已读留言
data.CtrlCode = ctrlCode | 0x80 data.CtrlCode = ctrlCode | 0x80
case 0x62: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID case 0x62: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID
if data.Length > 27 { //todo if data.Length > 27 {
//devInfo := cache.GetDeviceInfo(data.DevID) iccID := string(data.Data[0:20])
//var areaInfo cache.CacheBAreaStruct // 1. 通过IccID查card_user_id和area_service_id
//if devInfo.AreaID > 0 { simInfo := cache.GetSimInfo(iccID)
// areaInfo = cache.GetAreaInfo(devInfo.AreaID)
//} var areaServiceInfo cache.AreaServiceStruct
//familyInfo := cache.GetSimFamilyNum(devInfo.AreaID,string(data.Data[1:21])) // 2. 通过area_service_id查areaID
//calledNum := string(data.Data[27:]) if simInfo.AreaServiceID > 0 {
//var nickname string areaServiceInfo = cache.GetAreaServiceInfo(simInfo.AreaServiceID)
//for i:=0;i < len(familyInfo.Family);i++{ }
// if calledNum == familyInfo.Family[i].Phone {
// nickname = familyInfo.Family[i].Nickname // 通过areaID查areaName
// break var areaName string
// } if areaServiceInfo.AreaID > 0 {
//} areaName = cache.GetAreaMapName(areaServiceInfo.AreaID, true)
//// 以事务方式存2张表 }
//if result := dbcurd.InsertUCallRecordAndUpdateUSimInfo(dbcurd.InsertTableUCallRecordStruct{
// //CustomerId: // 3. 通过card_user_id查name
// //CardUserId: var cardUserInfo model.CacheCardUserStruct
// //CardUserName: if simInfo.CardUserID > 0 {
// CardID: string(data.Data[1:21]), cardUserInfo, _ = cache.GetCardUserInfo(simInfo.CardUserID)
// CardType:0, }
// CalledNumber: calledNum,
// CalledNickname: nickname, // 通过simInfo查出called_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"), calledNum := string(data.Data[27:])
// TalkTime: int16(data.Data[25]) + int16(data.Data[26]<<8), var nickname string
// AreaId: devInfo.AreaID, for i := 0; i < len(simInfo.FamilyNum); i++ {
// OperatorId: areaInfo.OperatorID, if calledNum == simInfo.FamilyNum[i].Phone {
// DeviceId: data.DevID, nickname = simInfo.FamilyNum[i].Nickname
// Status: data.Data[0], break
//});result > 1 { }
// return }
//} else if result == 0 { //扣套餐分钟数
// talkTime := uint16(data.Data[24]) + uint16(data.Data[25])<<8
//}
data.CtrlCode = ctrlCode | 0x80 // 以事务方式存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 { } else {
data.CtrlCode = ctrlCode | 0x80 //还是回硬件 data.CtrlCode = ctrlCode | 0x80 //还是回硬件
logger.Log.Error("data.Length error", logger.Log.Error("data.Length error",
...@@ -647,7 +680,7 @@ func insertDevHexResetRecord(data *devproduct.HexData) { ...@@ -647,7 +680,7 @@ func insertDevHexResetRecord(data *devproduct.HexData) {
} }
firmwareVersion = strTemp[2] // firmwareVersion = strTemp[2] //
} }
go dbcurd.InsertDevResetRecord(dbcurd.TableDevHexResetRecord{ go dbcurd.InsertDevResetRecord(&dbcurd.TableDevHexResetRecord{
DevId: data.DevID, DevId: data.DevID,
DevUtc: data.TimeUtc, DevUtc: data.TimeUtc,
ResetReason: resetReason, ResetReason: resetReason,
......
...@@ -313,7 +313,7 @@ var doc = `{ ...@@ -313,7 +313,7 @@ var doc = `{
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "通过邀请码绑定学生", "summary": "通过邀请码绑定学生 [complete]",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
...@@ -327,7 +327,7 @@ var doc = `{ ...@@ -327,7 +327,7 @@ var doc = `{
"0": { "0": {
"description": "学生信息", "description": "学生信息",
"schema": { "schema": {
"$ref": "#/definitions/api_we.bindCardUserRes" "$ref": "#/definitions/api_we.BindCardUserRes"
} }
}, },
"30": { "30": {
...@@ -552,7 +552,7 @@ var doc = `{ ...@@ -552,7 +552,7 @@ var doc = `{
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)", "summary": "创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]",
"parameters": [ "parameters": [
{ {
"description": "学生信息", "description": "学生信息",
...@@ -560,7 +560,7 @@ var doc = `{ ...@@ -560,7 +560,7 @@ var doc = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dbcurd.InsertTableUserCardUserStruct" "$ref": "#/definitions/dbcurd.InsertTableUCardUserStruct"
} }
} }
], ],
...@@ -575,6 +575,38 @@ var doc = `{ ...@@ -575,6 +575,38 @@ var doc = `{
} }
}, },
"/we/carduser/{id}": { "/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": { "put": {
"security": [ "security": [
{ {
...@@ -629,7 +661,7 @@ var doc = `{ ...@@ -629,7 +661,7 @@ var doc = `{
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)", "summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -646,6 +678,40 @@ var doc = `{ ...@@ -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": { "/we/familynum": {
"put": { "put": {
"security": [ "security": [
...@@ -811,14 +877,14 @@ var doc = `{ ...@@ -811,14 +877,14 @@ var doc = `{
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "传学生ID至后台,后台返回卡信息", "description": "传学生ID至后台,后台返回卡状态",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "获取学生公话卡状态", "summary": "获取学生公话卡状态(含亲情号信息) [complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -838,7 +904,7 @@ var doc = `{ ...@@ -838,7 +904,7 @@ var doc = `{
} }
} }
}, },
"/we/sharecode/{id}": { "/we/sharestring/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
...@@ -852,7 +918,7 @@ var doc = `{ ...@@ -852,7 +918,7 @@ var doc = `{
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "获取邀请码(仅主家长有权限)", "summary": "获取邀请码(仅主家长有权限) [complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -950,7 +1016,7 @@ var doc = `{ ...@@ -950,7 +1016,7 @@ var doc = `{
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "微信学生首页,获取近20条用户最新动态", "summary": "微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -964,7 +1030,10 @@ var doc = `{ ...@@ -964,7 +1030,10 @@ var doc = `{
"200": { "200": {
"description": "学生动态信息", "description": "学生动态信息",
"schema": { "schema": {
"$ref": "#/definitions/api_we.wechatCardUsersTrendType" "type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
} }
...@@ -1002,33 +1071,66 @@ var doc = `{ ...@@ -1002,33 +1071,66 @@ var doc = `{
} }
} }
}, },
"api_we.PutCardUserReq": { "api_we.BindCardUserRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": { "class": {
"description": "选填,班级,number", "description": "0无意义",
"type": "integer" "type": "integer"
}, },
"grade": { "grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"", "description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer" "type": "integer"
}, },
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": { "name": {
"description": "必填,学生名字,maxLen=16", "type": "string"
"type": "string", },
"example": "汤圆" "service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
}, },
"sex": { "sex": {
"description": "选填,0女1男", "description": "0无意义 1女 2男",
"type": "integer" "type": "integer"
}, },
"stuNum": { "stuNum": {
"description": "选填,学号,字符串,maxLen=32", "description": "\"\"无意义",
"type": "string" "type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
}, },
"api_we.WeResUserInfoStruct": { "api_we.GetCardUserAndTrendRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": { "area": {
...@@ -1051,6 +1153,21 @@ var doc = `{ ...@@ -1051,6 +1153,21 @@ var doc = `{
"name": { "name": {
"type": "string" "type": "string"
}, },
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": { "sex": {
"description": "0无意义 1女 2男", "description": "0无意义 1女 2男",
"type": "integer" "type": "integer"
...@@ -1058,33 +1175,35 @@ var doc = `{ ...@@ -1058,33 +1175,35 @@ var doc = `{
"stuNum": { "stuNum": {
"description": "\"\"无意义", "description": "\"\"无意义",
"type": "string" "type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
}, },
"api_we.bindCardUserRes": { "api_we.GetCardUserInfoRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": { "area": {
"description": "区域名字", "description": "区域名字",
"type": "string", "type": "string",
"example": "四川省成都市温江区实验中学" "example": "温江实验中学"
}, },
"class": { "class": {
"description": "0无意义",
"type": "integer" "type": "integer"
}, },
"grade": { "grade": {
"description": "\"1~9对应一年级~九年级,10~12对应高一~高三\"", "description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer" "type": "integer"
}, },
"id": { "id": {
"description": "学生ID", "description": "学生ID",
"type": "integer" "type": "integer"
}, },
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": { "name": {
"type": "string" "type": "string"
}, },
...@@ -1104,10 +1223,70 @@ var doc = `{ ...@@ -1104,10 +1223,70 @@ var doc = `{
] ]
}, },
"sex": { "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" "type": "integer"
}, },
"stuNum": { "stuNum": {
"description": "\"\"无意义",
"type": "string" "type": "string"
} }
} }
...@@ -1176,18 +1355,17 @@ var doc = `{ ...@@ -1176,18 +1355,17 @@ var doc = `{
"type": "integer" "type": "integer"
}, },
"expiryAt": { "expiryAt": {
"description": "到期时间",
"type": "string" "type": "string"
}, },
"family": { "family": {
"description": "亲情号列表", "description": "亲情号列表",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/api_we.familyNumStruct" "$ref": "#/definitions/model.CacheFamilyOnePerson"
} }
}, },
"monthMin": { "monthMin": {
"description": "月套餐使用分钟数", "description": "本月已使用分钟数",
"type": "integer" "type": "integer"
}, },
"monthPack": { "monthPack": {
...@@ -1199,7 +1377,7 @@ var doc = `{ ...@@ -1199,7 +1377,7 @@ var doc = `{
"type": "string" "type": "string"
}, },
"status": { "status": {
"description": "状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失", "description": "0无数据 1 正常使用 2 已挂失",
"type": "integer" "type": "integer"
} }
} }
...@@ -1292,28 +1470,7 @@ var doc = `{ ...@@ -1292,28 +1470,7 @@ var doc = `{
} }
} }
}, },
"api_we.wechatCardUsersTrendType": { "dbcurd.InsertTableUCardUserStruct": {
"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": {
"type": "object", "type": "object",
"properties": { "properties": {
"areaID": { "areaID": {
...@@ -1395,6 +1552,42 @@ var doc = `{ ...@@ -1395,6 +1552,42 @@ var doc = `{
"example": "四川省" "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": { "securityDefinitions": {
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dbdao.TableBaseArea" "$ref": "#/definitions/dbcurd.TableBaseArea"
} }
} }
], ],
...@@ -298,7 +298,7 @@ ...@@ -298,7 +298,7 @@
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "通过邀请码绑定学生", "summary": "通过邀请码绑定学生 [complete]",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
...@@ -312,7 +312,7 @@ ...@@ -312,7 +312,7 @@
"0": { "0": {
"description": "学生信息", "description": "学生信息",
"schema": { "schema": {
"$ref": "#/definitions/api_we.bindCardUserRes" "$ref": "#/definitions/api_we.BindCardUserRes"
} }
}, },
"30": { "30": {
...@@ -537,7 +537,7 @@ ...@@ -537,7 +537,7 @@
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全)", "summary": "创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]",
"parameters": [ "parameters": [
{ {
"description": "学生信息", "description": "学生信息",
...@@ -545,7 +545,7 @@ ...@@ -545,7 +545,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dbdao.InsertTableUserCardUserStruct" "$ref": "#/definitions/dbcurd.InsertTableUCardUserStruct"
} }
} }
], ],
...@@ -560,6 +560,38 @@ ...@@ -560,6 +560,38 @@
} }
}, },
"/we/carduser/{id}": { "/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": { "put": {
"security": [ "security": [
{ {
...@@ -614,7 +646,7 @@ ...@@ -614,7 +646,7 @@
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)", "summary": "主家长删除一个学生,(当家长点删除时弹框二次确认)[并发弱安全complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -631,6 +663,40 @@ ...@@ -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": { "/we/familynum": {
"put": { "put": {
"security": [ "security": [
...@@ -796,14 +862,14 @@ ...@@ -796,14 +862,14 @@
"ApiKeyAuth": [] "ApiKeyAuth": []
} }
], ],
"description": "传学生ID至后台,后台返回卡信息", "description": "传学生ID至后台,后台返回卡状态",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "获取学生公话卡状态", "summary": "获取学生公话卡状态(含亲情号信息) [complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -823,7 +889,7 @@ ...@@ -823,7 +889,7 @@
} }
} }
}, },
"/we/sharecode/{id}": { "/we/sharestring/{id}": {
"get": { "get": {
"security": [ "security": [
{ {
...@@ -837,7 +903,7 @@ ...@@ -837,7 +903,7 @@
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "获取邀请码(仅主家长有权限)", "summary": "获取邀请码(仅主家长有权限) [complete]",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -935,7 +1001,7 @@ ...@@ -935,7 +1001,7 @@
"tags": [ "tags": [
"家长微信" "家长微信"
], ],
"summary": "微信学生首页,获取近20条用户最新动态", "summary": "微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态",
"parameters": [ "parameters": [
{ {
"type": "integer", "type": "integer",
...@@ -949,7 +1015,10 @@ ...@@ -949,7 +1015,10 @@
"200": { "200": {
"description": "学生动态信息", "description": "学生动态信息",
"schema": { "schema": {
"$ref": "#/definitions/api_we.wechatCardUsersTrendType" "type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
} }
...@@ -987,33 +1056,66 @@ ...@@ -987,33 +1056,66 @@
} }
} }
}, },
"api_we.PutCardUserReq": { "api_we.BindCardUserRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": {
"description": "区域名字",
"type": "string",
"example": "温江实验中学"
},
"class": { "class": {
"description": "选填,班级,number", "description": "0无意义",
"type": "integer" "type": "integer"
}, },
"grade": { "grade": {
"description": "必填,\"1~9对应一年级~九年级,10~12对应高一~高三\"", "description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer" "type": "integer"
}, },
"id": {
"description": "学生ID",
"type": "integer"
},
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": { "name": {
"description": "必填,学生名字,maxLen=16", "type": "string"
"type": "string", },
"example": "汤圆" "service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
}, },
"sex": { "sex": {
"description": "选填,0女1男", "description": "0无意义 1女 2男",
"type": "integer" "type": "integer"
}, },
"stuNum": { "stuNum": {
"description": "选填,学号,字符串,maxLen=32", "description": "\"\"无意义",
"type": "string" "type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
}, },
"api_we.WeResUserInfoStruct": { "api_we.GetCardUserAndTrendRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": { "area": {
...@@ -1036,6 +1138,21 @@ ...@@ -1036,6 +1138,21 @@
"name": { "name": {
"type": "string" "type": "string"
}, },
"service": {
"description": "对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)",
"type": "array",
"items": {
"type": "integer"
},
"example": [
1,
2,
2,
0,
0,
0
]
},
"sex": { "sex": {
"description": "0无意义 1女 2男", "description": "0无意义 1女 2男",
"type": "integer" "type": "integer"
...@@ -1043,33 +1160,35 @@ ...@@ -1043,33 +1160,35 @@
"stuNum": { "stuNum": {
"description": "\"\"无意义", "description": "\"\"无意义",
"type": "string" "type": "string"
},
"trend": {
"type": "array",
"items": {
"$ref": "#/definitions/model.CacheCardUserTrendStruct"
}
} }
} }
}, },
"api_we.bindCardUserRes": { "api_we.GetCardUserInfoRes": {
"type": "object", "type": "object",
"properties": { "properties": {
"area": { "area": {
"description": "区域名字", "description": "区域名字",
"type": "string", "type": "string",
"example": "四川省成都市温江区实验中学" "example": "温江实验中学"
}, },
"class": { "class": {
"description": "0无意义",
"type": "integer" "type": "integer"
}, },
"grade": { "grade": {
"description": "\"1~9对应一年级~九年级,10~12对应高一~高三\"", "description": "0无意义 \"1~9对应一年级~九年级,10~12对应高一~高三\"",
"type": "integer" "type": "integer"
}, },
"id": { "id": {
"description": "学生ID", "description": "学生ID",
"type": "integer" "type": "integer"
}, },
"master": {
"description": "true:本来就是主家长,false:已成功绑定成副家长",
"type": "boolean",
"example": false
},
"name": { "name": {
"type": "string" "type": "string"
}, },
...@@ -1089,10 +1208,70 @@ ...@@ -1089,10 +1208,70 @@
] ]
}, },
"sex": { "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" "type": "integer"
}, },
"stuNum": { "stuNum": {
"description": "\"\"无意义",
"type": "string" "type": "string"
} }
} }
...@@ -1161,18 +1340,17 @@ ...@@ -1161,18 +1340,17 @@
"type": "integer" "type": "integer"
}, },
"expiryAt": { "expiryAt": {
"description": "到期时间",
"type": "string" "type": "string"
}, },
"family": { "family": {
"description": "亲情号列表", "description": "亲情号列表",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/api_we.familyNumStruct" "$ref": "#/definitions/model.CacheFamilyOnePerson"
} }
}, },
"monthMin": { "monthMin": {
"description": "月套餐使用分钟数", "description": "本月已使用分钟数",
"type": "integer" "type": "integer"
}, },
"monthPack": { "monthPack": {
...@@ -1184,7 +1362,7 @@ ...@@ -1184,7 +1362,7 @@
"type": "string" "type": "string"
}, },
"status": { "status": {
"description": "状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失", "description": "0无数据 1 正常使用 2 已挂失",
"type": "integer" "type": "integer"
} }
} }
...@@ -1277,28 +1455,7 @@ ...@@ -1277,28 +1455,7 @@
} }
} }
}, },
"api_we.wechatCardUsersTrendType": { "dbcurd.InsertTableUCardUserStruct": {
"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": {
"type": "object", "type": "object",
"properties": { "properties": {
"areaID": { "areaID": {
...@@ -1329,7 +1486,7 @@ ...@@ -1329,7 +1486,7 @@
} }
} }
}, },
"dbdao.TableBaseArea": { "dbcurd.TableBaseArea": {
"type": "object", "type": "object",
"properties": { "properties": {
"county_id": { "county_id": {
...@@ -1380,6 +1537,42 @@ ...@@ -1380,6 +1537,42 @@
"example": "四川省" "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": { "securityDefinitions": {
......
...@@ -21,26 +21,51 @@ definitions: ...@@ -21,26 +21,51 @@ definitions:
example: 海科学校 example: 海科学校
type: string type: string
type: object type: object
api_we.PutCardUserReq: api_we.BindCardUserRes:
properties: properties:
area:
description: 区域名字
example: 温江实验中学
type: string
class: class:
description: 选填,班级,number description: 0无意义
type: integer type: integer
grade: grade:
description: 必填,"1~9对应一年级~九年级,10~12对应高一~高三" description: 0无意义 "1~9对应一年级~九年级,10~12对应高一~高三"
type: integer type: integer
id:
description: 学生ID
type: integer
master:
description: true:本来就是主家长,false:已成功绑定成副家长
example: false
type: boolean
name: name:
description: 必填,学生名字,maxLen=16
example: 汤圆
type: string type: string
service:
description: 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
example:
- 1
- 2
- 2
- 0
- 0
- 0
items:
type: integer
type: array
sex: sex:
description: 选填,0女1 description: 0无意义 1女 2
type: integer type: integer
stuNum: stuNum:
description: 选填,学号,字符串,maxLen=32 description: '""无意义'
type: string type: string
trend:
items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
type: object type: object
api_we.WeResUserInfoStruct: api_we.GetCardUserAndTrendRes:
properties: properties:
area: area:
description: 区域名字 description: 区域名字
...@@ -57,31 +82,44 @@ definitions: ...@@ -57,31 +82,44 @@ definitions:
type: integer type: integer
name: name:
type: string type: string
service:
description: 对应6个数字对应公话、定位、饮水、卡消费、洗浴、洗衣机图标(0不显示,1正常,2显示但提示校区暂未开通该服务)
example:
- 1
- 2
- 2
- 0
- 0
- 0
items:
type: integer
type: array
sex: sex:
description: 0无意义 1女 2男 description: 0无意义 1女 2男
type: integer type: integer
stuNum: stuNum:
description: '""无意义' description: '""无意义'
type: string type: string
trend:
items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
type: object type: object
api_we.bindCardUserRes: api_we.GetCardUserInfoRes:
properties: properties:
area: area:
description: 区域名字 description: 区域名字
example: 四川省成都市温江区实验中学 example: 温江实验中学
type: string type: string
class: class:
description: 0无意义
type: integer type: integer
grade: grade:
description: '"1~9对应一年级~九年级,10~12对应高一~高三"' description: 0无意义 "1~9对应一年级~九年级,10~12对应高一~高三"
type: integer type: integer
id: id:
description: 学生ID description: 学生ID
type: integer type: integer
master:
description: true:本来就是主家长,false:已成功绑定成副家长
example: false
type: boolean
name: name:
type: string type: string
service: service:
...@@ -97,9 +135,53 @@ definitions: ...@@ -97,9 +135,53 @@ definitions:
type: integer type: integer
type: array type: array
sex: 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 type: integer
stuNum: stuNum:
description: '""无意义'
type: string type: string
type: object type: object
api_we.creatCardUserRes: api_we.creatCardUserRes:
...@@ -148,15 +230,14 @@ definitions: ...@@ -148,15 +230,14 @@ definitions:
description: 本月可修改亲情号次数 description: 本月可修改亲情号次数
type: integer type: integer
expiryAt: expiryAt:
description: 到期时间
type: string type: string
family: family:
description: 亲情号列表 description: 亲情号列表
items: items:
$ref: '#/definitions/api_we.familyNumStruct' $ref: '#/definitions/model.CacheFamilyOnePerson'
type: array type: array
monthMin: monthMin:
description: 月套餐使用分钟数 description: 本月已使用分钟数
type: integer type: integer
monthPack: monthPack:
description: 月套餐分钟数 description: 月套餐分钟数
...@@ -165,7 +246,7 @@ definitions: ...@@ -165,7 +246,7 @@ definitions:
description: 卡号 description: 卡号
type: string type: string
status: status:
description: 状态 0未绑定卡 1 正常使用 2 服务已到期 3 已挂失 description: 0无数据 1 正常使用 2 已挂失
type: integer type: integer
type: object type: object
api_we.slaveWeUserRes: api_we.slaveWeUserRes:
...@@ -230,22 +311,7 @@ definitions: ...@@ -230,22 +311,7 @@ definitions:
$ref: '#/definitions/api_we.WeResUserInfoStruct' $ref: '#/definitions/api_we.WeResUserInfoStruct'
type: array type: array
type: object type: object
api_we.wechatCardUsersTrendType: dbcurd.InsertTableUCardUserStruct:
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:
properties: properties:
areaID: areaID:
description: 必填,校区ID description: 必填,校区ID
...@@ -268,7 +334,7 @@ definitions: ...@@ -268,7 +334,7 @@ definitions:
description: 选填,学号,字符串,maxLen=32 description: 选填,学号,字符串,maxLen=32
type: string type: string
type: object type: object
dbdao.TableBaseArea: dbcurd.TableBaseArea:
properties: properties:
county_id: county_id:
description: 必填,所属区县ID description: 必填,所属区县ID
...@@ -307,6 +373,32 @@ definitions: ...@@ -307,6 +373,32 @@ definitions:
example: 四川省 example: 四川省
type: string type: string
type: object 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: info:
contact: {} contact: {}
description: 用于家长端微信小程序及web端管理后台 description: 用于家长端微信小程序及web端管理后台
...@@ -324,7 +416,7 @@ paths: ...@@ -324,7 +416,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/dbdao.TableBaseArea' $ref: '#/definitions/dbcurd.TableBaseArea'
produces: produces:
- application/json - application/json
responses: responses:
...@@ -500,14 +592,14 @@ paths: ...@@ -500,14 +592,14 @@ paths:
"0": "0":
description: 学生信息 description: 学生信息
schema: schema:
$ref: '#/definitions/api_we.bindCardUserRes' $ref: '#/definitions/api_we.BindCardUserRes'
"30": "30":
description: 邀请码无效 description: 邀请码无效
"31": "31":
description: 邀请码已过期 description: 邀请码已过期
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 通过邀请码绑定学生 summary: 通过邀请码绑定学生 [complete]
tags: tags:
- 家长微信 - 家长微信
/we/callrecord/{id}: /we/callrecord/{id}:
...@@ -648,7 +740,7 @@ paths: ...@@ -648,7 +740,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/dbdao.InsertTableUserCardUserStruct' $ref: '#/definitions/dbcurd.InsertTableUCardUserStruct'
produces: produces:
- application/json - application/json
responses: responses:
...@@ -658,7 +750,7 @@ paths: ...@@ -658,7 +750,7 @@ paths:
$ref: '#/definitions/api_we.creatCardUserRes' $ref: '#/definitions/api_we.creatCardUserRes'
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 创建一个学生 [complete](同一微信号并发创建学生,WechatCustomerMap缓存弱安全) summary: 创建一个学生 [同一微信号并发创建学生,WechatCustomerMap缓存弱安全complete]
tags: tags:
- 家长微信 - 家长微信
/we/carduser/{id}: /we/carduser/{id}:
...@@ -677,7 +769,27 @@ paths: ...@@ -677,7 +769,27 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - 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: tags:
- 家长微信 - 家长微信
put: put:
...@@ -706,6 +818,27 @@ paths: ...@@ -706,6 +818,27 @@ paths:
summary: 修改学生信息 summary: 修改学生信息
tags: 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: /we/familynum:
delete: delete:
consumes: consumes:
...@@ -809,7 +942,7 @@ paths: ...@@ -809,7 +942,7 @@ paths:
- 家长微信 - 家长微信
/we/phonecardstatus/{id}: /we/phonecardstatus/{id}:
get: get:
description: 传学生ID至后台,后台返回卡信息 description: 传学生ID至后台,后台返回卡状态
parameters: parameters:
- description: 学生ID - description: 学生ID
in: path in: path
...@@ -825,10 +958,10 @@ paths: ...@@ -825,10 +958,10 @@ paths:
$ref: '#/definitions/api_we.getPhoneCardStatusRes' $ref: '#/definitions/api_we.getPhoneCardStatusRes'
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 获取学生公话卡状态 summary: 获取学生公话卡状态(含亲情号信息) [complete]
tags: tags:
- 家长微信 - 家长微信
/we/sharecode/{id}: /we/sharestring/{id}:
get: get:
description: 主家长生成邀请码,有效时长可选1分钟~60分钟 description: 主家长生成邀请码,有效时长可选1分钟~60分钟
parameters: parameters:
...@@ -851,7 +984,7 @@ paths: ...@@ -851,7 +984,7 @@ paths:
type: string type: string
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 获取邀请码(仅主家长有权限) summary: 获取邀请码(仅主家长有权限) [complete]
tags: tags:
- 家长微信 - 家长微信
/we/slaveweuser/{id}: /we/slaveweuser/{id}:
...@@ -904,10 +1037,12 @@ paths: ...@@ -904,10 +1037,12 @@ paths:
"200": "200":
description: 学生动态信息 description: 学生动态信息
schema: schema:
$ref: '#/definitions/api_we.wechatCardUsersTrendType' items:
$ref: '#/definitions/model.CacheCardUserTrendStruct'
type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 微信学生首页,获取近20条用户最新动态 summary: 微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态
tags: tags:
- 家长微信 - 家长微信
securityDefinitions: securityDefinitions:
......
...@@ -2,7 +2,7 @@ package tencent ...@@ -2,7 +2,7 @@ package tencent
import "errors" import "errors"
func TencentCode2Session(code string) (string, error) { func WechatCode2Session(code string) (string, error) {
var testTemp = map[string]string{ var testTemp = map[string]string{
"codeTest1": "unionIDTest1", "codeTest1": "unionIDTest1",
"codeTest2": "unionIDTest2", "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