作者 yangfu

Merge branch 'feature_sign_up' into test

@@ -226,10 +226,10 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -226,10 +226,10 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
226 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 226 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
227 } else { 227 } else {
228 // 更新共创项目申请人计数 228 // 更新共创项目申请人计数
229 - cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1  
230 - if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {  
231 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
232 - } 229 + //cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1
  230 + //if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
  231 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  232 + //}
233 if err := transactionContext.CommitTransaction(); err != nil { 233 if err := transactionContext.CommitTransaction(); err != nil {
234 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 234 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
235 } 235 }
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 "encoding/json" 6 "encoding/json"
7 "fmt" 7 "fmt"
8 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
  9 + "github.com/linmadan/egglib-go/transaction/pg"
9 "github.com/linmadan/egglib-go/utils/tool_funs" 10 "github.com/linmadan/egglib-go/utils/tool_funs"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/dto" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/dto"
@@ -401,6 +402,14 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -401,6 +402,14 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
401 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil { 402 if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
402 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 403 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
403 } else { 404 } else {
  405 +
  406 + if err = cooperationContractService.UpdateCooperationProjectStaticsInfo(transactionContext,
  407 + cooperationContract.Company.CompanyId,
  408 + cooperationContract.Org.OrgId,
  409 + cooperationContract.CooperationProjectNumber); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + }
  412 +
404 if err := transactionContext.CommitTransaction(); err != nil { 413 if err := transactionContext.CommitTransaction(); err != nil {
405 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 414 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
406 } 415 }
@@ -1609,6 +1618,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1609,6 +1618,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1609 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error()) 1618 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
1610 } 1619 }
1611 } 1620 }
  1621 +
  1622 + if err = cooperationContractService.UpdateCooperationProjectStaticsInfo(transactionContext,
  1623 + updateCooperationContractCommand.CompanyId,
  1624 + updateCooperationContractCommand.OrgId,
  1625 + updateCooperationContractCommand.CooperationProjectNumber); err != nil {
  1626 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1627 + }
  1628 +
1612 if err21 := transactionContext.CommitTransaction(); err21 != nil { 1629 if err21 := transactionContext.CommitTransaction(); err21 != nil {
1613 return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error()) 1630 return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
1614 } 1631 }
@@ -1639,6 +1656,70 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1639,6 +1656,70 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1639 } 1656 }
1640 } 1657 }
1641 1658
  1659 +// 更新共创项目统计数据(申请人数 、 合约数)
  1660 +func (cooperationContractService *CooperationContractService) UpdateCooperationProjectStaticsInfo(transactionContext application.TransactionContext,
  1661 + companyId, orgId int64,
  1662 + cooperationProjectNumber string) error {
  1663 + cooperationProjectRepository, _ := factory.CreateCooperationProjectRepository(map[string]interface{}{
  1664 + "transactionContext": transactionContext,
  1665 + })
  1666 + project, err := cooperationProjectRepository.FindOne(map[string]interface{}{
  1667 + "companyId": companyId,
  1668 + "orgId": orgId,
  1669 + "cooperationProjectNumber": cooperationProjectNumber,
  1670 + })
  1671 + if err != nil {
  1672 + return err
  1673 + }
  1674 +
  1675 + cooperationContractDao, _ := dao.NewCooperationContractDao(transactionContext.(*pg.TransactionContext))
  1676 + total, contracts, err := cooperationContractDao.Find(map[string]interface{}{
  1677 + "companyId": companyId,
  1678 + "orgId": orgId,
  1679 + "cooperationProjectNumber": cooperationProjectNumber,
  1680 + "offsetLimitFlag": false,
  1681 + })
  1682 + if err != nil {
  1683 + return err
  1684 + }
  1685 + project.ContractCount = int32(total)
  1686 +
  1687 + // 共创合约数量
  1688 + cooperationContractIds := make([]int64, 0)
  1689 + for i := range contracts {
  1690 + cooperationContractIds = append(cooperationContractIds, contracts[i].CooperationContractId)
  1691 + }
  1692 +
  1693 + // 承接人数量
  1694 + cooperationContractUndertakerRepository, _ := dao.NewCooperationContractUndertakerDao(transactionContext.(*pg.TransactionContext))
  1695 + _, underTakers, err := cooperationContractUndertakerRepository.Find(map[string]interface{}{
  1696 + "companyId": companyId,
  1697 + "orgId": orgId,
  1698 + "cooperationProjectNumber": cooperationProjectNumber,
  1699 + "cooperationContractIds": cooperationContractIds,
  1700 + "offsetLimitFlag": false,
  1701 + })
  1702 + if err != nil {
  1703 + return err
  1704 + }
  1705 + var count = 0
  1706 + for i := range underTakers {
  1707 + item := underTakers[i]
  1708 + count += 1 // 默认承接人
  1709 + if item.Undertaker.Referrer != nil && item.Undertaker.Referrer.UserBaseId != 0 {
  1710 + count += 1
  1711 + }
  1712 + if item.Undertaker.Salesman != nil && item.Undertaker.Salesman.UserBaseId != 0 {
  1713 + count += 1
  1714 + }
  1715 + }
  1716 + project.ApplicantCount = int32(count)
  1717 + if _, err := cooperationProjectRepository.Save(project); err != nil {
  1718 + return err
  1719 + }
  1720 + return nil
  1721 +}
  1722 +
