- move some funcs from jxtools to dao.

This commit is contained in:
gazebo
2018-09-11 11:38:31 +08:00
parent 45ce7352fc
commit 70bf5a522a
8 changed files with 130 additions and 48 deletions

View File

@@ -4,10 +4,8 @@ import (
"errors"
"strconv"
"strings"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
@@ -57,11 +55,7 @@ func UpdatePlaces(places []map[string]interface{}, userName string) (num int64,
return 0, ErrMissingInput
}
placeid := &model.Place{}
globals.SugarLogger.Debug(utils.Format4Output(place, false))
valid, _ := jxutils.FilterMapByFieldList(place, []string{"jdCode", "enabled", "mtpsPrice"})
valid["updatedAt"] = time.Now()
valid["lastOperator"] = userName
globals.SugarLogger.Debug(valid)
valid := dao.NormalMakeMapByFieldList(place, []string{"jdCode", "enabled", "mtpsPrice"}, userName)
if num, err = dao.UpdateEntityByKV(nil, placeid, valid, utils.Params2Map("Code", place["code"])); err != nil {
return num, err
}
@@ -74,6 +68,7 @@ func UpdatePlace(placeCode int, payload map[string]interface{}, userName string)
return UpdatePlaces([]map[string]interface{}{payload}, userName)
}
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
sql := `
FROM store t1
@@ -205,7 +200,7 @@ func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err e
func UpdateStore(storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
store := &model.Store{}
store.ID = storeID
valid := jxutils.NormalMakeMapByStructObject(payload, store, userName)
valid := dao.NormalMakeMapByStructObject(payload, store, userName)
db := dao.GetDB()
if num, err = dao.UpdateEntityByKV(db, store, valid, nil); err == nil {
dummy := &model.StoreMap{}
@@ -220,10 +215,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
}
func CreateStore(store *model.Store, userName string) (id int, err error) {
store.ID = 0
store.LastOperator = userName
store.CreatedAt = time.Now()
store.UpdatedAt = store.CreatedAt
dao.WrapAddIDCULEntity(store, userName)
if err = dao.CreateEntity(nil, store); err == nil {
return store.ID, nil
}
@@ -243,6 +235,7 @@ func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*
func AddStoreVendorMap(db *dao.DaoDB, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
store, err := GetPurchaseHandler(storeMap.VendorID).ReadStore(storeMap.VendorStoreID)
if err == nil {
dao.WrapAddIDCULEntity(storeMap, userName)
storeMap.DeliveryType = store.DeliveryType
storeMap.Status = store.Status
storeMap.SyncStatus = model.SyncFlagModifiedMask
@@ -271,8 +264,8 @@ func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[stri
}
if err == nil {
dummyStoreMap := &model.StoreMap{}
valid := jxutils.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
if valid["status"] != nil {
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
if valid["status"] != nil { // 对于store vendor map只有Status改变才需要同步到厂商
valid[model.FieldSyncStatus] = model.SyncFlagModifiedMask
}
globals.SugarLogger.Debug(utils.Format4Output(valid, false))