From c41adc075aa7776938b629a3372b34022ae744db Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 4 Nov 2021 16:16:57 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=8C=E5=96=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/account.go | 9 +++++++-- app/api/config.go | 30 ++++++++++++++++++++++++++++- app/api/manage.go | 4 ++++ app/api/supplier.go | 12 ++++++------ app/api/user.go | 10 +++++----- app/common/model/manage_material.go | 5 +++-- app/controller/account/instance.go | 10 ++++++---- app/controller/manage/material.go | 11 ++++------- app/init.go | 3 +++ router/router.go | 8 +++++++- 10 files changed, 74 insertions(+), 28 deletions(-) diff --git a/app/api/account.go b/app/api/account.go index 61cfca7..2d6b8b4 100644 --- a/app/api/account.go +++ b/app/api/account.go @@ -28,14 +28,19 @@ type Account struct{} * * @apiSuccess (200) {Number} code 成功响应状态码! * @apiSuccess (200) {String} msg 成功提示 - * @apiSuccess (200) {String} data token + * @apiSuccess (200) {Json} data 具体信息 + * @apiSuccess (200) {String} data.token token信息,接口需要携带 + * @apiSuccess (200) {Number} data.effect_time token有效时长,秒 * * @apiSuccessExample {json} Success response: * HTTPS 200 OK * { * "code": 200 * "msg": "ok" - * "data": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjE3NDU2OTMwIiwiaWF0IjoiMTYxNjg1MjEzMCIsInVpZCI6IjIwMTMxMTI4MTMwMTg0MTkyMDAifQ.D7oSD4OGdz8rJt0rFNVEl5Ea47_vtuC51IDrY9mUTPo" + * "data": { + * "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNjM4NjA0NDYwIiwiaWF0IjoiMTYzNjAxMjQ2MCIsInVpZCI6IjIwOTU2MTg2ODk5ODEyMjI5MTIifQ.Q4_peBb9aeGaZAfUFMMzn21cbfhY6_DEocI9xlj9v9g", + * "effect_time": 2592000 + * } * } */ func (a *Account) Login(c *gin.Context) { diff --git a/app/api/config.go b/app/api/config.go index ee0e564..a499b79 100644 --- a/app/api/config.go +++ b/app/api/config.go @@ -12,6 +12,34 @@ type Config struct{} * @apiDefine Config 配置管理 */ +/** +* @api {get} /api/v1/config/area 区域管理 +* @apiVersion 1.0.0 +* @apiName ConfigArea +* @apiGroup Config +* +* @apiHeader {string} x-token token +* @apiHeader {string} Content-Type=application/json 传输方式 +* +* @apiParam {String} [key="''"] 区域标识 +* +* @apiSuccess (200) {Number} code 成功响应状态码! +* @apiSuccess (200) {String} msg 成功提示 +* @apiSuccess (200) {Json} data 数据信息{"110000": "北京市", "120000": "天津市", ...} +* +* @apiSuccessExample {json} Success response: +* HTTPS 200 OK +* { +* "code": 200 +* "msg": "ok" +* "data": { +* "110000": "北京市", +* "120000": "天津市", +* "130000": "河北省", +* "140000": "山西省", +* } +* } + */ func (*Config) Area(c *gin.Context) { form := &struct { Key string `json:"key" form:"key"` @@ -21,5 +49,5 @@ func (*Config) Area(c *gin.Context) { return } data := config.NewInstance()(getSession()(c).(*service.Session)).Area(form.Key) - APIResponse(nil, data) + APIResponse(nil, data)(c) } diff --git a/app/api/manage.go b/app/api/manage.go index be0ddf0..4273ed1 100644 --- a/app/api/manage.go +++ b/app/api/manage.go @@ -1,3 +1,7 @@ package api type Manage struct{} + +/** + * @apiDefine Manage 数据管理 + */ diff --git a/app/api/supplier.go b/app/api/supplier.go index 974fc17..68968e7 100644 --- a/app/api/supplier.go +++ b/app/api/supplier.go @@ -45,7 +45,7 @@ func (*Supplier) MaterialAdd(c *gin.Context) { Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark, Kind: model.ManageSupplierKindForMaterial, }) - APIResponse(err) + APIResponse(err)(c) } func (*Supplier) MaterialEdit(c *gin.Context) { @@ -61,7 +61,7 @@ func (*Supplier) MaterialEdit(c *gin.Context) { ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark, Kind: model.ManageSupplierKindForMaterial, }) - APIResponse(err) + APIResponse(err)(c) } func (*Supplier) MaterialDelete(c *gin.Context) { @@ -72,7 +72,7 @@ func (*Supplier) MaterialDelete(c *gin.Context) { return } err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert()) - APIResponse(err) + APIResponse(err)(c) } func (*Supplier) Repair(c *gin.Context) { @@ -101,7 +101,7 @@ func (*Supplier) RepairAdd(c *gin.Context) { Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark, Kind: model.ManageSupplierKindForRepair, }) - APIResponse(err) + APIResponse(err)(c) } func (*Supplier) RepairEdit(c *gin.Context) { @@ -117,7 +117,7 @@ func (*Supplier) RepairEdit(c *gin.Context) { ID: form.Convert(), Name: form.Name, Mobile: form.Mobile, Address: form.Address, Remark: form.Remark, Kind: model.ManageSupplierKindForRepair, }) - APIResponse(err) + APIResponse(err)(c) } func (*Supplier) RepairDelete(c *gin.Context) { @@ -128,5 +128,5 @@ func (*Supplier) RepairDelete(c *gin.Context) { return } err := manage.NewSupplier()(getSession()(c).(*service.Session)).Delete(form.Convert()) - APIResponse(err) + APIResponse(err)(c) } diff --git a/app/api/user.go b/app/api/user.go index 6260063..965202c 100644 --- a/app/api/user.go +++ b/app/api/user.go @@ -10,12 +10,12 @@ type User struct{} func (*User) Info(c *gin.Context) { data := user.NewInstance()(getSession()(c).(*service.Session)).Info() - APIResponse(nil, data) + APIResponse(nil, data)(c) } func (*User) Menu(c *gin.Context) { data, err := user.NewMenu()(getSession()(c).(*service.Session)).Menu() - APIResponse(err, data) + APIResponse(err, data)(c) } func (*User) List(c *gin.Context) { @@ -31,7 +31,7 @@ func (*User) List(c *gin.Context) { } data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID, form.Page, form.PageSize) - APIResponse(err, data) + APIResponse(err, data)(c) } func (*User) Add(c *gin.Context) { @@ -47,7 +47,7 @@ func (*User) Add(c *gin.Context) { } data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID, form.Page, form.PageSize) - APIResponse(err, data) + APIResponse(err, data)(c) } func (*User) Edit(c *gin.Context) { @@ -63,5 +63,5 @@ func (*User) Edit(c *gin.Context) { } data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID, form.Page, form.PageSize) - APIResponse(err, data) + APIResponse(err, data)(c) } diff --git a/app/common/model/manage_material.go b/app/common/model/manage_material.go index 0373a3a..08cd8aa 100644 --- a/app/common/model/manage_material.go +++ b/app/common/model/manage_material.go @@ -8,8 +8,9 @@ type ManageMaterial struct { Code string `gorm:"column:code;type:varchar(35);default:null;comment:编号" json:"code"` Title string `gorm:"column:title;type:varchar(100);default:null;comment:名称" json:"title"` Image - Unit ManageMaterialUnit `gorm:"column:unit;type:tinyint(1);default:0;comment:单位" json:"unit"` - Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"remark"` + Unit ManageMaterialUnit `gorm:"column:unit;type:tinyint(1);default:0;comment:单位" json:"unit"` + Position string `gorm:"column:position;type:varchar(20);default:null;comment:position" json:"position"` + Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"remark"` ModelDeleted ModelAt } diff --git a/app/controller/account/instance.go b/app/controller/account/instance.go index 3857128..d897d1d 100644 --- a/app/controller/account/instance.go +++ b/app/controller/account/instance.go @@ -52,17 +52,19 @@ func (c *Instance) Login(account, password, captchaKey, captchaValue, ip string) } } session := service.NewSession() - session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{ - config.TokenForUID: mSysUser.UUID, - }) session.UID = mSysUser.UUID + key := session.UIDToString() + + session.Token = utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{ + config.TokenForUID: key, + }) session.TenantID = mSysUser.TenantID session.Name = mSysUser.Name session.Avatar = mSysUser.Avatar session.Mobile = mSysUser.Mobile session.IsAdmin = mSysUser.IsAdminUser() - service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, session.UIDToString(), session) + service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, key, session) service.Publish(config.EventForAccountLoginProduce, session.TenantID, session.UID, ip) return &InstanceLoginResponse{Token: session.Token, EffectTime: config.SettingInfo.TokenEffectTime}, nil diff --git a/app/controller/manage/material.go b/app/controller/manage/material.go index 6c95a1f..74f48cb 100644 --- a/app/controller/manage/material.go +++ b/app/controller/manage/material.go @@ -22,9 +22,9 @@ type ( } // MaterialParams 基本参数 MaterialParams struct { - ID, ManufacturerID uint64 - Code, Title, Image, Remark string - Unit int + ID, ManufacturerID uint64 + Code, Title, Image, Position, Remark string + Unit int } ) @@ -97,6 +97,7 @@ func (c *Material) Form(params *MaterialParams) error { mManageMaterial.Code = params.Code mManageMaterial.Title = params.Title mManageMaterial.Unit = model2.ManageMaterialUnit(params.Unit) + mManageMaterial.Position = params.Position mManageMaterial.Remark = params.Remark if mManageMaterial.ID > 0 { @@ -121,10 +122,6 @@ func (c *Material) Delete(id uint64) error { return model2.Delete(mManageMaterial.ManageMaterial) } -func (c *Material) Supplier() { - -} - func NewMaterial() MaterialHandle { return func(session *service.Session) *Material { return &Material{session} diff --git a/app/init.go b/app/init.go index 53ca3e8..9f0a6e3 100644 --- a/app/init.go +++ b/app/init.go @@ -4,9 +4,12 @@ import ( "ArmedPolice/app/event" "ArmedPolice/app/service" "ArmedPolice/config" + "ArmedPolice/lib" ) func Init() { + // 载入数据配置 + lib.LoadConfig("./json/area.json", &config.SettingAreaInfo) // RedisHash存储/移除监听 service.Subscribe(config.EventForRedisHashProduce, event.NewRedisHashProduce()) service.Subscribe(config.EventForRedisHashDestroy, event.NewRedisHashDestroy()) diff --git a/router/router.go b/router/router.go index 3db5e6a..3d2724c 100644 --- a/router/router.go +++ b/router/router.go @@ -52,6 +52,12 @@ func (this *Router) registerAPI() { accountV1.POST("/login", _api.Login) accountV1.POST("/logout", _api.Logout) } + // Config 配置管理 + configV1 := v1.Group("/config") + { + _api := new(api.Config) + configV1.GET("/area", _api.Area) + } // Tenant 租户单位管理 tenantV1 := v1.Group("/tenant") { @@ -73,7 +79,7 @@ func (this *Router) registerAPI() { menuV1 := v1.Group("/menu") { _api := new(api.Menu) - menuV1.POST("/list", _api.List) + menuV1.GET("/list", _api.List) menuV1.POST("/add", _api.Add) menuV1.POST("/edit", _api.Edit) menuV1.POST("/status", _api.Status)