Commit 79bfae0c by zhangjiec

调整目录结构

parent 4bf1f194
package api_public
import (
"dc_golang_server_1/cache"
"dc_golang_server_1/api"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"dc_golang_server_1/web"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"net/http"
......@@ -15,12 +16,12 @@ import (
// @Summary 获取全国省份列表 [complete]
// @Description 获取带首字母的省份列表
// @Product json
// @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Success 0 {object} []model.CacheBDistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Router /base/province [GET]
// @Security ApiKeyAuth
func GetProvinceList(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": cache.ProvinceMap,
})
}
......@@ -31,15 +32,15 @@ func GetProvinceList(c *gin.Context) {
// @Description 获取带首字母的城市列表
// @Param provinceID path integer true "省份id"
// @Product json
// @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Success 0 {object} []model.CacheBDistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Router /base/city/{provinceID} [GET]
// @Security ApiKeyAuth
func GetCityList(c *gin.Context) {
para, _ := strconv.Atoi(c.Param("id"))
v, _ := cache.CityMap.Load(uint32(para)) // 如果查不到就直接返回空data
// data, _ := v.([]cache.DistrictStruct)
// data, _ := v.([]model.CacheBDistrictStruct)
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": v,
})
}
......@@ -50,13 +51,13 @@ func GetCityList(c *gin.Context) {
// @Description 获取带首字母的城市列表
// @Param cityID path integer true "城市ID"
// @Product json
// @Success 0 {object} []cache.DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Success 0 {object} []model.CacheBDistrictStruct "按首字母排序好的列表,可直接用作展示"
// @Router /base/county/{cityID} [GET]
// @Security ApiKeyAuth
func GetCountyList(c *gin.Context) {
para, _ := strconv.Atoi(c.Param("id"))
v, _ := cache.CountyMap.Load(uint32(para)) // 如果查不到就直接返回空data
// data, _ := v.([]cache.DistrictStruct)
// data, _ := v.([]model.CacheBDistrictStruct)
c.JSON(http.StatusOK, gin.H{
"code": 0,
"data": v,
......@@ -81,8 +82,8 @@ func GetAreaByCounty(c *gin.Context) {
countyID, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.JSON(http.StatusOK, gin.H{
"code": web.ErrorReqParaFormat,
"message": web.CodeMsg[web.ErrorReqParaFormat],
"code": api.ErrorReqParaFormat,
"message": api.CodeMsg[api.ErrorReqParaFormat],
})
return
}
......@@ -92,8 +93,8 @@ func GetAreaByCounty(c *gin.Context) {
zap.String("Src", "GetAreaByCounty"),
zap.Int("countyID", countyID))
c.JSON(http.StatusOK, gin.H{
"code": web.ErrorSystemErr,
"message": web.CodeMsg[web.ErrorSystemErr],
"code": api.ErrorSystemErr,
"message": api.CodeMsg[api.ErrorSystemErr],
})
return
}
......@@ -101,20 +102,13 @@ func GetAreaByCounty(c *gin.Context) {
testRole, ok := cache.GetWechatCustomerTestRole(userID.(uint32))
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": web.ErrorUserTokenWrong,
"message": web.CodeMsg[web.ErrorUserTokenWrong],
"code": api.ErrorUserTokenWrong,
"message": api.CodeMsg[api.ErrorUserTokenWrong],
})
return
}
areaList, ok := cache.GetCountyAreaMap(uint32(countyID))
if ok == false {
c.JSON(http.StatusOK, gin.H{
"code": web.ErrorReqPara,
"message": web.CodeMsg[web.ErrorReqPara] + ",区县id=" + strconv.Itoa(countyID),
})
return
}
areaList := cache.GetCountyAreaMap(uint32(countyID))
var data []countyAreaRes
......@@ -126,7 +120,7 @@ func GetAreaByCounty(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": data,
})
}
......@@ -180,8 +174,8 @@ func GetAreaByLocation(c *gin.Context) {
}
var data []locationAreaRes
v, _ := cache.AreaMap.Load(uint32(14)) // todo 根据经纬度计算距离 还要看status 和 用户的权限
if a, ok := v.(cache.AreaStruct); ok { //类型断言正确
v, _ := cache.AreaMap.Load(uint32(14)) // todo 根据经纬度计算距离 还要看status 和 用户的权限
if a, ok := v.(model.CacheBAreaStruct); ok { //类型断言正确
data = append(data, locationAreaRes{
a.Name,
"温江区",
......@@ -190,7 +184,7 @@ func GetAreaByLocation(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": data,
})
}
package api_we
import (
"dc_golang_server_1/web"
//"dc_golang_server_1/web"
"dc_golang_server_1/api"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
// DeleteCardUser 主家长删除一个学生
// @Tags 家长微信
// @Summary 主家长删除一个学生
// @Description 传学生ID至后台,后台返回成功失败
// @Produce json
// @Param id path integer true "学生ID"
// @Success 0
// @Router /we/carduser/{id} [DELETE]
// @Security ApiKeyAuth
func DeleteCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
})
}
type bindCardUserRes struct {
Master bool `json:"master" example:"false"` //true:本来就是主家长,false:已成功绑定成副家长
ID uint32 `json:"id"` // 学生ID
......@@ -49,7 +33,7 @@ type bindCardUserRes struct {
func BindCardUser(c *gin.Context) {
res := bindCardUserRes{}
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": res,
})
}
......@@ -65,7 +49,7 @@ func BindCardUser(c *gin.Context) {
// @Security ApiKeyAuth
func DeleteBindCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -88,7 +72,7 @@ type wechatCardUsersTrendType struct {
func GetCardUsersTrend(c *gin.Context) {
//id, _ := strconv.Atoi(c.Param("id"))
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": [20]wechatCardUsersTrendType{},
})
}
......@@ -124,7 +108,7 @@ type slaveWeUserRes struct {
// @Security ApiKeyAuth
func GetBindCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": []slaveWeUserRes{},
})
}
......@@ -141,7 +125,7 @@ func GetBindCardUser(c *gin.Context) {
// @Security ApiKeyAuth
func CardUserShareCode(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": "todo",
})
}
......@@ -157,7 +141,7 @@ func CardUserShareCode(c *gin.Context) {
//// @Security ApiKeyAuth
//func PutCardUserShareOn(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "code": web.Success,
// "code": api.Success,
// })
//}
......@@ -172,7 +156,7 @@ func CardUserShareCode(c *gin.Context) {
//// @Security ApiKeyAuth
//func PutCardUserShareOff(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "code": web.Success,
// "code": api.Success,
// })
//}
......@@ -188,7 +172,7 @@ func CardUserShareCode(c *gin.Context) {
// @Security ApiKeyAuth
func DeleteSlaveWeUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -204,7 +188,7 @@ func DeleteSlaveWeUser(c *gin.Context) {
//// @Security ApiKeyAuth
//func DeleteAllSlaveWeUser(c *gin.Context) {
// c.JSON(http.StatusOK, gin.H{
// "code": web.Success,
// "code": api.Success,
// })
//}
......@@ -234,7 +218,7 @@ type PutCardUserReq struct {
// @Security ApiKeyAuth
func PutCardUser(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -251,7 +235,7 @@ func PutCardUser(c *gin.Context) {
// @Security ApiKeyAuth
func CardLoss(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -268,7 +252,7 @@ func CardLoss(c *gin.Context) {
// @Security ApiKeyAuth
func CardBind(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -284,7 +268,7 @@ func CardBind(c *gin.Context) {
// @Security ApiKeyAuth
func DeleteCardBind(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -314,7 +298,7 @@ type getPhoneCardStatusRes struct {
// @Security ApiKeyAuth
func GetPhoneCardStatus(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": getPhoneCardStatusRes{},
})
}
......@@ -346,7 +330,7 @@ type getCallRecordRes struct {
// @Security ApiKeyAuth
func GetCallRecord(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
"data": [2]getCallRecordRes{},
})
}
......@@ -364,7 +348,7 @@ func GetCallRecord(c *gin.Context) {
// @Security ApiKeyAuth
func AddFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -382,7 +366,7 @@ func AddFamilyNum(c *gin.Context) {
// @Security ApiKeyAuth
func PutFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
......@@ -399,6 +383,6 @@ func PutFamilyNum(c *gin.Context) {
// @Security ApiKeyAuth
func DeleteFamilyNum(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"code": web.Success,
"code": api.Success,
})
}
package web
package api
import (
"github.com/gin-gonic/gin"
......
package web
package api
const (
Success = 0
......
package web
package api
import (
"dc_golang_server_1/cache"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/util"
"github.com/gin-gonic/gin"
"math/rand"
......@@ -247,7 +247,7 @@ func JeffWTAdmin() gin.HandlerFunc {
}
}
//package web
//package api
//
//import (
// "dc_golang_server_1/cache"
......
package router
import (
"dc_golang_server_1/config"
"dc_golang_server_1/api"
"dc_golang_server_1/api/api_admin"
"dc_golang_server_1/api/api_public"
"dc_golang_server_1/api/api_we"
_ "dc_golang_server_1/docs"
"dc_golang_server_1/logger"
"dc_golang_server_1/web"
"dc_golang_server_1/web/api_admin"
"dc_golang_server_1/web/api_public"
"dc_golang_server_1/web/api_we"
config2 "dc_golang_server_1/util/config"
"fmt"
"github.com/gin-gonic/gin"
"github.com/swaggo/gin-swagger"
......@@ -16,18 +16,18 @@ import (
)
func InitRouter() { //*gin.Engine{
gin.SetMode(config.HttpServerMode)
gin.SetMode(config2.HttpServerMode)
r := gin.New()
r.Use(logger.HttpGinLog(), gin.Recovery())
r.Use(web.Cors()) //全局跨域 局部跨域的话在路由组里面去添加
r.Use(api.Cors()) //全局跨域 局部跨域的话在路由组里面去添加
//r.Use(CheckToken()) //jwt 还是在对应需要token的路由组添加
if config.HttpServerSwagger {
if config2.HttpServerSwagger {
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
base := r.Group("base/")
base.Use(web.JeffWTPublic())
base.Use(api.JeffWTPublic())
{
base.GET("province", api_public.GetProvinceList)
base.GET("city/:id", api_public.GetCityList)
......@@ -38,7 +38,7 @@ func InitRouter() { //*gin.Engine{
r.POST("we/login/:code", api_we.WeLogin)
wechat := r.Group("we/")
wechat.Use(web.JeffWTWechat())
wechat.Use(api.JeffWTWechat())
{ // 需要token的
wechat.POST("carduser", api_we.CreateCardUser) //创建学生
wechat.DELETE("carduser/:id", api_we.DeleteCardUser) //删除学生
......@@ -71,15 +71,15 @@ func InitRouter() { //*gin.Engine{
// r.POST("ad/login", api_we.AdminLogin)
admin := r.Group("ad/")
// admin.Use(web.JeffWTAdmin())
// admin.Use(api.JeffWTAdmin())
{
admin.POST("area", api_admin.CreateArea) // 新建一个学校
// admin.GET("cache", api_cache.GetCacheMap) // 获取缓存内容
}
fmt.Println(time.Now(), "server is running:swagger", config.HttpServerSwagger)
fmt.Println(time.Now(), "server is running:swagger", config2.HttpServerSwagger)
err := r.Run(config.HttpServerPort)
err := r.Run(config2.HttpServerPort)
if err != nil {
panic(err)
}
......
package cache
import (
"dc_golang_server_1/data_db_cache/model"
"sync"
"time"
)
// ProvinceMap /*********************************************************全国行政区域**/------------------------OK
var ProvinceMap []DistrictStruct // 省份列表[]District
var CityMap sync.Map // 城市列表map[uint32][]District //省份ID作为KEY
var CountyMap sync.Map // 区县列表map[uint32][]District //城市ID作为KEY
type DistrictStruct struct {
Id uint32 `json:"id" example:"1"`
Name string `json:"name" example:"四川省"`
Initial string `json:"initial" example:"S"`
}
var ProvinceMap []model.CacheBDistrictStruct // 省份列表[]model.CacheBDistrictStruct
var CityMap sync.Map // 城市列表map[uint32][]model.CacheBDistrictStruct //省份ID作为KEY
var CountyMap sync.Map // 区县列表map[uint32][]model.CacheBDistrictStruct //城市ID作为KEY
//type CacheBDistrictStruct struct {
// Id uint32 `json:"id" example:"1"`
// Name string `json:"name" example:"四川省"`
// Initial string `json:"initial" example:"S"`
//}
// CountyAreaMap /******************************************************************区县学校列表**/
var CountyAreaMap sync.Map //map[uint32][[]uint32] 区县ID作为KEY,[]area_id 作为Value
// var LockCountyAreaMap bool // todo 正规的做法是用 map[区县ID]bool
// TestAreaMap /******************************************************************测试校区列表**/
// AreaMap /******************************************************区域(校区)**/
var AreaMap sync.Map //area_id 作为KEY AreaStruct 作为VALUE
type AreaStruct struct { // AreaStruct 区域信息缓存,通过区域ID查出,后续再加支付信息
Name string
Longitude uint32
Latitude uint32
CountyID uint32
AreaService []uint32
Status uint8 //校区状态 0 不展示 1展示 2测试校区
// CreatAt time.Time
}
var AreaMap sync.Map //area_id 作为KEY CacheBAreaStruct 作为VALUE
//type CacheBAreaStruct struct { // CacheBAreaStruct 区域信息缓存,通过区域ID查出,后续再加支付信息
// Name string
// Longitude uint32
// Latitude uint32
// CountyID uint32
// AreaService []uint32
// Status uint8 //校区状态 0 不展示 1展示 2测试校区
//}
// var LockAreaMapAreaService bool todo
/*********************************************************代理商**/
//// AgentMap 代理商
......@@ -47,7 +50,7 @@ type OperatorStruct struct {
/*---------------------------------------------------------------*/
/******************************************************区域(校区)服务信息**/
var areaServiceMap sync.Map //area_service_id 作为KEY AreaStruct 作为VALUE
var areaServiceMap sync.Map //area_service_id 作为KEY CacheBAreaStruct 作为VALUE
type AreaServiceStruct struct { //
AreaID uint32
ServiceID uint8 //服务项目 1公话 2定位 3饮水 4POS .........
......@@ -71,6 +74,7 @@ type AdminStruct struct {
AreaServiceAuth [][]uint32 //area_service_id,admin_role_id
}
// todo 加锁var LockAreaMapAreaService bool
/*---------------------------------------------------------------*/
// roleAuthMap /****************************角色权限(包含区域和系统角色)*/
......@@ -80,22 +84,24 @@ type RoleAuthStruct struct {
MenuRole map[uint32][]uint32 // 菜单、按钮权限
}
// todo 加锁
/***************************************************微信用户(家长)**/ //------------------------OK
var WechatCustomerUnionIDToIDMAP sync.Map // UnionID作为KEY(string),微信用户ID作为VALUE(uint32)
var WechatCustomerMap sync.Map // 微信的WechatUserID(uint32)作为KEY
type WechatCustomerStruct struct {
TokenCreatTime int64
TestRole bool // 测试用户(可看到测试校区)
WePhone string // 手机号
Nickname string // 微信昵称
AvatarURL string // 头像链接
MasterCardUserID []uint32 // 自己创建的学生用户
SlaveCardUserID []uint32 // 被邀请查看的学生用户
}
//type CacheUWeCustomerStruct struct {
// TokenCreatTime int64
// TestRole bool // 测试用户(可看到测试校区)
// WePhone string // 手机号
// Nickname string // 微信昵称
// AvatarURL string // 头像链接
// MasterCardUserID []uint32 // 自己创建的学生用户
// SlaveCardUserID []uint32 // 被邀请查看的学生用户
//}
// todo 加锁
/****************************************************************/
/***************************************************卡用户(学生、教师、职工)**/
//CardUserMap /***************************************************卡用户(学生、教师、职工)**/
var CardUserMap sync.Map //卡用户 CardUserID卡用户ID(uint32) 作为KEY 纯卡用户可以不绑定微信
type CardUserType struct {
MasterWechatUserID uint32
......@@ -121,6 +127,7 @@ type CardUserType struct {
IcCardID uint32
}
// todo 加锁SlaveWechatUserID
/*---------------------------------------------------------------*/
/*******************************************************电话设备**/
......@@ -148,6 +155,7 @@ type FamilyOnePerson struct {
Nickname string
}
// todo 加锁FamilyNum
/*---------------------------------------------------------------*/
/***************************************************卡用户动态**/
......@@ -162,7 +170,7 @@ type CardUserTrendType struct {
/*---------------------------------------------------------------*/
func Init() {
initBCityMaps() // 初始化行政区域省市区缓存
initBDistrictMaps() // 初始化行政区域省市区缓存
initAreaMapAndCountyAreaMap()
initWechatCustomerMap()
......
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -25,8 +26,8 @@ import (
func initAreaMapAndCountyAreaMap() {
fmt.Println(time.Now(), "cache: initAreaMap begin")
var areaID uint32
var temp AreaStruct
rows, err := dbmodel.PgDb.Query("SELECT id,county_id,name,longitude,latitude,status FROM b_area") //
var temp model.CacheBAreaStruct
rows, err := dbdao.PgDb.Query("SELECT id,county_id,name,longitude,latitude,status FROM b_area") //
defer rows.Close()
if err != nil {
log.Panicln("SelectAreaToMap rows", err)
......@@ -59,7 +60,7 @@ func initAreaMapAndCountyAreaMap() {
func GetAreaMapName(areaID uint32, test bool) string {
if v, ok := AreaMap.Load(areaID); ok {
if data, ok := v.(AreaStruct); ok {
if data, ok := v.(model.CacheBAreaStruct); ok {
if data.Status == 1 || (data.Status == 2 && test) {
return data.Name
}
......@@ -79,9 +80,9 @@ func GetAreaMapName(areaID uint32, test bool) string {
return ""
}
func GetAreaMapInfo(areaID uint32, info *AreaStruct) bool {
func GetAreaMapInfo(areaID uint32, info *model.CacheBAreaStruct) bool {
if v, ok := AreaMap.Load(areaID); ok {
if *info, ok = v.(AreaStruct); ok {
if *info, ok = v.(model.CacheBAreaStruct); ok {
return true
} else {
AreaMap.Delete(areaID)
......
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -13,7 +13,7 @@ func initAreaServiceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin")
var areaID int32
var temp AreaServiceStruct
rows, err := dbmodel.PgDb.Query("SELECT id,name,status FROM b_area") //todo
rows, err := dbdao.PgDb.Query("SELECT id,name,status FROM b_area") //todo
defer rows.Close()
if err != nil {
log.Panicln("SelectAreaToMap rows", err)
......@@ -57,7 +57,7 @@ func GetAreaServiceInfo(areaServiceID uint32) (areaServiceInfo AreaServiceStruct
var err error
for i := 0; i < 10; i++ {
err = dbmodel.PgDb.QueryRow("SELECT name,status FROM b_area WHERE id=$1",
err = dbdao.PgDb.QueryRow("SELECT name,status FROM b_area WHERE id=$1",
areaServiceID).Scan(&areaServiceInfo.Name, &areaServiceInfo.Status) //todo
if err != nil {
fmt.Println("GetAreaInfo SELECT:", i, err)
......
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -11,21 +12,21 @@ import (
)
// 初始化行政区域缓存
func initBCityMaps() {
fmt.Println(time.Now(), "cache: initBCityMaps begin")
func initBDistrictMaps() {
fmt.Println(time.Now(), "cache: initBDistrictMaps begin")
go func() bool {
ProvinceMap = []DistrictStruct{} //先清空原来的缓存
var temp DistrictStruct
rows, err := dbmodel.PgDb.Query("SELECT id,name,initial FROM b_city WHERE level=1 ORDER BY initial,sort")
ProvinceMap = []model.CacheBDistrictStruct{} //先清空原来的缓存
var temp model.CacheBDistrictStruct
rows, err := dbdao.PgDb.Query("SELECT id,name,initial FROM b_district WHERE level=1 ORDER BY initial,sort")
defer rows.Close()
if err != nil {
log.Panicln("ProvinceMap SELECT b_city rows", err)
log.Panicln("ProvinceMap SELECT b_district rows", err)
}
for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &temp.Initial)
if err != nil {
log.Panicln("ProvinceMap SELECT b_city rows.Scan", err)
log.Panicln("ProvinceMap SELECT b_district rows.Scan", err)
}
ProvinceMap = append(ProvinceMap, temp)
}
......@@ -38,7 +39,7 @@ func initBCityMaps() {
selectToDistrictMap(2, &CityMap)
selectToDistrictMap(3, &CountyMap)
fmt.Println(time.Now(), "cache: initBCityMaps OK")
fmt.Println(time.Now(), "cache: initBDistrictMaps OK")
}
func selectToDistrictMap(level uint8, tempMap *sync.Map) bool {
......@@ -49,22 +50,22 @@ func selectToDistrictMap(level uint8, tempMap *sync.Map) bool {
})
var parentID uint32
var temp DistrictStruct
rows, err := dbmodel.PgDb.Query("SELECT id,name,parent_id,initial FROM b_city WHERE level=$1 ORDER BY initial,sort", level)
var temp model.CacheBDistrictStruct
rows, err := dbdao.PgDb.Query("SELECT id,name,parent_id,initial FROM b_district WHERE level=$1 ORDER BY initial,sort", level)
defer rows.Close()
if err != nil {
log.Panicln("SELECT b_city rows", err, level)
log.Panicln("SELECT b_district rows", err, level)
}
for rows.Next() {
err = rows.Scan(&temp.Id, &temp.Name, &parentID, &temp.Initial)
if err != nil {
log.Panicln("SELECT b_city rows.Scan", err, level)
log.Panicln("SELECT b_district rows.Scan", err, level)
}
var bufStruct []DistrictStruct
var bufStruct []model.CacheBDistrictStruct
if v, ok := tempMap.Load(parentID); ok { //map已经有了
if bufStruct, ok = v.([]DistrictStruct); ok == false { //类型断言错误
if bufStruct, ok = v.([]model.CacheBDistrictStruct); ok == false { //类型断言错误
tempMap.Delete(parentID)
logger.Log.Error("[]DistrictStruct 类型断言错误",
logger.Log.Error("[]BDistrictStruct 类型断言错误",
zap.Uint8("level", level),
zap.String("src", "selectToDistrictMap"))
}
......
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -24,7 +24,7 @@ func initCardUserMap() {
fmt.Println(time.Now(), "cache: initCardUserMap begin")
var cardUserID uint32
var temp CardUserType
rows, err := dbmodel.PgDb.Query("SELECT id,role,name,sex,area_id,grade,class,student_num,first_topup_at is not null FROM u_card_user") //
rows, err := dbdao.PgDb.Query("SELECT id,role,name,sex,area_id,grade,class,student_num,first_topup_at is not null FROM u_card_user") //
defer rows.Close()
if err != nil {
log.Panicln("Select u_card_user To Map rows", err)
......
......@@ -5,22 +5,19 @@ import (
"go.uber.org/zap"
)
func GetCountyAreaMap(countyID uint32) ([]uint32, bool) {
func GetCountyAreaMap(countyID uint32) []uint32 {
var data []uint32
if v, ok := CountyAreaMap.Load(countyID); ok {
if data, ok = v.([]uint32); ok {
return data, true
return data
} else {
CountyAreaMap.Delete(countyID)
logger.Log.Error("CountyAreaMap 类型断言错误",
zap.String("Src", "GetCountyAreaMap"),
zap.Uint32("countyID", countyID))
// todoN 查库
}
}
logger.Log.Error("CountyAreaMap 没数据",
zap.String("Src", "GetCountyAreaMap"),
zap.Uint32("countyID", countyID))
return data, false
return data
}
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -13,7 +13,7 @@ func initPhone20DeviceMap() {
fmt.Println(time.Now(), "cache: initDeviceMap begin")
var devID uint32
var temp Phone20DeviceStruct
rows, err := dbmodel.PgDb.Query("SELECT id,area_service_id,allow_call_time,status FROM d_device")
rows, err := dbdao.PgDb.Query("SELECT id,area_service_id,allow_call_time,status FROM d_device")
defer rows.Close()
if err != nil {
log.Panicln("SelectDeviceToMap rows", err)
......@@ -50,7 +50,7 @@ func GetPhone20Info(devID uint32) Phone20DeviceStruct {
var temp Phone20DeviceStruct
var err error
for i := 0; i < 100; i++ {
err = dbmodel.PgDb.QueryRow("SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE id=$1",
err = dbdao.PgDb.QueryRow("SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE id=$1",
devID).Scan(&temp.AreaServiceID, &temp.AllowCallTime, &temp.Status)
if err != nil {
fmt.Println("GetPhone20Info SELECT:", i, err)
......
package cache
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/data_db_cache/model"
"dc_golang_server_1/logger"
"fmt"
"go.uber.org/zap"
......@@ -14,9 +15,9 @@ func initWechatCustomerMap() {
fmt.Println(time.Now(), "cache: initWechatCustomerMap begin")
var weUserID uint32
var unionID string
var temp WechatCustomerStruct
var temp model.CacheUWeCustomerStruct
// 1. 查u_we_customer表获得基础数据
rows, err := dbmodel.PgDb.Query("SELECT id,unionid,phone,nickname,avatarurl,test_role FROM u_we_customer") //
rows, err := dbdao.PgDb.Query("SELECT id,unionid,phone,nickname,avatarurl,test_role FROM u_we_customer") //
// defer rows.Close()
if err != nil {
rows.Close()
......@@ -42,7 +43,7 @@ func initWechatCustomerMap() {
rows.Close()
// 2. 查家长学生对应关系表u_we_card_user表,获得绑定的学生数据
rows, err = dbmodel.PgDb.Query("SELECT we_user_id,card_user_id,master FROM u_we_card_user order by create_at") //
rows, err = dbdao.PgDb.Query("SELECT we_user_id,card_user_id,master FROM u_we_card_user order by create_at") //
defer rows.Close()
if err != nil {
log.Panicln("Select u_we_card_user rows", err)
......@@ -57,7 +58,7 @@ func initWechatCustomerMap() {
}
if master {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if value, ok := v.(WechatCustomerStruct); ok {
if value, ok := v.(model.CacheUWeCustomerStruct); ok {
value.MasterCardUserID = append(value.MasterCardUserID, cUserID)
WechatCustomerMap.Store(weUserID, value)
} else {
......@@ -76,7 +77,7 @@ func initWechatCustomerMap() {
}
} else {
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if value, ok := v.(WechatCustomerStruct); ok {
if value, ok := v.(model.CacheUWeCustomerStruct); ok {
value.SlaveCardUserID = append(value.SlaveCardUserID, cUserID)
WechatCustomerMap.Store(weUserID, value)
} else {
......@@ -104,9 +105,9 @@ func initWechatCustomerMap() {
}
func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
var data WechatCustomerStruct
var data model.CacheUWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(WechatCustomerStruct); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
return data.TokenCreatTime //正常情况
} else {
logger.Log.Error("WechatCustomerMap 类型断言错误",
......@@ -123,9 +124,9 @@ func GetWechatCustomerTokenCreatTime(weUserID uint32) int64 {
}
func GetWechatCustomerTestRole(userID uint32) (bool, bool) {
var data WechatCustomerStruct
var data model.CacheUWeCustomerStruct
if v, ok := WechatCustomerMap.Load(userID); ok {
if data, ok = v.(WechatCustomerStruct); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
return data.TestRole, true //正常情况
} else {
logger.Log.Error("WechatCustomerMap 类型断言错误",
......@@ -153,10 +154,10 @@ func GetWechatCustomerUserIDByUnionID(unionID string) uint32 {
return 0
}
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (WechatCustomerStruct, bool) {
var data WechatCustomerStruct
func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64) (model.CacheUWeCustomerStruct, bool) {
var data model.CacheUWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(WechatCustomerStruct); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if newTime != 0 {
data.TokenCreatTime = newTime
WechatCustomerMap.Store(weUserID, data)
......@@ -181,12 +182,16 @@ func GetWechatCustomerInfoAndCanUpdateTokenTime(weUserID uint32, newTime int64)
return data, false
}
func InsertWechatCustomerMap(unionID string, userInfo *WechatCustomerStruct) uint32 {
func InsertWechatCustomerMap(unionID string, userInfo *model.CacheUWeCustomerStruct) uint32 {
//id := dbdao.InsertUWeCustomerUnionID(unionID)
//if id == 0{
//
//}
var err error
//var res sql.Result
var id uint32
for i := 0; i < 10; i++ {
err = dbmodel.PgDb.QueryRow("INSERT INTO u_we_customer(unionid)VALUES($1)RETURNING id", unionID).Scan(&id)
err = dbdao.PgDb.QueryRow("INSERT INTO u_we_customer(unionid)VALUES($1)RETURNING id", unionID).Scan(&id)
if err == nil {
WechatCustomerUnionIDToIDMAP.Store(unionID, id)
WechatCustomerMap.Store(id, *userInfo)
......@@ -206,10 +211,10 @@ func InsertWechatCustomerMap(unionID string, userInfo *WechatCustomerStruct) uin
return 0
}
func selectDBWechatCustomerByUserIDToCache(userID uint32, userInfo *WechatCustomerStruct) bool {
func selectDBWechatCustomerByUserIDToCache(userID uint32, userInfo *model.CacheUWeCustomerStruct) bool {
var unionID string
// 1. 查u_we_customer表获得基础数据
err := dbmodel.PgDb.QueryRow("SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1", userID).Scan(
err := dbdao.PgDb.QueryRow("SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1", userID).Scan(
&unionID,
&userInfo.WePhone,
&userInfo.Nickname,
......@@ -222,7 +227,7 @@ func selectDBWechatCustomerByUserIDToCache(userID uint32, userInfo *WechatCustom
return false
}
// 2. 查u_we_card_user表,获得绑定的学生数据
rows, err := dbmodel.PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
rows, err := dbdao.PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
defer rows.Close()
if err != nil {
logger.Log.Error("selectDBWechatCustomerByUserIDToCache rows 错误",
......@@ -259,9 +264,9 @@ func selectDBWechatCustomerByUserIDToCache(userID uint32, userInfo *WechatCustom
return true
}
func selectDBWechatCustomerByUnionIDToCache(unionID string, userInfo *WechatCustomerStruct) (userID uint32) { //返回userID
func selectDBWechatCustomerByUnionIDToCache(unionID string, userInfo *model.CacheUWeCustomerStruct) (userID uint32) { //返回userID
// 1. 查u_we_customer表获得基础数据
err := dbmodel.PgDb.QueryRow("SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1", unionID).Scan(
err := dbdao.PgDb.QueryRow("SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1", unionID).Scan(
&userID,
&userInfo.WePhone,
&userInfo.Nickname,
......@@ -274,7 +279,7 @@ func selectDBWechatCustomerByUnionIDToCache(unionID string, userInfo *WechatCust
return
}
// 2. 查u_we_card_user表,获得绑定的学生数据
rows, err := dbmodel.PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
rows, err := dbdao.PgDb.Query("SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at", userID)
defer rows.Close()
if err != nil {
logger.Log.Error("selectDBWechatCustomerByUnionIDToCache rows 错误",
......@@ -314,9 +319,9 @@ func selectDBWechatCustomerByUnionIDToCache(unionID string, userInfo *WechatCust
// InsertNewStudentIDToWechatCustomerMap 缓存定制方法:微信用户增加/绑定卡用户
func InsertNewStudentIDToWechatCustomerMap(weUserID uint32, cardUserID uint32, master bool) bool {
var data WechatCustomerStruct
var data model.CacheUWeCustomerStruct
if v, ok := WechatCustomerMap.Load(weUserID); ok {
if data, ok = v.(WechatCustomerStruct); ok {
if data, ok = v.(model.CacheUWeCustomerStruct); ok {
if master {
data.MasterCardUserID = append(data.MasterCardUserID, cardUserID)
} else {
......
package dbmodel
package dbdao
//CREATE TABLE IF NOT EXISTS public.d_device
//(
......
package dbmodel
package dbdao
import (
"dc_golang_server_1/logger"
......
package dbmodel
package dbdao
import (
"dc_golang_server_1/logger"
......
package dbmodel
package dbdao
import (
"dc_golang_server_1/logger"
......
package dbmodel
package dbdao
import (
"dc_golang_server_1/logger"
......
package dbmodel
package dbdao
import (
"database/sql"
"dc_golang_server_1/config"
config2 "dc_golang_server_1/util/config"
_ "github.com/lib/pq"
)
......@@ -17,7 +17,7 @@ var stmtInsertDevHexResetRecord *sql.Stmt
func InitDb() {
var err error
// fmt.Println("DBDSN",config.DbDSN)
PgDb, err = sql.Open("postgres", config.DbDSN)
PgDb, err = sql.Open("postgres", config2.DbDSN)
if err != nil {
panic("数据库连接失败" + err.Error())
}
......
package dbmodel
package dbdao
import (
"dc_golang_server_1/logger"
......
package dbmodel
package dbdao
//CREATE TABLE IF NOT EXISTS public.u_sim_info
//(
......
package devproduct
import (
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/logger"
"dc_golang_server_1/util"
"encoding/hex"
......@@ -37,7 +37,7 @@ type HexData struct {
}
func /*(d *DCLongTCPHex)*/ insertDevHexCommandRecord(data *HexData, ciphertext string, direction uint8) {
go dbmodel.InsertDevCommandRecord(dbmodel.TableDevHexCommandRecord{
go dbdao.InsertDevCommandRecord(dbdao.TableDevHexCommandRecord{
DevID: data.DevID,
DevUtc: data.TimeUtc,
CtrlCode: strconv.FormatUint(uint64(data.CtrlCode), 16),
......@@ -52,20 +52,20 @@ func (d *DCLongTCPHex) receiveResponse(conn *net.TCPConn, data []byte, nowConnDe
c, err := util.DecryptBase64ToBytes(data, d.password, d.iv)
if err != nil {
if nowConnDevID != 0 {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "Decrypt err")
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "Decrypt err")
}
return 0
}
if util.CheckCRC(c) == false {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "CheckCRC err")
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "CheckCRC err")
return 0
}
cLen := len(c)
if cLen < 12 {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "cLen<12")
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "cLen<12")
return 0
} else if int(c[9])+12 != cLen {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "cLen!=c[9]+12")
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "cLen!=c[9]+12")
return 0
}
......@@ -75,13 +75,13 @@ func (d *DCLongTCPHex) receiveResponse(conn *net.TCPConn, data []byte, nowConnDe
// 时间有效性判断
nowTimeUtc := uint32(time.Now().Unix())
if nowTimeUtc > rData.TimeUtc+300 || rData.TimeUtc > nowTimeUtc+300 {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "utc err:"+strconv.FormatUint(uint64(rData.TimeUtc), 10))
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "utc err:"+strconv.FormatUint(uint64(rData.TimeUtc), 10))
return 0
}
// 设备类型判断
if c[4] != d.devType {
dbmodel.InsertDevCommandErr(nowConnDevID, string(data), "devType error")
dbdao.InsertDevCommandErr(nowConnDevID, string(data), "devType error")
return 0
}
......
package dcphone20
import (
"dc_golang_server_1/config"
config2 "dc_golang_server_1/util/config"
)
func NewDCPhone20() {
var dcPhone20TCP DCPhone20
dcPhone20TCP.NewDCPhone20("DCRYM-2018-pswd.", "I can't tell YOU", 0x5B) // config
dcPhone20TCP.TCPStart(config.TcpLongPort)
dcPhone20TCP.TCPStart(config2.TcpLongPort)
// dcPhone10TCP.NewDCPhone20API(r)
}
package dcphone20
import (
"dc_golang_server_1/cache"
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/devproduct"
"dc_golang_server_1/logger"
"fmt"
......@@ -493,7 +493,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
case 0x26: // 0x22:"usedevice/dev_post_call_log",// 上报通话记录 SIM ICCID
if data.Length > 27 { //todo
//devInfo := cache.GetDeviceInfo(data.DevID)
//var areaInfo cache.AreaStruct
//var areaInfo cache.CacheBAreaStruct
//if devInfo.AreaID > 0 {
// areaInfo = cache.GetAreaInfo(devInfo.AreaID)
//}
......@@ -507,7 +507,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// }
//}
//// 以事务方式存2张表
//if result := dbmodel.InsertUCallRecordAndUpdateUSimInfo(dbmodel.TableUserCallRecord{
//if result := dbdao.InsertUCallRecordAndUpdateUSimInfo(dbdao.TableUserCallRecord{
// //CustomerId:
// //CardUserId:
// //CardUserName:
......@@ -595,7 +595,7 @@ func insertDevHexResetRecord(data *devproduct.HexData) {
}
firmwareVersion = strTemp[2] //
}
go dbmodel.InsertDevResetRecord(dbmodel.TableDevHexResetRecord{
go dbdao.InsertDevResetRecord(dbdao.TableDevHexResetRecord{
DevId: data.DevID,
DevUtc: data.TimeUtc,
ResetReason: resetReason,
......
package devproduct
import (
"dc_golang_server_1/config"
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/logger"
config2 "dc_golang_server_1/util/config"
"go.uber.org/zap"
"net"
"strconv"
......@@ -93,7 +93,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
if co, ok := connMyID.(*net.TCPConn); ok { // 类型断言
if co == conn {
s.ConnectMap.Delete(myDevID)
dbmodel.DevConnectRecord(myDevID, 1) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
dbdao.DevConnectRecord(myDevID, 1) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
//logger.Log.Debug("device offline",
// zap.String("Src", "TCP-SERVER-connectionHandle"),
// zap.Uint32("DevID", myDevID),
......@@ -101,7 +101,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
// zap.String("State", "offline"))
} else {
// s.ConnectMap.Delete(myDevID) 这里人家存了新的,不能去删了噻
dbmodel.DevConnectRecord(myDevID, 3) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
dbdao.DevConnectRecord(myDevID, 3) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
//logger.Log.Debug("have a new link,close old link",
// zap.String("Src", "TCP-SERVER-connectionHandle"),
// zap.Uint32("DevID", myDevID),
......@@ -115,7 +115,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
// zap.Uint32("DevID", myDevID),
// zap.String("Conn", conn.RemoteAddr().String()),
// zap.String("State", "offline")) // 类型断言失败
dbmodel.DevConnectRecord(myDevID, 4) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
dbdao.DevConnectRecord(myDevID, 4) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
}
} else {
//logger.Log.Debug("map no have myDevID",
......@@ -123,7 +123,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
// zap.Uint32("DevID", myDevID),
// zap.String("Conn", conn.RemoteAddr().String()),
// zap.String("State", "offline"))
dbmodel.DevConnectRecord(myDevID, 2) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
dbdao.DevConnectRecord(myDevID, 2) // state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
}
}
......@@ -132,8 +132,8 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
// fmt.Println("-----------------------------------Out ConnSocketCount:", s.ConnSocketCount)
}()
if s.ConnSocketCount > config.TcpLongMaxConnections { //限制最大连接数2万个配置文件 最大连接限制数添加到配置文件
logger.Log.Error("ConnSocketCount overrun:"+strconv.Itoa(int(config.TcpLongMaxConnections)),
if s.ConnSocketCount > config2.TcpLongMaxConnections { //限制最大连接数2万个配置文件 最大连接限制数添加到配置文件
logger.Log.Error("ConnSocketCount overrun:"+strconv.Itoa(int(config2.TcpLongMaxConnections)),
zap.String("Src", "TCP-SERVER-connectionHandle"),
zap.Uint32("DevID", myDevID),
zap.String("Conn", conn.RemoteAddr().String()),
......@@ -146,18 +146,18 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
rBuf := make([]byte, 512)
rLen := 0
i := 0
timeConn := time.Now().Unix() + config.TcpLongNewConnRightfulTimeout //配置文件 120秒
timeConn := time.Now().Unix() + config2.TcpLongNewConnRightfulTimeout //配置文件 120秒
for {
if myDevID == 0 {
if time.Now().Unix() > timeConn { // 连上来2分钟都没整个正确的数据来,就给它断球
logger.Log.Warn("NewConnRightfulTimeout:"+strconv.Itoa(int(config.TcpLongNewConnRightfulTimeout)), // 超时没收到合法的指令
logger.Log.Warn("NewConnRightfulTimeout:"+strconv.Itoa(int(config2.TcpLongNewConnRightfulTimeout)), // 超时没收到合法的指令
zap.String("Src", "TCP-SERVER-connectionHandle"),
// zap.Uint32("DevID", myDevID),
zap.String("Conn", conn.RemoteAddr().String()),
zap.Int32("ConnSocketCount", s.ConnSocketCount))
return
}
if err := conn.SetReadDeadline(time.Now().Add(config.TcpLongNewConnReadDeadline)); err != nil { // 配置文件 新连接1分钟超时未收到数据(配置文件用秒)
if err := conn.SetReadDeadline(time.Now().Add(config2.TcpLongNewConnReadDeadline)); err != nil { // 配置文件 新连接1分钟超时未收到数据(配置文件用秒)
logger.Log.Warn("conn.SetReadDeadline:new", //
zap.String("Src", "TCP-SERVER-connectionHandle"),
zap.Uint32("DevID", myDevID),
......@@ -167,7 +167,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
return
}
} else {
if err := conn.SetReadDeadline(time.Now().Add(config.TcpLongOldConnReadDeadline)); err != nil { // 配置文件 老连接3分钟超时未收到数据(配置文件用秒)
if err := conn.SetReadDeadline(time.Now().Add(config2.TcpLongOldConnReadDeadline)); err != nil { // 配置文件 老连接3分钟超时未收到数据(配置文件用秒)
logger.Log.Warn("conn.SetReadDeadline:old", //
zap.String("Src", "TCP-SERVER-connectionHandle"),
zap.Uint32("DevID", myDevID),
......@@ -221,7 +221,7 @@ func (s *TCPLongServer) connectionHandle(conn *net.TCPConn, callBack receiveCall
}*/
}
// logger 新链接来的合法设备
dbmodel.DevConnectRecord(newID, 0)
dbdao.DevConnectRecord(newID, 0)
//logger.Log.Debug("a new link is coming",
// zap.String("Src", "TCP-SERVER-connectionHandle"),
// zap.Uint32("DevID", newID),
......
......@@ -48,7 +48,7 @@ var doc = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbmodel.TableBaseArea"
"$ref": "#/definitions/dbdao.TableBaseArea"
}
}
],
......@@ -89,7 +89,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -123,7 +123,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -226,7 +226,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -560,7 +560,7 @@ var doc = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbmodel.InsertTableUserCardUser"
"$ref": "#/definitions/dbdao.InsertTableUserCardUser"
}
}
],
......@@ -1339,24 +1339,7 @@ var doc = `{
}
}
},
"cache.DistrictStruct": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"example": 1
},
"initial": {
"type": "string",
"example": "S"
},
"name": {
"type": "string",
"example": "四川省"
}
}
},
"dbmodel.InsertTableUserCardUser": {
"dbdao.InsertTableUserCardUser": {
"type": "object",
"properties": {
"areaID": {
......@@ -1387,7 +1370,7 @@ var doc = `{
}
}
},
"dbmodel.TableBaseArea": {
"dbdao.TableBaseArea": {
"type": "object",
"properties": {
"county_id": {
......@@ -1421,6 +1404,23 @@ var doc = `{
"example": 1
}
}
},
"model.CacheBDistrictStruct": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"example": 1
},
"initial": {
"type": "string",
"example": "S"
},
"name": {
"type": "string",
"example": "四川省"
}
}
}
},
"securityDefinitions": {
......@@ -1443,7 +1443,7 @@ type swaggerInfo struct {
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = swaggerInfo{
Version: "V0.0.1",
Version: "V0.0.0.1",
Host: "",
BasePath: "/",
Schemes: []string{},
......
......@@ -4,7 +4,7 @@
"description": "用于家长端微信小程序及web端管理后台",
"title": "多彩中小学一卡通系统",
"contact": {},
"version": "V0.0.1"
"version": "V0.0.0.1"
},
"basePath": "/",
"paths": {
......@@ -33,7 +33,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbmodel.TableBaseArea"
"$ref": "#/definitions/dbdao.TableBaseArea"
}
}
],
......@@ -74,7 +74,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -108,7 +108,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -211,7 +211,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/cache.DistrictStruct"
"$ref": "#/definitions/model.CacheBDistrictStruct"
}
}
}
......@@ -545,7 +545,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dbmodel.InsertTableUserCardUser"
"$ref": "#/definitions/dbdao.InsertTableUserCardUser"
}
}
],
......@@ -1324,24 +1324,7 @@
}
}
},
"cache.DistrictStruct": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"example": 1
},
"initial": {
"type": "string",
"example": "S"
},
"name": {
"type": "string",
"example": "四川省"
}
}
},
"dbmodel.InsertTableUserCardUser": {
"dbdao.InsertTableUserCardUser": {
"type": "object",
"properties": {
"areaID": {
......@@ -1372,7 +1355,7 @@
}
}
},
"dbmodel.TableBaseArea": {
"dbdao.TableBaseArea": {
"type": "object",
"properties": {
"county_id": {
......@@ -1406,6 +1389,23 @@
"example": 1
}
}
},
"model.CacheBDistrictStruct": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"example": 1
},
"initial": {
"type": "string",
"example": "S"
},
"name": {
"type": "string",
"example": "四川省"
}
}
}
},
"securityDefinitions": {
......
......@@ -283,19 +283,7 @@ definitions:
description: 显示在第一行
type: string
type: object
cache.DistrictStruct:
properties:
id:
example: 1
type: integer
initial:
example: S
type: string
name:
example: 四川省
type: string
type: object
dbmodel.InsertTableUserCardUser:
dbdao.InsertTableUserCardUser:
properties:
areaID:
description: 必填,校区ID
......@@ -318,7 +306,7 @@ definitions:
description: 选填,学号,字符串,maxLen=32
type: string
type: object
dbmodel.TableBaseArea:
dbdao.TableBaseArea:
properties:
county_id:
description: 必填,所属区县ID
......@@ -345,11 +333,23 @@ definitions:
example: 1
type: integer
type: object
model.CacheBDistrictStruct:
properties:
id:
example: 1
type: integer
initial:
example: S
type: string
name:
example: 四川省
type: string
type: object
info:
contact: {}
description: 用于家长端微信小程序及web端管理后台
title: 多彩中小学一卡通系统
version: V0.0.1
version: V0.0.0.1
paths:
/ad/area:
post:
......@@ -362,7 +362,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/dbmodel.TableBaseArea'
$ref: '#/definitions/dbdao.TableBaseArea'
produces:
- application/json
responses:
......@@ -389,7 +389,7 @@ paths:
description: 按首字母排序好的列表,可直接用作展示
schema:
items:
$ref: '#/definitions/cache.DistrictStruct'
$ref: '#/definitions/model.CacheBDistrictStruct'
type: array
security:
- ApiKeyAuth: []
......@@ -410,7 +410,7 @@ paths:
description: 按首字母排序好的列表,可直接用作展示
schema:
items:
$ref: '#/definitions/cache.DistrictStruct'
$ref: '#/definitions/model.CacheBDistrictStruct'
type: array
security:
- ApiKeyAuth: []
......@@ -475,7 +475,7 @@ paths:
description: 按首字母排序好的列表,可直接用作展示
schema:
items:
$ref: '#/definitions/cache.DistrictStruct'
$ref: '#/definitions/model.CacheBDistrictStruct'
type: array
security:
- ApiKeyAuth: []
......@@ -686,7 +686,7 @@ paths:
name: data
required: true
schema:
$ref: '#/definitions/dbmodel.InsertTableUserCardUser'
$ref: '#/definitions/dbdao.InsertTableUserCardUser'
produces:
- application/json
responses:
......
package logger
import (
config2 "dc_golang_server_1/config"
config3 "dc_golang_server_1/util/config"
"github.com/gin-gonic/gin"
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
......@@ -30,38 +30,38 @@ func Init() {
//debug info
infoLevel := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl < zapcore.WarnLevel && lvl >= config2.LogLevel
return lvl < zapcore.WarnLevel && lvl >= config3.LogLevel
})
//warn
warnLevel := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl == zapcore.WarnLevel && lvl >= config2.LogLevel
return lvl == zapcore.WarnLevel && lvl >= config3.LogLevel
})
//error DPanic Panci Fatal
errorLevel := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl > zapcore.WarnLevel && lvl >= config2.LogLevel
return lvl > zapcore.WarnLevel && lvl >= config3.LogLevel
})
infoWriter := &lumberjack.Logger{
Filename: config2.LogPath + "info.log",
MaxSize: config2.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config2.LogInfoMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config2.LogInfoMaxFileDay, //保存30天
Filename: config3.LogPath + "info.log",
MaxSize: config3.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config3.LogInfoMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config3.LogInfoMaxFileDay, //保存30天
Compress: false, //是否压缩
}
warnWriter := &lumberjack.Logger{
Filename: config2.LogPath + "warn.log",
MaxSize: config2.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config2.LogWarnMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config2.LogWarnMaxFileDay, //保存30天
Filename: config3.LogPath + "warn.log",
MaxSize: config3.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config3.LogWarnMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config3.LogWarnMaxFileDay, //保存30天
Compress: false, //是否压缩
}
errorWriter := &lumberjack.Logger{
Filename: config2.LogPath + "error.log",
MaxSize: config2.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config2.LogErrorMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config2.LogErrorMaxFileDay, //保存30天
Filename: config3.LogPath + "error.log",
MaxSize: config3.LogFileMaxSize, //最大M数,超过则切割
MaxBackups: config3.LogErrorMaxFileNum, //最大文件保留数,超过就删除最老的日志文件
MaxAge: config3.LogErrorMaxFileDay, //保存30天
Compress: false, //是否压缩
}
......@@ -76,11 +76,6 @@ func Init() {
func HttpGinLog() gin.HandlerFunc { //logger *log.Log
return func(c *gin.Context) {
//defer func() {
// if r := recover();r!=nil{
// fmt.Println("recover",r)
// }
//}()
startTime := time.Now().UnixMicro()
c.Next()
// stopTime := time.Since(startTime)
......
package main
import (
"dc_golang_server_1/cache"
"dc_golang_server_1/config"
"dc_golang_server_1/dbmodel"
"dc_golang_server_1/api/router"
"dc_golang_server_1/data_db_cache/cache"
"dc_golang_server_1/data_db_cache/dbdao"
"dc_golang_server_1/devproduct/dcphone20"
"dc_golang_server_1/logger"
"dc_golang_server_1/web/router"
config2 "dc_golang_server_1/util/config"
"fmt"
"os"
"os/signal"
......@@ -16,7 +16,7 @@ import (
)
// @title 多彩中小学一卡通系统
// @version V0.0.1
// @version V0.0.0.1
// @Description 用于家长端微信小程序及web端管理后台
// @securityDefinitions.apikey ApiKeyAuth
// @in header
......@@ -26,20 +26,20 @@ func main() { //
fmt.Println(time.Now(), "system init")
runtime.GOMAXPROCS(runtime.NumCPU())
config.Init()
config2.Init()
logger.Init()
go func() {
osc := make(chan os.Signal, 1)
signal.Notify(osc, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
s := <-osc
dbmodel.CloseDb()
dbdao.CloseDb()
fmt.Println("程序退出:", s)
os.Exit(1)
}()
dbmodel.InitDb()
// defer dbmodel.CloseDb()
dbdao.InitDb()
// defer dbdao.CloseDb()
cache.Init()
......
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