hpds_jkw_web/internal/service/manage.go

2303 lines
64 KiB
Go
Raw Normal View History

2023-01-06 10:09:23 +08:00
package service
import (
"context"
"fmt"
2023-01-06 19:15:52 +08:00
"git.hpds.cc/Component/logging"
2023-01-13 11:26:39 +08:00
"hpds-iot-web/config"
2023-01-06 10:09:23 +08:00
"hpds-iot-web/internal/proto"
"hpds-iot-web/model"
2023-01-13 11:26:39 +08:00
"hpds-iot-web/pkg/minedata"
2023-01-06 10:09:23 +08:00
"net/http"
2023-01-13 11:26:39 +08:00
"strconv"
"strings"
2023-01-06 10:09:23 +08:00
"time"
"xorm.io/xorm"
)
type ManageService interface {
OwnerList(ctx context.Context, req proto.OwnerRequest) (rsp *proto.BaseResponse, err error)
2023-01-10 10:01:42 +08:00
OwnerInfo(ctx context.Context, ownerId int64) (rsp *proto.BaseResponse, err error)
2023-01-06 10:09:23 +08:00
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)
2023-01-13 11:26:39 +08:00
2023-01-06 10:09:23 +08:00
ProjectList(ctx context.Context, req proto.ProjectRequest) (rsp *proto.BaseResponse, err error)
2023-01-13 11:26:39 +08:00
GetLngLat(ctx context.Context, mileagePile string) (lng, lat float64, err error)
ProjectInfo(ctx context.Context, req proto.ProjectItemRequest) (rsp *proto.BaseResponse, err error)
2023-01-06 10:09:23 +08:00
AddProject(ctx context.Context, req proto.ProjectItemRequest) (rsp *proto.BaseResponse, err error)
EditProject(ctx context.Context, req proto.ProjectItemRequest) (rsp *proto.BaseResponse, err error)
DelProject(ctx context.Context, req proto.ProjectItemRequest) (rsp *proto.BaseResponse, err error)
2023-06-17 09:38:26 +08:00
GetProjectResult(ctx context.Context, req proto.ProjectRequest) (rsp *proto.BaseResponse, err error)
2023-07-10 15:28:20 +08:00
GetProjectData(ctx context.Context, req proto.ProjectDataRequest) (rsp *proto.BaseResponse, err error)
2023-01-06 10:09:23 +08:00
ProductList(ctx context.Context, req proto.ProductRequest) (rsp *proto.BaseResponse, err error)
2023-01-10 10:01:42 +08:00
GetProductInfo(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error)
2023-01-06 10:09:23 +08:00
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)
CategoryList(ctx context.Context, req proto.ProductCategoryRequest) (rsp *proto.BaseResponse, err error)
AddCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (rsp *proto.BaseResponse, err error)
EditCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (rsp *proto.BaseResponse, err error)
DelCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (rsp *proto.BaseResponse, err error)
AttributeList(ctx context.Context, req proto.AttributeRequest) (rsp *proto.BaseResponse, err error)
AddAttribute(ctx context.Context, req proto.AttributeItemRequest) (rsp *proto.BaseResponse, err error)
EditAttribute(ctx context.Context, req proto.AttributeItemRequest) (rsp *proto.BaseResponse, err error)
DelAttribute(ctx context.Context, req proto.AttributeItemRequest) (rsp *proto.BaseResponse, err error)
EventList(ctx context.Context, req proto.AttributeRequest) (rsp *proto.BaseResponse, err error)
AddEvent(ctx context.Context, req proto.EventItemRequest) (rsp *proto.BaseResponse, err error)
EditEvent(ctx context.Context, req proto.EventItemRequest) (rsp *proto.BaseResponse, err error)
DelEvent(ctx context.Context, req proto.EventItemRequest) (rsp *proto.BaseResponse, err error)
ServiceList(ctx context.Context, req proto.AttributeRequest) (rsp *proto.BaseResponse, err error)
AddService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error)
EditService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error)
DelService(ctx context.Context, req proto.ServiceItemRequest) (rsp *proto.BaseResponse, err error)
2023-01-06 14:38:22 +08:00
EventParamsList(ctx context.Context, req proto.EventParamsRequest) (rsp *proto.BaseResponse, err error)
AddEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error)
EditEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error)
DelEventParams(ctx context.Context, req proto.EventParamItem) (rsp *proto.BaseResponse, err error)
ServiceParamsList(ctx context.Context, req proto.ServiceParamsRequest) (rsp *proto.BaseResponse, err error)
AddServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error)
EditServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error)
DelServiceParams(ctx context.Context, req proto.ServiceParamItem) (rsp *proto.BaseResponse, err error)
2023-01-11 18:05:29 +08:00
DeviceList(ctx context.Context, req proto.DeviceRequest) (rsp *proto.BaseResponse, err error)
DeviceInfo(ctx context.Context, req proto.DeviceItemRequest) (rsp *proto.BaseResponse, err error)
AddDevice(ctx context.Context, req proto.DeviceItemRequest) (rsp *proto.BaseResponse, err error)
EditDevice(ctx context.Context, req proto.DeviceItemRequest) (rsp *proto.BaseResponse, err error)
DeleteDevice(ctx context.Context, req proto.DeviceItemRequest) (rsp *proto.BaseResponse, err error)
2023-01-06 10:09:23 +08:00
}
2023-01-13 11:26:39 +08:00
func NewManageService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) ManageService {
2023-01-06 10:09:23 +08:00
return &repo{
2023-01-13 11:26:39 +08:00
AppConfig: cfg,
engine: engine,
logger: logger,
2023-01-06 10:09:23 +08:00
}
}
func (rp *repo) OwnerList(ctx context.Context, req proto.OwnerRequest) (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:
data := make([]model.Owner, 0)
count, err := rp.engine.Where("(? = '' or owner_name like ?)", req.OwnerName, "%"+req.OwnerName+"%").
And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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
}
2023-01-10 10:01:42 +08:00
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
}
2023-01-06 10:09:23 +08:00
func (rp *repo) AddOwner(ctx context.Context, req proto.OwnerItemReq) (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:
item := &model.Owner{
OwnerName: req.OwnerName,
ChargeUser: req.ChargeUser,
Phone: req.Phone,
Creator: req.Creator,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
Status: 1,
}
_, err = rp.engine.Insert(item)
if err != nil {
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) EditOwner(ctx context.Context, req proto.OwnerItemReq) (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(req.OwnerId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的业主")
goto ReturnPoint
}
item.OwnerName = req.OwnerName
item.Phone = req.Phone
item.ChargeUser = req.ChargeUser
item.Modifier = req.Creator
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.OwnerId).AllCols().Update(item)
if err != nil {
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) DelOwner(ctx context.Context, req proto.OwnerItemReq) (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(req.OwnerId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的业主")
goto ReturnPoint
}
item.Status = 0
item.Modifier = req.Creator
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.OwnerId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "删除业主成功"
rsp.Err = ctx.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) ProjectList(ctx context.Context, req proto.ProjectRequest) (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:
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+"%").
2023-01-10 10:01:42 +08:00
And("(? = 0 or owner_id = ?)", req.OwnerId, req.OwnerId).
2023-01-13 11:26:39 +08:00
And("status = 1").
2023-01-06 10:09:23 +08:00
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) ProjectInfo(ctx context.Context, req proto.ProjectItemRequest) (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.Project)
h, err = rp.engine.ID(req.ProjectId).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
}
2023-01-06 10:09:23 +08:00
func (rp *repo) AddProject(ctx context.Context, req proto.ProjectItemRequest) (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:
item := &model.Project{
ProjectName: req.ProjectName,
OwnerId: req.OwnerId,
LineName: req.LineName,
StartName: req.StartName,
EndName: req.EndName,
FixedDeviceNum: req.FixedDeviceNum,
Direction: req.Direction,
LaneNum: req.LaneNum,
Status: 1,
2023-06-17 09:38:26 +08:00
SideType: req.SideType,
2023-01-06 10:09:23 +08:00
Creator: req.Creator,
}
var (
sLng, sLat, eLng, eLat float64
)
sLng, sLat, err = rp.GetLngLat(ctx, fmt.Sprintf("%s+%s", req.LineName, req.StartName))
2023-01-13 11:26:39 +08:00
if err != nil {
goto ReturnPoint
}
item.StartPointLng = sLng
item.StartPointLat = sLat
2023-01-13 11:26:39 +08:00
eLng, eLat, err = rp.GetLngLat(ctx, fmt.Sprintf("%s+%s", req.LineName, req.EndName))
2023-01-13 11:26:39 +08:00
if err != nil {
goto ReturnPoint
}
item.EndPointLng = eLng
item.EndPointLat = eLat
2023-01-13 11:26:39 +08:00
2023-01-06 10:09:23 +08:00
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-01-13 11:26:39 +08:00
func (rp *repo) GetLngLat(ctx context.Context, mileagePile string) (lng, lat float64, err error) {
mine := minedata.NewMineData(rp.AppConfig.MineData.AccessKey)
//正里程桩
res, err := mine.MilepostService(mileagePile)
if err != nil {
return 0, 0, err
}
if len(res.Items) > 0 {
location := strings.Split(res.Items[0].Location, ",")
lng, err := strconv.ParseFloat(location[0], 64)
if err != nil {
return 0, 0, err
}
lat, err := strconv.ParseFloat(location[1], 64)
if err != nil {
return 0, 0, err
}
return lng, lat, err
}
return 0, 0, fmt.Errorf("未能取到经纬度信息")
}
2023-01-06 10:09:23 +08:00
func (rp *repo) EditProject(ctx context.Context, req proto.ProjectItemRequest) (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.Project)
h, err = rp.engine.ID(req.ProjectId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的项目")
goto ReturnPoint
}
item.Modifier = req.Creator
if len(req.ProjectName) > 0 {
item.ProjectName = req.ProjectName
}
if req.OwnerId > 0 {
item.OwnerId = req.OwnerId
}
2023-06-17 09:38:26 +08:00
if req.BizType > 0 {
item.BizType = req.BizType
}
2023-01-06 10:09:23 +08:00
if len(req.LineName) > 0 {
item.LineName = req.LineName
}
if len(req.StartName) > 0 {
item.StartName = req.StartName
2023-01-13 11:26:39 +08:00
slng, slat, err := rp.GetLngLat(ctx, fmt.Sprintf("%s+%s", req.LineName, req.StartName))
if err != nil {
goto ReturnPoint
}
item.StartPointLng = slng
item.StartPointLat = slat
2023-01-06 10:09:23 +08:00
}
if len(req.EndName) > 0 {
item.EndName = req.EndName
2023-01-13 11:26:39 +08:00
elng, elat, err := rp.GetLngLat(ctx, fmt.Sprintf("%s+%s", req.LineName, req.EndName))
if err != nil {
goto ReturnPoint
}
item.EndPointLng = elng
item.EndPointLat = elat
2023-01-06 10:09:23 +08:00
}
if req.FixedDeviceNum > 0 {
item.FixedDeviceNum = req.FixedDeviceNum
}
if len(req.Direction) > 0 {
item.Direction = req.Direction
}
if req.LaneNum > 0 {
item.LaneNum = req.LaneNum
}
2023-06-17 09:38:26 +08:00
if req.SideType > 0 && item.SideType != req.SideType {
item.SideType = req.SideType
}
2023-01-06 10:09:23 +08:00
_, err = rp.engine.ID(req.ProjectId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelProject(ctx context.Context, req proto.ProjectItemRequest) (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.Project)
h, err = rp.engine.ID(req.ProjectId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的项目")
goto ReturnPoint
}
item.Modifier = req.Creator
item.Status = 0
_, err = rp.engine.ID(req.ProjectId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-06-17 09:38:26 +08:00
func (rp *repo) GetProjectResult(ctx context.Context, req proto.ProjectRequest) (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
count int64
)
project := new(model.Project)
h, err = rp.engine.ID(req.ProjectId).Get(project)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未找到对应的项目")
goto ReturnPoint
}
if project.BizType == 4 {
if project.SideType == 1 {
list := make([]model.MultiLevelPlatform, 0)
count, err = rp.engine.Where("project_id=?", req.ProjectId).
And("(? = 0 or multi_level_platform_type=?)", req.SideType, req.SideType).
Asc("created_at").
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&list)
if err != nil {
goto ReturnPoint
}
rsp = FillPaging(count, req.Page, req.Size, list, rsp)
} else {
list := make([]model.Gnss, 0)
count, err = rp.engine.Where("project_id=?", req.ProjectId).
And("(? = 0 or gnss_type=?)", req.SideType, req.SideType).
Asc("created_at").
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&list)
if err != nil {
goto ReturnPoint
}
rsp = FillPaging(count, req.Page, req.Size, list, rsp)
}
} else {
list := make([]model.ProjectResult, 0)
count, err = rp.engine.Where("project_id=?", req.ProjectId).Asc("source_result_id").
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&list)
if err != nil {
goto ReturnPoint
}
rsp = FillPaging(count, req.Page, req.Size, list, rsp)
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-07-10 15:28:20 +08:00
func (rp *repo) GetProjectData(ctx context.Context, req proto.ProjectDataRequest) (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 (
count int64
)
srcList := make([]model.FileManager, 0)
dataset := make([]int64, 0)
err = rp.engine.SQL("select dataset_id from dataset where project_id = ?", req.ProjectId).Find(&dataset)
if err != nil {
goto ReturnPoint
}
sess := rp.engine.In("dataset_id", dataset)
if len(req.KPileStart) > 0 {
sess = sess.And("milepost_number >= ?", req.KPileStart)
}
if len(req.KPileEnd) > 0 {
sess = sess.And("milepost_number <= ?", req.KPileEnd)
}
if req.FileType > 0 {
sess = sess.And("file_type = ?", req.FileType)
}
count, err = sess.Limit(int(req.Size), int(((req.Page)-1)*req.Size)).Asc("create_at").
FindAndCount(&srcList)
if err != nil {
goto ReturnPoint
}
list := make([]proto.ProjectSrcFile, len(srcList))
for k, v := range srcList {
upDown := "上行"
if v.UpDown == 1 {
upDown = "下行"
}
list[k] = proto.ProjectSrcFile{
FileId: v.FileId,
FileName: v.FileName,
FileType: v.FileType,
MilepostNumber: v.MilepostNumber,
AccessUrl: v.AccessUrl,
UpDown: upDown,
LineNum: v.LineNum,
Longitude: v.Longitude,
Latitude: v.Latitude,
CreateAt: v.CreateAt,
UpdateAt: v.UpdateAt,
}
}
2023-06-17 09:38:26 +08:00
2023-07-10 15:28:20 +08:00
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, list, rsp)
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
}
2023-01-06 10:09:23 +08:00
func (rp *repo) ProductList(ctx context.Context, req proto.ProductRequest) (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:
data := make([]model.MatterModel, 0)
count, err := rp.engine.Where("(? = 0 or category_id = ?) ", req.CategoryId, req.CategoryId).
And("(? = '' or matter_name like ?)", req.ProductName, "%"+req.ProductName+"%").
And("(? = 0 or protocol = ?)", req.Protocol, req.Protocol).
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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
}
2023-01-10 10:01:42 +08:00
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
}
2023-01-06 10:09:23 +08:00
func (rp *repo) AddProduct(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:
item := &model.MatterModel{
MatterName: req.MatterName,
CategoryId: req.CategoryId,
Protocol: req.Protocol,
2023-01-10 10:01:42 +08:00
Connection: req.Connection,
ModelDesc: req.ModelDesc,
2023-01-06 10:09:23 +08:00
UserVersion: 1,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditProduct(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
}
if len(req.MatterName) > 0 {
item.MatterName = req.MatterName
}
if req.CategoryId > 0 {
item.CategoryId = req.CategoryId
}
if req.Protocol > 0 {
item.Protocol = req.Protocol
}
2023-01-10 10:01:42 +08:00
if req.Connection > 0 {
item.Connection = req.Connection
}
if len(req.ModelDesc) > 0 {
item.ModelDesc = req.ModelDesc
}
2023-01-06 10:09:23 +08:00
if req.UserVersion > 0 {
item.UserVersion = req.UserVersion
}
_, err = rp.engine.ID(req.MatterId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelProduct(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
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.MatterId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) CategoryList(ctx context.Context, req proto.ProductCategoryRequest) (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:
data := make([]model.MatterCategory, 0)
count, err := rp.engine.Where("(? = '' or category_name like ?) ", req.CategoryName, req.CategoryName).
2023-01-13 11:26:39 +08:00
And("status = 1").
2023-01-06 10:09:23 +08:00
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (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:
item := &model.MatterCategory{
CategoryName: req.CategoryName,
CategoryDesc: req.CategoryDesc,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (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.MatterCategory)
h, err = rp.engine.ID(req.CategoryId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的类目")
goto ReturnPoint
}
if len(req.CategoryName) > 0 {
item.CategoryName = req.CategoryName
}
if len(req.CategoryDesc) > 0 {
item.CategoryDesc = req.CategoryDesc
}
_, err = rp.engine.ID(req.CategoryId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelCategory(ctx context.Context, req proto.ProductCategoryItemRequest) (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.MatterCategory)
h, err = rp.engine.ID(req.CategoryId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的类目")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.CategoryId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) AttributeList(ctx context.Context, req proto.AttributeRequest) (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:
data := make([]model.MatterAttribute, 0)
count, err := rp.engine.Where("matter_id = ? ", req.MatterId).
And("version_id = ?", req.VersionId).
2023-01-10 10:01:42 +08:00
And(" status = 1").
2023-01-06 10:09:23 +08:00
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddAttribute(ctx context.Context, req proto.AttributeItemRequest) (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:
item := &model.MatterAttribute{
MatterId: req.MatterId,
VersionId: req.VersionId,
AttributeName: req.AttributeName,
AttributeKey: req.AttributeKey,
AttributeDesc: req.AttributeDesc,
DataType: req.DataType,
MaxValue: req.MaxValue,
MinValue: req.MinValue,
StepValue: req.StepValue,
Unit: req.Unit,
IsOnlyRead: req.IsOnlyRead,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditAttribute(ctx context.Context, req proto.AttributeItemRequest) (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.MatterAttribute)
h, err = rp.engine.ID(req.AttributeId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的属性")
goto ReturnPoint
}
if req.MatterId > 0 {
item.MatterId = req.MatterId
}
if req.VersionId > 0 {
item.VersionId = req.VersionId
}
if len(req.AttributeName) > 0 {
item.AttributeName = req.AttributeName
}
if len(req.AttributeKey) > 0 {
item.AttributeKey = req.AttributeKey
}
if len(req.AttributeDesc) > 0 {
item.AttributeDesc = req.AttributeDesc
}
if req.DataType > 0 {
item.DataType = req.DataType
}
if len(req.MaxValue) > 0 {
item.MaxValue = req.MaxValue
}
if len(req.MinValue) > 0 {
item.MinValue = req.MinValue
}
if len(req.StepValue) > 0 {
item.StepValue = req.StepValue
}
if len(req.Unit) > 0 {
item.Unit = req.Unit
}
if req.IsOnlyRead > 0 {
item.IsOnlyRead = req.IsOnlyRead
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.AttributeId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelAttribute(ctx context.Context, req proto.AttributeItemRequest) (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.MatterAttribute)
2023-01-10 10:01:42 +08:00
h, err = rp.engine.ID(req.AttributeId).Get(item)
2023-01-06 10:09:23 +08:00
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的属性")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
2023-01-10 10:01:42 +08:00
_, err = rp.engine.ID(req.AttributeId).AllCols().Update(item)
2023-01-06 10:09:23 +08:00
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EventList(ctx context.Context, req proto.AttributeRequest) (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:
data := make([]model.MatterEvent, 0)
count, err := rp.engine.Where("matter_id = ? ", req.MatterId).
And("version_id = ?", req.VersionId).
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddEvent(ctx context.Context, req proto.EventItemRequest) (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:
item := &model.MatterEvent{
MatterId: req.MatterId,
VersionId: req.VersionId,
EventIdentifier: req.EventIdentifier,
EventType: req.EventType,
EventDesc: req.EventDesc,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditEvent(ctx context.Context, req proto.EventItemRequest) (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.MatterEvent)
h, err = rp.engine.ID(req.EventId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的事件")
goto ReturnPoint
}
if req.MatterId > 0 {
item.MatterId = req.MatterId
}
if req.VersionId > 0 {
item.VersionId = req.VersionId
}
if len(req.EventIdentifier) > 0 {
item.EventIdentifier = req.EventIdentifier
}
if len(req.EventType) > 0 {
item.EventType = req.EventType
}
if len(req.EventDesc) > 0 {
item.EventDesc = req.EventDesc
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.EventId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelEvent(ctx context.Context, req proto.EventItemRequest) (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.MatterEvent)
h, err = rp.engine.ID(req.EventId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的事件")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.EventId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-01-06 14:38:22 +08:00
func (rp *repo) EventParamsList(ctx context.Context, req proto.EventParamsRequest) (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:
data := make([]model.MatterEventParams, 0)
count, err := rp.engine.Where("matter_id = ? ", req.MatterId).
And("version_id = ?", req.VersionId).
And("event_id = ?", req.EventId).
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddEventParams(ctx context.Context, req proto.EventParamItem) (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:
item := &model.MatterEventParams{
MatterId: req.MatterId,
VersionId: req.VersionId,
EventId: req.EventId,
ParamName: req.ParamName,
ParamIdentifier: req.ParamIdentifier,
2023-01-10 10:01:42 +08:00
ParamDesc: req.ParamDesc,
2023-01-06 14:38:22 +08:00
DataType: req.DataType,
MaxValue: req.MaxValue,
MinValue: req.MinValue,
StepValue: req.StepValue,
Unit: req.Unit,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditEventParams(ctx context.Context, req proto.EventParamItem) (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.MatterEventParams)
h, err = rp.engine.ID(req.ParamsId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的参数")
goto ReturnPoint
}
if req.MatterId > 0 {
item.MatterId = req.MatterId
}
if req.VersionId > 0 {
item.VersionId = req.VersionId
}
if req.EventId > 0 {
item.EventId = req.EventId
}
if len(req.ParamName) > 0 {
item.ParamName = req.ParamName
}
if len(req.ParamIdentifier) > 0 {
item.ParamIdentifier = req.ParamIdentifier
}
2023-01-10 10:01:42 +08:00
if len(req.ParamDesc) > 0 {
item.ParamDesc = req.ParamDesc
}
2023-01-06 14:38:22 +08:00
if req.DataType > 0 {
item.DataType = req.DataType
}
if len(req.MaxValue) > 0 {
item.MaxValue = req.MaxValue
}
if len(req.MinValue) > 0 {
item.MinValue = req.MinValue
}
if len(req.StepValue) > 0 {
item.StepValue = req.StepValue
}
if len(req.Unit) > 0 {
item.Unit = req.Unit
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelEventParams(ctx context.Context, req proto.EventParamItem) (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.MatterEventParams)
h, err = rp.engine.ID(req.ParamsId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的参数")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-01-06 10:09:23 +08:00
func (rp *repo) ServiceList(ctx context.Context, req proto.AttributeRequest) (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:
data := make([]model.MatterService, 0)
count, err := rp.engine.Where("matter_id = ? ", req.MatterId).
And("version_id = ?", req.VersionId).
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddService(ctx context.Context, req proto.ServiceItemRequest) (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:
item := &model.MatterService{
MatterId: req.MatterId,
VersionId: req.VersionId,
ServiceName: req.ServiceName,
ServiceIdentifier: req.ServiceIdentifier,
Calling: req.Calling,
ServiceDesc: req.ServiceDesc,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditService(ctx context.Context, req proto.ServiceItemRequest) (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.MatterService)
h, err = rp.engine.ID(req.ServiceId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的服务")
goto ReturnPoint
}
if req.MatterId > 0 {
item.MatterId = req.MatterId
}
if req.VersionId > 0 {
item.VersionId = req.VersionId
}
if len(req.ServiceName) > 0 {
item.ServiceName = req.ServiceName
}
if len(req.ServiceIdentifier) > 0 {
item.ServiceIdentifier = req.ServiceIdentifier
}
if len(req.ServiceDesc) > 0 {
item.ServiceDesc = req.ServiceDesc
}
if req.Calling > 0 {
item.Calling = req.Calling
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ServiceId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelService(ctx context.Context, req proto.ServiceItemRequest) (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.MatterService)
h, err = rp.engine.ID(req.ServiceId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的服务")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ServiceId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-01-06 14:38:22 +08:00
func (rp *repo) ServiceParamsList(ctx context.Context, req proto.ServiceParamsRequest) (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:
data := make([]model.MatterServiceParams, 0)
count, err := rp.engine.Where("matter_id = ? ", req.MatterId).
And("version_id = ?", req.VersionId).
And("service_id = ?", req.ServiceId).
And("params_owner_type = ?", req.ParamsOwnerType).
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) AddServiceParams(ctx context.Context, req proto.ServiceParamItem) (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:
item := &model.MatterServiceParams{
MatterId: req.MatterId,
VersionId: req.VersionId,
ServiceId: req.ServiceId,
ParamsOwnerType: req.ParamsOwnerType,
ParamName: req.ParamName,
ParamIdentifier: req.ParamIdentifier,
2023-01-10 10:01:42 +08:00
ParamDesc: req.ParamDesc,
2023-01-06 14:38:22 +08:00
DataType: req.DataType,
MaxValue: req.MaxValue,
MinValue: req.MinValue,
StepValue: req.StepValue,
Unit: req.Unit,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditServiceParams(ctx context.Context, req proto.ServiceParamItem) (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.MatterServiceParams)
h, err = rp.engine.ID(req.ParamsId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的参数")
goto ReturnPoint
}
if req.MatterId > 0 {
item.MatterId = req.MatterId
}
if req.VersionId > 0 {
item.VersionId = req.VersionId
}
if req.ServiceId > 0 {
item.ServiceId = req.ServiceId
}
if req.ParamsOwnerType > 0 {
item.ParamsOwnerType = req.ParamsOwnerType
}
if len(req.ParamName) > 0 {
item.ParamName = req.ParamName
}
if len(req.ParamIdentifier) > 0 {
item.ParamIdentifier = req.ParamIdentifier
}
2023-01-10 10:01:42 +08:00
if len(req.ParamDesc) > 0 {
item.ParamDesc = req.ParamDesc
}
2023-01-06 14:38:22 +08:00
if req.DataType > 0 {
item.DataType = req.DataType
}
if len(req.MaxValue) > 0 {
item.MaxValue = req.MaxValue
}
if len(req.MinValue) > 0 {
item.MinValue = req.MinValue
}
if len(req.StepValue) > 0 {
item.StepValue = req.StepValue
}
if len(req.Unit) > 0 {
item.Unit = req.Unit
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DelServiceParams(ctx context.Context, req proto.ServiceParamItem) (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.MatterServiceParams)
h, err = rp.engine.ID(req.ParamsId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的参数")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.ParamsId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}
2023-01-11 18:05:29 +08:00
func (rp *repo) DeviceList(ctx context.Context, req proto.DeviceRequest) (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:
data := make([]model.Device, 0)
count, err := rp.engine.Where("(? = '' or device_name like ? or device_imei like ? or device_sn like ?)",
req.Key, "%"+req.Key+"%", "%"+req.Key+"%", "%"+req.Key+"%").
And("(? = 0 or device_type_id = ?)", req.DeviceTypeId, req.DeviceTypeId).
And("(? = 0 or butt_matter_id = ?)", req.ProductId, req.ProductId).
And("status = 1").
Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
FindAndCount(&data)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
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) DeviceInfo(ctx context.Context, req proto.DeviceItemRequest) (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.Device)
h, err = rp.engine.ID(req.DeviceId).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) AddDevice(ctx context.Context, req proto.DeviceItemRequest) (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:
item := &model.Device{
DeviceName: req.DeviceName,
DeviceBrandId: req.DeviceBrandId,
DeviceImei: req.DeviceImei,
DeviceSn: req.DeviceSn,
DeviceTypeId: req.DeviceTypeId,
ButtMatterId: req.ButtMatterId,
ButtType: req.ButtType,
ButtAddress: req.ButtAddress,
ButtPort: req.ButtPort,
Longitude: req.Longitude,
Latitude: req.Latitude,
DeviceDesc: req.DeviceDesc,
Status: 1,
CreateAt: time.Now().Unix(),
UpdateAt: time.Now().Unix(),
}
_, err = rp.engine.Insert(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) EditDevice(ctx context.Context, req proto.DeviceItemRequest) (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.Device)
h, err = rp.engine.ID(req.DeviceId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的设备")
goto ReturnPoint
}
if len(req.DeviceName) > 0 {
item.DeviceName = req.DeviceName
}
if req.DeviceBrandId > 0 {
item.DeviceBrandId = req.DeviceBrandId
}
if len(req.DeviceImei) > 0 {
item.DeviceImei = req.DeviceImei
}
if len(req.DeviceSn) > 0 {
item.DeviceSn = req.DeviceSn
}
if len(req.DeviceDesc) > 0 {
item.DeviceDesc = req.DeviceDesc
}
if req.DeviceTypeId > 0 {
item.DeviceTypeId = req.DeviceTypeId
}
if req.ButtMatterId > 0 {
item.ButtMatterId = req.ButtMatterId
}
if req.ButtType > 0 {
item.ButtType = req.ButtType
}
if len(req.ButtAddress) > 0 {
item.ButtAddress = req.ButtAddress
}
if req.ButtPort > 0 {
item.ButtPort = req.ButtPort
}
if req.Longitude > 0 {
item.Longitude = req.Longitude
}
if req.Latitude > 0 {
item.Latitude = req.Latitude
}
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.DeviceId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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) DeleteDevice(ctx context.Context, req proto.DeviceItemRequest) (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.Device)
h, err = rp.engine.ID(req.DeviceId).Get(item)
if err != nil {
goto ReturnPoint
}
if !h {
err = fmt.Errorf("未能找到对应的设备")
goto ReturnPoint
}
item.Status = 0
item.UpdateAt = time.Now().Unix()
_, err = rp.engine.ID(req.DeviceId).AllCols().Update(item)
if err != nil {
goto ReturnPoint
}
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
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
}