cc23c30c9e
CI / changes (push) Successful in 1m34s
CI / ad (push) Successful in 27s
CI / admin (push) Successful in 17s
CI / aiserver (push) Successful in 26s
CI / analysis (push) Successful in 22s
CI / bff (push) Successful in 21s
CI / chore (push) Successful in 20s
CI / equipment (push) Successful in 19s
CI / express (push) Successful in 19s
CI / factory (push) Successful in 19s
CI / message (push) Successful in 18s
CI / order (push) Successful in 19s
CI / payment (push) Successful in 17s
CI / percutaneous (push) Successful in 17s
CI / product (push) Successful in 19s
CI / record (push) Successful in 19s
CI / sale (push) Successful in 19s
CI / store (push) Successful in 20s
CI / support (push) Successful in 19s
CI / task (push) Successful in 21s
CI / user (push) Successful in 22s
CI / water (push) Successful in 25s
CI / wecom (push) Successful in 21s
CI / ws (push) Successful in 9s
85 lines
2.1 KiB
Go
85 lines
2.1 KiB
Go
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 SettingLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SettingLogic {
|
|
return &SettingLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *SettingLogic) Setting(in *water.SettingRequest) (*water.Response, error) {
|
|
var v validator.HostCodeValidator
|
|
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}}
|
|
var info dao.SettingCreate
|
|
err := model.SettingModel{}.Init().GetOne(w, &info)
|
|
if err != nil {
|
|
return l.fail(utils.Fail)
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return l.ok(false)
|
|
}
|
|
change := false
|
|
if in.Hardness < utils.NumberZero && info.Hardness != in.Hardness {
|
|
change = true
|
|
info.Hardness = in.Hardness
|
|
}
|
|
if in.Soften < utils.NumberZero && info.Soften != in.Soften {
|
|
change = true
|
|
info.Soften = in.Soften
|
|
}
|
|
if in.UseNumber < utils.NumberZero && info.UseNumber != in.UseNumber {
|
|
change = true
|
|
info.UseNumber = in.UseNumber
|
|
}
|
|
if in.SaltPercent < utils.NumberZero && info.SaltPercent != in.SaltPercent {
|
|
change = true
|
|
info.SaltPercent = in.SaltPercent
|
|
}
|
|
if in.RefreshTime != utils.StringEmpty && info.RefreshTime != in.RefreshTime {
|
|
change = true
|
|
info.RefreshTime = in.RefreshTime
|
|
}
|
|
|
|
if in.NoDisturbing != utils.StringEmpty && info.NoDisturbing != in.NoDisturbing {
|
|
change = true
|
|
info.NoDisturbing = in.NoDisturbing
|
|
}
|
|
if change {
|
|
_, err = model.SettingModel{}.Init().Edit(w, &info)
|
|
if err != nil {
|
|
return l.fail(utils.Fail)
|
|
}
|
|
return l.ok(true)
|
|
}
|
|
return l.ok(false)
|
|
}
|