作者 yangfu

共创项目详情功能 - 附件获取

... ... @@ -65,6 +65,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationProjectSharedInfo:
res, err = statisticsService.PersonCooperationProjectSharedInfo(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationProjectSharedInfoAttachment:
res, err = statisticsService.PersonCooperationProjectSharedInfoAttachment(contractStatisticsQuery.QueryOptions)
case domain_service.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.RelevantCooperationContractNumbers:
... ...
... ... @@ -107,3 +107,15 @@ func ConditionInContractNumbers(numbers []string) string {
//}
//return fmt.Sprintf("account_detail <@'%v'", json.MarshalToString(response))
}
func ConditionInDividendsEstimateOrderIds(ids []int64) string {
var sqlBuilder = bytes.NewBuffer(nil)
l := len(ids)
for i := range ids {
sqlBuilder.WriteString(fmt.Sprintf(`account_detail @> '[{"dividendsEstimateOrderId":%v}]' `, ids[i]))
if i < (l - 1) {
sqlBuilder.WriteString(" OR ")
}
}
return sqlBuilder.String()
}
... ...
... ... @@ -395,6 +395,7 @@ func (ptr *CooperationStatisticsService) CompanyCooperationProjectContracts(quer
// func(ptr *CooperationStatisticsService)
// 个人 - 共创浏览 详情页 - 附件数据
// response,error 有可能同时为空,返回需要判断
func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttachment(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
... ... @@ -402,16 +403,96 @@ func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttac
// 用户
UserId int64 `json:"userId" valid:"Required"`
// 项目ID
ProjectId int64 `json:"projectId" valid:"Required"`
ProjectId int64 `json:"cooperationProjectId" valid:"Required"`
// 合约ID
ContractId int64 `json:"contractId" valid:"Required"`
ContractId int64 `json:"cooperationContractId" valid:"Required"`
// 附件类型 1:合约附件 2:支付凭证
AttachType int `json:"attachType" valid:"Required"`
AttachmentType int `json:"attachmentType" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
var response = domain.CooperationProjectSharedInfoDto{}
var response = struct {
Attachment *domain.Attachment `json:"attachment"`
UserBaseId int64 `json:"userBaseId"`
}{}
userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
userDetail, e := userServiceGateway.GetUser(0, 0, request.UserId)
if e != nil {
return nil, e
}
request.UserBaseId = userDetail.UserBaseId
response.UserBaseId = userDetail.UserBaseId
switch request.AttachmentType {
case 1:
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
contracts, err := contractRepository.FindOne(map[string]interface{}{"cooperationContractId": request.ContractId})
if err != nil {
return nil, fmt.Errorf("合约不存在")
}
undertakerRepository, _ := dao.NewCooperationContractUndertakerDao(ptr.transactionContext)
_, undertakers, err := undertakerRepository.Find(map[string]interface{}{
"userBaseId": request.UserBaseId,
"cooperationContractIds": []int64{contracts.CooperationContractId},
})
if err != nil {
return nil, err
}
for i := range undertakers {
if len(undertakers[i].Undertaker.ContractAttachment) == 0 {
continue
}
response.Attachment = undertakers[i].Undertaker.ContractAttachment[0]
break
}
case 2:
// 0.2 合约数据
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
contracts, err := contractRepository.FindOne(map[string]interface{}{"cooperationContractId": request.ContractId})
if err != nil {
return nil, fmt.Errorf("合约不存在")
}
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
"orgId": contracts.Org.OrgId,
"companyId": contracts.Company.CompanyId,
"cooperationContractNumber": contracts.CooperationContractNumber,
"isCanceled": false,
"paymentStatus": int32(2),
})
if err != nil {
return nil, err
}
var estimateIds []int64
if len(dividendsEstimates) == 0 {
return response, nil
}
for i := range dividendsEstimates {
estimateIds = append(estimateIds, dividendsEstimates[i].DividendsEstimateId)
}
creditAccountRepository, _ := repository.NewCreditAccountRepository(ptr.transactionContext)
_, creditAccount, err := creditAccountRepository.Find(map[string]interface{}{
"userBaseId": request.UserBaseId,
"orgId": contracts.Org.OrgId,
"companyId": contracts.Company.CompanyId,
"dividendsEstimateOrderIds": estimateIds,
})
if err != nil {
return nil, err
}
if len(creditAccount) == 0 {
return response, nil
}
for i := range creditAccount {
if len(creditAccount[i].PaymentDocumentAttachments) == 0 {
continue
}
response.Attachment = creditAccount[i].PaymentDocumentAttachments[0] // 获取第一个
break
}
default:
return nil, fmt.Errorf("unkown attachment type %v", request.AttachmentType)
}
return response, nil
}
... ...
... ... @@ -45,6 +45,8 @@ const (
PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics"
// 个人 - 共创项目共享信息数据
PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo"
// 个人 - 共创项目共享信息数据 - 附件
PersonCooperationProjectSharedInfoAttachment = "PersonCooperationProjectSharedInfoAttachment"
// 账期结算单统计
CreditAccountStatistics = "CreditAccountStatistics"
... ...
... ... @@ -247,6 +247,10 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac
if offsetLimitFlag {
query.SetOffsetAndLimit(20)
}
if v, ok := queryOptions["dividendsEstimateOrderIds"]; ok && len(v.([]int64)) > 0 {
//query.Where("cooperation_contract_number in (?)", pg.In(v))
query.Where(domain.ConditionInDividendsEstimateOrderIds(v.([]int64)))
}
query.SetOrderDirect("credit_account_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, creditAccounts, err
... ...