作者 yangfu

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

…ion-cooperation into dev
  1 +package dto
  2 +
  3 +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
  4 +
  5 +type CooperationContractByUndertakerDto struct {
  6 +}
  7 +
  8 +func (dto *CooperationContractByUndertakerDto) LoadDto(contract *domain.CooperationContract) error {
  9 + return nil
  10 +}
@@ -791,7 +791,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC @@ -791,7 +791,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
791 } 791 }
792 } 792 }
793 793
794 -// SearchCooperationContractByUndertaker 根据承接人返回共创项目合约 794 +// SearchCooperationContractByUndertaker TODO 根据承接人返回共创项目合约
795 func (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) { 795 func (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) {
796 if err := searchCooperationContractByUndertakerQuery.ValidateQuery(); err != nil { 796 if err := searchCooperationContractByUndertakerQuery.ValidateQuery(); err != nil {
797 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 797 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
6 "reflect" 6 "reflect"
7 "strings" 7 "strings"
8 - "time"  
9 ) 8 )
10 9
11 type OrderGoods struct { 10 type OrderGoods struct {
@@ -31,7 +30,7 @@ type CreateDividendsOrderCommand struct { @@ -31,7 +30,7 @@ type CreateDividendsOrderCommand struct {
31 // 分红订单原单号 30 // 分红订单原单号
32 DividendsOriginalOrderNum string `cname:"源单号" json:"dividendsOriginalOrderNum" valid:"Required"` 31 DividendsOriginalOrderNum string `cname:"源单号" json:"dividendsOriginalOrderNum" valid:"Required"`
33 // 订单时间 32 // 订单时间
34 - OrderTime time.Time `cname:"订单时间" json:"orderTime" valid:"Required"` 33 + OrderTime string `cname:"订单时间" json:"orderTime" valid:"Required"`
35 // 备注 34 // 备注
36 Remarks string `cname:"备注" json:"remarks" valid:"Required"` 35 Remarks string `cname:"备注" json:"remarks" valid:"Required"`
37 // 订单区域名称 36 // 订单区域名称
@@ -136,9 +136,12 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -136,9 +136,12 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
136 dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount 136 dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
137 } 137 }
138 138
139 - //// 订单时间转换  
140 - //orderTimeInt, _ := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)  
141 - //orderTime := utils.TransformTimestampToTime(orderTimeInt) 139 + // 订单时间转换
  140 + orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
  141 + if err != nil {
  142 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
  143 + }
  144 + orderTime := utils.TransformTimestampToTime(orderTimeInt)
142 145
143 // 新增分红订单 146 // 新增分红订单
144 newDividendsOrder := &domain.DividendsOrder{ 147 newDividendsOrder := &domain.DividendsOrder{
@@ -146,7 +149,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -146,7 +149,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
146 DividendsOrderNumber: dividendsOrderNumber, 149 DividendsOrderNumber: dividendsOrderNumber,
147 DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum, 150 DividendsOriginalOrderNum: createDividendsOrderCommand.DividendsOriginalOrderNum,
148 DividendsOrderAmount: dividendsOrderAmount, 151 DividendsOrderAmount: dividendsOrderAmount,
149 - OrderTime: createDividendsOrderCommand.OrderTime, 152 + OrderTime: orderTime,
150 DividendTime: time.Time{}, 153 DividendTime: time.Time{},
151 DividendStatus: domain.TO_BE_DIVIDEND, 154 DividendStatus: domain.TO_BE_DIVIDEND,
152 Region: &domain.RegionInfo{ 155 Region: &domain.RegionInfo{
@@ -258,8 +261,18 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -258,8 +261,18 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
258 dividendsOrderDao = value 261 dividendsOrderDao = value
259 } 262 }
260 263
  264 + // 分红订单仓储初始化
  265 + var dividendsOrderRepository domain.DividendsOrderRepository
  266 + if value, err1 := factory.CreateDividendsOrderRepository(map[string]interface{}{
  267 + "transactionContext": transactionContext,
  268 + }); err1 != nil {
  269 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err1.Error())
  270 + } else {
  271 + dividendsOrderRepository = value
  272 + }
  273 +
261 var dividendsOrderImportFailed []*domain.DividendsOrder 274 var dividendsOrderImportFailed []*domain.DividendsOrder
262 - var dividendsOrderImportSuccesfully []*domain.DividendsOrder 275 + var dividendsOrderImportSuccessfully []*domain.DividendsOrder
263 276
264 for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { 277 for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
265 // 生成分红订单号 278 // 生成分红订单号
@@ -269,13 +282,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -269,13 +282,13 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
269 } 282 }
270 283
271 // 校验分红订单编号是否唯一 284 // 校验分红订单编号是否唯一
272 - numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{ 285 + numberAvailable, err3 := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
273 "companyId": importDividendsOrderCommand.CompanyId, 286 "companyId": importDividendsOrderCommand.CompanyId,
274 "orgId": importDividendsOrderCommand.OrgId, 287 "orgId": importDividendsOrderCommand.OrgId,
275 "dividendsOrderNumber": dividendsOrderNumber, 288 "dividendsOrderNumber": dividendsOrderNumber,
276 }) 289 })
277 - if err != nil {  
278 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 290 + if err3 != nil {
  291 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
279 } 292 }
280 if !numberAvailable { 293 if !numberAvailable {
281 return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常") 294 return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
@@ -329,25 +342,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -329,25 +342,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
329 Operator: operator, 342 Operator: operator,
330 } 343 }
331 344
332 - // 分红订单仓储初始化  
333 - var dividendsOrderRepository domain.DividendsOrderRepository  
334 - if value, err1 := factory.CreateDividendsOrderRepository(map[string]interface{}{  
335 - "transactionContext": transactionContext,  
336 - }); err1 != nil {  
337 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err1.Error())  
338 - } else {  
339 - dividendsOrderRepository = value  
340 - }  
341 if dividendsOrderSaved, err2 := dividendsOrderRepository.Save(newDividendsOrder); err2 != nil { 345 if dividendsOrderSaved, err2 := dividendsOrderRepository.Save(newDividendsOrder); err2 != nil {
342 dividendsOrderImportFailed = append(dividendsOrderImportFailed, newDividendsOrder) 346 dividendsOrderImportFailed = append(dividendsOrderImportFailed, newDividendsOrder)
343 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())  
344 } else { 347 } else {
345 - dividendsOrderImportSuccesfully = append(dividendsOrderImportSuccesfully, dividendsOrderSaved)  
346 - return dividendsOrderSaved, nil 348 + dividendsOrderImportSuccessfully = append(dividendsOrderImportSuccessfully, dividendsOrderSaved)
347 } 349 }
348 } 350 }
349 - if err3 := transactionContext.CommitTransaction(); err3 != nil {  
350 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error()) 351 + if len(dividendsOrderImportFailed) == 0 {
  352 + if err3 := transactionContext.CommitTransaction(); err3 != nil {
  353 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error())
  354 + }
  355 + return dividendsOrderImportSuccessfully, nil
