Commit 5e84e218 by zhangjiec

1. 增加部分接口

parent 63e35752
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"
)
// CardBind 绑定卡
// @Tags 家长微信
// @Summary 绑定卡 [complete]
// @Description 传学生id及卡类型、卡号至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param code query string true "卡号"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)"
// @Success 0
// @Router /we/cardbind/{id} [PUT]
// @Security ApiKeyAuth
func CardBind(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("CardBind",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
cardUserInfo, r := cache.GetCardUserInfoAndCheckCardUserMaserAndSlaveWeID(cardUserID, weUserID)
if r < 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
pType, _ := strconv.Atoi(c.Query("type"))
if pType != 1 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " type暂时只支持1",
})
return
}
simID := c.Query("code")
if len(simID) == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " code不能为空",
})
return
}
//if len(cardUserInfo.SimCardID)>0{
// if cardUserInfo.SimCardID == simID {
//
// }
// c.JSON(http.StatusOK, gin.H{
// "code": api.ErrorReqPara,
// "message": "错误:已绑卡号"+cardUserInfo.SimCardID,
// })
// return
//}
// 获取sim卡信息
simInfo := cache.GetSimInfo(simID)
if simInfo == nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": "输入的卡号错误:系统找不到该卡号",
})
return
}
// 如果已经绑定了学生,则不可绑定
if simInfo.CardUserID != 0 {
if simInfo.CardUserID == cardUserID {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": "输入的卡号错误:此卡号已被绑定",
})
}
return
}
// 校区对不上,不允许绑定
areaServiceInfo := cache.GetAreaServiceInfo(simInfo.AreaServiceID)
if areaServiceInfo == nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("CardBind simInfo.AreaServiceID在AreaServiceMap找不到",
zap.Uint32("simInfo.AreaServiceID", simInfo.AreaServiceID))
return
}
if areaServiceInfo.AreaID != cardUserInfo.AreaID { // 卡号跟绑定的校区不对应
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": "输入的卡号错误:非运营商绑定的本校区卡号",
})
return
}
// 操作数据库
if dbcurd.UpdateUSimInfoCardUserID(simID, cardUserID) {
// CardUserMap SimInfoMap 并发不安全
cardUserInfo.SimCardID = simID
cache.CardUserMap.Store(cardUserID, *cardUserInfo) // todo 并发不安全 所有的store delete都封装一下
simInfo.CardUserID = cardUserID
cache.SimInfoMap.Store(simID, *simInfo)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
}
}
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"
)
// CardLoss 卡挂失/解挂
// @Tags 家长微信
// @Summary 卡挂失/解挂 [complete]
// @Description 传学生id及卡类型至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param loss query integer true "1解挂,2挂失,其他预留无意义"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)" default(1)
// @Success 0
// @Router /we/cardloss/{id} [PUT]
// @Security ApiKeyAuth
func CardLoss(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")
masterWeUserID := v.(uint32)
if ok != true || masterWeUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("CardLoss",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(cardUserID, masterWeUserID) < 2 { //todo 从userinfo查
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
pType, _ := strconv.Atoi(c.Query("type"))
if pType != 1 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " type暂时只支持1",
})
return
}
status, _ := strconv.Atoi(c.Query("loss"))
if status == 0 || status > 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " loss内容不正确",
})
return
}
userInfo := cache.GetCardUserInfo(cardUserID)
if userInfo == nil { //查不到用户信息
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
return
}
if len(userInfo.SimCardID) == 0 { //用户没绑卡
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserNotHavePhoneCard,
"data": api.CodeMsg[api.ErrorUserNotHavePhoneCard],
})
return
}
if dbcurd.UpdateUSimInfoStatus(userInfo.SimCardID, uint8(status)) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
return
}
simInfo := cache.GetSimInfo(userInfo.SimCardID)
if simInfo != nil { // 这里并发不安全
simInfo.Status = uint8(status)
cache.SimInfoMap.Store(userInfo.SimCardID, *simInfo)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
}
}
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"
)
// DeleteCardBind 解绑卡
// @Tags 家长微信
// @Summary 解绑卡 [complete]
// @Description 传学生id及卡类型至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)"
// @Success 0
// @Router /we/cardbind/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteCardBind(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("CardLoss",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
cardUserInfo, role := cache.GetCardUserInfoAndCheckCardUserMaserAndSlaveWeID(cardUserID, weUserID)
if role < 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
pType, _ := strconv.Atoi(c.Query("type"))
if pType != 1 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + " type暂时只支持1",
})
return
}
if len(cardUserInfo.SimCardID) == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
return
}
// 获取sim卡信息
simInfoP := cache.GetSimInfo(cardUserInfo.SimCardID)
if simInfoP == nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": "输入的卡号错误:系统找不到该卡号",
})
return
}
if dbcurd.UpdateUSimInfoCardUserID(cardUserInfo.SimCardID, 0) { // 数据库将sim卡信息里对应的学生ID置0
simID := cardUserInfo.SimCardID
cardUserInfo.SimCardID = ""
cache.CardUserMap.Store(cardUserID, *cardUserInfo) // todo 并发不安全 所有的store delete都封装一下
simInfoP.CardUserID = 0
cache.SimInfoMap.Store(simID, *simInfoP)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
}
}
...@@ -43,8 +43,8 @@ func DeleteCardUser(c *gin.Context) { ...@@ -43,8 +43,8 @@ func DeleteCardUser(c *gin.Context) {
return return
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
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],
...@@ -58,6 +58,14 @@ func DeleteCardUser(c *gin.Context) { ...@@ -58,6 +58,14 @@ func DeleteCardUser(c *gin.Context) {
}) })
return return
} }
// 如果绑卡,需解绑再删除
if len(cardUserInfo.SimCardID) > 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorDeleteCardUserHaveSimCard,
"message": api.CodeMsg[api.ErrorDeleteCardUserHaveSimCard],
})
return
}
// 先删库 软删除 事务处理u_card_user和u_we_card_user // 先删库 软删除 事务处理u_card_user和u_we_card_user
if dbcurd.UpdateUCardUserAndUWeCardUserDeleteAt(cardUserID) == false { if dbcurd.UpdateUCardUserAndUWeCardUserDeleteAt(cardUserID) == false {
......
package api_we 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"
)
// DeleteSlaveBindCardUser 副家长解绑学生
// @Tags 家长微信
// @Summary 副家长解绑学生 [complete]
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0
// @Router /we/bindcarduser/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteSlaveBindCardUser(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("DeleteSlaveBindCardUser",
zap.Reflect("c.Get(\"userID\")", v))
return
}
if dbcurd.UpdateUWeCardUserDeleteAt(weUserID, cardUserID) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
}
cache.DeleteAStudentIDInWechatCustomerMap(weUserID, cardUserID, false)
cache.DeleteASlaveWeUserIDInCardUserMap(weUserID, cardUserID)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
// MasterDeleteSlaveWeUser 删除副家长(仅主家长有权限)
// @Tags 家长微信
// @Summary 删除副家长(仅主家长有权限) [complete]
// @Description 传学生ID和微信UnionID,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param weUserID query integer true "副家长微信weUserID"
// @Success 0
// @Router /we/slaveweuser/{id} [DELETE]
// @Security ApiKeyAuth
func MasterDeleteSlaveWeUser(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")
masterWeUserID := v.(uint32)
if ok != true || masterWeUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("DeleteSlaveBindCardUser",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(cardUserID, masterWeUserID) != 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
weUserIDInt, _ := strconv.Atoi(c.Query("id"))
weUserID := uint32(weUserIDInt)
if weUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqPara,
"message": api.CodeMsg[api.ErrorReqPara] + "副家长ID不正确",
})
return
}
if dbcurd.UpdateUWeCardUserDeleteAt(weUserID, cardUserID) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
}
cache.DeleteAStudentIDInWechatCustomerMap(weUserID, cardUserID, false)
cache.DeleteASlaveWeUserIDInCardUserMap(weUserID, cardUserID)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
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"
)
// GetCallRecord 查询通话记录
// @Tags 家长微信
// @Summary 查询通话记录 [complete]
// @Description 传学生ID至后台,后台返回通话记录列表
// @Produce json
// @Param id path integer true "学生ID"
// @Param pnum query integer false "页数,选填,不填则默认第0页"
// @Param psize query integer false "页条数,选填,不填则不分页全部返回"
// @Param start query string false "起始时间时间和结束时间同时填或同时不填,可以是纯年月日2021-10-01,也可以是带时间年月日时分2021-10-01 10:00或年月日时分秒2021-10-01 10:00:00,年月日时分秒没带全的默认后面为00" default(2021-10-01)
// @Param end query string false "起始时间时间和结束时间同时填或同时不填,可以是纯年月日2021-10-01,也可以是带时间年月日时分2021-10-01 10:00或年月日时分秒2021-10-01 10:00:00,年月日时分秒没带全的默认后面为00" default(2021-10-31 23:59:59)
// @Param asc query bool false "是否升序,选填,不填则是降序" default(false)
// @Success 0 {object} []model.SelectWeGetCallRecordStruct "通话记录列表"
// @Router /we/callrecord/{id} [GET]
// @Security ApiKeyAuth
func GetCallRecord(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")
masterWeUserID := v.(uint32)
if ok != true || masterWeUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("GetCallRecord",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(cardUserID, masterWeUserID) < 2 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
pNum, _ := strconv.Atoi(c.Query("pnum"))
pSize, _ := strconv.Atoi(c.Query("psize"))
startTime := c.Query("start")
endTime := c.Query("end")
desc := "desc"
if c.Query("asc") == "true" {
desc = "asc"
}
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": dbcurd.SelectWeGetCallRecord(cardUserID, startTime, endTime, desc, pNum, pSize),
})
}
...@@ -3,7 +3,6 @@ package api_we ...@@ -3,7 +3,6 @@ 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/data_db_cache/model" "dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -50,8 +49,8 @@ func GetCardUserAndTrend(c *gin.Context) { ...@@ -50,8 +49,8 @@ func GetCardUserAndTrend(c *gin.Context) {
return return
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
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],
...@@ -78,7 +77,7 @@ func GetCardUserAndTrend(c *gin.Context) { ...@@ -78,7 +77,7 @@ func GetCardUserAndTrend(c *gin.Context) {
StuNum: cardUserInfo.StuNum, StuNum: cardUserInfo.StuNum,
}, },
Service: [6]uint8{1, 2, 2, 2, 2, 2}, Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取 Trend: cache.GetCardUserTrendMapByCardUserID(cardUserID),
}, },
}) })
} }
...@@ -17,7 +17,7 @@ type GetCardUserInfoRes struct { ...@@ -17,7 +17,7 @@ type GetCardUserInfoRes struct {
// GetCardUser 获取单个学生信息 // GetCardUser 获取单个学生信息
// @Tags 家长微信 // @Tags 家长微信
// @Summary 获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态 // @Summary 获取单个学生信息 [complete]
// @Description 传学生的ID,后台返回学生信息 // @Description 传学生的ID,后台返回学生信息
// @Produce json // @Produce json
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
...@@ -47,8 +47,8 @@ func GetCardUser(c *gin.Context) { ...@@ -47,8 +47,8 @@ func GetCardUser(c *gin.Context) {
return return
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
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],
......
...@@ -47,8 +47,8 @@ func GetCardUserShareCode(c *gin.Context) { ...@@ -47,8 +47,8 @@ func GetCardUserShareCode(c *gin.Context) {
return return
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
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],
...@@ -176,8 +176,8 @@ func BindCardUser(c *gin.Context) { ...@@ -176,8 +176,8 @@ func BindCardUser(c *gin.Context) {
}) })
return return
} }
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorShareCode, "code": api.ErrorShareCode,
"message": api.CodeMsg[api.ErrorShareCode], "message": api.CodeMsg[api.ErrorShareCode],
...@@ -212,7 +212,7 @@ func BindCardUser(c *gin.Context) { ...@@ -212,7 +212,7 @@ func BindCardUser(c *gin.Context) {
StuNum: cardUserInfo.StuNum, StuNum: cardUserInfo.StuNum,
}, },
Service: [6]uint8{1, 2, 2, 2, 2, 2}, Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取 Trend: cache.GetCardUserTrendMapByCardUserID(cardUserID),
}, },
}, },
}) })
...@@ -234,7 +234,7 @@ func BindCardUser(c *gin.Context) { ...@@ -234,7 +234,7 @@ func BindCardUser(c *gin.Context) {
StuNum: cardUserInfo.StuNum, StuNum: cardUserInfo.StuNum,
}, },
Service: [6]uint8{1, 2, 2, 2, 2, 2}, Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取 Trend: cache.GetCardUserTrendMapByCardUserID(cardUserID),
}, },
}, },
}) })
...@@ -254,8 +254,8 @@ func BindCardUser(c *gin.Context) { ...@@ -254,8 +254,8 @@ func BindCardUser(c *gin.Context) {
cache.InsertNewStudentIDToWechatCustomerMap(weUserID, cardUserID, false) cache.InsertNewStudentIDToWechatCustomerMap(weUserID, cardUserID, false)
cache.InsertWechatAndCardUserRelationToCardUserMap(weUserID, cardUserID, false) cache.InsertWechatAndCardUserRelationToCardUserMap(weUserID, cardUserID, false)
cardUserInfo, ok = cache.GetCardUserInfo(cardUserID) cardUserInfo = cache.GetCardUserInfo(cardUserID)
if ok == false { // 刚才都有,在就没有了呢 if cardUserInfo == nil { // 刚才都有,在就没有了呢
logger.Log.Error("BindCardUser cache.GetCardUserInfo(cardUserID) 突然没有了", logger.Log.Error("BindCardUser cache.GetCardUserInfo(cardUserID) 突然没有了",
zap.Uint32("cardUserID", cardUserID), zap.Uint32("cardUserID", cardUserID),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
...@@ -280,7 +280,7 @@ func BindCardUser(c *gin.Context) { ...@@ -280,7 +280,7 @@ func BindCardUser(c *gin.Context) {
StuNum: cardUserInfo.StuNum, StuNum: cardUserInfo.StuNum,
}, },
Service: [6]uint8{1, 2, 2, 2, 2, 2}, Service: [6]uint8{1, 2, 2, 2, 2, 2},
Trend: dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID), // todo 改成从缓存取 Trend: cache.GetCardUserTrendMapByCardUserID(cardUserID),
}, },
}, },
}) })
......
...@@ -3,7 +3,6 @@ package api_we ...@@ -3,7 +3,6 @@ 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"
...@@ -13,7 +12,7 @@ import ( ...@@ -13,7 +12,7 @@ import (
// GetCardUserTrend 微信学生首页,获取近20条用户最新动态 // GetCardUserTrend 微信学生首页,获取近20条用户最新动态
// @Tags 家长微信 // @Tags 家长微信
// @Summary 微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态 // @Summary 微信学生首页,获取近20条用户最新动态 [complete]
// @Description 微信学生首页,获取近20条用户最新动态 // @Description 微信学生首页,获取近20条用户最新动态
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
// @Product json // @Product json
...@@ -54,6 +53,6 @@ func GetCardUserTrend(c *gin.Context) { ...@@ -54,6 +53,6 @@ func GetCardUserTrend(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.Success, "code": api.Success,
"data": dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(uint32(cardUserID)), // todo 改成从缓存取 "data": cache.GetCardUserTrendMapByCardUserID(uint32(cardUserID)), // todo 改成从缓存取
}) })
} }
...@@ -69,8 +69,8 @@ func GetPhoneCardStatus(c *gin.Context) { ...@@ -69,8 +69,8 @@ func GetPhoneCardStatus(c *gin.Context) {
} }
// 查出该学生信息 // 查出该学生信息
cardUserInfo, ok := cache.GetCardUserInfo(cardUserID) cardUserInfo := cache.GetCardUserInfo(cardUserID)
if ok == false { if cardUserInfo == nil {
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],
...@@ -79,21 +79,32 @@ func GetPhoneCardStatus(c *gin.Context) { ...@@ -79,21 +79,32 @@ func GetPhoneCardStatus(c *gin.Context) {
} }
if cardUserInfo.SimCardID == "" { if cardUserInfo.SimCardID == "" {
c.JSON(http.StatusOK, gin.H{ c.JSON(
"code": api.ErrorUserNotHavePhoneCard, http.StatusOK,
"message": api.CodeMsg[api.ErrorUserNotHavePhoneCard], gin.H{
}) "code": api.Success,
"data": getPhoneCardStatusRes{}, //学生未绑卡
},
)
return return
} }
c.JSON( res := cache.GetSimInfo(cardUserInfo.SimCardID)
http.StatusOK, if res != nil {
gin.H{ c.JSON(
"code": api.Success, http.StatusOK,
"data": getPhoneCardStatusRes{ gin.H{
cardUserInfo.SimCardID, "code": api.Success,
cache.GetSimInfo(cardUserInfo.SimCardID), "data": getPhoneCardStatusRes{
cardUserInfo.SimCardID,
*res,
},
}, },
}, )
) } else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
}
} }
...@@ -2,9 +2,12 @@ package api_we ...@@ -2,9 +2,12 @@ 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/logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http" "net/http"
"time" "strconv"
) )
type slaveWeUserRes struct { type slaveWeUserRes struct {
...@@ -17,7 +20,7 @@ type slaveWeUserRes struct { ...@@ -17,7 +20,7 @@ type slaveWeUserRes struct {
// 手机号 // 手机号
Phone string `json:"phone"` Phone string `json:"phone"`
// 绑定时间 // 绑定时间
CreateAt time.Time `json:"createAt"` // CreateAt time.Time `json:"createAt"`
} }
//type getBindCardUserRes struct { //type getBindCardUserRes struct {
...@@ -27,18 +30,73 @@ type slaveWeUserRes struct { ...@@ -27,18 +30,73 @@ type slaveWeUserRes struct {
// ShareCode string `json:"shareCode"` // ShareCode string `json:"shareCode"`
//} //}
// GetBindCardUser 获取学生副家长列表(仅主家长有权限) // GetSlaveBindCardUser 获取学生副家长列表(仅主家长有权限)
// @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"
// @Success 0 {object} []slaveWeUserRes "副家长信息列表" // @Success 0 {object} []slaveWeUserRes "副家长信息列表"
// @Router /we/bindcarduser/{id} [GET] // @Router /we/bindcarduser/{id} [GET]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func GetBindCardUser(c *gin.Context) { func GetSlaveBindCardUser(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")
masterWeUserID := v.(uint32)
if ok != true || masterWeUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("DeleteSlaveBindCardUser",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 查出该学生信息
cardUserInfo := cache.GetCardUserInfo(cardUserID)
if cardUserInfo == nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
// 主家长权限才可查
if cardUserInfo.MasterWechatUserID != masterWeUserID {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"message": api.CodeMsg[api.ErrorUserRole],
})
return
}
res := make([]slaveWeUserRes, 0)
for _, v = range cardUserInfo.SlaveWechatUserID {
slaveInfo := cache.GetWeUserInfoFromMapAndDB(v.(uint32))
if slaveInfo != nil {
res = append(res, slaveWeUserRes{
v.(uint32),
slaveInfo.Nickname,
slaveInfo.AvatarURL,
slaveInfo.WePhone,
})
}
}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.Success, "code": api.Success,
"data": []slaveWeUserRes{}, "data": res,
}) })
} }
...@@ -75,16 +75,15 @@ func WeLogin(c *gin.Context) { ...@@ -75,16 +75,15 @@ func WeLogin(c *gin.Context) {
} }
} }
} }
var userInfo model.CacheWeCustomerStruct var userInfo *model.CacheWeCustomerStruct
var haveInfo bool
if userID != 0 { if userID != 0 {
userInfo, haveInfo = cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, nowTime) userInfo = cache.GetWechatCustomerInfoAndCacheUpdateTokenTime(userID, nowTime)
if haveInfo { if userInfo != nil {
dbcurd.UpdateUWeCustomerLoginTime(userID) dbcurd.UpdateUWeCustomerLoginTime(userID)
} }
} }
if haveInfo == false { // 微信服务器登录 if userInfo == nil { // 微信服务器登录
unionID, err := tencent2.WechatCode2Session(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{
...@@ -95,8 +94,18 @@ func WeLogin(c *gin.Context) { ...@@ -95,8 +94,18 @@ func WeLogin(c *gin.Context) {
} }
userID = cache.GetWechatCustomerUserIDByUnionID(unionID) userID = cache.GetWechatCustomerUserIDByUnionID(unionID)
if userID == 0 { // 原来没有,只有注册 if userID == 0 { // 原来没有,只有注册
userInfo.TokenCreatTime = nowTime var res uint8
userID = cache.InsertWechatCustomerMap(unionID, &userInfo) userID, res = dbcurd.InsertUWeCustomerUnionID(unionID) //插入
if res == dbcurd.InsertSysErr {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"message": api.CodeMsg[api.ErrorSystemBusy],
})
return
}
if res == dbcurd.InsertDuplicate {
userInfo, userID = dbcurd.SelectUWeCustomerByUnionIDToCacheModel(unionID)
}
if userID == 0 { if userID == 0 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr, "code": api.ErrorSystemErr,
...@@ -104,9 +113,14 @@ func WeLogin(c *gin.Context) { ...@@ -104,9 +113,14 @@ func WeLogin(c *gin.Context) {
}) })
return return
} }
userInfo = &model.CacheWeCustomerStruct{
TokenCreatTime: nowTime,
}
cache.WechatCustomerUnionIDToIDMAP.Store(unionID, userID)
cache.WechatCustomerMap.Store(userID, *userInfo)
} else { // 已有用户 } else { // 已有用户
userInfo, haveInfo = cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, nowTime) userInfo = cache.GetWechatCustomerInfoAndCacheUpdateTokenTime(userID, nowTime)
if haveInfo { if userInfo != nil {
dbcurd.UpdateUWeCustomerLoginTime(userID) dbcurd.UpdateUWeCustomerLoginTime(userID)
} else { } else {
cache.WechatCustomerMap.Delete(userID) cache.WechatCustomerMap.Delete(userID)
...@@ -131,8 +145,8 @@ func WeLogin(c *gin.Context) { ...@@ -131,8 +145,8 @@ func WeLogin(c *gin.Context) {
} }
for _, cardUserID := range userInfo.MasterCardUserID { for _, cardUserID := range userInfo.MasterCardUserID {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok { cardUserInfo := cache.GetCardUserInfo(cardUserID)
var areaInfo model.CacheBAreaStruct if cardUserInfo != nil {
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
upInfo.Name = cardUserInfo.Name upInfo.Name = cardUserInfo.Name
...@@ -141,9 +155,10 @@ func WeLogin(c *gin.Context) { ...@@ -141,9 +155,10 @@ func WeLogin(c *gin.Context) {
upInfo.Class = cardUserInfo.Class upInfo.Class = cardUserInfo.Class
upInfo.StuNum = cardUserInfo.StuNum upInfo.StuNum = cardUserInfo.StuNum
// upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2} // upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2}
if cache.GetAreaMapInfo(cardUserInfo.AreaID, &areaInfo) { areaInfoP := cache.GetAreaMapInfo(cardUserInfo.AreaID)
if areaInfo.Status == 1 || (areaInfo.Status == 2 && userInfo.TestRole) { if areaInfoP != nil {
upInfo.Area = areaInfo.Name if areaInfoP.Status == 1 || (areaInfoP.Status == 2 && userInfo.TestRole) {
upInfo.Area = areaInfoP.Name
} }
} }
res.Master = append(res.Master, upInfo) res.Master = append(res.Master, upInfo)
...@@ -151,8 +166,8 @@ func WeLogin(c *gin.Context) { ...@@ -151,8 +166,8 @@ func WeLogin(c *gin.Context) {
} }
for _, cardUserID := range userInfo.SlaveCardUserID { for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok { cardUserInfo := cache.GetCardUserInfo(cardUserID)
var areaInfo model.CacheBAreaStruct if cardUserInfo != nil {
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
upInfo.Name = cardUserInfo.Name upInfo.Name = cardUserInfo.Name
...@@ -161,9 +176,10 @@ func WeLogin(c *gin.Context) { ...@@ -161,9 +176,10 @@ func WeLogin(c *gin.Context) {
upInfo.Class = cardUserInfo.Class upInfo.Class = cardUserInfo.Class
upInfo.StuNum = cardUserInfo.StuNum upInfo.StuNum = cardUserInfo.StuNum
// upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2} // upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2}
if cache.GetAreaMapInfo(cardUserInfo.AreaID, &areaInfo) { areaInfoP := cache.GetAreaMapInfo(cardUserInfo.AreaID)
if areaInfo.Status == 1 || (areaInfo.Status == 2 && userInfo.TestRole) { if areaInfoP != nil {
upInfo.Area = areaInfo.Name if areaInfoP.Status == 1 || (areaInfoP.Status == 2 && userInfo.TestRole) {
upInfo.Area = areaInfoP.Name
} }
} }
res.Slave = append(res.Slave, upInfo) res.Slave = append(res.Slave, upInfo)
...@@ -197,8 +213,8 @@ func GetStudentList(c *gin.Context) { ...@@ -197,8 +213,8 @@ func GetStudentList(c *gin.Context) {
return return
} }
userInfo, ok := cache.GetWechatCustomerInfoAndCanUpdateTokenTime(userID, 0) userInfo := cache.GetWeUserInfoFromMapAndDB(userID)
if ok == false { // 微信服务器登录 if userInfo == nil { // 微信服务器登录
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],
...@@ -208,8 +224,8 @@ func GetStudentList(c *gin.Context) { ...@@ -208,8 +224,8 @@ 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.GetCardUserInfo(cardUserID); ok { cardUserInfo := cache.GetCardUserInfo(cardUserID)
var areaInfo model.CacheBAreaStruct if cardUserInfo != nil {
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
upInfo.Name = cardUserInfo.Name upInfo.Name = cardUserInfo.Name
...@@ -218,9 +234,10 @@ func GetStudentList(c *gin.Context) { ...@@ -218,9 +234,10 @@ func GetStudentList(c *gin.Context) {
upInfo.Class = cardUserInfo.Class upInfo.Class = cardUserInfo.Class
upInfo.StuNum = cardUserInfo.StuNum upInfo.StuNum = cardUserInfo.StuNum
// upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2} // upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2}
if cache.GetAreaMapInfo(cardUserInfo.AreaID, &areaInfo) { areaInfoP := cache.GetAreaMapInfo(cardUserInfo.AreaID)
if areaInfo.Status == 1 || (areaInfo.Status == 2 && userInfo.TestRole) { if areaInfoP != nil {
upInfo.Area = areaInfo.Name if areaInfoP.Status == 1 || (areaInfoP.Status == 2 && userInfo.TestRole) {
upInfo.Area = areaInfoP.Name
} }
} }
res.Master = append(res.Master, upInfo) res.Master = append(res.Master, upInfo)
...@@ -228,8 +245,8 @@ func GetStudentList(c *gin.Context) { ...@@ -228,8 +245,8 @@ func GetStudentList(c *gin.Context) {
} }
for _, cardUserID := range userInfo.SlaveCardUserID { for _, cardUserID := range userInfo.SlaveCardUserID {
if cardUserInfo, ok := cache.GetCardUserInfo(cardUserID); ok { cardUserInfo := cache.GetCardUserInfo(cardUserID)
var areaInfo model.CacheBAreaStruct if cardUserInfo != nil {
var upInfo WeResUserInfoStruct var upInfo WeResUserInfoStruct
upInfo.ID = cardUserID upInfo.ID = cardUserID
upInfo.Name = cardUserInfo.Name upInfo.Name = cardUserInfo.Name
...@@ -238,9 +255,10 @@ func GetStudentList(c *gin.Context) { ...@@ -238,9 +255,10 @@ func GetStudentList(c *gin.Context) {
upInfo.Class = cardUserInfo.Class upInfo.Class = cardUserInfo.Class
upInfo.StuNum = cardUserInfo.StuNum upInfo.StuNum = cardUserInfo.StuNum
// upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2} // upInfo.Service = [6]uint8{1, 2, 2, 2, 2, 2}
if cache.GetAreaMapInfo(cardUserInfo.AreaID, &areaInfo) { areaInfoP := cache.GetAreaMapInfo(cardUserInfo.AreaID)
if areaInfo.Status == 1 || (areaInfo.Status == 2 && userInfo.TestRole) { if areaInfoP != nil {
upInfo.Area = areaInfo.Name if areaInfoP.Status == 1 || (areaInfoP.Status == 2 && userInfo.TestRole) {
upInfo.Area = areaInfoP.Name
} }
} }
res.Slave = append(res.Slave, upInfo) res.Slave = append(res.Slave, upInfo)
......
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"
)
// PutCardUser 修改学生信息
// @Tags 家长微信
// @Summary 修改学生信息 [complete]
// @Description 传学生id及新信息至后台,后台返回成功失败
// @Accept json
// @Produce json
// @Param id path integer true "学生ID"
// @Param data body model.UpdateUCardUserInfoStruct true "学生信息"
// @Success 0
// @Router /we/carduser/{id} [PUT]
// @Security ApiKeyAuth
func PutCardUser(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")
masterWeUserID := v.(uint32)
if ok != true || masterWeUserID == 0 {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
logger.Log.Error("DeleteSlaveBindCardUser",
zap.Reflect("c.Get(\"userID\")", v))
return
}
// 校验weUserID是否有cardUserID权限
if cache.CheckCardUserMaserAndSlaveWeID(cardUserID, masterWeUserID) < 2 { // todo 其实后面会查,所以这里不用调这个函数,但是暂时并发不安全,先查一盘,后面查完马上改
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorUserRole,
"data": api.CodeMsg[api.ErrorUserRole],
})
return
}
var reqData model.UpdateUCardUserInfoStruct
err := c.ShouldBindJSON(&reqData)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorReqParaFormat,
"message": api.CodeMsg[api.ErrorReqParaFormat],
})
return
}
if dbcurd.UpdateUCardUserInfo(cardUserID, &reqData) == false {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemBusy,
"data": api.CodeMsg[api.ErrorSystemBusy],
})
return
}
userInfo := cache.GetCardUserInfo(cardUserID)
if userInfo != nil { // 这里并发不安全
userInfo.Sex = reqData.Sex
userInfo.Grade = reqData.Grade
userInfo.Class = reqData.Class
userInfo.Name = reqData.Name
userInfo.StuNum = reqData.StudentNo
cache.CardUserMap.Store(cardUserID, *userInfo)
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": api.ErrorSystemErr,
"data": api.CodeMsg[api.ErrorSystemErr],
})
}
}
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"dc_golang_server_1/api" "dc_golang_server_1/api"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
"time"
) )
//// PutCardUserShareOn 打开邀请码开关(仅主家长有权限) //// PutCardUserShareOn 打开邀请码开关(仅主家长有权限)
...@@ -37,22 +36,6 @@ import ( ...@@ -37,22 +36,6 @@ import (
// }) // })
//} //}
// DeleteSlaveWeUser 删除副家长(仅主家长有权限)
// @Tags 家长微信
// @Summary 删除副家长(仅主家长有权限)
// @Description 传学生ID和微信UnionID,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param weUserID query integer true "副家长微信weUserID"
// @Success 0
// @Router /we/slaveweuser/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteSlaveWeUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
//// DeleteAllSlaveWeUser 清空所有副家长(仅主家长有权限) //// DeleteAllSlaveWeUser 清空所有副家长(仅主家长有权限)
//// @Tags 家长微信 //// @Tags 家长微信
//// @Summary 删除副家长(仅主家长有权限) //// @Summary 删除副家长(仅主家长有权限)
...@@ -69,123 +52,6 @@ func DeleteSlaveWeUser(c *gin.Context) { ...@@ -69,123 +52,6 @@ func DeleteSlaveWeUser(c *gin.Context) {
// }) // })
//} //}
type PutCardUserReq struct {
// 必填,学生名字,maxLen=16
Name string `json:"name" example:"汤圆"`
// 必填,"1~9对应一年级~九年级,10~12对应高一~高三"
Grade int8 `json:"grade"`
// 选填,0女1男
Sex uint8 `json:"sex,omitempty"`
// 选填,班级,number
Class int8 `json:"class,omitempty"`
// 选填,学号,字符串,maxLen=32
StudentNo string `json:"stuNum,omitempty"`
}
// PutCardUser 修改学生信息
// @Tags 家长微信
// @Summary 修改学生信息
// @Description 传学生id及新信息至后台,后台返回成功失败
// @Accept json
// @Produce json
// @Param id path integer true "学生ID"
// @Param data body PutCardUserReq true "学生信息"
// @Success 0
// @Router /we/carduser/{id} [PUT]
// @Security ApiKeyAuth
func PutCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
// CardLoss 卡挂失/解挂
// @Tags 家长微信
// @Summary 卡挂失/解挂
// @Description 传学生id及卡类型至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param loss query bool true "true挂失,false解挂"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)"
// @Success 0
// @Router /we/cardloss/{id} [PUT]
// @Security ApiKeyAuth
func CardLoss(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
// CardBind 绑定卡
// @Tags 家长微信
// @Summary 绑定卡
// @Description 传学生id及卡类型、卡号至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param code query string true "卡号"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)"
// @Success 0
// @Router /we/cardbind/{id} [PUT]
// @Security ApiKeyAuth
func CardBind(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
// DeleteCardBind 解绑卡
// @Tags 家长微信
// @Summary 解绑卡
// @Description 传学生id及卡类型至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Param type query integer true "卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)"
// @Success 0
// @Router /we/cardbind/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteCardBind(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
})
}
type familyNumStruct struct {
Phone string `json:"phone"`
Name string `json:"name"`
}
type getCallRecordRes struct {
// 被叫号码
CalledNumber string `json:"number"`
// 昵称
CalledNickname string `json:"nickname"`
// 通话开始时间
CallStartAt time.Time `json:"startAt"`
// 通话时长,单位(分钟)
TalkTime uint8 `json:"time"`
}
// GetCallRecord 查询通话记录
// @Tags 家长微信
// @Summary 查询通话记录
// @Description 传学生ID至后台,后台返回通话记录列表
// @Produce json
// @Param id path integer true "学生ID"
// @Param pnum query integer true "页数"
// @Param psize query integer true "页条数"
// @Param start query string false "起始时间 2020-10-10 10:00:00"
// @Param end query string false "结束时间 2030-10-10 10:00:00"
// @Param asc query bool false "是否升序" default(false)
// @Success 0 {object} []getCallRecordRes "通话记录列表"
// @Router /we/callrecord/{id} [GET]
// @Security ApiKeyAuth
func GetCallRecord(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": api.Success,
"data": [2]getCallRecordRes{},
})
}
// AddFamilyNum 添加亲情号 // AddFamilyNum 添加亲情号
// @Tags 家长微信 // @Tags 家长微信
// @Summary 添加亲情号 // @Summary 添加亲情号
...@@ -193,9 +59,9 @@ func GetCallRecord(c *gin.Context) { ...@@ -193,9 +59,9 @@ func GetCallRecord(c *gin.Context) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
// @Param data body familyNumStruct true "亲情号内容" // @Param data body model.CacheFamilyOnePerson true "亲情号内容"
// @Success 0 // @Success 0
// @Router /we/familynum [POST] // @Router /we/familynum/{id} [POST]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func AddFamilyNum(c *gin.Context) { func AddFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
...@@ -211,9 +77,9 @@ func AddFamilyNum(c *gin.Context) { ...@@ -211,9 +77,9 @@ func AddFamilyNum(c *gin.Context) {
// @Produce json // @Produce json
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
// @Param phone query string true "电话号码" // @Param phone query string true "电话号码"
// @Param data body familyNumStruct true "亲情号内容" // @Param data body model.CacheFamilyOnePerson true "亲情号内容"
// @Success 0 // @Success 0
// @Router /we/familynum [PUT] // @Router /we/familynum/{id} [PUT]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func PutFamilyNum(c *gin.Context) { func PutFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
...@@ -230,7 +96,7 @@ func PutFamilyNum(c *gin.Context) { ...@@ -230,7 +96,7 @@ func PutFamilyNum(c *gin.Context) {
// @Param id path integer true "学生ID" // @Param id path integer true "学生ID"
// @Param phone query string true "电话号码" // @Param phone query string true "电话号码"
// @Success 0 // @Success 0
// @Router /we/familynum [DELETE] // @Router /we/familynum/{id} [DELETE]
// @Security ApiKeyAuth // @Security ApiKeyAuth
func DeleteFamilyNum(c *gin.Context) { func DeleteFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
......
...@@ -12,9 +12,10 @@ const ( ...@@ -12,9 +12,10 @@ const (
ErrorTencentErr = 8 ErrorTencentErr = 8
ErrorUserNotHavePhoneCard = 9 ErrorUserNotHavePhoneCard = 9
ErrorReqParaFormat = 10 ErrorReqParaFormat = 10
ErrorReqPara = 11 ErrorReqPara = 11
ErrorReqInsertDuplicate = 12 ErrorReqInsertDuplicate = 12
ErrorDeleteCardUserHaveSimCard = 13
ErrorShareCode = 30 ErrorShareCode = 30
ErrorShareCodeRunTime = 31 ErrorShareCodeRunTime = 31
...@@ -29,11 +30,12 @@ var CodeMsg = map[uint16]string{ ...@@ -29,11 +30,12 @@ var CodeMsg = map[uint16]string{
ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)", ErrorSystemErr: "系统错误,请尝试重新登录(开发测试人员请联系开发人员)",
ErrorSystemBusy: "服务器忙,请重试", ErrorSystemBusy: "服务器忙,请重试",
ErrorTencentErr: "微信服务器返回的错误:", ErrorTencentErr: "微信服务器返回的错误:",
ErrorUserNotHavePhoneCard: "用户未绑定话卡", ErrorUserNotHavePhoneCard: "用户未绑定话卡",
ErrorReqPara: "请求参数内容(取值)错误", ErrorReqPara: "请求参数内容(取值)错误",
ErrorReqParaFormat: "请求参数格式错误", ErrorReqParaFormat: "请求参数格式错误",
ErrorReqInsertDuplicate: "内容重复,无法创建", ErrorReqInsertDuplicate: "内容重复,无法创建",
ErrorDeleteCardUserHaveSimCard: "已绑定电话卡,请解绑电话卡后再删除",
ErrorShareCode: "邀请码无效,请联系主家长微信重新分享", ErrorShareCode: "邀请码无效,请联系主家长微信重新分享",
ErrorShareCodeRunTime: "邀请码已过期,请联系主家长微信重新分享", ErrorShareCodeRunTime: "邀请码已过期,请联系主家长微信重新分享",
......
...@@ -46,22 +46,22 @@ func InitRouter() { //*gin.Engine{ ...@@ -46,22 +46,22 @@ func InitRouter() { //*gin.Engine{
wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生 wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生
wechat.GET("trend/:id", api_we.GetCardUserTrend) //获取学生最新动态 wechat.GET("trend/:id", api_we.GetCardUserTrend) //获取学生最新动态
wechat.GET("cardusertrend/:id", api_we.GetCardUserAndTrend) //获取单个学生信息和最新动态 wechat.GET("cardusertrend/:id", api_we.GetCardUserAndTrend) //获取单个学生信息和最新动态
wechat.GET("bindcarduser/:id", api_we.GetBindCardUser) //获取学生副家长列表(仅主家长有权限) wechat.GET("bindcarduser/:id", api_we.GetSlaveBindCardUser) //获取学生副家长列表(仅主家长有权限)
wechat.GET("sharestring/:id", api_we.GetCardUserShareCode) //获取邀请码(仅主家长有权限) wechat.GET("sharestring/:id", api_we.GetCardUserShareCode) //获取邀请码(仅主家长有权限)
wechat.POST("bindcarduser/:share_code", api_we.BindCardUser) //副家长绑定学生 wechat.POST("bindcarduser/:share_code", api_we.BindCardUser) //副家长绑定学生
wechat.DELETE("bindcarduser/:id", api_we.DeleteSlaveBindCardUser) //副家长解绑学生 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/:id", api_we.DeleteSlaveWeUser) //删除副家长(仅主家长有权限) wechat.DELETE("slaveweuser/:id", api_we.MasterDeleteSlaveWeUser) //删除副家长(仅主家长有权限)
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) //绑定卡
wechat.DELETE("cardbind/:id", api_we.DeleteCardBind) //解绑卡 wechat.DELETE("cardbind/:id", api_we.DeleteCardBind) //解绑卡
wechat.GET("phonecardstatus/:id", api_we.GetPhoneCardStatus) //获取学生公话卡状态 wechat.GET("phonecardstatus/:id", api_we.GetPhoneCardStatus) //获取学生公话卡状态
wechat.GET("callrecord/:id", api_we.GetCallRecord) // 查询通话记录 wechat.GET("callrecord/:id", api_we.GetCallRecord) // 查询通话记录
wechat.POST("familynum/:id", api_we.AddFamilyNum) //添加亲情号 wechat.POST("familynum/:id", api_we.AddFamilyNum) //添加亲情号
wechat.PUT("familynum/:id", api_we.PutFamilyNum) //修改亲情号 wechat.PUT("familynum/:id", api_we.PutFamilyNum) //修改亲情号
wechat.DELETE("familynum/:id", api_we.DeleteFamilyNum) //删除亲情号 wechat.DELETE("familynum/:id", api_we.DeleteFamilyNum) //删除亲情号
//缴费 //缴费
//查询缴费记录 //查询缴费记录
......
set GOOS=linux
swag init
go build -o dcGoServer2 -ldflags "-w -s" main.go
\ No newline at end of file
...@@ -33,11 +33,11 @@ NewConnRightfulTimeout = 120 ...@@ -33,11 +33,11 @@ NewConnRightfulTimeout = 120
OldConnReadDeadline = 180 OldConnReadDeadline = 180
[log] [log]
#debug info warn error 只允许设置这3个等级,以保证至少记录error DPanic Panci Fatal #debug info warn error 只允许设置这4个等级,以保证至少记录error DPanic Panic Fatal
#debug info: 记录流水数据(都存在info.log里) #debug info: 记录流水数据(都存在info.log里)
#warn: 应检查原因,主要来自外部 #warn: 应检查原因,主要来自外部
#error DPanic Panci Fatal: 应立即检查原因来内部或硬件设备或业务服务器 #error DPanic Panci Fatal: 应立即检查原因来内部或硬件设备或业务服务器
Level = warn Level = debug
#log文件的存储路径 #log文件的存储路径
Path = ./log/ Path = ./log/
#单个日志文件大小限制,单位MB #单个日志文件大小限制,单位MB
......
...@@ -17,7 +17,7 @@ func Init() { ...@@ -17,7 +17,7 @@ func Init() {
initPhone20DeviceMap() initPhone20DeviceMap()
// initAdminMap() // initAdminMap()
// initOperatorMap() // initOperatorMap()
//initCardUserTrendMap() initCardUserTrendMap()
} }
// ProvinceMap /*********************************************************全国行政区域**/------------------------OK // ProvinceMap /*********************************************************全国行政区域**/------------------------OK
...@@ -64,14 +64,14 @@ var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE ...@@ -64,14 +64,14 @@ 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 //status不为0的所有校区服务
type AreaServiceStruct struct { // 后续再加支付信息 //type AreaServiceStruct struct { // 后续再加支付信息
AreaID uint32 // AreaID uint32
ServiceType 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暂未开放
} //}
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
...@@ -143,7 +143,7 @@ var CardUserTrendMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KE ...@@ -143,7 +143,7 @@ var CardUserTrendMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KE
// DeviceID uint32 // DeviceID uint32
// Content string // Content string
// Time time.Time // Time time.Time
//} //
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
/********************************************************Sim卡信息(仅存学生绑定了的)**/ /********************************************************Sim卡信息(仅存学生绑定了的)**/
...@@ -166,12 +166,12 @@ var SimInfoMap sync.Map //sim_id(string) 作为KEY ...@@ -166,12 +166,12 @@ var SimInfoMap sync.Map //sim_id(string) 作为KEY
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
/*******************************************************电话设备**/ /*******************************************************电话设备**/
var phone20DeviceMap sync.Map //device_id 作为KEY CachePhone20DeviceStruct 作为VALUE var phone20DeviceMap sync.Map //device_id 作为KEY CachePhone20DeviceStruct 作为VALUE //存放绑定了校区的设备
//type CachePhone20DeviceStruct struct { //type CachePhone20DeviceStruct struct {
// AreaServiceID uint32 //AreaServiceID uint32
// AllowCallTime uint8 //允许通话时长,255表示不限制时长 //AllowCallTime uint8 //允许通话时长,255表示不限制时长
// //Place string //安装位置 //PlaceUser string //位置,家长微信看到的
// Status bool //Status bool
//} //}
/*---------------------------------------------------------------*/ /*---------------------------------------------------------------*/
...@@ -78,17 +78,16 @@ func GetAreaMapName(areaID uint32, test bool) string { ...@@ -78,17 +78,16 @@ func GetAreaMapName(areaID uint32, test bool) string {
return "" return ""
} }
func GetAreaMapInfo(areaID uint32, info *model.CacheBAreaStruct) bool { func GetAreaMapInfo(areaID uint32) *model.CacheBAreaStruct {
//var info model.CacheBAreaStruct
if v, ok := AreaMap.Load(areaID); ok { if v, ok := AreaMap.Load(areaID); ok {
if *info, ok = v.(model.CacheBAreaStruct); ok { if info, ok := v.(model.CacheBAreaStruct); ok {
return true return &info
} else { } else {
AreaMap.Delete(areaID) AreaMap.Delete(areaID)
logger.Log.Error("AreaMap 类型断言错误", logger.Log.Error("AreaMap 类型断言错误",
zap.String("Src", "GetAreaMapInfo"), zap.String("Src", "GetAreaMapInfo"),
zap.Uint32("areaID", areaID)) zap.Uint32("areaID", areaID))
return false
} }
} else { } else {
logger.Log.Error("AreaMap 没数据", logger.Log.Error("AreaMap 没数据",
...@@ -96,6 +95,10 @@ func GetAreaMapInfo(areaID uint32, info *model.CacheBAreaStruct) bool { ...@@ -96,6 +95,10 @@ func GetAreaMapInfo(areaID uint32, info *model.CacheBAreaStruct) bool {
zap.Uint32("areaID", areaID)) zap.Uint32("areaID", areaID))
} }
// todo 查库 //if areaID == 0 {
return false // // todo1 logger
// return nil
//}
// todo1 查库
return 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"
...@@ -10,17 +11,18 @@ import ( ...@@ -10,17 +11,18 @@ import (
"time" "time"
) )
// initAreaServiceMap status不为0的所有校区服务
func initAreaServiceMap() { func initAreaServiceMap() {
fmt.Println(time.Now(), "cache: initAreaServiceMap begin") fmt.Println(time.Now(), "cache: initAreaServiceMap begin")
var areaServiceID uint32 var areaServiceID uint32
var temp AreaServiceStruct var temp model.CacheAreaServiceStruct
rows, err := dbcurd.PgDb.Query("SELECT id,service_type,area_id,status FROM b_area_service") // rows, err := dbcurd.PgDb.Query("SELECT id,service_type,area_id,operator_id,status FROM b_area_service WHERE status!=0") //
if err != nil { if err != nil {
log.Panicln("initAreaServiceMap rows", err) log.Panicln("initAreaServiceMap rows", err)
} }
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
err = rows.Scan(&areaServiceID, &temp.ServiceType, &temp.AreaID, &temp.Status) err = rows.Scan(&areaServiceID, &temp.ServiceType, &temp.AreaID, &temp.OperatorID, &temp.Status)
if err != nil { if err != nil {
log.Panicln("initAreaServiceMap rows.Scan", err) log.Panicln("initAreaServiceMap rows.Scan", err)
} }
...@@ -37,16 +39,16 @@ func initAreaServiceMap() { ...@@ -37,16 +39,16 @@ func initAreaServiceMap() {
} }
} }
func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct) { func GetAreaServiceInfo(areaServiceID uint32) *model.CacheAreaServiceStruct {
if info, ok := areaServiceMap.Load(areaServiceID); ok { //map有 if info, ok := areaServiceMap.Load(areaServiceID); ok { //map有
if areaServiceInfo, ok = info.(AreaServiceStruct); ok { //类型断言正确 if areaServiceInfo, ok := info.(model.CacheAreaServiceStruct); ok { //类型断言正确
if areaServiceInfo.Status == 0 { if areaServiceInfo.Status == 0 {
areaServiceMap.Delete(areaServiceID) areaServiceMap.Delete(areaServiceID)
logger.Log.Error("areaServiceMap areaServiceInfo.Status == 0", logger.Log.Error("areaServiceMap areaServiceInfo.Status == 0",
zap.Uint32("areaServiceID", areaServiceID), zap.Uint32("areaServiceID", areaServiceID),
zap.String("src", "GetAreaServiceInfo")) zap.String("src", "GetAreaServiceInfo"))
} else { } else {
return areaServiceInfo return &areaServiceInfo
} }
} else { //类型断言失败 } else { //类型断言失败
areaServiceMap.Delete(areaServiceID) areaServiceMap.Delete(areaServiceID)
...@@ -55,18 +57,25 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct ...@@ -55,18 +57,25 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct
zap.String("src", "GetAreaServiceInfo")) zap.String("src", "GetAreaServiceInfo"))
} }
} }
if areaServiceID == 0 {
logger.Log.Error("GetAreaServiceInfo 传入ID为0",
zap.Uint32("areaServiceID", areaServiceID),
zap.String("src", "GetAreaServiceInfo"))
return nil
}
var err error var err error
var areaServiceInfo model.CacheAreaServiceStruct
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
err = dbcurd.PgDb.QueryRow("SELECT service_type,area_id,status FROM b_area_service WHERE id=$1", err = dbcurd.PgDb.QueryRow("SELECT service_type,area_id,operator_id,status FROM b_area_service WHERE id=$1",
areaServiceID).Scan(&areaServiceInfo.ServiceType, &areaServiceInfo.AreaID, &areaServiceInfo.Status) areaServiceID).Scan(&areaServiceInfo.ServiceType, &areaServiceInfo.AreaID, &areaServiceInfo.OperatorID, &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 service_type,area_id,status FROM b_area_service WHERE id=$1", logger.Log.Error("GetAreaServiceInfo SELECT service_type,area_id,operator_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 nil
} }
fmt.Println("b_area_service SELECT:", i, err) fmt.Println("b_area_service SELECT:", i, err)
time.Sleep(3 * time.Millisecond) time.Sleep(3 * time.Millisecond)
...@@ -77,11 +86,11 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct ...@@ -77,11 +86,11 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct
zap.Uint32("areaServiceID", areaServiceID), zap.Uint32("areaServiceID", areaServiceID),
zap.Error(err), zap.Error(err),
zap.String("src", "GetAreaServiceInfo")) zap.String("src", "GetAreaServiceInfo"))
return return &areaServiceInfo
} }
logger.Log.Error("GetAreaServiceInfo SELECT operator_id,status FROM b_area WHERE id=$1", //todo logger.Log.Error("GetAreaServiceInfo SELECT service_type,area_id,operator_id,status FROM b_area_service WHERE id=$1", //todo
zap.Uint32("areaServiceID", areaServiceID), zap.Uint32("areaServiceID", areaServiceID),
zap.Error(err), zap.Error(err),
zap.String("src", "GetAreaServiceInfo")) zap.String("src", "GetAreaServiceInfo"))
return return nil
} }
...@@ -85,10 +85,10 @@ func initWechatAndCardUserRelationToWechatCustomerMapAndCardUserMap() { ...@@ -85,10 +85,10 @@ func initWechatAndCardUserRelationToWechatCustomerMapAndCardUserMap() {
} }
} }
func GetCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) { func GetCardUserInfo(cardUserID uint32) *model.CacheCardUserStruct {
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
} else { //类型断言失败 } else { //类型断言失败
CardUserMap.Delete(cardUserID) CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误", logger.Log.Error("CardUserMap 类型断言错误",
...@@ -101,24 +101,28 @@ func GetCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) { ...@@ -101,24 +101,28 @@ func GetCardUserInfo(cardUserID uint32) (model.CacheCardUserStruct, bool) {
zap.String("src", "GetCardUserInfo")) zap.String("src", "GetCardUserInfo"))
} }
var temp model.CacheCardUserStruct //if cardUserID == 0 {
// fmt.Println("GetCardUserInfo 居然传入了0")
// return nil
//}
// var temp model.CacheCardUserStruct
// todo1 再去查一盘库 // todo1 再去查一盘库
return temp, false return nil
} }
// CheckCardUserMaserAndSlaveWeID 0 没有这个卡用户 1 微信号在这个卡用户里啥都不是 2 主 3 从 // CheckCardUserMaserAndSlaveWeID 0 没有这个卡用户 1 微信号在这个卡用户里啥都不是 2 主 3 从
func CheckCardUserMaserAndSlaveWeID(cardUserID uint32, weUserID uint32) uint8 { func CheckCardUserMaserAndSlaveWeID(cardUserID, weUserID uint32) uint8 {
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 { //类型断言正确
if v.MasterWechatUserID == weUserID { if v.MasterWechatUserID == weUserID {
return 1 return 2
} }
for _, slave := range v.SlaveWechatUserID { for _, slave := range v.SlaveWechatUserID {
if weUserID == slave { if weUserID == slave {
return 2 return 3
} }
} }
return 0 return 1
} else { //类型断言失败 } else { //类型断言失败
CardUserMap.Delete(cardUserID) CardUserMap.Delete(cardUserID)
logger.Log.Error("CardUserMap 类型断言错误", logger.Log.Error("CardUserMap 类型断言错误",
...@@ -136,8 +140,51 @@ func CheckCardUserMaserAndSlaveWeID(cardUserID uint32, weUserID uint32) uint8 { ...@@ -136,8 +140,51 @@ func CheckCardUserMaserAndSlaveWeID(cardUserID uint32, weUserID uint32) uint8 {
return 0 return 0
} }
// CheckCardUserMaserAndSlaveWeID 0 微信号在这个卡用户里啥都不是 1 主 2 从
//func CheckCardUserMaserAndSlaveWeID(weUserID uint32,v *model.CacheCardUserStruct) uint8 {
// if v.MasterWechatUserID == weUserID {
// return 2
// }
// for _, slave := range v.SlaveWechatUserID {
// if weUserID == slave {
// return 3
// }
// }
// return 1
//}
// GetCardUserInfoAndCheckCardUserMaserAndSlaveWeID 0 没有这个卡用户 1 微信号在这个卡用户里啥都不是 2 主 3 从
func GetCardUserInfoAndCheckCardUserMaserAndSlaveWeID(cardUserID, weUserID uint32) (*model.CacheCardUserStruct, uint8) {
if s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
if v.MasterWechatUserID == weUserID {
return &v, 2
}
for _, slave := range v.SlaveWechatUserID {
if weUserID == slave {
return &v, 3
}
}
return &v, 1
} 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 nil, 0
}
// 并发不安全 // 并发不安全
func InsertWechatAndCardUserRelationToCardUserMap(weUserID uint32, cardUserID uint32, master bool) bool { func InsertWechatAndCardUserRelationToCardUserMap(weUserID, cardUserID uint32, master bool) 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 { //类型断言正确
if master { if master {
...@@ -178,3 +225,30 @@ func InsertWechatAndCardUserRelationToCardUserMap(weUserID uint32, cardUserID ui ...@@ -178,3 +225,30 @@ func InsertWechatAndCardUserRelationToCardUserMap(weUserID uint32, cardUserID ui
// todo1 再去查一盘库 // todo1 再去查一盘库
return false return false
} }
// DeleteASlaveWeUserIDInCardUserMap 并发不安全
func DeleteASlaveWeUserIDInCardUserMap(weUserID, cardUserID uint32) {
if s, ok := CardUserMap.Load(cardUserID); ok { // map有
if v, ok4 := s.(model.CacheCardUserStruct); ok4 { //类型断言正确
for i, slaveID := range v.SlaveWechatUserID {
if slaveID == weUserID {
v.SlaveWechatUserID = append(v.SlaveWechatUserID[:i], v.SlaveWechatUserID[i+1:]...)
CardUserMap.Store(cardUserID, v)
return
}
}
} 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 再去查一盘库
}
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"
"fmt" "fmt"
"log"
"time"
) )
//// initCardUserTrendMap 获取学生近20条动态,现在只有通话记录 // initCardUserTrendMap 获取学生近20条动态,现在只有通话记录
//func initCardUserTrendMap(){ func initCardUserTrendMap() {
// fmt.Println(time.Now(), "cache: initCardUserTrendMap begin") fmt.Println(time.Now(), "cache: initCardUserTrendMap begin")
// var cardUserID uint32 var cardUserID uint32
// var ok bool var ok bool
// CardUserMap.Range(func(k, _ interface{}) bool { CardUserMap.Range(func(k, _ interface{}) bool {
// cardUserID , ok = k.(uint32) cardUserID, ok = k.(uint32)
// if ok != true { if ok != true {
// log.Panicln(time.Now(), "initCardUserTrendMap k.(uint32) error", k) log.Panicln(time.Now(), "initCardUserTrendMap k.(uint32) error", k)
// } }
// trends := selectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID) trends := dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID)
// if trends != nil { if trends != nil {
// CardUserTrendMap.Store(cardUserID,trends) CardUserTrendMap.Store(cardUserID, trends)
// } }
// return true return true
// }) })
// fmt.Println(time.Now(), "cache: initCardUserTrendMap OK") fmt.Println(time.Now(), "cache: initCardUserTrendMap OK")
//} }
//
//func GetCardUserTrendByCardUserID(cardUserID uint32)(trends []model.CacheCardUserTrendStruct){
//
//}
func InsertCardUserTrendMap(cardUserID uint32, temp *model.CacheCardUserTrendStruct) { // 并发不安全,可改成channel传递 func InsertCardUserTrendMap(cardUserID uint32, temp *model.CacheCardUserTrendStruct) { // 并发不安全,可改成channel传递
if v, ok := CardUserTrendMap.Load(cardUserID); ok { if v, ok := CardUserTrendMap.Load(cardUserID); ok {
if trends, ok := v.([]model.CacheCardUserTrendStruct); ok { if trends, ok := v.([]model.CacheCardUserTrendStruct); ok {
trends = append(trends, *temp) trends = append([]model.CacheCardUserTrendStruct{*temp}, trends...)
length := len(trends) length := len(trends)
if length > 20 { if length > 20 {
trends = trends[length-20 : length] trends = trends[:20]
} }
CardUserTrendMap.Store(cardUserID, trends) CardUserTrendMap.Store(cardUserID, trends)
return
} else { // 类型断言错误 } else { // 类型断言错误
fmt.Println("InsertCardUserTrendMap CardUserTrendMap 类型断言错误") fmt.Println("InsertCardUserTrendMap CardUserTrendMap 类型断言错误")
CardUserTrendMap.Delete(cardUserID) CardUserTrendMap.Delete(cardUserID)
...@@ -44,6 +44,28 @@ func InsertCardUserTrendMap(cardUserID uint32, temp *model.CacheCardUserTrendStr ...@@ -44,6 +44,28 @@ func InsertCardUserTrendMap(cardUserID uint32, temp *model.CacheCardUserTrendStr
} }
trends := make([]model.CacheCardUserTrendStruct, 1) trends := make([]model.CacheCardUserTrendStruct, 1)
trends[1] = *temp trends[0] = *temp
CardUserTrendMap.Store(cardUserID, trends) CardUserTrendMap.Store(cardUserID, trends)
} }
func GetCardUserTrendMapByCardUserID(cardUserID uint32) (trends []model.CacheCardUserTrendStruct) {
if v, ok := CardUserTrendMap.Load(cardUserID); ok {
if trends, ok = v.([]model.CacheCardUserTrendStruct); ok {
return trends
} else { // 类型断言错误
fmt.Println("InsertCardUserTrendMap CardUserTrendMap 类型断言错误")
CardUserTrendMap.Delete(cardUserID)
}
} /*else {
logger.Log.Error("CardUserTrendMap 有问题,没数据",
zap.Uint32("cardUserID", cardUserID),
zap.String("src", "GetCardUserTrendMapByCardUserID"))
}*/
//trends = dbcurd.SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID)
//if trends != nil {
// CardUserTrendMap.Store(cardUserID,trends)
//}
return nil
}
...@@ -7,15 +7,15 @@ import ( ...@@ -7,15 +7,15 @@ import (
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
"log" "log"
"strings"
"time" "time"
) )
// initPhone20DeviceMap 将所有绑定了校区的设备读入缓存
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 model.CachePhone20DeviceStruct var temp model.CachePhone20DeviceStruct
rows, err := dbcurd.PgDb.Query("SELECT device_id,area_service_id,allow_call_time,status,place_user FROM d_phone20") rows, err := dbcurd.PgDb.Query("SELECT device_id,area_service_id,allow_call_time,status,place_user FROM d_phone20 WHERE area_service_id!=0")
if err != nil { if err != nil {
log.Panicln("SelectDeviceToMap rows", err) log.Panicln("SelectDeviceToMap rows", err)
} }
...@@ -38,10 +38,10 @@ func initPhone20DeviceMap() { ...@@ -38,10 +38,10 @@ func initPhone20DeviceMap() {
} }
} }
func GetPhone20Info(devID uint32) model.CachePhone20DeviceStruct { 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.(model.CachePhone20DeviceStruct); ok2 { //类型断言正确 if v, ok2 := info.(model.CachePhone20DeviceStruct); ok2 { //类型断言正确
return v //,true return &v
} else { //类型断言失败 } else { //类型断言失败
phone20DeviceMap.Delete(devID) phone20DeviceMap.Delete(devID)
logger.Log.Error("DeviceMap 类型断言错误", logger.Log.Error("DeviceMap 类型断言错误",
...@@ -49,32 +49,32 @@ func GetPhone20Info(devID uint32) model.CachePhone20DeviceStruct { ...@@ -49,32 +49,32 @@ func GetPhone20Info(devID uint32) model.CachePhone20DeviceStruct {
zap.String("src", "getDeviceInfo")) zap.String("src", "getDeviceInfo"))
} }
} }
var temp model.CachePhone20DeviceStruct //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",
devID).Scan(&temp.AreaServiceID, &temp.AllowCallTime, &temp.Status) // devID).Scan(&temp.AreaServiceID, &temp.AllowCallTime, &temp.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.Warn("d_phone20 设备表无数据", // logger.Log.Warn("d_phone20 设备表无数据",
zap.Uint32("devID", devID), // zap.Uint32("devID", devID),
zap.Error(err)) // zap.Error(err))
return temp // return nil,false
} // }
fmt.Println("GetPhone20Info SELECT:", i, err) // fmt.Println("GetPhone20Info SELECT:", i, err)
time.Sleep(3 * time.Millisecond) // time.Sleep(3 * time.Millisecond)
continue // continue
} // }
phone20DeviceMap.Store(devID, temp) // phone20DeviceMap.Store(devID, temp)
logger.Log.Error("数据库有而缓存没有 GetPhone20Info", // logger.Log.Error("数据库有而缓存没有 GetPhone20Info",
zap.Uint32("devID", devID), // zap.Uint32("devID", devID),
zap.Error(err), // zap.Error(err),
zap.String("src", "GetPhone20Info")) // zap.String("src", "GetPhone20Info"))
return temp //,true // return &temp,true
} //}
logger.Log.Error("getDeviceInfo SELECT SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE id=$1", //logger.Log.Error("getDeviceInfo SELECT SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE id=$1",
zap.Uint32("devID", devID), // zap.Uint32("devID", devID),
zap.Error(err), // zap.Error(err),
zap.String("src", "GetPhone20Info")) // zap.String("src", "GetPhone20Info"))
return temp //,false return nil
} }
...@@ -33,10 +33,10 @@ func initFamilyNumToSimInfoMap() { ...@@ -33,10 +33,10 @@ func initFamilyNumToSimInfoMap() {
fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap end") fmt.Println(time.Now(), "cache: initFamilyNumToSimInfoMap end")
} }
func GetSimInfo(simId string) model.CacheSimInfoStruct { func GetSimInfo(simId string) *model.CacheSimInfoStruct {
if s, ok := SimInfoMap.Load(simId); ok { // map有 if s, ok := SimInfoMap.Load(simId); ok { // map有
if info, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确 if info, ok4 := s.(model.CacheSimInfoStruct); ok4 { //类型断言正确
return info return &info
} else { //类型断言失败 } else { //类型断言失败
SimInfoMap.Delete(simId) SimInfoMap.Delete(simId)
logger.Log.Error("SimInfoMap 类型断言错误", logger.Log.Error("SimInfoMap 类型断言错误",
...@@ -49,9 +49,9 @@ func GetSimInfo(simId string) model.CacheSimInfoStruct { ...@@ -49,9 +49,9 @@ func GetSimInfo(simId string) model.CacheSimInfoStruct {
zap.String("src", "GetSimInfo")) zap.String("src", "GetSimInfo"))
} }
var temp model.CacheSimInfoStruct //var temp model.CacheSimInfoStruct
//// todoN 再去查一盘库 //// todoN 再去查一盘库
return temp return nil
} }
// AddSimMonthTalkMinutes 缓存里增加本月通话分钟数 // AddSimMonthTalkMinutes 缓存里增加本月通话分钟数
...@@ -78,8 +78,8 @@ func AddSimMonthTalkMinutes(simId string, min uint16) { ...@@ -78,8 +78,8 @@ func AddSimMonthTalkMinutes(simId string, min uint16) {
zap.String("src", "AddSimMonthTalkMinutes")) zap.String("src", "AddSimMonthTalkMinutes"))
} }
var info model.CacheSimInfoStruct info := dbcurd.SelectUSimInfoBySimID(simId)
if dbcurd.SelectUSimInfoBySimID(simId, &info) == false { if info == nil {
logger.Log.Error("严重错误:卡号来账单居然没查到卡信息", logger.Log.Error("严重错误:卡号来账单居然没查到卡信息",
zap.String("simId", simId), zap.String("simId", simId),
zap.Uint16("min", min), zap.Uint16("min", min),
...@@ -88,8 +88,6 @@ func AddSimMonthTalkMinutes(simId string, min uint16) { ...@@ -88,8 +88,6 @@ func AddSimMonthTalkMinutes(simId string, min uint16) {
return return
} }
info.FamilyNum = dbcurd.SelectUSimFamilyNumBySimID(simId) info.FamilyNum = dbcurd.SelectUSimFamilyNumBySimID(simId)
SimInfoMap.Store(simId, info) SimInfoMap.Store(simId, *info)
AddSimMonthTalkMinutes(simId, min) AddSimMonthTalkMinutes(simId, min)
} }
// 学生绑卡时,如果原来绑卡的学生已经删除,则还是可以绑,若里面有正常的学生,则不准绑?
...@@ -42,6 +42,64 @@ func initWechatCustomerMap() { ...@@ -42,6 +42,64 @@ func initWechatCustomerMap() {
fmt.Println(time.Now(), "cache: initWechatCustomerMap OK") fmt.Println(time.Now(), "cache: initWechatCustomerMap OK")
} }
func GetWeUserInfoFromMapAndDB(weUserID uint32) *model.CacheWeCustomerStruct {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok := v.(model.CacheWeCustomerStruct); ok {
return &data //正常情况
} else {
WechatCustomerMap.Delete(weUserID)
logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "GetWeUserInfoFromMapAndDB"),
zap.Uint32("userID", weUserID))
}
} else {
logger.Log.Error("WechatCustomerMap 没数据",
zap.String("Src", "GetWeUserInfoFromMapAndDB"),
zap.Uint32("userID", weUserID))
}
data, unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID)
if len(unionID) == 0 || data == nil {
return nil //没有这个用户
}
logger.Log.Error("WechatCustomerMap 没数据,数据库有",
zap.String("Src", "GetWeUserInfoFromMapAndDB"),
zap.Uint32("userID", weUserID))
return data
}
func GetWechatCustomerInfoAndCacheUpdateTokenTime(weUserID uint32, newTime int64) *model.CacheWeCustomerStruct {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok := v.(model.CacheWeCustomerStruct); ok {
if newTime > 0 {
data.TokenCreatTime = newTime
WechatCustomerMap.Store(weUserID, data)
}
return &data //正常的话就该这里
} else {
WechatCustomerMap.Delete(weUserID)
logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "GetWechatCustomerInfo"),
zap.Uint32("weUserID", weUserID))
// todoN 考虑查一遍库
}
} else {
logger.Log.Error("WechatCustomerMap 没数据",
zap.String("Src", "GetWechatCustomerInfo"),
zap.Uint32("weUserID", weUserID))
}
// 再查一遍库
data, unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID)
if len(unionID) == 0 || data == nil {
return nil
}
data.TokenCreatTime = newTime
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, *data)
return data
}
func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 { func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
var data model.CacheWeCustomerStruct var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok { if v, ok := WechatCustomerMap.Load(weUserID); ok {
...@@ -62,11 +120,11 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 { ...@@ -62,11 +120,11 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
} }
func GetWechatCustomerTestRole(userID uint32) (bool, bool) { func GetWechatCustomerTestRole(userID uint32) (bool, bool) {
var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(userID); ok { if v, ok := WechatCustomerMap.Load(userID); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok { if data, ok := v.(model.CacheWeCustomerStruct); ok {
return data.TestRole, true //正常情况 return data.TestRole, true //正常情况
} else { } else {
WechatCustomerMap.Delete(userID)
logger.Log.Error("WechatCustomerMap 类型断言错误", logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "GetWechatCustomerTestRole"), zap.String("Src", "GetWechatCustomerTestRole"),
zap.Uint32("userID", userID)) zap.Uint32("userID", userID))
...@@ -78,13 +136,13 @@ func GetWechatCustomerTestRole(userID uint32) (bool, bool) { ...@@ -78,13 +136,13 @@ func GetWechatCustomerTestRole(userID uint32) (bool, bool) {
} }
// 再查一遍库 // 再查一遍库
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(userID, &data) data, unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(userID)
if len(unionID) == 0 { if len(unionID) == 0 || data == nil {
return false, false return false, false
} }
WechatCustomerUnionIDToIDMAP.Store(unionID, userID) WechatCustomerUnionIDToIDMAP.Store(unionID, userID)
WechatCustomerMap.Store(userID, data) WechatCustomerMap.Store(userID, *data)
return data.TestRole, true return data.TestRole, true
} }
...@@ -97,60 +155,28 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 { ...@@ -97,60 +155,28 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 {
return 0 return 0
} }
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheWeCustomerStruct, bool) { //// InsertWechatCustomerMap 注意:并发不安全
var data model.CacheWeCustomerStruct //func InsertWechatCustomerMapAndDB(unionID string, userInfo *model.CacheWeCustomerStruct) uint32 {
if v, ok := WechatCustomerMap.Load(weUserID); ok { // userID, res := dbcurd.InsertUWeCustomerUnionID(unionID)
if data, ok = v.(model.CacheWeCustomerStruct); ok { // if res == dbcurd.InsertSysErr {
if newTime > 0 { // return 0
data.TokenCreatTime = newTime // }
WechatCustomerMap.Store(weUserID, data) // if res == dbcurd.InsertDuplicate {
} // if userID = dbcurd.SelectUWeCustomerByUnionIDToCacheModel(unionID, userInfo); userID == 0 {
return data, true //正常的话就该这里 // return 0
} else { // }
logger.Log.Error("WechatCustomerMap 类型断言错误", // }
zap.String("Src", "GetWechatCustomerInfo"), // WechatCustomerUnionIDToIDMAP.Store(unionID, userID)
zap.Uint32("weUserID", weUserID)) // WechatCustomerMap.Store(userID, *userInfo)
// todoN 考虑查一遍库 //
} // return userID
} else { //}
logger.Log.Error("WechatCustomerMap 没数据",
zap.String("Src", "GetWechatCustomerInfo"),
zap.Uint32("weUserID", weUserID))
}
// 再查一遍库
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data)
if len(unionID) == 0 {
return data, false
}
data.TokenCreatTime = newTime
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, data)
return data, true
}
// InsertWechatCustomerMap 注意:并发不安全
func InsertWechatCustomerMap(unionID string, userInfo *model.CacheWeCustomerStruct) uint32 {
userID, res := dbcurd.InsertUWeCustomerUnionID(unionID)
if res == dbcurd.InsertSysErr {
return 0
}
if res == dbcurd.InsertDuplicate {
if userID = dbcurd.SelectUWeCustomerByUnionIDToCacheModel(unionID, userInfo); userID == 0 {
return 0
}
}
WechatCustomerUnionIDToIDMAP.Store(unionID, userID)
WechatCustomerMap.Store(userID, *userInfo)
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.CacheWeCustomerStruct // var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok { if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheWeCustomerStruct); 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 {
...@@ -159,6 +185,7 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m ...@@ -159,6 +185,7 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m
WechatCustomerMap.Store(weUserID, data) WechatCustomerMap.Store(weUserID, data)
return true //正常的话就该这里 return true //正常的话就该这里
} else { } else {
WechatCustomerMap.Delete(weUserID)
logger.Log.Error("WechatCustomerMap 类型断言错误", logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"), zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
...@@ -170,23 +197,23 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m ...@@ -170,23 +197,23 @@ func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, m
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
} }
// 再查一遍库,库里面已经添加了学生数据了,就不用再添加了 // 再查一遍库,库里面已经添加了学生数据了,就不用再添加了
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data) data, unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID)
if len(unionID) == 0 { if len(unionID) == 0 || data == nil {
logger.Log.Error("数据库表u_we_customer 数据有问题", logger.Log.Error("数据库表u_we_customer 数据有问题",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"), zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
return false return false
} }
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID) WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, data) WechatCustomerMap.Store(weUserID, *data)
return true return true
} }
// DeleteAStudentIDInWechatCustomerMap 注意这里并发并不安全 // DeleteAStudentIDInWechatCustomerMap 注意这里并发并不安全
func DeleteAStudentIDInWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool { func DeleteAStudentIDInWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool {
var data model.CacheWeCustomerStruct //var data model.CacheWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok { if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(model.CacheWeCustomerStruct); ok { if data, ok := v.(model.CacheWeCustomerStruct); ok {
if master { if master {
for i, cID := range data.MasterCardUserID { for i, cID := range data.MasterCardUserID {
if cID == cardUserID { if cID == cardUserID {
...@@ -204,24 +231,24 @@ func DeleteAStudentIDInWechatCustomerMap(weUserID uint32, cardUserID uint32, mas ...@@ -204,24 +231,24 @@ func DeleteAStudentIDInWechatCustomerMap(weUserID uint32, cardUserID uint32, mas
return true //正常的话就该这里 return true //正常的话就该这里
} else { } else {
logger.Log.Error("WechatCustomerMap 类型断言错误", logger.Log.Error("WechatCustomerMap 类型断言错误",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"), zap.String("Src", "DeleteAStudentIDInWechatCustomerMap"),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
// todoN 考虑查一遍库 // todoN 考虑查一遍库
} }
} else { } else {
logger.Log.Error("WechatCustomerMap 没数据", logger.Log.Error("WechatCustomerMap 没数据",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"), zap.String("Src", "DeleteAStudentIDInWechatCustomerMap"),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
} }
// 再查一遍库,库里面已经添加了学生数据了,就不用再添加了 // 再查一遍库,库里面已经添加了学生数据了,就不用再添加了
unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID, &data) data, unionID := dbcurd.SelectUWeCustomerByUserIDToCacheModel(weUserID)
if len(unionID) == 0 { if len(unionID) == 0 || data == nil {
logger.Log.Error("数据库表u_we_customer 数据有问题", logger.Log.Error("数据库表u_we_customer 数据有问题",
zap.String("Src", "InsertNewStudentIDToWechatCustomerMap"), zap.String("Src", "DeleteAStudentIDInWechatCustomerMap"),
zap.Uint32("weUserID", weUserID)) zap.Uint32("weUserID", weUserID))
return false return false
} }
WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID) WechatCustomerUnionIDToIDMAP.Store(unionID, weUserID)
WechatCustomerMap.Store(weUserID, data) WechatCustomerMap.Store(weUserID, *data)
return true return true
} }
...@@ -33,6 +33,7 @@ func InitDb() { ...@@ -33,6 +33,7 @@ func InitDb() {
//PgDb.SetConnMaxLifetime() //PgDb.SetConnMaxLifetime()
//PgDb.SetConnMaxIdleTime() //PgDb.SetConnMaxIdleTime()
//PgDb.SetMaxOpenConns() //PgDb.SetMaxOpenConns()
//PgDb.SetMaxIdleConns()
//PgDb.Stats() //PgDb.Stats()
// 硬件通讯流水 // 硬件通讯流水
......
...@@ -119,3 +119,45 @@ func SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID uint32) ( ...@@ -119,3 +119,45 @@ func SelectCardUserTrendsLimit20FromUCallRecordByCardUserID(cardUserID uint32) (
} }
return return
} }
//CalledNumber string `json:"number"` // 被叫号码
//CalledNickname string `json:"nickname"` // 昵称
//CallStartAt time.Time `json:"startAt"` // 通话开始时间
//TalkTime uint8 `json:"time"` // 通话时长,单位(分钟)
func SelectWeGetCallRecord(cardUserID uint32, startTime, endTime, desc string, pNum, pSize int) (callRecord []model.SelectWeGetCallRecordStruct) {
sql := "SELECT call_start_at,called_number,called_nickname,(talk_time+59)/60,place_user FROM public.u_call_record WHERE card_user_id=$1" // 后面分表后看情况优化,现在第一筛选条件为card_user_id我认为更好
if len(startTime) > 0 && len(endTime) > 0 {
sql += " AND call_start_at BETWEEN'" + startTime + "'AND'" + endTime + "'"
}
sql += " ORDER BY call_start_at " + desc
if pSize > 0 {
sql += " LIMIT " + strconv.Itoa(pSize)
if pNum > 0 {
sql += " OFFSET " + strconv.Itoa(pNum*pSize)
}
}
// fmt.Println("sql:",sql)
rows, err := PgDb.Query(sql, cardUserID)
if err != nil {
fmt.Println("SelectWeGetCallRecord", sql, err)
return
}
defer rows.Close()
callRecord = make([]model.SelectWeGetCallRecordStruct, 0)
var temp model.SelectWeGetCallRecordStruct
for rows.Next() {
err = rows.Scan(&temp.CallStartAt, &temp.CalledNumber, &temp.CalledNickname, &temp.TalkTime, &temp.Place)
if err != nil {
fmt.Println("SelectWeGetCallRecord", sql, err)
return
}
callRecord = append(callRecord, temp)
}
// 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil {
fmt.Println(time.Now(), "SelectWeGetCallRecord rows.Err()", sql, err)
}
return
}
package dbcurd package dbcurd
import ( import (
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger" "dc_golang_server_1/logger"
"go.uber.org/zap" "go.uber.org/zap"
"time" "time"
...@@ -76,7 +77,7 @@ func UpdateUCardUserAndUWeCardUserDeleteAt(id uint32) bool { ...@@ -76,7 +77,7 @@ func UpdateUCardUserAndUWeCardUserDeleteAt(id uint32) bool {
return false return false
} }
defer clearTransaction(tx) defer clearTransaction(tx)
deleteAt := time.Now() deleteAt := time.Now() //.Format("2006-01-02 15:04:05.000000")
_, err = tx.Exec("UPDATE u_card_user SET delete_at=$1 WHERE id=$2", deleteAt, id) _, err = tx.Exec("UPDATE u_card_user SET delete_at=$1 WHERE id=$2", deleteAt, id)
if err != nil { if err != nil {
logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt 1", logger.Log.Error("UpdateUCardUserAndUWeCardUserDeleteAt 1",
...@@ -101,3 +102,17 @@ func UpdateUCardUserAndUWeCardUserDeleteAt(id uint32) bool { ...@@ -101,3 +102,17 @@ func UpdateUCardUserAndUWeCardUserDeleteAt(id uint32) bool {
return true return true
} }
func UpdateUCardUserInfo(id uint32, info *model.UpdateUCardUserInfoStruct) bool {
_, err := PgDb.Exec("UPDATE u_card_user SET name=$1,sex=$2,grade=$3,class=$4,student_num=$5 WHERE id=$6",
info.Name,
info.Sex,
info.Grade,
info.Class,
info.StudentNo,
id)
if err == nil {
return true
}
return false
}
...@@ -9,7 +9,8 @@ import ( ...@@ -9,7 +9,8 @@ import (
"time" "time"
) )
func SelectUSimInfoBySimID(simId string, cacheData *model.CacheSimInfoStruct) bool { func SelectUSimInfoBySimID(simId string) *model.CacheSimInfoStruct {
var cacheData model.CacheSimInfoStruct
var err error var err error
for i := 0; i < 5; i++ { 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", 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",
...@@ -21,15 +22,31 @@ func SelectUSimInfoBySimID(simId string, cacheData *model.CacheSimInfoStruct) bo ...@@ -21,15 +22,31 @@ func SelectUSimInfoBySimID(simId string, cacheData *model.CacheSimInfoStruct) bo
&cacheData.Status, &cacheData.Status,
&cacheData.ExpiryAt) &cacheData.ExpiryAt)
if err == nil { if err == nil {
return true return &cacheData
} }
if strings.Contains(err.Error(), "no rows in result") { if strings.Contains(err.Error(), "no rows in result") {
return false return nil
} }
fmt.Println("SelectUSimInfoBySimID:", i, err) fmt.Println("SelectUSimInfoBySimID:", i, err)
time.Sleep(2 * time.Millisecond) time.Sleep(2 * time.Millisecond)
} }
logger.Log.Error("SelectUSimInfoBySimID Err", logger.Log.Error("SelectUSimInfoBySimID Err",
zap.Error(err)) zap.Error(err))
return nil
}
func UpdateUSimInfoStatus(simId string, status uint8) bool {
_, err := PgDb.Exec("UPDATE u_sim_info SET status=$1 WHERE sim_id=$2", status, simId)
if err == nil {
return true
}
return false
}
func UpdateUSimInfoCardUserID(simId string, cardUserID uint32) bool {
_, err := PgDb.Exec("UPDATE u_sim_info SET card_user_id=$1 WHERE sim_id=$2", cardUserID, simId)
if err == nil {
return true
}
return false return false
} }
package dbcurd package dbcurd
import "time"
// InsertOrUpdateUWeCardUserSlave 副家长绑定学生 // InsertOrUpdateUWeCardUserSlave 副家长绑定学生
func InsertOrUpdateUWeCardUserSlave(weUserID, cardUserID uint32) bool { 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) _, 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)
...@@ -8,3 +10,11 @@ func InsertOrUpdateUWeCardUserSlave(weUserID, cardUserID uint32) bool { ...@@ -8,3 +10,11 @@ func InsertOrUpdateUWeCardUserSlave(weUserID, cardUserID uint32) bool {
} }
return false return false
} }
func UpdateUWeCardUserDeleteAt(weUserID, cardUserID uint32) bool {
_, err := PgDb.Exec("UPDATE u_we_card_user SET delete_at=$1 WHERE we_user_id=$2 AND card_user_id=$3", time.Now(), weUserID, cardUserID)
if err == nil {
return true
}
return false
}
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"time" "time"
) )
func UpdateUWeCustomerLoginTime(weUserID uint32) { //todoN 以后添加微信登录流水表 func UpdateUWeCustomerLoginTime(weUserID uint32) { //todoN 以后添加微信登录流水表 也可以先存缓存,半夜来插入
var err error var err error
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
_, err = stmtUpdateWechatUserLogin.Exec(time.Now().Format("2006-01-02 15:04:05.000"), weUserID) //这里格式化可加可不加 _, err = stmtUpdateWechatUserLogin.Exec(time.Now().Format("2006-01-02 15:04:05.000"), weUserID) //这里格式化可加可不加
...@@ -44,70 +44,74 @@ func InsertUWeCustomerUnionID(unionID string) (id uint32, res uint8) { ...@@ -44,70 +44,74 @@ func InsertUWeCustomerUnionID(unionID string) (id uint32, res uint8) {
return 0, InsertSysErr return 0, InsertSysErr
} }
func SelectUWeCustomerByUnionIDToCacheModel(unionID string, userInfo *model.CacheWeCustomerStruct) (userID uint32) { func SelectUWeCustomerByUnionIDToCacheModel(weUnionID string) (*model.CacheWeCustomerStruct, uint32) {
var weUserInfo model.CacheWeCustomerStruct
var weUserID 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", weUnionID).Scan(
&userID, &weUserID,
&userInfo.WePhone, &weUserInfo.WePhone,
&userInfo.Nickname, &weUserInfo.Nickname,
&userInfo.AvatarURL, &weUserInfo.AvatarURL,
&userInfo.TestRole) &weUserInfo.TestRole)
if err != nil { if err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 1", logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 1",
zap.String("unionID", unionID), zap.String("weUnionID", weUnionID),
zap.Error(err)) zap.Error(err))
return 0 return nil, 0
} }
// 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", weUserID)
if err != nil { if err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 2", logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 2",
zap.Uint32("userID", userID), zap.Uint32("weUserID", weUserID),
zap.Error(err)) zap.Error(err))
fmt.Println(err) fmt.Println(err)
return 0 return &weUserInfo, weUserID
} }
defer rows.Close() defer rows.Close()
var cUserID uint32 var cUserID uint32
var master bool var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0] //weUserInfo.MasterCardUserID = weUserInfo.MasterCardUserID[0:0]
userInfo.SlaveCardUserID = userInfo.SlaveCardUserID[0:0] //weUserInfo.SlaveCardUserID = weUserInfo.SlaveCardUserID[0:0]
for rows.Next() { for rows.Next() {
err = rows.Scan(&cUserID, &master) err = rows.Scan(&cUserID, &master)
if err != nil { if err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 3", logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 3",
zap.Uint32("userID", userID), zap.Uint32("weUserID", weUserID),
zap.Error(err)) zap.Error(err))
continue continue
} }
if master { if master {
userInfo.MasterCardUserID = append(userInfo.MasterCardUserID, cUserID) weUserInfo.MasterCardUserID = append(weUserInfo.MasterCardUserID, cUserID)
} else { } else {
userInfo.SlaveCardUserID = append(userInfo.SlaveCardUserID, cUserID) weUserInfo.SlaveCardUserID = append(weUserInfo.SlaveCardUserID, cUserID)
} }
} }
// 处理完毕后,需要判断一次遍历过程中是否有错误产生 // 处理完毕后,需要判断一次遍历过程中是否有错误产生
if err = rows.Err(); err != nil { if err = rows.Err(); err != nil {
logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 4", logger.Log.Error("SelectUWeCustomerByUnionIDToCacheModel 4",
zap.Uint32("userID", userID), zap.Uint32("weUserID", weUserID),
zap.Error(err)) zap.Error(err))
} }
return return &weUserInfo, weUserID
} }
func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheWeCustomerStruct) (unionID string) { func SelectUWeCustomerByUserIDToCacheModel(userID uint32) (*model.CacheWeCustomerStruct, string) {
var weUserInfo model.CacheWeCustomerStruct
var weUnionID 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, &weUnionID,
&userInfo.WePhone, &weUserInfo.WePhone,
&userInfo.Nickname, &weUserInfo.Nickname,
&userInfo.AvatarURL, &weUserInfo.AvatarURL,
&userInfo.TestRole) &weUserInfo.TestRole)
if err != nil { if err != nil {
logger.Log.Error("SelectUWeCustomerByUserIDToCacheModel 1", logger.Log.Error("SelectUWeCustomerByUserIDToCacheModel 1",
zap.Uint32("userID", userID), zap.Uint32("userID", userID),
zap.Error(err)) zap.Error(err))
return "" return nil, ""
} }
// 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)
...@@ -115,13 +119,11 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW ...@@ -115,13 +119,11 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW
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 &weUserInfo, weUnionID
} }
defer rows.Close() defer rows.Close()
var cUserID uint32 var cUserID uint32
var master bool var master bool
userInfo.MasterCardUserID = userInfo.MasterCardUserID[0:0]
userInfo.SlaveCardUserID = userInfo.SlaveCardUserID[0:0]
for rows.Next() { for rows.Next() {
err = rows.Scan(&cUserID, &master) err = rows.Scan(&cUserID, &master)
if err != nil { if err != nil {
...@@ -131,9 +133,9 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW ...@@ -131,9 +133,9 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW
continue continue
} }
if master { if master {
userInfo.MasterCardUserID = append(userInfo.MasterCardUserID, cUserID) weUserInfo.MasterCardUserID = append(weUserInfo.MasterCardUserID, cUserID)
} else { } else {
userInfo.SlaveCardUserID = append(userInfo.SlaveCardUserID, cUserID) weUserInfo.SlaveCardUserID = append(weUserInfo.SlaveCardUserID, cUserID)
} }
} }
// 处理完毕后,需要判断一次遍历过程中是否有错误产生 // 处理完毕后,需要判断一次遍历过程中是否有错误产生
...@@ -142,5 +144,5 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW ...@@ -142,5 +144,5 @@ func SelectUWeCustomerByUserIDToCacheModel(userID uint32, userInfo *model.CacheW
zap.Uint32("userID", userID), zap.Uint32("userID", userID),
zap.Error(err)) zap.Error(err))
} }
return return &weUserInfo, weUnionID
} }
...@@ -17,6 +17,14 @@ type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过 ...@@ -17,6 +17,14 @@ type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过
Status uint8 //校区状态 0 不展示 1展示 2测试校区 Status uint8 //校区状态 0 不展示 1展示 2测试校区
} }
type CacheAreaServiceStruct struct { // 后续再加支付信息
AreaID uint32
ServiceType uint8 //服务项目 1公话 2定位 3饮水 4POS .........
OperatorID uint32 //运营商ID
//Name string //服务名字(例宿舍135栋饮水)name
Status uint8 //状态 0无内容1正式2测试3暂停4暂未开放
}
type CacheWeCustomerStruct struct { type CacheWeCustomerStruct struct {
TokenCreatTime int64 TokenCreatTime int64
TestRole bool // 测试用户(可看到测试校区) TestRole bool // 测试用户(可看到测试校区)
......
package model
type UpdateUCardUserInfoStruct struct {
Name string `json:"name" example:"汤圆"` // 必填,学生名字,maxLen=16
Grade int8 `json:"grade"` // 必填,"1~9对应一年级~九年级,10~12对应高一~高三"
Sex uint8 `json:"sex"` // 必填,0未知,1女2男
Class int8 `json:"class"` // 必填,班级,0未知
StudentNo string `json:"stuNum"` // 必填,学号,字符串,maxLen=32,""空字符串表示未知
}
type SelectWeGetCallRecordStruct struct {
CalledNumber string `json:"number"` // 被叫号码
CalledNickname string `json:"nickname"` // 昵称
CallStartAt string `json:"startAt"` // 通话开始时间
TalkTime uint8 `json:"time"` // 通话时长,单位(分钟)
Place string `json:"place"` // 位置
}
No preview for this file type
File added
...@@ -327,9 +327,16 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -327,9 +327,16 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
enc := mahonia.NewEncoder("gbk") enc := mahonia.NewEncoder("gbk")
// 1.根据设备编号查status和AreaServiceID // 1.根据设备编号查status和AreaServiceID
v := cache.GetPhone20Info(data.DevID) v := cache.GetPhone20Info(data.DevID)
if v == nil {
data.Data[0] = 0xff
errMessage := enc.ConvertString("设备未在系统注册")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册 if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册
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...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
return return
...@@ -350,15 +357,22 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -350,15 +357,22 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
} }
//2.根据AreaServiceID查status //2.根据AreaServiceID查status
areaService := cache.GetAreaServiceInfo(v.AreaServiceID) areaServiceInfo := cache.GetAreaServiceInfo(v.AreaServiceID)
if areaService.Status == 3 { if areaServiceInfo == nil {
data.Data[0] = 0xff
errMessage := enc.ConvertString("系统配置错误 请联系管理员")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
if areaServiceInfo.Status == 3 {
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...)
data.Length = uint8(len(data.Data)) data.Length = uint8(len(data.Data))
return return
} }
if areaService.Status == 0 || areaService.ServiceType > 2 { if areaServiceInfo.Status == 0 || areaServiceInfo.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...)
...@@ -368,7 +382,15 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -368,7 +382,15 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// 3.根据IccID查卡信息 // 3.根据IccID查卡信息
s := cache.GetSimInfo(string(data.Data[1:])) s := cache.GetSimInfo(string(data.Data[1:]))
if s == nil {
data.Data[0] = 0xff
errMessage := enc.ConvertString("无效卡")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码 if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码
fmt.Println("case 0x60: s.Status==0")
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...)
...@@ -473,9 +495,16 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -473,9 +495,16 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// 1.根据设备编号查status和AreaServiceID // 1.根据设备编号查status和AreaServiceID
v := cache.GetPhone20Info(data.DevID) v := cache.GetPhone20Info(data.DevID)
if v == nil {
data.Data = append(data.Data, 0xff)
errMessage := enc.ConvertString("设备未在系统注册")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册 if v.AreaServiceID == 0 { // 后台没添加该设备,返回显示 话机设备未注册
data.Data = append(data.Data, 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
...@@ -491,6 +520,12 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -491,6 +520,12 @@ 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) data.Data = append(data.Data, 0xff)
if s == nil {
errMessage := enc.ConvertString("无效卡")
data.Data = append(data.Data, errMessage...)
data.Length = uint8(len(data.Data))
return
}
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...)
...@@ -502,6 +537,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -502,6 +537,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
return return
} }
if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码 if s.Status == 0 { // 这张卡不对,显示 未查询到亲情号码
fmt.Println("case 0x63: s.Status == 0")
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))
...@@ -550,65 +586,75 @@ func (dev *DCPhone20) response(data *devproduct.HexData) { ...@@ -550,65 +586,75 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
case 0x62: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID case 0x62: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID
if data.Length > 27 { if data.Length > 27 {
iccID := string(data.Data[0:20]) iccID := string(data.Data[0:20])
// 1. 通过IccID查card_user_id和area_service_id talkTime := uint16(data.Data[24]) + uint16(data.Data[25])<<8
simInfo := cache.GetSimInfo(iccID) 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")
dbInsertData := dbcurd.InsertTableUCallRecordStruct{
var areaServiceInfo cache.AreaServiceStruct DeviceId: data.DevID, // 2. DeviceId
// 2. 通过area_service_id查areaID CallStartAt: callStartAt, // 3. CallStartAt
if simInfo.AreaServiceID > 0 { SimID: iccID, // 5. SimID
areaServiceInfo = cache.GetAreaServiceInfo(simInfo.AreaServiceID) CalledNumber: string(data.Data[27:]), // 6. CalledNumber
TalkTime: talkTime, // 8. TalkTime
Status: data.Data[26], // 12. Status
} }
// 通过areaID查areaName // 1. 通过IccID查card_user_id和area_service_id// 2. 通过area_service_id查areaID operatorID // 3.通过areaID查areaName
var areaName string simInfoP := cache.GetSimInfo(iccID)
if areaServiceInfo.AreaID > 0 { if simInfoP != nil {
areaName = cache.GetAreaMapName(areaServiceInfo.AreaID, true) dbInsertData.CardUserId = simInfoP.CardUserID // 1 CardUserId
} dbInsertData.AreaServiceID = simInfoP.AreaServiceID // 10. AreaServiceID
// 3. 通过card_user_id查name if simInfoP.AreaServiceID > 0 {
var cardUserInfo model.CacheCardUserStruct areaServiceInfoP := cache.GetAreaServiceInfo(simInfoP.AreaServiceID)
if simInfo.CardUserID > 0 { if areaServiceInfoP != nil {
cardUserInfo, _ = cache.GetCardUserInfo(simInfo.CardUserID) dbInsertData.OperatorId = areaServiceInfoP.OperatorID // 11. OperatorId
} if areaServiceInfoP.AreaID > 0 {
dbInsertData.AreaName = cache.GetAreaMapName(areaServiceInfoP.AreaID, true) // 9. AreaName
}
}
}
// 通过simInfo查出called_nickname // 4. 通过card_user_id查name
calledNum := string(data.Data[27:]) if simInfoP.CardUserID > 0 {
var nickname string cardUserInfoP := cache.GetCardUserInfo(simInfoP.CardUserID)
for i := 0; i < len(simInfo.FamilyNum); i++ { if cardUserInfoP != nil {
if calledNum == simInfo.FamilyNum[i].Phone { dbInsertData.CardUserName = cardUserInfoP.Name // 4. CardUserName
nickname = simInfo.FamilyNum[i].Nickname }
break }
// 通过simInfo查出called_nickname
for i := 0; i < len(simInfoP.FamilyNum); i++ {
if dbInsertData.CalledNumber == simInfoP.FamilyNum[i].Phone {
dbInsertData.CalledNickname = simInfoP.FamilyNum[i].Nickname // 7. CalledNickname
break
}
} }
} }
talkTime := uint16(data.Data[24]) + uint16(data.Data[25])<<8 // 5. 通过deviceID查placeUser
v := cache.GetPhone20Info(data.DevID)
if v != nil {
dbInsertData.PlaceUser = v.PlaceUser // 13. PlaceUser
}
// 以事务方式存2张表 // 以事务方式存2张表
if result := dbcurd.InsertUCallRecordAndUpdateUSimInfo(&dbcurd.InsertTableUCallRecordStruct{ if result := dbcurd.InsertUCallRecordAndUpdateUSimInfo(&dbInsertData); result == dbcurd.InsertDuplicate {
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 data.CtrlCode = ctrlCode | 0x80
fmt.Println("通话记录重复") fmt.Println("通话记录重复")
return return
} else if result == dbcurd.InsertOK { } else if result == dbcurd.InsertOK {
// todo 缓存添加学生动态
// 缓存扣套餐分钟数 // 缓存扣套餐分钟数
if talkTime > 0 { if talkTime > 0 {
cache.AddSimMonthTalkMinutes(iccID, (talkTime+59)/60) cache.AddSimMonthTalkMinutes(iccID, (talkTime+59)/60)
} }
// 缓存添加学生动态
if dbInsertData.CardUserId > 0 {
cache.InsertCardUserTrendMap(dbInsertData.CardUserId, &model.CacheCardUserTrendStruct{
ServiceType: 1,
Title: "公话机-" + dbInsertData.PlaceUser,
Content: "被叫:" + dbInsertData.CalledNickname + " 时长:" + strconv.Itoa((int(talkTime)+59)/60) + "分",
Time: callStartAt,
})
}
data.CtrlCode = ctrlCode | 0x80 data.CtrlCode = ctrlCode | 0x80
} }
......
...@@ -141,25 +141,6 @@ definitions: ...@@ -141,25 +141,6 @@ definitions:
description: '""无意义' description: '""无意义'
type: string type: string
type: object 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: api_we.WeResUserInfoStruct:
properties: properties:
area: area:
...@@ -202,28 +183,6 @@ definitions: ...@@ -202,28 +183,6 @@ definitions:
type: integer type: integer
type: array type: array
type: object type: object
api_we.familyNumStruct:
properties:
name:
type: string
phone:
type: string
type: object
api_we.getCallRecordRes:
properties:
nickname:
description: 昵称
type: string
number:
description: 被叫号码
type: string
startAt:
description: 通话开始时间
type: string
time:
description: 通话时长,单位(分钟)
type: integer
type: object
api_we.getPhoneCardStatusRes: api_we.getPhoneCardStatusRes:
properties: properties:
changeable: changeable:
...@@ -254,9 +213,6 @@ definitions: ...@@ -254,9 +213,6 @@ definitions:
avatarURL: avatarURL:
description: 头像URL description: 头像URL
type: string type: string
createAt:
description: 绑定时间
type: string
nickname: nickname:
description: 微信昵称 description: 微信昵称
type: string type: string
...@@ -399,6 +355,43 @@ definitions: ...@@ -399,6 +355,43 @@ definitions:
phone: phone:
type: string type: string
type: object type: object
model.SelectWeGetCallRecordStruct:
properties:
nickname:
description: 昵称
type: string
number:
description: 被叫号码
type: string
place:
description: 位置
type: string
startAt:
description: 通话开始时间
type: string
time:
description: 通话时长,单位(分钟)
type: integer
type: object
model.UpdateUCardUserInfoStruct:
properties:
class:
description: 必填,班级,0未知
type: integer
grade:
description: 必填,"1~9对应一年级~九年级,10~12对应高一~高三"
type: integer
name:
description: 必填,学生名字,maxLen=16
example: 汤圆
type: string
sex:
description: 必填,0未知,1女2男
type: integer
stuNum:
description: 必填,学号,字符串,maxLen=32,""空字符串表示未知
type: string
type: object
info: info:
contact: {} contact: {}
description: 用于家长端微信小程序及web端管理后台 description: 用于家长端微信小程序及web端管理后台
...@@ -552,7 +545,7 @@ paths: ...@@ -552,7 +545,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 副家长解绑学生 summary: 副家长解绑学生 [complete]
tags: tags:
- 家长微信 - 家长微信
get: get:
...@@ -574,7 +567,7 @@ paths: ...@@ -574,7 +567,7 @@ paths:
type: array type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 获取学生副家长列表(仅主家长有权限) summary: 获取学生副家长列表(仅主家长有权限) [complete]
tags: tags:
- 家长微信 - 家长微信
/we/bindcarduser/{share_code}: /we/bindcarduser/{share_code}:
...@@ -611,26 +604,28 @@ paths: ...@@ -611,26 +604,28 @@ paths:
name: id name: id
required: true required: true
type: integer type: integer
- description: 页数 - description: 页数,选填,不填则默认第0页
in: query in: query
name: pnum name: pnum
required: true
type: integer type: integer
- description: 页条数 - description: 页条数,选填,不填则不分页全部返回
in: query in: query
name: psize name: psize
required: true
type: integer type: integer
- description: 起始时间 2020-10-10 10:00:00 - default: "2021-10-01"
description: 起始时间时间和结束时间同时填或同时不填,可以是纯年月日2021-10-01,也可以是带时间年月日时分2021-10-01
10:00或年月日时分秒2021-10-01 10:00:00,年月日时分秒没带全的默认后面为00
in: query in: query
name: start name: start
type: string type: string
- description: 结束时间 2030-10-10 10:00:00 - default: "2021-10-31 23:59:59"
description: 起始时间时间和结束时间同时填或同时不填,可以是纯年月日2021-10-01,也可以是带时间年月日时分2021-10-01
10:00或年月日时分秒2021-10-01 10:00:00,年月日时分秒没带全的默认后面为00
in: query in: query
name: end name: end
type: string type: string
- default: false - default: false
description: 是否升序 description: 是否升序,选填,不填则是降序
in: query in: query
name: asc name: asc
type: boolean type: boolean
...@@ -641,11 +636,11 @@ paths: ...@@ -641,11 +636,11 @@ paths:
description: 通话记录列表 description: 通话记录列表
schema: schema:
items: items:
$ref: '#/definitions/api_we.getCallRecordRes' $ref: '#/definitions/model.SelectWeGetCallRecordStruct'
type: array type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 查询通话记录 summary: 查询通话记录 [complete]
tags: tags:
- 家长微信 - 家长微信
/we/cardbind/{id}: /we/cardbind/{id}:
...@@ -669,7 +664,7 @@ paths: ...@@ -669,7 +664,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 解绑卡 summary: 解绑卡 [complete]
tags: tags:
- 家长微信 - 家长微信
put: put:
...@@ -697,7 +692,7 @@ paths: ...@@ -697,7 +692,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 绑定卡 summary: 绑定卡 [complete]
tags: tags:
- 家长微信 - 家长微信
/we/cardloss/{id}: /we/cardloss/{id}:
...@@ -709,12 +704,13 @@ paths: ...@@ -709,12 +704,13 @@ paths:
name: id name: id
required: true required: true
type: integer type: integer
- description: true挂失,false解挂 - description: 1解挂,2挂失,其他预留无意义
in: query in: query
name: loss name: loss
required: true required: true
type: boolean type: integer
- description: 卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变) - default: 1
description: 卡类型:1电话卡,2定位卡,3IC卡(饮水、消费、洗浴、洗衣机均为IC卡,固任何一个服务的卡挂失状态改变,其余也跟随改变)
in: query in: query
name: type name: type
required: true required: true
...@@ -726,7 +722,7 @@ paths: ...@@ -726,7 +722,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 卡挂失/解挂 summary: 卡挂失/解挂 [complete]
tags: tags:
- 家长微信 - 家长微信
/we/carduser: /we/carduser:
...@@ -789,7 +785,7 @@ paths: ...@@ -789,7 +785,7 @@ paths:
$ref: '#/definitions/api_we.GetCardUserInfoRes' $ref: '#/definitions/api_we.GetCardUserInfoRes'
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 获取单个学生信息[complete不推荐]推荐使用:获取单个学生信息和最新动态 summary: 获取单个学生信息 [complete]
tags: tags:
- 家长微信 - 家长微信
put: put:
...@@ -807,7 +803,7 @@ paths: ...@@ -807,7 +803,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/api_we.PutCardUserReq' $ref: '#/definitions/model.UpdateUCardUserInfoStruct'
produces: produces:
- application/json - application/json
responses: responses:
...@@ -815,7 +811,7 @@ paths: ...@@ -815,7 +811,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 修改学生信息 summary: 修改学生信息 [complete]
tags: tags:
- 家长微信 - 家长微信
/we/cardusertrend/{id}: /we/cardusertrend/{id}:
...@@ -839,7 +835,7 @@ paths: ...@@ -839,7 +835,7 @@ paths:
summary: 获取单个学生信息和最新动态[complete] summary: 获取单个学生信息和最新动态[complete]
tags: tags:
- 家长微信 - 家长微信
/we/familynum: /we/familynum/{id}:
delete: delete:
consumes: consumes:
- application/json - application/json
...@@ -880,7 +876,7 @@ paths: ...@@ -880,7 +876,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/api_we.familyNumStruct' $ref: '#/definitions/model.CacheFamilyOnePerson'
produces: produces:
- application/json - application/json
responses: responses:
...@@ -911,7 +907,7 @@ paths: ...@@ -911,7 +907,7 @@ paths:
name: data name: data
required: true required: true
schema: schema:
$ref: '#/definitions/api_we.familyNumStruct' $ref: '#/definitions/model.CacheFamilyOnePerson'
produces: produces:
- application/json - application/json
responses: responses:
...@@ -1008,7 +1004,7 @@ paths: ...@@ -1008,7 +1004,7 @@ paths:
description: "" description: ""
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 删除副家长(仅主家长有权限) summary: 删除副家长(仅主家长有权限) [complete]
tags: tags:
- 家长微信 - 家长微信
/we/stulist: /we/stulist:
...@@ -1042,7 +1038,7 @@ paths: ...@@ -1042,7 +1038,7 @@ paths:
type: array type: array
security: security:
- ApiKeyAuth: [] - ApiKeyAuth: []
summary: 微信学生首页,获取近20条用户最新动态 [complete不推荐]推荐使用:获取单个学生信息和最新动态 summary: 微信学生首页,获取近20条用户最新动态 [complete]
tags: tags:
- 家长微信 - 家长微信
securityDefinitions: securityDefinitions:
......
{"level":"INFO","ts":"2021-10-28 17:40:10.206","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":74277,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":405,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:40:27.981","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":237,"Ip":"127.0.0.1","Method":"GET","Path":"/we/phonecardstatus/5","DataSize":276,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:40:37.046","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":37842,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":116,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:40:44.399","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":998,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":64,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:40:51.534","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":38383,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":116,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:40:56.179","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":36648,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":116,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:41:00.418","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":40236,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":116,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
{"level":"INFO","ts":"2021-10-28 17:41:04.822","msg":"","HostName":"DESKTOP-2789F62","Status":200,"SpendNanoS":74008,"Ip":"127.0.0.1","Method":"POST","Path":"/we/login/%7Bcode%7D","DataSize":116,"Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400"}
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