作者 yangfu

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

…ion-cooperation into dev
不能预览此文件类型
@@ -51,9 +51,7 @@ type CreateRelevantPeopleCommand struct { @@ -51,9 +51,7 @@ type CreateRelevantPeopleCommand struct {
51 type CreateCooperationContractCommand struct { 51 type CreateCooperationContractCommand struct {
52 // 共创合约描述 52 // 共创合约描述
53 CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"` 53 CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
54 - // 共创合约编号  
55 - CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`  
56 - // 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 54 + // 共创项目编号
57 CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"` 55 CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
58 // 共创合约发起部门编码 56 // 共创合约发起部门编码
59 DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"` 57 DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"`
@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
  12 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
12 "strconv" 13 "strconv"
13 "time" 14 "time"
14 ) 15 )
@@ -90,6 +91,30 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -90,6 +91,30 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
90 organization = data 91 organization = data
91 } 92 }
92 93
  94 + // 共创合约DAO初始化
  95 + var cooperationContractDao *dao.CooperationContractDao
  96 + if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
  97 + "transactionContext": transactionContext,
  98 + }); err != nil {
  99 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  100 + } else {
  101 + cooperationContractDao = value
  102 + }
  103 + // 生成共创合约编号
  104 + contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
  105 + if err2 != nil {
  106 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  107 + }
  108 + // 校验共创合约编号是否唯一
  109 + numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
  110 + "companyId": createCooperationContractCommand.CompanyId,
  111 + "orgId": createCooperationContractCommand.OrgId,
  112 + "cooperationContractNumber": contractNumber,
  113 + })
  114 + if !numberAvailable {
  115 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创合约异常")
  116 + }
  117 +
93 // 获取承接人 118 // 获取承接人
94 var undertakers []*domain.Undertaker 119 var undertakers []*domain.Undertaker
95 for _, undertaker := range createCooperationContractCommand.Undertakers { 120 for _, undertaker := range createCooperationContractCommand.Undertakers {
@@ -122,7 +147,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -122,7 +147,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
122 undertakers = append(undertakers, &domain.Undertaker{ 147 undertakers = append(undertakers, &domain.Undertaker{
123 UndertakerId: 0, 148 UndertakerId: 0,
124 UserId: undertakerDomain.UserId, 149 UserId: undertakerDomain.UserId,
125 - CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, 150 + CooperationContractNumber: contractNumber,
126 UserBaseId: undertakerDomain.UserBaseId, 151 UserBaseId: undertakerDomain.UserBaseId,
127 Org: undertakerDomain.Org, 152 Org: undertakerDomain.Org,
128 Orgs: undertakerDomain.Orgs, 153 Orgs: undertakerDomain.Orgs,
@@ -150,7 +175,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -150,7 +175,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
150 } 175 }
151 relevantPeople = append(relevantPeople, &domain.Relevant{ 176 relevantPeople = append(relevantPeople, &domain.Relevant{
152 RelevantId: 0, 177 RelevantId: 0,
153 - CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, 178 + CooperationContractNumber: contractNumber,
154 UserId: relevantDomain.UserId, 179 UserId: relevantDomain.UserId,
155 UserBaseId: relevantDomain.UserBaseId, 180 UserBaseId: relevantDomain.UserBaseId,
156 Org: relevantDomain.Org, 181 Org: relevantDomain.Org,
@@ -169,7 +194,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -169,7 +194,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
169 for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules { 194 for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules {
170 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{ 195 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
171 DividendsIncentivesRuleId: 0, 196 DividendsIncentivesRuleId: 0,
172 - CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, 197 + CooperationContractNumber: contractNumber,
173 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage, 198 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
174 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage, 199 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
175 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage, 200 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
@@ -189,7 +214,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -189,7 +214,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
189 for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules { 214 for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules {
190 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{ 215 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
191 MoneyIncentivesRuleId: 0, 216 MoneyIncentivesRuleId: 0,
192 - CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, 217 + CooperationContractNumber: contractNumber,
193 MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount), 218 MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
194 MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage), 219 MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
195 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, 220 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
@@ -224,7 +249,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -224,7 +249,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
224 newCooperationContract := &domain.CooperationContract{ 249 newCooperationContract := &domain.CooperationContract{
225 CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription, 250 CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
226 CooperationContractName: createCooperationContractCommand.CooperationContractName, 251 CooperationContractName: createCooperationContractCommand.CooperationContractName,
227 - CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber, 252 + CooperationContractNumber: contractNumber,
228 CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes, 253 CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes,
229 CooperationContractSponsor: sponsor, 254 CooperationContractSponsor: sponsor,
230 CooperationMode: cooperationMode, 255 CooperationMode: cooperationMode,
@@ -4,7 +4,9 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/d @@ -4,7 +4,9 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/d
4 4
5 type CooperationProjectsDto struct { 5 type CooperationProjectsDto struct {
6 *domain.CooperationProject 6 *domain.CooperationProject
7 - CooperationMode *CooperationMode `json:"cooperationMode"` 7 + //CooperationMode *CooperationMode `json:"cooperationMode"`
  8 + // 可以去除勾选的共创项目承接对象列表
  9 + UndertakerTypesUncheckedAvailable []int32 `json:"undertakerTypesUncheckedAvailable"`
8 } 10 }
9 11
10 type CooperationMode struct { 12 type CooperationMode struct {
@@ -16,11 +18,13 @@ type CooperationMode struct { @@ -16,11 +18,13 @@ type CooperationMode struct {
16 CooperationModeName string `json:"cooperationModeName"` 18 CooperationModeName string `json:"cooperationModeName"`
17 } 19 }
18 20
19 -func (dto *CooperationProjectsDto) LoadDto(project *domain.CooperationProject, mode *domain.CooperationMode) { 21 +func (dto *CooperationProjectsDto) LoadDto(project *domain.CooperationProject, mode *domain.CooperationMode, undertakerTypesUncheckedAvailable []int32) error {
20 dto.CooperationProject = project 22 dto.CooperationProject = project
21 - dto.CooperationMode = &CooperationMode{  
22 - CooperationModeId: mode.CooperationModeId,  
23 - CooperationModeName: mode.CooperationModeName,  
24 - CooperationModeNumber: mode.CooperationModeNumber,  
25 - } 23 + dto.UndertakerTypesUncheckedAvailable = undertakerTypesUncheckedAvailable
  24 + //dto.CooperationMode = &CooperationMode{
  25 + // CooperationModeId: mode.CooperationModeId,
  26 + // CooperationModeName: mode.CooperationModeName,
  27 + // CooperationModeNumber: mode.CooperationModeNumber,
  28 + //}
  29 + return nil
26 } 30 }
@@ -5,10 +5,12 @@ import ( @@ -5,10 +5,12 @@ import (
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
6 "github.com/linmadan/egglib-go/utils/tool_funs" 6 "github.com/linmadan/egglib-go/utils/tool_funs"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/dto"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 12 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
  13 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
12 "strconv" 14 "strconv"
13 "time" 15 "time"
14 ) 16 )
@@ -134,8 +136,31 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro @@ -134,8 +136,31 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
134 if cooperationMode == nil { 136 if cooperationMode == nil {
135 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationProjectCommand.CooperationModeNumber)) 137 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationProjectCommand.CooperationModeNumber))
136 } else { 138 } else {
  139 + // 共创项目DAO初始化
  140 + var cooperationProjectDao *dao.CooperationProjectDao
  141 + if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
  142 + "transactionContext": transactionContext,
  143 + }); err != nil {
  144 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  145 + } else {
  146 + cooperationProjectDao = value
  147 + }
  148 + // 生成共创项目编号
  149 + projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber()
  150 + if err2 != nil {
  151 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  152 + }
  153 + // 校验共创项目编号是否唯一
  154 + numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
  155 + "companyId": createCooperationProjectCommand.CompanyId,
  156 + "orgId": createCooperationProjectCommand.OrgId,
  157 + "cooperationProjectNumber": projectNumber,
  158 + })
  159 + if !numberAvailable {
  160 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常")
  161 + }
137 newCooperationProject := &domain.CooperationProject{ 162 newCooperationProject := &domain.CooperationProject{
138 - CooperationProjectNumber: fmt.Sprintf("%v", time.Now().UnixNano()), //TODO:项目编码生成 163 + CooperationProjectNumber: projectNumber,
139 CooperationProjectName: createCooperationProjectCommand.CooperationProjectName, 164 CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
140 CooperationProjectUndertakerTypes: createCooperationProjectCommand.CooperationProjectUndertakerTypes, 165 CooperationProjectUndertakerTypes: createCooperationProjectCommand.CooperationProjectUndertakerTypes,
141 CooperationProjectSponsor: sponsor, 166 CooperationProjectSponsor: sponsor,
@@ -203,6 +228,27 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -203,6 +228,27 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
203 if cooperationProject == nil { 228 if cooperationProject == nil {
204 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationProjectQuery.CooperationProjectId, 10))) 229 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationProjectQuery.CooperationProjectId, 10)))
205 } else { 230 } else {
  231 + // 共创项目DAO初始化
  232 + var cooperationProjectDao *dao.CooperationProjectDao
  233 + if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
  234 + "transactionContext": transactionContext,
  235 + }); err != nil {
  236 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  237 + } else {
  238 + cooperationProjectDao = value
  239 + }
  240 + //TODO 获取可删除的承接对象类型
  241 + undertakerTypesUncheckedAvailable, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
  242 + "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
  243 + "cooperationProjectUndertakerTypes": cooperationProject.CooperationProjectUndertakerTypes,
  244 + })
  245 + if err != nil {
  246 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  247 + }
  248 + cooperationProjectDto := &dto.CooperationProjectsDto{}
  249 + if err := cooperationProjectDto.LoadDto(cooperationProject, nil, undertakerTypesUncheckedAvailable); err != nil {
  250 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  251 + }
206 if err := transactionContext.CommitTransaction(); err != nil { 252 if err := transactionContext.CommitTransaction(); err != nil {
207 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 253 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
208 } 254 }
@@ -12,3 +12,35 @@ func CreateCooperationModeDao(options map[string]interface{}) (*dao.CooperationM @@ -12,3 +12,35 @@ func CreateCooperationModeDao(options map[string]interface{}) (*dao.CooperationM
12 } 12 }
13 return dao.NewCooperationModeDao(transactionContext) 13 return dao.NewCooperationModeDao(transactionContext)
14 } 14 }
  15 +
  16 +func CreateCooperationProjectDao(options map[string]interface{}) (*dao.CooperationProjectDao, error) {
  17 + var transactionContext *pg.TransactionContext
  18 + if value, ok := options["transactionContext"]; ok {
  19 + transactionContext = value.(*pg.TransactionContext)
  20 + }
  21 + return dao.NewCooperationProjectDao(transactionContext)
  22 +}
  23 +
  24 +func CreateCooperationContractDao(options map[string]interface{}) (*dao.CooperationContractDao, error) {
  25 + var transactionContext *pg.TransactionContext
  26 + if value, ok := options["transactionContext"]; ok {
  27 + transactionContext = value.(*pg.TransactionContext)
  28 + }
  29 + return dao.NewCooperationContractDao(transactionContext)
  30 +}
  31 +
  32 +func CreateDividendsOrderDao(options map[string]interface{}) (*dao.DividendsOrderDao, error) {
  33 + var transactionContext *pg.TransactionContext
  34 + if value, ok := options["transactionContext"]; ok {
  35 + transactionContext = value.(*pg.TransactionContext)
  36 + }
  37 + return dao.NewDividendsOrderDao(transactionContext)
  38 +}
  39 +
  40 +func CreateDividendsReturnedOrderDao(options map[string]interface{}) (*dao.DividendsReturnedOrderDao, error) {
  41 + var transactionContext *pg.TransactionContext
  42 + if value, ok := options["transactionContext"]; ok {
  43 + transactionContext = value.(*pg.TransactionContext)
  44 + }
  45 + return dao.NewDividendsReturnedOrderDao(transactionContext)
  46 +}
不能预览此文件类型
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  8 + "time"
  9 +)
  10 +
  11 +type CooperationContractDao struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +// GenerateContractNumber 生成共创合约编号
  16 +func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
  17 + tx := dao.transactionContext.PgTx
  18 + var cooperationContractModels []*models.CooperationContract
  19 + query := tx.Model(&cooperationContractModels)
  20 + currentTime := time.Now()
  21 + todayZeroTime := utils.GetZeroTime(currentTime)
  22 + nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
  23 + query.Where("cooperation_contract.created_at >= ?", todayZeroTime)
  24 + query.Where("cooperation_contract.created_at < ?", nextDayZeroTime)
  25 + if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
  26 + return "", err
  27 + } else {
  28 + countStr := fmt.Sprintf("%03d", count+1)
  29 + timestamp := currentTime.Unix()
  30 + timeNow := time.Unix(timestamp, 0)
  31 + timeString := timeNow.Format("20060102")
  32 + timeString = timeString[2:len(timeString)]
  33 + contractNumber := "HY" + timeString + "#" + countStr
  34 + return contractNumber, nil
  35 + }
  36 +}
  37 +
  38 +// CheckContractNumberAvailable 检验合约编号唯一性
  39 +func (dao *CooperationContractDao) CheckContractNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
  40 + tx := dao.transactionContext.PgTx
  41 + var cooperationContractModels []*models.CooperationContract
  42 + query := tx.Model(&cooperationContractModels)
  43 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  44 + query = query.Where("cooperation_contract_number = ?", cooperationContractNumber)
  45 + }
  46 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  47 + query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
  48 + }
  49 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  50 + query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
  51 + }
  52 + ok, err := query.Exists()
  53 + return !ok, err
  54 +}
  55 +
  56 +func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
  57 + if transactionContext == nil {
  58 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  59 + } else {
  60 + return &CooperationContractDao{
  61 + transactionContext: transactionContext,
  62 + }, nil
  63 + }
  64 +}
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  8 + "time"
  9 +)
  10 +
  11 +type CooperationProjectDao struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +// GenerateProjectNumber 生成共创项目编码
  16 +func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
  17 + tx := dao.transactionContext.PgTx
  18 + var cooperationProjectModels []*models.CooperationProject
  19 + query := tx.Model(&cooperationProjectModels)
  20 + currentTime := time.Now()
  21 + todayZeroTime := utils.GetZeroTime(currentTime)
  22 + nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
  23 + query.Where("cooperation_project.created_at >= ?", todayZeroTime)
  24 + query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
  25 + if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
  26 + return "", err
  27 + } else {
  28 + countStr := fmt.Sprintf("%03d", count+1)
  29 + timestamp := currentTime.Unix()
  30 + timeNow := time.Unix(timestamp, 0)
  31 + timeString := timeNow.Format("20060102")
  32 + timeString = timeString[2:len(timeString)]
  33 + contractNumber := "XM" + timeString + "#" + countStr
  34 + return contractNumber, nil
  35 + }
  36 +}
  37 +
  38 +// CheckUndertakerTypesUncheckedAvailable TODO 校验项目承接对象是否可以删除
  39 +func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {
  40 + return []int32{}, nil
  41 +}
  42 +
  43 +// CheckProjectNumberAvailable 校验项目编号唯一性
  44 +func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
  45 + tx := dao.transactionContext.PgTx
  46 + var cooperationProjectModels []*models.CooperationProject
  47 + query := tx.Model(&cooperationProjectModels)
  48 + if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
  49 + query = query.Where("cooperation_project_number = ?", cooperationProjectNumber)
  50 + }
  51 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  52 + query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
  53 + }
  54 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  55 + query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId)
  56 + }
  57 + ok, err := query.Exists()
  58 + return !ok, err
  59 +}
  60 +
  61 +func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) {
  62 + if transactionContext == nil {
  63 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  64 + } else {
  65 + return &CooperationProjectDao{
  66 + transactionContext: transactionContext,
  67 + }, nil
  68 + }
  69 +}
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  8 + "time"
  9 +)
  10 +
  11 +type DividendsOrderDao struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +// GenerateDividendsOrderNumber 生成分红订单号
  16 +func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
  17 + tx := dao.transactionContext.PgTx
  18 + var dividendsOrderModels []*models.DividendsOrder
  19 + query := tx.Model(&dividendsOrderModels)
  20 + currentTime := time.Now()
  21 + todayZeroTime := utils.GetZeroTime(currentTime)
  22 + nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
  23 + query.Where("dividends_order.created_at >= ?", todayZeroTime)
  24 + query.Where("dividends_order.created_at < ?", nextDayZeroTime)
  25 + if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
  26 + return "", err
  27 + } else {
  28 + countStr := fmt.Sprintf("%03d", count+1)
  29 + timestamp := currentTime.Unix()
  30 + timeNow := time.Unix(timestamp, 0)
  31 + timeString := timeNow.Format("20060102")
  32 + timeString = timeString[2:len(timeString)]
  33 + dividendsOrderNumber := "SL" + timeString + "#" + countStr
  34 + return dividendsOrderNumber, nil
  35 + }
  36 +}
  37 +
  38 +func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
  39 + if transactionContext == nil {
  40 + return nil, fmt.Errorf("transactionContext参数不能未")
  41 + } else {
  42 + return &DividendsOrderDao{
  43 + transactionContext: transactionContext,
  44 + }, nil
  45 + }
  46 +}
  1 +package dao
  2 +
  3 +import (
  4 + "fmt"
  5 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  8 + "time"
  9 +)
  10 +
  11 +type DividendsReturnedOrderDao struct {
  12 + transactionContext *pgTransaction.TransactionContext
  13 +}
  14 +
  15 +// GenerateDividendsReturnedOrderNumber 生成分红退货单号
  16 +func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (string, error) {
  17 + tx := dao.transactionContext.PgTx
  18 + var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
  19 + query := tx.Model(&dividendsReturnedOrderModels)
  20 + currentTime := time.Now()
  21 + todayZeroTime := utils.GetZeroTime(currentTime)
  22 + nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
  23 + query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
  24 + query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
  25 + if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
  26 + return "", err
  27 + } else {
  28 + countStr := fmt.Sprintf("%03d", count+1)
  29 + timestamp := currentTime.Unix()
  30 + timeNow := time.Unix(timestamp, 0)
  31 + timeString := timeNow.Format("20060102")
  32 + timeString = timeString[2:len(timeString)]
  33 + dividendsReturnedOrderNumber := "RE" + timeString + "#" + countStr
  34 + return dividendsReturnedOrderNumber, nil
  35 + }
  36 +}
  37 +
  38 +func NewDividendsReturnedOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsReturnedOrderDao, error) {
  39 + if transactionContext == nil {
  40 + return nil, fmt.Errorf("transactionContext参数不能未")
  41 + } else {
  42 + return &DividendsReturnedOrderDao{
  43 + transactionContext: transactionContext,
  44 + }, nil
  45 + }
  46 +}
  1 +package utils
  2 +
  3 +import (
  4 + "fmt"
  5 + "strconv"
  6 + "time"
  7 +)
  8 +
  9 +func GetDayBegin() time.Time {
  10 + t := time.Now()
  11 + today, _ := time.Parse("2006-01-02", t.Format("2006-01-02"))
  12 + return today
  13 +}
  14 +
  15 +func GetDayEnd() time.Time {
  16 + t := GetDayBegin()
  17 + nextDay := t.AddDate(0, 0, 1)
  18 + return nextDay
  19 +}
  20 +
  21 +//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
  22 +func GetFirstDateOfMonth(d time.Time) time.Time {
  23 + d = d.AddDate(0, 0, -d.Day()+1)
  24 + return GetZeroTime(d)
  25 +}
  26 +
  27 +//获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
  28 +func GetNextMonthFirstDay(d time.Time) time.Time {
  29 + d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
  30 + return GetZeroTime(d)
  31 +}
  32 +
  33 +//获取某一天的0点时间
  34 +func GetZeroTime(d time.Time) time.Time {
  35 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
  36 +}
  37 +
  38 +//获取某一天的23点59分59秒
  39 +func GetNextDayZeroTime(d time.Time) time.Time {
  40 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
  41 +}
  42 +
  43 +// TransformTimestampToTime 根据13位时间戳返回日期时间格式时间
  44 +func TransformTimestampToTime(timeStamp int64) time.Time {
  45 + t := strconv.FormatInt(timeStamp, 10)
  46 + tIpartStr := t[0:10]
  47 + //tDecpartStr := t[10:13]
  48 + ipart, _ := strconv.ParseInt(tIpartStr, 10, 64)
  49 + //decpart, _ := strconv.ParseInt(tDecpartStr, 10, 64)
  50 + myTime := time.Unix(ipart, 0)
  51 + fmt.Println(myTime)
  52 + return time.Date(myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second(), 0, time.Local)
  53 +}