add apis
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 1s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 1s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 1s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / water (push) Failing after 8s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 1s
CI / bff (push) Successful in 26s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 1s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 1s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 0s
CI / water (push) Failing after 8s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
)
|
||||
|
||||
type UsersCreate struct {
|
||||
Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"`
|
||||
UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户ID
|
||||
HostCode string `gorm:"column:host_code;type:varchar(255);default:NULL" json:"host_code"` // 设备号
|
||||
Status int32 `gorm:"column:status;type:tinyint(1);not null;default:3" json:"status"` // 状态:1为正常,2为禁用,3为申请
|
||||
}
|
||||
|
||||
type UsersInfo struct {
|
||||
Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"`
|
||||
UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户ID
|
||||
UserName string `gorm:"-" json:"user_name"` // 用户名
|
||||
HostCode string `gorm:"column:host_code;type:varchar(255);default:NULL" json:"host_code"` // 设备号
|
||||
Status int32 `gorm:"column:status;type:tinyint(1);not null;default:3" json:"status"` // 状态:1为正常,2为禁用,3为申请
|
||||
UpdateTime utils.CustomTime `json:"update_time" gorm:"update_time"`
|
||||
CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"`
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
WarningStatus = 1
|
||||
WarningStatusSolved = 2
|
||||
WarningStatusUnsolved = 3
|
||||
)
|
||||
|
||||
type WarningCreate struct {
|
||||
Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"`
|
||||
UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户ID
|
||||
HostCode string `gorm:"column:host_code;type:varchar(255);default:NULL" json:"host_code"` // 设备号
|
||||
Time utils.CustomTime `gorm:"column:time;type:datetime;default:NULL" json:"time"` // 剩余盐量
|
||||
Type int32 `gorm:"column:type;type:tinyint(1);default:NULL" json:"type"` // 类型:1流量计 2液位计 3侵水计 4超声
|
||||
Content string `gorm:"column:content;type:varchar(255);default:NULL" json:"content"`
|
||||
}
|
||||
|
||||
type WarningInfo struct {
|
||||
Id int64 `gorm:"column:id;type:int;not null;autoIncrement" json:"id"`
|
||||
UserId int64 `gorm:"column:user_id;type:int;default:NULL" json:"user_id"` // 用户ID
|
||||
HostCode string `gorm:"column:host_code;type:varchar(255);default:NULL" json:"host_code"` // 设备号
|
||||
Time utils.CustomTime `gorm:"column:time;type:datetime;default:NULL" json:"time"` // 剩余盐量
|
||||
Status int32 `gorm:"column:status;type:tinyint(1);default:NULL" json:"status"` // 状态,1为报警,2为已解决,3为未解决
|
||||
Type int32 `gorm:"column:type;type:tinyint(1);default:NULL" json:"type"` // 类型:1流量计 2液位计 3侵水计 4超声
|
||||
Content string `gorm:"column:content;type:varchar(255);default:NULL" json:"content"`
|
||||
CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"`
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"lone-services/services/water/validator"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddWarningLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAddWarningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddWarningLogic {
|
||||
return &AddWarningLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 添加 流量计 液位计 侵水计 超声 四种设备异常警
|
||||
func (l *AddWarningLogic) AddWarning(in *water.AddWarningRequest) (*water.Response, error) {
|
||||
var v validator.WarningAddValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
aTime, _ := utils.ParseDateOnly(in.Time)
|
||||
info := dao.UsersCreate{
|
||||
HostCode: in.HostCode,
|
||||
Content: in.Content,
|
||||
Type: in.Type,
|
||||
Time: aTime,
|
||||
UserId: adminInfo.ID,
|
||||
}
|
||||
err := model.WarningModel{}.Init().Create(&info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"lone-services/services/water/validator"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApplyStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewApplyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyStatusLogic {
|
||||
return &ApplyStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 同意
|
||||
func (l *ApplyStatusLogic) ApplyStatus(in *water.ApplyStatusRequest) (*water.Response, error) {
|
||||
var v validator.UserStatusValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"id": string(in.Id)}}
|
||||
|
||||
var info dao.UsersInfo
|
||||
err := model.UsersModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
info.Status = in.Status
|
||||
|
||||
_, err = model.UsersModel{}.Init().Edit(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"lone-services/services/water/validator"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApplyUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewApplyUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyUserLogic {
|
||||
return &ApplyUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 申请
|
||||
func (l *ApplyUserLogic) ApplyUser(in *water.ApplyUserRequest) (*water.Response, error) {
|
||||
var v validator.UserApplyValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"user_id": string(in.UserId), "status": utils.StringStatusOk}}
|
||||
|
||||
var info dao.UsersCreate
|
||||
err := model.UsersModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
return l.fail(utils.ErrorExist)
|
||||
}
|
||||
|
||||
info.UserId = in.UserId
|
||||
info.HostCode = in.HostCode
|
||||
|
||||
err = model.UsersModel{}.Init().Create(&info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ChangeAdminLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewChangeAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChangeAdminLogic {
|
||||
return &ChangeAdminLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 转移管理人
|
||||
func (l *ChangeAdminLogic) ChangeAdmin(in *water.ChangeAdminRequest) (*water.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &water.Response{}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWarningLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewGetWarningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWarningLogic {
|
||||
return &GetWarningLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取 流量计 液位计 侵水计 超声 四种设备异常警告
|
||||
func (l *GetWarningLogic) GetWarning(in *water.GetWarningItemsRequest) (*water.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Page: int(in.Page),
|
||||
Size: int(in.Size)}
|
||||
|
||||
w.Eq = make(map[string]string)
|
||||
if len(in.HostCode) > utils.NumberZero {
|
||||
w.Eq["host_code"] = in.HostCode
|
||||
}
|
||||
if in.Type > utils.NumberZero {
|
||||
w.Eq["type"] = string(in.Type)
|
||||
}
|
||||
|
||||
var info []dao.WarningInfo
|
||||
items, err := model.WarningModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
return l.ok(items)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"time"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWaterInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewGetWaterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWaterInfoLogic {
|
||||
return &GetWaterInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取月,日量
|
||||
func (l *GetWaterInfoLogic) GetWaterInfo(in *water.EmptyRequest) (*water.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
date := utils.Now().Format(time.DateOnly)
|
||||
w := modelbase.Params{Eq: map[string]string{"date": date}}
|
||||
var logDate dao.LogDate
|
||||
err := model.LogDateModel{}.Init().GetOne(w, &logDate)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
type ret struct {
|
||||
date int64
|
||||
month int64
|
||||
}
|
||||
var retData ret
|
||||
if logDate.Id > utils.NumberZero {
|
||||
retData.date = logDate.Water
|
||||
|
||||
}
|
||||
|
||||
month := utils.Now().Format("2006-01")
|
||||
w = modelbase.Params{Eq: map[string]string{"month": month}}
|
||||
var monthDate dao.LogDate
|
||||
err = model.LogDateModel{}.Init().GetOne(w, &monthDate)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if logDate.Id > utils.NumberZero {
|
||||
retData.date = monthDate.Water
|
||||
|
||||
}
|
||||
return l.ok(retData)
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"lone-services/services/water/validator"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UsersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsersLogic {
|
||||
return &UsersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 管理人列表
|
||||
func (l *UsersLogic) Users(in *water.UsersRequest) (*water.Response, error) {
|
||||
var v validator.UserItemsValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"host_code": in.HostCode, "status": utils.StringStatusOk}}
|
||||
|
||||
var info []dao.UsersInfo
|
||||
err := model.UsersModel{}.Init().Items(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
ids := []int64{}
|
||||
for _, v := range info {
|
||||
ids = append(ids, v.UserId)
|
||||
}
|
||||
|
||||
userItems := svc.GetUsers(ids, l.svcCtx.UserSvcName)
|
||||
|
||||
idsName := make(map[int64]string)
|
||||
for _, val := range userItems {
|
||||
idsName[val.Id] = val.Name
|
||||
}
|
||||
for k, v := range info {
|
||||
if kVal, ok := idsName[v.UserId]; ok {
|
||||
info[k].UserName = kVal
|
||||
}
|
||||
}
|
||||
|
||||
return l.ok(info)
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/dao"
|
||||
"lone-services/services/water/model"
|
||||
"lone-services/services/water/validator"
|
||||
|
||||
"lone-services/rpc/water/pb"
|
||||
"lone-services/services/water/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WarningStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWarningStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WarningStatusLogic {
|
||||
return &WarningStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 状态
|
||||
func (l *WarningStatusLogic) WarningStatus(in *water.WarningStatusRequest) (*water.Response, error) {
|
||||
var v validator.WarningStatusValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
w := modelbase.Params{Eq: map[string]string{"id": string(in.Id)}}
|
||||
|
||||
var info dao.WarningInfo
|
||||
err := model.WarningModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
info.Status = in.Status
|
||||
_, err = model.WarningModel{}.Init().Edit(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
@@ -52,3 +52,51 @@ func (s *WaterServer) GetSetting(ctx context.Context, in *water.HostCodeRequest)
|
||||
l := logic.NewGetSettingLogic(ctx, s.svcCtx)
|
||||
return l.GetSetting(in)
|
||||
}
|
||||
|
||||
// 获取月,日量
|
||||
func (s *WaterServer) GetWaterInfo(ctx context.Context, in *water.EmptyRequest) (*water.Response, error) {
|
||||
l := logic.NewGetWaterInfoLogic(ctx, s.svcCtx)
|
||||
return l.GetWaterInfo(in)
|
||||
}
|
||||
|
||||
// 获取 流量计 液位计 侵水计 超声 四种设备异常警告
|
||||
func (s *WaterServer) GetWarning(ctx context.Context, in *water.GetWarningItemsRequest) (*water.Response, error) {
|
||||
l := logic.NewGetWarningLogic(ctx, s.svcCtx)
|
||||
return l.GetWarning(in)
|
||||
}
|
||||
|
||||
// 添加 流量计 液位计 侵水计 超声 四种设备异常警
|
||||
func (s *WaterServer) AddWarning(ctx context.Context, in *water.AddWarningRequest) (*water.Response, error) {
|
||||
l := logic.NewAddWarningLogic(ctx, s.svcCtx)
|
||||
return l.AddWarning(in)
|
||||
}
|
||||
|
||||
// 状态
|
||||
func (s *WaterServer) WarningStatus(ctx context.Context, in *water.WarningStatusRequest) (*water.Response, error) {
|
||||
l := logic.NewWarningStatusLogic(ctx, s.svcCtx)
|
||||
return l.WarningStatus(in)
|
||||
}
|
||||
|
||||
// 申请
|
||||
func (s *WaterServer) ApplyUser(ctx context.Context, in *water.ApplyUserRequest) (*water.Response, error) {
|
||||
l := logic.NewApplyUserLogic(ctx, s.svcCtx)
|
||||
return l.ApplyUser(in)
|
||||
}
|
||||
|
||||
// 同意
|
||||
func (s *WaterServer) ApplyStatus(ctx context.Context, in *water.ApplyStatusRequest) (*water.Response, error) {
|
||||
l := logic.NewApplyStatusLogic(ctx, s.svcCtx)
|
||||
return l.ApplyStatus(in)
|
||||
}
|
||||
|
||||
// 转移管理人
|
||||
func (s *WaterServer) ChangeAdmin(ctx context.Context, in *water.ChangeAdminRequest) (*water.Response, error) {
|
||||
l := logic.NewChangeAdminLogic(ctx, s.svcCtx)
|
||||
return l.ChangeAdmin(in)
|
||||
}
|
||||
|
||||
// 管理人列表
|
||||
func (s *WaterServer) Users(ctx context.Context, in *water.UsersRequest) (*water.Response, error) {
|
||||
l := logic.NewUsersLogic(ctx, s.svcCtx)
|
||||
return l.Users(in)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
user "lone-services/rpc/user/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
func GetUsers(ids []int64, name string) []*user.UserBriefItem {
|
||||
cli, err := GetRpcClient(name)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
client := user.NewUserClient(cli.Conn())
|
||||
items, err := client.InternalUsersByIds(context.Background(), &user.InternalUsersByIdsReq{Ids: ids})
|
||||
if err != nil {
|
||||
logx.Errorf("get store err: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return items.Items
|
||||
}
|
||||
@@ -1,22 +1,94 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"lone-services/pkg/discovery"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/water/internal/config"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type rpcClientCacheEntry struct {
|
||||
cli zrpc.Client
|
||||
target string
|
||||
expireAt time.Time
|
||||
}
|
||||
|
||||
const rpcClientCacheTTL = 30 * time.Second //缓存过期时间
|
||||
|
||||
var (
|
||||
rpcCacheLock sync.Mutex
|
||||
rpcCache = make(map[string]*rpcClientCacheEntry)
|
||||
)
|
||||
|
||||
func GetRpcClient(serviceName string) (zrpc.Client, error) {
|
||||
if serviceName == utils.StringEmpty {
|
||||
err := fmt.Errorf("rpc serviceName is empty")
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cacheKey := serviceName
|
||||
|
||||
rpcCacheLock.Lock()
|
||||
entry, ok := rpcCache[cacheKey]
|
||||
if ok && time.Now().Before(entry.expireAt) {
|
||||
rpcCacheLock.Unlock()
|
||||
return entry.cli, nil
|
||||
}
|
||||
delete(rpcCache, cacheKey)
|
||||
rpcCacheLock.Unlock()
|
||||
|
||||
inst, err := discovery.Pick(serviceName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("discovery pick %s failed: %w", serviceName, err)
|
||||
logx.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
target := net.JoinHostPort(inst.IP, strconv.FormatUint(inst.Port, utils.NumberTen))
|
||||
|
||||
cli := zrpc.MustNewClient(zrpc.RpcClientConf{
|
||||
Target: target,
|
||||
Timeout: utils.RpcTimeOut, //rpc调用超时5s
|
||||
})
|
||||
|
||||
rpcCacheLock.Lock()
|
||||
rpcCache[cacheKey] = &rpcClientCacheEntry{
|
||||
cli: cli,
|
||||
target: target,
|
||||
expireAt: time.Now().Add(rpcClientCacheTTL),
|
||||
}
|
||||
rpcCacheLock.Unlock()
|
||||
|
||||
return cli, nil
|
||||
}
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
UserSvcName string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
//启动仅读取配置,不建立rpc连接 多个服务就多个
|
||||
userSvc := utils.GetConfigString("services.user")
|
||||
if userSvc == utils.StringEmpty {
|
||||
logx.Error("config services.user empty")
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
UserSvcName: userSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/water/internal/dao"
|
||||
)
|
||||
|
||||
type UsersModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m UsersModel) TableName() string {
|
||||
return modelbase.Prefix() + "users"
|
||||
}
|
||||
|
||||
func (m UsersModel) Init() UsersModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m UsersModel) Create(data *dao.UsersCreate) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/water/internal/dao"
|
||||
)
|
||||
|
||||
type WarningModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m WarningModel) TableName() string {
|
||||
return modelbase.Prefix() + "warning"
|
||||
}
|
||||
|
||||
func (m WarningModel) Init() WarningModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m WarningModel) Create(data *dao.UsersCreate) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
type UserApplyValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
UserId int64 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p UserApplyValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
"UserId.required": "用户不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type UserStatusValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
Status int32 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p UserStatusValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "ID不能为空",
|
||||
"Status.required": "状态不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type UserChangeValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
UserId int64 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p UserChangeValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
"UserId.required": "用户不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type UserItemsValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p UserItemsValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
// WarningAddValidator 查看列表
|
||||
type WarningAddValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
Time string `validate:"required"`
|
||||
Type int64 `validate:"required"`
|
||||
Content string `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p WarningAddValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
"Time.required": "时间不能为空",
|
||||
"Type.required": "类型不能为空",
|
||||
"Content.required": "内容不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type WarningStatusValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
Status int32 `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p WarningStatusValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "ID不能为空",
|
||||
"Status.required": "状态不能为空",
|
||||
}
|
||||
}
|
||||
@@ -14,14 +14,21 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
AddLogRequest = water.AddLogRequest
|
||||
EmptyRequest = water.EmptyRequest
|
||||
HostCodeRequest = water.HostCodeRequest
|
||||
LogItemsRequest = water.LogItemsRequest
|
||||
Response = water.Response
|
||||
SettingRequest = water.SettingRequest
|
||||
WifiCheckRequest = water.WifiCheckRequest
|
||||
WifiSetRequest = water.WifiSetRequest
|
||||
AddLogRequest = water.AddLogRequest
|
||||
AddWarningRequest = water.AddWarningRequest
|
||||
ApplyStatusRequest = water.ApplyStatusRequest
|
||||
ApplyUserRequest = water.ApplyUserRequest
|
||||
ChangeAdminRequest = water.ChangeAdminRequest
|
||||
EmptyRequest = water.EmptyRequest
|
||||
GetWarningItemsRequest = water.GetWarningItemsRequest
|
||||
HostCodeRequest = water.HostCodeRequest
|
||||
LogItemsRequest = water.LogItemsRequest
|
||||
Response = water.Response
|
||||
SettingRequest = water.SettingRequest
|
||||
UsersRequest = water.UsersRequest
|
||||
WarningStatusRequest = water.WarningStatusRequest
|
||||
WifiCheckRequest = water.WifiCheckRequest
|
||||
WifiSetRequest = water.WifiSetRequest
|
||||
|
||||
Water interface {
|
||||
WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
@@ -30,6 +37,22 @@ type (
|
||||
LogItems(ctx context.Context, in *LogItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Setting(ctx context.Context, in *SettingRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
GetSetting(ctx context.Context, in *HostCodeRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 获取月,日量
|
||||
GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 获取 流量计 液位计 侵水计 超声 四种设备异常警告
|
||||
GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 添加 流量计 液位计 侵水计 超声 四种设备异常警
|
||||
AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 状态
|
||||
WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 申请
|
||||
ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 同意
|
||||
ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 转移管理人
|
||||
ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
// 管理人列表
|
||||
Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultWater struct {
|
||||
@@ -72,3 +95,51 @@ func (m *defaultWater) GetSetting(ctx context.Context, in *HostCodeRequest, opts
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.GetSetting(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 获取月,日量
|
||||
func (m *defaultWater) GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.GetWaterInfo(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 获取 流量计 液位计 侵水计 超声 四种设备异常警告
|
||||
func (m *defaultWater) GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.GetWarning(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 添加 流量计 液位计 侵水计 超声 四种设备异常警
|
||||
func (m *defaultWater) AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.AddWarning(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 状态
|
||||
func (m *defaultWater) WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.WarningStatus(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 申请
|
||||
func (m *defaultWater) ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.ApplyUser(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 同意
|
||||
func (m *defaultWater) ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.ApplyStatus(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 转移管理人
|
||||
func (m *defaultWater) ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.ChangeAdmin(ctx, in, opts...)
|
||||
}
|
||||
|
||||
// 管理人列表
|
||||
func (m *defaultWater) Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := water.NewWaterClient(m.cli.Conn())
|
||||
return client.Users(ctx, in, opts...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user