From 5e18926f02fd13170dd71778c8ec15ef07d636c2 Mon Sep 17 00:00:00 2001 From: wangjian Date: Tue, 10 Jan 2023 10:01:42 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=89=8D=E7=AB=AF=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/manage.go | 32 ++++++++++++++ internal/handler/user.go | 8 ++++ internal/proto/request.go | 5 +++ internal/router/router.go | 8 ++++ internal/service/index.go | 53 ++++++++++++++++++++++++ internal/service/manage.go | 99 ++++++++++++++++++++++++++++++++++++++++++-- model/index.go | 1 + model/matterEventParams.go | 1 + model/matterModel.go | 2 + model/matterServiceParams.go | 1 + 10 files changed, 207 insertions(+), 3 deletions(-) diff --git a/internal/handler/manage.go b/internal/handler/manage.go index fdebed5..3e723ed 100644 --- a/internal/handler/manage.go +++ b/internal/handler/manage.go @@ -7,6 +7,7 @@ import ( "hpds-iot-web/internal/service" "hpds-iot-web/model" e "hpds-iot-web/pkg/err" + "strconv" ) func (s HandlerService) OwnerList(c *gin.Context) (data interface{}, err error) { @@ -33,6 +34,22 @@ func (s HandlerService) OwnerList(c *gin.Context) (data interface{}, err error) return } +func (s HandlerService) OwnerInfo(c *gin.Context) (data interface{}, err error) { + repo := service.NewManageService(s.Engine, s.Logger) + us, _ := c.Get("operatorUser") + userInfo := us.(*model.SystemUser) + //var req proto.OwnerItemReq + //err = c.ShouldBindJSON(&req) + id, err := strconv.ParseInt(c.Query("ownerId"), 10, 64) + if err != nil { + go s.SaveLog("OwnerInfo", "Manage", "", "", c.Request.URL.Path, fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") + return nil, e.NewValidErr(err) + } + data, err = repo.OwnerInfo(c, id) + go s.SaveLog("获取业主信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") + return +} + func (s HandlerService) AddOwner(c *gin.Context) (data interface{}, err error) { repo := service.NewManageService(s.Engine, s.Logger) us, _ := c.Get("operatorUser") @@ -175,6 +192,21 @@ func (s HandlerService) ProductList(c *gin.Context) (data interface{}, err error go s.SaveLog("产品(物模型)列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") return } + +func (s HandlerService) GetProductInfo(c *gin.Context) (data interface{}, err error) { + repo := service.NewManageService(s.Engine, s.Logger) + us, _ := c.Get("operatorUser") + userInfo := us.(*model.SystemUser) + var req proto.ProductItemRequest + err = c.ShouldBindJSON(&req) + if err != nil { + go s.SaveLog("GetProductInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") + return nil, e.NewValidErr(err) + } + data, err = repo.GetProductInfo(c, req) + go s.SaveLog("查看产品(物模型)", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "") + return +} func (s HandlerService) AddProduct(c *gin.Context) (data interface{}, err error) { repo := service.NewManageService(s.Engine, s.Logger) us, _ := c.Get("operatorUser") diff --git a/internal/handler/user.go b/internal/handler/user.go index 78eba6f..50f0217 100644 --- a/internal/handler/user.go +++ b/internal/handler/user.go @@ -27,3 +27,11 @@ func (s HandlerService) GetUserInfo(c *gin.Context) (data interface{}, err error data, err = repo.GetUserInfo(c, userinfo.UserId) return } + +func (s HandlerService) MenuList(c *gin.Context) (data interface{}, err error) { + repo := service.NewUserService(s.Engine, s.Logger) + us, _ := c.Get("operatorUser") + userinfo := us.(*model.SystemUser) + data, err = repo.MenuList(c, userinfo.UserId) + return +} diff --git a/internal/proto/request.go b/internal/proto/request.go index 5db3c32..de99c41 100644 --- a/internal/proto/request.go +++ b/internal/proto/request.go @@ -52,6 +52,7 @@ func (r OwnerItemReq) ToString() string { type ProjectRequest struct { LineName string `json:"lineName"` ProjectName string `json:"projectName"` + OwnerId int64 `json:"ownerId,omitempty"` BasePageList } @@ -106,6 +107,8 @@ type ProductItemRequest struct { MatterName string `json:"matterName"` CategoryId int64 `json:"categoryId"` Protocol int `json:"protocol"` + Connection int `json:"connection"` + ModelDesc string `json:"modelDesc"` UserVersion int64 `json:"userVersion"` Status int `json:"status"` } @@ -240,6 +243,7 @@ type EventParamItem struct { EventId int64 `json:"eventId"` ParamName string `json:"paramName"` ParamIdentifier string `json:"paramIdentifier"` + ParamDesc string `json:"paramDesc"` DataType int `json:"dataType"` MaxValue string `json:"maxValue"` MinValue string `json:"minValue"` @@ -279,6 +283,7 @@ type ServiceParamItem struct { ParamsOwnerType int `json:"paramsOwnerType"` ParamName string `json:"paramName"` ParamIdentifier string `json:"paramIdentifier"` + ParamDesc string `json:"paramDesc"` DataType int `json:"dataType"` MaxValue string `json:"maxValue"` MinValue string `json:"minValue"` diff --git a/internal/router/router.go b/internal/router/router.go index e24e62a..30b0775 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -24,6 +24,11 @@ func InitRouter(logger *logging.Logger, engine *xorm.Engine) *gin.Engine { user.Use(middleware.JwtAuthMiddleware(logger.Logger)) user.POST("/login", e.ErrorWrapper(hs.Login)) user.GET("/getUserInfo", e.ErrorWrapper(hs.GetUserInfo)) + + menu := user.Group("/menu") + { + menu.GET("/list", e.ErrorWrapper(hs.MenuList)) + } } manage := r.Group("/manage") { @@ -31,6 +36,7 @@ func InitRouter(logger *logging.Logger, engine *xorm.Engine) *gin.Engine { owner := manage.Group("/owner") { owner.POST("/list", e.ErrorWrapper(hs.OwnerList)) + owner.GET("/info", e.ErrorWrapper(hs.OwnerInfo)) owner.POST("/add", e.ErrorWrapper(hs.AddOwner)) owner.POST("/edit", e.ErrorWrapper(hs.EditOwner)) owner.POST("/delete", e.ErrorWrapper(hs.DelOwner)) @@ -46,6 +52,8 @@ func InitRouter(logger *logging.Logger, engine *xorm.Engine) *gin.Engine { product := manage.Group("/product") { product.POST("/list", e.ErrorWrapper(hs.ProductList)) + + product.POST("/info", e.ErrorWrapper(hs.GetProductInfo)) product.POST("/add", e.ErrorWrapper(hs.AddProduct)) product.POST("/edit", e.ErrorWrapper(hs.EditProduct)) product.POST("/delete", e.ErrorWrapper(hs.DelProduct)) diff --git a/internal/service/index.go b/internal/service/index.go index 0cb9c72..ef4dd52 100644 --- a/internal/service/index.go +++ b/internal/service/index.go @@ -47,6 +47,7 @@ type repo struct { type UserService interface { Login(ctx context.Context, userName, pass string) (rsp *proto.BaseResponse, err error) GetUserInfo(ctx context.Context, userId int64) (rsp *proto.BaseResponse, err error) + MenuList(ctx context.Context, userId int64) (rsp *proto.BaseResponse, err error) } func NewUserService(engine *xorm.Engine, logger *logging.Logger) UserService { @@ -190,3 +191,55 @@ ReturnPoint: } return rsp, err } + +func (rp *repo) MenuList(ctx context.Context, userId int64) (rsp *proto.BaseResponse, err error) { + rsp = new(proto.BaseResponse) + select { + case <-ctx.Done(): + err = fmt.Errorf("超时/取消") + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Message = "超时/取消" + rsp.Err = ctx.Err() + return rsp, ctx.Err() + default: + //获取用户 + roleList := make([]model.SystemUserRole, 0) + err = rp.engine.Where("user_id = ? and status = 1", userId).Find(&roleList) + if err != nil { + goto ReturnPoint + } + roleIdList := make([]int64, len(roleList)) + for k, v := range roleList { + roleIdList[k] = v.RoleId + } + menuList := make([]model.SystemRoleMenu, 0) + err = rp.engine.In("role_id", roleIdList).And("status = 1").Find(&menuList) + if err != nil { + goto ReturnPoint + } + menuIdList := make([]int64, len(menuList)) + for k, v := range menuList { + menuIdList[k] = v.RoleId + } + list := make([]model.SystemMenu, 0) + err = rp.engine.In("menu_id", menuIdList).And("status = 1").Find(&list) + if err != nil { + goto ReturnPoint + } + rsp.Code = http.StatusOK + rsp.Status = http.StatusText(http.StatusOK) + rsp.Message = "成功" + rsp.Data = list + rsp.Err = err + return rsp, err + } +ReturnPoint: + if err != nil { + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Err = err + rsp.Message = "失败" + } + return rsp, err +} diff --git a/internal/service/manage.go b/internal/service/manage.go index 9ea8b07..0c88274 100644 --- a/internal/service/manage.go +++ b/internal/service/manage.go @@ -13,6 +13,7 @@ import ( type ManageService interface { OwnerList(ctx context.Context, req proto.OwnerRequest) (rsp *proto.BaseResponse, err error) + OwnerInfo(ctx context.Context, ownerId int64) (rsp *proto.BaseResponse, err error) AddOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error) EditOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error) DelOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error) @@ -22,6 +23,7 @@ type ManageService interface { DelProject(ctx context.Context, req proto.ProjectItemRequest) (rsp *proto.BaseResponse, err error) ProductList(ctx context.Context, req proto.ProductRequest) (rsp *proto.BaseResponse, err error) + GetProductInfo(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) AddProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) EditProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) DelProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) @@ -98,7 +100,43 @@ ReturnPoint: } return rsp, err } - +func (rp *repo) OwnerInfo(ctx context.Context, ownerId int64) (rsp *proto.BaseResponse, err error) { + rsp = new(proto.BaseResponse) + select { + case <-ctx.Done(): + err = fmt.Errorf("超时/取消") + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Message = "超时/取消" + rsp.Err = ctx.Err() + return rsp, ctx.Err() + default: + var h bool + item := new(model.Owner) + h, err = rp.engine.ID(ownerId).Get(item) + if err != nil { + goto ReturnPoint + } + if !h { + err = fmt.Errorf("未能找到对应的业主") + goto ReturnPoint + } + rsp.Code = http.StatusOK + rsp.Status = http.StatusText(http.StatusOK) + rsp.Message = "获取业主信息成功" + rsp.Err = ctx.Err() + rsp.Data = item + return rsp, err + } +ReturnPoint: + if err != nil { + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Err = err + rsp.Message = "失败" + } + return rsp, err +} func (rp *repo) AddOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error) { rsp = new(proto.BaseResponse) select { @@ -246,6 +284,7 @@ func (rp *repo) ProjectList(ctx context.Context, req proto.ProjectRequest) (rsp data := make([]model.Project, 0) count, err := rp.engine.Where("(? = '' or project_name like ?) ", req.ProjectName, "%"+req.ProjectName+"%"). And("(? = '' or line_name like ?)", req.LineName, "%"+req.LineName+"%"). + And("(? = 0 or owner_id = ?)", req.OwnerId, req.OwnerId). Limit(int(req.Size), int(((req.Page)-1)*req.Size)). FindAndCount(&data) if err != nil { @@ -465,6 +504,43 @@ ReturnPoint: return rsp, err } +func (rp *repo) GetProductInfo(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) { + rsp = new(proto.BaseResponse) + select { + case <-ctx.Done(): + err = fmt.Errorf("超时/取消") + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Message = "超时/取消" + rsp.Err = ctx.Err() + return rsp, ctx.Err() + default: + var h bool + item := new(model.MatterModel) + h, err = rp.engine.ID(req.MatterId).Get(item) + if err != nil { + goto ReturnPoint + } + if !h { + err = fmt.Errorf("未能找到对应的产品") + goto ReturnPoint + } + rsp.Code = http.StatusOK + rsp.Status = http.StatusText(http.StatusOK) + rsp.Message = "成功" + rsp.Data = item + rsp.Err = err + return rsp, err + } +ReturnPoint: + if err != nil { + rsp.Code = http.StatusInternalServerError + rsp.Status = http.StatusText(http.StatusInternalServerError) + rsp.Err = err + rsp.Message = "失败" + } + return rsp, err +} func (rp *repo) AddProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error) { rsp = new(proto.BaseResponse) select { @@ -480,6 +556,8 @@ func (rp *repo) AddProduct(ctx context.Context, req proto.ProductItemRequest) (r MatterName: req.MatterName, CategoryId: req.CategoryId, Protocol: req.Protocol, + Connection: req.Connection, + ModelDesc: req.ModelDesc, UserVersion: 1, Status: 1, CreateAt: time.Now().Unix(), @@ -535,6 +613,12 @@ func (rp *repo) EditProduct(ctx context.Context, req proto.ProductItemRequest) ( if req.Protocol > 0 { item.Protocol = req.Protocol } + if req.Connection > 0 { + item.Connection = req.Connection + } + if len(req.ModelDesc) > 0 { + item.ModelDesc = req.ModelDesc + } if req.UserVersion > 0 { item.UserVersion = req.UserVersion } @@ -775,6 +859,7 @@ func (rp *repo) AttributeList(ctx context.Context, req proto.AttributeRequest) ( data := make([]model.MatterAttribute, 0) count, err := rp.engine.Where("matter_id = ? ", req.MatterId). And("version_id = ?", req.VersionId). + And(" status = 1"). Limit(int(req.Size), int(((req.Page)-1)*req.Size)). FindAndCount(&data) if err != nil { @@ -932,7 +1017,7 @@ func (rp *repo) DelAttribute(ctx context.Context, req proto.AttributeItemRequest default: var h bool item := new(model.MatterAttribute) - h, err = rp.engine.ID(req.MatterId).Get(item) + h, err = rp.engine.ID(req.AttributeId).Get(item) if err != nil { goto ReturnPoint } @@ -942,7 +1027,7 @@ func (rp *repo) DelAttribute(ctx context.Context, req proto.AttributeItemRequest } item.Status = 0 item.UpdateAt = time.Now().Unix() - _, err = rp.engine.ID(req.MatterId).AllCols().Update(item) + _, err = rp.engine.ID(req.AttributeId).AllCols().Update(item) if err != nil { goto ReturnPoint } @@ -1192,6 +1277,7 @@ func (rp *repo) AddEventParams(ctx context.Context, req proto.EventParamItem) (r EventId: req.EventId, ParamName: req.ParamName, ParamIdentifier: req.ParamIdentifier, + ParamDesc: req.ParamDesc, DataType: req.DataType, MaxValue: req.MaxValue, MinValue: req.MinValue, @@ -1256,6 +1342,9 @@ func (rp *repo) EditEventParams(ctx context.Context, req proto.EventParamItem) ( if len(req.ParamIdentifier) > 0 { item.ParamIdentifier = req.ParamIdentifier } + if len(req.ParamDesc) > 0 { + item.ParamDesc = req.ParamDesc + } if req.DataType > 0 { item.DataType = req.DataType } @@ -1569,6 +1658,7 @@ func (rp *repo) AddServiceParams(ctx context.Context, req proto.ServiceParamItem ParamsOwnerType: req.ParamsOwnerType, ParamName: req.ParamName, ParamIdentifier: req.ParamIdentifier, + ParamDesc: req.ParamDesc, DataType: req.DataType, MaxValue: req.MaxValue, MinValue: req.MinValue, @@ -1636,6 +1726,9 @@ func (rp *repo) EditServiceParams(ctx context.Context, req proto.ServiceParamIte if len(req.ParamIdentifier) > 0 { item.ParamIdentifier = req.ParamIdentifier } + if len(req.ParamDesc) > 0 { + item.ParamDesc = req.ParamDesc + } if req.DataType > 0 { item.DataType = req.DataType } diff --git a/model/index.go b/model/index.go index cbc1958..9b6e9c8 100644 --- a/model/index.go +++ b/model/index.go @@ -47,6 +47,7 @@ func New(driveName, dsn string) { &SystemRoleRoute{}, &SystemRole{}, &SystemUser{}, + &SystemUserRole{}, ) if err != nil { zap.L().Error("同步数据库表结构", zap.Error(err)) diff --git a/model/matterEventParams.go b/model/matterEventParams.go index ba7ca23..0296aa5 100644 --- a/model/matterEventParams.go +++ b/model/matterEventParams.go @@ -7,6 +7,7 @@ type MatterEventParams struct { EventId int64 `xorm:"not null INT(11) default 0" json:"eventId"` ParamName string `xorm:"varchar(200) not null" json:"paramName"` //参数名称 ParamIdentifier string `xorm:"varchar(64) not null" json:"paramIdentifier"` //参数标识符 + ParamDesc string `xorm:"VARCHAR(200)" json:"paramDesc"` //参数描述 DataType int `xorm:"not null INT(11) default 0" json:"dataType"` //数据类型 MaxValue string `xorm:"varchar(200) " json:"maxValue"` MinValue string `xorm:"varchar(200)" json:"minValue"` diff --git a/model/matterModel.go b/model/matterModel.go index 075f5b7..f6f10ce 100644 --- a/model/matterModel.go +++ b/model/matterModel.go @@ -6,7 +6,9 @@ type MatterModel struct { MatterName string `xorm:"varchar(200) not null" json:"matterName"` CategoryId int64 `xorm:"not null INT(11) default 0 index" json:"categoryId"` Protocol int `xorm:"not null INT(11) default 0" json:"protocol"` + Connection int `xorm:"not null SMALLINT default 0" json:"connection"` UserVersion int64 `xorm:"not null INT(11) default 0" json:"userVersion"` + ModelDesc string `xorm:"VARCHAR(200)" json:"modelDesc"` Status int `xorm:"not null INT(11) default 0" json:"status"` CreateAt int64 `xorm:"created" json:"createAt"` UpdateAt int64 `xorm:"updated" json:"updateAt"` diff --git a/model/matterServiceParams.go b/model/matterServiceParams.go index f4828bb..eda0a7f 100644 --- a/model/matterServiceParams.go +++ b/model/matterServiceParams.go @@ -8,6 +8,7 @@ type MatterServiceParams struct { ParamsOwnerType int `xorm:"not null SMALLINT default 0" json:"paramsOwnerType"` //参数的所属类型,1:服务入参; 2:服务出参 ParamName string `xorm:"varchar(200) not null" json:"paramName"` //参数名称 ParamIdentifier string `xorm:"varchar(64) not null" json:"paramIdentifier"` //参数标识符 + ParamDesc string `xorm:"varchar(200)" json:"paramDesc"` //参数描述 DataType int `xorm:"not null INT(11) default 0" json:"dataType"` //数据类型 MaxValue string `xorm:"varchar(200) " json:"maxValue"` MinValue string `xorm:"varchar(200)" json:"minValue"`