作者 yangfu

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

…ion-cooperation into dev
... ... @@ -92,6 +92,7 @@ func (cooperationModeService *CooperationModeService) CreateCooperationMode(crea
} else {
cooperationModeDao = value
}
// 校验共创模式编码唯一性
numberAvailable, _ := cooperationModeDao.CheckModeNumberAvailable(map[string]interface{}{
"companyId": createCooperationModeCommand.CompanyId,
... ... @@ -231,6 +232,8 @@ func (cooperationModeService *CooperationModeService) RemoveCooperationMode(remo
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 共创模式仓储初始化
var cooperationModeRepository domain.CooperationModeRepository
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -239,6 +242,18 @@ func (cooperationModeService *CooperationModeService) RemoveCooperationMode(remo
} else {
cooperationModeRepository = value
}
// 共创模式DAO初始化
var cooperationModeDao *dao.CooperationModeDao
if value, err := factory.CreateCooperationModeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationModeDao = value
}
// 获取共创模式
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeId": removeCooperationModeCommand.CooperationModeId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")
... ... @@ -246,13 +261,25 @@ func (cooperationModeService *CooperationModeService) RemoveCooperationMode(remo
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCooperationModeCommand.CooperationModeId, 10)))
}
if cooperationMode, err := cooperationModeRepository.Remove(cooperationMode); err != nil {
// 校验共创模式是否可以删除
deleteAvailable, _ := cooperationModeDao.CheckModeIsDeleteAvailable(map[string]interface{}{
"companyId": removeCooperationModeCommand.CompanyId,
"orgId": removeCooperationModeCommand.OrgId,
"cooperationModeNumber": cooperationMode.CooperationModeNumber,
})
if !deleteAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "当前共创模式存在业务数据,不可删除")
}
// 移除共创模式
if cooperationModeRemoved, err := cooperationModeRepository.Remove(cooperationMode); 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 cooperationMode, nil
return cooperationModeRemoved, nil
}
}
... ... @@ -271,6 +298,8 @@ func (cooperationModeService *CooperationModeService) BatchRemoveCooperationMode
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 共创模式仓储初始化
var cooperationModeRepository domain.CooperationModeRepository
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -279,13 +308,41 @@ func (cooperationModeService *CooperationModeService) BatchRemoveCooperationMode
} else {
cooperationModeRepository = value
}
cooperationModeIds, _ := utils.SliceAtoi(batchRemoveCooperationModeCommand.CooperationModeIds)
// 共创模式ID列表类型转换
cooperationModeIds, err := utils.SliceAtoi(batchRemoveCooperationModeCommand.CooperationModeIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式类型错误")
}
// 共创模式DAO初始化
var cooperationModeDao *dao.CooperationModeDao
if value, err := factory.CreateCooperationModeDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationModeDao = value
}
// 获取共创模式
if count, cooperationModes, err := cooperationModeRepository.Find(map[string]interface{}{
"cooperationModeIds": cooperationModeIds,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationMode := range cooperationModes {
// 校验共创模式是否可以删除
deleteAvailable, _ := cooperationModeDao.CheckModeIsDeleteAvailable(map[string]interface{}{
"companyId": batchRemoveCooperationModeCommand.CompanyId,
"orgId": batchRemoveCooperationModeCommand.OrgId,
"cooperationModeNumber": cooperationMode.CooperationModeNumber,
})
if !deleteAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "所选共创模式存在业务数据,不可删除")
}
}
if cooperationMode, err := cooperationModeRepository.BatchRemove(cooperationModes); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -195,6 +195,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
ApplicantCount: 0,
}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
... ...
... ... @@ -653,6 +653,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
... ... @@ -696,6 +698,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
... ...
... ... @@ -11,6 +11,8 @@ import (
type GetDividendsOrderQuery struct {
// 分红订单ID
DividendsOrderId int64 `cname:"分红订单ID" json:"dividendsOrderId" valid:"Required"`
// 分红订单编号
DividendsOrderNumber string `cname:"分红订单编号" json:"dividendsOrderNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -41,7 +41,7 @@ type CreateDividendsReturnedOrderCommand struct {
// 退货日期
DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 订单日期
OrderTime time.Time `cname:"订单日期" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单日期" json:"orderTime" valid:"Required"`
// 退货区域名称
RegionName string `cname:"退货区域名称" json:"regionName,omitempty"`
// 订单产品列表
... ...
... ... @@ -5,7 +5,6 @@ import (
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
)
type UpdateDividendsReturnedOrderCommand struct {
... ... @@ -24,7 +23,7 @@ type UpdateDividendsReturnedOrderCommand struct {
// 退货区域
RegionName string `cname:"退货区域" json:"regionName,omitempty"`
// 订单时间
OrderTime time.Time `cname:"订单日期" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单日期" json:"orderTime" valid:"Required"`
// 订单产品列表
OrderGoods []*OrderGoods `cname:"订单产品列表" json:"orderGoods,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -99,15 +99,25 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsReturnedOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 校验分红退货单编号是否唯一
//numberAvailable, _ := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
// "companyId": createDividendsOrderCommand.CompanyId,
// "orgId": createDividendsOrderCommand.OrgId,
// "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
//})
//if !numberAvailable {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
//}
numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err != nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, err.Error())
}
if !numberAvailable {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
}
// 获取分红退货单产品
var orderGoods []*domain.OrderGood
... ... @@ -152,6 +162,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
UpdatedAt: time.Time{},
Operator: operator,
OperateTime: time.Now(),
OrderTime: orderTime,
}
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
... ... @@ -563,6 +574,13 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
}
dividendsReturnedDate := utils.TransformTimestampToTime(dividendsReturnedDateInt)
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 获取分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId})
if err != nil {
... ... @@ -607,6 +625,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate
dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderAmount
dividendsReturnedOrder.Goods = orderGoods
dividendsReturnedOrder.OrderTime = orderTime
// 保存分红退货单更新
if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil {
... ...
... ... @@ -7,4 +7,8 @@ type AccountDetail struct {
DividendsType int32 `json:"dividendsType"`
// 分红金额
DividendsAmount float64 `json:"dividendsAmount"`
// 产品ID
OrderGoodId int64 `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
}
... ...
... ... @@ -42,6 +42,8 @@ type CooperationProject struct {
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 共创申请人计数
ApplicantCount int32 `json:"applicantCount"`
}
type CooperationProjectRepository interface {
... ...
... ... @@ -26,6 +26,8 @@ type CreditAccount struct {
ParticipateType string `json:"participateType"`
// 结算明细
AccountDetail []*AccountDetail `json:"accountDetail"`
// 产品金额统计
GoodAmountCount float64 `json:"goodAmountCount"`
// 支付凭证附件
PaymentDocumentAttachments []*Attachment `json:"paymentDocumentAttachments"`
// 数据所属组织机构
... ...
... ... @@ -61,6 +61,10 @@ type DividendsEstimate struct {
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 订单产品ID
OrderGoodId int64 `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
}
type DividendsEstimateRepository interface {
... ...
... ... @@ -49,6 +49,24 @@ func (dao *CooperationModeDao) CheckModeNumberAvailable(queryOptions map[string]
return !ok, err
}
// CheckModeIsDeleteAvailable 校验模式是否有项目数据关联
func (dao *CooperationModeDao) CheckModeIsDeleteAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
query := tx.Model(&cooperationProjectModels)
if cooperationModeNumber, ok := queryOptions["cooperationModeNumber"]; ok && cooperationModeNumber != "" {
query = query.Where("cooperation_mode_number = ?", cooperationModeNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
// UpdateCooperationModeSlice 更新多个共创模式
func (dao *CooperationModeDao) UpdateCooperationModeSlice(modeIds []int64, status int32) ([]*domain.CooperationMode, error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -35,7 +35,25 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st
}
}
// CalculateDividendsOrderAmount 计算分红订单金额
// CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
if dividendsOrderNumber, ok := queryOptions["dividendsReturnedOrderNumber"]; ok && dividendsOrderNumber != "" {
query = query.Where("dividends_returned_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_returned_order.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
// CalculateDividendsReturnedOrderAmount 计算分红订单金额
func (dao *DividendsReturnedOrderDao) CalculateDividendsReturnedOrderAmount(queryOptions map[string]interface{}) (float64, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModel = new(models.DividendsReturnedOrder)
... ...
... ... @@ -45,4 +45,6 @@ type CooperationProject struct {
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 申请人统计
ApplicantCount int32 `comment:"申请人统计"`
}
... ...
... ... @@ -29,6 +29,8 @@ type CreditAccount struct {
ParticipateType string `comment:"参与类型,承接人,推荐人,业务员"`
// 结算明细
AccountDetail []*domain.AccountDetail `comment:"结算明细"`
// 产品金额统计
GoodAmountCount float64 `comment:"产品金额统计"`
// 支付凭证附件
PaymentDocumentAttachments []*domain.Attachment `comment:"支付凭证附件"`
// 数据所属组织机构
... ...
... ... @@ -41,5 +41,6 @@ func TransformToCooperationProjectDomainModelFromPgModels(
UpdatedAt: cooperationProjectModel.UpdatedAt,
DeletedAt: cooperationProjectModel.DeletedAt,
CreatedAt: cooperationProjectModel.CreatedAt,
ApplicantCount: cooperationProjectModel.ApplicantCount,
}, nil
}
... ...
... ... @@ -18,6 +18,7 @@ func TransformToCreditAccountDomainModelFromPgModels(creditAccountModel *models.
Participator: creditAccountModel.Participator,
ParticipateType: creditAccountModel.ParticipateType,
AccountDetail: creditAccountModel.AccountDetail,
GoodAmountCount: creditAccountModel.GoodAmountCount,
PaymentDocumentAttachments: creditAccountModel.PaymentDocumentAttachments,
Org: creditAccountModel.Org,
Company: creditAccountModel.Company,
... ...
... ... @@ -172,6 +172,9 @@ func (repository *CooperationModeRepository) Find(queryOptions map[string]interf
var cooperationModeModels []*models.CooperationMode
cooperationModes := make([]*domain.CooperationMode, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationModeModels), queryOptions)
if cooperationModeIds, ok := queryOptions["cooperationModeIds"]; ok && len(cooperationModeIds.([]int64)) > 0 {
query.Where("cooperation_mode_id in (?)", pg.In(cooperationModeIds))
}
if cooperationModeName, ok := queryOptions["cooperationModeName"]; ok && cooperationModeName != "" {
query.Where("cooperation_mode_name like ?", fmt.Sprintf("%%%s%%", cooperationModeName))
}
... ...
... ... @@ -47,6 +47,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
"updated_at",
"deleted_at",
"created_at",
"applicant_count",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -82,6 +83,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.UpdatedAt,
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
),
fmt.Sprintf("INSERT INTO cooperation_projects (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -103,6 +105,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.UpdatedAt,
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
); err != nil {
return cooperationProject, err
}
... ... @@ -128,6 +131,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.UpdatedAt,
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
),
fmt.Sprintf("UPDATE cooperation_projects SET %s WHERE cooperation_project_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -149,6 +153,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.UpdatedAt,
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
cooperationProject.Identify(),
); err != nil {
return cooperationProject, err
... ... @@ -181,6 +186,7 @@ func (repository *CooperationProjectRepository) UpdateMany(cooperationProjects [
UpdatedAt: time.Now(),
DeletedAt: cooperationProject.DeletedAt,
CreatedAt: cooperationProject.CreatedAt,
ApplicantCount: cooperationProject.ApplicantCount,
})
}
if _, err := tx.Model(&cooperationProjectModels).WherePK().Update(); err != nil {
... ...
... ... @@ -38,6 +38,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
"participator",
"participate_type",
"account_detail",
"good_amount_count",
"payment_document_attachments",
"org",
"company",
... ... @@ -74,6 +75,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.Participator,
&creditAccount.ParticipateType,
&creditAccount.AccountDetail,
&creditAccount.GoodAmountCount,
&creditAccount.PaymentDocumentAttachments,
&creditAccount.Org,
&creditAccount.Company,
... ... @@ -96,6 +98,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Participator,
creditAccount.ParticipateType,
creditAccount.AccountDetail,
creditAccount.GoodAmountCount,
creditAccount.PaymentDocumentAttachments,
creditAccount.Org,
creditAccount.Company,
... ... @@ -122,6 +125,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.Participator,
&creditAccount.ParticipateType,
&creditAccount.AccountDetail,
&creditAccount.GoodAmountCount,
&creditAccount.PaymentDocumentAttachments,
&creditAccount.Org,
&creditAccount.Company,
... ... @@ -144,6 +148,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Participator,
creditAccount.ParticipateType,
creditAccount.AccountDetail,
creditAccount.GoodAmountCount,
creditAccount.PaymentDocumentAttachments,
creditAccount.Org,
creditAccount.Company,
... ...
... ... @@ -367,7 +367,10 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
dividendsOrderModel := new(models.DividendsOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
//query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -61,6 +61,8 @@ func (controller *DividendsOrderController) GetDividendsOrder() {
getDividendsOrderQuery.UserBaseId = header.UserBaseId
dividendsOrderId, _ := controller.GetInt64(":dividendsOrderId")
getDividendsOrderQuery.DividendsOrderId = dividendsOrderId
dividendsOrderNumber := controller.GetString("dividendsOrderNumber")
getDividendsOrderQuery.DividendsOrderNumber = dividendsOrderNumber
data, err := dividendsOrderService.GetDividendsOrder(getDividendsOrderQuery)
controller.Response(data, err)
}
... ...