351 } 356 }
352 return nil, nil 357 return nil, nil
353 } 358 }
@@ -34,7 +34,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide @@ -34,7 +34,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
34 _ = transactionContext.RollbackTransaction() 34 _ = transactionContext.RollbackTransaction()
35 }() 35 }()
36 36
37 - // 公司REST服务初始 37 + // 公司REST服务初始
38 var companyService service.CompanyService 38 var companyService service.CompanyService
39 if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil { 39 if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
40 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 40 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -207,7 +207,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends @@ -207,7 +207,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends
207 } 207 }
208 } 208 }
209 209
210 -// ImportDividendsReturnedOrder TODO 导入分红退货单 210 +// ImportDividendsReturnedOrder 导入分红退货单
211 func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDividendsReturnedOrder(importDividendsReturnedOrderCommand *command.ImportDividendsReturnedOrderCommand) (interface{}, error) { 211 func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDividendsReturnedOrder(importDividendsReturnedOrderCommand *command.ImportDividendsReturnedOrderCommand) (interface{}, error) {
212 if err := importDividendsReturnedOrderCommand.ValidateCommand(); err != nil { 212 if err := importDividendsReturnedOrderCommand.ValidateCommand(); err != nil {
213 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 213 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -222,8 +222,140 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide @@ -222,8 +222,140 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
222 defer func() { 222 defer func() {
223 _ = transactionContext.RollbackTransaction() 223 _ = transactionContext.RollbackTransaction()
224 }() 224 }()
225 - if err := transactionContext.CommitTransaction(); err != nil { 225 +
  226 + // 公司REST服务初始化
  227 + var companyService service.CompanyService
  228 + if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
  229 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  230 + } else {
  231 + companyService = value
  232 + }
  233 +
  234 + // 获取公司信息
  235 + var company *domain.Company
  236 + if data, err := companyService.CompanyFrom(importDividendsReturnedOrderCommand.CompanyId); err != nil {
  237 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  238 + } else {
  239 + company = data
  240 + }
  241 +
  242 + // 组织机构REST服务初始化
  243 + var organizationService service.OrgService
  244 + if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
  245 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  246 + } else {
  247 + organizationService = value
  248 + }
  249 +
  250 + // 获取组织机构信息
  251 + var organization *domain.Org
  252 + if data, err := organizationService.OrgFrom(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId); err != nil {
  253 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  254 + } else {
  255 + organization = data
  256 + }
  257 +
  258 + // 用户REST服务初始化
  259 + var userService service.UserService
  260 + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil {
  261 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  262 + } else {
  263 + userService = value
  264 + }
  265 +
  266 + // 获取操作人
  267 + var operator *domain.User
  268 + if data, err := userService.OperatorFrom(importDividendsReturnedOrderCommand.CompanyId, importDividendsReturnedOrderCommand.OrgId, importDividendsReturnedOrderCommand.UserId); err != nil {
  269 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  270 + } else {
  271 + operator = data
  272 + }
  273 +
  274 + // 分红退货单DAO初始化
  275 + var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
  276 + if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
  277 + "transactionContext": transactionContext,
  278 + }); err != nil {
226 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 279 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  280 + } else {
  281 + dividendsReturnedOrderDao = value
  282 + }
  283 +
  284 + // 分红退货单仓储初始化
  285 + var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
  286 + if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
  287 + "transactionContext": transactionContext,
  288 + }); err != nil {
  289 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  290 + } else {
  291 + dividendsReturnedOrderRepository = value
  292 + }
  293 +
  294 + var dividendsReturnedOrderImportFailed []*domain.DividendsReturnedOrder
  295 + var dividendsReturnedOrderImportSuccessfully []*domain.DividendsReturnedOrder
  296 +
  297 + for _, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
  298 + // 生成分红订单号
  299 + dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
  300 + if err != nil {
  301 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  302 + }
  303 +
  304 + // 获取分红退货单产品
  305 + var orderGoods []*domain.OrderGood
  306 + for _, orderGood := range dividendsReturnedOrder.OrderGoods {
  307 + orderGoods = append(orderGoods, &domain.OrderGood{
  308 + OrderGoodId: 0,
  309 + OrderGoodAmount: orderGood.OrderGoodAmount,
  310 + OrderGoodName: orderGood.OrderGoodName,
  311 + OrderGoodPrice: orderGood.OrderGoodPrice,
  312 + OrderGoodQuantity: orderGood.OrderGoodQuantity,
  313 + DividendsOrderNumber: "",
  314 + DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
  315 + CooperationContractNumber: orderGood.CooperationContractNumber,
  316 + OrderGoodExpense: 0,
  317 + OrgId: importDividendsReturnedOrderCommand.OrgId,
  318 + CompanyId: importDividendsReturnedOrderCommand.CompanyId,
  319 + CreatedAt: time.Now(),
  320 + DeletedAt: time.Time{},
  321 + UpdatedAt: time.Time{},
  322 + })
  323 + }
  324 +
  325 + newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
  326 + DividendsReturnedOrderNumber: dividendsReturnedOrderNumber,
  327 + DividendsReturnedOrderRefund: dividendsReturnedOrder.DividendsReturnedOrderRefund,
  328 + OriginalOrderNum: dividendsReturnedOrder.OriginalOrderNum,
  329 + DividendsOrderNumber: "",
  330 + DividendsReturnedCustomerName: dividendsReturnedOrder.DividendsReturnedCustomerName,
  331 + DividendsReturnedDate: dividendsReturnedOrder.DividendsReturnedDate,
  332 + Region: &domain.RegionInfo{
  333 + RegionNumber: "",
  334 + RegionName: dividendsReturnedOrder.RegionName,
  335 + },
  336 + Goods: orderGoods,
  337 + Remarks: dividendsReturnedOrder.Remarks,
  338 + DividendStatus: domain.TO_BE_DIVIDENDED,
  339 + DividendTime: time.Time{},
  340 + Org: organization,
  341 + Company: company,
  342 + CreatedAt: time.Now(),
  343 + UpdatedAt: time.Time{},
  344 + Operator: operator,
  345 + OperateTime: time.Now(),
  346 + }
  347 +
  348 + if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(newDividendsReturnedOrder); err != nil {
  349 + dividendsReturnedOrderImportFailed = append(dividendsReturnedOrderImportFailed, newDividendsReturnedOrder)
  350 + } else {
  351 + dividendsReturnedOrderImportSuccessfully = append(dividendsReturnedOrderImportSuccessfully, dividendsReturnedOrderSaved)
  352 + }
  353 + }
  354 + if len(dividendsReturnedOrderImportFailed) == 0 {
  355 + if err := transactionContext.CommitTransaction(); err != nil {
  356 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  357 + }
  358 + return dividendsReturnedOrderImportSuccessfully, nil
227 } 359 }
228 return nil, nil 360 return nil, nil
229 } 361 }
@@ -330,6 +462,10 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD @@ -330,6 +462,10 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD
330 dividendsReturnedOrderRepository = value 462 dividendsReturnedOrderRepository = value
331 } 463 }
332 464
  465 + if len(batchRemoveDividendsOrderCommand.DividendsReturnedOrderIds) == 0 {
  466 + return nil, nil
  467 + }
  468 +
333 dividendsReturnedOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsReturnedOrderIds) 469 dividendsReturnedOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsReturnedOrderIds)
334 if err != nil { 470 if err != nil {
335 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号错误") 471 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号错误")
@@ -191,7 +191,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do @@ -191,7 +191,7 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
191 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil { 191 if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
192 return nil, err 192 return nil, err
193 } 193 }
194 - dividendsEstimatesSaved := []*domain.DividendsEstimate{} 194 + var dividendsEstimatesSaved []*domain.DividendsEstimate
195 for _, dividendsEstimateModel := range dividendsEstimateModels { 195 for _, dividendsEstimateModel := range dividendsEstimateModels {
196 if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil { 196 if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
197 return dividendsEstimates, err 197 return dividendsEstimates, err