作者 yangfu

合约统计修改

@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
12 "time" 13 "time"
13 ) 14 )
14 15
@@ -234,6 +235,61 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in @@ -234,6 +235,61 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in
234 return int64(count), cooperationContracts, nil 235 return int64(count), cooperationContracts, nil
235 } 236 }
236 237
  238 +func (dao *CooperationContractDao) FindOne(queryOptions map[string]interface{}) (*domain.CooperationContract, error) {
  239 + tx := dao.transactionContext.PgTx
  240 + cooperationContractModel := new(models.CooperationContract)
  241 + query := sqlbuilder.BuildQuery(tx.Model(cooperationContractModel), queryOptions)
  242 + query.SetWhereByQueryOption("cooperation_contract.cooperation_contract_id = ?", "cooperationContractId")
  243 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  244 + query.Where("cooperation_contract.cooperation_contract_number = ?", cooperationContractNumber)
  245 + }
  246 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  247 + query.Where("company->>'companyId' = '?'", companyId)
  248 + }
  249 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  250 + query.Where("org->>'orgId' = '?'", orgId)
  251 + }
  252 + if err := query.First(); err != nil {
  253 + if err.Error() == "pg: no rows in result set" {
  254 + return nil, fmt.Errorf("共创合约不存在")
  255 + } else {
  256 + return nil, err
  257 + }
  258 + }
  259 + if cooperationContractModel.CooperationContractId == 0 {
  260 + return nil, nil
  261 + } else {
  262 + var cooperationModeModels []*models.CooperationMode
  263 + cooperationModeQuery := tx.Model(&cooperationModeModels)
  264 + if countMode, err := cooperationModeQuery.
  265 + Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
  266 + Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
  267 + Where("cooperation_mode_number = ?", cooperationContractModel.CooperationModeNumber).
  268 + Limit(1).
  269 + SelectAndCount(); err != nil {
  270 + log.Logger.Error("合约关联的共创模式不存在", map[string]interface{}{
  271 + "cooperationContractModel": cooperationContractModel,
  272 + })
  273 + } else {
  274 + if countMode > 0 {
  275 + // 获取分红激励规则列表
  276 + var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
  277 + var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
  278 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  279 + var cooperationContractRelevantModels []*models.CooperationContractRelevant
  280 + return transform.TransformToCooperationContractDomainModelFromPgModels(
  281 + cooperationContractModel,
  282 + cooperationModeModels[0],
  283 + dividendsIncentivesRuleModels,
  284 + moneyIncentivesRuleModels,
  285 + cooperationContractRelevantModels,
  286 + cooperationContractUndertakerModels)
  287 + }
  288 + }
  289 + return nil, fmt.Errorf("共创合约不存在")
  290 + }
  291 +}
  292 +
237 func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) { 293 func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
238 if transactionContext == nil { 294 if transactionContext == nil {
239 return nil, fmt.Errorf("transactionContext参数不能为nil") 295 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -257,8 +257,23 @@ type searchContractDividendsResult struct { @@ -257,8 +257,23 @@ type searchContractDividendsResult struct {
257 // 257 //
258 // queryOptions 查询参数 258 // queryOptions 查询参数
259 func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) { 259 func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
  260 + var request = struct {
  261 + //企业
  262 + CompanyId int64 `json:"companyId" valid:"Required"`
  263 + //OrgId int64 `json:"orgId"`
  264 + //UserId int64 `json:"userId"`
  265 + //个人
  266 + //UserBaseId int64 `json:"userBaseId"`
  267 + //Offset int `json:"offset"`
  268 + //Limit int `json:"limit"`
  269 + ContractId int `json:"contractId" valid:"Required"`
  270 + }{}
  271 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  272 + return nil, err
  273 + }
  274 + queryOptions = tool_funs.SimpleStructToMap(&request)
260 // 1.合约详情 275 // 1.合约详情
261 - contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext) 276 + contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext)
262 if _, ok := queryOptions["contractId"]; !ok { 277 if _, ok := queryOptions["contractId"]; !ok {
263 return nil, fmt.Errorf("合约ID(contractId)不能为空") 278 return nil, fmt.Errorf("合约ID(contractId)不能为空")
264 } 279 }
@@ -294,15 +309,16 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -294,15 +309,16 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
294 } 309 }
295 } 310 }
296 } 311 }
297 -  
298 - orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)  
299 - _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})  
300 - if err != nil {  
301 - return res, err  
302 - }  
303 var mapOrderGoods = make(map[int64]*domain.OrderGood) 312 var mapOrderGoods = make(map[int64]*domain.OrderGood)
304 - for i := range orderGoods {  
305 - mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i] 313 + if len(orderGoodIds) > 0 {
  314 + orderGoodRepository, _ := repository.NewOrderGoodRepository(ptr.transactionContext)
  315 + _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{"orderGoodIds": orderGoodIds})
  316 + if err != nil {
  317 + return res, err
  318 + }
  319 + for i := range orderGoods {
  320 + mapOrderGoods[orderGoods[i].OrderGoodId] = orderGoods[i]
  321 + }
306 } 322 }
307 323
308 var dividends = make([]interface{}, 0) 324 var dividends = make([]interface{}, 0)