Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…
…ion-cooperation into dev
正在显示
7 个修改的文件
包含
56 行增加
和
7 行删除
@@ -175,11 +175,20 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro | @@ -175,11 +175,20 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro | ||
175 | "orgId": createCooperationProjectCommand.OrgId, | 175 | "orgId": createCooperationProjectCommand.OrgId, |
176 | "cooperationProjectNumber": projectNumber, | 176 | "cooperationProjectNumber": projectNumber, |
177 | }) | 177 | }) |
178 | - // TODO 校验共创项目名称是否唯一 | ||
179 | - | ||
180 | if !numberAvailable { | 178 | if !numberAvailable { |
181 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常") | 179 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常") |
182 | } | 180 | } |
181 | + | ||
182 | + // 校验共创项目名称是否唯一 | ||
183 | + nameAvailable, _ := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{ | ||
184 | + "companyId": createCooperationProjectCommand.CompanyId, | ||
185 | + "orgId": createCooperationProjectCommand.OrgId, | ||
186 | + "cooperationProjectName": createCooperationProjectCommand.CooperationProjectName, | ||
187 | + }) | ||
188 | + if !nameAvailable { | ||
189 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目名称重复") | ||
190 | + } | ||
191 | + | ||
183 | newCooperationProject := &domain.CooperationProject{ | 192 | newCooperationProject := &domain.CooperationProject{ |
184 | CooperationProjectNumber: projectNumber, | 193 | CooperationProjectNumber: projectNumber, |
185 | CooperationProjectName: createCooperationProjectCommand.CooperationProjectName, | 194 | CooperationProjectName: createCooperationProjectCommand.CooperationProjectName, |
@@ -489,6 +498,16 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | @@ -489,6 +498,16 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | ||
489 | operator = data | 498 | operator = data |
490 | } | 499 | } |
491 | 500 | ||
501 | + // 共创项目DAO初始化 | ||
502 | + var cooperationProjectDao *dao.CooperationProjectDao | ||
503 | + if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{ | ||
504 | + "transactionContext": transactionContext, | ||
505 | + }); err != nil { | ||
506 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
507 | + } else { | ||
508 | + cooperationProjectDao = value | ||
509 | + } | ||
510 | + | ||
492 | // 获取发起人 | 511 | // 获取发起人 |
493 | var sponsor *domain.User | 512 | var sponsor *domain.User |
494 | // sponsorUid类型转换 | 513 | // sponsorUid类型转换 |
@@ -520,6 +539,18 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | @@ -520,6 +539,18 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro | ||
520 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId))) | 539 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId))) |
521 | } | 540 | } |
522 | 541 | ||
542 | + // 校验共创项目名称是否唯一 | ||
543 | + if cooperationProject.CooperationProjectName != updateCooperationProjectCommand.CooperationProjectName { | ||
544 | + nameAvailable, _ := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{ | ||
545 | + "companyId": updateCooperationProjectCommand.CompanyId, | ||
546 | + "orgId": updateCooperationProjectCommand.OrgId, | ||
547 | + "cooperationProjectName": updateCooperationProjectCommand.CooperationProjectName, | ||
548 | + }) | ||
549 | + if !nameAvailable { | ||
550 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目名称重复") | ||
551 | + } | ||
552 | + } | ||
553 | + | ||
523 | applicantTypes := make(map[int32]interface{}) | 554 | applicantTypes := make(map[int32]interface{}) |
524 | 555 | ||
525 | // 获取所有申请人 | 556 | // 获取所有申请人 |
@@ -104,6 +104,24 @@ func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[s | @@ -104,6 +104,24 @@ func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[s | ||
104 | return !ok, err | 104 | return !ok, err |
105 | } | 105 | } |
106 | 106 | ||
107 | +// CheckProjectNameAvailable 校验共创项目名称唯一 | ||
108 | +func (dao *CooperationProjectDao) CheckProjectNameAvailable(queryOptions map[string]interface{}) (bool, error) { | ||
109 | + tx := dao.transactionContext.PgTx | ||
110 | + var cooperationProjectModels []*models.CooperationProject | ||
111 | + query := tx.Model(&cooperationProjectModels) | ||
112 | + if cooperationProjectName, ok := queryOptions["cooperationProjectName"]; ok && cooperationProjectName != "" { | ||
113 | + query = query.Where("cooperation_project_name = ?", cooperationProjectName) | ||
114 | + } | ||
115 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
116 | + query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId) | ||
117 | + } | ||
118 | + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { | ||
119 | + query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId) | ||
120 | + } | ||
121 | + ok, err := query.Exists() | ||
122 | + return !ok, err | ||
123 | +} | ||
124 | + | ||
107 | func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) { | 125 | func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) { |
108 | if transactionContext == nil { | 126 | if transactionContext == nil { |
109 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 127 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | type CooperationContractUndertaker struct { | 8 | type CooperationContractUndertaker struct { |
9 | tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"` | 9 | tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"` |
10 | // 共创合约承接人id | 10 | // 共创合约承接人id |
11 | - CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk,unique"` | 11 | + CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk"` |
12 | // 共创合约编号 | 12 | // 共创合约编号 |
13 | CooperationContractNumber string `comment:"共创合约编号"` | 13 | CooperationContractNumber string `comment:"共创合约编号"` |
14 | // 共创合约承接人uid | 14 | // 共创合约承接人uid |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | type DividendsIncentivesRule struct { | 8 | type DividendsIncentivesRule struct { |
9 | tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"` | 9 | tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"` |
10 | // 分红规则ID | 10 | // 分红规则ID |
11 | - DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk,unique"` | 11 | + DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk"` |
12 | // 关联的项目合约编号 | 12 | // 关联的项目合约编号 |
13 | CooperationContractNumber string `comment:"关联的项目合约编号"` | 13 | CooperationContractNumber string `comment:"关联的项目合约编号"` |
14 | // 推荐人抽成比例 | 14 | // 推荐人抽成比例 |
@@ -10,7 +10,7 @@ type DividendsOrder struct { | @@ -10,7 +10,7 @@ type DividendsOrder struct { | ||
10 | // 分红订单ID | 10 | // 分红订单ID |
11 | DividendsOrderId int64 `comment:"分红订单ID" pg:",pk"` | 11 | DividendsOrderId int64 `comment:"分红订单ID" pg:",pk"` |
12 | // 分红订单号 | 12 | // 分红订单号 |
13 | - DividendsOrderNumber string `comment:"分红订单号" pg:",unique"` | 13 | + DividendsOrderNumber string `comment:"分红订单号"` |
14 | // 分红订单原单号 | 14 | // 分红订单原单号 |
15 | DividendsOriginalOrderNum string `comment:"分红订单原单号"` | 15 | DividendsOriginalOrderNum string `comment:"分红订单原单号"` |
16 | // 分红订单金额 | 16 | // 分红订单金额 |
@@ -10,7 +10,7 @@ type DividendsReturnedOrder struct { | @@ -10,7 +10,7 @@ type DividendsReturnedOrder struct { | ||
10 | // 分红退货单记录ID | 10 | // 分红退货单记录ID |
11 | DividendsReturnedOrderId int64 `comment:"分红退货单记录ID" pg:",pk"` | 11 | DividendsReturnedOrderId int64 `comment:"分红退货单记录ID" pg:",pk"` |
12 | // 分红退货单号 | 12 | // 分红退货单号 |
13 | - DividendsReturnedOrderNumber string `comment:"分红退货单号" pg:",unique"` | 13 | + DividendsReturnedOrderNumber string `comment:"分红退货单号"` |
14 | // 退货金额 | 14 | // 退货金额 |
15 | DividendsReturnedOrderRefund float64 `comment:"退货金额"` | 15 | DividendsReturnedOrderRefund float64 `comment:"退货金额"` |
16 | // 源单号(原始订单号) | 16 | // 源单号(原始订单号) |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | type MoneyIncentivesRule struct { | 8 | type MoneyIncentivesRule struct { |
9 | tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"` | 9 | tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"` |
10 | // 金额激励规则ID | 10 | // 金额激励规则ID |
11 | - MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk,unique"` | 11 | + MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk"` |
12 | // 关联的共创合约编号 | 12 | // 关联的共创合约编号 |
13 | CooperationContractNumber string `comment:"关联的共创合约编号"` | 13 | CooperationContractNumber string `comment:"关联的共创合约编号"` |
14 | // 激励金额 | 14 | // 激励金额 |
-
请 注册 或 登录 后发表评论