作者 陈志颖

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
... ... @@ -184,10 +184,10 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"grid": map[string]interface{}{
//"grid": map[string]interface{}{
"list": cooperationModes,
"total": count,
},
//},
}, nil
}
}
... ... @@ -305,10 +305,10 @@ func (cooperationModeService *CooperationModeService) SearchCooperationMode(sear
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"grid": map[string]interface{}{
//"grid": map[string]interface{}{
"list": cooperationModes,
"total": count,
},
//},
}, nil
}
}
... ...
... ... @@ -219,10 +219,10 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"grid": map[string]interface{}{
//"grid": map[string]interface{}{
"total": count,
"list": cooperationProjects,
},
//},
}, nil
}
}
... ... @@ -303,10 +303,27 @@ func (cooperationProjectService *CooperationProjectService) SearchCooperationPro
defer func() {
_ = transactionContext.RollbackTransaction()
}()
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
if count, cooperationProjects, err := cooperationProjectRepository.Find(tool_funs.SimpleStructToMap(searchCooperationProjectQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return map[string]interface{}{
//"grid": map[string]interface{}{
"total": count,
"list": cooperationProjects,
//},
}, nil
}
}
// UpdateCooperationProject 更新共创项目服务
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
type OrderGoodDao struct {
transactionContext *pgTransaction.TransactionContext
}
// CooperationGoodsStatistics 共创产品统计数据
//
// queryOptions 查询参数
// - beginTime 开始时间
// - endTime 结束时间
// - companyId 企业Id
// - orgId 组织Id
func (dao *OrderGoodDao) CooperationGoodsStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationGoodsStatisticsDto, error) {
tx := dao.transactionContext.PgTx
var goods []*domain.CooperationGoodsStatisticsDto
var queryTime string
if _, ok := queryOptions["beginTime"]; ok {
queryTime = fmt.Sprintf("and created_at>='%v' and created_at<'%v'", queryOptions["beginTime"], queryOptions["endTime"])
}
sql := fmt.Sprintf(`select order_good_name goodName,sum(order_good_amount) goodAmount from order_goods
where company_id=? and org_id = ? %v
GROUP BY order_good_name
order by goodAmount desc`, queryTime)
_, err := tx.Query(&goods, sql, queryOptions["companyId"], queryOptions["orgId"])
return goods, err
}
func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderGoodDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package domain_service
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"time"
)
// PgCommonStatisticsService 通用统计服务
type PgCommonStatisticsService struct {
transactionContext *pgTransaction.TransactionContext
}
const (
// 共创产品统计数据
CooperationGoodsStatistics = iota + 1
)
var (
MapKey = map[int]string{
CooperationGoodsStatistics: "cooperationGoodsStatistics",
}
)
// Scan 扫描需要统计的项
//
// keyFlags 统计项标识符号
// queryOption 查询参数
func (ptr *PgCommonStatisticsService) Scan(keyFlags []int, queryOption map[string]interface{}) (interface{}, error) {
var res = make(map[string]interface{})
for i := range keyFlags {
switch keyFlags[i] {
case CooperationGoodsStatistics:
}
}
return res, nil
}
// totalOrganizationUser 统计组织用户
// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
func (ptr *PgCommonStatisticsService) CooperationGoodsStatistics(companyId, orgId int64, rankType int) ([]*domain.CooperationGoodsStatisticsDto, error) {
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
queryOptions := make(map[string]interface{})
queryOptions["companyId"] = companyId
queryOptions["orgId"] = orgId
y := time.Now().Year()
m := time.Now().Month()
var beginTime, endTime time.Time
if 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年榜
beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
endTime = beginTime.AddDate(1, 0, 0)
queryOptions["beginTime"] = beginTime
queryOptions["endTime"] = endTime
}
return orderGoodDao.CooperationGoodsStatistics(queryOptions)
}
func (ptr *PgCommonStatisticsService) loadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[string]interface{}, error) {
var res = make(map[string]interface{})
for i := 0; i < len(keys); i++ {
k := keys[i]
if v, ok := queryOption[k]; ok {
res[k] = v
} else {
return nil, fmt.Errorf("参数 %v 不存在", k)
}
}
return res, nil
}
type item struct {
key string
val interface{}
}
... ...
package pg
import (
"context"
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
... ... @@ -9,7 +10,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"github.com/linmadan/egglib-go/persistent/pg/comment"
"github.com/linmadan/egglib-go/persistent/pg/hooks"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
... ... @@ -23,7 +23,7 @@ func init() {
Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
})
if !constant.DISABLE_SQL_GENERATE_PRINT {
DB.AddQueryHook(hooks.SqlGeneratePrintHook{Logger: log.Logger})
DB.AddQueryHook(SqlGeneratePrintHook{})
}
if !constant.DISABLE_CREATE_TABLE {
for _, model := range []interface{}{
... ... @@ -55,3 +55,19 @@ func init() {
}
}
}
type SqlGeneratePrintHook struct {
}
func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
return c, nil
}
func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
sqlStr, err := q.FormattedQuery()
if err != nil {
return err
}
log.Logger.Debug(string(sqlStr))
return nil
}
... ...
... ... @@ -20,7 +20,7 @@ func init() {
web.BConfig.RunMode = "dev"
web.BConfig.Listen.HTTPPort = 8082
web.BConfig.Listen.EnableAdmin = false
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego"
web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
if os.Getenv("RUN_MODE") != "" {
web.BConfig.RunMode = os.Getenv("RUN_MODE")
}
... ...