1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package series
- import (
- "context"
- "encoding/json"
- "fmt"
- "time"
- "adm-vehicle-style/errors"
- "adm-vehicle-style/model"
- v1 "adm-vehicle-style/pb/v1"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- )
- func Update(ctx context.Context, req *v1.UpdateSeriesRequest) (reply *v1.EmptyReply, err error) {
- reply = &v1.EmptyReply{}
- // 捕获各个task中的异常并返回给调用者
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- if req.Id <= 0 || req.SeriesName == "" || req.Maker == "" {
- return reply, errors.ParamsError
- }
- values := map[string]interface{}{
- "series_name": req.SeriesName,
- "maker": req.Maker,
- "status": req.Status,
- "update_time": time.Now().Format("200601"),
- "old_series_name":req.OldSeriesName,
- }
- if req.HasImg == 1 {
- values["has_img"] = 1
- }
- tx := database.DB().Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- return
- }
- tx.Commit()
- }()
- if err = model.NewSySerieModel().Update(tx.Where("id = ?", req.Id), values); err != nil {
- return reply, errors.SystemError
- }
- res, err := model.NewSySerieModel().Get(database.DB().Where("id = ?", req.Id))
- if err != nil {
- return reply, errors.SystemError
- }
- if err = model.NewSyStyleModel().Update(tx.Where("series_id = ?", res.SeriesId), map[string]interface{}{
- "is_on": req.Status,
- "series_name": req.SeriesName,
- }); err != nil {
- return reply, errors.SystemError
- }
- return reply, nil
- }
|