作者 陈志颖

feat:增加合约可去除承接对象判断

@@ -365,14 +365,39 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont @@ -365,14 +365,39 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
365 } else { 365 } else {
366 cooperationContractDao = value 366 cooperationContractDao = value
367 } 367 }
368 - // 获取可删除的承接对象类型  
369 - undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{  
370 - "cooperationContractNumber": cooperationContract.CooperationContractNumber,  
371 - "cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes, 368 +
  369 + // 可以去除勾选的承接人对象列表
  370 + var undertakerTypesUncheckedAvailable []int32
  371 +
  372 + // 判断承接对象是否存在员工
  373 + gotUser, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
  374 + "cooperationContractNumber": cooperationContract.CooperationContractNumber,
  375 + "user": true,
  376 + })
  377 + if err != nil {
  378 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  379 + }
  380 + if !gotUser {
  381 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 1)
  382 + }
  383 +
  384 + // 判断承接对象是否存在共创用户
  385 + gotPartner, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
  386 + "cooperationContractNumber": cooperationContract.CooperationContractNumber,
  387 + "partner": true,
372 }) 388 })
373 if err != nil { 389 if err != nil {
374 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 390 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
375 } 391 }
  392 + if !gotPartner {
  393 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 2)
  394 + }
  395 +
  396 + // 判断承接人是否存在公开用户
  397 + if !gotUser && !gotPartner {
  398 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3)
  399 + }
  400 +
376 cooperationContractDto := &dto.CooperationContractDto{} 401 cooperationContractDto := &dto.CooperationContractDto{}
377 if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil { 402 if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil {
378 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 403 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -35,10 +35,28 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) { @@ -35,10 +35,28 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
35 } 35 }
36 } 36 }
37 37
38 -// CheckUndertakerTypesUncheckedAvailable TODO 校验合约承接对象是否可以删除  
39 -func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {  
40 -  
41 - return []int32{}, nil 38 +// CheckUndertakerTypesUncheckedAvailable 校验合约承接对象是否可以删除
  39 +func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) (bool, error) {
  40 + tx := dao.transactionContext.PgTx
  41 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  42 + query := tx.Model(&cooperationContractUndertakerModels)
  43 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  44 + query = query.Where("cooperation_contract_number = ?", cooperationContractNumber)
  45 + }
  46 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  47 + query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
  48 + }
  49 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  50 + query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
  51 + }
  52 + if user, ok := queryOptions["user"]; ok && user.(bool) != false {
  53 + query = query.Where("user_type = ?", 1)
  54 + }
  55 + if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
  56 + query = query.Where("user_type = ?", 2)
  57 + }
  58 + ok, err := query.Exists()
  59 + return !ok, err
42 } 60 }
43 61
44 // CheckContractNumberAvailable 检验合约编号唯一性 62 // CheckContractNumberAvailable 检验合约编号唯一性