作者 yangfu

共创模式修改

@@ -184,10 +184,10 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo @@ -184,10 +184,10 @@ func (cooperationModeService *CooperationModeService) ListCooperationMode(listCo
184 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 184 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
185 } 185 }
186 return map[string]interface{}{ 186 return map[string]interface{}{
187 - "grid": map[string]interface{}{  
188 - "list": cooperationModes,  
189 - "total": count,  
190 - }, 187 + //"grid": map[string]interface{}{
  188 + "list": cooperationModes,
  189 + "total": count,
  190 + //},
191 }, nil 191 }, nil
192 } 192 }
193 } 193 }
@@ -305,10 +305,10 @@ func (cooperationModeService *CooperationModeService) SearchCooperationMode(sear @@ -305,10 +305,10 @@ func (cooperationModeService *CooperationModeService) SearchCooperationMode(sear
305 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 305 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
306 } 306 }
307 return map[string]interface{}{ 307 return map[string]interface{}{
308 - "grid": map[string]interface{}{  
309 - "list": cooperationModes,  
310 - "total": count,  
311 - }, 308 + //"grid": map[string]interface{}{
  309 + "list": cooperationModes,
  310 + "total": count,
  311 + //},
312 }, nil 312 }, nil
313 } 313 }
314 } 314 }
@@ -219,10 +219,10 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje @@ -219,10 +219,10 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
219 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 219 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
220 } 220 }
221 return map[string]interface{}{ 221 return map[string]interface{}{
222 - "grid": map[string]interface{}{  
223 - "total": count,  
224 - "list": cooperationProjects,  
225 - }, 222 + //"grid": map[string]interface{}{
  223 + "total": count,
  224 + "list": cooperationProjects,
  225 + //},
226 }, nil 226 }, nil
227 } 227 }
228 } 228 }
@@ -303,10 +303,27 @@ func (cooperationProjectService *CooperationProjectService) SearchCooperationPro @@ -303,10 +303,27 @@ func (cooperationProjectService *CooperationProjectService) SearchCooperationPro
303 defer func() { 303 defer func() {
304 _ = transactionContext.RollbackTransaction() 304 _ = transactionContext.RollbackTransaction()
305 }() 305 }()
306 - if err := transactionContext.CommitTransaction(); err != nil {  
307 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 306 + var cooperationProjectRepository domain.CooperationProjectRepository
  307 + if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
  308 + "transactionContext": transactionContext,
  309 + }); err != nil {
  310 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  311 + } else {
  312 + cooperationProjectRepository = value
  313 + }
  314 + if count, cooperationProjects, err := cooperationProjectRepository.Find(tool_funs.SimpleStructToMap(searchCooperationProjectQuery)); err != nil {
  315 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  316 + } else {
  317 + if err := transactionContext.CommitTransaction(); err != nil {
  318 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  319 + }
  320 + return map[string]interface{}{
  321 + //"grid": map[string]interface{}{
  322 + "total": count,
  323 + "list": cooperationProjects,
  324 + //},
  325 + }, nil
308 } 326 }
309 - return nil, nil  
310 } 327 }
311 328
312 // UpdateCooperationProject 更新共创项目服务 329 // UpdateCooperationProject 更新共创项目服务
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  7 +)
  8 +
  9 +type OrderGoodDao struct {
  10 + transactionContext *pgTransaction.TransactionContext
  11 +}
  12 +
  13 +// CooperationGoodsStatistics 共创产品统计数据
  14 +//
  15 +// queryOptions 查询参数
  16 +// - beginTime 开始时间
  17 +// - endTime 结束时间
  18 +// - companyId 企业Id
  19 +// - orgId 组织Id
  20 +func (dao *OrderGoodDao) CooperationGoodsStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationGoodsStatisticsDto, error) {
  21 + tx := dao.transactionContext.PgTx
  22 + var goods []*domain.CooperationGoodsStatisticsDto
  23 + var queryTime string
  24 + if _, ok := queryOptions["beginTime"]; ok {
  25 + queryTime = fmt.Sprintf("and created_at>='%v' and created_at<'%v'", queryOptions["beginTime"], queryOptions["endTime"])
  26 + }
  27 + sql := fmt.Sprintf(`select order_good_name goodName,sum(order_good_amount) goodAmount from order_goods
  28 +where company_id=? and org_id = ? %v
  29 +GROUP BY order_good_name
  30 +order by goodAmount desc`, queryTime)
  31 + _, err := tx.Query(&goods, sql, queryOptions["companyId"], queryOptions["orgId"])
  32 + return goods, err
  33 +}
  34 +
  35 +func NewOrderGoodDao(transactionContext *pgTransaction.TransactionContext) (*OrderGoodDao, error) {
  36 + if transactionContext == nil {
  37 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  38 + } else {
  39 + return &OrderGoodDao{
  40 + transactionContext: transactionContext,
  41 + }, nil
  42 + }
  43 +}
  1 +package domain_service
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
  8 + "time"
  9 +)
  10 +
  11 +// PgCommonStatisticsService 通用统计服务
  12 +type PgCommonStatisticsService struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +const (
  17 + // 共创产品统计数据
  18 + CooperationGoodsStatistics = iota + 1
  19 +)
  20 +
  21 +var (
  22 + MapKey = map[int]string{
  23 + CooperationGoodsStatistics: "cooperationGoodsStatistics",
  24 + }
  25 +)
  26 +
  27 +// Scan 扫描需要统计的项
  28 +//
  29 +// keyFlags 统计项标识符号
  30 +// queryOption 查询参数
  31 +func (ptr *PgCommonStatisticsService) Scan(keyFlags []int, queryOption map[string]interface{}) (interface{}, error) {
  32 + var res = make(map[string]interface{})
  33 + for i := range keyFlags {
  34 + switch keyFlags[i] {
  35 + case CooperationGoodsStatistics:
  36 + }
  37 + }
  38 + return res, nil
  39 +}
  40 +
  41 +// totalOrganizationUser 统计组织用户
  42 +
  43 +// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
  44 +func (ptr *PgCommonStatisticsService) CooperationGoodsStatistics(companyId, orgId int64, rankType int) ([]*domain.CooperationGoodsStatisticsDto, error) {
  45 + orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
  46 + queryOptions := make(map[string]interface{})
  47 + queryOptions["companyId"] = companyId
  48 + queryOptions["orgId"] = orgId
  49 + y := time.Now().Year()
  50 + m := time.Now().Month()
  51 + var beginTime, endTime time.Time
  52 + if rankType == 1 { //1月榜
  53 + beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
  54 + endTime = beginTime.AddDate(0, 1, 0)
  55 + queryOptions["beginTime"] = beginTime
  56 + queryOptions["endTime"] = endTime
  57 + } else if rankType == 2 { //2年榜
  58 + beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
  59 + endTime = beginTime.AddDate(1, 0, 0)
  60 + queryOptions["beginTime"] = beginTime
  61 + queryOptions["endTime"] = endTime
  62 + }
  63 + return orderGoodDao.CooperationGoodsStatistics(queryOptions)
  64 +}
  65 +
  66 +func (ptr *PgCommonStatisticsService) loadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[string]interface{}, error) {
  67 + var res = make(map[string]interface{})
  68 + for i := 0; i < len(keys); i++ {
  69 + k := keys[i]
  70 + if v, ok := queryOption[k]; ok {
  71 + res[k] = v
  72 + } else {
  73 + return nil, fmt.Errorf("参数 %v 不存在", k)
  74 + }
  75 + }
  76 + return res, nil
  77 +}
  78 +
  79 +type item struct {
  80 + key string
  81 + val interface{}
  82 +}
