作者 yangfu

Merge branch 'feature_sign_up' into test

... ... @@ -226,10 +226,10 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
// 更新共创项目申请人计数
cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1
if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1
//if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/dto"
... ... @@ -401,6 +402,14 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
if cooperationContract, err := cooperationContractRepository.Save(newCooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err = cooperationContractService.UpdateCooperationProjectStaticsInfo(transactionContext,
cooperationContract.Company.CompanyId,
cooperationContract.Org.OrgId,
cooperationContract.CooperationProjectNumber); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -1609,6 +1618,14 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err20.Error())
}
}
if err = cooperationContractService.UpdateCooperationProjectStaticsInfo(transactionContext,
updateCooperationContractCommand.CompanyId,
updateCooperationContractCommand.OrgId,
updateCooperationContractCommand.CooperationProjectNumber); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err21 := transactionContext.CommitTransaction(); err21 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err21.Error())
}
... ... @@ -1639,6 +1656,70 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
}
// 更新共创项目统计数据(申请人数 、 合约数)
func (cooperationContractService *CooperationContractService) UpdateCooperationProjectStaticsInfo(transactionContext application.TransactionContext,
companyId, orgId int64,
cooperationProjectNumber string) error {
cooperationProjectRepository, _ := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
project, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"companyId": companyId,
"orgId": orgId,
"cooperationProjectNumber": cooperationProjectNumber,
})
if err != nil {
return err
}
cooperationContractDao, _ := dao.NewCooperationContractDao(transactionContext.(*pg.TransactionContext))
total, contracts, err := cooperationContractDao.Find(map[string]interface{}{
"companyId": companyId,
"orgId": orgId,
"cooperationProjectNumber": cooperationProjectNumber,
"offsetLimitFlag": false,
})
if err != nil {
return err
}
project.ContractCount = int32(total)
// 共创合约数量
cooperationContractIds := make([]int64, 0)
for i := range contracts {
cooperationContractIds = append(cooperationContractIds, contracts[i].CooperationContractId)
}
// 承接人数量
cooperationContractUndertakerRepository, _ := dao.NewCooperationContractUndertakerDao(transactionContext.(*pg.TransactionContext))
_, underTakers, err := cooperationContractUndertakerRepository.Find(map[string]interface{}{
"companyId": companyId,
"orgId": orgId,
"cooperationProjectNumber": cooperationProjectNumber,
"cooperationContractIds": cooperationContractIds,
"offsetLimitFlag": false,
})
if err != nil {
return err
}
var count = 0
for i := range underTakers {
item := underTakers[i]
count += 1 // 默认承接人
if item.Undertaker.Referrer != nil && item.Undertaker.Referrer.UserBaseId != 0 {
count += 1
}
if item.Undertaker.Salesman != nil && item.Undertaker.Salesman.UserBaseId != 0 {
count += 1
}
}
project.ApplicantCount = int32(count)
if _, err := cooperationProjectRepository.Save(project); err != nil {
return err
}
return nil
}
func NewCooperationContractService(options map[string]interface{}) *CooperationContractService {
newCooperationContractService := &CooperationContractService{}
return newCooperationContractService
... ...
... ... @@ -47,6 +47,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CompanyCooperationUsersStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyPaymentHistoryStatistics:
res, err = statisticsService.CompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyCooperationProjectContracts:
res, err = statisticsService.CompanyCooperationProjectContracts(contractStatisticsQuery.QueryOptions)
case domain_service.PaymentHistoryHistogramStatistics:
res, err = statisticsService.PaymentHistoryHistogramStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationUserModeStatistics:
... ... @@ -61,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.PersonCooperationContractStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCompanyPaymentHistoryStatistics:
res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.PersonCooperationProjectSharedInfo:
res, err = statisticsService.PersonCooperationProjectSharedInfo(contractStatisticsQuery.QueryOptions)
case domain_service.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.RelevantCooperationContractNumbers:
... ...
... ... @@ -1091,7 +1091,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
return map[string]interface{}{
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
"dividendsEstimates": dividendsEstimatesSaved,
}, nil
}
}
... ...
package domain
import "time"
import (
"strings"
"time"
)
// CooperationPersonStatisticsDto 共创人员信息统计
type CooperationPersonStatisticsDto struct {
... ... @@ -15,3 +18,97 @@ type CooperationPersonStatisticsDto struct {
// 共创人员姓名
UserName string `json:"userName"`
}
// 1.共创项目浏览详情
// 共创项目详情
type CooperationProjectSharedInfoDto struct {
// 共创项目数据
Project interface{} `json:"project"`
// 企业信息
Org *Org `json:"org"`
// 企业关注状态
OrgStarred bool `json:"orgStarred"`
// 合同参与人
ContractParticipant []*ContractParticipant `json:"contractParticipant"`
}
// 项目参与人
type ContractParticipant struct {
//
User *User `json:"-"`
// 参与人
Participant interface{} `json:"participant"`
// 合约数据 (合约名称、合约状态、合约附件)
Contract interface{} `json:"contract"`
// 订单金额
OrderAmount float64 `json:"orderAmount"`
// 分红金额 ()
DividendsAmount float64 `json:"dividendsAmount"`
// 合同内容
ContractContent string `json:"contractContent"`
// 敏感标识
SensitiveFlag bool `json:"sensitiveFlag"`
// 共创合约编号
primaryKey string `json:"key"`
}
func (u *User) SimpleCopy() map[string]interface{} {
return map[string]interface{}{
"userId": u.UserId,
//"userBaseId":u.UserBaseId,
"userInfo": u.UserInfo,
}
}
func (ut *Undertaker) ToUser() *User {
return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
}
func (ut *Referrer) ToUser() *User {
return &User{UserId: ut.UserId, UserBaseId: ut.UserBaseId, UserInfo: ut.UserInfo}
}
func (ut *Salesman) ToUser() *User {
return &User{UserId: ut.UserId, UserInfo: ut.UserInfo}
}
func NewContractParticipant(u *User, primaryKey string, attachments []*Attachment) *ContractParticipant {
p := &ContractParticipant{
User: u,
Participant: u.SimpleCopy(),
primaryKey: primaryKey,
}
if len(attachments) > 0 {
p.ContractContent = attachments[0].Name
}
return p
}
func (cp *ContractParticipant) Complete(userBaseId int64, sensitive bool) *ContractParticipant {
cp.SensitiveFlag = false
if sensitive {
if cp.User.UserBaseId != userBaseId {
cp.DividendsAmount = 0
cp.SensitiveFlag = true
name := []byte(cp.User.UserInfo.UserName)
for i := range name {
if i == 0 {
continue
}
name[i] = byte('*')
}
cp.User.UserInfo.UserName = string(name)
cp.Participant = cp.User.SimpleCopy()
}
return cp
}
return cp
}
func (cp *ContractParticipant) CooperationContractNumber() string {
sp := strings.Split(cp.primaryKey, "-")
if len(sp) == 0 {
return ""
}
return sp[0]
}
... ...
... ... @@ -44,6 +44,8 @@ type CooperationProject struct {
CreatedAt time.Time `json:"createdAt"`
// 共创申请人计数
ApplicantCount int32 `json:"applicantCount"`
// 合约计数
ContractCount int32 `json:"contractCount"`
}
type CooperationProjectRepository interface {
... ...
... ... @@ -214,6 +214,9 @@ func (dao *CooperationContractDao) Find(queryOptions map[string]interface{}) (in
if cooperationModeNumber, ok := queryOptions["cooperationModeNumber"]; ok && cooperationModeNumber.(string) != "" {
query.Where("cooperation_mode_number = ?", cooperationModeNumber)
}
if CooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && CooperationProjectNumber.(string) != "" {
query.Where("cooperation_project_number = ?", CooperationProjectNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...
... ... @@ -43,6 +43,9 @@ func (repository *CooperationContractUndertakerDao) Find(queryOptions map[string
return query, nil
})
}
if cooperationContractIds, ok := queryOptions["cooperationContractIds"]; ok && len(cooperationContractIds.([]int64)) > 0 {
query.Where("cooperation_contract_id in (?)", pg.In(cooperationContractIds))
}
if userId, ok := queryOptions["userId"]; ok && userId.(int64) != 0 {
query.WhereGroup(func(query *orm.Query) (*orm.Query, error) {
query.WhereOr("user_id = ? ", userId)
... ...
... ... @@ -211,6 +211,45 @@ func (dao *DividendsEstimateDao) DividendsEstimateStatistics(queryOptions map[st
return nil
}
// CountDividendsEstimate 统计当前分红预算单总数
func (dao *DividendsEstimateDao) DividendsEstimateStatisticsGroup(queryOptions map[string]interface{}) (map[string]float64, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
query.Column("cooperation_contract_number")
query.ColumnExpr("sum(dividends_amount) dividends_amount")
//query.ColumnExpr(`sum((case when dividends_account_status =1 then dividends_amount else 0 end)) accounting `)
//query.ColumnExpr(`sum((case when dividends_account_status =2 then dividends_amount else 0 end)) accounted `)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
query = query.Where(`dividends_user->>'userBaseId'='?'`, userBaseId)
}
if _, ok := queryOptions["beginTime"]; ok {
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)))
}
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
}
query.Where("is_canceled =false")
query.Group("cooperation_contract_number")
err := query.Select(&dividendsEstimateModels)
if err != nil {
return nil, err
}
response := make(map[string]float64)
for i := range dividendsEstimateModels {
response[dividendsEstimateModels[i].CooperationContractNumber] = dividendsEstimateModels[i].DividendsAmount
}
return response, nil
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -84,9 +84,9 @@ func (dao *DividendsOrderDao) CalculateDividendsOrderAmount(queryOptions map[str
if endTime, ok := queryOptions["endTime"]; ok {
query.Where("order_time< ?", endTime)
}
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query.Where("cooperation_contract_number = ?", cooperationContractNumber)
}
//if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
// query.Where("cooperation_contract_number = ?", cooperationContractNumber)
//}
err := query.Select()
if err != nil {
return 0, err
... ...
... ... @@ -119,6 +119,41 @@ func (dao *DividendsOrderDao) CalculateGoodOrderAmount(queryOptions map[string]i
return orderGood.OrderGoodAmount, nil
}
// CalculateDividendsOrderAmount 计算分红订单金额
func (dao *DividendsOrderDao) CalculateGoodOrderAmountByGroup(queryOptions map[string]interface{}) (map[string]float64, error) {
tx := dao.transactionContext.PgTx
var orderGood = new(models.OrderGood)
query := tx.Model(orderGood)
var orderGoods = make([]*models.OrderGood, 0)
query.Column("cooperation_contract_number")
query.ColumnExpr("sum(case when dividends_order_number is null then -order_good_amount else order_good_amount end) as order_good_amount")
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company_id = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org_id = '?'", orgId)
}
if beginTime, ok := queryOptions["beginTime"]; ok {
query.Where("order_time>= ?", beginTime)
}
if endTime, ok := queryOptions["endTime"]; ok {
query.Where("order_time< ?", endTime)
}
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
}
query.Group("cooperation_contract_number")
err := query.Select(&orderGoods)
if err != nil {
return nil, err
}
response := make(map[string]float64)
for i := range orderGoods {
response[orderGoods[i].CooperationContractNumber] = orderGoods[i].OrderGoodAmount
}
return response, nil
}
func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -287,7 +287,10 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s
func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
json.UnmarshalFromString(json.MarshalToString(queryOption), obj)
validation := validation.Validation{}
_, err := validation.Valid(obj)
result, err := validation.Valid(obj)
if !result && len(validation.Errors) > 0 {
return validation.Errors[0]
}
return err
}
... ...
package domain_service
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
... ... @@ -191,3 +194,224 @@ func (ptr *CooperationStatisticsService) PersonCompanyPaymentHistoryStatistics(q
return retMap, nil
}
// 个人 - 共创浏览 详情页
func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfo(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserBaseId int64 `json:"userBaseId"`
// 项目ID
ProjectId int64 `json:"projectId" valid:"Required"`
// 敏感数据
Sensitive bool `json:"sensitive" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
var response = domain.CooperationProjectSharedInfoDto{
ContractParticipant: make([]*domain.ContractParticipant, 0),
}
projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
if err != nil {
return nil, fmt.Errorf("共创项目不存在")
}
// 0.共创项目数据
updateAt := project.UpdatedAt
if project.UpdatedAt.IsZero() {
updateAt = project.CreatedAt
}
response.Project = map[string]interface{}{
"cooperationProjectId": project.CooperationProjectId,
"attachment": project.Attachment,
"cooperationProjectDescription": project.CooperationProjectDescription,
"cooperationProjectName": project.CooperationProjectName,
//"cooperationProjectDescription":project.CooperationProjectDescription,
"updatedAt": updateAt.Unix() * 1000,
}
// 0.1 组织数据
response.Org = project.Org
if request.UserBaseId != 0 {
// 当前用户对于项目组织的关注状态
userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
userDetail, e := userServiceGateway.GetUserInfo(0, 0, request.UserBaseId)
if e == nil && userDetail != nil {
response.OrgStarred = userDetail.CheckOrgStarred(project.Org.OrgId)
}
}
// 0.2 合约数据
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
_, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
if len(contracts) == 0 {
return response, nil
}
contractNumbers := make([]string, 0)
mapContract := make(map[string]*domain.CooperationContract)
for i := range contracts {
contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
mapContract[contracts[i].CooperationContractNumber] = contracts[i]
}
keyfun := func(num string, userBaseId int64) string {
return num + "-" + fmt.Sprintf("%v", userBaseId)
}
// 1.项目的承接人
undertakerRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
_, undertakers, err := undertakerRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
userSorted := make([]string, 0)
mapUser := make(map[string]*domain.ContractParticipant)
for i := range undertakers {
u := undertakers[i]
key := keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)
userSorted = append(userSorted, key)
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.ToUser(), key, u.Undertaker.ContractAttachment)
if u.Undertaker.Referrer != nil {
key = keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)
userSorted = append(userSorted, key)
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Referrer.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Referrer.ToUser(), key, u.Undertaker.ContractAttachment)
}
if u.Undertaker.Salesman != nil {
userSorted = append(userSorted, keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId))
mapUser[keyfun(u.CooperationContractNumber, u.Undertaker.Salesman.UserBaseId)] = domain.NewContractParticipant(u.Undertaker.Salesman.ToUser(), key, u.Undertaker.ContractAttachment)
}
}
// 2.合约的订单金额
mapContractOrderAmount := make(map[string]float64)
dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
})
// 3.计算合约用户的分红预算金额
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, dividends, err := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId, "dividendsAccountStatus": int32(1), "offsetLimit": false})
for i := range dividends {
d := dividends[i]
key := keyfun(d.CooperationContractNumber, d.DividendsUser.UserBaseId)
if v, ok := mapUser[key]; ok {
v.DividendsAmount += d.DividendsAmount
}
}
for _, v := range mapUser {
if v1, ok := mapContractOrderAmount[v.CooperationContractNumber()]; ok {
v.OrderAmount = v1
}
if v1, ok := mapContract[v.CooperationContractNumber()]; ok {
v.Contract = map[string]interface{}{
"cooperationContractId": v1.CooperationContractId,
"cooperationContractName": v1.CooperationContractName,
"status": v1.Status,
}
}
}
for i := range userSorted {
if v, ok := mapUser[userSorted[i]]; ok {
response.ContractParticipant = append(response.ContractParticipant, v.Complete(request.UserBaseId, request.Sensitive))
}
}
return response, nil
}
// 个人 - 共创浏览 合约列表
func (ptr *CooperationStatisticsService) CompanyCooperationProjectContracts(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
// 项目ID
ProjectId int64 `json:"projectId" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
projectRepository, _ := repository.NewCooperationProjectRepository(ptr.transactionContext)
project, err := projectRepository.FindOne(map[string]interface{}{"cooperationProjectId": request.ProjectId})
if err != nil {
return nil, fmt.Errorf("共创项目不存在")
}
// 0.2 合约数据
contractRepository, _ := dao.NewCooperationContractDao(ptr.transactionContext) // repository.NewCooperationContractRepository(ptr.transactionContext)
_, contracts, _ := contractRepository.Find(map[string]interface{}{"cooperationProjectNumber": project.CooperationProjectNumber,
"companyId": project.Company.CompanyId,
"orgId": project.Org.OrgId,
"limit": request.Limit,
"offset": request.Offset,
})
if len(contracts) == 0 {
return nil, nil
}
contractNumbers := make([]string, 0)
mapContract := make(map[string]*domain.CooperationContract)
for i := range contracts {
contractNumbers = append(contractNumbers, contracts[i].CooperationContractNumber)
mapContract[contracts[i].CooperationContractNumber] = contracts[i]
}
// 2.合约的订单金额
mapContractOrderAmount := make(map[string]float64)
dividendsOrderDao, _ := dao.NewDividendsOrderDao(ptr.transactionContext)
mapContractOrderAmount, _ = dividendsOrderDao.CalculateGoodOrderAmountByGroup(map[string]interface{}{
"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId,
})
// 3.计算合约用户的分红预算金额
dividendsEstimateRepository, _ := dao.NewDividendsEstimateDao(ptr.transactionContext) //repository.NewDividendsEstimateRepository(ptr.transactionContext)
mapDividends, err := dividendsEstimateRepository.DividendsEstimateStatisticsGroup(map[string]interface{}{"cooperationContractNumbers": contractNumbers, "companyId": project.Company.CompanyId, "orgId": project.Org.OrgId})
if err != nil {
return nil, err
}
results := make([]interface{}, 0)
for i := range contracts {
item := contracts[i]
resultItem := &searchContractDividendsResult{
CooperationContractId: item.CooperationContractId,
CooperationContractName: item.CooperationContractName,
CooperationContractNumber: item.CooperationContractNumber,
Status: item.Status,
CreatedAt: item.CreatedAt.Unix() * 1000,
}
if v, ok := mapContractOrderAmount[contracts[i].CooperationContractNumber]; ok {
resultItem.DividendsOrderAmount = v
}
if v, ok := mapDividends[contracts[i].CooperationContractNumber]; ok {
resultItem.DividendsAmount = v
}
results = append(results, resultItem)
}
return results, nil
}
// func(ptr *CooperationStatisticsService)
// 个人 - 共创浏览 详情页 - 附件数据
func (ptr *CooperationStatisticsService) PersonCooperationProjectSharedInfoAttachment(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
UserBaseId int64 `json:"userBaseId"`
// 用户
UserId int64 `json:"userId" valid:"Required"`
// 项目ID
ProjectId int64 `json:"projectId" valid:"Required"`
// 合约ID
ContractId int64 `json:"contractId" valid:"Required"`
// 附件类型 1:合约附件 2:支付凭证
AttachType int `json:"attachType" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
var response = domain.CooperationProjectSharedInfoDto{}
return response, nil
}
... ...
... ... @@ -34,6 +34,8 @@ const (
CooperationUserModeStatistics = "CooperationUserModeStatistics"
// 公司 - 共创用户分红支付统计
CompanyPaymentHistoryStatistics = "CompanyPaymentHistoryStatistics"
// 企业共创项目 - 合约列表
CompanyCooperationProjectContracts = "CompanyCooperationProjectContracts"
// 个人 - 共创企业统计
CooperationCompanyStatistics = "CooperationCompanyStatistics"
... ... @@ -41,6 +43,8 @@ const (
PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
// 个人 - 企业支付统计
PersonCompanyPaymentHistoryStatistics = "PersonCompanyPaymentHistoryStatistics"
// 个人 - 共创项目共享信息数据
PersonCooperationProjectSharedInfo = "PersonCooperationProjectSharedInfo"
// 账期结算单统计
CreditAccountStatistics = "CreditAccountStatistics"
... ...
... ... @@ -47,4 +47,6 @@ type CooperationProject struct {
CreatedAt time.Time `comment:"创建时间"`
// 申请人统计
ApplicantCount int32 `comment:"申请人统计"`
// 合约计数
ContractCount int32 `comment:"合约计数"`
}
... ...
... ... @@ -42,5 +42,6 @@ func TransformToCooperationProjectDomainModelFromPgModels(
DeletedAt: cooperationProjectModel.DeletedAt,
CreatedAt: cooperationProjectModel.CreatedAt,
ApplicantCount: cooperationProjectModel.ApplicantCount,
ContractCount: cooperationProjectModel.ContractCount,
}, nil
}
... ...
... ... @@ -49,6 +49,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
"deleted_at",
"created_at",
"applicant_count",
"contract_count",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -85,6 +86,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
&cooperationProject.ContractCount,
),
fmt.Sprintf("INSERT INTO cooperation_projects (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -107,6 +109,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
cooperationProject.ContractCount,
); err != nil {
return cooperationProject, err
}
... ... @@ -133,6 +136,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
&cooperationProject.ContractCount,
),
fmt.Sprintf("UPDATE cooperation_projects SET %s WHERE cooperation_project_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -155,6 +159,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
cooperationProject.ContractCount,
cooperationProject.Identify(),
); err != nil {
return cooperationProject, err
... ...
... ... @@ -70,10 +70,24 @@ type UserDetail struct {
DeletedAt time.Time `json:"deletedAt"`
OrgName string `json:"orgName"`
} `json:"userOrg"`
Favorite struct {
OrgItems []int64 `json:"orgItems"`
} `json:"favorite"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
}
func (user *UserDetail) CheckOrgStarred(orgId int64) bool {
var starred bool = false
for i := range user.Favorite.OrgItems {
if user.Favorite.OrgItems[i] == orgId {
starred = true
return starred
}
}
return false
}
func (translator *UserTranslator) ToRelevantFromRepresentation(user *UserDetail) (*domain.Relevant, error) {
var orgs []*domain.Org
for _, org := range user.UserOrg {
... ...