1642 func NewCooperationContractService(options map[string]interface{}) *CooperationContractService { 1723 func NewCooperationContractService(options map[string]interface{}) *CooperationContractService {
1643 newCooperationContractService := &CooperationContractService{} 1724 newCooperationContractService := &CooperationContractService{}
1644 return newCooperationContractService 1725 return newCooperationContractService
@@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
47 res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions) 47 res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
48 case domain_service.CompanyPaymentHistoryStatistics: 48 case domain_service.CompanyPaymentHistoryStatistics:
49 res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) 49 res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
  50 + case domain_service.CompanyCooperationProjectContracts:
  51 + res, err = statisticsService.CompanyCooperationProjectContracts(contractStatisticsQuery.QueryOptions)
50 case domain_service.PaymentHistoryHistogramStatistics: 52 case domain_service.PaymentHistoryHistogramStatistics:
51 res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions) 53 res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions)
52 case domain_service.CooperationUserModeStatistics: 54 case domain_service.CooperationUserModeStatistics:
@@ -61,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS @@ -61,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
61 res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions) 63 res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
62 case domain_service.PersonCompanyPaymentHistoryStatistics: 64 case domain_service.PersonCompanyPaymentHistoryStatistics:
63 res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) 65 res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
  66 + case domain_service.PersonCooperationProjectSharedInfo:
  67 + res, err = statisticsService.PersonCooperationProjectSharedInfo(contractStatisticsQuery.QueryOptions)
64 case domain_service.CreditAccountStatistics: 68 case domain_service.CreditAccountStatistics:
65 res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions) 69 res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
66 case domain_service.RelevantCooperationContractNumbers: 70 case domain_service.RelevantCooperationContractNumbers:
@@ -1091,7 +1091,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -1091,7 +1091,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
1091 } 1091 }
1092 1092
1093 return map[string]interface{}{ 1093 return map[string]interface{}{
1094 - "report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr), 1094 + "report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
  1095 + "dividendsEstimates": dividendsEstimatesSaved,
1095 }, nil 1096 }, nil
1096 } 1097 }
1097 } 1098 }
1 package domain 1 package domain
2 2
3 -import "time" 3 +import (
  4 + "strings"
  5 + "time"
  6 +)
