From 3aec482720066735b5fa187347c43528d460bed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 17 Jan 2020 16:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=A2=9E=E5=8A=A0=E9=97=A8=E5=BA=97=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 12 ++++++++---- business/jxstore/event/event.go | 10 +++++++--- business/jxstore/misc/misc.go | 4 ++-- business/model/dao/event.go | 14 +++++++------- business/model/event.go | 1 + business/model/store_sku.go | 4 ++-- controllers/event.go | 11 ++++++----- 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index cd75a29b4..923f48859 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -1084,9 +1084,11 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs // updateFieldMap["Price"] = 1 } if tmpStatus := getSkuSaleStatus(inSkuBind, skuBindInfo); tmpStatus != model.StoreSkuBindStatusNA { + if tmpStatus != skuBind.Status { + updateFieldMap[model.FieldStatus] = 1 + } skuBind.Status = tmpStatus setStoreSkuBindStatus(skuBind, model.SyncFlagSaleMask) - updateFieldMap[model.FieldStatus] = 1 } if skuBindInfo.UnitPrice != 0 && isCanChangePrice { // 这里是否需要加此条件限制 price := jxutils.CaculateSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit, v.SkuNameUnit) @@ -1107,8 +1109,10 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs if err := ValidateStruct(skuBindInfo); err != nil { globals.SugarLogger.Infof("更改商品:%s, 可售时间不合法!时间范围:[%v] 至 [%v]", allBinds[0].Name, skuBindInfo.StatusSaleBegin, skuBindInfo.StatusSaleEnd) } else { - updateFieldMap["StatusSaleBegin"] = int(skuBindInfo.StatusSaleBegin) - updateFieldMap["StatusSaleEnd"] = int(skuBindInfo.StatusSaleEnd) + if skuBind.StatusSaleBegin != skuBindInfo.StatusSaleBegin || skuBind.StatusSaleEnd != skuBindInfo.StatusSaleEnd { + updateFieldMap["StatusSaleBegin"] = 1 + updateFieldMap["StatusSaleEnd"] = 1 + } skuBind.StatusSaleBegin = skuBindInfo.StatusSaleBegin skuBind.StatusSaleEnd = skuBindInfo.StatusSaleEnd } @@ -1180,7 +1184,7 @@ func AddEventDetail(db *dao.DaoDB, ctx *jxcontext.Context, operateType, thingID, ThingID: thingID, ThingType: thingType, StoreID: storeID, - AccessUUID: ctx.GetTrackInfo(), + AccessUUID: ctx.GetTrackInfo()[0:strings.Index(ctx.GetTrackInfo(), ",")], BeforeData: beforeData, AfterData: afterData, } diff --git a/business/jxstore/event/event.go b/business/jxstore/event/event.go index 81e9277fc..e01a2a1ef 100644 --- a/business/jxstore/event/event.go +++ b/business/jxstore/event/event.go @@ -29,7 +29,7 @@ type CheckCookie struct { Status string `json:"status"` } -func AddOperateEvent(ctx *jxcontext.Context, accessUUID string) (err error) { +func AddOperateEvent(ctx *jxcontext.Context, accessUUID, jsonData string) (err error) { var ( apiFunction string db = dao.GetDB() @@ -43,12 +43,16 @@ func AddOperateEvent(ctx *jxcontext.Context, accessUUID string) (err error) { return err } } + if accessUUID != "" { + accessUUID = accessUUID[0:strings.Index(accessUUID, ",")] + } event := &model.OperateEvent{ CreatedAt: time.Now(), LastOperator: ctx.GetUserName(), APIFunction: apiFunction, UserID: ctx.GetUserID(), AccessUUID: accessUUID, + JsonData: jsonData, } dao.Begin(db) defer func() { @@ -90,7 +94,7 @@ func DeleteOperateEventAndDetail(ctx *jxcontext.Context, deleteTime time.Time) ( return err } -func GetOperateEvents(ctx *jxcontext.Context, apiFunction, name string, operateType int, skuIDs, storeIDs []int, fromTime, toTime string, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { +func GetOperateEvents(ctx *jxcontext.Context, name string, apiFunctions []string, operateTypes, skuIDs, storeIDs []int, fromTime, toTime string, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { var ( fromTimeP time.Time toTimeP time.Time @@ -104,7 +108,7 @@ func GetOperateEvents(ctx *jxcontext.Context, apiFunction, name string, operateT } pageSize = jxutils.FormalizePageSize(pageSize) offset = jxutils.FormalizePageOffset(offset) - operateEventExt, totalCount, err := dao.GetOperateEvents(db, apiFunction, name, operateType, skuIDs, storeIDs, fromTimeP, toTimeP, offset, pageSize) + operateEventExt, totalCount, err := dao.GetOperateEvents(db, name, apiFunctions, operateTypes, skuIDs, storeIDs, fromTimeP, toTimeP, offset, pageSize) if err != nil { return pageInfo, err } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 72af30326..0e9dde7aa 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -44,7 +44,7 @@ var ( "08:00:00", "18:00:00", } - createStorePriceTimeList = []string{ + createStorePriceTimeList = []string{ "02:00:00", } refreshPageActTimeList = []string{ @@ -156,7 +156,7 @@ func Init() { cms.AutoFocusStoreSkusForTopSkus(jxcontext.AdminCtx, true, true) }, createStorePriceTimeList) ScheduleTimerFunc("GetCheckVendorCookie", func() { - event.GetCheckVendorCookie(jxcontext.AdminCtx, []int{0, 1, 3}, true) + event.GetCheckVendorCookie(jxcontext.AdminCtx, []int{0, 1, 3, 102}, true) }, checkCookieList) } ScheduleTimerFunc("AutoSaleStoreSku", func() { diff --git a/business/model/dao/event.go b/business/model/dao/event.go index 4b7c4bad1..759388fe9 100644 --- a/business/model/dao/event.go +++ b/business/model/dao/event.go @@ -40,7 +40,7 @@ func DeleteOperateEvent(db *DaoDB, deleteTime time.Time) (err error) { return err } -func GetOperateEvents(db *DaoDB, apiFunction, name string, operateType int, skuIDs, storeIDs []int, fromTime, toTime time.Time, offset, pageSize int) (operateEventExt []*OperateEventExt, totalCount int, err error) { +func GetOperateEvents(db *DaoDB, name string, apiFunctions []string, operateTypes, skuIDs, storeIDs []int, fromTime, toTime time.Time, offset, pageSize int) (operateEventExt []*OperateEventExt, totalCount int, err error) { sql := ` SELECT SQL_CALC_FOUND_ROWS DISTINCT a.*, c.name FROM operate_event a @@ -61,13 +61,13 @@ func GetOperateEvents(db *DaoDB, apiFunction, name string, operateType int, skuI sql += " AND a.created_at <= ?" sqlParams = append(sqlParams, toTime) } - if apiFunction != "" { - sql += " AND a.api_function = ?" - sqlParams = append(sqlParams, apiFunction) + if len(apiFunctions) > 0 { + sql += " AND a.api_function IN (" + GenQuestionMarks(len(apiFunctions)) + ")" + sqlParams = append(sqlParams, apiFunctions) } - if operateType != 0 { - sql += " AND b.operate_type = ?" - sqlParams = append(sqlParams, operateType) + if len(operateTypes) > 0 { + sql += " AND b.operate_type IN (" + GenQuestionMarks(len(operateTypes)) + ")" + sqlParams = append(sqlParams, operateTypes) } if len(skuIDs) > 0 { sql += " AND b.thing_id IN (" + GenQuestionMarks(len(skuIDs)) + ")" diff --git a/business/model/event.go b/business/model/event.go index 647203e32..756c639fe 100644 --- a/business/model/event.go +++ b/business/model/event.go @@ -9,6 +9,7 @@ type OperateEvent struct { AccessUUID string `orm:"column(access_uuid)" json:"accessUUID"` UserID string `orm:"column(user_id)" json:"userID"` APIFunction string `orm:"column(api_function)" json:"apiFunction"` + JsonData string `orm:"size(3200)" json:"jsonData"` } func (v *OperateEvent) TableIndex() [][]string { diff --git a/business/model/store_sku.go b/business/model/store_sku.go index 49aebbbc6..25895a27a 100644 --- a/business/model/store_sku.go +++ b/business/model/store_sku.go @@ -117,8 +117,8 @@ type StoreSkuBind struct { AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"` - StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围 - StatusSaleEnd int16 `json:"statusSaleEnd"` + StatusSaleBegin int16 //商品可售时间范围 + StatusSaleEnd int16 } func (*StoreSkuBind) TableUnique() [][]string { diff --git a/controllers/event.go b/controllers/event.go index 87338f611..e28eee701 100644 --- a/controllers/event.go +++ b/controllers/event.go @@ -14,9 +14,9 @@ type EventController struct { // @Title 查询操作日志事件明细 // @Description 查询操作日志事件明细 // @Param token header string true "认证token" -// @Param apiFunction query string false "功能名" +// @Param apiFunctions query string false "功能名列表" // @Param name query string false "操作人姓名,支持模糊查询" -// @Param operateType query int false "操作类型,1为修改,2为新增,4为删除" +// @Param operateTypes query string false "操作类型列表,1为修改,2为新增,4为删除" // @Param skuIDs query string false "商品ID列表" // @Param storeIDs query string false "门店ID列表" // @Param fromTime query string false "开始日期(包含),格式(2006-01-02 00:00:00)" @@ -27,10 +27,11 @@ type EventController struct { // @Failure 200 {object} controllers.CallResult // @router /GetOperateEvents [get] func (c *EventController) GetOperateEvents() { - var storeIDList, skuIDList []int + var storeIDList, skuIDList, operateTypeList []int + var apiFunctionList []string c.callGetOperateEvents(func(params *tEventGetOperateEventsParams) (retVal interface{}, errCode string, err error) { - if jxutils.Strings2Objs(params.StoreIDs, &storeIDList, params.SkuIDs, &skuIDList); err == nil { - retVal, err = event.GetOperateEvents(params.Ctx, params.ApiFunction, params.Name, params.OperateType, skuIDList, storeIDList, params.FromTime, params.ToTime, params.Offset, params.PageSize) + if jxutils.Strings2Objs(params.StoreIDs, &storeIDList, params.SkuIDs, &skuIDList, params.ApiFunctions, &apiFunctionList, params.OperateTypes, &operateTypeList); err == nil { + retVal, err = event.GetOperateEvents(params.Ctx, params.Name, apiFunctionList, operateTypeList, skuIDList, storeIDList, params.FromTime, params.ToTime, params.Offset, params.PageSize) } return retVal, "", err })