作者 陈志颖

feat:共创合约、分红退货单、分红订单删除仓储修改

... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"strconv"
)
// CooperationContractService 共创合约服务
... ... @@ -43,8 +44,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
//CooperationProjectNumber: createCooperationContractCommand.CooperationProjectNumber,
//DepartmentNumber: createCooperationContractCommand.DepartmentNumber,
CooperationContractUndertakerType: createCooperationContractCommand.CooperationContractUndertakerType,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerType,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
//CooperationModeNumber: createCooperationContractCommand.CooperationModeNumber,
//SponsorUid: createCooperationContractCommand.SponsorUid,
//DividendsIncentivesRules: createCooperationContractCommand.DividendsIncentivesRules,
... ... @@ -130,7 +131,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
... ... @@ -145,7 +146,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getCooperationContractQuery.CooperationContractId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationContractQuery.CooperationContractId, 10)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -167,7 +168,7 @@ func (cooperationContractService *CooperationContractService) ListCooperationCon
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
... ... @@ -205,7 +206,7 @@ func (cooperationContractService *CooperationContractService) RemoveCooperationC
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
... ... @@ -220,7 +221,7 @@ func (cooperationContractService *CooperationContractService) RemoveCooperationC
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeCooperationContractCommand.CooperationContractId)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(removeCooperationContractCommand.CooperationContractId, 10)))
}
if cooperationContract, err := cooperationContractRepository.Remove(cooperationContract); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -245,7 +246,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -266,7 +267,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -287,7 +288,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
_ = transactionContext.RollbackTransaction()
}()
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
... ...
... ... @@ -2,7 +2,6 @@ package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"reflect"
"strings"
... ... @@ -20,42 +19,12 @@ type ReleaseCooperationProjectCommand struct {
UserBaseId int64 `cname:"用户基本id" json:"userBaseId,string" valid:"Required"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 组织名称
OrgName string `cname:"组织名称" json:"orgName" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID,通过集成REST上下文获取" json:"companyId,string" valid:"Required"`
// 公司logo
CompanyLogo string `cname:"公司logo" json:"companyLogo" valid:"Required"`
// 公司名称
CompanyName string `cname:"公司名称" json:"companyName" valid:"Required"`
// 用户关联的组织机构
Orgs []*domain.Org `cname:"用户关联的组织机构" json:"orgs" valid:"Required"`
// 共创项目发起人id
CooperationProjectSponsorId string `cname:"共创项目发起人id" json:"cooperationProjectSponsorId" valid:"Required"`
// 部门ID,通过REST集成上下文获取
DepartmentId int64 `cname:"部门ID,通过REST集成上下文获取" json:"departmentId,string" valid:"Required"`
// 部门名称
DepartmentName string `cname:"部门名称" json:"departmentName" valid:"Required"`
// 部门编码
DepartmentNumber string `cname:"部门编码" json:"departmentNumber" valid:"Required"`
// 是否组织机构标识,1为是,2为否,默认为否
IsOrganization bool `cname:"是否组织机构标识,1为是,2为否,默认为否" json:"isOrganization" valid:"Required"`
// 角色ID
RoleId int64 `cname:"角色ID" json:"roleId,string" valid:"Required"`
// 角色名称
RoleName string `cname:"角色名称" json:"roleName" valid:"Required"`
// 用户头像
UserAvatar string `cname:"用户头像" json:"userAvatar" valid:"Required"`
// 用户邮箱
UserEmail string `cname:"用户邮箱" json:"userEmail" valid:"Required"`
// 共创人员姓名
UserName string `cname:"共创人员姓名" json:"userName" valid:"Required"`
// 用户手机号
UserPhone string `cname:"用户手机号" json:"userPhone" valid:"Required"`
// 用户账号,区别于手机号,冗余字段
UserAccount string `cname:"用户账号,区别于手机号,冗余字段" json:"userAccount" valid:"Required"`
// 用户类型
UserType int32 `cname:"用户类型" json:"userType" valid:"Required"`
// 状态
Status int32 `cname:"状态" json:"status" valid:"Required"`
DepartmentId int64 `cname:"部门ID" json:"departmentId,string" valid:"Required"`
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"共创项目承接对象,1员工,2共创用户,3公开,可以多选" json:"cooperationProjectUndertakerType" valid:"Required"`
// 共创项目描述
... ...
... ... @@ -19,7 +19,7 @@ type CooperationContract struct {
// 共创合约业务员
CooperationContractSalesman *User `json:"cooperationContractSalesman"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int32 `json:"cooperationContractUndertakerType"`
CooperationContractUndertakerTypes []int32 `json:"cooperationContractUndertakerType"`
// 共创合约发起人
CooperationContractSponsor *User `json:"cooperationContractSponsor"`
// 共创模式或者合伙模式
... ... @@ -87,7 +87,7 @@ func (cooperationContract *CooperationContract) Update(data map[string]interface
cooperationContract.CooperationContractReferrer.Status = status.(int32)
}
if cooperationContractUndertakerType, ok := data["cooperationContractUndertakerType"]; ok {
cooperationContract.CooperationContractUndertakerType = cooperationContractUndertakerType.([]int32)
cooperationContract.CooperationContractUndertakerTypes = cooperationContractUndertakerType.([]int32)
}
if status, ok := data["status"]; ok {
cooperationContract.Status = status.(int32)
... ...
package service
type ApplyForCooperationService interface {
ApplyFor()
ApplyForCooperation()
}
... ...
package service
type ReleaseCooperationProjectService interface {
Release()
}
... ...
... ... @@ -20,7 +20,7 @@ type CooperationContract struct {
// 共创合约业务员
CooperationContractSalesman *domain.User `comment:"共创合约业务员"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int32 `comment:"共创合约承接对象,1员工,2共创用户,3公开" pg:",array"`
CooperationContractUndertakerTypes []int32 `comment:"共创合约承接对象,1员工,2共创用户,3公开" pg:",array"`
// 共创合约发起人
CooperationContractSponsor *domain.User `comment:"共创合约发起人"`
// 共创模式编号
... ...
... ... @@ -85,14 +85,14 @@ func TransformToCooperationContractDomainModelFromPgModels(
})
}
return &domain.CooperationContract{
CooperationContractId: cooperationContractModel.CooperationContractId,
CooperationContractDescription: cooperationContractModel.CooperationContractDescription,
CooperationContractName: cooperationContractModel.CooperationContractName,
CooperationContractNumber: cooperationContractModel.CooperationContractNumber,
CooperationContractReferrer: cooperationContractModel.CooperationContractReferrer,
CooperationContractSalesman: cooperationContractModel.CooperationContractSalesman,
CooperationContractUndertakerType: cooperationContractModel.CooperationContractUndertakerType,
CooperationContractSponsor: cooperationContractModel.CooperationContractSponsor,
CooperationContractId: cooperationContractModel.CooperationContractId,
CooperationContractDescription: cooperationContractModel.CooperationContractDescription,
CooperationContractName: cooperationContractModel.CooperationContractName,
CooperationContractNumber: cooperationContractModel.CooperationContractNumber,
CooperationContractReferrer: cooperationContractModel.CooperationContractReferrer,
CooperationContractSalesman: cooperationContractModel.CooperationContractSalesman,
CooperationContractUndertakerTypes: cooperationContractModel.CooperationContractUndertakerTypes,
CooperationContractSponsor: cooperationContractModel.CooperationContractSponsor,
CooperationMode: &domain.CooperationMode{
CooperationModeId: cooperationMode.CooperationModeId,
CooperationModeNumber: cooperationMode.CooperationModeNumber,
... ...
... ... @@ -32,7 +32,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
"cooperation_contract_number",
"cooperation_contract_referrer",
"cooperation_contract_salesman",
"cooperation_contract_undertaker_type",
"cooperation_contract_undertaker_types",
"cooperation_contract_sponsor",
"cooperation_mode_number",
"status",
... ... @@ -65,7 +65,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractNumber,
&cooperationContract.CooperationContractReferrer,
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerType),
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode.CooperationModeNumber,
&cooperationContract.Status,
... ... @@ -84,7 +84,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractNumber,
cooperationContract.CooperationContractReferrer,
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerType),
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode.CooperationModeNumber,
cooperationContract.Status,
... ... @@ -189,7 +189,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
&cooperationContract.CooperationContractNumber,
&cooperationContract.CooperationContractReferrer,
&cooperationContract.CooperationContractSalesman,
pg.Array(&cooperationContract.CooperationContractUndertakerType),
pg.Array(&cooperationContract.CooperationContractUndertakerTypes),
&cooperationContract.CooperationContractSponsor,
&cooperationContract.CooperationMode.CooperationModeNumber,
&cooperationContract.Status,
... ... @@ -208,7 +208,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
cooperationContract.CooperationContractNumber,
cooperationContract.CooperationContractReferrer,
cooperationContract.CooperationContractSalesman,
pg.Array(cooperationContract.CooperationContractUndertakerType),
pg.Array(cooperationContract.CooperationContractUndertakerTypes),
cooperationContract.CooperationContractSponsor,
cooperationContract.CooperationMode.CooperationModeNumber,
cooperationContract.Status,
... ... @@ -224,6 +224,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return cooperationContract, err
}
// TODO 更新相关人
// 查找相关人列表
var cooperationContractRelevantFetched []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantFetched)
... ... @@ -233,8 +234,10 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 待更新相关人
var cooperationContractRelevantPeopleToUpdate []*domain.Relevant
// 待添加相关人
var cooperationContractRelevantPeopleToAdd []*domain.Relevant
for _, relevant := range cooperationContract.RelevantPeople {
if relevant.RelevantId != 0 {
cooperationContractRelevantPeopleToUpdate = append(cooperationContractRelevantPeopleToUpdate, relevant)
... ... @@ -285,30 +288,26 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
})
}
// 待删除的相关人
// 待新增的相关人
//TODO 更新承接人
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
var cooperationContractUndertakersFetched []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakersFetched)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//TODO 更新分红激励规则
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
var dividendsIncentivesRulesFetched []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRulesFetched)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
//TODO 更新金额激励规则
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
var moneyIncentivesRulesFetched []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRulesFetched)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContract.CooperationContractNumber).Select(); err != nil {
return nil, err
}
... ... @@ -322,7 +321,46 @@ func (repository *CooperationContractRepository) Remove(cooperationContract *dom
if _, err := tx.Model(cooperationContractModel).WherePK().Delete(); err != nil {
return cooperationContract, err
} else {
//TODO 删除关联数据
// 获取分红激励规则列表
var dividendsIncentivesRuleModels []*models.DividendsIncentivesRule
dividendsIncentivesRuleQuery := tx.Model(&dividendsIncentivesRuleModels)
if err := dividendsIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&dividendsIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
// 获取金额激励规则列表
var moneyIncentivesRuleModels []*models.MoneyIncentivesRule
moneyIncentivesRuleQuery := tx.Model(&moneyIncentivesRuleModels)
if err := moneyIncentivesRuleQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&moneyIncentivesRuleModels).WherePK().Delete(); err != nil {
return nil, err
}
}
// 获取承接人列表
var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
cooperationContractUndertakerQuery := tx.Model(&cooperationContractUndertakerModels)
if err := cooperationContractUndertakerQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractUndertakerModels).WherePK().Delete(); err != nil {
return nil, err
}
}
// 获取相关人列表
var cooperationContractRelevantModels []*models.CooperationContractRelevant
cooperationContractRelevantQuery := tx.Model(&cooperationContractRelevantModels)
if err := cooperationContractRelevantQuery.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).Select(); err != nil {
return nil, err
} else {
if _, err := tx.Model(&cooperationContractRelevantModels).WherePK().Delete(); err != nil {
return nil, err
}
}
}
return cooperationContract, nil
}
... ...
... ... @@ -173,6 +173,17 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide
dividendsOrderModel.DividendsOrderId = dividendsOrder.Identify().(int64)
if _, err := tx.Model(dividendsOrderModel).WherePK().Delete(); err != nil {
return dividendsOrder, err
} else {
// 获取订单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_order_number = ?", dividendsOrderModel.DividendsOrderNumber).Select(); err != nil {
return nil, err
}
// 批量删除订单产品
if _, err := tx.Model(&orderGoodModels).WherePK().Delete(); err != nil {
return nil, err
}
}
return dividendsOrder, nil
}
... ...
... ... @@ -178,6 +178,17 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde
dividendsReturnedOrderModel.DividendsReturnedOrderId = dividendsReturnedOrder.Identify().(int64)
if _, err := tx.Model(dividendsReturnedOrderModel).WherePK().Delete(); err != nil {
return dividendsReturnedOrder, err
} else {
// 获取退货单产品
var orderGoodModels []*models.OrderGood
orderGoodModelQuery := tx.Model(&orderGoodModels)
if err := orderGoodModelQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsOrderNumber).Select(); err != nil {
return nil, err
}
// 批量删除退货单产品
if _, err := tx.Model(&orderGoodModels).WherePK().Delete(); err != nil {
return nil, err
}
}
return dividendsReturnedOrder, nil
}
... ...