作者 陈志颖

refactor:优化共创项目详情查询条件

... ... @@ -10,7 +10,9 @@ import (
type GetCooperationProjectQuery struct {
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId" valid:"Required"`
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId"`
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ... @@ -22,7 +24,9 @@ type GetCooperationProjectQuery struct {
}
func (getCooperationProjectQuery *GetCooperationProjectQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
if getCooperationProjectQuery.CooperationProjectId == 0 && getCooperationProjectQuery.CooperationProjectNumber == "" {
validation.Error("共创项目ID和共创项目编号不能同时为空")
}
}
func (getCooperationProjectQuery *GetCooperationProjectQuery) ValidateQuery() error {
... ...
... ... @@ -222,7 +222,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
} else {
cooperationProjectRepository = value
}
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": getCooperationProjectQuery.CooperationProjectId})
cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuery))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -50,12 +50,6 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp
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)
}
if count, err := query.SelectAndCount(); err != nil {
return false, err
} else {
... ... @@ -65,6 +59,12 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
queryUndertaker := tx.Model(&cooperationContractUndertakerModels)
queryUndertaker.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber)
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, err2 := queryUndertaker.Exists()
return !ok, err2
}
... ...
... ... @@ -204,9 +204,11 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
cooperationProjectModel := new(models.CooperationProject)
query := sqlbuilder.BuildQuery(tx.Model(cooperationProjectModel), queryOptions)
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query.Where("cooperation_project_number = ?", cooperationProjectNumber)
query.Where("cooperation_project.cooperation_project_number = ?", cooperationProjectNumber)
}
if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
}
query.SetWhereByQueryOption("cooperation_project.cooperation_project_id = ?", "cooperationProjectId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -61,6 +61,8 @@ func (controller *CooperationProjectController) GetCooperationProject() {
getCooperationProjectQuery.UserBaseId = header.UserBaseId
cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
getCooperationProjectQuery.CooperationProjectId = cooperationProjectId
cooperationProjectNumber := controller.GetString("cooperationProjectNumber")
getCooperationProjectQuery.CooperationProjectNumber = cooperationProjectNumber
data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
controller.Response(data, err)
}
... ...