4 7
5 // CooperationPersonStatisticsDto 共创人员信息统计 8 // CooperationPersonStatisticsDto 共创人员信息统计
6 type CooperationPersonStatisticsDto struct { 9 type CooperationPersonStatisticsDto struct {
@@ -15,3 +18,97 @@ type CooperationPersonStatisticsDto struct { @@ -15,3 +18,97 @@ type CooperationPersonStatisticsDto struct {
15 // 共创人员姓名 18 // 共创人员姓名
16 UserName string `json:"userName"` 19 UserName string `json:"userName"`
17 } 20 }
  21 +
  22 +// 1.共创项目浏览详情
  23 +
  24 +// 共创项目详情
  25 +type CooperationProjectSharedInfoDto struct {
  26 + // 共创项目数据
  27 + Project interface{} `json:"project"`
  28 + // 企业信息
  29 + Org *Org `json:"org"`
  30 + // 企业关注状态
  31 + OrgStarred bool `json:"orgStarred"`
  32 + // 合同参与人
  33 + ContractParticipant []*ContractParticipant `json:"contractParticipant"`
  34 +}
  35 +
  36 +// 项目参与人
  37 +type ContractParticipant struct {
  38 + //
  39 + User *User `json:"-"`
  40 + // 参与人
  41 + Participant interface{} `json:"participant"`
  42 + // 合约数据 (合约名称、合约状态、合约附件)
  43 + Contract interface{} `json:"contract"`
  44 + // 订单金额
  45 + OrderAmount float64 `json:"orderAmount"`
  46 + // 分红金额 ()
  47 + DividendsAmount float64 `json:"dividendsAmount"`
  48 + // 合同内容
  49 + ContractContent string `json:"contractContent"`
  50 + // 敏感标识
  51 + SensitiveFlag bool `json:"sensitiveFlag"`
  52 + // 共创合约编号
  53 + primaryKey string `json:"key"`
  54 +}
  55 +
  56 +func (u *User) SimpleCopy() map[string]interface{} {
  57 + return map[string]interface{}{
  58 + "userId": u.UserId,
  59 + //"userBaseId":u.UserBaseId,
  60 + "userInfo": u.UserInfo,
  61 + }
  62 +}
  63 +func (ut *Undertaker) ToUser() *User {
  64 + return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
  65 +}
  66 +
  67 +func (ut *Referrer) ToUser() *User {
  68 + return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
  69 +}
  70 +
  71 +func (ut *Salesman) ToUser() *User {
  72 + return &User{UserId: ut.UserId, UserInfo: ut.UserInfo}
  73 +}
  74 +
  75 +func NewContractParticipant(u *User, primaryKey string, attachments []*Attachment) *ContractParticipant {
  76 + p := &ContractParticipant{
  77 + User: u,
  78 + Participant: u.SimpleCopy(),
  79 + primaryKey: primaryKey,
  80 + }
  81 + if len(attachments) > 0 {
  82 + p.ContractContent = attachments[0].Name
  83 + }
  84 + return p
  85 +}
  86 +
  87 +func (cp *ContractParticipant) Complete(userBaseId int64, sensitive bool) *ContractParticipant {
  88 + cp.SensitiveFlag = false
  89 + if sensitive {
  90 + if cp.User.UserBaseId != userBaseId {
  91 + cp.DividendsAmount = 0
  92 + cp.SensitiveFlag = true
  93 + name := []byte(cp.User.UserInfo.UserName)
  94 + for i := range name {
  95 + if i == 0 {
  96 + continue
  97 + }
  98 + name[i] = byte('*')
  99 + }
  100 + cp.User.UserInfo.UserName = string(name)
  101 + cp.Participant = cp.User.SimpleCopy()
  102 + }
  103 + return cp
  104 + }
  105 + return cp
  106 +}
  107 +
  108 +func (cp *ContractParticipant) CooperationContractNumber() string {
  109 + sp := strings.Split(cp.primaryKey, "-")
  110 + if len(sp) == 0 {
  111 + return ""
  112 + }
  113 + return sp[0]
  114 +}
@@ -44,6 +44,8 @@ type CooperationProject struct { @@ -44,6 +44,8 @@ type CooperationProject struct {
44 CreatedAt time.Time `json:"createdAt"` 44 CreatedAt time.Time `json:"createdAt"`
45 // 共创申请人计数 45 // 共创申请人计数
46 ApplicantCount int32 `json:"applicantCount"` 46 ApplicantCount int32 `json:"applicantCount"`
  47 + // 合约计数
  48 + ContractCount int32 `json:"contractCount"`
47 } 49 }
48 50
49 type CooperationProjectRepository interface { 51 type CooperationProjectRepository interface {
@@ -214,6 +214,9 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in @@ -214,6 +214,9 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in
214 if cooperationModeNumber, ok := queryOptions["cooperationModeNumber"]; ok && cooperationModeNumber.(string) != "" { 214 if cooperationModeNumber, ok := queryOptions["cooperationModeNumber"]; ok && cooperationModeNumber.(string) != "" {
215 query.Where("cooperation_mode_number = ?", cooperationModeNumber) 215 query.Where("cooperation_mode_number = ?", cooperationModeNumber)
216 } 216 }
  217 + if CooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && CooperationProjectNumber.(string) != "" {
  218 + query.Where("cooperation_project_number = ?", CooperationProjectNumber)
  219 + }
217 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 220 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
218 query.Where("company->>'companyId' = '?'", companyId) 221 query.Where("company->>'companyId' = '?'", companyId)
219 } 222 }
@@ -43,6 +43,9 @@ func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string @@ -43,6 +43,9 @@ func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string
43 return query, nil 43 return query, nil
44 }) 44 })
45 } 45 }
  46 + if cooperationContractIds, ok := queryOptions["cooperationContractIds"]; ok && len(cooperationContractIds.([]int64)) > 0 {
  47 + query.Where("cooperation_contract_id in (?)", pg.In(cooperationContractIds))
  48 + }
