作者 yangfu

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

…ion-cooperation into dev
... ... @@ -101,18 +101,31 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
var newCooperationApplication *domain.CooperationApplication
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作
// TODO 获取申请人信息
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 && applyForCooperationCommand.UserBaseId != 0 { // 游客操作
// 获取申请人信息
var applicant *domain.User
if data, err := userService.VisitorFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserBaseId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
} else {
applicant = data
}
// TODO 校验:同一个用户,不能多次申请同一个项目
// 校验:同一个用户,不能多次申请同一个项目
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
"visitorUserBaseId": applicant.UserBaseId,
"cooperationApplicationId": cooperationProject.CooperationProjectId,
})
if applicationExist {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
}
// TODO 校验:判断用户类型是否属于承接对象
//if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
//}
// 校验:判断用户类型是否属于承接对象
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
}
newCooperationApplication = &domain.CooperationApplication{
CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息
CooperationApplicationApplicant: applicant,
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
CooperationApplicationStatus: 1,
... ... @@ -157,6 +170,7 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
"companyId": applyForCooperationCommand.CompanyId,
"orgId": applyForCooperationCommand.OrgId,
"applicantId": applicant.UserId,
"cooperationApplicationId": cooperationProject.CooperationProjectId,
})
if applicationExist {
... ...
... ... @@ -16,9 +16,9 @@ type PayCreditAccountCommand struct {
// 账期结算实付金额
ActuallyPaidAmount float64 `cname:"账期结算实付金额" json:"actuallyPaidAmount" valid:"Required"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
Remarks string `cname:"备注" json:"remarks"`
// 支付凭证附件
PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment" valid:"Required"`
PaymentDocumentAttachments []*domain.Attachment `cname:"支付凭证附件" json:"paymentDocumentAttachment"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ... @@ -30,7 +30,6 @@ type PayCreditAccountCommand struct {
}
func (payCreditAccountCommand *PayCreditAccountCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (payCreditAccountCommand *PayCreditAccountCommand) ValidateCommand() error {
... ...
... ... @@ -609,6 +609,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
})
}
// 统计分红订单
var countDividendsOrders int32
// 获取订单产品
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
"orderGoodIds": orderGoodIds,
... ... @@ -634,9 +637,15 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for i, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), int64(i))
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -718,25 +727,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
"dividendsEstimates": dividendsEstimates,
})
// 创建成功的分红预算单
var dividendsEstimatesSavedSuccessfully []*domain.DividendsEstimate
// 创建失败的分红预算单
var dividendsEstimateSaveFailed []*domain.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
dividendsEstimateSaveFailed = append(dividendsEstimateSaveFailed, dividendsEstimate)
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else if dividendsEstimateSaved != nil {
dividendsEstimatesSavedSuccessfully = append(dividendsEstimatesSavedSuccessfully, dividendsEstimate)
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
successfullyCount := len(dividendsEstimatesSaved)
return fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// TODO 分析成功和失败原因
return dividendsEstimatesSavedSuccessfully, nil
}
}
... ...
... ... @@ -643,6 +643,9 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
// 统计当前分红订单数
count, err := dividendsOrderDao.CountDividendsOrder(map[string]interface{}{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 批量创建分红订单
for i, dividendsOrder := range createDividendsOrderCommands {
... ...
package service
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"time"
)
type DividendsEstimateDetail struct {
... ... @@ -12,6 +14,28 @@ type DividendsEstimateDetail struct {
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
}
// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividendsEstimateNumber(count int64, index int64) (string, error) {
currentTime := time.Now()
if count+index < 1000 {
countStr := fmt.Sprintf("%03d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsEstimateNumber := "FH" + timeString + "#" + countStr
return dividendsEstimateNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+index+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsEstimateNumber := "FH" + timeString + "#" + countStr
return dividendsEstimateNumber, nil
}
}
type ConfirmDividendsIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error)
... ...
... ... @@ -9,4 +9,5 @@ type UserService interface {
RelevantFrom(companyId int64, orgId int64, userId int64) (*domain.Relevant, error) // 获取相关人
SalesmanFrom(companyId int64, orgId int64, userId int64) (*domain.Salesman, error) // 获取业务员
OperatorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取操作人
VisitorFrom(companyId int64, orgId int64, userId int64) (*domain.User, error) // 获取游客
}
... ...
... ... @@ -27,6 +27,9 @@ func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[str
if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
}
if visitorUserBaseId, ok := queryOptions["visitorUserBaseId"]; ok && visitorUserBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, visitorUserBaseId)
}
if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
}
... ...
... ... @@ -75,6 +75,18 @@ func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface
return ok, err
}
// CountDividendsEstimate 统计当前分红预算单总数
func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]interface{}) (int, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return 0, err
} else {
return count, nil
}
}
func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -172,6 +172,33 @@ func (service *UserService) OperatorFrom(companyId int64, orgId int64, userId in
}
}
// VisitorFrom 获取游客
func (service *UserService) VisitorFrom(companyId int64, orgId int64, userBaseId int64) (*domain.User, error) {
var returnData *domain.User
if userAdaptor, err := adaptor.NewUserAdaptor(); err != nil {
return nil, err
} else {
if visitor, err := userAdaptor.ToParticipator(companyId, orgId, userBaseId, "Visitor"); err != nil {
return nil, err
} else {
if visitor != nil {
log.Logger.Debug("游客", map[string]interface{}{
"visitor interface": visitor,
})
visitorJson, err1 := json.Marshal(visitor)
if err1 != nil {
return nil, err
}
err2 := json.Unmarshal(visitorJson, &returnData)
if err2 != nil {
return nil, err2
}
}
return returnData, nil
}
}
}
func NewUserService() (*UserService, error) {
return &UserService{}, nil
}
... ...
... ... @@ -164,7 +164,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.Identify() == nil {
dividendsEstimateId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsEstimate.DividendsEstimateId = dividendsEstimateId
}
}
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.DividendsEstimateId,
DividendsAccountStatus: dividendsEstimate.DividendsAccountStatus,
DividendsAmount: dividendsEstimate.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber,
... ...
... ... @@ -54,6 +54,12 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
return map[string]interface{}{}, nil
}
return user, nil
case "Visitor": // 游客
visitor, err := userTranslator.ToVisitorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return visitor, nil
}
}
return map[string]interface{}{}, nil
... ...
... ... @@ -42,6 +42,33 @@ func (serviceGateway *HttplibUserServiceGateway) GetUser(companyId int64, orgId
return &data, err
}
// GetUserInfo 获取用户信息
func (serviceGateway *HttplibUserServiceGateway) GetUserInfo(companyId int64, orgId int64, userBaseId int64) (*translator.UserDetail, error) {
url := serviceGateway.baseURL + "/auth/user-info"
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["userBaseId"] = userBaseId
_, err1 := request.JSONBody(options)
if err1 != nil {
return nil, err1
}
byteResult, err := request.Bytes()
if err != nil {
return nil, fmt.Errorf("获取获取用户信息失败:%w", err)
}
log.Logger.Debug("获取用户模块请求数据:获取用户信息。", map[string]interface{}{
"result": string(byteResult),
})
var result GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析获取用户:%w", err)
}
var data translator.UserDetail
err = serviceGateway.getResponseData(result, &data)
return &data, err
}
// GetUsers 获取用户
func (serviceGateway *HttplibUserServiceGateway) GetUsers(companyId int64, orgId int64, uids []int64) (map[string]interface{}, error) {
companyIdStr := strconv.FormatInt(companyId, 10)
... ...
... ... @@ -8,6 +8,20 @@ import (
type UserTranslator struct {
}
type UserInfoDetail struct {
UserBaseId int64 `json:"userBaseId"`
UserType int32 `json:"userType"`
UserInfo struct {
UserName string `json:"userName"`
Phone string `json:"phone"`
} `json:"userInfo,omitempty"`
Im struct {
Accid string `json:"accid"`
ImToken string `json:"imToken"`
CsAccountId string `json:"csAccountId"`
} `json:"im,omitempty"`
}
type UserDetail struct {
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
... ... @@ -348,7 +362,7 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
var roles []*domain.Role
for _, role := range user.UserRole {
roles = append(roles, &domain.Role{
RoleId: int64(role.RoleID),
RoleId: role.RoleID,
RoleName: role.RoleName,
})
}
... ... @@ -386,6 +400,19 @@ func (translator *UserTranslator) ToUserFromRepresentation(user *UserDetail) (*d
}, nil
}
func (translator *UserTranslator) ToVisitorFromRepresentation(user *UserDetail) (*domain.User, error) {
return &domain.User{
UserBaseId: user.UserBaseId,
UserInfo: &domain.UserInfo{
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
},
UserType: user.UserType,
UserName: user.UserInfo.UserName,
UserPhone: user.UserInfo.Phone,
}, nil
}
func NewUserTranslator() (*UserTranslator, error) {
return &UserTranslator{}, nil
}
... ...