作者 陈志颖

refactor:增加合伙人编号

正在显示 37 个修改的文件 包含 247 行增加264 行删除
appname = partnermg
runmode = "${RUN_MODE||dev}"
httpport = "${HTTP_PORT||8082}"
httpport = "${HTTP_PORT||8083}"
#开启监控
EnableAdmin = false
... ...
... ... @@ -4,7 +4,6 @@ go 1.14
require (
github.com/360EntSecGroup-Skylar/excelize/v2 v2.3.1
github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
github.com/Shopify/sarama v1.23.1
github.com/ajg/form v1.5.1 // indirect
github.com/astaxie/beego v1.12.2
... ...
... ... @@ -17,7 +17,7 @@ type CreatePartnerInfoCommand struct {
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
// 区域
... ... @@ -26,6 +26,8 @@ type CreatePartnerInfoCommand struct {
Salesman []domain.Salesman `json:"salesman,omitempty"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (command CreatePartnerInfoCommand) ValidateCommand() error {
... ...
/**
@author: stevechan
@date: 2020/12/29
@note:
**/
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
// 移除合伙人
type RemovePartnerInfoCommand struct {
// 合伙人Id
Id int64 `json:"id" valid:"Required"`
}
func (command *RemovePartnerInfoCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
return nil
}
... ...
... ... @@ -13,7 +13,7 @@ type UpdatePartnerInfoCommand struct {
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory []int64 `json:"partnerCategory,omitempty"`
PartnerCategory []*domain.PartnerCategory `json:"partnerCategory,omitempty"`
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
... ... @@ -22,6 +22,8 @@ type UpdatePartnerInfoCommand struct {
CooperateTime time.Time `json:"cooperateTime"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
... ...
... ... @@ -2,11 +2,12 @@ package query
type ListPartnerInfoQuery struct {
// 合伙人类别
Partnertype int `json:"partnerType"`
PartnerType int `json:"partnerType"`
//所属区域
RegionInfo string `json:"regionInfo"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 公司id
CompanyId int64 `json:"companyId"`
// 查询偏离量
Offset int `json:"offset"`
... ... @@ -15,6 +16,5 @@ type ListPartnerInfoQuery struct {
}
func (q *ListPartnerInfoQuery) ValidateQuery() error {
return nil
}
... ...
... ... @@ -21,7 +21,13 @@ func NewPartnerInfoService(options map[string]interface{}) *PartnerInfoService {
return newPartnerInfoService
}
// CreatePartnerInfo 创建合伙人
/**
* @Author SteveChan
* @Description //TODO 创建合伙人,判断编号是否重复
* @Date 15:42 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.CreatePartnerInfoCommand) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -35,16 +41,17 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
defer func() {
transactionContext.RollbackTransaction()
}()
//检查账号是否存在
var (
partnerinfoDao *dao.PartnerInfoDao
partnerInfoDao *dao.PartnerInfoDao
)
if partnerinfoDao, 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())
}
ok, err := partnerinfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
ok, err := partnerInfoDao.PartnerAccountExist(cmd.Account, cmd.CompanyId)
if err != nil {
return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
... ... @@ -55,7 +62,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -67,13 +74,18 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
var ids []int64
for _, partnerCategory := range cmd.PartnerCategory {
ids = append(ids, partnerCategory.Id)
}
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: ids,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
newPartnerInfo := domain.PartnerInfo{
Partner: domain.Partner{
Account: cmd.Account,
... ... @@ -86,7 +98,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
Salesman: cmd.Salesman,
CooperateTime: cmd.CooperateTime,
CompanyId: cmd.CompanyId,
PartnerCategoryInfos: categorys,
PartnerCategoryInfos: categories,
}
if err = partnerInfoRepository.Save(&newPartnerInfo); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -106,7 +118,13 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(cmd *command.Cre
return &newPartnerInfo, nil
}
// GetPartnerInfo 返回合伙人
/**
* @Author SteveChan
* @Description //TODO 返回合伙人,增加合伙人编号字段
* @Date 15:43 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -123,7 +141,7 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
var (
PartnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
partnerData *domain.PartnerInfo
)
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
... ... @@ -145,19 +163,19 @@ func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(q query.GetPartnerI
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
categoryIds := []int64{}
var categoryIds []int64
for _, v := range partnerData.PartnerCategoryInfos {
categoryIds = append(categoryIds, v.Id)
}
if len(categoryIds) > 0 {
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
_, categories, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: categoryIds,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
}
partnerData.PartnerCategoryInfos = categorys
partnerData.PartnerCategoryInfos = categories
err = transactionContext.CommitTransaction()
return partnerData, nil
}
... ... @@ -191,15 +209,20 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(cmd *command.Upd
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var ids []int64
for _, partnerCategory := range cmd.PartnerCategory {
ids = append(ids, partnerCategory.Id)
}
_, categorys, err = categoryRepository.Find(domain.PartnerCategoryFindQuery{
Ids: cmd.PartnerCategory,
Ids: ids,
})
if err != nil {
e := fmt.Sprintf("获取合伙人分类数据失败:%s", err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
partnerInfo, err := partnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: cmd.Id, CompanyId: cmd.CompanyId,
UserId: cmd.Id,
CompanyId: cmd.CompanyId,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -246,14 +269,13 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
partnerInfoRepository domain.PartnerInfoRepository
categoryRepository domain.PartnerCategoryRepository
categorys []domain.PartnerCategory
categories []domain.PartnerCategory
)
if partnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -271,8 +293,8 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
PartnerName: listPartnerInfoQuery.PartnerName,
CompanyId: listPartnerInfoQuery.CompanyId,
}
if listPartnerInfoQuery.Partnertype > 0 {
queryOption.PartnerCategory = []int{listPartnerInfoQuery.Partnertype}
if listPartnerInfoQuery.PartnerType > 0 {
queryOption.PartnerCategory = []int{listPartnerInfoQuery.PartnerType}
}
// RegionInfo
if len(listPartnerInfoQuery.RegionInfo) > 0 {
... ... @@ -284,18 +306,18 @@ 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{})
_, categories, 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]
categoriesMap := make(map[int64]domain.PartnerCategory)
for i := range categories {
categoriesMap[categories[i].Id] = categories[i]
}
for i := range partnerInfos {
categoryInPartner := []domain.PartnerCategory{}
var categoryInPartner []domain.PartnerCategory
for _, vv := range partnerInfos[i].PartnerCategoryInfos {
if categoryData, ok := categorysMap[vv.Id]; ok {
if categoryData, ok := categoriesMap[vv.Id]; ok {
categoryInPartner = append(categoryInPartner, categoryData)
}
}
... ... @@ -307,6 +329,30 @@ func (PartnerInfoService *PartnerInfoService) ListPartnerInfo(listPartnerInfoQue
return count, partnerInfos, nil
}
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 16:40 2020/12/29
* @Param
* @return
**/
func (PartnerInfoService *PartnerInfoService) RemovePartnerInfo(cmd command.RemovePartnerInfoCommand) (err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
if err = cmd.ValidateCommand(); err != nil {
return application.ThrowError(application.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
transactionContext.RollbackTransaction()
}()
return nil
}
func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPartnerInfoCommand) (err error) {
if len(cmd.Ids) == 0 {
return nil
... ... @@ -324,14 +370,14 @@ func (PartnerInfoService *PartnerInfoService) UpdateStatus(cmd command.StatusPar
transactionContext.RollbackTransaction()
}()
var (
partnerinfoDao *dao.PartnerInfoDao
partnerInfoDao *dao.PartnerInfoDao
)
if partnerinfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
if partnerInfoDao, err = factory.CreatePartnerInfoDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
err = partnerinfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
err = partnerInfoDao.UpdatePartnerStatus(cmd.Ids, cmd.CompanyId, cmd.Status)
if err != nil {
e := fmt.Sprintf("更新合伙人(id=%v)的数据失败;%s", cmd.Ids, err)
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
... ...
... ... @@ -8,14 +8,14 @@ var LOG_LEVEL = "debug"
var LOG_File = "./logs/partnermg.log"
var (
UCENTER_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" //统一用户中心地址
UCENTER_HOST = "https://suplus-ucenter-test.fjmaimaimai.com" //统一用户中心地址
UCENTER_SECRET = "cykbjnfqgctn"
UCENTER_APP_KEY = "39aefef9e22744a3b2d2d3791824ae7b"
UCENTER_CHECK_ALT = "rsF0pL!6DwjBO735"
)
var (
BUSINESS_ADMIN_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com" //企业平台的地址
BUSINESS_ADMIN_HOST = "http://suplus-business-admin-test.fjmaimaimai.com" //企业平台的地址
)
func init() {
... ... @@ -34,9 +34,7 @@ func init() {
if os.Getenv("UCENTER_CHECK_ALT") != "" {
UCENTER_CHECK_ALT = os.Getenv("UCENTER_CHECK_ALT")
}
if os.Getenv("BUSINESS_ADMIN_HOST") != "" {
BUSINESS_ADMIN_HOST = os.Getenv("BUSINESS_ADMIN_HOST")
}
}
... ...
... ... @@ -14,7 +14,7 @@ var KafkaCfg KafkaConfig
func init() {
KafkaCfg = KafkaConfig{
Servers: []string{""},
Servers: []string{"127.0.0.1:9092"},
ConsumerId: "partnermg_local",
}
if os.Getenv("KAFKA_HOST") != "" {
... ...
... ... @@ -2,7 +2,7 @@ package constant
import "os"
var POSTGRESQL_DB_NAME = "partner_dev"
var POSTGRESQL_DB_NAME = "partner_test"
var POSTGRESQL_USER = "postgres"
var POSTGRESQL_PASSWORD = "eagle1010"
var POSTGRESQL_HOST = "114.55.200.59"
... ...
... ... @@ -114,7 +114,7 @@ type OrderBase struct {
DataFrom OrderDataFrom `json:"dataFrom"`
//备注
Remark OrderBaseRemark `json:"remark"`
//合伙人类型
PartnerCategory PartnerCategory `json:"partnerCategory"`
}
... ...
... ... @@ -6,6 +6,8 @@ type PartnerCategory struct {
Id int64 `json:"id"`
// 名称
Name string `json:"name,omitempty"`
// 合伙人编码
Code string `json:"code"`
}
type PartnerCategoryFindQuery struct {
... ...
... ... @@ -48,6 +48,8 @@ type PartnerInfo struct {
PartnerCategory int `json:"partnerCategory"`
//公司id
CompanyId int64 `json:"companyId"`
//备注
Remark string `json:"remark"`
}
func (p *PartnerInfo) IsUsable() bool {
... ... @@ -78,5 +80,6 @@ type PartnerInfoRepository interface {
Save(dm *PartnerInfo) error
FindOne(queryOptions PartnerFindOneQuery) (*PartnerInfo, error)
Find(queryOptions PartnerFindQuery) ([]PartnerInfo, error)
Remove(Id int64) error
CountAll(queryOptions PartnerFindQuery) (int, error)
}
... ...
... ... @@ -42,3 +42,14 @@ func (dao PartnerInfoDao) UpdatePartnerStatus(ids []int64, companyId int64, stat
Update()
return err
}
/**
* @Author SteveChan
* @Description //TODO 编号查重
* @Date 17:55 2020/12/28
* @Param
* @return
**/
func (dao PartnerInfoDao) CheckDuplication() {
}
... ...
... ... @@ -7,4 +7,6 @@ type PartnerCategoryInfo struct {
Id int64
// 名称
Name string
// 合伙人编码
Code string
}
... ...
... ... @@ -36,6 +36,8 @@ type PartnerInfo struct {
PartnerCategoryInfos []domain.PartnerCategory
//公司id
CompanyId int64
//备注
Remark string
}
var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil)
... ...
... ... @@ -12,21 +12,6 @@ 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 (
... ... @@ -48,3 +33,19 @@ func (repository PartnerCategoryRepository) Find(queryOptions domain.PartnerCate
}
return cnt, partnerCategoryInfos, nil
}
func (repository PartnerCategoryRepository) transformPgModelToDomainModel(m *models.PartnerCategoryInfo) (domain.PartnerCategory, error) {
pc := domain.PartnerCategory{
Id: m.Id,
Name: m.Name,
Code: m.Code,
}
return pc, nil
}
func NewPartnerCategoryRepository(transactionContext *transaction.TransactionContext) (*PartnerCategoryRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerCategoryRepository{transactionContext: transactionContext}, nil
}
... ...
... ... @@ -18,50 +18,18 @@ var (
_ domain.PartnerInfoRepository = (*PartnerInfoRepository)(nil)
)
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) {
m := domain.PartnerInfo{
Partner: domain.Partner{
Id: partnerInfoModel.Id,
PartnerName: partnerInfoModel.PartnerName,
Account: partnerInfoModel.Account,
},
PartnerCategory: partnerInfoModel.PartnerCategory,
Password: partnerInfoModel.Password,
Status: partnerInfoModel.Status,
CreateAt: partnerInfoModel.CreateAt,
Salesman: partnerInfoModel.Salesman,
RegionInfo: partnerInfoModel.RegionInfo,
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
}
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) error {
var (
err error
tx = repository.transactionContext.PgTx
)
categorys := []domain.PartnerCategory{}
var categories []domain.PartnerCategory
for _, v := range dm.PartnerCategoryInfos {
categorys = append(categorys, domain.PartnerCategory{
categories = append(categories, domain.PartnerCategory{
Id: v.Id,
Name: v.Name,
Code: v.Code,
})
}
m := &models.PartnerInfo{
... ... @@ -75,7 +43,8 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
RegionInfo: dm.RegionInfo,
CooperateTime: dm.CooperateTime,
CompanyId: dm.CompanyId,
PartnerCategoryInfos: categorys,
PartnerCategoryInfos: categories,
Remark: dm.Remark,
}
if m.Id == 0 {
err = tx.Insert(m)
... ... @@ -86,7 +55,7 @@ func (repository *PartnerInfoRepository) Save(dm *domain.PartnerInfo) error {
} else {
_, err = tx.Model(m).WherePK().
Column("partner_name", "account", "password", "status", "partner_category", "salesman",
"region_info", "cooperate_time", "update_at", "partner_category_infos").
"region_info", "cooperate_time", "update_at", "partner_category_infos, remark").
Update()
if err != nil {
return err
... ... @@ -124,7 +93,7 @@ func (repository *PartnerInfoRepository) FindOne(queryOptions domain.PartnerFind
func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuery) ([]domain.PartnerInfo, error) {
db := repository.transactionContext.PgTx
partnerModels := []models.PartnerInfo{}
var partnerModels []models.PartnerInfo
query := db.Model(&partnerModels)
if len(queryOption.PartnerName) > 0 {
query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%")
... ... @@ -174,7 +143,28 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
return partnerReturn, nil
}
func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 15:33 2020/12/29
* @Param
* @return
**/
func (repository *PartnerInfoRepository) Remove(id int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.PartnerInfo{
Id: id,
}
_, err = tx.Model(m).
Where("id=?", id).
Delete()
return err
}
func (repository *PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQuery) (int, error) {
db := repository.transactionContext.PgTx
partnerModels := models.PartnerInfo{}
query := db.Model(&partnerModels)
... ... @@ -202,3 +192,40 @@ func (repository PartnerInfoRepository) CountAll(queryOption domain.PartnerFindQ
cnt, err := query.Count()
return cnt, err
}
func (repository *PartnerInfoRepository) transformPgModelToDomainModel(partnerInfoModel *models.PartnerInfo) (domain.PartnerInfo, error) {
m := domain.PartnerInfo{
Partner: domain.Partner{
Id: partnerInfoModel.Id,
PartnerName: partnerInfoModel.PartnerName,
Account: partnerInfoModel.Account,
},
PartnerCategory: partnerInfoModel.PartnerCategory,
Password: partnerInfoModel.Password,
Status: partnerInfoModel.Status,
CreateAt: partnerInfoModel.CreateAt,
Salesman: partnerInfoModel.Salesman,
RegionInfo: partnerInfoModel.RegionInfo,
CooperateTime: partnerInfoModel.CooperateTime,
CompanyId: partnerInfoModel.CompanyId,
Remark: partnerInfoModel.Remark,
}
var p []domain.PartnerCategory
for _, v := range partnerInfoModel.PartnerCategoryInfos {
category := domain.PartnerCategory{
Id: v.Id,
Name: v.Name,
Code: v.Code,
}
p = append(p, category)
}
m.PartnerCategoryInfos = p
return m, nil
}
func NewPartnerInfoRepository(transactionContext *transaction.TransactionContext) (*PartnerInfoRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &PartnerInfoRepository{transactionContext: transactionContext}, nil
}
... ...
... ... @@ -36,7 +36,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
PartnerName string `json:"partnerName"`
PartnerType []int64 `json:"partnerType"`
PartnerType []*domain.PartnerCategory `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State int `json:"state"`
... ... @@ -104,7 +104,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerType []int64 `json:"partnerType"`
PartnerType []*domain.PartnerCategory `json:"partnerType"`
Area string `json:"area"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
... ... @@ -195,11 +195,12 @@ func (c *PartnerInfoController) GetPartnerInfo() {
rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
rspResult["phone"] = partnerInfo.Salesman[0].Telephone
}
partnerTypes := []map[string]interface{}{}
var partnerTypes []map[string]interface{}
for _, v := range partnerInfo.PartnerCategoryInfos {
m := map[string]interface{}{
"id": v.Id,
"name": v.Name,
"code": v.Code,
}
partnerTypes = append(partnerTypes, m)
}
... ... @@ -208,6 +209,17 @@ func (c *PartnerInfoController) GetPartnerInfo() {
return
}
/**
* @Author SteveChan
* @Description //TODO 移除合伙人
* @Date 15:31 2020/12/29
* @Param
* @return
**/
func (c *PartnerInfoController) RemovePartnerInfo() {
}
//PartnerInfoSetState 合伙人批量禁用.启用
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
... ... @@ -224,19 +236,19 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
comanyId := c.GetUserCompany()
companyId := c.GetUserCompany()
var cmd partnerInfoCmd.StatusPartnerInfoCommand
switch param.Status {
case 0:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
CompanyId: companyId,
Status: domain.PARTNER_STATUS_NO,
}
case 1:
cmd = partnerInfoCmd.StatusPartnerInfoCommand{
Ids: param.Id,
CompanyId: comanyId,
CompanyId: companyId,
Status: domain.PARTNER_STATUS_YES,
}
default:
... ... @@ -256,7 +268,7 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
//ListPartnerInfo 合伙人列表
func (c *PartnerInfoController) ListPartnerInfo() {
type Parameter struct {
Partnertype int `json:"partnerType"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
PartnerName string `json:"partnerName"`
PageSize int `json:"pageSize"`
... ... @@ -280,7 +292,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
}
companyId := c.GetUserCompany()
query := partnerQuery.ListPartnerInfoQuery{
Partnertype: param.Partnertype,
PartnerType: param.PartnerType,
PartnerName: param.PartnerName,
RegionInfo: param.Area,
Limit: param.PageSize,
... ... @@ -294,7 +306,7 @@ func (c *PartnerInfoController) ListPartnerInfo() {
c.ResponseError(err)
return
}
resp := []map[string]interface{}{}
var resp []map[string]interface{}
indexBegin := query.Offset
for i := range partners {
m := map[string]interface{}{
... ...
... ... @@ -32,7 +32,7 @@ func (c *UserController) ListUser() {
//用与适配前端定义的数据结构
type Paramter struct {
SearchText string `json:"searchText"`
PageSize int `json::"pageSize"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
... ...
... ... @@ -23,6 +23,7 @@ func init() {
beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
beego.NSRouter("/batchDisabled", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
beego.NSRouter("/:id", &controllers.PartnerInfoController{}, "DELETE:RemovePartnerInfo"),
),
beego.NSNamespace("/dividends",
beego.NSRouter("/list", &controllers.OrderDividendController{}, "POST:PageListOrderDividend"),
... ...
... ... @@ -51,6 +51,7 @@ func (c *MessageConsumer) ConsumeClaim(groupSession sarama.ConsumerGroupSession,
}
if err = topicHandle(message); err != nil {
logs.Error("Message claimed: kafka消息处理错误 topic =", message.Topic, message.Offset, err)
}
groupSession.MarkMessage(message, "")
}
... ...
... ... @@ -30,6 +30,9 @@ func init() {
if runEnv == "partnermg_prd" {
initHandleRoutersProd()
}
if runEnv == "partnermg_dev" {
initHandleRoutersDev()
}
}
func initHandleRoutersTest() {
... ... @@ -39,3 +42,7 @@ func initHandleRoutersTest() {
func initHandleRoutersProd() {
TopicHandleRouters["xiangmi_project"] = handles.DataFromXiangMi
}
func initHandleRoutersDev() {
TopicHandleRouters["xiangmi_project_dev"] = handles.DataFromXiangMi
}
\ No newline at end of file
... ...
package geetest
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
type GeetestLib struct {
CaptchaID string
PrivateKey string
Client *http.Client
}
type FailbackRegisterRespnse struct {
Success int `json:"success"`
GT string `json:"gt"`
Challenge string `json:"challenge"`
NewCaptcha int `json:"new_captcha"`
}
const (
geetestHost = "http://api.geetest.com"
registerURL = geetestHost + "/register.php"
validateURL = geetestHost + "/validate.php"
)
func MD5Encode(input string) string {
md5Instant := md5.New()
md5Instant.Write([]byte(input))
return hex.EncodeToString(md5Instant.Sum(nil))
}
// 初始化 GeetestLib
func NewGeetestLib(capthcaID string, privateKey string, timeOut time.Duration) (geetest GeetestLib){
client := &http.Client{Timeout: timeOut}
geetest = GeetestLib{capthcaID, privateKey, client}
return
}
func (g *GeetestLib) getFailBackRegisterResponse(success int, challenge string) []byte {
if challenge == "" {
challenge = hex.EncodeToString(md5.New().Sum(nil))
}
response := FailbackRegisterRespnse{
success,
g.CaptchaID,
challenge,
1,
}
res, _ := json.Marshal(response)
return res
}
func (g *GeetestLib) do(req *http.Request) (body []byte, err error) {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
var resp *http.Response
if resp, err = g.Client.Do(req); err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode >= http.StatusInternalServerError {
err = errors.New("http status code 5xx")
return
}
if body, err = ioutil.ReadAll(resp.Body); err != nil {
return
}
return
}
func (g *GeetestLib) PreProcess(userID string, userIP string) (int8, []byte) {
params := url.Values{}
params.Add("gt", g.CaptchaID)
params.Add("new_captcha", "1")
if userID != "" {
params.Add("user_id", userID)
}
if userIP != "" {
params.Add("ip_adress", userIP)
}
req, _ := http.NewRequest("GET", registerURL+"?"+params.Encode(), nil)
body, err := g.do(req)
if err != nil {
return 0, g.getFailBackRegisterResponse(0, "")
}
challenge := string(body)
if len(challenge) != 32 {
return 0, g.getFailBackRegisterResponse(0, "")
} else {
challenge = MD5Encode(challenge + g.PrivateKey)
return 1, g.getFailBackRegisterResponse(1, challenge)
}
}
func (g *GeetestLib) checkParas(challenge string, validate string, seccode string) bool {
if challenge == "" || validate == "" || seccode == "" {
return false
}
return true
}
func (g *GeetestLib) checkSuccessRes(challenge string, validate string) bool {
return MD5Encode(g.PrivateKey+"geetest"+challenge) == validate
}
func (g *GeetestLib) checkFailbackRes(challenge string, validate string) bool {
return MD5Encode(challenge) == validate
}
func (g *GeetestLib) SuccessValidate(challenge string, validate string, seccode string, userID string, userIP string) bool {
if !g.checkParas(challenge, validate, seccode) {
return false
}
if !g.checkSuccessRes(challenge, validate) {
return false
}
params := url.Values{}
params.Add("seccode", seccode)
params.Add("challenge", challenge)
params.Add("captchaid", g.CaptchaID)
params.Add("sdk", "golang_v1.0.0")
if userID != "" {
params.Add("user_id", userID)
}
if userIP != "" {
params.Add("ip_adress", userIP)
}
req, _ := http.NewRequest("POST", validateURL, strings.NewReader(params.Encode()))
body, err := g.do(req)
if err != nil {
return false
}
res := string(body)
return res == MD5Encode(seccode)
}
func (g *GeetestLib) FailbackValidate(challenge string, validate string, seccode string) bool {
if !g.checkParas(challenge, validate, seccode) {
return false
}
if !g.checkFailbackRes(challenge, validate) {
return false
}
return true
}
... ... @@ -3,9 +3,6 @@
github.com/360EntSecGroup-Skylar/excelize/v2
# github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798
github.com/DataDog/zstd
# github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
## explicit
github.com/GeeTeam/gt3-golang-sdk/geetest
# github.com/Shopify/sarama v1.23.1
## explicit
github.com/Shopify/sarama
... ...