46 if userId, ok := queryOptions["userId"]; ok && userId.(int64) != 0 { 49 if userId, ok := queryOptions["userId"]; ok && userId.(int64) != 0 {
47 query.WhereGroup(func(query *orm.Query) (*orm.Query, error) { 50 query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
48 query.WhereOr("user_id = ? ", userId) 51 query.WhereOr("user_id = ? ", userId)
@@ -211,6 +211,45 @@ func (dao *DividendsEstimateDao) DividendsEstimateStatistics(queryOptions map[st @@ -211,6 +211,45 @@ func (dao *DividendsEstimateDao) DividendsEstimateStatistics(queryOptions map[st
211 return nil 211 return nil
212 } 212 }
213 213
  214 +// CountDividendsEstimate 统计当前分红预算单总数
  215 +func (dao *DividendsEstimateDao) DividendsEstimateStatisticsGroup(queryOptions map[string]interface{}) (map[string]float64, error) {
  216 + tx := dao.transactionContext.PgTx
  217 + var dividendsEstimateModels []*models.DividendsEstimate
  218 + query := tx.Model(&dividendsEstimateModels)
  219 + query.Column("cooperation_contract_number")
  220 + query.ColumnExpr("sum(dividends_amount) dividends_amount")
  221 + //query.ColumnExpr(`sum((case when dividends_account_status =1 then dividends_amount else 0 end)) accounting `)
  222 + //query.ColumnExpr(`sum((case when dividends_account_status =2 then dividends_amount else 0 end)) accounted `)
  223 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  224 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  225 + }
  226 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  227 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  228 + }
  229 + if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
  230 + query = query.Where(`dividends_user->>'userBaseId'='?'`, userBaseId)
  231 + }
  232 + if _, ok := queryOptions["beginTime"]; ok {
  233 + query.Where(fmt.Sprintf("created_at>='%s' and created_at<'%s'", (queryOptions["beginTime"].(time.Time)).Format(time.RFC3339), (queryOptions["endTime"].(time.Time)).Format(time.RFC3339)))
  234 + }
  235 + if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
  236 + query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
  237 + }
  238 + query.Where("is_canceled =false")
  239 +
  240 + query.Group("cooperation_contract_number")
  241 + err := query.Select(&dividendsEstimateModels)
  242 + if err != nil {
  243 + return nil, err
  244 + }
  245 + response := make(map[string]float64)
  246 + for i := range dividendsEstimateModels {
  247 + response[dividendsEstimateModels[i].CooperationContractNumber] = dividendsEstimateModels[i].DividendsAmount
  248 + }
  249 +
  250 + return response, nil
  251 +}
  252 +
214 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) { 253 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
215 if transactionContext == nil { 254 if transactionContext == nil {
216 return nil, fmt.Errorf("transactionContext参数不能为空") 255 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -84,9 +84,9 @@ func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[str @@ -84,9 +84,9 @@ func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[str
84 if endTime, ok := queryOptions["endTime"]; ok { 84 if endTime, ok := queryOptions["endTime"]; ok {
85 query.Where("order_time< ?", endTime) 85 query.Where("order_time< ?", endTime)
86 } 86 }
87 - if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {  
88 - query.Where("cooperation_contract_number = ?", cooperationContractNumber)  
89 - } 87 + //if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  88 + // query.Where("cooperation_contract_number = ?", cooperationContractNumber)
  89 + //}
90 err := query.Select() 90 err := query.Select()
91 if err != nil { 91 if err != nil {
92 return 0, err 92 return 0, err
@@ -119,6 +119,41 @@ func (dao *DividendsOrderDao) CalculateGoodOrderAmount(queryOptions map[string]i @@ -119,6 +119,41 @@ func (dao *DividendsOrderDao) CalculateGoodOrderAmount(queryOptions map[string]i
119 return orderGood.OrderGoodAmount, nil 119 return orderGood.OrderGoodAmount, nil
120 } 120 }
121 121
  122 +// CalculateDividendsOrderAmount 计算分红订单金额
  123 +func (dao *DividendsOrderDao) CalculateGoodOrderAmountByGroup(queryOptions map[string]interface{}) (map[string]float64, error) {
  124 + tx := dao.transactionContext.PgTx
  125 + var orderGood = new(models.OrderGood)
  126 + query := tx.Model(orderGood)
  127 + var orderGoods = make([]*models.OrderGood, 0)
  128 + query.Column("cooperation_contract_number")
  129 + query.ColumnExpr("sum(case when dividends_order_number is null then -order_good_amount else order_good_amount end) as order_good_amount")
  130 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  131 + query.Where("company_id = '?'", companyId)
  132 + }
  133 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  134 + query.Where("org_id = '?'", orgId)
  135 + }
  136 + if beginTime, ok := queryOptions["beginTime"]; ok {
  137 + query.Where("order_time>= ?", beginTime)
  138 + }
  139 + if endTime, ok := queryOptions["endTime"]; ok {
  140 + query.Where("order_time< ?", endTime)
  141 + }
  142 + if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
  143 + query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
  144 + }
  145 + query.Group("cooperation_contract_number")
  146 + err := query.Select(&orderGoods)
  147 + if err != nil {
  148 + return nil, err
  149 + }
  150 + response := make(map[string]float64)
  151 + for i := range orderGoods {
  152 + response[orderGoods[i].CooperationContractNumber] = orderGoods[i].OrderGoodAmount
  153 + }
  154 + return response, nil
  155 +}
  156 +
122 func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) { 157 func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
123 if transactionContext == nil { 158 if transactionContext == nil {
124 return nil, fmt.Errorf("transactionContext参数不能为nil") 159 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -287,7 +287,10 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s @@ -287,7 +287,10 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s
287 func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error { 287 func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
288 json.UnmarshalFromString(json.MarshalToString(queryOption), obj) 288 json.UnmarshalFromString(json.MarshalToString(queryOption), obj)
289 validation := validation.Validation{} 289 validation := validation.Validation{}
290 - _, err := validation.Valid(obj) 290 + result, err := validation.Valid(obj)
  291 + if !result && len(validation.Errors) > 0 {
  292 + return validation.Errors[0]
  293 + }
291 return err 294 return err
292 } 295 }
293 296
1 package domain_service 1 package domain_service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
5 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
10 "time" 13 "time"
11 ) 14 )
@@ -191,3 +194,224 @@ func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(q @@ -191,3 +194,224 @@ func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(q
191 194
192 return retMap, nil 195 return retMap, nil
193 } 196 }
  197 +
  198 +// 个人 - 共创浏览 详情页
  199 +func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(queryOptions map[string]interface{}) (interface{}, error) {
  200 + // 参数验证
  201 + var request = struct {
  202 + UserBaseId int64 `json:"userBaseId"`
  203 + // 项目ID
  204 + ProjectId int64 `json:"projectId" valid:"Required"`
  205 + // 敏感数据
  206 + Sensitive bool `json:"sensitive" valid:"Required"`
  207 + }{}
  208 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  209 + return nil, err
  210 + }
  211 + queryOptions = tool_funs.SimpleStructToMap(&request)
  212 + var response = domain.CooperationProjectSharedInfoDto{
  213 + ContractParticipant: make([]*domain.ContractParticipant, 0),
  214 + }
  215 +
  216 + projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
  217 + project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
  218 + if err != nil {
  219 + return nil, fmt.Errorf("共创项目不存在")
  220 + }
  221 +
  222 + // 0.共创项目数据
  223 + updateAt := project.UpdatedAt
  224 + if project.UpdatedAt.IsZero() {
  225 + updateAt = project.CreatedAt
  226 + }
  227 + response.Project = map[string]interface{}{
  228 + "cooperationProjectId": project.CooperationProjectId,
  229 + "attachment": project.Attachment,
  230 + "cooperationProjectDescription": project.CooperationProjectDescription,
  231 + "cooperationProjectName": project.CooperationProjectName,
  232 + //"cooperationProjectDescription":project.CooperationProjectDescription,
  233 + "updatedAt": updateAt.Unix() * 1000,
  234 + }
  235 + // 0.1 组织数据
  236 + response.Org = project.Org
  237 + if request.UserBaseId != 0 {
  238 + // 当前用户对于项目组织的关注状态
  239 + userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
  240 + userDetail, e := userServiceGateway.GetUserInfo(0, 0, request.UserBaseId)
  241 + if e == nil && userDetail != nil {
  242 + response.OrgStarred = userDetail.CheckOrgStarred(project.Org.OrgId)
  243 + }
  244 + }
  245 +
  246 + // 0.2 合约数据
  247 + contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
  248 + _, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
  249 + if len(contracts) == 0 {
  250 + return response, nil
  251 + }
  252 +
  253 + contractNumbers := make([]string, 0)
  254 + mapContract := make(map[string]*domain.CooperationContract)
  255 + for i := range contracts {
  256 + contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
  257 + mapContract[contracts[i].CooperationContractNumber] = contracts[i]
  258 + }
  259 + keyfun := func(num string, userBaseId int64) string {
  260 + return num + "-" + fmt.Sprintf("%v", userBaseId)
  261 + }
  262 +
  263 + // 1.项目的承接人
  264 + undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
  265 + _, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
  266 + userSorted := make([]string, 0)
  267 + mapUser := make(map[string]*domain.ContractParticipant)
  268 + for i := range undertakers {
  269 + u := undertakers[i]
  270 + key := keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)
  271 + userSorted = append(userSorted, key)
  272 + mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.ToUser(), key, u.Undertaker.ContractAttachment)
  273 + if u.Undertaker.Referrer != nil {
  274 + key = keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)
  275 + userSorted = append(userSorted, key)
  276 + mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Referrer.ToUser(), key, u.Undertaker.ContractAttachment)
  277 + }
  278 + if u.Undertaker.Salesman != nil {
  279 + userSorted = append(userSorted, keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId))
  280 + mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Salesman.ToUser(), key, u.Undertaker.ContractAttachment)
  281 + }
  282 + }
  283 +
  284 + // 2.合约的订单金额
  285 + mapContractOrderAmount := make(map[string]float64)
  286 + dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
  287 + mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
  288 + "cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
  289 + })
  290 +
  291 + // 3.计算合约用户的分红预算金额
  292 + dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
  293 + _, dividends, err := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId, "dividendsAccountStatus": int32(1), "offsetLimit": false})
  294 + for i := range dividends {
  295 + d := dividends[i]
  296 + key := keyfun(d.CooperationContractNumber, d.DividendsUser.UserBaseId)
  297 + if v, ok := mapUser[key]; ok {
  298 + v.DividendsAmount += d.DividendsAmount
  299 + }
  300 + }
  301 +
  302 + for _, v := range mapUser {
  303 + if v1, ok := mapContractOrderAmount[v.CooperationContractNumber()]; ok {
  304 + v.OrderAmount = v1
  305 + }
  306 + if v1, ok := mapContract[v.CooperationContractNumber()]; ok {
  307 + v.Contract = map[string]interface{}{
  308 + "cooperationContractId": v1.CooperationContractId,
  309 + "cooperationContractName": v1.CooperationContractName,
  310 + "status": v1.Status,
  311 + }
  312 + }
  313 + }
  314 +
  315 + for i := range userSorted {
  316 + if v, ok := mapUser[userSorted[i]]; ok {
  317 + response.ContractParticipant = append(response.ContractParticipant, v.Complete(request.UserBaseId, request.Sensitive))
  318 + }
  319 + }
  320 + return response, nil
  321 +}
  322 +
  323 +// 个人 - 共创浏览 合约列表
  324 +func (ptr *CooperationStatisticsService) CompanyCooperationProjectContracts(queryOptions map[string]interface{}) (interface{}, error) {
  325 + // 参数验证
  326 + var request = struct {
  327 + Offset int `json:"offset"`
  328 + Limit int `json:"limit"`
  329 + // 项目ID
  330 + ProjectId int64 `json:"projectId" valid:"Required"`
  331 + }{}
  332 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  333 + return nil, err
  334 + }
  335 + projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
  336 + project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
  337 + if err != nil {
  338 + return nil, fmt.Errorf("共创项目不存在")
  339 + }
  340 +
  341 + // 0.2 合约数据
  342 + contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
  343 + _, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber,
  344 + "companyId": project.Company.CompanyId,
  345 + "orgId": project.Org.OrgId,
  346 + "limit": request.Limit,
  347 + "offset": request.Offset,
  348 + })
  349 + if len(contracts) == 0 {
  350 + return nil, nil
  351 + }
  352 +
  353 + contractNumbers := make([]string, 0)
  354 + mapContract := make(map[string]*domain.CooperationContract)
  355 + for i := range contracts {
  356 + contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
  357 + mapContract[contracts[i].CooperationContractNumber] = contracts[i]
  358 + }
  359 +
  360 + // 2.合约的订单金额
  361 + mapContractOrderAmount := make(map[string]float64)
  362 + dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
  363 + mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
  364 + "cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
  365 + })
  366 +
  367 + // 3.计算合约用户的分红预算金额
  368 + dividendsEstimateRepository, _ := dao.NewDividendsEstimateDao(ptr.transactionContext) //repository.NewDividendsEstimateRepository(ptr.transactionContext)
  369 + mapDividends, err := dividendsEstimateRepository.DividendsEstimateStatisticsGroup(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
  370 + if err != nil {
  371 + return nil, err
  372 + }
  373 + results := make([]interface{}, 0)
  374 + for i := range contracts {
  375 + item := contracts[i]
  376 +
  377 + resultItem := &searchContractDividendsResult{
  378 + CooperationContractId: item.CooperationContractId,
  379 + CooperationContractName: item.CooperationContractName,
  380 + CooperationContractNumber: item.CooperationContractNumber,
  381 + Status: item.Status,
  382 + CreatedAt: item.CreatedAt.Unix() * 1000,
  383 + }
  384 + if v, ok := mapContractOrderAmount[contracts[i].CooperationContractNumber]; ok {
  385 + resultItem.DividendsOrderAmount = v
  386 + }
  387 + if v, ok := mapDividends[contracts[i].CooperationContractNumber]; ok {
  388 + resultItem.DividendsAmount = v
  389 + }
  390 + results = append(results, resultItem)
  391 + }
  392 + return results, nil
  393 +}
  394 +
  395 +// func(ptr *CooperationStatisticsService)
  396 +
  397 +// 个人 - 共创浏览 详情页 - 附件数据
  398 +func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttachment(queryOptions map[string]interface{}) (interface{}, error) {
  399 + // 参数验证
  400 + var request = struct {
  401 + UserBaseId int64 `json:"userBaseId"`
  402 + // 用户
  403 + UserId int64 `json:"userId" valid:"Required"`
  404 + // 项目ID
  405 + ProjectId int64 `json:"projectId" valid:"Required"`
  406 + // 合约ID
  407 + ContractId int64 `json:"contractId" valid:"Required"`
  408 + // 附件类型 1:合约附件 2:支付凭证
  409 + AttachType int `json:"attachType" valid:"Required"`
  410 + }{}
  411 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  412 + return nil, err
  413 + }
  414 + queryOptions = tool_funs.SimpleStructToMap(&request)
  415 + var response = domain.CooperationProjectSharedInfoDto{}
  416 + return response, nil
  417 +}
