作者 陈志颖

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

... ... @@ -365,14 +365,39 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
} else {
cooperationContractDao = value
}
// 获取可删除的承接对象类型
undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
// 可以去除勾选的承接人对象列表
var undertakerTypesUncheckedAvailable []int32
// 判断承接对象是否存在员工
gotUser, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationContractNumber": cooperationContract.CooperationContractNumber,
"cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes,
"user": true,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if !gotUser {
undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 1)
}
// 判断承接对象是否存在共创用户
gotPartner, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationContractNumber": cooperationContract.CooperationContractNumber,
"partner": true,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if !gotPartner {
undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 2)
}
// 判断承接人是否存在公开用户
if !gotUser && !gotPartner {
undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3)
}
cooperationContractDto := &dto.CooperationContractDto{}
if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -35,10 +35,28 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
}
}
// CheckUndertakerTypesUncheckedAvailable TODO 校验合约承接对象是否可以删除
func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {
return []int32{}, nil
// CheckUndertakerTypesUncheckedAvailable 校验合约承接对象是否可以删除
func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
query := tx.Model(&cooperationContractUndertakerModels)
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query = query.Where("cooperation_contract_number = ?", cooperationContractNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
}
if user, ok := queryOptions["user"]; ok && user.(bool) != false {
query = query.Where("user_type = ?", 1)
}
if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
query = query.Where("user_type = ?", 2)
}
ok, err := query.Exists()
return !ok, err
}
// CheckContractNumberAvailable 检验合约编号唯一性
... ...