| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package logic
- import (
- "git.rtzhtech.cn/iss/public-lib/dao"
- "git.rtzhtech.cn/iss/public-lib/dto"
- "git.rtzhtech.cn/iss/public-lib/model"
- "git.rtzhtech.cn/iss/public-lib/svc"
- "github.com/gogf/gf/v2/util/gconv"
- "gorm.io/gen/field"
- )
- type MpInfoLogic struct {
- SvcCtx *svc.ServiceContext
- }
- // NewMpInfoLogic
- // @Description: 测点
- // @return *MpInfoLogic
- func NewMpInfoLogic() *MpInfoLogic {
- return &MpInfoLogic{
- SvcCtx: svc.SvcCtx,
- }
- }
- // AddMpInfo
- // @Description: 添加
- // @receiver l
- // @param in
- // @return error
- func (l *MpInfoLogic) AddMpInfo(in *model.DevMpinfo) error {
- in.ID = 0
- err := l.SvcCtx.DevMpinfo.Create(in)
- return err
- }
- // DelMpInfo
- // @Description: 删除
- // @receiver l
- // @param mpId 测点id
- // @return error
- func (l *MpInfoLogic) DelMpInfo(mpId int64) error {
- do := l.SvcCtx.DevMpinfo
- _linkRelationObj := l.SvcCtx.LinkRelationObj
- _alarmRelation := l.SvcCtx.AlarmRelation
- //删除关联的 联动、告警
- _linkRelationObj.Where(_linkRelationObj.Linkfromid.Eq(mpId)).Delete()
- _alarmRelation.Where(_alarmRelation.Mpid.Eq(mpId)).Delete()
- _, err := do.Where(do.Mpid.Eq(mpId)).Delete()
- return err
- }
- // ModifyMpInfo
- // @Description: 修改
- // @receiver l
- // @param in 可修改除测点ID,App id外的信息
- // @param fields 更新字段,当field为null时,更新in的全部字段
- // @return error
- func (l *MpInfoLogic) ModifyMpInfo(in *model.DevMpinfo, fields ...string) error {
- do := l.SvcCtx.DevMpinfo
- var err error
- _do := do.Omit(do.ID, do.Appid).Where(do.Mpid.Eq(in.Mpid))
- if fields == nil {
- m := gconv.Map(in)
- _, err = _do.Updates(m)
- return err
- }
- var fieldList []field.Expr
- for _, v := range fields {
- _f, ok := do.GetFieldByName(v)
- if ok {
- fieldList = append(fieldList, _f)
- }
- }
- _, err = _do.Select(fieldList...).Updates(in)
- return err
- }
- func (l *MpInfoLogic) getMpInfoCond(req *dto.GetMpInfoReq) *dao.Condition {
- _dao := l.SvcCtx.DevMpinfo
- cond := NewCondition(&req.LimitPage)
- if req.MpName != "" {
- cond.Where[_dao.Mpname.String()] = req.MpName
- }
- if req.ZoneName != "" {
- cond.Where[_dao.Zonename.String()] = req.ZoneName
- }
- if req.PositionName != "" {
- cond.Where[_dao.Positionname.String()] = req.PositionName
- }
- if req.AppId > 0 {
- cond.Where[_dao.Appid.String()] = req.AppId
- }
- if req.ModelId > 0 {
- cond.Where[_dao.Modelid.String()] = req.ModelId
- }
- if req.DeviceId > 0 {
- cond.Where[_dao.Deviceid.String()] = req.DeviceId
- }
- return cond
- }
- // GetMpInfoInfo
- // @Description: 分页查询
- // @receiver l
- // @param where 查询条件
- // @param page
- // @param limit
- // @return []*model.DevDevinfo
- // @return error
- func (l *MpInfoLogic) GetMpInfo(req *dto.GetMpInfoReq) (*dto.GetMpInfoResp, error) {
- _dao := l.SvcCtx.DevMpinfo
- cond := l.getMpInfoCond(req)
- resp := &dto.GetMpInfoResp{}
- err := _dao.Base.Find(cond, &resp.List)
- if err != nil {
- return nil, err
- }
- err = _dao.Base.Count(cond, &resp.Total)
- return resp, err
- }
- // GetMpInfoCount
- // @Description:查询满足条件的总数
- // @receiver l
- // @param where 查询条件
- // @return int64
- // @return error
- func (l *MpInfoLogic) GetMpInfoCount(req *dto.GetMpInfoReq) (int64, error) {
- cond := l.getMpInfoCond(req)
- var count int64
- err := l.SvcCtx.DevMpinfo.Base.Count(cond, &count)
- if err != nil {
- return 0, err
- }
- return count, err
- }
|