作者 yangfu

企业端共创统计修改

... ... @@ -37,6 +37,12 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.SearchContractDividends(contractStatisticsQuery.QueryOptions)
case domain_service.GetContractDividends:
res, err = statisticsService.GetContractDividends(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationGoodsStatistics:
res, err = statisticsService.CooperationGoodsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CooperationModeStatistics:
res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyDividendsStatistics:
res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -27,7 +27,7 @@ type CooperationModeStatisticsDto struct {
type DividendStatisticsDto struct {
// 分红预算
DividendsEstimate string `json:"dividendsEstimate"`
DividendsEstimate float64 `json:"dividendsEstimate"`
// 订单金额
OrderAmount float64 `json:"orderAmount"`
}
\ No newline at end of file
}
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type OrderGoodDao struct {
... ... @@ -20,7 +21,7 @@ type OrderGoodDao struct {
func (dao *OrderGoodDao) CooperationGoodsStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationGoodsStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var goods []*domain.CooperationGoodsStatisticsDto
var queryTime,queryLimit string
var queryTime, queryLimit string
if _, ok := queryOptions["beginTime"]; ok {
queryTime = fmt.Sprintf("and created_at>='%v' and created_at<'%v'", queryOptions["beginTime"], queryOptions["endTime"])
}
... ... @@ -32,7 +33,7 @@ where company_id=? and org_id = ? %v
GROUP BY order_good_name
order by goodAmount desc
%v
`, queryTime,queryLimit)
`, queryTime, queryLimit)
_, err := tx.Query(&goods, sql, queryOptions["companyId"], queryOptions["orgId"])
return goods, err
}
... ... @@ -62,26 +63,24 @@ group by b.cooperation_mode_number
// - companyId 企业Id
// - orgId 组织Id
// - paymentStatus 支付状态
func (dao *OrderGoodDao) DividendsStatistics(queryOptions map[string]interface{}) (*domain.DividendStatisticsDto, error) {
func (dao *OrderGoodDao) CompanyDividendsStatistics(queryOptions map[string]interface{}) (*domain.DividendStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var queryTime, queryPaymentStatus string
if _, ok := queryOptions["beginTime"]; ok {
queryTime = fmt.Sprintf("and created_at>='%v' and created_at<'%v'", queryOptions["beginTime"], queryOptions["endTime"])
queryTime = fmt.Sprintf("and created_at>='%s' and created_at<'%s'", (queryOptions["beginTime"].(time.Time)).Format(time.RFC3339), (queryOptions["endTime"].(time.Time)).Format(time.RFC3339))
}
if _, ok := queryOptions["paymentStatus"]; ok {
queryPaymentStatus = fmt.Sprintf(" and payment_status=%v", queryOptions["paymentStatus"])
}
sql := fmt.Sprintf(`select sum(actually_paid_amount) dividendsEstimate,0 orderAmount
sql := fmt.Sprintf(`select sum(actually_paid_amount) dividends_estimate,0 order_amount
from credit_accounts
where company->>'companyId' = '?' and org->>'orgId' = '?' %v %v
`, queryTime, queryPaymentStatus)
var s *domain.DividendStatisticsDto
_, err := tx.Query(&s, sql, queryOptions["companyId"], queryOptions["orgId"])
var s = &domain.DividendStatisticsDto{}
_, err := tx.Query(s, sql, queryOptions["companyId"], queryOptions["orgId"])
return s, err
}
func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ... @@ -90,4 +89,4 @@ func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*Ord
transactionContext: transactionContext,
}, nil
}
}
\ No newline at end of file
}
... ...
... ... @@ -2,6 +2,9 @@ package domain_service
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"github.com/linmadan/egglib-go/utils/json"
"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/utils"
... ... @@ -12,32 +15,44 @@ import (
// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
// top 排名前n个
func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(companyId, orgId int64, rankType int, top int) ([]*domain.CooperationGoodsStatisticsDto, error) {
func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationGoodsStatisticsDto, error) {
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
// 参数验证
var request = struct {
CompanyId int64 `json:"companyId" valid:"Required"`
OrgId int64 `json:"orgId" valid:"Required"`
RankType int `json:"rankType" valid:"Required"`
Top int `json:"top" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
y := time.Now().Year()
m := time.Now().Month()
var beginTime, endTime time.Time
if rankType == 1 { //1月榜
if request.RankType == 1 { //1月榜
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(0, 1, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
} else if rankType == 2 { //2年榜
queryOptions["beginTime"] = beginTime.Format(time.RFC3339)
queryOptions["endTime"] = endTime.Format(time.RFC3339)
} else if request.RankType == 2 { //2年榜
beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(1, 0, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
queryOptions["beginTime"] = beginTime.Format(time.RFC3339)
queryOptions["endTime"] = endTime.Format(time.RFC3339)
}
if top > 0 {
queryOptions["limit"] = top
if request.Top > 0 {
queryOptions["limit"] = request.Top
}
goods, err := orderGoodDao.CooperationGoodsStatistics(queryOptions)
if err != nil {
return nil, err
}
if len(goods) == 0 {
goods = make([]*domain.CooperationGoodsStatisticsDto, 0)
}
// 2.计算百分比
var totalAmount float64
... ... @@ -54,16 +69,25 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(companyId, o
// CooperationModeStatistics 企业-共创模式统计
//
// p1 p1_desc
func (ptr *CooperationStatisticsService) CooperationModeStatistics(companyId, orgId int64) ([]*domain.CooperationModeStatisticsDto, error) {
func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
// 参数验证
var request = struct {
CompanyId int64 `json:"companyId" valid:"Required"`
OrgId int64 `json:"orgId" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
modeStatistics, err := orderGoodDao.CooperationModeStatistics(queryOptions)
if err != nil {
return nil, err
}
if len(modeStatistics) == 0 {
modeStatistics = make([]*domain.CooperationModeStatisticsDto, 0)
}
return modeStatistics, nil
}
... ... @@ -71,14 +95,22 @@ func (ptr *CooperationStatisticsService) CooperationModeStatistics(companyId, or
// DividendsStatistics 分红统计
//
// action 1:当前月
func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(companyId, orgId int64, action int) (interface{}, error) {
func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
CompanyId int64 `json:"companyId" valid:"Required"`
OrgId int64 `json:"orgId" valid:"Required"`
Action int `json:"action" valid:"Required"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
var beginTime, endTime time.Time
var res = make(map[string]interface{})
if action == 1 {
if request.Action == 1 {
y := time.Now().Year()
m := time.Now().Month()
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
... ... @@ -86,18 +118,18 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(companyId, o
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
}
totalDividends, err := orderGoodDao.DividendsStatistics(queryOptions)
totalDividends, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
if err != nil {
return nil, err
}
res["creditAccount"] = totalDividends.DividendsEstimate
res["orderAmount"] = totalDividends.OrderAmount
queryOptions["paymentStatus"] = 2
dividendsEstimate, err := orderGoodDao.DividendsStatistics(queryOptions)
dividendsEstimate, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
if err != nil {
return nil, err
}
res["creditAccount"] = totalDividends.DividendsEstimate
res["orderAmount"] = totalDividends.OrderAmount
res["dividendsEstimate"] = dividendsEstimate.DividendsEstimate
return res, nil
}
... ... @@ -115,6 +147,13 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s
return res, nil
}
func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
json.UnmarshalFromString(json.MarshalToString(queryOption), obj)
validation := validation.Validation{}
_, err := validation.Valid(obj)
return err
}
type item struct {
key string
val interface{}
... ...