作者 yangfu

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

…ion-cooperation into dev
不能预览此文件类型
... ... @@ -51,9 +51,7 @@ type CreateRelevantPeopleCommand struct {
type CreateCooperationContractCommand struct {
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 共创合约发起部门编码
DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"`
... ...
... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"strconv"
"time"
)
... ... @@ -90,6 +91,30 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
organization = data
}
// 共创合约DAO初始化
var cooperationContractDao *dao.CooperationContractDao
if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationContractDao = value
}
// 生成共创合约编号
contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 校验共创合约编号是否唯一
numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
"orgId": createCooperationContractCommand.OrgId,
"cooperationContractNumber": contractNumber,
})
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创合约异常")
}
// 获取承接人
var undertakers []*domain.Undertaker
for _, undertaker := range createCooperationContractCommand.Undertakers {
... ... @@ -122,7 +147,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
undertakers = append(undertakers, &domain.Undertaker{
UndertakerId: 0,
UserId: undertakerDomain.UserId,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
... ... @@ -150,7 +175,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
relevantPeople = append(relevantPeople, &domain.Relevant{
RelevantId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
... ... @@ -169,7 +194,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
for _, dividendsIncentivesRule := range createCooperationContractCommand.DividendsIncentivesRules {
dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
DividendsIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
... ... @@ -189,7 +214,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
for _, moneyIncentivesRule := range createCooperationContractCommand.MoneyIncentivesRules {
moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
MoneyIncentivesRuleId: 0,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),
MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage),
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
... ... @@ -224,7 +249,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
newCooperationContract := &domain.CooperationContract{
CooperationContractDescription: createCooperationContractCommand.CooperationContractDescription,
CooperationContractName: createCooperationContractCommand.CooperationContractName,
CooperationContractNumber: createCooperationContractCommand.CooperationContractNumber,
CooperationContractNumber: contractNumber,
CooperationContractUndertakerTypes: createCooperationContractCommand.CooperationContractUndertakerTypes,
CooperationContractSponsor: sponsor,
CooperationMode: cooperationMode,
... ...
... ... @@ -4,7 +4,9 @@ import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/d
type CooperationProjectsDto struct {
*domain.CooperationProject
CooperationMode *CooperationMode `json:"cooperationMode"`
//CooperationMode *CooperationMode `json:"cooperationMode"`
// 可以去除勾选的共创项目承接对象列表
UndertakerTypesUncheckedAvailable []int32 `json:"undertakerTypesUncheckedAvailable"`
}
type CooperationMode struct {
... ... @@ -16,11 +18,13 @@ type CooperationMode struct {
CooperationModeName string `json:"cooperationModeName"`
}
func (dto *CooperationProjectsDto) LoadDto(project *domain.CooperationProject, mode *domain.CooperationMode) {
func (dto *CooperationProjectsDto) LoadDto(project *domain.CooperationProject, mode *domain.CooperationMode, undertakerTypesUncheckedAvailable []int32) error {
dto.CooperationProject = project
dto.CooperationMode = &CooperationMode{
CooperationModeId: mode.CooperationModeId,
CooperationModeName: mode.CooperationModeName,
CooperationModeNumber: mode.CooperationModeNumber,
}
dto.UndertakerTypesUncheckedAvailable = undertakerTypesUncheckedAvailable
//dto.CooperationMode = &CooperationMode{
// CooperationModeId: mode.CooperationModeId,
// CooperationModeName: mode.CooperationModeName,
// CooperationModeNumber: mode.CooperationModeNumber,
//}
return nil
}
... ...
... ... @@ -5,10 +5,12 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"strconv"
"time"
)
... ... @@ -134,8 +136,31 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationProjectCommand.CooperationModeNumber))
} else {
// 共创项目DAO初始化
var cooperationProjectDao *dao.CooperationProjectDao
if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationProjectDao = value
}
// 生成共创项目编号
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber()
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 校验共创项目编号是否唯一
numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
"orgId": createCooperationProjectCommand.OrgId,
"cooperationProjectNumber": projectNumber,
})
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常")
}
newCooperationProject := &domain.CooperationProject{
CooperationProjectNumber: fmt.Sprintf("%v", time.Now().UnixNano()), //TODO:项目编码生成
CooperationProjectNumber: projectNumber,
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
CooperationProjectUndertakerTypes: createCooperationProjectCommand.CooperationProjectUndertakerTypes,
CooperationProjectSponsor: sponsor,
... ... @@ -203,6 +228,27 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationProjectQuery.CooperationProjectId, 10)))
} else {
// 共创项目DAO初始化
var cooperationProjectDao *dao.CooperationProjectDao
if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationProjectDao = value
}
//TODO 获取可删除的承接对象类型
undertakerTypesUncheckedAvailable, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
"cooperationProjectUndertakerTypes": cooperationProject.CooperationProjectUndertakerTypes,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
cooperationProjectDto := &dto.CooperationProjectsDto{}
if err := cooperationProjectDto.LoadDto(cooperationProject, nil, undertakerTypesUncheckedAvailable); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -12,3 +12,35 @@ func CreateCooperationModeDao(options map[string]interface{}) (*dao.CooperationM
}
return dao.NewCooperationModeDao(transactionContext)
}
func CreateCooperationProjectDao(options map[string]interface{}) (*dao.CooperationProjectDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewCooperationProjectDao(transactionContext)
}
func CreateCooperationContractDao(options map[string]interface{}) (*dao.CooperationContractDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewCooperationContractDao(transactionContext)
}
func CreateDividendsOrderDao(options map[string]interface{}) (*dao.DividendsOrderDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewDividendsOrderDao(transactionContext)
}
func CreateDividendsReturnedOrderDao(options map[string]interface{}) (*dao.DividendsReturnedOrderDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewDividendsReturnedOrderDao(transactionContext)
}
... ...
不能预览此文件类型
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type CooperationContractDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateContractNumber 生成共创合约编号
func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
tx := dao.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
query := tx.Model(&cooperationContractModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_contract.created_at >= ?", todayZeroTime)
query.Where("cooperation_contract.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "HY" + timeString + "#" + countStr
return contractNumber, nil
}
}
// CheckContractNumberAvailable 检验合约编号唯一性
func (dao *CooperationContractDao) CheckContractNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
query := tx.Model(&cooperationContractModels)
if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
query = query.Where("cooperation_contract_number = ?", cooperationContractNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationContractDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type CooperationProjectDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateProjectNumber 生成共创项目编码
func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
tx := dao.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
query := tx.Model(&cooperationProjectModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_project.created_at >= ?", todayZeroTime)
query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
}
}
// CheckUndertakerTypesUncheckedAvailable TODO 校验项目承接对象是否可以删除
func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {
return []int32{}, nil
}
// CheckProjectNumberAvailable 校验项目编号唯一性
func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
query := tx.Model(&cooperationProjectModels)
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query = query.Where("cooperation_project_number = ?", cooperationProjectNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationProjectDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type DividendsOrderDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateDividendsOrderNumber 生成分红订单号
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
query := tx.Model(&dividendsOrderModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_order.created_at >= ?", todayZeroTime)
query.Where("dividends_order.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "SL" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
func NewDividendsOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
} else {
return &DividendsOrderDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"time"
)
type DividendsReturnedOrderDao struct {
transactionContext *pgTransaction.TransactionContext
}
// GenerateDividendsReturnedOrderNumber 生成分红退货单号
func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (string, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
currentTime := time.Now()
todayZeroTime := utils.GetZeroTime(currentTime)
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsReturnedOrderNumber := "RE" + timeString + "#" + countStr
return dividendsReturnedOrderNumber, nil
}
}
func NewDividendsReturnedOrderDao(transactionContext *pgTransaction.TransactionContext) (*DividendsReturnedOrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能未")
} else {
return &DividendsReturnedOrderDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
package utils
import (
"fmt"
"strconv"
"time"
)
func GetDayBegin() time.Time {
t := time.Now()
today, _ := time.Parse("2006-01-02", t.Format("2006-01-02"))
return today
}
func GetDayEnd() time.Time {
t := GetDayBegin()
nextDay := t.AddDate(0, 0, 1)
return nextDay
}
//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
func GetFirstDateOfMonth(d time.Time) time.Time {
d = d.AddDate(0, 0, -d.Day()+1)
return GetZeroTime(d)
}
//获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
func GetNextMonthFirstDay(d time.Time) time.Time {
d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
return GetZeroTime(d)
}
//获取某一天的0点时间
func GetZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
}
//获取某一天的23点59分59秒
func GetNextDayZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
}
// TransformTimestampToTime 根据13位时间戳返回日期时间格式时间
func TransformTimestampToTime(timeStamp int64) time.Time {
t := strconv.FormatInt(timeStamp, 10)
tIpartStr := t[0:10]
//tDecpartStr := t[10:13]
ipart, _ := strconv.ParseInt(tIpartStr, 10, 64)
//decpart, _ := strconv.ParseInt(tDecpartStr, 10, 64)
myTime := time.Unix(ipart, 0)
fmt.Println(myTime)
return time.Date(myTime.Year(), myTime.Month(), myTime.Day(), myTime.Hour(), myTime.Minute(), myTime.Second(), 0, time.Local)
}
... ...