|
@@ -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")
|