查询skunames优化

This commit is contained in:
苏尹岚
2020-04-09 17:14:48 +08:00
parent 14b8ef36d5
commit be496be64a
3 changed files with 46 additions and 33 deletions

View File

@@ -72,7 +72,7 @@ func changeStoreSkusByOrder(order *weimobapi.OrderDetail) {
for _, v := range skuBindInfos {
nameIDs = append(nameIDs, v.NameID)
}
if skuNamesInfo, err := cms.GetSkuNames(ctx, "", false, map[string]interface{}{
if skuNamesInfo, err := cms.GetSkuNames(ctx, "", false, false, map[string]interface{}{
"nameIDs": string(utils.MustMarshal(nameIDs)),
}, 0, 0); err == nil {
for _, skuName := range skuNamesInfo.SkuNames {

View File

@@ -410,19 +410,22 @@ func DeleteCategoryMap(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int) (n
})
}
func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPrice bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *SkuNamesInfo, err error) {
db := dao.GetDB()
sql := `
FROM sku_name t1
LEFT JOIN sku t2 ON t1.id = t2.name_id AND t2.deleted_at = ?
LEFT JOIN sku_name_place_bind t3 ON t1.id = t3.name_id
LEFT JOIN price_refer_snapshot t4 ON t4.city_code = ? AND t4.snapshot_at = ? AND t4.name_id = t1.id
WHERE t1.deleted_at = ?`
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
0, utils.Time2Date(time.Now().AddDate(0, 0, -1)),
utils.DefaultTimeValue,
}
if isQueryMidPrice {
sql += " LEFT JOIN price_refer_snapshot t4 ON t4.city_code = ? AND t4.snapshot_at = ? AND t4.name_id = t1.id"
sqlParams = append(sqlParams, 0, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
}
sql += " WHERE t1.deleted_at = ?"
sqlParams = append(sqlParams, utils.DefaultTimeValue)
if keyword != "" {
keywordLike := "%" + keyword + "%"
sql += `
@@ -588,8 +591,12 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
t1.ex_prefix,
t1.ex_prefix_begin,
t1.ex_prefix_end,
t1.yb_name_suffix,
t4.mid_unit_price`
t1.yb_name_suffix
`
if isQueryMidPrice {
sql += `,
t4.mid_unit_pirce`
}
if isBySku {
sql += `,
t2.id`
@@ -624,7 +631,12 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
t1.ex_prefix_begin,
t1.ex_prefix_end,
t1.yb_name_suffix,
t4.mid_unit_price,
`
if isQueryMidPrice {
sqlData += " t4.mid_unit_price,"
}
sqlData +=
`
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status,
',"createdAt":"', CONCAT(REPLACE(t2.created_at," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(t2.updated_at," ","T"),"+08:00"),
'","lastOperator":"', t2.last_operator, '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit,
@@ -841,7 +853,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
}
dao.Commit(db)
tmpInfo, err := GetSkuNames(ctx, "", false, utils.Params2Map("nameID", skuNameExt.SkuName.ID), 0, 1)
tmpInfo, err := GetSkuNames(ctx, "", false, false, utils.Params2Map("nameID", skuNameExt.SkuName.ID), 0, 1)
if err != nil {
return nil, err
}
@@ -1091,7 +1103,7 @@ func AddSku(ctx *jxcontext.Context, nameID int, sku *model.Sku, userName string)
}
dao.Commit(db)
result, err2 := GetSkuNames(ctx, "", false, utils.Params2Map("skuID", sku.ID), 0, 0)
result, err2 := GetSkuNames(ctx, "", false, false, utils.Params2Map("skuID", sku.ID), 0, 0)
if err = err2; err == nil {
if result.TotalCount == 1 {
outSkuNameExt = result.SkuNames[0]
@@ -1978,7 +1990,7 @@ func writeToExcel(excelTitle []string, dataList interface{}, task *tasksch.SeqTa
if err != nil {
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err)
} else {
noticeMsg := fmt.Sprintf("[详情点我]path=%s\n", downloadURL)
noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
task.SetNoticeMsg(noticeMsg)
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess downloadURL: [%v]", downloadURL)
}

View File

@@ -153,12 +153,13 @@ func (c *SkuController) SyncCategory() {
// @Param offset query int false "门店列表起始序号以0开始缺省为0"
// @Param pageSize query int false "门店列表页大小缺省为50-1表示全部"
// @Param isBySku query bool false "是否将sku拆开缺省为false"
// @Param isQueryMidPrice query bool false "是否查询中位价缺省为false"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetSkuNames [get,post]
func (c *SkuController) GetSkuNames() {
c.callGetSkuNames(func(params *tSkuGetSkuNamesParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetSkuNames(params.Ctx, params.Keyword, params.IsBySku, params.MapData, params.Offset, params.PageSize)
retVal, err = cms.GetSkuNames(params.Ctx, params.Keyword, params.IsBySku, params.IsQueryMidPrice, params.MapData, params.Offset, params.PageSize)
return retVal, "", err
})
}