- 改UpdtePlace的调用参数
This commit is contained in:
@@ -20,7 +20,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
serviceInfo map[string]interface{}
|
serviceInfo map[string]interface{}
|
||||||
|
allowUpdatePlaceFieldsMap = map[string]bool{
|
||||||
|
"name": true,
|
||||||
|
"enabled": true,
|
||||||
|
"mtpsPrice": true,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||||
@@ -126,12 +131,18 @@ func UpdatePlaces(ctx *jxcontext.Context, places []map[string]interface{}, userN
|
|||||||
if len(places) == 0 {
|
if len(places) == 0 {
|
||||||
return 0, ErrMissingInput
|
return 0, ErrMissingInput
|
||||||
}
|
}
|
||||||
|
updateFields := []string{}
|
||||||
|
for k := range places[0] {
|
||||||
|
if allowUpdatePlaceFieldsMap[k] {
|
||||||
|
updateFields = append(updateFields, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, place := range places {
|
for _, place := range places {
|
||||||
if place["code"] == nil {
|
if place["code"] == nil {
|
||||||
return 0, ErrMissingInput
|
return 0, ErrMissingInput
|
||||||
}
|
}
|
||||||
placeid := &model.Place{}
|
placeid := &model.Place{}
|
||||||
valid := dao.NormalMakeMapByFieldList(place, []string{"jdCode", "enabled", "mtpsPrice"}, userName)
|
valid := dao.NormalMakeMapByFieldList(place, updateFields, userName)
|
||||||
if num, err = dao.UpdateEntityLogically(nil, placeid, valid, userName, utils.Params2Map("Code", place["code"])); err != nil {
|
if num, err = dao.UpdateEntityLogically(nil, placeid, valid, userName, utils.Params2Map("Code", place["code"])); err != nil {
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}) (num int64, err error) {
|
func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}) (num int64, err error) {
|
||||||
if conditions != nil {
|
if conditions != nil && refutil.IsFieldExist(item, model.FieldDeletedAt) {
|
||||||
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
||||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||||
})
|
})
|
||||||
@@ -71,7 +71,7 @@ func UpdateEntityLogically(db *DaoDB, item interface{}, kvs map[string]interface
|
|||||||
|
|
||||||
// 此函数会更新同步标志
|
// 此函数会更新同步标志
|
||||||
func UpdateEntityLogicallyAndUpdateSyncStatus(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}, syncStatusFieldName string, valueMask int) (num int64, err error) {
|
func UpdateEntityLogicallyAndUpdateSyncStatus(db *DaoDB, item interface{}, kvs map[string]interface{}, userName string, conditions map[string]interface{}, syncStatusFieldName string, valueMask int) (num int64, err error) {
|
||||||
if conditions != nil {
|
if conditions != nil && refutil.IsFieldExist(item, model.FieldDeletedAt) {
|
||||||
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
conditions = utils.MergeMaps(conditions, map[string]interface{}{
|
||||||
model.FieldDeletedAt: utils.DefaultTimeValue,
|
model.FieldDeletedAt: utils.DefaultTimeValue,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -52,17 +52,26 @@ func (c *CmsController) UpdatePlaces() {
|
|||||||
// @Title 修改地点信息
|
// @Title 修改地点信息
|
||||||
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
|
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param code formData int true "地点编号,注意是code不是ID,payload中的code会被忽略"
|
// @Param code formData int true "地点编号,注意是code不是ID"
|
||||||
// @Param payload formData string true "json数据,place对象"
|
// @Param enabled formData bool true "是否启用"
|
||||||
|
// @Param name formData string false "地点名"
|
||||||
|
// @Param mtpsPrice formData int false "美团配送基础价格"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /UpdatePlace [put]
|
// @router /UpdatePlace [put]
|
||||||
func (c *CmsController) UpdatePlace() {
|
func (c *CmsController) UpdatePlace() {
|
||||||
c.callUpdatePlace(func(params *tCmsUpdatePlaceParams) (retVal interface{}, errCode string, err error) {
|
c.callUpdatePlace(func(params *tCmsUpdatePlaceParams) (retVal interface{}, errCode string, err error) {
|
||||||
place := make(map[string]interface{}, 0)
|
payload := map[string]interface{}{
|
||||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &place); err == nil {
|
"code": params.Code,
|
||||||
retVal, err = cms.UpdatePlace(params.Ctx, params.Code, place, params.Ctx.GetUserName())
|
"enabled": params.Enabled,
|
||||||
}
|
}
|
||||||
|
if params.Name != "" {
|
||||||
|
payload["name"] = params.Name
|
||||||
|
}
|
||||||
|
if params.MtpsPrice > 0 {
|
||||||
|
payload["mtpsPrice"] = params.MtpsPrice
|
||||||
|
}
|
||||||
|
retVal, err = cms.UpdatePlaces(params.Ctx, []map[string]interface{}{payload}, params.Ctx.GetUserName())
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
|||||||
return &value
|
return &value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsFieldExist(obj interface{}, fieldName string) bool {
|
||||||
|
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).IsValid()
|
||||||
|
}
|
||||||
|
|
||||||
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
||||||
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user