@@ -34,6 +34,8 @@ const ( @@ -34,6 +34,8 @@ const (
34 CooperationUserModeStatistics = "CooperationUserModeStatistics" 34 CooperationUserModeStatistics = "CooperationUserModeStatistics"
35 // 公司 - 共创用户分红支付统计 35 // 公司 - 共创用户分红支付统计
36 CompanyPaymentHistoryStatistics = "CompanyPaymentHistoryStatistics" 36 CompanyPaymentHistoryStatistics = "CompanyPaymentHistoryStatistics"
  37 + // 企业共创项目 - 合约列表
  38 + CompanyCooperationProjectContracts = "CompanyCooperationProjectContracts"
37 39
38 // 个人 - 共创企业统计 40 // 个人 - 共创企业统计
39 CooperationCompanyStatistics = "CooperationCompanyStatistics" 41 CooperationCompanyStatistics = "CooperationCompanyStatistics"
@@ -41,6 +43,8 @@ const ( @@ -41,6 +43,8 @@ const (
41 PersonCooperationContractStatistics = "PersonCooperationContractStatistics" 43 PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
42 // 个人 - 企业支付统计 44 // 个人 - 企业支付统计
43 PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics" 45 PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics"
  46 + // 个人 - 共创项目共享信息数据
  47 + PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo"
44 48
45 // 账期结算单统计 49 // 账期结算单统计
46 CreditAccountStatistics = "CreditAccountStatistics" 50 CreditAccountStatistics = "CreditAccountStatistics"
@@ -47,4 +47,6 @@ type CooperationProject struct { @@ -47,4 +47,6 @@ type CooperationProject struct {
47 CreatedAt time.Time `comment:"创建时间"` 47 CreatedAt time.Time `comment:"创建时间"`
48 // 申请人统计 48 // 申请人统计
49 ApplicantCount int32 `comment:"申请人统计"` 49 ApplicantCount int32 `comment:"申请人统计"`
  50 + // 合约计数
  51 + ContractCount int32 `comment:"合约计数"`
50 } 52 }
@@ -42,5 +42,6 @@ func TransformToCooperationProjectDomainModelFromPgModels( @@ -42,5 +42,6 @@ func TransformToCooperationProjectDomainModelFromPgModels(
42 DeletedAt: cooperationProjectModel.DeletedAt, 42 DeletedAt: cooperationProjectModel.DeletedAt,
43 CreatedAt: cooperationProjectModel.CreatedAt, 43 CreatedAt: cooperationProjectModel.CreatedAt,
44 ApplicantCount: cooperationProjectModel.ApplicantCount, 44 ApplicantCount: cooperationProjectModel.ApplicantCount,
  45 + ContractCount: cooperationProjectModel.ContractCount,
45 }, nil 46 }, nil
46 } 47 }
@@ -49,6 +49,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -49,6 +49,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
49 "deleted_at", 49 "deleted_at",
50 "created_at", 50 "created_at",
51 "applicant_count", 51 "applicant_count",
  52 + "contract_count",
52 } 53 }
53 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) 54 insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
54 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) 55 insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
@@ -85,6 +86,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -85,6 +86,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
85 &cooperationProject.DeletedAt, 86 &cooperationProject.DeletedAt,
86 &cooperationProject.CreatedAt, 87 &cooperationProject.CreatedAt,
87 &cooperationProject.ApplicantCount, 88 &cooperationProject.ApplicantCount,
  89 + &cooperationProject.ContractCount,
