作者 陈志颖

feat:新增领域值对象

正在显示 45 个修改的文件 包含 959 行增加152 行删除
... ... @@ -10,7 +10,7 @@ import (
type RemoveContractUndertakerFeedbackCommand struct {
// 合约承接方反馈记录ID
FeedbackId int64 `cname:"合约承接方反馈记录ID" json:"feedbackId,string" valid:"Required"`
FeedbackId string `cname:"合约承接方反馈记录ID" json:"feedbackId" valid:"Required"`
// 承接人uid
UnderTakerUid string `cname:"承接人uid" json:"underTakerUid,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -10,7 +10,7 @@ import (
type GetContractUndertakerFeedbackQuery struct {
// 合约承接方反馈记录ID
FeedbackId int64 `cname:"合约承接方反馈记录ID" json:"feedbackId,string" valid:"Required"`
FeedbackId string `cname:"合约承接方反馈记录ID" json:"feedbackId" valid:"Required"`
// 承接人uid
UnderTakerUid string `cname:"承接人uid" json:"underTakerUid,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -10,11 +10,11 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 共创合约服务
// CooperationContractService 共创合约服务
type CooperationContractService struct {
}
// 创建共创合约服务
// CreateCooperationContract 创建共创合约服务
func (cooperationContractService *CooperationContractService) CreateCooperationContract(createCooperationContractCommand *command.CreateCooperationContractCommand) (interface{}, error) {
if err := createCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -30,11 +30,11 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
transactionContext.RollbackTransaction()
}()
userServiceGateway, err := factory.CreateUserServiceGateway(nil)
if err != nil {
fmt.Println(err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//userServiceGateway, err := factory.CreateUserServiceGateway(nil)
//if err != nil {
// fmt.Println(err.Error())
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//userServiceGateway.GetUser(createCooperationContractCommand.SponsorUid)
... ... @@ -73,7 +73,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
}
// 返回共创合约服务
// GetCooperationContract 返回共创合约服务
func (cooperationContractService *CooperationContractService) GetCooperationContract(getCooperationContractQuery *query.GetCooperationContractQuery) (interface{}, error) {
if err := getCooperationContractQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -110,7 +110,7 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
}
}
// 返回共创合约服务列表
// ListCooperationContract 返回共创合约服务列表
func (cooperationContractService *CooperationContractService) ListCooperationContract(listCooperationContractQuery *query.ListCooperationContractQuery) (interface{}, error) {
if err := listCooperationContractQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -146,7 +146,7 @@ func (cooperationContractService *CooperationContractService) ListCooperationCon
}
}
// 移除共创合约服务
// RemoveCooperationContract 移除共创合约服务
func (cooperationContractService *CooperationContractService) RemoveCooperationContract(removeCooperationContractCommand *command.RemoveCooperationContractCommand) (interface{}, error) {
if err := removeCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -186,7 +186,7 @@ func (cooperationContractService *CooperationContractService) RemoveCooperationC
}
}
// 查询共创合约
// SearchCooperationContract 查询共创合约
func (cooperationContractService *CooperationContractService) SearchCooperationContract(searchCooperationContractQuery *query.SearchCooperationContractQuery) (interface{}, error) {
if err := searchCooperationContractQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -207,7 +207,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
return nil, nil
}
// 根据承接人返回共创项目合约
// SearchCooperationContractByUndertaker 根据承接人返回共创项目合约
func (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) {
if err := searchCooperationContractByUndertakerQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -228,7 +228,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
return nil, nil
}
// 更新共创合约服务
// UpdateCooperationContract 更新共创合约服务
func (cooperationContractService *CooperationContractService) UpdateCooperationContract(updateCooperationContractCommand *command.UpdateCooperationContractCommand) (interface{}, error) {
if err := updateCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ...
package dto
// CooperationModeStatisticsDto 共创模式统计
type CooperationModeStatisticsDto struct {
// 共创人数统计
CooperationPeople float64 `json:"cooperationPeople"`
// 分红预算统计
DividendsEstimate float64 `json:"dividendsEstimate"`
// 订单金额统计
OrderAmount float64 `json:"orderAmount"`
}
... ...
... ... @@ -10,11 +10,11 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
)
// 共创项目服务
// CooperationProjectService 共创项目服务
type CooperationProjectService struct {
}
// 判断当前勾选的承接对象是否存在用户
// CheckUndertaker 判断当前勾选的承接对象是否存在用户
func (cooperationProjectService *CooperationProjectService) CheckUndertaker(checkUndertakerQuery *query.CheckUndertakerQuery) (interface{}, error) {
if err := checkUndertakerQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -35,7 +35,7 @@ func (cooperationProjectService *CooperationProjectService) CheckUndertaker(chec
return nil, nil
}
// 创建共创项目服务
// CreateCooperationProject 创建共创项目服务
func (cooperationProjectService *CooperationProjectService) CreateCooperationProject(createCooperationProjectCommand *command.CreateCooperationProjectCommand) (interface{}, error) {
if err := createCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -53,12 +53,12 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
newCooperationProject := &domain.CooperationProject{
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
CooperationProjectUndertakerType: createCooperationProjectCommand.CooperationProjectUndertakerType,
SponsorUid: createCooperationProjectCommand.SponsorUid,
PublisherUid: createCooperationProjectCommand.PublisherUid,
//SponsorUid: createCooperationProjectCommand.SponsorUid,
//PublisherUid: createCooperationProjectCommand.PublisherUid,
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CompanyId: createCooperationProjectCommand.CompanyId,
OrgId: createCooperationProjectCommand.OrgId,
UserId: createCooperationProjectCommand.UserId,
//CompanyId: createCooperationProjectCommand.CompanyId,
//OrgId: createCooperationProjectCommand.OrgId,
//UserId: createCooperationProjectCommand.UserId,
}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
... ... @@ -78,7 +78,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
}
}
// 返回共创项目服务
// GetCooperationProject 返回共创项目服务
func (cooperationProjectService *CooperationProjectService) GetCooperationProject(getCooperationProjectQuery *query.GetCooperationProjectQuery) (interface{}, error) {
if err := getCooperationProjectQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -115,7 +115,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
}
}
// 返回共创项目服务列表
// ListCooperationProject 返回共创项目服务列表
func (cooperationProjectService *CooperationProjectService) ListCooperationProject(listCooperationProjectQuery *query.ListCooperationProjectQuery) (interface{}, error) {
if err := listCooperationProjectQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -151,7 +151,7 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
}
}
// 发布共创项目
// ReleaseCooperationProject 发布共创项目
func (cooperationProjectService *CooperationProjectService) ReleaseCooperationProject(releaseCooperationProjectCommand *command.ReleaseCooperationProjectCommand) (interface{}, error) {
if err := releaseCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -172,7 +172,7 @@ func (cooperationProjectService *CooperationProjectService) ReleaseCooperationPr
return nil, nil
}
// 移除共创项目服务
// RemoveCooperationProject 移除共创项目服务
func (cooperationProjectService *CooperationProjectService) RemoveCooperationProject(removeCooperationProjectCommand *command.RemoveCooperationProjectCommand) (interface{}, error) {
if err := removeCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -212,7 +212,7 @@ func (cooperationProjectService *CooperationProjectService) RemoveCooperationPro
}
}
// 查询共创项目
// SearchCooperationProject 查询共创项目
func (cooperationProjectService *CooperationProjectService) SearchCooperationProject(searchCooperationProjectQuery *query.SearchCooperationProjectQuery) (interface{}, error) {
if err := searchCooperationProjectQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -233,7 +233,7 @@ func (cooperationProjectService *CooperationProjectService) SearchCooperationPro
return nil, nil
}
// 更新共创项目服务
// UpdateCooperationProject 更新共创项目服务
func (cooperationProjectService *CooperationProjectService) UpdateCooperationProject(updateCooperationProjectCommand *command.UpdateCooperationProjectCommand) (interface{}, error) {
if err := updateCooperationProjectCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ...
... ... @@ -85,3 +85,19 @@ func CreateCreditAccountRepository(options map[string]interface{}) (domain.Credi
}
return repository.NewCreditAccountRepository(transactionContext)
}
func CreateDividendsOrderRepository(options map[string]interface{}) (domain.DividendsOrderRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDividendsOrderRepository(transactionContext)
}
func CreateDividendsReturnedOrderRepository(options map[string]interface{}) (domain.DividendsReturnedOrderRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewDividendsReturnedOrderRepository(transactionContext)
}
... ...
package domain
// AnnualDividendsExpenseDto 企业年度分红总支出
type AnnualDividendsExpenseDto struct {
// 总支出
TotalExpense float64 `json:"totalExpense"`
// 企业分红支出明细
DividendsExpenseDetail *DividendsExpenseDetail `json:"dividendsExpenseDetail"`
}
... ...
package domain
// 附件对象
// Attachment 附件对象
type Attachment struct {
// 附件文件类型,jpg,pdf
FileType string `json:"fileType"`
... ...
package domain
// 公司值对象
// Company 公司值对象
type Company struct {
// 公司ID,通过集成REST上下文获取
CompanyId int64 `json:"companyId,string"`
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 承接人反馈信息
// ContractUndertakerFeedback 承接人反馈信息
type ContractUndertakerFeedback struct {
// 合约承接方反馈记录ID
FeedbackId int64 `json:"feedbackId,string"`
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 共创申请实体
// CooperationApplication 共创申请实体
type CooperationApplication struct {
// 共创申请ID
CooperationApplicationId int64 `json:"cooperationApplicationId,string"`
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 共创项目合约实体
// CooperationContract 共创项目合约实体
type CooperationContract struct {
// 共创合约ID
CooperationContractId int64 `json:"cooperationContractId,string"`
... ...
package domain
// CooperationContractByUndertaker 根据承接人返回共创项目合约
type CooperationContractByUndertaker struct {
// 共创合约ID
CooperationContractId int64 `json:"cooperationContractId,string"`
// 共创合约描述
CooperationContractDescription string `json:"cooperationContractDescription"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创合约名称
CooperationContractName string `json:"cooperationContractName"`
// 共创模式
CooperationMode *CooperationMode `json:"cooperationMode"`
// 共创合约发起人
CooperationContractSponsor *User `json:"cooperationContractSponsor"`
// 状态
Status int32 `json:"status"`
// 共创合约承接人
ContractUndertaker *User `json:"contractUndertaker"`
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 共创合约变更日志
// CooperationContractChangeLog 共创合约变更日志
type CooperationContractChangeLog struct {
// 共创合约变更日志
CooperationContractChangeLogId int64 `json:"cooperationContractChangeLogId,string"`
... ...
package domain
// CooperationGoodsStatisticsDto 共创产品统计
type CooperationGoodsStatisticsDto struct {
// 共创产品总金额统计
GoodAmount float64 `json:"goodAmount"`
// 共创产品名称
GoodName string `json:"goodName"`
// 共创产品在TOP5中的占比统计
GoodRatio float64 `json:"goodRatio"`
// 排名
Rank int32 `json:"rank"`
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 共创模式实体
// CooperationMode 共创模式实体
type CooperationMode struct {
// 共创模式ID
CooperationModeId int64 `json:"cooperationModeId,string"`
... ... @@ -54,30 +54,6 @@ func (cooperationMode *CooperationMode) Update(data map[string]interface{}) erro
if status, ok := data["status"]; ok {
cooperationMode.Status = status.(int32)
}
if orgId, ok := data["orgId"]; ok {
cooperationMode.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationMode.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationMode.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationMode.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationMode.Org.Company.CompanyName = companyName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationMode.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationMode.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationMode.Company.CompanyName = companyName.(string)
}
if remarks, ok := data["remarks"]; ok {
cooperationMode.Remarks = remarks.(string)
}
... ... @@ -87,83 +63,14 @@ func (cooperationMode *CooperationMode) Update(data map[string]interface{}) erro
if userBaseId, ok := data["userBaseId"]; ok {
cooperationMode.Operator.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
cooperationMode.Operator.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
cooperationMode.Operator.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
cooperationMode.Operator.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationMode.Operator.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationMode.Operator.Org.Company.CompanyName = companyName.(string)
}
if orgs, ok := data["orgs"]; ok {
cooperationMode.Operator.Orgs = orgs.([]*Org)
}
if departmentId, ok := data["departmentId"]; ok {
cooperationMode.Operator.Department.DepartmentId = departmentId.(int64)
}
if departmentName, ok := data["departmentName"]; ok {
cooperationMode.Operator.Department.DepartmentName = departmentName.(string)
}
if departmentNumber, ok := data["departmentNumber"]; ok {
cooperationMode.Operator.Department.DepartmentNumber = departmentNumber.(string)
}
if isOrganization, ok := data["isOrganization"]; ok {
cooperationMode.Operator.Department.IsOrganization = isOrganization.(bool)
}
if roleId, ok := data["roleId"]; ok {
cooperationMode.Operator.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
cooperationMode.Operator.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
cooperationMode.Operator.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
cooperationMode.Operator.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
cooperationMode.Operator.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
cooperationMode.Operator.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
cooperationMode.Operator.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
cooperationMode.Operator.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
cooperationMode.Operator.Status = status.(int32)
}
if companyId, ok := data["companyId"]; ok {
cooperationMode.Operator.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
cooperationMode.Operator.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
cooperationMode.Operator.Company.CompanyName = companyName.(string)
}
if operateTime, ok := data["operateTime"]; ok {
cooperationMode.OperateTime = operateTime.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
cooperationMode.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
cooperationMode.DeletedAt = deletedAt.(time.Time)
}
if createdAt, ok := data["createdAt"]; ok {
cooperationMode.CreatedAt = createdAt.(time.Time)
}
return nil
}
... ...
package domain
import "time"
// CooperationPersonStatisticsDto 共创人员信息统计
type CooperationPersonStatisticsDto struct {
// 共创时间
CooperationTime time.Time `json:"cooperationTime"`
// 合伙类型,即共创模式
CooperationTypes []*CooperationMode `json:"cooperationTypes"`
// 分红明细
DividendsDetails *DividendsDetails `json:"dividendsDetails"`
// 订单明细
OrderDetails *OrderDetails `json:"orderDetails"`
// 共创人员姓名
UserName string `json:"userName"`
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 共创项目实体
// CooperationProject 共创项目实体
type CooperationProject struct {
// 共创项目ID
CooperationProjectId int64 `json:"cooperationProjectId,string"`
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 账期结算单实体
// CreditAccount 账期结算单实体
type CreditAccount struct {
// 账期结算单ID
CreditAccountId int64 `json:"creditAccountId,string"`
... ...
package domain
// 部门值对象
// Department 部门值对象
type Department struct {
// 部门ID,通过REST集成上下文获取
DepartmentId int64 `json:"departmentId,string"`
... ...
package domain
// 分红明细
// DividendsDetails 分红明细
type DividendsDetails struct {
// 分红支出
DividendsExpense float64 `json:"dividendsExpense"`
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 分红预算实体
// DividendsEstimate 分红预算实体
type DividendsEstimate struct {
// 承接人分红预算记录ID
DividendsEstimateId int64 `json:"dividendsEstimateId,string"`
... ...
package domain
// 具体分红类型支出
// DividendsExpenseByType 具体分红类型支出
type DividendsExpenseByType struct {
// 具体分红类型支出
DividendsExpenseByType string `json:"dividendsExpenseByType"`
... ...
package domain
// DividendsExpenseDetail 企业分红支出明细
type DividendsExpenseDetail struct {
// 待结算
ToBeAccounted float64 `json:"toBeAccounted"`
// 已结算
Accounted float64 `json:"accounted"`
// 已支付
Paid float64 `json:"paid"`
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 金额激励规则实体
// DividendsIncentivesRule 金额激励规则实体
type DividendsIncentivesRule struct {
// 分红规则ID
DividendsIncentivesRuleId int64 `json:"dividendsIncentivesRuleId,string"`
... ...
package domain
import "time"
// 分红订单实体
type DividendsOrder struct {
// 分红订单ID
DividendsOrderId int64 `json:"dividendsOrderId,string"`
// 分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"`
// 分红订单原单号
DividendsOriginalOrderNum string `json:"dividendsOriginalOrderNum"`
// 分红订单金额
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
// 订单业务员
OrderSalesman *User `json:"orderSalesman"`
// 订单产生时间
OrderTime time.Time `json:"orderTime"`
// 分红订单分红时间
DividendTime time.Time `json:"dividendTime"`
// 分红订单分红状态,1待分红,2已分红,3部分分红
DividendStatus int32 `json:"dividendStatus"`
// 区域
Region *RegionInfo `json:"region"`
// 客户姓名
CustomerName string `json:"customerName"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
// 操作人
Operator *User `json:"operator"`
}
type DividendsOrderRepository interface {
Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error)
FindOne(queryOptions map[string]interface{}) (*DividendsOrder, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsOrder, error)
}
func (dividendsOrder *DividendsOrder) Identify() interface{} {
if dividendsOrder.DividendsOrderId == 0 {
return nil
}
return dividendsOrder.DividendsOrderId
}
func (dividendsOrder *DividendsOrder) Update(data map[string]interface{}) error {
if dividendsOrderNumber, ok := data["dividendsOrderNumber"]; ok {
dividendsOrder.DividendsOrderNumber = dividendsOrderNumber.(int64)
}
if dividendsOriginalOrderNum, ok := data["dividendsOriginalOrderNum"]; ok {
dividendsOrder.DividendsOriginalOrderNum = dividendsOriginalOrderNum.(string)
}
if dividendsOrderAmount, ok := data["dividendsOrderAmount"]; ok {
dividendsOrder.DividendsOrderAmount = dividendsOrderAmount.(float64)
}
if userId, ok := data["userId"]; ok {
dividendsOrder.OrderSalesman.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
dividendsOrder.OrderSalesman.UserBaseId = userBaseId.(int64)
}
if orgId, ok := data["orgId"]; ok {
dividendsOrder.OrderSalesman.Org.OrgId = orgId.(int64)
}
if orgName, ok := data["orgName"]; ok {
dividendsOrder.OrderSalesman.Org.OrgName = orgName.(string)
}
if companyId, ok := data["companyId"]; ok {
dividendsOrder.OrderSalesman.Org.Company.CompanyId = companyId.(int64)
}
if companyLogo, ok := data["companyLogo"]; ok {
dividendsOrder.OrderSalesman.Org.Company.CompanyLogo = companyLogo.(string)
}
if companyName, ok := data["companyName"]; ok {
dividendsOrder.OrderSalesman.Org.Company.CompanyName = companyName.(string)
}
if roleId, ok := data["roleId"]; ok {
dividendsOrder.OrderSalesman.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
dividendsOrder.OrderSalesman.Role.RoleName = roleName.(string)
}
if userAvatar, ok := data["userAvatar"]; ok {
dividendsOrder.OrderSalesman.UserInfo.UserAvatar = userAvatar.(string)
}
if userEmail, ok := data["userEmail"]; ok {
dividendsOrder.OrderSalesman.UserInfo.UserEmail = userEmail.(string)
}
if userName, ok := data["userName"]; ok {
dividendsOrder.OrderSalesman.UserInfo.UserName = userName.(string)
}
if userPhone, ok := data["userPhone"]; ok {
dividendsOrder.OrderSalesman.UserInfo.UserPhone = userPhone.(string)
}
if userAccount, ok := data["userAccount"]; ok {
dividendsOrder.OrderSalesman.UserInfo.UserAccount = userAccount.(string)
}
if userType, ok := data["userType"]; ok {
dividendsOrder.OrderSalesman.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
dividendsOrder.OrderSalesman.Status = status.(int32)
}
if orderTime, ok := data["orderTime"]; ok {
dividendsOrder.OrderTime = orderTime.(time.Time)
}
if dividendTime, ok := data["dividendTime"]; ok {
dividendsOrder.DividendTime = dividendTime.(time.Time)
}
if dividendStatus, ok := data["dividendStatus"]; ok {
dividendsOrder.DividendStatus = dividendStatus.(int32)
}
if regionNumber, ok := data["regionNumber"]; ok {
dividendsOrder.Region.RegionNumber = regionNumber.(string)
}
if regionName, ok := data["regionName"]; ok {
dividendsOrder.Region.RegionName = regionName.(string)
}
if customerName, ok := data["customerName"]; ok {
dividendsOrder.CustomerName = customerName.(string)
}
return nil
}
... ...
package domain
import "time"
// DividendsReturnedOrder 分红退货单实体
type DividendsReturnedOrder struct {
// 分红退货单记录ID
DividendsReturnedOrderId int64 `json:"dividendsReturnedOrderId"`
// 分红退货单号
DividendsReturnedOrderNumber string `json:"dividendsReturnedOrderNumber"`
// 退货金额
DividendsReturnedOrderRefund float64 `json:"dividendsReturnedOrderRefund"`
// 源单号(原始订单号)
OriginalOrderNum string `json:"originalOrderNum"`
// 关联分红订单号
DividendsOrderNumber int64 `json:"dividendsOrderNumber,string"`
// 退货客户姓名
DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"`
// 退货日期
DividendsReturnedDate time.Time `json:"dividendsReturnedDate"`
// 退货区域
Region *RegionInfo `json:"region"`
// 备注
Remarks string `json:"remarks"`
// 分红订单分红状态,1待分红,2已分红,3部分分红
DividendStatus int32 `json:"dividendStatus"`
// 分红订单分红时间
DividendTime time.Time `json:"dividendTime"`
// 数据所属组织机构
Org *Org `json:"org"`
// 公司
Company *Company `json:"company"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 删除时间
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 操作人
Operator *User `json:"operator"`
// 操作时间
OperateTime time.Time `json:"operateTime"`
}
type DividendsReturnedOrderRepository interface {
Save(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error)
Remove(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error)
FindOne(queryOptions map[string]interface{}) (*DividendsReturnedOrder, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsReturnedOrder, error)
}
func (dividendsReturnedOrder *DividendsReturnedOrder) Identify() interface{} {
if dividendsReturnedOrder.DividendsReturnedOrderId == 0 {
return nil
}
return dividendsReturnedOrder.DividendsReturnedOrderId
}
func (dividendsReturnedOrder *DividendsReturnedOrder) Update(data map[string]interface{}) error {
if dividendsReturnedOrderNumber, ok := data["dividendsReturnedOrderNumber"]; ok {
dividendsReturnedOrder.DividendsReturnedOrderNumber = dividendsReturnedOrderNumber.(string)
}
if dividendsReturnedOrderRefund, ok := data["dividendsReturnedOrderRefund"]; ok {
dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderRefund.(float64)
}
if originalOrderNum, ok := data["originalOrderNum"]; ok {
dividendsReturnedOrder.OriginalOrderNum = originalOrderNum.(string)
}
if dividendsOrderNumber, ok := data["dividendsOrderNumber"]; ok {
dividendsReturnedOrder.DividendsOrderNumber = dividendsOrderNumber.(int64)
}
if dividendsReturnedCustomerName, ok := data["dividendsReturnedCustomerName"]; ok {
dividendsReturnedOrder.DividendsReturnedCustomerName = dividendsReturnedCustomerName.(string)
}
if dividendsReturnedDate, ok := data["dividendsReturnedDate"]; ok {
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate.(time.Time)
}
if regionNumber, ok := data["regionNumber"]; ok {
dividendsReturnedOrder.Region.RegionNumber = regionNumber.(string)
}
if regionName, ok := data["regionName"]; ok {
dividendsReturnedOrder.Region.RegionName = regionName.(string)
}
if remarks, ok := data["remarks"]; ok {
dividendsReturnedOrder.Remarks = remarks.(string)
}
if dividendStatus, ok := data["dividendStatus"]; ok {
dividendsReturnedOrder.DividendStatus = dividendStatus.(int32)
}
if dividendTime, ok := data["dividendTime"]; ok {
dividendsReturnedOrder.DividendTime = dividendTime.(time.Time)
}
if orgId, ok := data["orgId"]; ok {
dividendsReturnedOrder.Org.OrgId = orgId.(int64)
}
if roleId, ok := data["roleId"]; ok {
dividendsReturnedOrder.Operator.Role.RoleId = roleId.(int64)
}
if roleName, ok := data["roleName"]; ok {
dividendsReturnedOrder.Operator.Role.RoleName = roleName.(string)
}
if userType, ok := data["userType"]; ok {
dividendsReturnedOrder.Operator.UserType = userType.(int32)
}
if status, ok := data["status"]; ok {
dividendsReturnedOrder.Operator.Status = status.(int32)
}
return nil
}
... ...
... ... @@ -2,7 +2,7 @@ package domain
import "time"
// 金额激励规则实体
// MoneyIncentivesRule 金额激励规则实体
type MoneyIncentivesRule struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string"`
... ...
package domain
// 订单明细
type OrderDetails struct {
// 订单金额统计
OrderAmount float64 `json:"orderAmount"`
// 具体订单类型的金额明细
OrderAmountByTypes []*OrderAmountByType `json:"orderAmountByTypes"`
}
... ...
package domain
// 组织机构值对象
// Org 组织机构值对象
type Org struct {
// 组织机构ID
OrgId int64 `json:"orgId,string"`
... ...
package domain
// 推荐人值对象
// Referrer 推荐人值对象
type Referrer struct {
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
package domain
// 区域信息值对象
// RegionInfo 区域信息值对象
type RegionInfo struct {
// 区域编号
RegionNumber string `json:"regionNumber"`
... ...
package domain
// 共创合约相关人值对象
// Relevant 共创合约相关人值对象
type Relevant struct {
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
package domain
// 用户角色值对象
// Role 用户角色值对象
type Role struct {
// 角色ID
RoleId int64 `json:"roleId,string"`
... ...
package domain
// 业务员值对象
// Salesman 业务员值对象
type Salesman struct {
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
package domain
// 共创合约承接方值对象
// Undertaker 共创合约承接方值对象
type Undertaker struct {
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
package domain
// 用户第三方服务防腐模型
// User 用户第三方服务防腐模型
type User struct {
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `json:"userId,string"`
... ...
package domain
// 用户信息值对象
// UserInfo 用户信息值对象
type UserInfo struct {
// 用户头像
UserAvatar string `json:"userAvatar"`
... ...
package models
type DividendsOrder struct {
tableName string `comment:"分红订单实体" pg:"dividends_orders,alias:dividends_order"`
// 分红订单ID
DividendsOrderId int64 `comment:"分红订单ID" pg:"pk:dividends_order_id"`
// 分红订单号
DividendsOrderNumber int64 `comment:"分红订单号"`
// 分红订单原单号
DividendsOriginalOrderNum string `comment:"分红订单原单号"`
// 分红订单金额
DividendsOrderAmount float64 `comment:"分红订单金额"`
// 订单业务员
OrderSalesman *User `comment:"订单业务员"`
// 订单产生时间
OrderTime time.Time `comment:"订单产生时间"`
// 分红订单分红时间
DividendTime time.Time `comment:"分红订单分红时间"`
// 分红订单分红状态,1待分红,2已分红,3部分分红
DividendStatus int32 `comment:"分红订单分红状态,1待分红,2已分红,3部分分红"`
// 区域
Region *RegionInfo `comment:"区域"`
// 客户姓名
CustomerName string `comment:"客户姓名"`
// 数据所属组织机构
Org *Org `comment:"数据所属组织机构"`
// 公司
Company *Company `comment:"公司"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
// 操作人
Operator *User `comment:"操作人"`
}
... ...
package models
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DividendsReturnedOrder struct {
tableName string `comment:"分红退货单实体" pg:"dividends_returned_orders,alias:dividends_returned_order"`
// 分红退货单记录ID
DividendsReturnedOrderId int64 `comment:"分红退货单记录ID" pg:"pk:dividends_returned_order_id"`
// 分红退货单号
DividendsReturnedOrderNumber string `comment:"分红退货单号"`
// 退货金额
DividendsReturnedOrderRefund float64 `comment:"退货金额"`
// 源单号(原始订单号)
OriginalOrderNum string `comment:"源单号(原始订单号)"`
// 关联分红订单号
DividendsOrderNumber int64 `comment:"关联分红订单号"`
// 退货客户姓名
DividendsReturnedCustomerName string `comment:"退货客户姓名"`
// 退货日期
DividendsReturnedDate time.Time `comment:"退货日期"`
// 退货区域
Region *domain.RegionInfo `comment:"退货区域"`
// 备注
Remarks string `comment:"备注"`
// 分红订单分红状态,1待分红,2已分红,3部分分红
DividendStatus int32 `comment:"分红订单分红状态,1待分红,2已分红,3部分分红"`
// 分红订单分红时间
DividendTime time.Time `comment:"分红订单分红时间"`
// 数据所属组织机构
Org *domain.Org `comment:"数据所属组织机构"`
// 公司
Company *domain.Company `comment:"公司"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 删除时间
DeletedAt time.Time `comment:"删除时间"`
// 更新时间
UpdatedAt time.Time `comment:"更新时间"`
// 操作人
Operator *domain.User `comment:"操作人"`
// 操作时间
OperateTime time.Time `comment:"操作时间"`
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel *models.DividendsOrder) (*domain.DividendsOrder, error) {
return &domain.DividendsOrder{
DividendsOrderId: dividendsOrderModel.DividendsOrderId,
DividendsOrderNumber: dividendsOrderModel.DividendsOrderNumber,
DividendsOriginalOrderNum: dividendsOrderModel.DividendsOriginalOrderNum,
DividendsOrderAmount: dividendsOrderModel.DividendsOrderAmount,
OrderSalesman: dividendsOrderModel.OrderSalesman,
OrderTime: dividendsOrderModel.OrderTime,
DividendTime: dividendsOrderModel.DividendTime,
DividendStatus: dividendsOrderModel.DividendStatus,
Region: dividendsOrderModel.Region,
CustomerName: dividendsOrderModel.CustomerName,
Org: dividendsOrderModel.Org,
Company: dividendsOrderModel.Company,
CreatedAt: dividendsOrderModel.CreatedAt,
DeletedAt: dividendsOrderModel.DeletedAt,
UpdatedAt: dividendsOrderModel.UpdatedAt,
OperateTime: dividendsOrderModel.OperateTime,
Operator: dividendsOrderModel.Operator,
}, nil
}
... ...
package transform
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel *models.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) {
return &domain.DividendsReturnedOrder{
DividendsReturnedOrderId: dividendsReturnedOrderModel.DividendsReturnedOrderId,
DividendsReturnedOrderNumber: dividendsReturnedOrderModel.DividendsReturnedOrderNumber,
DividendsReturnedOrderRefund: dividendsReturnedOrderModel.DividendsReturnedOrderRefund,
OriginalOrderNum: dividendsReturnedOrderModel.OriginalOrderNum,
DividendsOrderNumber: dividendsReturnedOrderModel.DividendsOrderNumber,
DividendsReturnedCustomerName: dividendsReturnedOrderModel.DividendsReturnedCustomerName,
DividendsReturnedDate: dividendsReturnedOrderModel.DividendsReturnedDate,
Region: dividendsReturnedOrderModel.Region,
Remarks: dividendsReturnedOrderModel.Remarks,
DividendStatus: dividendsReturnedOrderModel.DividendStatus,
DividendTime: dividendsReturnedOrderModel.DividendTime,
Org: dividendsReturnedOrderModel.Org,
Company: dividendsReturnedOrderModel.Company,
CreatedAt: dividendsReturnedOrderModel.CreatedAt,
DeletedAt: dividendsReturnedOrderModel.DeletedAt,
UpdatedAt: dividendsReturnedOrderModel.UpdatedAt,
Operator: dividendsReturnedOrderModel.Operator,
OperateTime: dividendsReturnedOrderModel.OperateTime,
}, nil
}
... ...
package repository
import (
"fmt"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type DividendsOrderRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *DividendsOrderRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) {
sqlBuildFields := []string{
"dividends_order_id",
"dividends_order_number",
"dividends_original_order_num",
"dividends_order_amount",
"order_salesman",
"order_time",
"dividend_time",
"dividend_status",
"region",
"customer_name",
"org",
"company",
"created_at",
"deleted_at",
"updated_at",
"operate_time",
"operator",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsOrder_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsOrder.Identify() == nil {
dividendsOrderId, err := repository.nextIdentify()
if err != nil {
return dividendsOrder, err
} else {
dividendsOrder.DividendsOrderId = dividendsOrderId
}
if _, err := tx.QueryOne(
pg.Scan(
&dividendsOrder.DividendsOrderId,
&dividendsOrder.DividendsOrderNumber,
&dividendsOrder.DividendsOriginalOrderNum,
&dividendsOrder.DividendsOrderAmount,
&dividendsOrder.OrderSalesman,
&dividendsOrder.OrderTime,
&dividendsOrder.DividendTime,
&dividendsOrder.DividendStatus,
&dividendsOrder.Region,
&dividendsOrder.CustomerName,
&dividendsOrder.Org,
&dividendsOrder.Company,
&dividendsOrder.CreatedAt,
&dividendsOrder.DeletedAt,
&dividendsOrder.UpdatedAt,
&dividendsOrder.OperateTime,
&dividendsOrder.Operator,
),
fmt.Sprintf("INSERT INTO dividends_orders (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsOrder.DividendsOrderId,
dividendsOrder.DividendsOrderNumber,
dividendsOrder.DividendsOriginalOrderNum,
dividendsOrder.DividendsOrderAmount,
dividendsOrder.OrderSalesman,
dividendsOrder.OrderTime,
dividendsOrder.DividendTime,
dividendsOrder.DividendStatus,
dividendsOrder.Region,
dividendsOrder.CustomerName,
dividendsOrder.Org,
dividendsOrder.Company,
dividendsOrder.CreatedAt,
dividendsOrder.DeletedAt,
dividendsOrder.UpdatedAt,
dividendsOrder.OperateTime,
dividendsOrder.Operator,
); err != nil {
return dividendsOrder, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&dividendsOrder.DividendsOrderId,
&dividendsOrder.DividendsOrderNumber,
&dividendsOrder.DividendsOriginalOrderNum,
&dividendsOrder.DividendsOrderAmount,
&dividendsOrder.OrderSalesman,
&dividendsOrder.OrderTime,
&dividendsOrder.DividendTime,
&dividendsOrder.DividendStatus,
&dividendsOrder.Region,
&dividendsOrder.CustomerName,
&dividendsOrder.Org,
&dividendsOrder.Company,
&dividendsOrder.CreatedAt,
&dividendsOrder.DeletedAt,
&dividendsOrder.UpdatedAt,
&dividendsOrder.OperateTime,
&dividendsOrder.Operator,
),
fmt.Sprintf("UPDATE dividends_orders SET %s WHERE dividends_order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsOrder.DividendsOrderId,
dividendsOrder.DividendsOrderNumber,
dividendsOrder.DividendsOriginalOrderNum,
dividendsOrder.DividendsOrderAmount,
dividendsOrder.OrderSalesman,
dividendsOrder.OrderTime,
dividendsOrder.DividendTime,
dividendsOrder.DividendStatus,
dividendsOrder.Region,
dividendsOrder.CustomerName,
dividendsOrder.Org,
dividendsOrder.Company,
dividendsOrder.CreatedAt,
dividendsOrder.DeletedAt,
dividendsOrder.UpdatedAt,
dividendsOrder.OperateTime,
dividendsOrder.Operator,
dividendsOrder.Identify(),
); err != nil {
return dividendsOrder, err
}
}
return dividendsOrder, nil
}
func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
dividendsOrderModel := new(models.DividendsOrder)
dividendsOrderModel.DividendsOrderId = dividendsOrder.Identify().(int64)
if _, err := tx.Model(dividendsOrderModel).WherePK().Delete(); err != nil {
return dividendsOrder, err
}
return dividendsOrder, nil
}
func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
dividendsOrderModel := new(models.DividendsOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if dividendsOrderModel.DividendsOrderId == 0 {
return nil, nil
} else {
return transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel)
}
}
func (repository *DividendsOrderRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsOrder, error) {
tx := repository.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
dividendsOrders := make([]*domain.DividendsOrder, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsOrderModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("dividends_order_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsOrders, err
} else {
for _, dividendsOrderModel := range dividendsOrderModels {
if dividendsOrder, err := transform.TransformToDividendsOrderDomainModelFromPgModels(dividendsOrderModel); err != nil {
return 0, dividendsOrders, err
} else {
dividendsOrders = append(dividendsOrders, dividendsOrder)
}
}
return int64(count), dividendsOrders, nil
}
}
func NewDividendsOrderRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DividendsOrderRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/transform"
)
type DividendsReturnedOrderRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *DividendsReturnedOrderRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
return id, err
}
func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) {
sqlBuildFields := []string{
"dividends_returned_order_id",
"dividends_returned_order_number",
"dividends_returned_order_refund",
"original_order_num",
"dividends_order_number",
"dividends_returned_customer_name",
"dividends_returned_date",
"region",
"remarks",
"dividend_status",
"dividend_time",
"org",
"company",
"created_at",
"deleted_at",
"updated_at",
"operator",
"operate_time",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "dividendsReturnedOrder_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if dividendsReturnedOrder.Identify() == nil {
dividendsReturnedOrderId, err := repository.nextIdentify()
if err != nil {
return dividendsReturnedOrder, err
} else {
dividendsReturnedOrder.DividendsReturnedOrderId = dividendsReturnedOrderId
}
if _, err := tx.QueryOne(
pg.Scan(
&dividendsReturnedOrder.DividendsReturnedOrderId,
&dividendsReturnedOrder.DividendsReturnedOrderNumber,
&dividendsReturnedOrder.DividendsReturnedOrderRefund,
&dividendsReturnedOrder.OriginalOrderNum,
&dividendsReturnedOrder.DividendsOrderNumber,
&dividendsReturnedOrder.DividendsReturnedCustomerName,
&dividendsReturnedOrder.DividendsReturnedDate,
&dividendsReturnedOrder.Region,
&dividendsReturnedOrder.Remarks,
&dividendsReturnedOrder.DividendStatus,
&dividendsReturnedOrder.DividendTime,
&dividendsReturnedOrder.Org,
&dividendsReturnedOrder.Company,
&dividendsReturnedOrder.CreatedAt,
&dividendsReturnedOrder.DeletedAt,
&dividendsReturnedOrder.UpdatedAt,
&dividendsReturnedOrder.Operator,
&dividendsReturnedOrder.OperateTime,
),
fmt.Sprintf("INSERT INTO dividends_returned_orders (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
dividendsReturnedOrder.DividendsReturnedOrderId,
dividendsReturnedOrder.DividendsReturnedOrderNumber,
dividendsReturnedOrder.DividendsReturnedOrderRefund,
dividendsReturnedOrder.OriginalOrderNum,
dividendsReturnedOrder.DividendsOrderNumber,
dividendsReturnedOrder.DividendsReturnedCustomerName,
dividendsReturnedOrder.DividendsReturnedDate,
dividendsReturnedOrder.Region,
dividendsReturnedOrder.Remarks,
dividendsReturnedOrder.DividendStatus,
dividendsReturnedOrder.DividendTime,
dividendsReturnedOrder.Org,
dividendsReturnedOrder.Company,
dividendsReturnedOrder.CreatedAt,
dividendsReturnedOrder.DeletedAt,
dividendsReturnedOrder.UpdatedAt,
dividendsReturnedOrder.Operator,
dividendsReturnedOrder.OperateTime,
); err != nil {
return dividendsReturnedOrder, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(
&dividendsReturnedOrder.DividendsReturnedOrderId,
&dividendsReturnedOrder.DividendsReturnedOrderNumber,
&dividendsReturnedOrder.DividendsReturnedOrderRefund,
&dividendsReturnedOrder.OriginalOrderNum,
&dividendsReturnedOrder.DividendsOrderNumber,
&dividendsReturnedOrder.DividendsReturnedCustomerName,
&dividendsReturnedOrder.DividendsReturnedDate,
&dividendsReturnedOrder.Region,
&dividendsReturnedOrder.Remarks,
&dividendsReturnedOrder.DividendStatus,
&dividendsReturnedOrder.DividendTime,
&dividendsReturnedOrder.Org,
&dividendsReturnedOrder.Company,
&dividendsReturnedOrder.CreatedAt,
&dividendsReturnedOrder.DeletedAt,
&dividendsReturnedOrder.UpdatedAt,
&dividendsReturnedOrder.Operator,
&dividendsReturnedOrder.OperateTime,
),
fmt.Sprintf("UPDATE dividends_returned_orders SET %s WHERE dividends_returned_order_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
dividendsReturnedOrder.DividendsReturnedOrderId,
dividendsReturnedOrder.DividendsReturnedOrderNumber,
dividendsReturnedOrder.DividendsReturnedOrderRefund,
dividendsReturnedOrder.OriginalOrderNum,
dividendsReturnedOrder.DividendsOrderNumber,
dividendsReturnedOrder.DividendsReturnedCustomerName,
dividendsReturnedOrder.DividendsReturnedDate,
dividendsReturnedOrder.Region,
dividendsReturnedOrder.Remarks,
dividendsReturnedOrder.DividendStatus,
dividendsReturnedOrder.DividendTime,
dividendsReturnedOrder.Org,
dividendsReturnedOrder.Company,
dividendsReturnedOrder.CreatedAt,
dividendsReturnedOrder.DeletedAt,
dividendsReturnedOrder.UpdatedAt,
dividendsReturnedOrder.Operator,
dividendsReturnedOrder.OperateTime,
dividendsReturnedOrder.Identify(),
); err != nil {
return dividendsReturnedOrder, err
}
}
return dividendsReturnedOrder, nil
}
func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) {
tx := repository.transactionContext.PgTx
dividendsReturnedOrderModel := new(models.DividendsReturnedOrder)
dividendsReturnedOrderModel.DividendsReturnedOrderId = dividendsReturnedOrder.Identify().(int64)
if _, err := tx.Model(dividendsReturnedOrderModel).WherePK().Delete(); err != nil {
return dividendsReturnedOrder, err
}
return dividendsReturnedOrder, nil
}
func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsReturnedOrder, error) {
tx := repository.transactionContext.PgTx
dividendsReturnedOrderModel := new(models.DividendsReturnedOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsReturnedOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_id = ?", "dividendsReturnedOrderId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if dividendsReturnedOrderModel.DividendsReturnedOrderId == 0 {
return nil, nil
} else {
return transform.TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel)
}
}
func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.DividendsReturnedOrder, error) {
tx := repository.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
dividendsReturnedOrders := make([]*domain.DividendsReturnedOrder, 0)
query := sqlbuilder.BuildQuery(tx.Model(&dividendsReturnedOrderModels), queryOptions)
query.SetOffsetAndLimit(20)
query.SetOrderDirect("dividends_returned_order_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
return 0, dividendsReturnedOrders, err
} else {
for _, dividendsReturnedOrderModel := range dividendsReturnedOrderModels {
if dividendsReturnedOrder, err := transform.TransformToDividendsReturnedOrderDomainModelFromPgModels(dividendsReturnedOrderModel); err != nil {
return 0, dividendsReturnedOrders, err
} else {
dividendsReturnedOrders = append(dividendsReturnedOrders, dividendsReturnedOrder)
}
}
return int64(count), dividendsReturnedOrders, nil
}
}
func NewDividendsReturnedOrderRepository(transactionContext *pgTransaction.TransactionContext) (*DividendsReturnedOrderRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &DividendsReturnedOrderRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -23,8 +23,8 @@ func (controller *ContractUndertakerFeedbackController) UpdateContractUndertaker
contractUndertakerFeedbackService := service.NewContractUndertakerFeedbackService(nil)
updateContractUndertakerFeedbackCommand := &command.UpdateContractUndertakerFeedbackCommand{}
controller.Unmarshal(updateContractUndertakerFeedbackCommand)
contractUndertakerFeedbackId, _ := controller.GetString(":contractUndertakerFeedbackId")
updateContractUndertakerFeedbackCommand.ContractUndertakerFeedbackId = contractUndertakerFeedbackId
contractUndertakerFeedbackId := controller.GetString(":contractUndertakerFeedbackId")
updateContractUndertakerFeedbackCommand.FeedbackId = contractUndertakerFeedbackId
data, err := contractUndertakerFeedbackService.UpdateContractUndertakerFeedback(updateContractUndertakerFeedbackCommand)
controller.Response(data, err)
}
... ... @@ -32,8 +32,8 @@ func (controller *ContractUndertakerFeedbackController) UpdateContractUndertaker
func (controller *ContractUndertakerFeedbackController) GetContractUndertakerFeedback() {
contractUndertakerFeedbackService := service.NewContractUndertakerFeedbackService(nil)
getContractUndertakerFeedbackQuery := &query.GetContractUndertakerFeedbackQuery{}
contractUndertakerFeedbackId, _ := controller.GetString(":contractUndertakerFeedbackId")
getContractUndertakerFeedbackQuery.ContractUndertakerFeedbackId = contractUndertakerFeedbackId
contractUndertakerFeedbackId := controller.GetString(":contractUndertakerFeedbackId")
getContractUndertakerFeedbackQuery.FeedbackId = contractUndertakerFeedbackId
data, err := contractUndertakerFeedbackService.GetContractUndertakerFeedback(getContractUndertakerFeedbackQuery)
controller.Response(data, err)
}
... ... @@ -42,8 +42,8 @@ func (controller *ContractUndertakerFeedbackController) RemoveContractUndertaker
contractUndertakerFeedbackService := service.NewContractUndertakerFeedbackService(nil)
removeContractUndertakerFeedbackCommand := &command.RemoveContractUndertakerFeedbackCommand{}
controller.Unmarshal(removeContractUndertakerFeedbackCommand)
contractUndertakerFeedbackId, _ := controller.GetString(":contractUndertakerFeedbackId")
removeContractUndertakerFeedbackCommand.ContractUndertakerFeedbackId = contractUndertakerFeedbackId
contractUndertakerFeedbackId := controller.GetString(":contractUndertakerFeedbackId")
removeContractUndertakerFeedbackCommand.FeedbackId = contractUndertakerFeedbackId
data, err := contractUndertakerFeedbackService.RemoveContractUndertakerFeedback(removeContractUndertakerFeedbackCommand)
controller.Response(data, err)
}
... ...