feat:完善项目

This commit is contained in:
henry
2021-11-04 16:16:57 +08:00
parent 42c6fb01bb
commit c41adc075a
10 changed files with 74 additions and 28 deletions

View File

@ -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) {

View File

@ -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)
}

View File

@ -1,3 +1,7 @@
package api
type Manage struct{}
/**
* @apiDefine Manage 数据管理
*/

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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

View File

@ -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}

View File

@ -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())