作者 tangxuhui

新增:公司的参数设置

... ... @@ -3,7 +3,26 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic
go 1.16
require (
github.com/ajg/form v1.5.1 // indirect
github.com/beego/beego/v2 v2.0.1
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gavv/httpexpect v2.0.0+incompatible
github.com/go-pg/pg/v10 v10.10.2
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imkira/go-interpol v1.1.0 // indirect
github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
github.com/sergi/go-diff v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
github.com/yudai/gojsondiff v1.0.0 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
)
... ...
... ... @@ -29,3 +29,11 @@ func CreateNoticePersonalRepository(options map[string]interface{}) (domain.Noti
}
return repository.NewNoticePersonalRepository(transactionContext)
}
func CreateSystemSettingRepository(options map[string]interface{}) (domain.SystemSettingRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewSystemSettingRepository(transactionContext)
}
... ...
... ... @@ -15,6 +15,9 @@ type GetNoticePersonalListQuery struct {
PageIndex int64 `json:"pageIndex"`
// 是否是已读
IsRead int64 `json:"isRead"`
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
}
func (getNoticePersonalListQuery *GetNoticePersonalListQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -106,26 +106,55 @@ func (noticePersonalService *NoticePersonalService) AgreeJoinCreationProject(agr
}
// 获取消息列表
func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (interface{}, error) {
func (noticePersonalService *NoticePersonalService) GetNoticePersonalList(getNoticePersonalListQuery *query.GetNoticePersonalListQuery) (int64, interface{}, error) {
if err := getNoticePersonalListQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
return 0, 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())
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
//TODO
var noticePersonalRepository domain.NoticePersonalRepository
if value, err := factory.CreateNoticePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
noticePersonalRepository = value
}
queryOption := map[string]interface{}{
"limit": getNoticePersonalListQuery.PageSize,
"offset": (getNoticePersonalListQuery.PageIndex - 1) * getNoticePersonalListQuery.PageSize,
}
if getNoticePersonalListQuery.UserId > 0 {
queryOption["userId"] = getNoticePersonalListQuery.UserId
}
if getNoticePersonalListQuery.OrgId > 0 {
queryOption["orgId"] = getNoticePersonalListQuery.OrgId
}
if getNoticePersonalListQuery.CompanyId > 0 {
queryOption["companyId"] = getNoticePersonalListQuery.CompanyId
}
if getNoticePersonalListQuery.IsRead > 0 {
queryOption["isRead"] = getNoticePersonalListQuery.IsRead
}
cnt, noticeList, err := noticePersonalRepository.Find(queryOption)
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return cnt, noticeList, nil
}
// 设置消息:分红预算消息
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type UpdateSystemSettingCommand struct {
// 设置对应的编码
SettingCode string `json:"settingCode" valid:"Required"`
// 公司id
CompanyId int64 `json:"companyId" valid:"Required"`
//设定的值
Value string `json:"value" valid:"Required"`
}
func (updateSystemSettingCommand *UpdateSystemSettingCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateSystemSettingCommand *UpdateSystemSettingCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateSystemSettingCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type GetSystemSettingQuery struct {
// 设置对应的编码
SettingCode string `json:"settingCode" valid:"Required"`
// 企业id
CompanyId int64 `json:"companyId" valid:"Required"`
}
func (getSystemSettingQuery *GetSystemSettingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getSystemSettingQuery *GetSystemSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getSystemSettingQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type ListSystemSettingQuery struct {
// 公司id
CompanyId int64 `json:"companyId,omitempty"`
// 设置对应的编码
SettingCode string `json:"settingCode,omitempty"`
}
func (listSystemSettingQuery *ListSystemSettingQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listSystemSettingQuery *ListSystemSettingQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listSystemSettingQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
)
// 用户的系统设置
type SystemSettingService struct {
}
// 返回用户的系统设置
func (systemSettingService *SystemSettingService) GetSystemSetting(getSystemSettingQuery *query.GetSystemSettingQuery) (interface{}, error) {
if err := getSystemSettingQuery.ValidateQuery(); 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()
}()
var systemSettingRepository domain.SystemSettingRepository
if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemSettingRepository = value
}
systemSetting, err := systemSettingRepository.FindOne(map[string]interface{}{
"companyId": getSystemSettingQuery.CompanyId,
"settingCode": getSystemSettingQuery.SettingCode,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if systemSetting == nil {
//获取默认设置项
setting := domain.SystemSetting{}
defaultSet := setting.GetDefaultSetting(getSystemSettingQuery.SettingCode)
if len(defaultSet) == 0 {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取设置项失败,settingCode="+getSystemSettingQuery.SettingCode)
}
defaultSet[0].CompanyId = getSystemSettingQuery.CompanyId
systemSetting = &defaultSet[0]
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return systemSetting, nil
}
// 返回用户的系统设置列表
func (systemSettingService *SystemSettingService) ListSystemSetting(listSystemSettingQuery *query.ListSystemSettingQuery) (interface{}, error) {
if err := listSystemSettingQuery.ValidateQuery(); 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()
}()
var systemSettingRepository domain.SystemSettingRepository
if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemSettingRepository = value
}
queryOption := map[string]interface{}{
"companyId": listSystemSettingQuery.CompanyId,
}
if len(listSystemSettingQuery.SettingCode) > 0 {
queryOption["settingCode"] = listSystemSettingQuery.SettingCode
}
_, systemSettings, err := systemSettingRepository.Find(queryOption)
if 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())
}
settingMap := map[string]*domain.SystemSetting{}
for i := range systemSettings {
code := systemSettings[i].SettingCode
settingMap[code] = systemSettings[i]
}
defaultSettings := new(domain.SystemSetting).GetDefaultSetting("")
for i := range defaultSettings {
if v, ok := settingMap[defaultSettings[i].SettingCode]; ok {
defaultSettings[i].Value = v.Value
}
defaultSettings[i].CompanyId = listSystemSettingQuery.CompanyId
}
return map[string]interface{}{
"systemSettings": defaultSettings,
}, nil
}
// 更新用户的系统设置
func (systemSettingService *SystemSettingService) UpdateSystemSetting(updateSystemSettingCommand *command.UpdateSystemSettingCommand) (interface{}, error) {
if err := updateSystemSettingCommand.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()
}()
var systemSettingRepository domain.SystemSettingRepository
if value, err := factory.CreateSystemSettingRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
systemSettingRepository = value
}
_, systemSettings, err := systemSettingRepository.Find(map[string]interface{}{
"settingCode": updateSystemSettingCommand.SettingCode,
"companyId": updateSystemSettingCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var systemSetting *domain.SystemSetting
if len(systemSettings) == 0 {
defaultSet := new(domain.SystemSetting).GetDefaultSetting(updateSystemSettingCommand.SettingCode)
if len(defaultSet) > 0 {
systemSetting = &defaultSet[0]
systemSetting.CompanyId = updateSystemSettingCommand.CompanyId
}
} else {
systemSetting = systemSettings[0]
if err := systemSetting.Update(map[string]interface{}{
"value": updateSystemSettingCommand.Value,
}); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
}
if systemSetting == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "settingCode错误,settingCode="+updateSystemSettingCommand.SettingCode)
}
if systemSetting, err := systemSettingRepository.Save(systemSetting); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return systemSetting, nil
}
}
func NewSystemSettingService(options map[string]interface{}) *SystemSettingService {
newSystemSettingService := &SystemSettingService{}
return newSystemSettingService
}
... ...
package domain
// 系统参数设置
type SystemSetting struct {
// 公司id
CompanyId int64 `json:"companyId"`
// 管控层级
ControlLevel string `json:"controlLevel"`
// 描述
Description string `json:"description"`
// 设置对应的编码
SettingCode string `json:"settingCode"`
// 设置对应的名称
SettingName string `json:"settingName"`
// 数据id
SystemSettingId int64 `json:"systemSettingId"`
// 设定的值
Value string `json:"value"`
// 值类型
ValueType string `json:"valueType"`
}
type SystemSettingRepository interface {
Save(systemSetting *SystemSetting) (*SystemSetting, error)
Remove(systemSetting *SystemSetting) (*SystemSetting, error)
FindOne(queryOptions map[string]interface{}) (*SystemSetting, error)
Find(queryOptions map[string]interface{}) (int64, []*SystemSetting, error)
}
func (systemSetting *SystemSetting) Identify() interface{} {
if systemSetting.SystemSettingId == 0 {
return nil
}
return systemSetting.SystemSettingId
}
func (systemSetting *SystemSetting) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
systemSetting.CompanyId = companyId.(int64)
}
if controlLevel, ok := data["controlLevel"]; ok {
systemSetting.ControlLevel = controlLevel.(string)
}
if description, ok := data["description"]; ok {
systemSetting.Description = description.(string)
}
if settingCode, ok := data["settingCode"]; ok {
systemSetting.SettingCode = settingCode.(string)
}
if settingName, ok := data["settingName"]; ok {
systemSetting.SettingName = settingName.(string)
}
if systemSettingId, ok := data["systemSettingId"]; ok {
systemSetting.SystemSettingId = systemSettingId.(int64)
}
if value, ok := data["value"]; ok {
systemSetting.Value = value.(string)
}
if valueType, ok := data["valueType"]; ok {
systemSetting.ValueType = valueType.(string)
}
return nil
}
var defaultsysSettingList = []SystemSetting{
{
ControlLevel: "系统级",
ValueType: "字符",
Value: "TL123456!",
SettingName: "用户初始化密码",
SettingCode: "XT001",
Description: "用于用户初始化设置初始化密码",
},
}
func (systemSetting *SystemSetting) GetDefaultSetting(settingCode string) []SystemSetting {
var list []SystemSetting
if len(settingCode) > 0 {
for i := range defaultsysSettingList {
if defaultsysSettingList[i].SettingCode == settingCode {
list = append(list, defaultsysSettingList[i])
}
}
} else {
list = make([]SystemSetting, len(defaultsysSettingList))
copy(list, defaultsysSettingList)
}
return list
}
... ...
package models
type SystemSetting struct {
tableName string `pg:"system_settings,alias:system_setting"`
// 公司id
CompanyId int64
// 管控层级
ControlLevel string
// 描述
Description string
// 设置对应的编码
SettingCode string
// 设置对应的名称
SettingName string
// 数据id
SystemSettingId int64
// 设定的值
Value string
// 值类型
ValueType string
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
)
func TransformToSystemSettingDomainModelFromPgModels(systemSettingModel *models.SystemSetting) (*domain.SystemSetting, error) {
return &domain.SystemSetting{
CompanyId: systemSettingModel.CompanyId,
ControlLevel: systemSettingModel.ControlLevel,
Description: systemSettingModel.Description,
SettingCode: systemSettingModel.SettingCode,
SettingName: systemSettingModel.SettingName,
SystemSettingId: systemSettingModel.SystemSettingId,
Value: systemSettingModel.Value,
ValueType: systemSettingModel.ValueType,
}, nil
}
... ...
... ... @@ -6,7 +6,6 @@ import (
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
... ... @@ -17,11 +16,7 @@ type NoticePersonalRepository struct {
}
func (repository *NoticePersonalRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := idWorker.NextId()
return id, err
}
func (repository *NoticePersonalRepository) Save(noticePersonal *domain.NoticePersonal) (*domain.NoticePersonal, error) {
... ... @@ -157,6 +152,10 @@ func (repository *NoticePersonalRepository) Find(queryOptions map[string]interfa
query := sqlbuilder.BuildQuery(tx.Model(&noticePersonalModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("notice_personal_id", "DESC")
query.SetWhereByQueryOption("notice_personal.user_id", "userId")
query.SetWhereByQueryOption("notice_personal.org_id", "orgId")
query.SetWhereByQueryOption("notice_personal.company_id", "companyId")
query.SetWhereByQueryOption("notice_personal.is_read", "isRead")
if count, err := query.SelectAndCount(); err != nil {
return 0, noticePersonals, err
} else {
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/infrastructure/pg/transform"
)
type SystemSettingRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *SystemSettingRepository) nextIdentify() (int64, error) {
id, err := idWorker.NextId()
return id, err
}
func (repository *SystemSettingRepository) Save(systemSetting *domain.SystemSetting) (*domain.SystemSetting, error) {
sqlBuildFields := []string{
"company_id",
"control_level",
"description",
"setting_code",
"setting_name",
"system_setting_id",
"value",
"value_type",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "systemSetting_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if systemSetting.Identify() == nil {
systemSettingId, err := repository.nextIdentify()
if err != nil {
return systemSetting, err
} else {
systemSetting.SystemSettingId = systemSettingId
}
if _, err := tx.QueryOne(
pg.Scan(
&systemSetting.CompanyId,
&systemSetting.ControlLevel,
&systemSetting.Description,
&systemSetting.SettingCode,
&systemSetting.SettingName,
&systemSetting.SystemSettingId,
&systemSetting.Value,
&systemSetting.ValueType,
),
fmt.Sprintf("INSERT INTO system_settings (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
systemSetting.CompanyId,
systemSetting.ControlLevel,
systemSetting.Description,
systemSetting.SettingCode,
systemSetting.SettingName,
systemSetting.SystemSettingId,
systemSetting.Value,
systemSetting.ValueType,
); err != nil {
return systemSetting, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&systemSetting.CompanyId,
&systemSetting.ControlLevel,
&systemSetting.Description,
&systemSetting.SettingCode,
&systemSetting.SettingName,
&systemSetting.SystemSettingId,
&systemSetting.Value,
&systemSetting.ValueType,
),
fmt.Sprintf("UPDATE system_settings SET %s WHERE system_setting_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
systemSetting.CompanyId,
systemSetting.ControlLevel,
systemSetting.Description,
systemSetting.SettingCode,
systemSetting.SettingName,
systemSetting.SystemSettingId,
systemSetting.Value,
systemSetting.ValueType,
systemSetting.Identify(),
); err != nil {
return systemSetting, err
}
}
return systemSetting, nil
}
func (repository *SystemSettingRepository) Remove(systemSetting *domain.SystemSetting) (*domain.SystemSetting, error) {
tx := repository.transactionContext.PgTx
systemSettingModel := new(models.SystemSetting)
systemSettingModel.SystemSettingId = systemSetting.Identify().(int64)
if _, err := tx.Model(systemSettingModel).WherePK().Delete(); err != nil {
return systemSetting, err
}
return systemSetting, nil
}
func (repository *SystemSettingRepository) FindOne(queryOptions map[string]interface{}) (*domain.SystemSetting, error) {
tx := repository.transactionContext.PgTx
systemSettingModel := new(models.SystemSetting)
query := sqlbuilder.BuildQuery(tx.Model(systemSettingModel), queryOptions)
query.SetWhereByQueryOption("system_setting.system_setting_id = ?", "systemSettingId")
query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode")
query.SetWhereByQueryOption("system_setting.companyId=?", "companyId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if systemSettingModel.SystemSettingId == 0 {
return nil, nil
} else {
return transform.TransformToSystemSettingDomainModelFromPgModels(systemSettingModel)
}
}
func (repository *SystemSettingRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.SystemSetting, error) {
tx := repository.transactionContext.PgTx
var systemSettingModels []*models.SystemSetting
systemSettings := make([]*domain.SystemSetting, 0)
query := sqlbuilder.BuildQuery(tx.Model(&systemSettingModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("system_setting_id", "DESC")
query.SetWhereByQueryOption("system_setting.setting_code=?", "settingCode")
query.SetWhereByQueryOption("system_setting.companyId=?", "companyId")
if count, err := query.SelectAndCount(); err != nil {
return 0, systemSettings, err
} else {
for _, systemSettingModel := range systemSettingModels {
if systemSetting, err := transform.TransformToSystemSettingDomainModelFromPgModels(systemSettingModel); err != nil {
return 0, systemSettings, err
} else {
systemSettings = append(systemSettings, systemSetting)
}
}
return int64(count), systemSettings, nil
}
}
func NewSystemSettingRepository(transactionContext *pgTransaction.TransactionContext) (*SystemSettingRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &SystemSettingRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -14,7 +14,11 @@ type NoticePersonalController struct {
func (controller *NoticePersonalController) GetNoticePersonalList() {
noticePersonalService := service.NewNoticePersonalService(nil)
getNoticePersonalListQuery := &query.GetNoticePersonalListQuery{}
data, err := noticePersonalService.GetNoticePersonalList(getNoticePersonalListQuery)
cnt, list, err := noticePersonalService.GetNoticePersonalList(getNoticePersonalListQuery)
data := map[string]interface{}{
"count": cnt,
"list": list,
}
controller.Response(data, err)
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/application/systemSetting/service"
)
type SystemSettingController struct {
beego.BaseController
}
func (controller *SystemSettingController) UpdateSystemSetting() {
systemSettingService := service.NewSystemSettingService(nil)
updateSystemSettingCommand := &command.UpdateSystemSettingCommand{}
controller.Unmarshal(updateSystemSettingCommand)
data, err := systemSettingService.UpdateSystemSetting(updateSystemSettingCommand)
controller.Response(data, err)
}
func (controller *SystemSettingController) GetSystemSetting() {
systemSettingService := service.NewSystemSettingService(nil)
getSystemSettingQuery := &query.GetSystemSettingQuery{}
data, err := systemSettingService.GetSystemSetting(getSystemSettingQuery)
controller.Response(data, err)
}
func (controller *SystemSettingController) ListSystemSetting() {
systemSettingService := service.NewSystemSettingService(nil)
listSystemSettingQuery := &query.ListSystemSettingQuery{}
data, err := systemSettingService.ListSystemSetting(listSystemSettingQuery)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-basic/pkg/port/beego/controllers"
)
func init() {
web.Router("/system-settings/", &controllers.SystemSettingController{}, "Put:UpdateSystemSetting")
web.Router("/system-settings/get", &controllers.SystemSettingController{}, "Post:GetSystemSetting")
web.Router("/system-settings/search", &controllers.SystemSettingController{}, "Post:ListSystemSetting")
}
... ...