...
|
...
|
@@ -41,7 +41,7 @@ func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenu |
|
|
Sort: createMenuCommand.Sort,
|
|
|
Remark: createMenuCommand.Desc,
|
|
|
IsPublish: createMenuCommand.IsPublish,
|
|
|
EnableStatus: createMenuCommand.EnableStatus,
|
|
|
EnableStatus: domain.MenuStatusDisable,
|
|
|
}
|
|
|
var menuRepository domain.MenuRepository
|
|
|
if value, err := factory.CreateMenuRepository(map[string]interface{}{
|
...
|
...
|
@@ -292,6 +292,81 @@ func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenu |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 批量删除菜单
|
|
|
func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDeleteMenuCommand) (interface{}, error) {
|
|
|
if err := batchDeleteMenu.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
menuRepository, _, err := factory.FastPgMenu(transactionContext, 0)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
for i := 0; i < len(batchDeleteMenu.MenuIds); i++ {
|
|
|
if menu, err := menuRepository.FindOne(map[string]interface{}{"menuId": batchDeleteMenu.MenuIds[i]}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if _, err := menuRepository.Remove(menu); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 批量删除菜单
|
|
|
func (menuService *MenuService) BatchEnableMenu(batchEnableMenu *command.BatchEnableMenuCommand) (interface{}, error) {
|
|
|
if err := batchEnableMenu.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
menuRepository, _, err := factory.FastPgMenu(transactionContext, 0)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := 0; i < len(batchEnableMenu.MenuIds); i++ {
|
|
|
if menu, err := menuRepository.FindOne(map[string]interface{}{"menuId": batchEnableMenu.MenuIds[i]}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := menu.SetPublic(batchEnableMenu.Status); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if _, err := menuRepository.Save(menu); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
func NewMenuService(options map[string]interface{}) *MenuService {
|
|
|
newMenuService := &MenuService{}
|
|
|
return newMenuService
|
...
|
...
|
|