1311 lines
36 KiB
Go
1311 lines
36 KiB
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"go.uber.org/zap"
|
||
|
"hpds-iot-web/internal/proto"
|
||
|
"hpds-iot-web/model"
|
||
|
"net/http"
|
||
|
"time"
|
||
|
"xorm.io/xorm"
|
||
|
)
|
||
|
|
||
|
type ManageService interface {
|
||
|
OwnerList(ctx context.Context, req proto.OwnerRequest) (rsp *proto.BaseResponse, err error)
|
||
|
AddOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error)
|
||
|
EditOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error)
|
||
|
DelOwner(ctx context.Context, req proto.OwnerItemReq) (rsp *proto.BaseResponse, err error)
|
||
|
ProjectList(ctx context.Context, req proto.ProjectRequest) (rsp *proto.BaseResponse, err error)
|
||
|
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)
|
||
|
|
||
|
ProductList(ctx context.Context, req proto.ProductRequest) (rsp *proto.BaseResponse, err error)
|
||
|
AddProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error)
|
||
|
EditProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error)
|
||
|
DelProduct(ctx context.Context, req proto.ProductItemRequest) (rsp *proto.BaseResponse, err error)
|
||
|
|
||
|
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)
|
||
|
}
|
||
|
|
||
|
func NewManageService(engine *xorm.Engine, logger *zap.Logger) ManageService {
|
||
|
return &repo{
|
||
|
engine: engine,
|
||
|
logger: logger,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
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+"%").
|
||
|
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) 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,
|
||
|
Lng: req.Lng,
|
||
|
Lat: req.Lat,
|
||
|
Status: 1,
|
||
|
Creator: req.Creator,
|
||
|
}
|
||
|
_, 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) 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
|
||
|
}
|
||
|
if len(req.LineName) > 0 {
|
||
|
item.LineName = req.LineName
|
||
|
}
|
||
|
if len(req.StartName) > 0 {
|
||
|
item.StartName = req.StartName
|
||
|
}
|
||
|
if len(req.EndName) > 0 {
|
||
|
item.EndName = req.EndName
|
||
|
}
|
||
|
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
|
||
|
}
|
||
|
if req.Lng > 0 {
|
||
|
item.Lng = req.Lng
|
||
|
}
|
||
|
if req.Lat > 0 {
|
||
|
item.Lat = req.Lat
|
||
|
}
|
||
|
_, 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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
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
|
||
|
}
|
||
|
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).
|
||
|
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).
|
||
|
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)
|
||
|
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) 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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|