作者 唐旭辉

合伙人管理 完成

... ... @@ -7,7 +7,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
//AdminUserService 管理员相关服务
//AdminPermissionService 管理员权限
type AdminPermissionService struct {
}
... ... @@ -43,5 +43,6 @@ func (adminPermissionSrv AdminPermissionService) ListAdminPermission(queryOption
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return permissions, nil
}
... ...
... ... @@ -68,3 +68,12 @@ func CreateCompanyRepository(options map[string]interface{}) (domain.CompanyRepo
}
return repository.NewCompanyRepository(transactionContext)
}
// CreatePartnerCategoryRepository 合伙人分类数据
func CreatePartnerCategoryRepository(options map[string]interface{}) (domain.PartnerCategoryRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewPartnerCategoryRepository(transactionContext)
}
... ...
package query
type ListPartnerCategoryCommand struct {
}
... ...
package service
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type PartnerCategoryService struct {
}
func NewPartnerCategoryService(option map[string]interface{}) *PartnerCategoryService {
newService := new(PartnerCategoryService)
return newService
}
func (srv PartnerCategoryService) ListPartnerCategory(q query.ListPartnerCategoryCommand) (int, []domain.PartnerCategory, error) {
//实际业务
var err error
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
cnt int
)
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
cnt, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
if err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return cnt, categorys, nil
}
... ...
... ... @@ -16,25 +16,24 @@ type CreatePartnerInfoCommand struct {
Password string `json:"password,omitempty"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory,omitempty"`
// 合伙类别
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []domain.Salesman `json:"salesman,omitempty"`
//公司id
CompanyId int64 `json:"companyId"`
}
func (command CreatePartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_4) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
if len(command.PartnerCategory) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别必填")
}
if len(command.PartnerName) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人名称必填")
... ...
... ... @@ -7,16 +7,14 @@ import (
type StatusPartnerInfoCommand struct {
// 合伙人ID
Id int64 `json:"id"`
Status int `json:"status"`
Ids []int64 `json:"id"`
Status int `json:"status"`
CompanyId int64 `json:"companyId"`
}
func (command *StatusPartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
return nil
}
... ...
... ... @@ -13,25 +13,21 @@ type UpdatePartnerInfoCommand struct {
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory,omitempty"`
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []domain.Salesman `json:"salesman,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
//公司id
CompanyId int64 `json:"companyId"`
}
func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_3 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_4) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
}
if command.RegionInfo == nil {
return lib.ThrowError(lib.ARG_ERROR, "区域必填")
}
... ...
... ... @@ -2,7 +2,8 @@ package query
type GetPartnerInfoQuery struct {
// 合伙人ID
Id int64 `json:"id" `
Id int64 `json:"id" `
CompanyId int64 `json:"companyId"`
}
func (q *GetPartnerInfoQuery) ValidateQuery() error {
... ...
... ... @@ -7,6 +7,7 @@ type ListPartnerInfoQuery struct {
RegionInfo string `json:"regionInfo"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
CompanyId int64 `json:"companyId"`
// 查询偏离量
Offset int `json:"offset"`
// 查询限制
... ...
package service
import (
"fmt"
"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"
... ... @@ -19,12 +21,12 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
return newPartnerInfoService
}
// 创建客户价值
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command.CreatePartnerInfoCommand) (data interface{}, err error) {
// CreatePartnerInfo 创建合伙人
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data interface{}, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateCommand(); err != nil {
if err = cmd.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
... ... @@ -37,14 +39,12 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
var (
partnerinfoDao *dao.PartnerInfoDao
)
if v, err := factory.CreatePartnerInfoDao(map[string]interface{}{
if partnerinfoDao, 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)
ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
... ... @@ -52,37 +52,55 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "账号已存在")
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
newPartnerInfo := domain.PartnerInfo{
Partner: domain.Partner{
Account: command.Account,
PartnerName: command.PartnerName,
Account: cmd.Account,
PartnerName: cmd.PartnerName,
},
PartnerCategory: command.PartnerCategory,
Password: command.Password,
Status: command.Status,
RegionInfo: command.RegionInfo,
Salesman: command.Salesman,
CooperateTime: command.CooperateTime,
}
if data, err = PartnerInfoRepository.Save(newPartnerInfo); err != nil {
PartnerCategory: 0,
Password: cmd.Password,
Status: cmd.Status,
RegionInfo: cmd.RegionInfo,
Salesman: cmd.Salesman,
CooperateTime: cmd.CooperateTime,
CompanyId: cmd.CompanyId,
PartnerCategoryInfos: categorys,
}
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
return
return newPartnerInfo, nil
}
// GetPartnerInfo 返回合伙人
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateQuery(); err != nil {
if err = q.ValidateQuery(); err != nil {
return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
... ... @@ -91,26 +109,52 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPa
defer func() {
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
var (
PartnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
partnerData *domain.PartnerInfo
)
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})
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: q.Id})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if !partnerData.IsCompany(q.CompanyId) {
return nil, lib.ThrowError(lib.BUSINESS_ERROR, "企业信息异常操作")
}
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
categoryIds := []int64{}
for _, v := range partnerData.PartnerCategoryInfos {
categoryIds = append(categoryIds, v.Id)
}
if len(categoryIds) > 0 {
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: categoryIds,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
}
partnerData.PartnerCategoryInfos = categorys
err = transactionContext.CommitTransaction()
return
return partnerData, nil
}
//UpdatePartnerInfo 更新合伙人
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInfoCommand *command.UpdatePartnerInfoCommand) (err error) {
func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.UpdatePartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = updatePartnerInfoCommand.ValidateCommand(); err != nil {
if err = cmd.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
... ... @@ -119,24 +163,43 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInf
defer func() {
transactionContext.RollbackTransaction()
}()
var partnerInfoRepository domain.PartnerInfoRepository
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if categoryRepository, err = factory.CreatePartnerCategoryRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: updatePartnerInfoCommand.Id,
UserId: cmd.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
partnerInfo.CooperateTime = updatePartnerInfoCommand.CooperateTime
if _, err = partnerInfoRepository.Save(*partnerInfo); err != nil {
if !partnerInfo.IsCompany(cmd.CompanyId) {
return lib.ThrowError(lib.BUSINESS_ERROR, "异常操作")
}
partnerInfo.Salesman = cmd.Salesman
partnerInfo.Status = cmd.Status
partnerInfo.RegionInfo = cmd.RegionInfo
partnerInfo.CooperateTime = cmd.CooperateTime
partnerInfo.PartnerCategoryInfos = categorys
if err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
transactionContext.CommitTransaction()
... ... @@ -162,16 +225,24 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
transactionContext.RollbackTransaction()
}
}()
var partnerInfoRepository domain.PartnerInfoRepository
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if categoryRepository, err = factory.CreatePartnerCategoryRepository(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,
Offset: listPartnerInfoQuery.Offset,
Limit: listPartnerInfoQuery.Limit,
PartnerName: listPartnerInfoQuery.PartnerName,
}
if listPartnerInfoQuery.Partnertype > 0 {
... ... @@ -187,17 +258,37 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
if count, err = partnerInfoRepository.CountAll(queryOption); err != nil {
return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{})
if err != nil {
return count, partnerInfos, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
categorysMap := make(map[int64]domain.PartnerCategory)
for i := range categorys {
categorysMap[categorys[i].Id] = categorys[i]
}
for i := range partnerInfos {
categoryInPartner := []domain.PartnerCategory{}
for _, vv := range partnerInfos[i].PartnerCategoryInfos {
if categoryData, ok := categorysMap[vv.Id]; ok {
categoryInPartner = append(categoryInPartner, categoryData)
}
}
partnerInfos[i].PartnerCategoryInfos = categoryInPartner
}
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) {
func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) {
if len(cmd.Ids) == 0 {
return nil
}
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = command.ValidateCommand(); err != nil {
if err = cmd.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
... ... @@ -206,21 +297,18 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(command command.Statu
defer func() {
transactionContext.RollbackTransaction()
}()
var partnerInfoRepository domain.PartnerInfoRepository
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
var (
partnerinfoDao *dao.PartnerInfoDao
)
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: command.Id,
})
err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
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())
e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
transactionContext.CommitTransaction()
return
... ...
... ... @@ -142,7 +142,7 @@ func (service UsersService) GetUserPofile(userId int64) (interface{}, error) {
//buildUserPofile 组装前端需要的数据 ,用户登录后获取的配置
func (service UsersService) buildUserPofile(userData domain.Users, permissionList []domain.AdminPermission) map[string]interface{} {
menus := make([]map[string]interface{}, len(permissionList))
menus := make([]map[string]interface{}, 0, len(permissionList))
for _, v := range permissionList {
m := map[string]interface{}{
"code": v.Code,
... ... @@ -263,7 +263,7 @@ func (service UsersService) GetUserList(queryOption query.UserListQuery) (int, [
//buildGetUserList 组装构建前端需要的用户列表数据
func (service UsersService) buildGetUserList(usersData []domain.Users, permissionData []domain.AdminPermission) []map[string]interface{} {
result := make([]map[string]interface{}, len(usersData))
result := make([]map[string]interface{}, 0, len(usersData))
permissionMap := map[int64]domain.AdminPermission{}
for i := range permissionData {
permissionMap[permissionData[i].Id] = permissionData[i]
... ... @@ -366,12 +366,12 @@ func (service UsersService) buildGetUserData(userData *domain.Users, partnerList
if userData.IsUsable() {
result["status"] = 1
}
permissionIds := make([]int64, len(userData.Permission))
permissionIds := make([]int64, 0, len(userData.Permission))
for _, v := range userData.Permission {
permissionIds = append(permissionIds, v.Id)
}
result["permissionType"] = permissionIds
checkedPartner := make([]map[string]interface{}, len(partnerList))
checkedPartner := make([]map[string]interface{}, 0, len(partnerList))
for i := range partnerList {
m := map[string]interface{}{
"id": partnerList[i].Partner.Id,
... ... @@ -452,8 +452,8 @@ func (service UsersService) EditUserPermission(cmd command.EditUserPermissionCom
}
}
var (
partners = make([]domain.Partner, len(partnerList))
permissionsBase = make([]domain.AdminPermissionBase, len(permissionList))
partners = make([]domain.Partner, 0, len(partnerList))
permissionsBase = make([]domain.AdminPermissionBase, 0)
)
for i := range partnerList {
p := partnerList[i].Partner
... ...
... ... @@ -4,9 +4,9 @@ import "os"
var POSTGRESQL_DB_NAME = "partner_dev"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "postgres_15432"
var POSTGRESQL_HOST = "101.37.68.23"
var POSTGRESQL_PORT = "15432"
var POSTGRESQL_PASSWORD = "eagle1010"
var POSTGRESQL_HOST = "114.55.200.59"
var POSTGRESQL_PORT = "31543"
var DISABLE_CREATE_TABLE = true
var DISABLE_SQL_GENERATE_PRINT = false
... ...
package domain
// 合伙人分类信息
type PartnerCategoryInfo struct {
type PartnerCategory struct {
// 唯一标识
Id int64 `json:"id"`
// 名称
Name string `json:"name"`
}
type PartnerCategoryInfoRepository interface {
Find(queryOptions map[string]interface{}) (int64, []*PartnerCategoryInfo, error)
type PartnerCategoryFindQuery struct {
Ids []int64
}
type PartnerCategoryRepository interface {
Find(PartnerCategoryFindQuery) (int, []PartnerCategory, error)
}
... ...
... ... @@ -11,20 +11,20 @@ const (
)
//合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
const (
PARTNER_CATEGORY_1 int = 1
PARTNER_CATEGORY_2 int = 2
PARTNER_CATEGORY_3 int = 3
PARTNER_CATEGORY_4 int = 4
)
// const (
// PARTNER_CATEGORY_1 int = 1
// PARTNER_CATEGORY_2 int = 2
// PARTNER_CATEGORY_3 int = 3
// PARTNER_CATEGORY_4 int = 4
// )
//partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改)
var partnerCategoryMap = map[int]string{
PARTNER_CATEGORY_1: "事业合伙人",
PARTNER_CATEGORY_2: "业务合伙人",
PARTNER_CATEGORY_3: "研发合伙人",
PARTNER_CATEGORY_4: "业务-产品应用合伙人",
}
// //partnerCategoryMap 合伙类别键值对 (只读,请勿在运行时修改)
// var partnerCategoryMap = map[int]string{
// PARTNER_CATEGORY_1: "事业合伙人",
// PARTNER_CATEGORY_2: "业务合伙人",
// PARTNER_CATEGORY_3: "研发合伙人",
// PARTNER_CATEGORY_4: "业务-产品应用合伙人",
// }
type PartnerInfo struct {
Partner Partner `json:"partner"`
... ... @@ -43,25 +43,21 @@ type PartnerInfo struct {
//关联业务员
Salesman []Salesman `json:"salesman"`
//合伙人分类
PartnerCategoryInfos []PartnerCategoryInfo `json:"partnerCategoryInfos"`
PartnerCategoryInfos []PartnerCategory `json:"partnerCategoryInfos"`
//合伙类别
PartnerCategory int `json:"partnerCategory"`
//公司id
CompanyId int64 `json:"companyId"`
}
func (p *PartnerInfo) GetPartnerCategory() map[int]string {
categoryMap := map[int]string{}
if v, ok := partnerCategoryMap[p.PartnerCategory]; ok {
categoryMap[p.PartnerCategory] = v
}
return categoryMap
}
func (p *PartnerInfo) IsUsable() bool {
return p.Status == PARTNER_STATUS_YES
}
func (p *PartnerInfo) IsCompany(companyId int64) bool {
return p.CompanyId == companyId
}
type PartnerFindOneQuery struct {
UserId int64
AccountEqual string
... ... @@ -79,7 +75,7 @@ type PartnerFindQuery struct {
}
type PartnerInfoRepository interface {
Save(dm PartnerInfo) (*PartnerInfo, error)
Save(dm *PartnerInfo) error
FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error)
Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error)
CountAll(queryOptions PartnerFindQuery) (int, error)
... ...
... ... @@ -30,3 +30,14 @@ func (dao PartnerInfoDao) PartnerAccountExist(account string) (bool, error) {
return ok, err
}
func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, status int) error {
tx := dao.transactionContext.PgDd
m := &models.PartnerInfo{}
_, err := tx.Model(m).
WhereIn("id in (?)", ids).
Where("company_id=?", companyId).
Set("status=?", status).
Update()
return err
}
... ...
... ... @@ -33,7 +33,7 @@ type PartnerInfo struct {
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `pg:",default:1"` //partner_category
//合伙类别
PartnerCategoryInfos []PartnerCategoryInfo
PartnerCategoryInfos []struct{ Id int64 }
//公司id
CompanyId int64
}
... ...
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 PartnerCategoryRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) {
pc := domain.PartnerCategory{
Id: m.Id,
Name: m.Name,
}
return pc, nil
}
func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerCategoryRepository{transactionContext: transactionContext}, nil
}
func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCategoryFindQuery) (int, []domain.PartnerCategory, error) {
tx := repository.transactionContext.PgTx
var (
PartnerCategoryInfoModels []models.PartnerCategoryInfo
cnt int
err error
)
query := tx.Model(&PartnerCategoryInfoModels)
if len(queryOptions.Ids) > 0 {
query = query.WhereIn("id in(?)", queryOptions.Ids)
}
if cnt, err = query.SelectAndCount(); err != nil {
return 0, nil, err
}
partnerCategoryInfos := make([]domain.PartnerCategory, 0, len(PartnerCategoryInfoModels))
for i := range PartnerCategoryInfoModels {
m, _ := repository.transformPgModelToDomainModel(&PartnerCategoryInfoModels[i])
partnerCategoryInfos = append(partnerCategoryInfos, m)
}
return cnt, partnerCategoryInfos, nil
}
... ...
... ... @@ -3,6 +3,7 @@ package repository
import (
"fmt"
"github.com/go-pg/pg/v10/orm"
"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"
... ... @@ -32,6 +33,14 @@ func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerIn
CooperateTime: partnerInfoModel.CooperateTime,
CompanyId: partnerInfoModel.CompanyId,
}
p := []domain.PartnerCategory{}
for _, v := range partnerInfoModel.PartnerCategoryInfos {
catagory := domain.PartnerCategory{
Id: v.Id,
}
p = append(p, catagory)
}
m.PartnerCategoryInfos = p
return m, nil
}
... ... @@ -42,7 +51,7 @@ func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
func (repository *PartnerInfoRepository) Save(dm domain.PartnerInfo) (*domain.PartnerInfo, error) {
func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
var (
err error
tx = repository.transactionContext.PgTx
... ... @@ -58,23 +67,32 @@ func (repository *PartnerInfoRepository) Save(dm domain.PartnerInfo) (*domain.Pa
RegionInfo: dm.RegionInfo,
CooperateTime: dm.CooperateTime,
CompanyId: dm.CompanyId,
// PartnerCategoryInfos: dm.PartnerCategoryInfos,
}
categorys := []struct{ Id int64 }{}
for _, v := range dm.PartnerCategoryInfos {
temp := struct{ Id int64 }{
Id: v.Id,
}
categorys = append(categorys, temp)
}
m.PartnerCategoryInfos = categorys
if m.Id == 0 {
err = tx.Insert(m)
dm.Partner.Id = m.Id
if err != nil {
return nil, err
return err
}
} else {
_, err = tx.Model(m).WherePK().
Column("partner_name", "account", "password", "status", "partner_category", "salesman",
"region_info", "cooperate_time", "update_at").
"region_info", "cooperate_time", "update_at", "partner_category_infos").
Update()
if err != nil {
return nil, err
return err
}
}
return &dm, nil
return nil
}
func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFindOneQuery) (*domain.PartnerInfo, error) {
... ... @@ -107,8 +125,14 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
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)
query = query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
for _, value := range queryOption.PartnerCategory {
q = q.WhereOr(`partner_category_infos@> '{"id":?}'`, value)
}
return q, nil
})
}
if queryOption.CompanyId > 0 {
query = query.Where("company_id=?", queryOption.CompanyId)
... ... @@ -159,6 +183,9 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ
if queryOption.CompanyId > 0 {
query = query.Where("company_id=?", queryOption.CompanyId)
}
if len(queryOption.Ids) > 0 {
query = query.WhereIn("id in(?)", queryOption.Ids)
}
cnt, err := query.Count()
return cnt, err
}
... ...
... ... @@ -26,25 +26,26 @@ func NewUsersRepository(transactionContext *transaction.TransactionContext) (*Us
func (repository UsersRepository) transformPgModelToDomainModel(m *models.Users) (domain.Users, error) {
return domain.Users{
Id: m.Id,
CompanyId: m.CompanyId,
OpenId: m.OpenId,
Name: m.Name,
Sex: m.Sex,
JobNum: m.JobNum,
Phone: m.Phone,
PrivatePhone: m.PrivatePhone,
Email: m.Email,
ExtensionNum: m.ExtensionNum,
EntryTime: m.EntryTime,
Workspace: m.Workspace,
Status: m.Status,
Avatar: m.Avatar,
Remarks: m.Remarks,
ChargeStatus: m.ChargeStatus,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
Permission: m.Permission,
Id: m.Id,
CompanyId: m.CompanyId,
OpenId: m.OpenId,
Name: m.Name,
Sex: m.Sex,
JobNum: m.JobNum,
Phone: m.Phone,
PrivatePhone: m.PrivatePhone,
Email: m.Email,
ExtensionNum: m.ExtensionNum,
EntryTime: m.EntryTime,
Workspace: m.Workspace,
Status: m.Status,
Avatar: m.Avatar,
Remarks: m.Remarks,
ChargeStatus: m.ChargeStatus,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
Permission: m.Permission,
AccessPartners: m.AccessPartners,
}, nil
}
... ... @@ -117,7 +118,7 @@ func (reponsitory UsersRepository) FindOne(queryOptions domain.UsersFindOneQuery
m models.Users
)
query := tx.Model(&m)
query.Where("deleted_at ISNULL")
query.Where("delete_at ISNULL")
if queryOptions.Id > 0 {
query = query.Where("id=?", queryOptions.Id)
}
... ... @@ -141,7 +142,7 @@ func (reponsitory UsersRepository) Find(queryOption domain.UsersFindQuery) (int,
db := reponsitory.transactionContext.PgTx
usersModels := []models.Users{}
query := db.Model(&usersModels)
query.Where("deleted_at ISNULL")
query.Where("delete_at ISNULL")
if queryOption.CompanyId > 0 {
query = query.Where("company_id=?", queryOption.CompanyId)
}
... ...
package controllers
import (
categoryQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/query"
categoryService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/service"
partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
)
... ... @@ -41,3 +43,22 @@ func (c *CommonController) GetPartnerList() {
}
c.ResponseData(resp)
}
// GetPartnerCategory 下拉选项数据通用接口,获取合伙人分类列表
func (c *CommonController) GetPartnerCategory() {
newService := categoryService.NewPartnerCategoryService(nil)
_, categorys, err := newService.ListPartnerCategory(categoryQuery.ListPartnerCategoryCommand{})
if err != nil {
c.ResponseError(err)
return
}
resp := []map[string]interface{}{}
for i := range categorys {
m := map[string]interface{}{
"id": categorys[i].Id,
"name": categorys[i].Name,
}
resp = append(resp, m)
}
c.ResponseData(resp)
}
... ...
... ... @@ -35,14 +35,14 @@ func (c *PartnerInfoController) Prepare() {
func (c *PartnerInfoController) CreatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
PartnerName string `json:"partnerName"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
PartnerName string `json:"partnerName"`
PartnerType []int64 `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
}
var (
param Parameter
... ... @@ -93,13 +93,13 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
func (c *PartnerInfoController) UpdatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
ID int64 `json:"id"`
PartnerType []int64 `json:"partnerType"`
Area string `json:"area"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
}
var (
param Parameter
... ... @@ -156,9 +156,11 @@ func (c *PartnerInfoController) GetPartnerInfo() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
companyId := c.GetUserCompany()
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{
Id: param.Id,
Id: param.Id,
CompanyId: companyId,
})
if err != nil {
c.ResponseError(err)
... ... @@ -166,9 +168,9 @@ func (c *PartnerInfoController) GetPartnerInfo() {
}
//数据适配
rspResult := map[string]interface{}{
"account": partnerInfo.Partner.Account,
"partnerName": partnerInfo.Partner.PartnerName,
"partnerType": partnerInfo.PartnerCategory,
"account": partnerInfo.Partner.Account,
"partnerName": partnerInfo.Partner.PartnerName,
// "partnerType": []map[string]interface{}{},
"area": partnerInfo.RegionInfo.RegionName,
"salesmanName": "",
"phone": "",
... ... @@ -181,16 +183,24 @@ func (c *PartnerInfoController) GetPartnerInfo() {
rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
rspResult["phone"] = partnerInfo.Salesman[0].Telephone
}
partnerTypes := []map[string]interface{}{}
for _, v := range partnerInfo.PartnerCategoryInfos {
m := map[string]interface{}{
"id": v.Id,
"name": v.Name,
}
partnerTypes = append(partnerTypes, m)
}
rspResult["partnerType"] = partnerTypes
c.ResponseData(rspResult)
return
}
//PartnerInfoSetState 合伙人禁用启
//PartnerInfoSetState 合伙人批量禁
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
type Parameter struct {
Id int64 `json:"id"`
Status int `json:"status"`
Id []int64 `json:"id"`
}
var (
param Parameter
... ... @@ -201,20 +211,11 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
comanyId := c.GetUserCompany()
cmd := partnerInfoCmd.StatusPartnerInfoCommand{
Id: param.Id,
}
if param.Status == 1 {
//禁用操作
cmd.Status = domain.PARTNER_STATUS_NO
} else if param.Status == 2 {
//启用操作
cmd.Status = domain.PARTNER_STATUS_YES
} else {
//错误
c.ResponseError(lib.ThrowError(lib.ARG_ERROR, "状态错误"))
return
Ids: param.Id,
CompanyId: comanyId,
Status: domain.PARTNER_STATUS_NO,
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
err = newPartnerService.UpdateStatus(cmd)
... ... @@ -275,7 +276,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
"createTime": partners[i].CreateAt.Local().Format("2006-01-02 15:04:05"),
"cooperationTime": partners[i].CooperateTime.Local().Format("2006-01-02"),
"state": partners[i].Status,
"partnerType": partners[i].PartnerCategory,
"partnerType": partners[i].PartnerCategoryInfos,
"salesmanName": "",
"phone": "",
}
... ...
... ... @@ -17,7 +17,6 @@ func init() {
beego.NSRouter("/update", &controllers.UserController{}, "POST:EditUserPermission"),
beego.NSRouter("/detail", &controllers.UserController{}, "POST:GetUserData"),
beego.NSRouter("/list", &controllers.UserController{}, "POST:ListUser"),
// beego.NSRouter("/forbidden", &controllers.UserController{}, "POST:ForbiddenAdminUser"),
beego.NSRouter("/permission", &controllers.UserController{}, "POST:BeforeEditUser"),
),
beego.NSNamespace("/partners",
... ... @@ -25,7 +24,8 @@ func init() {
beego.NSRouter("/add", &controllers.PartnerInfoController{}, "POST:CreatePartnerInfo"),
beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
//beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
... ... @@ -41,13 +41,13 @@ func init() {
beego.NSRouter("/actual/list", &controllers.OrderInfoController{}, "POST:PageListOrderReal"),
beego.NSRouter("/actual/detail", &controllers.OrderInfoController{}, "POST:GetOrderReal"),
beego.NSRouter("/actual/del", &controllers.OrderInfoController{}, "POST:RemoveOrderReal"),
beego.NSRouter("/actual/update", &controllers.OrderInfoController{}, "POST:UpdateOrderReal"),
beego.NSRouter("/actual/close", &controllers.OrderInfoController{}, "POST:OrderDisable"),
),
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
beego.NSRouter("/partnerType", &controllers.CommonController{}, "POST:GetPartnerCategory"),
),
)
... ...
package routers
import (
"net/http"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
)
func init() {
beego.SetStaticPath("/log", constant.LOG_File)
//beego.SetStaticPath("/log", constant.LOG_File)
beego.Get("/log", func(ctx *context.Context) {
var s string
ctx.Input.Bind(&s, "id")
if s != "12345" {
ctx.Output.SetStatus(http.StatusBadRequest)
return
}
http.ServeFile(ctx.ResponseWriter, ctx.Request, constant.LOG_File)
return
})
}
... ...