作者 yangfu

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/allied-crea…

…tion-cooperation into test
@@ -19,6 +19,8 @@ type SearchCooperationProjectExtQuery struct { @@ -19,6 +19,8 @@ type SearchCooperationProjectExtQuery struct {
19 ExtUserId int64 `cname:"用户ID" json:"extUserId,omitempty"` 19 ExtUserId int64 `cname:"用户ID" json:"extUserId,omitempty"`
20 // 用户基础数据id 20 // 用户基础数据id
21 ExtUserBaseId int64 `cname:"用户基础数据ID" json:"extUserBaseId,omitempty"` 21 ExtUserBaseId int64 `cname:"用户基础数据ID" json:"extUserBaseId,omitempty"`
  22 + // 共创项目承接对象,1员工,2共创用户,3公开,可多选
  23 + ExtCooperationProjectUndertakerTypes []int32 `json:"extCooperationProjectUndertakerTypes"`
22 } 24 }
23 25
24 type SearchCooperationProjectQuery struct { 26 type SearchCooperationProjectQuery struct {
@@ -30,8 +32,10 @@ type SearchCooperationProjectQuery struct { @@ -30,8 +32,10 @@ type SearchCooperationProjectQuery struct {
30 CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName,omitempty"` 32 CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName,omitempty"`
31 // 共创项目编号 33 // 共创项目编号
32 CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber,omitempty"` 34 CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber,omitempty"`
33 - // 共创项目承接对象,1员工,2共创用户,4公开,可以多选 35 + // 共创项目承接对象,1员工,2共创用户,3公开
34 CooperationProjectUndertakerType int32 `json:"cooperationProjectUndertakerType"` 36 CooperationProjectUndertakerType int32 `json:"cooperationProjectUndertakerType"`
  37 + // 共创项目承接对象,1员工,2共创用户,3公开,可多选
  38 + CooperationProjectUndertakerTypes []int32 `json:"cooperationProjectUndertakerTypes"`
35 // 部门名称 39 // 部门名称
36 DepartmentName string `cname:"部门名称" json:"departmentName,omitempty"` 40 DepartmentName string `cname:"部门名称" json:"departmentName,omitempty"`
37 // 关键字搜索 41 // 关键字搜索
@@ -1271,19 +1271,27 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide @@ -1271,19 +1271,27 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
1271 var orderGoods []*domain.OrderGood 1271 var orderGoods []*domain.OrderGood
1272 var dividendsReturnedOrderAmount float64 1272 var dividendsReturnedOrderAmount float64
1273 for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods { 1273 for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods {
  1274 +
1274 // 产品ID类型转换 1275 // 产品ID类型转换
1275 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64) 1276 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
1276 if err3 != nil { 1277 if err3 != nil {
1277 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) 1278 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
1278 } 1279 }
1279 1280
  1281 + orderGoodFound := &domain.OrderGood{}
  1282 +
1280 // 获取产品 1283 // 获取产品
1281 - orderGoodFound, err4 := orderGoodRepository.FindOne(map[string]interface{}{ 1284 + if orderGood.OrderGoodId != "" {
  1285 + orderGoodFetched, err4 := orderGoodRepository.FindOne(map[string]interface{}{
1282 "orderGoodId": orderGoodId, 1286 "orderGoodId": orderGoodId,
1283 }) 1287 })
1284 if err4 != nil { 1288 if err4 != nil {
1285 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) 1289 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
1286 } 1290 }
  1291 + orderGoodFound = orderGoodFetched
  1292 + } else {
  1293 + orderGoodFound.OrderGoodDividendsStatus = int32(1)
  1294 + }
1287 1295
1288 // 退货产品金额计算 1296 // 退货产品金额计算
1289 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() 1297 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
@@ -5,7 +5,7 @@ import "os" @@ -5,7 +5,7 @@ import "os"
5 const SERVICE_NAME = "allied-creation-cooperation" 5 const SERVICE_NAME = "allied-creation-cooperation"
6 6
7 // LOG_TYPE 日志相关设置 7 // LOG_TYPE 日志相关设置
8 -var LOG_TYPE = "terminal" // file, terminal, es 8 +var LOG_TYPE = "console" // file, console, es
9 var LOG_FRAMEWORK = "beego" // beego logrus 9 var LOG_FRAMEWORK = "beego" // beego logrus
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 var LOG_FILE = "app.log" 11 var LOG_FILE = "app.log"
@@ -3,6 +3,8 @@ package repository @@ -3,6 +3,8 @@ package repository
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg/v10" 5 "github.com/go-pg/pg/v10"
  6 + "github.com/go-pg/pg/v10/orm"
  7 + query2 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
8 "time" 10 "time"
@@ -266,6 +268,39 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int @@ -266,6 +268,39 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
266 if cooperationProjectUndertakerType, ok := queryOptions["cooperationProjectUndertakerType"]; ok && cooperationProjectUndertakerType.(int32) != 0 { 268 if cooperationProjectUndertakerType, ok := queryOptions["cooperationProjectUndertakerType"]; ok && cooperationProjectUndertakerType.(int32) != 0 {
267 query.Where(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType) 269 query.Where(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
268 } 270 }
  271 + if cooperationProjectUndertakerTypes, ok := queryOptions["cooperationProjectUndertakerTypes"]; ok && len(cooperationProjectUndertakerTypes.([]int32)) > 0 {
  272 + query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  273 + for _, cooperationProjectUndertakerType := range cooperationProjectUndertakerTypes.([]int32) {
  274 + q.WhereOr(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
  275 + }
  276 + return q, nil
  277 + })
  278 + }
  279 + if searchCooperationProjectExtQueries, ok := queryOptions["searchCooperationProjectExtQueries"]; ok && len(searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery)) > 0 {
  280 + for _, searchCooperationProjectExtQuery := range searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery) {
  281 + query.WhereOrGroup(func(q *orm.Query) (*orm.Query, error) {
  282 + if searchCooperationProjectExtQuery.ExtCompanyId != 0 {
  283 + q.Where("company->>'companyId' = '?'", searchCooperationProjectExtQuery.ExtCompanyId)
  284 + }
  285 + if searchCooperationProjectExtQuery.ExtOrgId != 0 {
  286 + q.Where("org->>'orgId' = '?'", searchCooperationProjectExtQuery.ExtOrgId)
  287 + }
  288 + if len(searchCooperationProjectExtQuery.ExtOrgIds) > 0 {
  289 + newOrgIds := utils.SliceItoa(searchCooperationProjectExtQuery.ExtOrgIds)
  290 + q.Where("org->>'orgId' in (?)", pg.In(newOrgIds))
  291 + }
  292 + if len(searchCooperationProjectExtQuery.ExtCooperationProjectUndertakerTypes) > 0 {
  293 + q.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
  294 + for _, cooperationProjectUndertakerType := range searchCooperationProjectExtQuery.ExtCooperationProjectUndertakerTypes {
  295 + q.WhereOr(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, cooperationProjectUndertakerType)
  296 + }
  297 + return q, nil
  298 + })
  299 + }
  300 + return q, nil
  301 + })
  302 + }
  303 + }
