作者 tangxvhui

.

... ... @@ -12,3 +12,11 @@ func CreateAdminUserkDao(options map[string]interface{}) (*dao.AdminUserDao, err
}
return dao.NewAdminUserDao(transactionContext)
}
func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return dao.NewPartnerInfoDao(transactionContext)
}
... ...
... ... @@ -7,13 +7,13 @@ import (
)
//CreatePartnerInfoRepository 合伙人信息
// func CreatePartnerInfoRepository(options map[string]interface{}) (domain.PartnerInfoRepository, error) {
// var transactionContext *transaction.TransactionContext
// if value, ok := options["transactionContext"]; ok {
// transactionContext = value.(*transaction.TransactionContext)
// }
// return repository.NewPartnerInfoRepository(transactionContext)
// }
func CreatePartnerInfoRepository(options map[string]interface{}) (domain.PartnerInfoRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewPartnerInfoRepository(transactionContext)
}
//CreateAdminUserRepository 管理员信息
func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) {
... ... @@ -24,7 +24,7 @@ func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUser
return repository.NewAdminUserRepository(transactionContext)
}
//CreateAdminUserRepository 管理员信息
//CreateAdminUserRepository 管理员权限信息
func CreateAdminPermissionRepository(options map[string]interface{}) (domain.AdminPermissionRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"time"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type CreatePartnerInfoCommand struct {
domain.PartnerInfo
// 合伙人姓名
PartnerName string `json:"partnerName,omitempty"`
// 登录账号
Account string `json:"account,omitempty"`
// 登录密码
Password string `json:"password,omitempty"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []*domain.Salesman `json:"salesman,omitempty"`
}
func (c *CreatePartnerInfoCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(c)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
func (command CreatePartnerInfoCommand) ValidateCommand() error {
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemovePartnerInfoCommand struct {
// 合伙人ID
Id int `json:"id" valid:"Required"`
}
func (c *RemovePartnerInfoCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(c)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
package command
type StatusPartnerInfoCommand struct {
// 合伙人ID
Id int64 `json:"id"`
Status int `json:"status"`
}
func (c *StatusPartnerInfoCommand) ValidateCommand() error {
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type UpdatePartnerInfoCommand struct {
// 合伙人Id
Id int `json:"id,omitempty"`
// 合伙人姓名
PartnerName string `json:"partnerName,omitempty"`
// 登录账号
Account string `json:"account,omitempty"`
// 登录密码
Password string `json:"password,omitempty"`
Id int64 `json:"id,omitempty"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory,omitempty"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []*domain.Salesman `json:"salesman,omitempty"`
}
func (c *UpdatePartnerInfoCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(c)
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/astaxie/beego/validation"
)
type GetPartnerInfoQuery struct {
// 合伙人ID
Id int `json:"id" valid:"Required"`
Id int64 `json:"id" `
}
func (q *GetPartnerInfoQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(q)
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/astaxie/beego/validation"
)
type ListPartnerInfoQuery struct {
//状态
Status int `json:"status,omitempty"`
// 合伙人类别
PartnerCategory int `json:"partnerCategory,omitempty"`
//按创建任务时间排序(ASC,DESC)
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
//按创建任务时间排序(ASC,DESC)
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
Partnertype int `json:"partnerType"`
RegionInfo string `json:"regionInfo"`
PartnerName string `json:"partnerName"`
// 查询偏离量
Offset int `json:"offset,omitempty"`
Offset int `json:"offset"`
// 查询限制
Limit int `json:"limit,omitempty"`
Limit int `json:"limit"`
}
func (q *ListPartnerInfoQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(q)
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/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
// 客户价值服务
type PartnerInfoService struct {
}
func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
newPartnerInfoService := &PartnerInfoService{}
return newPartnerInfoService
}
// 创建客户价值
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
//检查账号是否存在
var (
partnerinfoDao *dao.PartnerInfoDao
)
if v, err := factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
} else {
partnerinfoDao = v
}
ok, err := partnerinfoDao.PartnerAccountExist(command.Account)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if ok {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
newPartnerInfo := &domain.PartnerInfo{
Account: command.Account,
PartnerName: command.PartnerName,
Password: command.Password,
Status: command.Status,
PartnerCategory: command.PartnerCategory,
RegionInfo: command.RegionInfo,
Salesman: command.Salesman,
CooperateTime: command.CooperateTime,
}
if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return
}
// GetPartnerInfo 返回合伙人
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateQuery(); err != nil {
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
data, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return
}
// 更新客户价值
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = updatePartnerInfoCommand.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var partnerInfoRepository domain.PartnerInfoRepository
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: updatePartnerInfoCommand.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
partnerInfo.PartnerCategory = updatePartnerInfoCommand.PartnerCategory
partnerInfo.Salesman = updatePartnerInfoCommand.Salesman
partnerInfo.Status = updatePartnerInfoCommand.Status
partnerInfo.RegionInfo = updatePartnerInfoCommand.RegionInfo
if _, err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
transactionContext.CommitTransaction()
return
}
// 返回客户价值列表
func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (int, []domain.PartnerInfo, error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
partnerInfos []domain.PartnerInfo
count int
err error
)
if err = listPartnerInfoQuery.ValidateQuery(); err != nil {
return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
var partnerInfoRepository domain.PartnerInfoRepository
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
queryOption := domain.PartnerFindQuery{
Offset: listPartnerInfoQuery.Offset,
Limit: listPartnerInfoQuery.Limit,
PartnerCategory: []int{listPartnerInfoQuery.Partnertype},
PartnerName: listPartnerInfoQuery.PartnerName,
}
// RegionInfo
if len(listPartnerInfoQuery.RegionInfo) > 0 {
queryOption.RegionInfo = &domain.RegionInfo{RegionName: listPartnerInfoQuery.RegionInfo}
}
if partnerInfos, err = partnerInfoRepository.Find(queryOption); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if count, err = partnerInfoRepository.CountAll(queryOption); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if err = transactionContext.CommitTransaction(); err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
return count, partnerInfos, nil
}
func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.StatusPartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var partnerInfoRepository domain.PartnerInfoRepository
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: command.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
partnerInfo.Status = command.Status
if _, err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
transactionContext.CommitTransaction()
return
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"time"
)
// 客户价值服务
type PartnerInfoService struct {
}
// 创建客户价值
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) {
var (
count int64
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
newPartnerInfo := &command.PartnerInfo
newPartnerInfo.CreateAt = time.Now()
newPartnerInfo.UpdateAt = time.Now()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
return nil, err
}
if count, _, err = PartnerInfoRepository.Find(map[string]interface{}{"account": command.Account}); err != nil {
return nil, err
}
if count > 0 {
return nil, fmt.Errorf("标签不可重复名称")
}
if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil {
return
}
err = transactionContext.CommitTransaction()
return
}
// 返回客户价值
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetPartnerInfoQuery) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
return nil, err
}
data, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": command.Id})
if err != nil {
return nil, err
}
if data == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(command.Id)))
}
err = transactionContext.CommitTransaction()
return
}
// 更新客户价值
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerInfo *domain.PartnerInfo
)
if err = updatePartnerInfoCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
return nil, err
}
PartnerInfo, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": updatePartnerInfoCommand.Id})
if err != nil {
return nil, err
}
if PartnerInfo == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updatePartnerInfoCommand.Id)))
}
//if count, PartnerInfos, err := PartnerInfoRepository.Find(map[string]interface{}{
// "PartnerInfoName": updatePartnerInfoCommand.PartnerInfoName,
// "companyId": PartnerInfo.CompanyId,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if count > 0 && PartnerInfos[0].PartnerInfoId != PartnerInfo.PartnerInfoId {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "标签不可重复名称")
// }
//}
if err := PartnerInfo.Update(tool_funs.SimpleStructToMap(updatePartnerInfoCommand)); err != nil {
return nil, err
}
if data, err = PartnerInfoRepository.Save(PartnerInfo); err != nil {
return nil, err
}
err = transactionContext.CommitTransaction()
return
}
// 移除客户价值
func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(removePartnerInfoCommand *command.RemovePartnerInfoCommand) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerInfo *domain.PartnerInfo
)
if err = removePartnerInfoCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
return nil, err
}
PartnerInfo, err = PartnerInfoRepository.FindOne(map[string]interface{}{"Id": removePartnerInfoCommand.Id})
if err != nil {
return nil, err
}
if PartnerInfo == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removePartnerInfoCommand.Id)))
}
if data, err = PartnerInfoRepository.Remove(PartnerInfo); err != nil {
return nil, err
}
err = transactionContext.CommitTransaction()
return
}
// 返回客户价值列表
func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQuery *query.ListPartnerInfoQuery) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
PartnerInfos []*domain.PartnerInfo
count int64
)
if err = listPartnerInfoQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{"transactionContext": transactionContext}); err != nil {
return nil, err
}
if count, PartnerInfos, err = PartnerInfoRepository.Find(tool_funs.SimpleStructToMap(listPartnerInfoQuery)); err != nil {
return nil, err
}
if err = transactionContext.CommitTransaction(); err != nil {
return nil, err
}
return map[string]interface{}{
"count": count,
"partnerInfos": PartnerInfos,
}, nil
}
func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
newPartnerInfoService := &PartnerInfoService{}
return newPartnerInfoService
}
... ... @@ -2,13 +2,6 @@ package domain
import "time"
type PartnerInfoRepository interface {
Save(dm *PartnerInfo) (*PartnerInfo, error)
Remove(dm *PartnerInfo) (*PartnerInfo, error)
FindOne(queryOptions map[string]interface{}) (*PartnerInfo, error)
Find(queryOptions map[string]interface{}) (int64, []*PartnerInfo, error)
}
type PartnerInfo struct {
// 合伙人ID
Id int64 `json:"id"`
... ... @@ -27,37 +20,29 @@ type PartnerInfo struct {
CreateAt time.Time `json:"createAt"`
//更新时间
UpdateAt time.Time `json:"updateAt"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
//关联业务员//所属区域信息
RegionInfo *RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []*Salesman `json:"salesman"`
}
func (m *PartnerInfo) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
type PartnerFindOneQuery struct {
UserId int64
AccountEqual string
}
type PartnerFindQuery struct {
Offset int
Limit int
PartnerCategory []int //合伙人类型
RegionInfo *RegionInfo //区域
PartnerName string //合伙人姓名
}
func (m *PartnerInfo) Update(data map[string]interface{}) error {
if partnerName, ok := data["partnerName"]; ok && partnerName != "" {
m.PartnerName = partnerName.(string)
}
if account, ok := data["account"]; ok && account != "" {
m.Account = account.(string)
}
if password, ok := data["account"]; ok && password != "" {
m.Password = password.(string)
}
if status, ok := data["status"]; ok && status != 0 {
m.Status = status.(int)
}
if partnerCategory, ok := data["partnerCategory"]; ok && partnerCategory != 0 {
m.PartnerCategory = partnerCategory.(int)
}
if salesman, ok := data["salesman"]; ok {
m.Salesman = salesman.([]*Salesman)
}
m.UpdateAt = time.Now()
return nil
type PartnerInfoRepository interface {
Save(dm *PartnerInfo) (*PartnerInfo, error)
FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error)
Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error)
CountAll(queryOptions PartnerFindQuery) (int, error)
}
... ...
package domain
type RegionInfo struct {
RegionName string `json:"regionName"`
}
... ...
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type PartnerInfoDao struct {
transactionContext *transaction.TransactionContext
}
func NewPartnerInfoDao(transactionContext *transaction.TransactionContext) (*PartnerInfoDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &PartnerInfoDao{
transactionContext: transactionContext,
}, nil
}
}
func (dao PartnerInfoDao) PartnerAccountExist(account string) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.PartnerInfo{}
ok, err := tx.Model(m).
Where("account=?", account).
Exists()
return ok, err
}
... ...
... ... @@ -9,7 +9,7 @@ import (
)
type PartnerInfo struct {
tableName struct{} `pg:"partner_infos,alias:partner_info"`
tableName struct{} `pg:"partner_info"`
// 合伙人ID
Id int64 `pg:",pk"`
// 合伙人姓名
... ... @@ -22,12 +22,14 @@ type PartnerInfo struct {
Status int `pg:",notnull,default:1"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `pg:",notnull,default:1"`
//所属区域信息
RegionInfo *domain.RegionInfo
//创建时间
CreateAt time.Time
//更新时间
UpdateAt time.Time
//合作时间
CooperateTime time.Time
//关联业务员
Salesman []*domain.Salesman
}
... ...
... ... @@ -138,7 +138,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer
func (reponsitory AdminUserRepository) CountAll(queryOption domain.AdminUserFindQuery) (int, error) {
db := reponsitory.transactionContext.PgDd
adminuserModels := []models.AdminUser{}
adminuserModels := models.AdminUser{}
query := db.Model(&adminuserModels)
if len(queryOption.AccountLike) > 0 {
query = query.Where("account like ?", "%"+queryOption.AccountLike+"%")
... ...
package repository
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type PartnerInfoRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil)
)
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) {
m := domain.PartnerInfo{
Id: partnerInfoModel.Id,
PartnerName: partnerInfoModel.PartnerName,
Account: partnerInfoModel.Account,
Password: partnerInfoModel.Password,
Status: partnerInfoModel.Status,
PartnerCategory: partnerInfoModel.PartnerCategory,
CreateAt: partnerInfoModel.CreateAt,
Salesman: partnerInfoModel.Salesman,
RegionInfo: partnerInfoModel.RegionInfo,
CooperateTime: partnerInfoModel.CooperateTime,
}
return m, nil
}
func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) (*domain.PartnerInfo, error) {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.PartnerInfo{
Id: dm.Id,
PartnerName: dm.PartnerName,
Account: dm.Account,
Password: dm.Password,
Status: dm.Status,
PartnerCategory: dm.PartnerCategory,
Salesman: dm.Salesman,
RegionInfo: dm.RegionInfo,
CooperateTime: dm.CooperateTime,
}
if m.Id == 0 {
err = tx.Insert(m)
dm.Id = m.Id
if err != nil {
return nil, err
}
} else {
err = tx.Update(m)
if err != nil {
return nil, err
}
}
return dm, nil
}
func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFindOneQuery) (*domain.PartnerInfo, error) {
tx := repository.transactionContext.PgDd
PartnerInfoModel := new(models.PartnerInfo)
query := tx.Model(PartnerInfoModel)
if len(queryOptions.AccountEqual) > 0 {
query = query.Where("account=?", queryOptions.AccountEqual)
}
if queryOptions.UserId > 0 {
query = query.Where("id=?", queryOptions.UserId)
}
if err := query.First(); err != nil {
return nil, err
}
result, err := repository.transformPgModelToDomainModel(PartnerInfoModel)
return &result, err
}
func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) {
db := repository.transactionContext.PgDd
partnerModels := []models.PartnerInfo{}
query := db.Model(&partnerModels)
if len(queryOption.PartnerName) > 0 {
query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%")
}
if queryOption.RegionInfo != nil {
query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%")
}
if len(queryOption.PartnerCategory) > 0 {
query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(20)
}
var (
err error
partnerReturn = make([]domain.PartnerInfo, 0)
)
err = query.Select()
if err != nil {
return partnerReturn, err
}
for i := range partnerModels {
domainPartner, err := repository.transformPgModelToDomainModel(&partnerModels[i])
if err != nil {
return partnerReturn, err
}
partnerReturn = append(partnerReturn, domainPartner)
}
return partnerReturn, nil
}
func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
db := repository.transactionContext.PgDd
adminuserModels := models.AdminUser{}
query := db.Model(&adminuserModels)
if len(queryOption.PartnerName) > 0 {
query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%")
}
if queryOption.RegionInfo != nil {
query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%")
}
if len(queryOption.PartnerCategory) > 0 {
query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory)
}
cnt, err := query.Count()
return cnt, err
}
... ...
package repository
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type PartnerInfoRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(PartnerInfoModel *models.PartnerInfo) (*domain.PartnerInfo, error) {
m := &domain.PartnerInfo{}
return m, nil
}
func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) (*domain.PartnerInfo, error) {
var (
err error
m = &models.PartnerInfo{}
tx = repository.transactionContext.PgTx
)
if err = GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Identify() == nil {
if dm.Id, err = NewSnowflakeId(); err != nil {
return dm, err
}
m.Id = dm.Id
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
// func (repository *PartnerInfoRepository) Remove(PartnerInfo *domain.PartnerInfo) (*domain.PartnerInfo, error) {
// var (
// tx = repository.transactionContext.PgTx
// PartnerInfoModel = &models.PartnerInfo{Id: PartnerInfo.Identify().(int64)}
// )
// if _, err := tx.Model(PartnerInfoModel).Where("id = ?", PartnerInfo.Id).Delete(); err != nil {
// return PartnerInfo, err
// }
// return PartnerInfo, nil
// }
// func (repository *PartnerInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.PartnerInfo, error) {
// tx := repository.transactionContext.PgTx
// PartnerInfoModel := new(models.PartnerInfo)
// query := NewQuery(tx.Model(PartnerInfoModel), queryOptions)
// query.SetWhere("partner_info.id = ?", "id")
// if err := query.First(); err != nil {
// return nil, query.HandleError(err, "没有此合伙人")
// }
// if PartnerInfoModel.Id == 0 {
// return nil, nil
// }
// return repository.transformPgModelToDomainModel(PartnerInfoModel)
// }
// func (repository *PartnerInfoRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.PartnerInfo, error) {
// tx := repository.transactionContext.PgTx
// var PartnerInfoModels []*models.PartnerInfo
// PartnerInfos := make([]*domain.PartnerInfo, 0)
// query := NewQuery(tx.Model(&PartnerInfoModels), queryOptions)
// query.
// SetWhere("partner_info.account = ?", "account").
// SetWhere(`partner_info.status = ?`, "status").
// SetWhere(`partner_info.partner_category = ?`, "partnerCategory").
// SetLimit().
// SetOrder("partner_info.create_at", "sortByCreateTime").
// SetOrder("partner_info.update_at", "sortByUpdateTime")
// var err error
// if query.AffectRow, err = query.SelectAndCount(); err != nil {
// return 0, PartnerInfos, err
// }
// for _, PartnerInfoModel := range PartnerInfoModels {
// if PartnerInfo, err := repository.transformPgModelToDomainModel(PartnerInfoModel); err != nil {
// return 0, PartnerInfos, err
// } else {
// PartnerInfos = append(PartnerInfos, PartnerInfo)
// }
// }
// return int64(query.AffectRow), PartnerInfos, nil
// }
... ... @@ -9,7 +9,7 @@ import (
var (
key []byte = []byte("sx87sda0w7x7sd")
JWtExpiresSecond int64 = 60 * 60 * 3
JWtExpiresSecond int64 = 60 * 60 * 12
)
//MyToken ...
... ...
package controllers
import (
"errors"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
)
type PartnerInfoController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *PartnerInfoController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok {
return
}
}
//CreatePartnerInfo 创建合伙人
func (controller *PartnerInfoController) CreatePartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &command.CreatePartnerInfoCommand{}
// )
// controller.JsonUnmarshal(command)
// controller.HandlerResponse(service.CreatePartnerInfo(command))
func (c *PartnerInfoController) CreatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
PartnerName string `json:"partnerName"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State string `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := partnerInfoCmd.CreatePartnerInfoCommand{}
serve := partnerInfoService.NewPartnerInfoService(nil)
serve.CreatePartnerInfo(&cmd)
c.ResponseData(nil)
return
}
//UpdatePartnerInfo 更新合伙人
func (controller *PartnerInfoController) UpdatePartnerInfo() {
func (c *PartnerInfoController) UpdatePartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &command.UpdatePartnerInfoCommand{}
... ... @@ -27,7 +67,7 @@ func (controller *PartnerInfoController) UpdatePartnerInfo() {
}
//GetPartnerInfo 获取合伙人
func (controller *PartnerInfoController) GetPartnerInfo() {
func (c *PartnerInfoController) GetPartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &query.GetPartnerInfoQuery{}
... ...