作者 陈志颖

feat:增加栏目设置

... ... @@ -13,9 +13,9 @@ type CreateColumnSettingCommand struct {
// 用户uid
Uid int64 `json:"uid"`
// 栏目设置描述
Description string `json:"description" valid:"Required"`
Description string `json:"description"`
// 栏目设置关联用户名称
UserName string `json:"userName" valid:"Required"`
UserName string `json:"userName"`
// 默认栏目设置
Value []domain.Column `json:"value"`
// 无效栏目设置爱
... ... @@ -24,9 +24,9 @@ type CreateColumnSettingCommand struct {
Key string `json:"key"`
}
func (createColumnSettingCommand *CreateColumnSettingCommand) Valid(validation *validation.Validation) {
_ = validation.SetError("CustomValid", "未实现的自定义认证")
}
//func (createColumnSettingCommand *CreateColumnSettingCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (createColumnSettingCommand *CreateColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
... ...
... ... @@ -8,16 +8,16 @@ import (
type RemoveColumnSettingCommand struct {
// 栏目设置id
ColumnSettingId int64 `json:"columnSettingId" valid:"Required"`
ColumnSettingId int64 `json:"columnSettingId"`
// 用户uid
Uid int64 `json:"uid"`
// 公司id
CompanyId int `json:"companyId"`
}
func (removeColumnSettingCommand *RemoveColumnSettingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
//func (removeColumnSettingCommand *RemoveColumnSettingCommand) Valid(validation *validation.Validation) {
// validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (removeColumnSettingCommand *RemoveColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
... ...
... ... @@ -18,9 +18,9 @@ type ResetColumnCommand struct {
InvalidValue []domain.Column `json:"invalidValue"`
}
func (resetColumnCommand *ResetColumnCommand) Valid(validation *validation.Validation) {
_ = validation.SetError("CustomValid", "未实现的自定义认证")
}
//func (resetColumnCommand *ResetColumnCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (resetColumnCommand *ResetColumnCommand) ValidateCommand() error {
valid := validation.Validation{}
... ...
... ... @@ -22,12 +22,21 @@ type UpdateColumnSettingCommand struct {
Value []domain.Column `json:"value"`
// 无效栏目设置
InvalidValue []domain.Column `json:"invalidValue"`
// 栏目
OrderBaseColumns OrderBaseColumns `json:"orderBaseColumns"`
}
func (updateColumnSettingCommand *UpdateColumnSettingCommand) Valid(validation *validation.Validation) {
_ = validation.SetError("CustomValid", "未实现的自定义认证")
type OrderBaseColumns struct {
// 选中的栏目
Selected []domain.Column `json:"selected"`
// 未选中的栏目
UnSelected []domain.Column `json:"unselected"`
}
//func (updateColumnSettingCommand *UpdateColumnSettingCommand) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (updateColumnSettingCommand *UpdateColumnSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateColumnSettingCommand)
... ...
... ... @@ -15,9 +15,9 @@ type GetColumnSettingQuery struct {
Uid int64 `json:"uid"`
}
func (getColumnSettingQuery *GetColumnSettingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
//func (getColumnSettingQuery *GetColumnSettingQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (getColumnSettingQuery *GetColumnSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
... ...
... ... @@ -13,9 +13,9 @@ type ListColumnSettingQuery struct {
Limit int `json:"limit" valid:"Required"`
}
func (listColumnSettingQuery *ListColumnSettingQuery) Valid(validation *validation.Validation) {
_ = validation.SetError("CustomValid", "未实现的自定义认证")
}
//func (listColumnSettingQuery *ListColumnSettingQuery) Valid(validation *validation.Validation) {
// _ = validation.SetError("CustomValid", "未实现的自定义认证")
//}
func (listColumnSettingQuery *ListColumnSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
... ...
package factory
import (
"github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/repository"
... ... @@ -107,9 +106,9 @@ func CreateOrderLogRepository(options map[string]interface{}) (domain.OrderLogRe
}
func CreateColumnSettingRepository(options map[string]interface{}) (domain.ColumnSettingRepository, error) {
var transactionContext *pg.TransactionContext
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewColumnSettingRepository(transactionContext)
}
... ...
... ... @@ -5,37 +5,61 @@ import (
"github.com/go-pg/pg"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type ColumnSettingRepository struct {
transactionContext *pgTransaction.TransactionContext
transactionContext *transaction.TransactionContext
}
func (repository *ColumnSettingRepository) nextIdentify() (int64, error) {
return 0, nil
}
//func (repository *ColumnSettingRepository) nextIdentify() (int64, error) {
// return 0, nil
//}
func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSetting) (*domain.ColumnSetting, error) {
tx := repository.transactionContext.PgTx
columnSettingModel := &models.ColumnSetting{
Id: columnSetting.Id,
CompanyId: columnSetting.CompanyId,
CreatedAt: columnSetting.CreatedAt,
Description: columnSetting.Description,
Key: columnSetting.Key,
Uid: columnSetting.Uid,
UpdatedAt: columnSetting.UpdatedAt,
UserName: columnSetting.UserName,
Value: columnSetting.Value,
InvalidValue: columnSetting.InvalidValue,
}
if columnSetting.Identify() == nil {
_, err := repository.nextIdentify()
_, err := tx.Model(columnSettingModel).Insert()
if err != nil {
return columnSetting, err
}
if _, errInsert := tx.QueryOne(
pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
"INSERT INTO column_settings (column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
columnSetting.Id, columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {
return columnSetting, errInsert
return nil, err
}
return nil, err
//_, err := repository.nextIdentify()
//if err != nil {
// return columnSetting, err
//}
//if _, errInsert := tx.QueryOne(
// pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
// "INSERT INTO column_settings (company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
// columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue)); errInsert != nil {
// return columnSetting, errInsert
//}
} else {
if _, errUpdate := tx.QueryOne(
pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
"UPDATE column_settings SET column_setting_id=?, company_id=?, created_at=?, description=?, key=?, uid=?, updated_at=?, user_name=?, value=?, invalid_value=? WHERE id=? RETURNING column_setting_id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
columnSetting.Id, columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue), columnSetting.Identify()); errUpdate != nil {
return columnSetting, errUpdate
//if _, errUpdate := tx.QueryOne(
// pg.Scan(&columnSetting.Id, &columnSetting.CompanyId, &columnSetting.CreatedAt, &columnSetting.Description, &columnSetting.Key, &columnSetting.Uid, &columnSetting.UpdatedAt, &columnSetting.UserName, pg.Array(&columnSetting.Value), pg.Array(&columnSetting.InvalidValue)),
// "UPDATE column_settings SET company_id=?, created_at=?, description=?, key=?, uid=?, updated_at=?, user_name=?, value=?, invalid_value=? WHERE id=? RETURNING id, company_id, created_at, description, key, uid, updated_at, user_name, value, invalid_value",
// columnSetting.CompanyId, columnSetting.CreatedAt, columnSetting.Description, columnSetting.Key, columnSetting.Uid, columnSetting.UpdatedAt, columnSetting.UserName, pg.Array(columnSetting.Value), pg.Array(columnSetting.InvalidValue), columnSetting.Identify()); errUpdate != nil {
// return columnSetting, errUpdate
//}
_, err := tx.Model(columnSettingModel).WherePK().
Column("company_id", "created_at", "description", "key", "uid", "updated_at", "user_name", "value", "invalid_value").Update()
if err != nil {
return nil, err
}
}
return columnSetting, nil
... ... @@ -150,7 +174,7 @@ func (repository *ColumnSettingRepository) transformPgModelToDomainModel(columnS
}, nil
}
func NewColumnSettingRepository(transactionContext *pgTransaction.TransactionContext) (*ColumnSettingRepository, error) {
func NewColumnSettingRepository(transactionContext *transaction.TransactionContext) (*ColumnSettingRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
... ...
... ... @@ -2,8 +2,11 @@ package controllers
import (
"encoding/json"
"errors"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"github.com/astaxie/beego/logs"
"github.com/linmadan/egglib-go/web/beego/utils"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/columnSetting/query"
... ... @@ -14,10 +17,30 @@ type ColumnSettingController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (controller *ColumnSettingController) Prepare() {
controller.BaseController.Prepare()
if ok := controller.ValidJWTToken(); !ok {
return
}
if ok := controller.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok {
return
}
}
func (controller *ColumnSettingController) CreateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
createColumnSettingCommand := &command.CreateColumnSettingCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createColumnSettingCommand)
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createColumnSettingCommand)
if err := controller.BindJsonData(&createColumnSettingCommand); err != nil {
logs.Error(err)
controller.ResponseError(errors.New("json数据解析失败"))
return
}
companyId := controller.GetUserCompany()
uid := controller.GetUserId()
createColumnSettingCommand.CompanyId = int(companyId)
createColumnSettingCommand.Uid = uid
data, err := columnSettingService.CreateColumnSetting(createColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -39,13 +62,20 @@ func (controller *ColumnSettingController) CreateColumnSetting() {
func (controller *ColumnSettingController) UpdateColumnSetting() {
columnSettingService := service.NewColumnSettingService(nil)
updateColumnSettingCommand := &command.UpdateColumnSettingCommand{}
_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateColumnSettingCommand)
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateColumnSettingCommand)
if err := controller.BindJsonData(&updateColumnSettingCommand); err != nil {
logs.Error(err)
controller.ResponseError(errors.New("json数据解析失败"))
return
}
//columnSettingId, _ := controller.GetInt64(":columnSettingId")
companyId := controller.GetUserCompany()
uid := controller.GetUserId()
//updateColumnSettingCommand.ColumnSettingId = columnSettingId
updateColumnSettingCommand.CompanyId = int(companyId)
updateColumnSettingCommand.Uid = uid
updateColumnSettingCommand.Selected = updateColumnSettingCommand.OrderBaseColumns.Selected
updateColumnSettingCommand.UnSelected = updateColumnSettingCommand.OrderBaseColumns.UnSelected
data, err := columnSettingService.UpdateColumnSetting(updateColumnSettingCommand)
var response utils.JsonResponse
if err != nil {
... ... @@ -116,7 +146,8 @@ func (controller *ColumnSettingController) ResetColumn() {
//_ = json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), resetColumnCommand)
resetColumnCommand.CompanyId = int(companyId)
resetColumnCommand.Uid = uid
resetColumnCommand.Value = domain.DefaultColumns // 还原默认栏目设置
resetColumnCommand.Value = domain.DefaultColumns // 还原默认栏目设置
resetColumnCommand.InvalidValue = domain.DefaultInvalidColumns // 还原默认无效栏目
data, err := columnSettingService.ResetColumn(resetColumnCommand)
var response utils.JsonResponse
if err != nil {
... ...
... ... @@ -45,7 +45,8 @@ func init() {
beego.NSRouter("/fileImport", &controllers.OrderInfoController{}, "POST:ImportOrderFromExcel"), // 导入订单数据
beego.NSRouter("/actual/listColumn", &controllers.ColumnSettingController{}, "POST:GetColumnSetting"), // 返回栏目设置列表
beego.NSRouter("/actual/updateColumn", &controllers.ColumnSettingController{}, "POST:UpdateColumnSetting"), // 更新栏目设置
beego.NSRouter("/actual/resetColumn", &controllers.ColumnSettingController{}, "Post:ResetColumn"), // 重置栏目设置
beego.NSRouter("/actual/resetColumn", &controllers.ColumnSettingController{}, "POST:ResetColumn"), // 重置栏目设置
beego.NSRouter("/actual/createColumn", &controllers.ColumnSettingController{}, "POST:CreateColumnSetting"), // 创建栏目设置,测试用
),
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
... ...