88 ), 90 ),
89 fmt.Sprintf("INSERT INTO cooperation_projects (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), 91 fmt.Sprintf("INSERT INTO cooperation_projects (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
90 cooperationProject.CooperationProjectId, 92 cooperationProject.CooperationProjectId,
@@ -107,6 +109,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -107,6 +109,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
107 nil, 109 nil,
108 cooperationProject.CreatedAt, 110 cooperationProject.CreatedAt,
109 cooperationProject.ApplicantCount, 111 cooperationProject.ApplicantCount,
  112 + cooperationProject.ContractCount,
110 ); err != nil { 113 ); err != nil {
111 return cooperationProject, err 114 return cooperationProject, err
112 } 115 }
@@ -133,6 +136,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -133,6 +136,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
133 &cooperationProject.DeletedAt, 136 &cooperationProject.DeletedAt,
134 &cooperationProject.CreatedAt, 137 &cooperationProject.CreatedAt,
135 &cooperationProject.ApplicantCount, 138 &cooperationProject.ApplicantCount,
  139 + &cooperationProject.ContractCount,
136 ), 140 ),
137 fmt.Sprintf("UPDATE cooperation_projects SET %s WHERE cooperation_project_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), 141 fmt.Sprintf("UPDATE cooperation_projects SET %s WHERE cooperation_project_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
138 cooperationProject.CooperationProjectId, 142 cooperationProject.CooperationProjectId,
@@ -155,6 +159,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain. @@ -155,6 +159,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
155 nil, 159 nil,
156 cooperationProject.CreatedAt, 160 cooperationProject.CreatedAt,
157 cooperationProject.ApplicantCount, 161 cooperationProject.ApplicantCount,
  162 + cooperationProject.ContractCount,
158 cooperationProject.Identify(), 163 cooperationProject.Identify(),
159 ); err != nil { 164 ); err != nil {
160 return cooperationProject, err 165 return cooperationProject, err
@@ -70,10 +70,24 @@ type UserDetail struct { @@ -70,10 +70,24 @@ type UserDetail struct {
70 DeletedAt time.Time `json:"deletedAt"` 70 DeletedAt time.Time `json:"deletedAt"`
71 OrgName string `json:"orgName"` 71 OrgName string `json:"orgName"`
72 } `json:"userOrg"` 72 } `json:"userOrg"`
  73 + Favorite struct {
  74 + OrgItems []int64 `json:"orgItems"`
  75 + } `json:"favorite"`
73 // 创建时间 76 // 创建时间
74 CreatedAt time.Time `json:"createdAt,omitempty"` 77 CreatedAt time.Time `json:"createdAt,omitempty"`
75 } 78 }
76 79
  80 +func (user *UserDetail) CheckOrgStarred(orgId int64) bool {
  81 + var starred bool = false
  82 + for i := range user.Favorite.OrgItems {
  83 + if user.Favorite.OrgItems[i] == orgId {
  84 + starred = true
  85 + return starred
  86 + }
  87 + }
  88 + return false
  89 +}
  90 +
77 func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) { 91 func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) {
78 var orgs []*domain.Org 92 var orgs []*domain.Org
79 for _, org := range user.UserOrg { 93 for _, org := range user.UserOrg {