作者 陈志颖

fix conflict

正在显示 43 个修改的文件 包含 721 行增加279 行删除
... ... @@ -11,6 +11,11 @@
- [APP端原型地址](https://9cnuol.axshare.com/)
- [WEB端原型地址](https://eq4yc2.axshare.com/)
## 开发环境服务地址
- [后端地址](http://allied-creation-cooperation-dev.fjmaimaimai.com/)
- [前端地址](http://allied-creation-standard-dev.fjmaimaimai.com/)
- [H5地址(app)](http://allied-creation-h5-dev.fjmaimaimai.com)
## 项目规范
- 领域描述语言文档位置:document/allied-creation-cooperation/
- GIT流程:里程碑->问题->功能分支->代码审查->合并分支
... ...
... ... @@ -62,6 +62,8 @@ spec:
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_HTTPS
value: "true"
- name: ENABLE_KAFKA_LOG
value: "false"
- name: USER_MODULE_HOST
... ...
... ... @@ -62,6 +62,8 @@ spec:
value: "beego"
- name: LOG_TYPE
value: "file"
- name: ENABLE_HTTPS
value: "true"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
... ...
... ... @@ -66,6 +66,8 @@ spec:
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
- name: ENABLE_HTTPS
value: "true"
- name: ENABLE_KAFKA_LOG
value: "false"
- name: USER_MODULE_HOST
... ...
... ... @@ -24,6 +24,10 @@ type OneClickApprovalCooperationApplicationCommand struct {
Action int32 `cname:"审核动作" json:"action" valid:"Required"`
// 审核状态
CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus"`
// 查询限制
OffsetLimit bool `cname:"查询限制" json:"offsetLimit"`
// 是否取消标志
IsCanceled int32 `cname:"是否删除" json:"isCanceled"`
}
func (oneClickApprovalCooperationApplicationCommand *OneClickApprovalCooperationApplicationCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -55,20 +55,20 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
}
// 公司REST服务初始化
var companyService service.CompanyService
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
companyService = value
}
//var companyService service.CompanyService
//if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// companyService = value
//}
// 组织机构REST服务初始化
var organizationService service.OrgService
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organizationService = value
}
//var organizationService service.OrgService
//if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// organizationService = value
//}
// 共创申请仓储初始化
var cooperationApplicationRepository domain.CooperationApplicationRepository
... ... @@ -162,20 +162,20 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
}
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
} else {
company = data
}
//var company *domain.Company
//if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
//} else {
// company = data
//}
// 获取组织机构信息
var organization *domain.Org
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
} else {
organization = data
}
//var organization *domain.Org
//if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
//} else {
// organization = data
//}
// 校验:同一个用户,不能多次申请同一个项目
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
... ... @@ -211,9 +211,9 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
CooperationApplicationVerifyTime: time.Time{},
CooperationApplyTime: time.Now(),
CooperationProject: cooperationProject,
Org: organization,
Org: cooperationProject.Org,
IsCanceled: 1,
Company: company,
Company: cooperationProject.Company,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
... ... @@ -371,6 +371,7 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova
// 获取共创申请
if count, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
"cooperationApplicationIds": cooperationApplicationIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -444,13 +445,18 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr
// 获取审核人
var verifier *domain.User
if data, err := userService.UserFrom(oneClickApprovalCooperationApplicationCommand.CompanyId, oneClickApprovalCooperationApplicationCommand.OrgId, oneClickApprovalCooperationApplicationCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取审核人失败")
} else {
verifier = data
}
// 查询共创申请
oneClickApprovalCooperationApplicationCommand.CooperationApplicationStatus = 1 // 待审核
oneClickApprovalCooperationApplicationCommand.OffsetLimit = false
oneClickApprovalCooperationApplicationCommand.IsCanceled = int32(1)
oneClickApprovalCooperationApplicationCommand.UserBaseId = 0
oneClickApprovalCooperationApplicationCommand.UserId = 0
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(oneClickApprovalCooperationApplicationCommand)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -28,7 +28,7 @@ type UpdateCooperationContractCommand struct {
// 金额激励规则列表
MoneyIncentivesRules []*CreateMoneyIncentivesRulesCommand `cname:"金额激励规则列表" json:"moneyIncentivesRules,omitempty"`
// 承接方列表
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers" valid:"Required"`
Undertakers []*CreateUndertakersCommand `cname:"承接方列表" json:"undertakers"`
// 相关人UID列表
RelevantIds []string `cname:"相关人列表" json:"relevantIds,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -561,6 +561,7 @@ func (cooperationContractService *CooperationContractService) BatchRemoveCoopera
cooperationContractIds, _ := utils.SliceAtoi(batchRemoveCooperationContractCommand.CooperationContractIds)
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"cooperationContractIds": cooperationContractIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -737,6 +738,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
}
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"cooperationContractIds": cooperationContractIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -1203,7 +1205,6 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 保存共创合约变更记录
var incentivesRuleChange string
var incentivesRuleChangeDetail string
var undertakerChange string
// 规则变更,原【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点),(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】-->更新后【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】
if cooperationContractFound.IncentivesType != cooperationContract.IncentivesType { // 1.激励规则类型变更
... ... @@ -1380,6 +1381,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
/*********************************************** 承接人变更 *****************************************************/
var undertakerChange string
// 计算原合约哈希值
//cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.Undertakers))
var cooperationContractFoundBytes []byte
... ... @@ -1439,7 +1441,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersOriginal = undertakersOriginal + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTmp1 := "【" + undertakersOriginal + "】"
... ... @@ -1476,7 +1478,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
UserPhone: "",
}
}
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
undertakersChanged = undertakersChanged + strconv.FormatInt(int64(i+1), 10) + "(" + undertaker.UserInfo.UserName + "," + undertaker.Referrer.UserName + "," + undertaker.Salesman.UserName + ")"
}
undertakerChangeTemp2 := "【" + undertakersChanged + "】"
// 拼接承接人变更记录
... ...
... ... @@ -328,6 +328,7 @@ func (cooperationModeService *CooperationModeService) BatchRemoveCooperationMode
// 获取共创模式
if count, cooperationModes, err := cooperationModeRepository.Find(map[string]interface{}{
"cooperationModeIds": cooperationModeIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -14,13 +14,13 @@ type GetCooperationProjectQuery struct {
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId" valid:"Required"`
OrgId int64 `cname:"组织机构ID" json:"orgId"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId" valid:"Required"`
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"`
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
}
func (getCooperationProjectQuery *GetCooperationProjectQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -52,6 +52,8 @@ type SearchCooperationProjectQuery struct {
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
// 额外的查询条件 0:不需要额外查询 1:额外查询
SearchCooperationProjectExtQueriesFlag int `cname:"额外的查询条件标识" json:"searchCooperationProjectExtQueriesFlag"`
// 额外的查询条件
SearchCooperationProjectExtQueries []*SearchCooperationProjectExtQuery `cname:"额外的查询条件" json:"searchCooperationProjectExtQueries"`
}
... ...
... ... @@ -281,6 +281,16 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
cooperationApplicationRepository = value
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
var getCooperationProjectQuerySpecific *query.GetCooperationProjectQuery
if getCooperationProjectQuery.CooperationProjectId != 0 { // 根据ID查询
getCooperationProjectQuerySpecific = &query.GetCooperationProjectQuery{
... ... @@ -349,6 +359,47 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3)
}
// 判断项目关联的合约承接人类型
undertakers := make([]*domain.Undertaker, 0)
if countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
"companyId": cooperationProject.Company.CompanyId,
"orgId": cooperationProject.Org.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
if countContracts > 0 {
for _, cooperationContract := range cooperationContracts {
undertakers = append(undertakers, cooperationContract.Undertakers...)
}
}
}
var undertakerUserTypes []int32
for _, undertaker := range undertakers {
undertakerUserTypes = append(undertakerUserTypes, undertaker.UserType)
}
undertakerUserTypes = utils.RemoveDuplicationInt32(undertakerUserTypes)
for i, userType := range undertakerUserTypes {
if userType == 1025 {
undertakerUserTypes[i] = 2
}
}
if utils.IsContain(undertakerUserTypes, int32(1)) && utils.IsContain(undertakerUserTypes, int32(2)) {
undertakerUserTypes = append(undertakerUserTypes, int32(3))
}
// 取项目承接人和合约承接人的交集
newUndertakerTypesUncheckedAvailable := utils.Intersect32(undertakerTypesUncheckedAvailable, undertakerUserTypes)
log.Logger.Info("承接人类型", map[string]interface{}{
"undertakerUserTypes": undertakerUserTypes,
})
// 返回所有员工类型的申请通过人
applicants := make([]*domain.User, 0)
... ... @@ -357,6 +408,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
"cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber,
"companyId": cooperationProject.Company.CompanyId,
"orgId": cooperationProject.Org.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -375,7 +427,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
}
cooperationProjectDto := &dto.CooperationProjectsDto{}
if err := cooperationProjectDto.LoadDto(cooperationProject, nil, undertakerTypesUncheckedAvailable, applicants); err != nil {
if err := cooperationProjectDto.LoadDto(cooperationProject, nil, newUndertakerTypesUncheckedAvailable, applicants); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
... ... @@ -639,6 +691,7 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
}
}
}
var undertakerTypes []int32
var k1, k2 int32
if len(applicantTypes) > 0 {
... ... @@ -654,6 +707,7 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
if k1 != 0 && k2 != 0 {
undertakerTypes = append(undertakerTypes, 3)
}
// 校验可以修改的承接人(申请人)类型
for _, t := range undertakerTypes {
if !utils.IsContain(updateCooperationProjectCommand.CooperationProjectUndertakerTypes, t) {
... ... @@ -766,6 +820,7 @@ func (cooperationProjectService *CooperationProjectService) BatchEndCooperationP
}
if count, cooperationProjects, err := cooperationProjectRepository.Find(map[string]interface{}{
"cooperationProjectIds": cooperationProjectIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -28,6 +28,8 @@ type SearchDividendsEstimateQuery struct {
PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 是否取消(删除)
IsCanceled bool `cname:"是否取消" json:"isCanceled,omitempty"`
}
func (searchDividendsEstimateQuery *SearchDividendsEstimateQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -343,6 +343,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs
// 获取分红预算
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
"dividendsEstimateIds": dividendsEstimateIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -520,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat
// ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算
func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) {
start := time.Now()
if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -549,12 +551,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 获取公司信息
startGetCompany := time.Now()
var company *domain.Company
if data, err := companyService.CompanyFrom(confirmDividendsIncentivesEstimateCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
company = data
}
fmt.Println("获取公司信息耗时:", time.Since(startGetCompany))
// 组织机构REST服务初始化
var organizationService service.OrgService
... ... @@ -565,12 +569,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 获取组织机构信息
startGetOrg := time.Now()
var organization *domain.Org
if data, err := organizationService.OrgFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organization = data
}
fmt.Println("获取组织机构数据耗时:", time.Since(startGetOrg))
// 用户REST服务初始化
var userService service.UserService
... ... @@ -581,12 +587,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 获取操作人
startGetOperator := time.Now()
var operator *domain.User
if data, err := userService.OperatorFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, confirmDividendsIncentivesEstimateCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
operator = data
}
fmt.Println("获取操作人耗时:", time.Since(startGetOperator))
// 订单产品仓储初始化
var orderGoodRepository domain.OrderGoodRepository
... ... @@ -638,6 +646,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
dividendsReturnedOrderRepository = value
}
// 共创合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 初始化确认业绩激励分红预算领域服务
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
... ... @@ -658,13 +676,52 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
estimateFailedDividendsOrders := make(map[string]string)
// 获取订单产品
startGetOrderGoods := time.Now()
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
"orderGoodIds": orderGoodIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
fmt.Println("获取订单产品耗时:", time.Since(startGetOrderGoods))
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
var cooperationContractNumbers []string
// 获取订单产品合约编号
for _, orderGood := range orderGoods {
cooperationContractNumbers = append(cooperationContractNumbers, orderGood.CooperationContractNumber)
}
newCooperationContractNumbers := utils.RemoveDuplicationString(cooperationContractNumbers)
cooperationContractsMap := make(map[string]*domain.CooperationContract, 0)
// 查询共创合约
startQueryContracts := time.Now()
if len(newCooperationContractNumbers) > 0 {
if count, cooperationContractsFound, err := cooperationContractRepository.Find(map[string]interface{}{
"cooperationContractNumbers": newCooperationContractNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
if count > 0 {
for _, cooperationContractFound := range cooperationContractsFound {
cooperationContractsMap[cooperationContractFound.CooperationContractNumber] = cooperationContractFound
}
}
}
} else {
return map[string]interface{}{
"report": fmt.Sprintf("已完成0单订单分红预算,生成0单分红预算,失败原因:产品未关联合约"),
}, nil
}
fmt.Println("查询共创合约耗时:", time.Since(startQueryContracts))
// 统计当前企业分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
... ... @@ -674,14 +731,21 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
var countDividendsEstimate int64
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
// 临时方案
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
returnedOrderGoodsToConfirm := make([]*domain.OrderGood, 0)
for _, orderGood := range orderGoods {
if orderGood.DividendsOrderNumber != "" {
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
// 分红订单产品预算
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm); err != nil {
} else if orderGood.DividendsReturnedOrderNumber != "" {
returnedOrderGoodsToConfirm = append(returnedOrderGoodsToConfirm, orderGood)
}
}
startConfirm := time.Now()
if len(orderGoodsToConfirm) > 0 { // 分红订单产品预算
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
... ... @@ -698,7 +762,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
// 统计分红预算单数目
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
... ... @@ -707,8 +771,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.ORDER_DIVIDENDS,
DividendsTypeName: "订单分红",
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderOrReturnedOrderNum: dividendsEstimateDetail.OrderOrReturnedOrderNumber,
CooperationContractNumber: dividendsEstimateDetail.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsPercentage: dividendsEstimateDetail.DividendsPercentage,
DividendsStage: dividendsEstimateDetail.DividendsStage,
... ... @@ -720,8 +784,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodId: dividendsEstimateDetail.OrderGoodId,
OrderGoodAmount: dividendsEstimateDetail.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
}
... ... @@ -733,11 +797,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
}
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
orderGoodsToConfirm := make([]*domain.OrderGood, 0)
orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
// 分红退货单产品预算
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoodsToConfirm); err != nil {
} else if len(returnedOrderGoodsToConfirm) > 0 { // 退货单产品预算
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(returnedOrderGoodsToConfirm, confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId, cooperationContractsMap); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
... ... @@ -754,7 +815,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
// 统计生成的预算单数量
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
... ... @@ -763,8 +824,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
DividendsType: domain.RETURN_WRITE_OFF,
DividendsTypeName: "退货冲销",
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderOrReturnedOrderNum: dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber,
CooperationContractNumber: dividendsReturnedEstimateDetail.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsPercentage: dividendsReturnedEstimateDetail.DividendsPercentage,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
... ... @@ -776,8 +837,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodId: dividendsReturnedEstimateDetail.OrderGoodId,
OrderGoodAmount: dividendsReturnedEstimateDetail.OrderGoodAmount,
PaymentStatus: int32(1),
CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
}
... ... @@ -790,15 +851,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
}
}
log.Logger.Info("新增的分红预算单", map[string]interface{}{
"dividendsEstimates": dividendsEstimates,
})
fmt.Println("订单分红耗时:", time.Since(startConfirm))
startInsert := time.Now()
if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
fmt.Println("插入预算单耗时:", time.Since(startInsert))
// 获取产品ID
orderGoodSavedIds := make([]int64, 0)
for _, dividendsEstimate := range dividendsEstimates {
... ... @@ -806,10 +865,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 更新订单产品分红状态
startUpdateGoodStatus := time.Now()
var orderGoodsSaved []*domain.OrderGood
if len(orderGoodSavedIds) > 0 {
// 订单产品ID去重
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodSavedIds)
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
"orderGoodIds": orderGoodSavedIds,
"orderGoodIds": newOrderGoodIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -824,6 +887,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
}
fmt.Println("更新订单产品分红状态耗时:", time.Since(startUpdateGoodStatus))
// 分离分红订单和退货单
dividendsOrderNumbers := make([]string, 0)
... ... @@ -840,20 +904,14 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
log.Logger.Info("分红订单", map[string]interface{}{
"dividendsOrderNumbers": dividendsOrderNumbers,
})
log.Logger.Info("分红退货单", map[string]interface{}{
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
})
// 查找分红订单
startUpdateOrder := time.Now()
if len(dividendsOrderNumbers) > 0 {
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumbers": dividendsOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -890,13 +948,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
}
fmt.Println("更新订单耗时:", time.Since(startUpdateOrder))
// 查找分红退货单
startUpdateReturnedOrder := time.Now()
if len(dividendsReturnedOrderNumbers) > 0 {
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -933,9 +994,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
}
fmt.Println("更新退货单耗时:", time.Since(startUpdateReturnedOrder))
startCommit := time.Now()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
fmt.Println("提交事务耗时:", time.Since(startCommit))
// 统计成功的分红预算
successfullyCount := len(dividendsEstimatesSaved)
... ... @@ -952,6 +1017,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
failedReasonStr = "无"
}
fmt.Println("函数执行完毕:", time.Since(start))
return map[string]interface{}{
"report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
}, nil
... ... @@ -1166,7 +1233,10 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g
} else {
dividendsEstimateRepository = value
}
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId})
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{
"dividendsEstimateId": getDividendsEstimateQuery.DividendsEstimateId,
"isCanceled": false,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -1283,6 +1353,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimat
} else {
dividendsEstimateRepository = value
}
searchDividendsEstimateQuery.IsCanceled = false
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(tool_funs.SimpleStructToMap(searchDividendsEstimateQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -14,13 +14,13 @@ type GetDividendsOrderQuery struct {
// 分红订单编号
DividendsOrderNumber string `cname:"分红订单编号" json:"dividendsOrderNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId" valid:"Required"`
OrgId int64 `cname:"组织机构ID" json:"orgId"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId" valid:"Required"`
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId" valid:"Required"`
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
}
func (getDividendsOrderQuery *GetDividendsOrderQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -406,8 +406,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
v := reflect.ValueOf(dividendsOrder)
for k := 0; k < t.NumField(); k++ {
//fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()), ", yaml:", t.Field(k).Tag.Get("yaml"))
fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
if t.Field(k).Name != "RegionName" && t.Field(k).Name != "Expense" {
//fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
if t.Field(k).Name != "Expense" {
if v.Field(k).Interface() == "" {
col := strconv.Itoa(k + 1)
nullCell = append(nullCell, col)
... ... @@ -439,10 +439,11 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
/***************************************************** 3.单元格类型校验 *********************************************/
typeError := make([]*domain.FailInfo, 0)
for _, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { // 行
var myRow []*domain.FailInfo
for j, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData { // 行
t := reflect.TypeOf(dividendsOrder)
v := reflect.ValueOf(dividendsOrder)
var myRow []*domain.FailInfo
for k := 0; k < t.NumField(); k++ { // 列
//r := strconv.Itoa(i + 1)
switch k {
... ... @@ -454,7 +455,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "订单日期格式错误,请输入正确的订单日期",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -467,7 +468,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "行产品数量格式错误,产品数量必须整数",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -476,7 +477,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "产品数量必须大于0,请重新填写",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -489,7 +490,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "产品价格格式错误,产品价格必须为数字类型",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -499,7 +500,16 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "产品价格超过最大限制,产品价格小数点前面不能超过十六位数字,并保留两位小数",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
// 正负判断
if univalent < 0 {
tmpRow := &domain.FailInfo{
FailReason: "产品价格必须大于0,请重新填写",
}
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -513,7 +523,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "费用格式错误,费用必须为数字类型",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
log.Logger.Info("费用类型错误", map[string]interface{}{
"tmpRow": tmpRow,
... ... @@ -525,7 +535,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
tmpRow := &domain.FailInfo{
FailReason: "费用超过最大限制,费用小数点前面不能超过十六位数字,并保留两位小数",
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
tmpRow.ImportDividendsOrderData = &importDividendsOrderCommand.DividendsOrderData[j]
myRow = append(myRow, tmpRow)
continue
}
... ... @@ -558,16 +568,17 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
var dividendsOrderCommands = make(map[string]*command.CreateDividendsOrderCommand)
for i, dividendsOrder := range importDividendsOrderCommand.DividendsOrderData {
hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum + dividendsOrder.OrderTime))
hashValue := md5.Sum([]byte(dividendsOrder.OriginalOrderNum))
hashString := hex.EncodeToString(hashValue[:])
if _, ok := dividendsOrderCommands[hashString]; !ok {
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsOrder.OrderTime, time.Local)
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "无效的订单日期",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
... ... @@ -577,6 +588,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "产品数量类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
... ... @@ -587,8 +599,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "产品价格类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
... ... @@ -598,8 +610,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
tmpRow := &domain.FailInfo{
FailReason: "费用类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
} else {
... ... @@ -634,14 +646,26 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
UserBaseId: importDividendsOrderCommand.UserBaseId,
LineNumbers: []int{i}, // 记录行号
}
} else { // 聚合同一笔订单产品
} else if _, exist := dividendsOrderCommands[hashString]; exist { // 聚合同一笔订单产品
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsOrder.OrderTime, time.Local)
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "无效的订单日期",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
// 产品相关:产品名称,产品数量、产品价格、费用
quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "产品数量类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
... ... @@ -650,8 +674,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if err != nil {
tmpRow := &domain.FailInfo{
FailReason: "产品价格类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
... ... @@ -661,8 +685,8 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
if expenseParse, err := strconv.ParseFloat(dividendsOrder.Expense, 64); err != nil {
tmpRow := &domain.FailInfo{
FailReason: "费用类型错误",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
tmpRow.ImportDividendsOrderData = &dividendsOrder
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
} else {
... ... @@ -670,6 +694,29 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
}
log.Logger.Info("订单时间1:", map[string]interface{}{
"timeValue": strconv.FormatInt(timeValue.Local().UnixNano()/1e6, 10),
})
log.Logger.Info("订单时间2:", map[string]interface{}{
"timeValue": dividendsOrderCommands[hashString].OrderTime,
})
if strconv.FormatInt(timeValue.Local().UnixNano()/1e6, 10) != dividendsOrderCommands[hashString].OrderTime {
log.Logger.Info("订单:", map[string]interface{}{
"order": dividendsOrder,
})
tmpRow := &domain.FailInfo{
FailReason: "同一来源单号的订单,订单日期必须相同",
ImportDividendsOrderData: &importDividendsOrderCommand.DividendsOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
log.Logger.Info("聚合订单错误:", map[string]interface{}{
"aggregateErrorList": aggregateErrorList,
})
continue
}
dividendsOrderCommands[hashString].OrderGoods = append(dividendsOrderCommands[hashString].OrderGoods, command.OrderGoods{
OrderGoodId: "0",
OrderGoodAmount: 0,
... ... @@ -861,6 +908,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrderGoodDividendsStatus: int32(1),
OrgId: importDividendsOrderCommand.OrgId,
CompanyId: importDividendsOrderCommand.CompanyId,
CreatedAt: time.Now(),
... ... @@ -1077,6 +1125,7 @@ func (dividendsOrderService *DividendsOrderService) RemoveDividendsOrder(removeD
// BatchRemoveDividendsOrder 批量移除分红订单实体对象
func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(batchRemoveDividendsOrderCommand *command.BatchRemoveDividendsOrderCommand) (interface{}, error) {
start := time.Now()
if err := batchRemoveDividendsOrderCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -1121,18 +1170,42 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
dividendsEstimateRepository = value
}
// 分红预算单DAO初始化
//var dividendsEstimateDao *dao.DividendsEstimateDao
//if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//} else {
// dividendsEstimateDao = value
//}
// 分红退货单DAO初始化
//var dividendsReturnedOrderDao *dao.DividendsReturnedOrderDao
//if value, err := factory.CreateDividendsReturnedOrderDao(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
//} else {
// dividendsReturnedOrderDao = value
//}
dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
}
if count, dividendsOrders, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderIds": dividendsOrderIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
fmt.Println("截止目前耗时1:", time.Since(start))
if count > 0 {
// 校验分红订单是否有退货单关联
for _, dividendsOrder := range dividendsOrders {
// 校验分红订单是否有关联的退货单
startCount := time.Now()
if countReturnedOrder, _, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
"companyId": dividendsOrder.Company.CompanyId,
... ... @@ -1145,13 +1218,29 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
}
}
fmt.Println("退货单计数:", time.Since(startCount))
//startCount := time.Now()
//if returnedOrderExist, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderExist(map[string]interface{}{
// "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
// "companyId": dividendsOrder.Company.CompanyId,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// if returnedOrderExist {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
// }
//}
//fmt.Println("退货单计数:", time.Since(startCount))
// 校验分红订单是否有分红预算
startEstimateCount := time.Now()
if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
"companyId": dividendsOrder.Company.CompanyId,
"orgId": dividendsOrder.Org.OrgId,
"orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
"offsetLimit": false,
"limit": 1,
"offset": 0,
"isCanceled": false,
}); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
... ... @@ -1160,15 +1249,34 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
}
}
fmt.Println("预算单计数:", time.Since(startEstimateCount))
//startEstimateCount := time.Now()
//if estimateOrderExist, err3 := dividendsEstimateDao.CheckDividendsEstimateOrderExist(map[string]interface{}{
// "companyId": dividendsOrder.Company.CompanyId,
// "orgId": dividendsOrder.Org.OrgId,
// "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
// "isCanceled": false,
//}); err3 != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
//} else {
// if estimateOrderExist {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
// }
//}
//fmt.Println("预算单计数:", time.Since(startEstimateCount))
}
fmt.Println("截止目前耗时2:", time.Since(start))
dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
fmt.Println("截止目前耗时3:", time.Since(start))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
fmt.Println("截止目前耗时4:", time.Since(start))
return dividendsOrdersRemoved, nil
} else {
return map[string]interface{}{}, nil
... ...
... ... @@ -445,14 +445,14 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
t := reflect.TypeOf(dividendsReturnedOrder)
v := reflect.ValueOf(dividendsReturnedOrder)
for k := 0; k < t.NumField(); k++ {
fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
if t.Field(k).Name != "RegionName" {
//fmt.Println("name:", fmt.Sprintf("%+v", t.Field(k).Name), ", value:", fmt.Sprintf("%v", v.Field(k).Interface()))
//if t.Field(k).Name != "RegionName" {
if v.Field(k).Interface() == "" {
col := strconv.Itoa(k + 1)
nullCell = append(nullCell, col)
nullFlag = true
}
}
//}
}
if nullFlag {
myRow := &domain.FailReturnedInfo{
... ... @@ -478,10 +478,11 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
/***************************************************** 3.单元格类型校验 *********************************************/
typeError := make([]*domain.FailReturnedInfo, 0)
for _, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData { // 行
var myRow []*domain.FailReturnedInfo
for j, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData { // 行
t := reflect.TypeOf(dividendsReturnedOrder)
v := reflect.ValueOf(dividendsReturnedOrder)
var myRow []*domain.FailReturnedInfo
for k := 0; k < t.NumField(); k++ { // 列
switch k {
case 3: // 退货日期校验
... ... @@ -491,7 +492,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if !ok {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货日期格式错误,请输入正确的退货日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -504,7 +505,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if !ok {
tmpRow := &domain.FailReturnedInfo{
FailReason: "订单日期格式错误,请输入正确的订单日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -517,7 +518,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货数量格式错误,退货数量必须整数",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -526,7 +527,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if orderGoodQuantity < 0 {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货数量必须大于0,请重新填写",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -539,7 +540,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if typeErr != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货价格格式错误,退货价格必须为数字类型",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -549,7 +550,17 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if univalent >= 1e16 {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货价格超过最大限制,退货价格小数点前面不能超过十六位数字,并保留两位小数",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
}
// 正负判断
if univalent < 0 {
tmpRow := &domain.FailReturnedInfo{
FailReason: "退货价格必须大于0,请重新填写",
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[j],
}
myRow = append(myRow, tmpRow)
continue
... ... @@ -581,7 +592,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
var dividendsReturnedOrderCommands = make(map[string]*command.CreateDividendsReturnedOrderCommand)
for i, dividendsReturnedOrder := range importDividendsReturnedOrderCommand.DividendsReturnedOrderData {
hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum + dividendsReturnedOrder.OrderTime))
hashValue := md5.Sum([]byte(dividendsReturnedOrder.OriginalOrderNum + dividendsReturnedOrder.DividendsReturnedDate))
hashString := hex.EncodeToString(hashValue[:])
if _, ok := dividendsReturnedOrderCommands[hashString]; !ok {
// 订单日期时间格式转换
... ... @@ -589,7 +600,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的订单日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -600,7 +611,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的退货日期",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -611,7 +622,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品数量类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -621,7 +632,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品价格类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -656,12 +667,23 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
LineNumbers: []int{i}, // 记录行号
}
} else { // 聚合同一笔订单产品
// 订单日期时间格式转换
timeValue, err := time.ParseInLocation("2006/01/02", dividendsReturnedOrder.OrderTime, time.Local)
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "无效的订单日期",
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
// 产品相关:产品名称,退货数量、退货价格
quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品数量类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -671,7 +693,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
if err != nil {
tmpRow := &domain.FailReturnedInfo{
FailReason: "产品价格类型错误",
ImportDividendsReturnedOrderData: &dividendsReturnedOrder,
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
}
if strconv.FormatInt(timeValue.Local().UnixNano()/1e6, 10) != dividendsReturnedOrderCommands[hashString].OrderTime {
tmpRow := &domain.FailReturnedInfo{
FailReason: "同一来源单号的退货单,订单日期必须相同",
ImportDividendsReturnedOrderData: &importDividendsReturnedOrderCommand.DividendsReturnedOrderData[i],
}
aggregateErrorList = append(aggregateErrorList, tmpRow)
continue
... ... @@ -844,12 +875,14 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
contractNumberExist := false
for _, cooperationContract := range cooperationContracts {
if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber {
if cooperationContract.Status == 1 {
contractNumberExist = true
break
}
}
}
if !contractNumberExist {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "退货单产品关联的共创合约不存在"
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[j].LineNumber] = "退货单产品关联的共创合约不存在或已暂停"
continue
}
... ... @@ -1113,6 +1146,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD
}
if count, dividendsReturnedOrders, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsReturnedOrderIds": dividendsReturnedOrderIds,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -17,6 +17,9 @@ var USER_MODULE_HOST = "http://127.0.0.1:8081"
// BASIC_MODULE_HOST 基础服务模块
var BASIC_MODULE_HOST = "http://127.0.0.1:8080"
// ENABLE_HTTPS 是否开启https访问
var ENABLE_HTTPS = "false"
func init() {
if os.Getenv("LOG_TYPE") != "" {
LOG_TYPE = os.Getenv("LOG_TYPE")
... ... @@ -39,4 +42,7 @@ func init() {
if os.Getenv("BASIC_MODULE_HOST") != "" {
BASIC_MODULE_HOST = os.Getenv("BASIC_MODULE_HOST")
}
if os.Getenv("ENABLE_HTTPS") != "" {
ENABLE_HTTPS = os.Getenv("ENABLE_HTTPS")
}
}
... ...
... ... @@ -78,6 +78,7 @@ type DividendsEstimateRepository interface {
SaveMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error)
UpdateMany(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error)
Remove(dividendsEstimate *DividendsEstimate) (*DividendsEstimate, error)
BatchRemove(dividendsEstimates []*DividendsEstimate) ([]*DividendsEstimate, error)
FindOne(queryOptions map[string]interface{}) (*DividendsEstimate, error)
Find(queryOptions map[string]interface{}) (int64, []*DividendsEstimate, error)
}
... ...
... ... @@ -17,6 +17,9 @@ type DividendsEstimateDetail struct {
IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
Reason string `json:"reason"` // 错误原因
CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"` // 承接人记录ID
CooperationContractNumber string `json:"cooperationContractNumber"`
OrderGoodId int64 `json:"orderGoodId"`
OrderGoodAmount float64 `json:"orderGoodAmount"`
}
// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
... ... @@ -43,5 +46,5 @@ func (DividendsEstimateDetail *DividendsEstimateDetail) GenerateSpecificDividend
type ConfirmDividendsIncentivesEstimateService interface {
coreDomain.DomainEventPublisher
Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error)
Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract) ([]*DividendsEstimateDetail, error)
}
... ...
... ... @@ -144,6 +144,16 @@ func (dao *CooperationContractDao) SearchCooperationContractByUndertaker(queryOp
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
query = query.Where(`A.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("A.company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("A.org->>'orgId' = '?'", orgId)
}
if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
newOrgIds := utils.SliceItoa(orgIds.([]int64))
query.Where("A.org->>'orgId' in (?)", pg.In(newOrgIds))
}
query.Join("JOIN cooperation_contracts AS A ON A.cooperation_contract_number = cooperation_contract_undertaker.cooperation_contract_number")
query.Join("JOIN cooperation_modes AS B ON B.cooperation_mode_number = A.cooperation_mode_number")
query = query.Order("cooperation_contract_undertaker_id DESC")
... ...
... ... @@ -147,9 +147,9 @@ func (dao *CreditAccountDao) CooperationUsersDividendsStatistics(queryOptions ma
if v, ok := queryOptions["sortByActuallyPaidAmount"]; ok {
vInt := v.(int)
if vInt == 1 {
query.Order("divides_amount asc")
query.Order("actually_paid_amount asc")
} else {
query.Order("divides_amount desc")
query.Order("actually_paid_amount desc")
}
}
query.GroupExpr("participator->>'userId'")
... ...
... ... @@ -26,7 +26,7 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber(queryOptions ma
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
if count, err := query.AllWithDeleted().Count(); err != nil {
return "", err
} else {
if count < 1000 {
... ... @@ -68,6 +68,31 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer
return !ok, err
}
// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
query = query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok {
query.Where("is_canceled = ?", isCanceled.(bool))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
count, err := query.Count()
if count > 0 {
return true, err
} else {
return false, err
}
}
// UserEstimated 判断金额激励用户是否已分红(已生成分红预算单)
func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
... ... @@ -118,7 +143,7 @@ func (dao *DividendsEstimateDao) CountDividendsEstimate(queryOptions map[string]
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
if count, err := query.AllWithDeleted().Count(); err != nil {
return 0, err
} else {
return count, nil
... ...
... ... @@ -104,7 +104,7 @@ func (dao *DividendsOrderDao) CountDividendsOrder(queryOptions map[string]interf
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 {
if count, err := query.AllWithDeleted().Count(); err != nil {
return 0, err
} else {
return count, nil
... ...
... ... @@ -38,6 +38,28 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(query
}
}
// CheckDividendsEstimateOrderExist 判断是否存在分红预算单
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query = query.Where("dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_returned_order.org @> '{"orgId":"?"}'`, orgId)
}
count, err := query.Count()
if count > 0 {
return true, err
} else {
return false, err
}
}
// CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
... ... @@ -91,7 +113,7 @@ func (dao *DividendsReturnedOrderDao) CountDividendsReturnedOrder(queryOptions m
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 {
if count, err := query.AllWithDeleted().Count(); err != nil {
return 0, err
} else {
return count, nil
... ...
... ... @@ -32,7 +32,7 @@ func (dao *OrderGoodDao) CooperationGoodsStatistics(queryOptions map[string]inte
if v, ok := queryOptions["limit"]; ok {
queryLimit += fmt.Sprintf("limit %v \n", v)
}
sql := fmt.Sprintf(`select order_good_name good_name,sum(coalesce(order_good_amount,0)) good_amount from order_goods
sql := fmt.Sprintf(`select order_good_name good_name,sum(coalesce(case when dividends_order_number is not null then order_good_amount else -order_good_amount end,0)) good_amount from order_goods
where company_id=? and org_id = ? and deleted_at is null %v
GROUP BY order_good_name
order by good_amount desc
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type CancelDividendsEstimateService struct {
... ... @@ -20,7 +21,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
//var cooperationContactRepository domain.CooperationContractRepository // 合约仓储
type orderGoodInfo struct {
OrderGoodId int64
CompanyId int64
OrgId int64
}
// 分红预算单仓储初始化
if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
... ... @@ -50,16 +56,10 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
orderGoodRepository = repo
}
// 共创合约仓储初始化
//if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// cooperationContactRepository = repo
//}
// 获取分红预算单
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
"dividendsEstimateIds": dividendsEstimateIds,
"offsetLimit": false,
}); err != nil {
return nil, err
} else {
... ... @@ -67,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
var dividendsEstimatesCanceled []*domain.DividendsEstimate
var orderOrReturnOrderNums []string
var orderGoodIds []int64
orderGoodMaps := make(map[string][]int64, 0)
for _, dividendsEstimate := range dividendsEstimates {
if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
... ... @@ -90,7 +91,9 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
// 获取相关订单/退货单号
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
}
//dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err3 != nil {
return nil, err3
... ... @@ -117,6 +120,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
dividendsEstimatesRelative[i].IsCanceled = true
dividendsEstimatesRelative[i].Operator = operator
}
//dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.BatchRemove(dividendsEstimatesRelative)
dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
if err4 != nil {
return nil, err4
... ... @@ -154,23 +158,26 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"dividendsOrderNumbers": orderNums,
"offsetLimit": false,
}); err4 != nil {
return nil, err4
} else {
// orderGoodIds去重
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
if countDividendsOrder > 0 {
for i, order := range orders {
goods := make([]*domain.OrderGood, 0)
// 取消分红的订单产品
newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[order.DividendsOrderNumber])
var goodIds []int64
for _, good := range order.Goods {
if good.OrderGoodDividendsStatus == 2 {
goods = append(goods, good)
goodIds = append(goodIds, good.OrderGoodId)
}
}
if len(goods) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
// goodIds去重
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
log.Logger.Info("")
if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
orders[i].DividendStatus = 1
} else if len(goods) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
} else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
orders[i].DividendStatus = 3
}
orders[i].DividendStatus = order.DividendStatus
... ... @@ -193,6 +200,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
"orderGoodIds": orderGoodIds,
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -216,24 +224,25 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"dividendsReturnedOrderNumbers": returnedOrderNums,
"offsetLimit": false,
}); err5 != nil {
return nil, err5
} else {
// orderGoodIds去重
newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)
if countDividendsReturnedOrder > 0 {
for i, returnedOrder := range returnedOrders {
goods := make([]*domain.OrderGood, 0)
// 已取消的退货单产品
newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[returnedOrder.DividendsReturnedOrderNumber])
var goodIds []int64
for _, good := range returnedOrder.Goods {
if good.OrderGoodDividendsStatus == 2 {
goods = append(goods, good)
goodIds = append(goodIds, good.OrderGoodId)
}
}
if len(goods) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
// goodIds去重
newGoodIds := utils.RemoveDuplicationInt64(goodIds)
if len(newGoodIds) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
returnedOrders[i].DividendStatus = 1
} else if len(goods) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
} else if len(newGoodIds) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
returnedOrders[i].DividendStatus = 3
}
returnedOrders[i].DividendStatus = returnedOrder.DividendStatus
... ... @@ -256,6 +265,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
"orderGoodIds": orderGoodIds,
"companyId": dividendsEstimates[0].Company.CompanyId,
"orgId": dividendsEstimates[0].Org.OrgId,
"offsetLimit": false,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -8,7 +8,6 @@ import (
"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/repository"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
)
type ConfirmDividendsIncentivesEstimateService struct {
... ... @@ -17,26 +16,10 @@ type ConfirmDividendsIncentivesEstimateService struct {
}
// Confirm 确认业绩分红预算
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) ([]*service.DividendsEstimateDetail, error) {
var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储
var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储
func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood, companyId int64, orgId int64, cooperationContractsMap map[string]*domain.CooperationContract) ([]*service.DividendsEstimateDetail, error) {
var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
// 共创合约仓储初始化
if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationContractRepository = repo
}
// 共创项目仓储初始化
if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil {
return nil, err
} else {
cooperationProjectRepository = repo
}
// 分红订单仓储初始化
if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil {
return nil, err
... ... @@ -54,17 +37,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 确认业绩分红预算
var dividendsEstimateDetails []*service.DividendsEstimateDetail
for _, orderGood := range orderGoods {
log.Logger.Info("业绩分红预算产品", map[string]interface{}{
"orderGood": orderGood,
})
// 获取合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractNumber": orderGood.CooperationContractNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
if orderGood.CooperationContractNumber == "" {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
... ... @@ -78,11 +51,14 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创合约错误",
Reason: "产品未关联合约,不能进行分红预算",
})
continue
}
if cooperationContract == nil {
// 获取合约
var cooperationContract *domain.CooperationContract
if _, ok := cooperationContractsMap[orderGood.CooperationContractNumber]; !ok {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
... ... @@ -100,9 +76,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
continue
} else {
log.Logger.Info("产品相关的合约", map[string]interface{}{
"cooperationContract": cooperationContract,
})
cooperationContract = cooperationContractsMap[orderGood.CooperationContractNumber]
if cooperationContract.Status == 2 {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
... ... @@ -123,51 +97,6 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
}
// 获取共创项目
if cooperationContract.CooperationProjectNumber != "" {
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
"companyId": cooperationContract.Company.CompanyId,
"orgId": cooperationContract.Org.OrgId,
})
if err != nil {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "查询错误",
})
continue
}
if cooperationProject == nil {
var orderNumber string
if orderGood.DividendsOrderNumber != "" {
orderNumber = orderGood.DividendsOrderNumber
} else {
orderNumber = orderGood.DividendsReturnedOrderNumber
}
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderNumber,
IsSuccessfully: false,
Reason: "共创项目" + cooperationContract.CooperationProjectNumber + "已结束或不存在",
})
continue
}
}
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
... ... @@ -250,6 +179,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
// 添加推荐人分红预算信息详情
... ... @@ -277,6 +209,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
}
... ... @@ -305,6 +240,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
}
... ... @@ -350,6 +288,18 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
}
// 计算分红
if len(cooperationContract.Undertakers) <= 0 {
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
IsSuccessfully: false,
Reason: "合约承接人不存在",
})
continue
} else {
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红退货预算信息详情
if dividendsIncentivesRuleMatched.DividendsIncentivesPercentage > 0 {
... ... @@ -376,6 +326,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.DividendsIncentivesPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
... ... @@ -404,6 +357,9 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.ReferrerPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
}
... ... @@ -433,12 +389,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
IsSuccessfully: true,
CooperationContractUndertakerId: undertaker.UndertakerId,
DividendsPercentage: dividendsIncentivesRuleMatched.SalesmanPercentage,
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
})
}
}
}
}
}
}
return dividendsEstimateDetails, nil
}
... ...
... ... @@ -68,7 +68,7 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions
// 2.计算百分比
var totalAmount float64
for i := range goods {
goods[i].Rank = int32(i + 1)
goods[i].Rank = int32(i+1) + int32(request.Offset)
totalAmount += goods[i].GoodAmount
}
for i := range goods {
... ... @@ -655,8 +655,16 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query
// 按关联相关人过滤
var contractNumbers []string
var err error
var retMap = map[string]interface{}{
"xAxis": map[string]interface{}{
"data": []string{},
},
"source": map[string]interface{}{
"value": []float64{},
},
}
if request.UserBaseId > 0 {
var retMap = make([]interface{}, 0)
contractNumbers, err = ptr.getUnderTakerContracts(map[string]interface{}{"userId": request.UserId})
if len(contractNumbers) == 0 {
return retMap, nil
... ... @@ -666,7 +674,6 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query
}
queryOptions["cooperationContractNumbers"] = contractNumbers
} else if request.UserId > 0 && request.OrgId > 0 {
var retMap = make([]interface{}, 0)
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"userId": request.UserId})
if len(contractNumbers) == 0 {
return retMap, nil
... ... @@ -693,7 +700,13 @@ func (ptr *CooperationStatisticsService) PaymentHistoryHistogramStatistics(query
}
queryOptions["paymentBeginTime"] = item.BeginTime
queryOptions["paymentEndTime"] = item.EndTime
if err := creditAccountDao.DividendsStatistics(queryOptions, dividends); err != nil {
if err := creditAccountDao.DividendsStatistics(map[string]interface{}{
"orgId": request.OrgId,
"userBaseId": request.UserBaseId,
"cooperationContractNumbers": contractNumbers,
"paymentBeginTime": item.BeginTime,
"paymentEndTime": item.EndTime,
}, dividends); err != nil {
return nil, err
}
values = append(values, dividends.Paid)
... ...
... ... @@ -367,6 +367,10 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
if a.DividendsPercentage > 0 {
item["dividendsRatio"] = a.DividendsPercentage
}
// 金额激励承接人分红比例百分百,业务员 推荐人按设定的比例
if a.DividendsType == 3 && a.DividendsPercentage == 0 {
item["dividendsRatio"] = 100
}
dividends = append(dividends, item)
}
res["dividends"] = dividends
... ... @@ -424,7 +428,12 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
if err := dividendsEstimateDao.DividendsEstimateStatistics(queryOptions, allDividendsEstimate); err != nil {
return nil, err
}
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
if err := creditAccountDao.DividendsStatistics(map[string]interface{}{
"companyId": request.CompanyId,
"orgId": request.OrgId,
"userBaseId": request.UserBaseId,
"cooperationContractNumbers": contractNumbers,
}, allDividends); err != nil {
return nil, err
}
allDividendsEstimate.Paid = allDividends.Paid
... ... @@ -437,10 +446,10 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
if err := creditAccountDao.DividendsStatistics(map[string]interface{}{
"companyId": request.CompanyId,
"orgId": request.OrgId,
"userId": request.UserId,
"userBaseId": request.UserBaseId,
"paymentBeginTime": queryOptions["beginTime"],
"paymentEndTime": queryOptions["endTime"],
"cooperationContractNumbers": contractNumbers,
}, annualDividends); err != nil {
return nil, err
}
... ... @@ -453,10 +462,10 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
if err := creditAccountDao.DividendsStatistics(map[string]interface{}{
"companyId": request.CompanyId,
"orgId": request.OrgId,
"userId": request.UserId,
"userBaseId": request.UserBaseId,
"paymentBeginTime": queryOptions["beginTime"],
"paymentEndTime": queryOptions["endTime"],
"cooperationContractNumbers": contractNumbers,
}, quarterDividends); err != nil {
return nil, err
}
... ...
... ... @@ -9,7 +9,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
rawlog "log"
)
... ...
... ... @@ -15,9 +15,9 @@ func TransformToCooperationContractChangeLogDomainModelFromPgModels(cooperationC
Company: cooperationContractChangeLogModel.Company,
Org: cooperationContractChangeLogModel.Org,
Operator: cooperationContractChangeLogModel.Operator,
OperatorTime: cooperationContractChangeLogModel.OperatorTime,
OperatorTime: cooperationContractChangeLogModel.OperatorTime.Local(),
UpdatedAt: cooperationContractChangeLogModel.UpdatedAt,
DeletedAt: cooperationContractChangeLogModel.DeletedAt,
CreatedAt: cooperationContractChangeLogModel.CreatedAt,
CreatedAt: cooperationContractChangeLogModel.CreatedAt.Local(),
}, nil
}
... ...
... ... @@ -164,9 +164,11 @@ func (repository *CooperationApplicationRepository) UpdateMany(cooperationApplic
UpdatedAt: time.Now(),
})
}
if len(cooperationApplicationModels) > 0 {
if _, err := tx.Model(&cooperationApplicationModels).WherePK().Update(); err != nil {
return nil, err
}
}
return cooperationApplications, nil
}
... ...
... ... @@ -51,7 +51,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "cooperationContract_id")
updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields)
tx := repository.transactionContext.PgTx
if cooperationContract.Identify() == nil {
if cooperationContract.Identify() == nil { // 新增合约
cooperationContractId, err := repository.nextIdentify()
if err != nil {
return cooperationContract, err
... ... @@ -256,7 +256,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
return nil, err
}
}
} else {
} else { // 编辑合约
if _, err := tx.QueryOne(
pg.Scan(
&cooperationContract.CooperationContractId,
... ... @@ -823,13 +823,6 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
}
}
}
// 返回新增的合约
//cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
// "cooperationContractId": cooperationContract.CooperationContractId,
//})
//if err != nil {
// return nil, err
//}
return cooperationContract, nil
}
... ... @@ -1111,7 +1104,8 @@ func (repository *CooperationContractRepository) FindOne(queryOptions map[string
if err := cooperationContractUndertakerQuery.
Where("company->>'companyId' = '?'", cooperationContractModel.Company.CompanyId).
Where("org->>'orgId' = '?'", cooperationContractModel.Org.OrgId).
Where("cooperation_contract_id = ?", cooperationContractModel.CooperationContractId).
//Where("cooperation_contract_id = ?", cooperationContractModel.CooperationContractId).
Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber).
Select(); err != nil {
return nil, fmt.Errorf("合约承接人不存在")
}
... ... @@ -1149,6 +1143,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if cooperationContractName, ok := queryOptions["cooperationContractName"]; ok && cooperationContractName != "" {
query.Where("cooperation_contract_name like ?", fmt.Sprintf("%%%s%%", cooperationContractName))
}
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query.Where("cooperation_project_number = ?", cooperationProjectNumber)
}
if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
query.Where(`(cooperation_contract.department->>'departmentName')::text LIKE ?`, fmt.Sprintf("%%%s%%", departmentName))
}
... ...
... ... @@ -276,7 +276,9 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
return q, nil
})
}
if searchCooperationProjectExtQueriesFlag, ok := queryOptions["searchCooperationProjectExtQueriesFlag"]; ok && searchCooperationProjectExtQueriesFlag.(int) != 0 {
if searchCooperationProjectExtQueries, ok := queryOptions["searchCooperationProjectExtQueries"]; ok && len(searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery)) > 0 {
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
for _, searchCooperationProjectExtQuery := range searchCooperationProjectExtQueries.([]*query2.SearchCooperationProjectExtQuery) {
query.WhereOrGroup(func(q *orm.Query) (*orm.Query, error) {
if searchCooperationProjectExtQuery.ExtCompanyId != 0 {
... ... @@ -300,6 +302,12 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
return q, nil
})
}
query.WhereOr(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, 3) //公开
return q, nil
})
} else {
query.Where(`cooperation_project.cooperation_project_undertaker_types @> '{?}'`, 3) //公开
}
}
if departmentName, ok := queryOptions["departmentName"]; ok && departmentName != "" {
query.Where("department->>'departmentName' like ? ", fmt.Sprintf("%%%s%%", departmentName))
... ...
... ... @@ -223,15 +223,16 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
return nil, err
}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
}
}
return dividendsEstimatesSaved, nil
//var dividendsEstimatesSaved []*domain.DividendsEstimate
//for _, dividendsEstimateModel := range dividendsEstimateModels {
// if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
// return dividendsEstimates, err
// } else {
// dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
// }
//}
//return dividendsEstimatesSaved, nil
return dividendsEstimates, nil
}
return nil, nil
}
... ... @@ -270,15 +271,16 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Update(); err != nil {
return nil, err
}
var dividendsEstimatesUpdated []*domain.DividendsEstimate
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesUpdated = append(dividendsEstimatesUpdated, dividendsEstimate)
}
}
return dividendsEstimatesUpdated, nil
//var dividendsEstimatesUpdated []*domain.DividendsEstimate
//for _, dividendsEstimateModel := range dividendsEstimateModels {
// if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
// return dividendsEstimates, err
// } else {
// dividendsEstimatesUpdated = append(dividendsEstimatesUpdated, dividendsEstimate)
// }
//}
//return dividendsEstimatesUpdated, nil
return dividendsEstimates, nil
}
func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.DividendsEstimate) (*domain.DividendsEstimate, error) {
... ... @@ -291,6 +293,21 @@ func (repository *DividendsEstimateRepository) Remove(dividendsEstimate *domain.
return dividendsEstimate, nil
}
func (repository *DividendsEstimateRepository) BatchRemove(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
for _, dividendsEstimate := range dividendsEstimates {
dividendsEstimateModels = append(dividendsEstimateModels, &models.DividendsEstimate{
DividendsEstimateId: dividendsEstimate.Identify().(int64),
})
}
if _, err := tx.Model(&dividendsEstimateModels).WherePK().Delete(); err != nil {
return dividendsEstimates, err
} else {
return dividendsEstimates, nil
}
}
func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]interface{}) (*domain.DividendsEstimate, error) {
tx := repository.transactionContext.PgTx
dividendsEstimateModel := new(models.DividendsEstimate)
... ... @@ -299,6 +316,9 @@ func (repository *DividendsEstimateRepository) FindOne(queryOptions map[string]i
if orderOrReturnedOrderNum, ok := queryOptions["orderOrReturnedOrderNum"]; ok && orderOrReturnedOrderNum != "" {
query.Where("order_or_returned_order_num = ?", orderOrReturnedOrderNum)
}
if isCanceled, ok := queryOptions["isCanceled"]; ok {
query.Where("is_canceled = ?", isCanceled.(bool))
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("分红预算单不存在")
... ...
... ... @@ -490,15 +490,6 @@ func (repository *DividendsOrderRepository) BatchRemove(dividendsOrders []*domai
} else {
for _, dividendsOrder := range dividendsOrders {
// 删除订单产品
//var orderGoodModels []*models.OrderGood
//if _, err := tx.Model(&orderGoodModels).
// Where("company_id = ?", dividendsOrder.Company.CompanyId).
// Where("org_id = ?", dividendsOrder.Org.OrgId).
// Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).WherePK().Delete(); err != nil {
// return nil, err
//}
// 删除订单产品
var orderGoodModels []*models.OrderGood
orderGoodQuery := tx.Model(&orderGoodModels)
if err := orderGoodQuery.
... ...
... ... @@ -30,6 +30,26 @@ func Intersect(nums1 []int64, nums2 []int64) []int64 {
return intersection
}
// Intersect32 返回两个数组的交集
func Intersect32(nums1 []int32, nums2 []int32) []int32 {
if len(nums1) > len(nums2) {
return Intersect32(nums2, nums1)
}
m := map[int32]int32{}
for _, num := range nums1 {
m[num]++
}
var intersection []int32
for _, num := range nums2 {
if m[num] > 0 {
intersection = append(intersection, num)
m[num]--
}
}
return intersection
}
// Difference 求差集 slice1-并集
func Difference(slice1, slice2 []int64) []int64 {
m := make(map[int64]int)
... ... @@ -144,6 +164,36 @@ func RemoveDuplicationInt64(arr []int64) []int64 {
return arr[:j]
}
func RemoveDuplicationString(arr []string) []string {
set := make(map[string]struct{}, len(arr))
j := 0
for _, v := range arr {
_, ok := set[v]
if ok {
continue
}
set[v] = struct{}{}
arr[j] = v
j++
}
return arr[:j]
}
func RemoveDuplicationInt32(arr []int32) []int32 {
set := make(map[int32]struct{}, len(arr))
j := 0
for _, v := range arr {
_, ok := set[v]
if ok {
continue
}
set[v] = struct{}{}
arr[j] = v
j++
}
return arr[:j]
}
// IsContain 判断int32数组是否包含
func IsContain(items []int32, item int32) bool {
for _, eachItem := range items {
... ...
... ... @@ -50,7 +50,8 @@ func (logger *BeegoLog) Debug(msg string, appends ...map[string]interface{}) {
logs.Debug(msg, make(map[string]interface{}, 0))
} else {
var out bytes.Buffer
err := json.Indent(&out, appendsJson, "", " ")
//err := json.Indent(&out, appendsJson, "", " ")
err := json.Compact(&out, appendsJson)
if err != nil {
fmt.Println(msg)
return
... ... @@ -65,7 +66,8 @@ func (logger *BeegoLog) Info(msg string, appends ...map[string]interface{}) {
logs.Info(msg, make(map[string]interface{}, 0))
} else {
var out bytes.Buffer
err := json.Indent(&out, appendsJson, "", " ")
//err := json.Indent(&out, appendsJson, "", " ")
err := json.Compact(&out, appendsJson)
if err != nil {
fmt.Println(msg)
return
... ...
... ... @@ -32,7 +32,16 @@ func init() {
}
}
//https支持
if os.Getenv("ENABLE_HTTPS") != "" {
enableHTTPS := os.Getenv("ENABLE_HTTPS")
if enableHTTPS == "true" {
web.BConfig.Listen.EnableHTTPS = true
} else {
web.BConfig.Listen.EnableHTTPS = false
}
} else {
web.BConfig.Listen.EnableHTTPS = false
}
web.BConfig.Listen.HTTPSPort = 443
web.BConfig.Listen.HTTPSCertFile = "./config/fjmaimaimai.com_bundle.crt"
web.BConfig.Listen.HTTPSKeyFile = "./config/fjmaimaimai.com.key"
... ...
... ... @@ -55,14 +55,18 @@ func (controller *CooperationProjectController) GetCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
getCooperationProjectQuery := &query.GetCooperationProjectQuery{}
header := controller.GetRequestHeader(controller.Ctx)
getCooperationProjectQuery.CompanyId = header.CompanyId
getCooperationProjectQuery.OrgId = header.OrgId
//getCooperationProjectQuery.CompanyId = header.CompanyId
//getCooperationProjectQuery.OrgId = header.OrgId
getCooperationProjectQuery.UserId = header.UserId
getCooperationProjectQuery.UserBaseId = header.UserBaseId
cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
getCooperationProjectQuery.CooperationProjectId = cooperationProjectId
cooperationProjectNumber := controller.GetString("cooperationProjectNumber")
getCooperationProjectQuery.CooperationProjectNumber = cooperationProjectNumber
companyId, _ := controller.GetInt64("companyId")
getCooperationProjectQuery.CompanyId = companyId
orgId, _ := controller.GetInt64("orgId")
getCooperationProjectQuery.OrgId = orgId
data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
controller.Response(data, err)
}
... ...
... ... @@ -55,14 +55,18 @@ func (controller *DividendsOrderController) GetDividendsOrder() {
dividendsOrderService := service.NewDividendsOrderService(nil)
getDividendsOrderQuery := &query.GetDividendsOrderQuery{}
header := controller.GetRequestHeader(controller.Ctx)
getDividendsOrderQuery.CompanyId = header.CompanyId
getDividendsOrderQuery.OrgId = header.OrgId
//getDividendsOrderQuery.CompanyId = header.CompanyId
//getDividendsOrderQuery.OrgId = header.OrgId
getDividendsOrderQuery.UserId = header.UserId
getDividendsOrderQuery.UserBaseId = header.UserBaseId
dividendsOrderId, _ := controller.GetInt64(":dividendsOrderId")
getDividendsOrderQuery.DividendsOrderId = dividendsOrderId
dividendsOrderNumber := controller.GetString("dividendsOrderNumber")
getDividendsOrderQuery.DividendsOrderNumber = dividendsOrderNumber
companyId, _ := controller.GetInt64("companyId")
getDividendsOrderQuery.CompanyId = companyId
orgId, _ := controller.GetInt64("orgId")
getDividendsOrderQuery.OrgId = orgId
data, err := dividendsOrderService.GetDividendsOrder(getDividendsOrderQuery)
controller.Response(data, err)
}
... ...