1 package pg 1 package pg
2 2
3 import ( 3 import (
  4 + "context"
4 "fmt" 5 "fmt"
5 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
6 "github.com/go-pg/pg/v10/orm" 7 "github.com/go-pg/pg/v10/orm"
@@ -9,7 +10,6 @@ import ( @@ -9,7 +10,6 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
10 11
11 "github.com/linmadan/egglib-go/persistent/pg/comment" 12 "github.com/linmadan/egglib-go/persistent/pg/comment"
12 - "github.com/linmadan/egglib-go/persistent/pg/hooks"  
13 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 13 _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
14 ) 14 )
15 15
@@ -23,7 +23,7 @@ func init() { @@ -23,7 +23,7 @@ func init() {
23 Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), 23 Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
24 }) 24 })
25 if !constant.DISABLE_SQL_GENERATE_PRINT { 25 if !constant.DISABLE_SQL_GENERATE_PRINT {
26 - DB.AddQueryHook(hooks.SqlGeneratePrintHook{Logger: log.Logger}) 26 + DB.AddQueryHook(SqlGeneratePrintHook{})
27 } 27 }
28 if !constant.DISABLE_CREATE_TABLE { 28 if !constant.DISABLE_CREATE_TABLE {
29 for _, model := range []interface{}{ 29 for _, model := range []interface{}{
@@ -55,3 +55,19 @@ func init() { @@ -55,3 +55,19 @@ func init() {
55 } 55 }
56 } 56 }
57 } 57 }
  58 +
  59 +type SqlGeneratePrintHook struct {
  60 +}
  61 +
  62 +func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
  63 + return c, nil
  64 +}
  65 +
  66 +func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
  67 + sqlStr, err := q.FormattedQuery()
  68 + if err != nil {
  69 + return err
  70 + }
  71 + log.Logger.Debug(string(sqlStr))
  72 + return nil
  73 +}
@@ -20,7 +20,7 @@ func init() { @@ -20,7 +20,7 @@ func init() {
20 web.BConfig.RunMode = "dev" 20 web.BConfig.RunMode = "dev"
21 web.BConfig.Listen.HTTPPort = 8082 21 web.BConfig.Listen.HTTPPort = 8082
22 web.BConfig.Listen.EnableAdmin = false 22 web.BConfig.Listen.EnableAdmin = false
23 - web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego" 23 + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego/routers"
24 if os.Getenv("RUN_MODE") != "" { 24 if os.Getenv("RUN_MODE") != "" {
25 web.BConfig.RunMode = os.Getenv("RUN_MODE") 25 web.BConfig.RunMode = os.Getenv("RUN_MODE")
26 } 26 }