Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dc_golang_server_1
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangjie
dc_golang_server_1
Commits
79bfae0c
Commit
79bfae0c
authored
Oct 20, 2021
by
zhangjiec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整目录结构
parent
4bf1f194
Hide whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
297 additions
and
312 deletions
+297
-312
APIPublic.go
api/api_public/APIPublic.go
+21
-27
wechatAPI.go
api/api_we/wechatAPI.go
+19
-35
cors.go
api/cors.go
+1
-1
errmsg.go
api/errmsg.go
+1
-1
jeffwt.go
api/jeffwt.go
+3
-3
router.go
api/router/router.go
+13
-13
cache.go
data_db_cache/cache/cache.go
+39
-31
cmap_area.go
data_db_cache/cache/cmap_area.go
+7
-6
cmap_areaservice.go
data_db_cache/cache/cmap_areaservice.go
+3
-3
cmap_bcity.go
data_db_cache/cache/cmap_bcity.go
+17
-16
cmap_carduser.go
data_db_cache/cache/cmap_carduser.go
+2
-2
cmap_countyarea.go
data_db_cache/cache/cmap_countyarea.go
+5
-8
cmap_district.go
data_db_cache/cache/cmap_district.go
+0
-0
cmap_operator.go
data_db_cache/cache/cmap_operator.go
+0
-0
cmap_phone20device.go
data_db_cache/cache/cmap_phone20device.go
+3
-3
cmap_siminfo.go
data_db_cache/cache/cmap_siminfo.go
+0
-0
cmap_wechatcustomer.go
data_db_cache/cache/cmap_wechatcustomer.go
+28
-23
d_device.go
data_db_cache/dbdao/d_device.go
+1
-1
d_hex_command_err.go
data_db_cache/dbdao/d_hex_command_err.go
+1
-1
d_hex_command_record.go
data_db_cache/dbdao/d_hex_command_record.go
+1
-1
d_hex_connect_record.go
data_db_cache/dbdao/d_hex_connect_record.go
+1
-1
d_hex_reset_record.go
data_db_cache/dbdao/d_hex_reset_record.go
+1
-1
db.go
data_db_cache/dbdao/db.go
+3
-3
u_call_record_sim_info.go
data_db_cache/dbdao/u_call_record_sim_info.go
+1
-1
u_card_user.go
data_db_cache/dbdao/u_card_user.go
+1
-1
u_sim_family_num.go
data_db_cache/dbdao/u_sim_family_num.go
+1
-1
u_sim_info.go
data_db_cache/dbdao/u_sim_info.go
+1
-1
dc_longtcp_hex_protocol.go
devproduct/dc_longtcp_hex_protocol.go
+8
-8
dc_phone20.go
devproduct/dcphone20/dc_phone20.go
+2
-2
dc_phone20_tcp.go
devproduct/dcphone20/dc_phone20_tcp.go
+5
-5
jeff_hex_server.go
devproduct/jeff_hex_server.go
+13
-13
docs.go
docs/docs.go
+25
-25
swagger.json
docs/swagger.json
+25
-25
swagger.yaml
docs/swagger.yaml
+20
-20
logger.go
logger/logger.go
+16
-21
main.go
main.go
+9
-9
setting.go
util/config/setting.go
+0
-0
数据库表结构.xlsx
数据库表结构.xlsx
+0
-0
No files found.
web/api_public/baseAPI
.go
→
api/api_public/APIPublic
.go
View file @
79bfae0c
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.CacheB
DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @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.CacheB
DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @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.CacheB
DistrictStruct)
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.CacheB
DistrictStruct "按首字母排序好的列表,可直接用作展示"
// @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.CacheB
DistrictStruct)
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
.
CacheB
AreaStruct
);
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
,
})
}
web
/api_we/wechatAPI.go
→
api
/api_we/wechatAPI.go
View file @
79bfae0c
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
,
})
}
web
/cors.go
→
api
/cors.go
View file @
79bfae0c
package
web
package
api
import
(
"github.com/gin-gonic/gin"
...
...
web
/errmsg.go
→
api
/errmsg.go
View file @
79bfae0c
package
web
package
api
const
(
Success
=
0
...
...
web
/jeffwt.go
→
api
/jeffwt.go
View file @
79bfae0c
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"
...
...
web
/router/router.go
→
api
/router/router.go
View file @
79bfae0c
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
(
config
2
.
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
config
2
.
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"
,
config
2
.
HttpServerSwagger
)
err
:=
r
.
Run
(
config
.
HttpServerPort
)
err
:=
r
.
Run
(
config
2
.
HttpServerPort
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
cache/cache.go
→
data_db_cache/
cache/cache.go
View file @
79bfae0c
package
cache
import
(
"dc_golang_server_1/data_db_cache/model"
"sync"
"time"
)
// ProvinceMap /*********************************************************全国行政区域**/------------------------OK
var
ProvinceMap
[]
DistrictStruct
// 省份列表[]Distri
ct
var
CityMap
sync
.
Map
// 城市列表map[uint32][]Distri
ct //省份ID作为KEY
var
CountyMap
sync
.
Map
// 区县列表map[uint32][]Distri
ct //城市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.CacheBDistrictStru
ct
var
CityMap
sync
.
Map
// 城市列表map[uint32][]model.CacheBDistrictStru
ct //省份ID作为KEY
var
CountyMap
sync
.
Map
// 区县列表map[uint32][]model.CacheBDistrictStru
ct //城市ID作为KEY
//type CacheB
DistrictStruct 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
CacheB
AreaStruct 作为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
()
{
initB
City
Maps
()
// 初始化行政区域省市区缓存
initB
District
Maps
()
// 初始化行政区域省市区缓存
initAreaMapAndCountyAreaMap
()
initWechatCustomerMap
()
...
...
cache/cmap_area.go
→
data_db_cache/
cache/cmap_area.go
View file @
79bfae0c
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
:=
db
model
.
PgDb
.
Query
(
"SELECT id,county_id,name,longitude,latitude,status FROM b_area"
)
//
var
temp
model
.
CacheB
AreaStruct
rows
,
err
:=
db
dao
.
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
.
CacheB
AreaStruct
);
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
.
CacheB
AreaStruct
)
bool
{
if
v
,
ok
:=
AreaMap
.
Load
(
areaID
);
ok
{
if
*
info
,
ok
=
v
.
(
AreaStruct
);
ok
{
if
*
info
,
ok
=
v
.
(
model
.
CacheB
AreaStruct
);
ok
{
return
true
}
else
{
AreaMap
.
Delete
(
areaID
)
...
...
cache/cmap_areaservice.go
→
data_db_cache/
cache/cmap_areaservice.go
View file @
79bfae0c
package
cache
import
(
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/d
ata_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
:=
db
model
.
PgDb
.
Query
(
"SELECT id,name,status FROM b_area"
)
//todo
rows
,
err
:=
db
dao
.
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
=
db
model
.
PgDb
.
QueryRow
(
"SELECT name,status FROM b_area WHERE id=$1"
,
err
=
db
dao
.
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
)
...
...
cache/cmap_bcity.go
→
data_db_cache/
cache/cmap_bcity.go
View file @
79bfae0c
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
initB
City
Maps
()
{
fmt
.
Println
(
time
.
Now
(),
"cache: initB
City
Maps begin"
)
func
initB
District
Maps
()
{
fmt
.
Println
(
time
.
Now
(),
"cache: initB
District
Maps begin"
)
go
func
()
bool
{
ProvinceMap
=
[]
DistrictStruct
{}
//先清空原来的缓存
var
temp
DistrictStruct
rows
,
err
:=
db
model
.
PgDb
.
Query
(
"SELECT id,name,initial FROM b_city
WHERE level=1 ORDER BY initial,sort"
)
ProvinceMap
=
[]
model
.
CacheB
DistrictStruct
{}
//先清空原来的缓存
var
temp
model
.
CacheB
DistrictStruct
rows
,
err
:=
db
dao
.
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: initB
City
Maps OK"
)
fmt
.
Println
(
time
.
Now
(),
"cache: initB
District
Maps 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
:=
db
model
.
PgDb
.
Query
(
"SELECT id,name,parent_id,initial FROM b_city
WHERE level=$1 ORDER BY initial,sort"
,
level
)
var
temp
model
.
CacheB
DistrictStruct
rows
,
err
:=
db
dao
.
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
.
CacheB
DistrictStruct
if
v
,
ok
:=
tempMap
.
Load
(
parentID
);
ok
{
//map已经有了
if
bufStruct
,
ok
=
v
.
([]
DistrictStruct
);
ok
==
false
{
//类型断言错误
if
bufStruct
,
ok
=
v
.
([]
model
.
CacheB
DistrictStruct
);
ok
==
false
{
//类型断言错误
tempMap
.
Delete
(
parentID
)
logger
.
Log
.
Error
(
"[]DistrictStruct 类型断言错误"
,
logger
.
Log
.
Error
(
"[]
B
DistrictStruct 类型断言错误"
,
zap
.
Uint8
(
"level"
,
level
),
zap
.
String
(
"src"
,
"selectToDistrictMap"
))
}
...
...
cache/cmap_carduser.go
→
data_db_cache/
cache/cmap_carduser.go
View file @
79bfae0c
package
cache
import
(
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/d
ata_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
:=
db
model
.
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
:=
db
dao
.
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
)
...
...
cache/cmap_countyarea.go
→
data_db_cache/
cache/cmap_countyarea.go
View file @
79bfae0c
...
...
@@ -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
}
cache/cmap_district.go
→
data_db_cache/
cache/cmap_district.go
View file @
79bfae0c
File moved
cache/cmap_operator.go
→
data_db_cache/
cache/cmap_operator.go
View file @
79bfae0c
File moved
cache/cmap_phone20device.go
→
data_db_cache/
cache/cmap_phone20device.go
View file @
79bfae0c
package
cache
import
(
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/d
ata_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
:=
db
model
.
PgDb
.
Query
(
"SELECT id,area_service_id,allow_call_time,status FROM d_device"
)
rows
,
err
:=
db
dao
.
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
=
db
model
.
PgDb
.
QueryRow
(
"SELECT area_service_id,allow_call_time,status FROM d_phone20 WHERE id=$1"
,
err
=
db
dao
.
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
)
...
...
cache/cmap_siminfo.go
→
data_db_cache/
cache/cmap_siminfo.go
View file @
79bfae0c
File moved
cache/cmap_wechatcustomer.go
→
data_db_cache/
cache/cmap_wechatcustomer.go
View file @
79bfae0c
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
Wechat
CustomerStruct
var
temp
model
.
CacheUWe
CustomerStruct
// 1. 查u_we_customer表获得基础数据
rows
,
err
:=
db
model
.
PgDb
.
Query
(
"SELECT id,unionid,phone,nickname,avatarurl,test_role FROM u_we_customer"
)
//
rows
,
err
:=
db
dao
.
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
=
db
model
.
PgDb
.
Query
(
"SELECT we_user_id,card_user_id,master FROM u_we_card_user order by create_at"
)
//
rows
,
err
=
db
dao
.
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
.
(
Wechat
CustomerStruct
);
ok
{
if
value
,
ok
:=
v
.
(
model
.
CacheUWe
CustomerStruct
);
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
.
(
Wechat
CustomerStruct
);
ok
{
if
value
,
ok
:=
v
.
(
model
.
CacheUWe
CustomerStruct
);
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
Wechat
CustomerStruct
var
data
model
.
CacheUWe
CustomerStruct
if
v
,
ok
:=
WechatCustomerMap
.
Load
(
weUserID
);
ok
{
if
data
,
ok
=
v
.
(
Wechat
CustomerStruct
);
ok
{
if
data
,
ok
=
v
.
(
model
.
CacheUWe
CustomerStruct
);
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
Wechat
CustomerStruct
var
data
model
.
CacheUWe
CustomerStruct
if
v
,
ok
:=
WechatCustomerMap
.
Load
(
userID
);
ok
{
if
data
,
ok
=
v
.
(
Wechat
CustomerStruct
);
ok
{
if
data
,
ok
=
v
.
(
model
.
CacheUWe
CustomerStruct
);
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
)
(
Wechat
CustomerStruct
,
bool
)
{
var
data
Wechat
CustomerStruct
func
GetWechatCustomerInfoAndCanUpdateTokenTime
(
weUserID
uint32
,
newTime
int64
)
(
model
.
CacheUWe
CustomerStruct
,
bool
)
{
var
data
model
.
CacheUWe
CustomerStruct
if
v
,
ok
:=
WechatCustomerMap
.
Load
(
weUserID
);
ok
{
if
data
,
ok
=
v
.
(
Wechat
CustomerStruct
);
ok
{
if
data
,
ok
=
v
.
(
model
.
CacheUWe
CustomerStruct
);
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
=
db
model
.
PgDb
.
QueryRow
(
"INSERT INTO u_we_customer(unionid)VALUES($1)RETURNING id"
,
unionID
)
.
Scan
(
&
id
)
err
=
db
dao
.
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
*
Wechat
CustomerStruct
)
bool
{
func
selectDBWechatCustomerByUserIDToCache
(
userID
uint32
,
userInfo
*
model
.
CacheUWe
CustomerStruct
)
bool
{
var
unionID
string
// 1. 查u_we_customer表获得基础数据
err
:=
db
model
.
PgDb
.
QueryRow
(
"SELECT unionid,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE id=$1"
,
userID
)
.
Scan
(
err
:=
db
dao
.
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
:=
db
model
.
PgDb
.
Query
(
"SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at"
,
userID
)
rows
,
err
:=
db
dao
.
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
*
Wechat
CustomerStruct
)
(
userID
uint32
)
{
//返回userID
func
selectDBWechatCustomerByUnionIDToCache
(
unionID
string
,
userInfo
*
model
.
CacheUWe
CustomerStruct
)
(
userID
uint32
)
{
//返回userID
// 1. 查u_we_customer表获得基础数据
err
:=
db
model
.
PgDb
.
QueryRow
(
"SELECT id,phone,nickname,avatarurl,test_role FROM u_we_customer WHERE unionid=$1"
,
unionID
)
.
Scan
(
err
:=
db
dao
.
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
:=
db
model
.
PgDb
.
Query
(
"SELECT card_user_id,master FROM u_we_card_user WHERE we_user_id=$1 order by create_at"
,
userID
)
rows
,
err
:=
db
dao
.
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
Wechat
CustomerStruct
var
data
model
.
CacheUWe
CustomerStruct
if
v
,
ok
:=
WechatCustomerMap
.
Load
(
weUserID
);
ok
{
if
data
,
ok
=
v
.
(
Wechat
CustomerStruct
);
ok
{
if
data
,
ok
=
v
.
(
model
.
CacheUWe
CustomerStruct
);
ok
{
if
master
{
data
.
MasterCardUserID
=
append
(
data
.
MasterCardUserID
,
cardUserID
)
}
else
{
...
...
d
bmodel
/d_device.go
→
d
ata_db_cache/dbdao
/d_device.go
View file @
79bfae0c
package
db
model
package
db
dao
//CREATE TABLE IF NOT EXISTS public.d_device
//(
...
...
d
bmodel
/d_hex_command_err.go
→
d
ata_db_cache/dbdao
/d_hex_command_err.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"dc_golang_server_1/logger"
...
...
d
bmodel
/d_hex_command_record.go
→
d
ata_db_cache/dbdao
/d_hex_command_record.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"dc_golang_server_1/logger"
...
...
d
bmodel
/d_hex_connect_record.go
→
d
ata_db_cache/dbdao
/d_hex_connect_record.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"dc_golang_server_1/logger"
...
...
d
bmodel
/d_hex_reset_record.go
→
d
ata_db_cache/dbdao
/d_hex_reset_record.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"dc_golang_server_1/logger"
...
...
d
bmodel
/db.go
→
d
ata_db_cache/dbdao
/db.go
View file @
79bfae0c
package
db
model
package
db
dao
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"
,
config
2
.
DbDSN
)
if
err
!=
nil
{
panic
(
"数据库连接失败"
+
err
.
Error
())
}
...
...
d
bmodel
/u_call_record_sim_info.go
→
d
ata_db_cache/dbdao
/u_call_record_sim_info.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"database/sql"
...
...
d
bmodel
/u_card_user.go
→
d
ata_db_cache/dbdao
/u_card_user.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"dc_golang_server_1/logger"
...
...
d
bmodel
/u_sim_family_num.go
→
d
ata_db_cache/dbdao
/u_sim_family_num.go
View file @
79bfae0c
package
db
model
package
db
dao
import
(
"time"
...
...
d
bmodel
/u_sim_info.go
→
d
ata_db_cache/dbdao
/u_sim_info.go
View file @
79bfae0c
package
db
model
package
db
dao
//CREATE TABLE IF NOT EXISTS public.u_sim_info
//(
...
...
devproduct/dc_longtcp_hex_protocol.go
View file @
79bfae0c
package
devproduct
import
(
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/d
ata_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
db
model
.
InsertDevCommandRecord
(
dbmodel
.
TableDevHexCommandRecord
{
go
db
dao
.
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
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"Decrypt err"
)
db
dao
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"Decrypt err"
)
}
return
0
}
if
util
.
CheckCRC
(
c
)
==
false
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"CheckCRC err"
)
db
dao
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"CheckCRC err"
)
return
0
}
cLen
:=
len
(
c
)
if
cLen
<
12
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"cLen<12"
)
db
dao
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"cLen<12"
)
return
0
}
else
if
int
(
c
[
9
])
+
12
!=
cLen
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"cLen!=c[9]+12"
)
db
dao
.
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
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"utc err:"
+
strconv
.
FormatUint
(
uint64
(
rData
.
TimeUtc
),
10
))
db
dao
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"utc err:"
+
strconv
.
FormatUint
(
uint64
(
rData
.
TimeUtc
),
10
))
return
0
}
// 设备类型判断
if
c
[
4
]
!=
d
.
devType
{
db
model
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"devType error"
)
db
dao
.
InsertDevCommandErr
(
nowConnDevID
,
string
(
data
),
"devType error"
)
return
0
}
...
...
devproduct/dcphone20/dc_phone20.go
View file @
79bfae0c
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
(
config
2
.
TcpLongPort
)
// dcPhone10TCP.NewDCPhone20API(r)
}
devproduct/dcphone20/dc_phone20_tcp.go
View file @
79bfae0c
package
dcphone20
import
(
"dc_golang_server_1/cache"
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/
data_db_cache/
cache"
"dc_golang_server_1/d
ata_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.
CacheB
AreaStruct
//if devInfo.AreaID > 0 {
// areaInfo = cache.GetAreaInfo(devInfo.AreaID)
//}
...
...
@@ -507,7 +507,7 @@ func (dev *DCPhone20) response(data *devproduct.HexData) {
// }
//}
//// 以事务方式存2张表
//if result := db
model.InsertUCallRecordAndUpdateUSimInfo(dbmodel
.TableUserCallRecord{
//if result := db
dao.InsertUCallRecordAndUpdateUSimInfo(dbdao
.TableUserCallRecord{
// //CustomerId:
// //CardUserId:
// //CardUserName:
...
...
@@ -595,7 +595,7 @@ func insertDevHexResetRecord(data *devproduct.HexData) {
}
firmwareVersion
=
strTemp
[
2
]
//
}
go
db
model
.
InsertDevResetRecord
(
dbmodel
.
TableDevHexResetRecord
{
go
db
dao
.
InsertDevResetRecord
(
dbdao
.
TableDevHexResetRecord
{
DevId
:
data
.
DevID
,
DevUtc
:
data
.
TimeUtc
,
ResetReason
:
resetReason
,
...
...
devproduct/jeff_hex_server.go
View file @
79bfae0c
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
)
db
model
.
DevConnectRecord
(
myDevID
,
1
)
// state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
db
dao
.
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) 这里人家存了新的,不能去删了噻
db
model
.
DevConnectRecord
(
myDevID
,
3
)
// state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
db
dao
.
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")) // 类型断言失败
db
model
.
DevConnectRecord
(
myDevID
,
4
)
// state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
db
dao
.
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"))
db
model
.
DevConnectRecord
(
myDevID
,
2
)
// state 0:新连接来了 1:设备正常离线 2:正常离线 3:新连接挤掉就连接 4:未知异常(连接池类型断言失败)
db
dao
.
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
>
config
2
.
TcpLongMaxConnections
{
//限制最大连接数2万个配置文件 最大连接限制数添加到配置文件
logger
.
Log
.
Error
(
"ConnSocketCount overrun:"
+
strconv
.
Itoa
(
int
(
config
2
.
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
()
+
config
2
.
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
(
config
2
.
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
(
config
2
.
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
(
config
2
.
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 新链接来的合法设备
db
model
.
DevConnectRecord
(
newID
,
0
)
db
dao
.
DevConnectRecord
(
newID
,
0
)
//logger.Log.Debug("a new link is coming",
// zap.String("Src", "TCP-SERVER-connectionHandle"),
// zap.Uint32("DevID", newID),
...
...
docs/docs.go
View file @
79bfae0c
...
...
@@ -48,7 +48,7 @@ var doc = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/db
model
.TableBaseArea"
"$ref": "#/definitions/db
dao
.TableBaseArea"
}
}
],
...
...
@@ -89,7 +89,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/
cache.
DistrictStruct"
"$ref": "#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -123,7 +123,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/
cache.
DistrictStruct"
"$ref": "#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -226,7 +226,7 @@ var doc = `{
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/
cache.
DistrictStruct"
"$ref": "#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -560,7 +560,7 @@ var doc = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/db
model
.InsertTableUserCardUser"
"$ref": "#/definitions/db
dao
.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 = `{
}
}
},
"db
model
.TableBaseArea": {
"db
dao
.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
{},
...
...
docs/swagger.json
View file @
79bfae0c
...
...
@@ -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/db
model
.TableBaseArea"
"$ref"
:
"#/definitions/db
dao
.TableBaseArea"
}
}
],
...
...
@@ -74,7 +74,7 @@
"schema"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"#/definitions/
cache.
DistrictStruct"
"$ref"
:
"#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -108,7 +108,7 @@
"schema"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"#/definitions/
cache.
DistrictStruct"
"$ref"
:
"#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -211,7 +211,7 @@
"schema"
:
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"#/definitions/
cache.
DistrictStruct"
"$ref"
:
"#/definitions/
model.CacheB
DistrictStruct"
}
}
}
...
...
@@ -545,7 +545,7 @@
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"$ref"
:
"#/definitions/db
model
.InsertTableUserCardUser"
"$ref"
:
"#/definitions/db
dao
.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 @@
}
}
},
"db
model
.TableBaseArea"
:
{
"db
dao
.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"
:
{
...
...
docs/swagger.yaml
View file @
79bfae0c
...
...
@@ -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
db
model
.TableBaseArea
:
db
dao
.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/db
model
.TableBaseArea'
$ref
:
'
#/definitions/db
dao
.TableBaseArea'
produces
:
-
application/json
responses
:
...
...
@@ -389,7 +389,7 @@ paths:
description
:
按首字母排序好的列表,可直接用作展示
schema
:
items
:
$ref
:
'
#/definitions/
cache.
DistrictStruct'
$ref
:
'
#/definitions/
model.CacheB
DistrictStruct'
type
:
array
security
:
-
ApiKeyAuth
:
[]
...
...
@@ -410,7 +410,7 @@ paths:
description
:
按首字母排序好的列表,可直接用作展示
schema
:
items
:
$ref
:
'
#/definitions/
cache.
DistrictStruct'
$ref
:
'
#/definitions/
model.CacheB
DistrictStruct'
type
:
array
security
:
-
ApiKeyAuth
:
[]
...
...
@@ -475,7 +475,7 @@ paths:
description
:
按首字母排序好的列表,可直接用作展示
schema
:
items
:
$ref
:
'
#/definitions/
cache.
DistrictStruct'
$ref
:
'
#/definitions/
model.CacheB
DistrictStruct'
type
:
array
security
:
-
ApiKeyAuth
:
[]
...
...
@@ -686,7 +686,7 @@ paths:
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/db
model
.InsertTableUserCardUser'
$ref
:
'
#/definitions/db
dao
.InsertTableUserCardUser'
produces
:
-
application/json
responses
:
...
...
logger/logger.go
View file @
79bfae0c
package
logger
import
(
config
2
"dc_golang_server_1
/config"
config
3
"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
>=
config
2
.
LogLevel
return
lvl
<
zapcore
.
WarnLevel
&&
lvl
>=
config
3
.
LogLevel
})
//warn
warnLevel
:=
zap
.
LevelEnablerFunc
(
func
(
lvl
zapcore
.
Level
)
bool
{
return
lvl
==
zapcore
.
WarnLevel
&&
lvl
>=
config
2
.
LogLevel
return
lvl
==
zapcore
.
WarnLevel
&&
lvl
>=
config
3
.
LogLevel
})
//error DPanic Panci Fatal
errorLevel
:=
zap
.
LevelEnablerFunc
(
func
(
lvl
zapcore
.
Level
)
bool
{
return
lvl
>
zapcore
.
WarnLevel
&&
lvl
>=
config
2
.
LogLevel
return
lvl
>
zapcore
.
WarnLevel
&&
lvl
>=
config
3
.
LogLevel
})
infoWriter
:=
&
lumberjack
.
Logger
{
Filename
:
config
2
.
LogPath
+
"info.log"
,
MaxSize
:
config
2
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
2
.
LogInfoMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
2
.
LogInfoMaxFileDay
,
//保存30天
Filename
:
config
3
.
LogPath
+
"info.log"
,
MaxSize
:
config
3
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
3
.
LogInfoMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
3
.
LogInfoMaxFileDay
,
//保存30天
Compress
:
false
,
//是否压缩
}
warnWriter
:=
&
lumberjack
.
Logger
{
Filename
:
config
2
.
LogPath
+
"warn.log"
,
MaxSize
:
config
2
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
2
.
LogWarnMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
2
.
LogWarnMaxFileDay
,
//保存30天
Filename
:
config
3
.
LogPath
+
"warn.log"
,
MaxSize
:
config
3
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
3
.
LogWarnMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
3
.
LogWarnMaxFileDay
,
//保存30天
Compress
:
false
,
//是否压缩
}
errorWriter
:=
&
lumberjack
.
Logger
{
Filename
:
config
2
.
LogPath
+
"error.log"
,
MaxSize
:
config
2
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
2
.
LogErrorMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
2
.
LogErrorMaxFileDay
,
//保存30天
Filename
:
config
3
.
LogPath
+
"error.log"
,
MaxSize
:
config
3
.
LogFileMaxSize
,
//最大M数,超过则切割
MaxBackups
:
config
3
.
LogErrorMaxFileNum
,
//最大文件保留数,超过就删除最老的日志文件
MaxAge
:
config
3
.
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)
...
...
main.go
View file @
79bfae0c
package
main
import
(
"dc_golang_server_1/
cache
"
"dc_golang_server_1/
config
"
"dc_golang_server_1/d
bmodel
"
"dc_golang_server_1/
api/router
"
"dc_golang_server_1/
data_db_cache/cache
"
"dc_golang_server_1/d
ata_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
()
config
2
.
Init
()
logger
.
Init
()
go
func
()
{
osc
:=
make
(
chan
os
.
Signal
,
1
)
signal
.
Notify
(
osc
,
syscall
.
SIGTERM
,
syscall
.
SIGINT
,
syscall
.
SIGKILL
)
s
:=
<-
osc
db
model
.
CloseDb
()
db
dao
.
CloseDb
()
fmt
.
Println
(
"程序退出:"
,
s
)
os
.
Exit
(
1
)
}()
db
model
.
InitDb
()
// defer db
model
.CloseDb()
db
dao
.
InitDb
()
// defer db
dao
.CloseDb()
cache
.
Init
()
...
...
config/setting.go
→
util/
config/setting.go
View file @
79bfae0c
File moved
数据库表结构.xlsx
deleted
100644 → 0
View file @
4bf1f194
File deleted
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment