column_setting.go 3.2 KB
package domain

import "time"

// 默认选中栏目
var DefaultColumns = []Column{
	{
		Id:       "index",
		ParamCn:  "序号",
		ParamFix: 1,
	}, {
		Id:       "orderId",
		ParamCn:  "订单号",
		ParamFix: 1,
	}, {
		Id:       "shipmentsId",
		ParamCn:  "发货单号",
		ParamFix: 2,
	}, {
		Id:       "saleDate",
		ParamCn:  "销售日期",
		ParamFix: 2,
	}, {
		Id:       "orderNum",
		ParamCn:  "订单数量",
		ParamFix: 2,
	}, {
		Id:       "quantityControl",
		ParamCn:  "数量调整",
		ParamFix: 2,
	}, {
		Id:       "orderPrice",
		ParamCn:  "订单金额",
		ParamFix: 2,
	}, {
		Id:       "priceControl",
		ParamCn:  "金额调整",
		ParamFix: 2,
	}, {
		Id:       "orderDist",
		ParamCn:  "订单区域",
		ParamFix: 2,
	}, {
		Id:       "partnerCategory",
		ParamCn:  "合伙人类型",
		ParamFix: 2,
	}, {
		Id:       "buyer",
		ParamCn:  "客户",
		ParamFix: 2,
	}, {
		Id:       "partner",
		ParamCn:  "合伙人",
		ParamFix: 2,
	},
}

// 默认未选中栏目
var DefaultInvalidColumns = []Column{
	{
		Id:       "updateTime",
		ParamCn:  "更新时间",
		ParamFix: 2,
	}, {
		Id:       "createTime",
		ParamCn:  "创建时间",
		ParamFix: 2,
	},
}

// 栏目设置
type ColumnSetting struct {
	// 栏目设置id
	Id int64 `json:"id"`
	// 栏目设置关联用户公司id
	CompanyId int `json:"companyId"`
	// 栏目设置创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 栏目设置描述
	Description string `json:"description"`
	// 栏目设置模块名称
	Key string `json:"key"`
	// 栏目设置关联用户uid
	Uid int64 `json:"uid"`
	// 栏目设置更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 栏目设置关联用户名称
	UserName string `json:"userName"`
	// 有效栏目数组
	Value []Column `json:"value"`
	// 无效栏目数组
	InvalidValue []Column `json:"invalidValue"`
}

type ColumnSettingRepository interface {
	Save(columnSetting *ColumnSetting) (*ColumnSetting, error)
	Remove(columnSetting *ColumnSetting, columnSettings []*ColumnSetting) (*ColumnSetting, []*ColumnSetting, error)
	FindOne(queryOptions map[string]interface{}) (*ColumnSetting, error)
	Find(queryOptions map[string]interface{}) (int64, []*ColumnSetting, error)
}

func (columnSetting *ColumnSetting) Identify() interface{} {
	if columnSetting.Id == 0 {
		return nil
	}
	return columnSetting.Id
}

func (columnSetting *ColumnSetting) Update(data map[string]interface{}) error {
	if companyId, ok := data["companyId"]; ok {
		columnSetting.CompanyId = companyId.(int)
	}
	if createdAt, ok := data["createdAt"]; ok {
		columnSetting.CreatedAt = createdAt.(time.Time)
	}
	if description, ok := data["description"]; ok {
		columnSetting.Description = description.(string)
	}
	if key, ok := data["key"]; ok {
		columnSetting.Key = key.(string)
	}
	if uid, ok := data["uid"]; ok {
		columnSetting.Uid = uid.(int64)
	}
	if updatedAt, ok := data["updatedAt"]; ok {
		columnSetting.UpdatedAt = updatedAt.(time.Time)
	}
	if userName, ok := data["userName"]; ok {
		columnSetting.UserName = userName.(string)
	}
	if value, ok := data["value"]; ok {
		columnSetting.Value = value.([]Column)
	}
	if invalidValue, ok := data["invalidValue"]; ok {
		columnSetting.InvalidValue = invalidValue.([]Column)
	}
	return nil
}