269 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" { 304 if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
270 query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName)) 305 query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName))
271 } 306 }
@@ -53,7 +53,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -53,7 +53,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
53 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id") 53 updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id")
54 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) 54 updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
55 tx := repository.transactionContext.PgTx 55 tx := repository.transactionContext.PgTx
56 - if dividendsReturnedOrder.Identify() == nil { 56 + if dividendsReturnedOrder.Identify() == nil { // 新增分红退货单
57 dividendsReturnedOrderId, err := repository.nextIdentify() 57 dividendsReturnedOrderId, err := repository.nextIdentify()
58 if err != nil { 58 if err != nil {
59 return dividendsReturnedOrder, err 59 return dividendsReturnedOrder, err
@@ -137,7 +137,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -137,7 +137,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
137 if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil { 137 if _, err := tx.Model(&orderGoodsModel).Insert(); err != nil {
138 return nil, err 138 return nil, err
139 } 139 }
140 - } else { 140 + } else { // 编辑分红退货单
141 if _, err := tx.QueryOne( 141 if _, err := tx.QueryOne(
142 pg.Scan( 142 pg.Scan(
143 &dividendsReturnedOrder.DividendsReturnedOrderId, 143 &dividendsReturnedOrder.DividendsReturnedOrderId,
@@ -200,8 +200,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -200,8 +200,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
200 200
201 // 待更新分红退货单产品 201 // 待更新分红退货单产品
202 var orderGoodsToUpdate []*domain.OrderGood 202 var orderGoodsToUpdate []*domain.OrderGood
  203 +
203 // 待添加分红退货单产品 204 // 待添加分红退货单产品
204 var orderGoodsToAdd []*domain.OrderGood 205 var orderGoodsToAdd []*domain.OrderGood
  206 +
205 for _, good := range dividendsReturnedOrder.Goods { 207 for _, good := range dividendsReturnedOrder.Goods {
206 if good.OrderGoodId != 0 { 208 if good.OrderGoodId != 0 {
207 orderGoodsToUpdate = append(orderGoodsToUpdate, good) 209 orderGoodsToUpdate = append(orderGoodsToUpdate, good)
@@ -305,7 +307,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder @@ -305,7 +307,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder
305 } 307 }
306 } 308 }
307 if len(orderGoodModelsToDelete) > 0 { 309 if len(orderGoodModelsToDelete) > 0 {
308 - if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil { 310 + if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil {
309 return nil, err 311 return nil, err
310 } 312 }
311 } 313 }