package service import ( "context" "fmt" "git.hpds.cc/Component/logging" "hpds-iot-web/config" "hpds-iot-web/internal/proto" "hpds-iot-web/model" "hpds-iot-web/pkg/minedata" "net/http" "strconv" "strings" "time" "xorm.io/xorm" ) type ManageService interface { OwnerList(ctx context.Context, req proto.OwnerRequest) (rsp *proto.BaseResponse, err error) OwnerInfo(ctx context.Context, ownerId int64) (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) GetLngLat(ctx context.Context, mileagePile string) (lng, lat float64, err error) ProjectInfo(ctx context.Context, req proto.ProjectItemRequest) (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) GetProductInfo(ctx context.Context, req proto.ProductItemRequest) (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) 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) 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) } func NewManageService(cfg *config.WebConfig, engine *xorm.Engine, logger *logging.Logger) ManageService { return &repo{ AppConfig: cfg, 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) 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 } 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+"%"). And("(? = 0 or owner_id = ?)", req.OwnerId, req.OwnerId). 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) 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 } 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, Creator: req.Creator, } 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 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 _, 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) 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("未能取到经纬度信息") } 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 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 } if len(req.EndName) > 0 { item.EndName = req.EndName 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 } 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 } _, 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) 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 } 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, Connection: req.Connection, ModelDesc: req.ModelDesc, 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.Connection > 0 { item.Connection = req.Connection } if len(req.ModelDesc) > 0 { item.ModelDesc = req.ModelDesc } 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). 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) 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). 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) 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.AttributeId).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.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) 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) 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, ParamDesc: req.ParamDesc, 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 } if len(req.ParamDesc) > 0 { item.ParamDesc = req.ParamDesc } 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 } 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 } 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, ParamDesc: req.ParamDesc, 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 } if len(req.ParamDesc) > 0 { item.ParamDesc = req.ParamDesc } 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 } 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 }