作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !10
... ... @@ -2,6 +2,7 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
... ... @@ -23,6 +24,8 @@ type UpdateCooperationProjectCommand struct {
PublisherUid string `cname:"共创项目发布人UID" json:"publisherUid" valid:"Required"`
// 共创项目描述
CooperationProjectDescription string `cname:"共创项目描述" json:"cooperationProjectDescription,omitempty"`
// 附件
Attachment []*domain.Attachment `cname:"共创项目附件" json:"attachment,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ... @@ -34,7 +37,6 @@ type UpdateCooperationProjectCommand struct {
}
func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateCooperationProjectCommand *UpdateCooperationProjectCommand) ValidateCommand() error {
... ...
... ... @@ -83,5 +83,8 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{}
if status, ok := data["status"]; ok {
cooperationProject.Status = status.(int32)
}
if attachment, ok := data["attachment"]; ok {
cooperationProject.Attachment = attachment.([]*Attachment)
}
return nil
}
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"time"
)
... ... @@ -234,6 +235,61 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in
return int64(count), cooperationContracts, nil
}
func (dao *CooperationContractDao) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
tx := dao.transactionContext.PgTx
cooperationContractModel := new(models.CooperationContract)
query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions)
query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId")
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("共创合约不存在")
} else {
return nil, err
}
}
if cooperationContractModel.CooperationContractId == 0 {
return nil, nil
} else {
var cooperationModeModels []*models.CooperationMode
cooperationModeQuery := tx.Model(&cooperationModeModels)
if countMode, err := cooperationModeQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
Limit(1).
SelectAndCount(); err != nil {
log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
"cooperationContractModel": cooperationContractModel,
})
} else {
if countMode > 0 {
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
var cooperationContractRelevantModels []*models.CooperationContractRelevant
return transform.TransformToCooperationContractDomainModelFromPgModels(
cooperationContractModel,
cooperationModeModels[0],
dividendsIncentivesRuleModels,
moneyIncentivesRuleModels,
cooperationContractRelevantModels,
cooperationContractUndertakerModels)
}
}
return nil, fmt.Errorf("共创合约不存在")
}
}
func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
)
type CooperationContractUndertakerDao struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string]interface{}) (int64, []*domain.CooperationContractUndertaker, error) {
tx := repository.transactionContext.PgTx
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakers := make([]*domain.CooperationContractUndertaker, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationContractUndertakerModels), queryOptions)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
newOrgIds := utils.SliceItoa(orgIds.([]int64))
query.Where("org->>'orgId' in (?)", pg.In(newOrgIds))
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
query.WhereOr("user_base_id = ? ", userBaseId)
query.WhereOr("referrer->>'userBaseId' = '?' ", userBaseId)
query.WhereOr("salesman->>'userBaseId' = '?' ", userBaseId)
return query, nil
})
}
offsetLimitFlag := true
if offsetLimit, ok := queryOptions["offsetLimit"]; ok {
offsetLimitFlag = offsetLimit.(bool)
}
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
query.SetOrderDirect("cooperation_contract_undertaker_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, cooperationContractUndertakers, err
} else {
for _, cooperationContractUndertakerModel := range cooperationContractUndertakerModels {
if cooperationContractUndertaker, err := transform.TransformToCooperationContractUndertakerDomainModelFromPgModels(cooperationContractUndertakerModel); err != nil {
return 0, cooperationContractUndertakers, err
} else {
cooperationContractUndertakers = append(cooperationContractUndertakers, cooperationContractUndertaker)
}
}
return int64(count), cooperationContractUndertakers, nil
}
}
func NewCooperationContractUndertakerDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractUndertakerDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractUndertakerDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
}
// 2.相关合约统计
cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
cooperationContractRelevantRepository, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
"limit": 1})
if err != nil {
... ... @@ -98,8 +98,8 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
queryOptions["limit"] = 10000 //TODO:合约数大于10000时?
cooperationContractUndertaker, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
_, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
if err != nil {
return nil, nil
... ...
... ... @@ -257,8 +257,23 @@ type searchContractDividendsResult struct {
//
// queryOptions 查询参数
func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
var request = struct {
//企业
CompanyId int64 `json:"companyId" valid:"Required"`
//OrgId int64 `json:"orgId"`
//UserId int64 `json:"userId"`
//个人
//UserBaseId int64 `json:"userBaseId"`
//Offset int `json:"offset"`
//Limit int `json:"limit"`
ContractId int `json:"contractId" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
// 1.合约详情
contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext)
if _, ok := queryOptions["contractId"]; !ok {
return nil, fmt.Errorf("合约ID(contractId)不能为空")
}
... ... @@ -294,15 +309,16 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
}
}
}
orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)
_, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})
if err != nil {
return res, err
}
var mapOrderGoods = make(map[int64]*domain.OrderGood)
for i := range orderGoods {
mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i]
if len(orderGoodIds) > 0 {
orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)
_, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})
if err != nil {
return res, err
}
for i := range orderGoods {
mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i]
}
}
var dividends = make([]interface{}, 0)
... ...