作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
)
type CancelCooperationApplicationCommand struct {
// 共创申请ID
CooperationApplicationId int64 `cname:"共创申请ID" json:"cooperationApplicationId,string" valid:"Required"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId,string" valid:"Required"`
// 组织机构id
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 菜单编码,APP端必须
Code string `cname:"菜单编码" json:"code" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
func (cancelCooperationApplicationCommand *CancelCooperationApplicationCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (cancelCooperationApplicationCommand *CancelCooperationApplicationCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(cancelCooperationApplicationCommand)
if err != nil {
return err
}
if !b {
elem := reflect.TypeOf(cancelCooperationApplicationCommand).Elem()
for _, validErr := range valid.Errors {
field, isExist := elem.FieldByName(validErr.Field)
if isExist {
return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
} else {
return fmt.Errorf(validErr.Message)
}
}
}
return nil
}
... ...
... ... @@ -424,10 +424,27 @@ func (cooperationApplicationService *CooperationApplicationService) SearchCooper
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(searchCooperationApplicationQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"grid": map[string]interface{}{
"total": count,
"list": cooperationApplications,
},
}, nil
}
return nil, nil
}
// UpdateCooperationApplication 更新共创申请服务
... ... @@ -473,6 +490,53 @@ func (cooperationApplicationService *CooperationApplicationService) UpdateCooper
}
}
// CancelCooperationApplication 取消共创申请
func (cooperationApplicationService *CooperationApplicationService) CancelCooperationApplication(cancelCooperationApplicationCommand *command.CancelCooperationApplicationCommand) (interface{}, error) {
if err := cancelCooperationApplicationCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//TODO 校验用户菜单模块权限
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
}
cooperationApplication, err := cooperationApplicationRepository.FindOne(map[string]interface{}{"cooperationApplicationId": cancelCooperationApplicationCommand.CooperationApplicationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationApplication == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cancelCooperationApplicationCommand.CooperationApplicationId, 10)))
}
if err := cooperationApplication.Update(map[string]interface{}{
"isCanceled": true,
}); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationApplication, nil
}
}
func NewCooperationApplicationService(options map[string]interface{}) *CooperationApplicationService {
newCooperationApplicationService := &CooperationApplicationService{}
return newCooperationApplicationService
... ...
... ... @@ -13,9 +13,7 @@ type UpdateCooperationContractCommand struct {
CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
// 共创合约编号
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber" valid:"Required"`
// 共创项目编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`
// 部门编码
DepartmentId string `cname:"部门ID" json:"departmentId" valid:"Required"`
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CooperationContractDto struct {
*domain.CooperationContract
// 可以去除勾选的共创项目承接对象列表
UndertakerTypesUncheckedAvailable []int32 `json:"undertakerTypesUncheckedAvailable"`
}
func (dto *CooperationContractDto) LoadDto(contract *domain.CooperationContract, undertakerTypesUncheckedAvailable []int32) error {
dto.CooperationContract = contract
dto.UndertakerTypesUncheckedAvailable = undertakerTypesUncheckedAvailable
return nil
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
... ... @@ -319,10 +320,31 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(getCooperationContractQuery.CooperationContractId, 10)))
} else {
// 共创合约DAO初始化
var cooperationContractDao *dao.CooperationContractDao
if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationContractDao = value
}
//TODO 获取可删除的承接对象类型
undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationContractNumber": cooperationContract.CooperationContractNumber,
"cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
cooperationContractDto := &dto.CooperationContractDto{}
if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationContract, nil
return cooperationContractDto, nil
}
}
... ...
... ... @@ -16,7 +16,7 @@ type UpdateCooperationProjectCommand struct {
// 共创模式编码
CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber" valid:"Required"`
// 承接对象,1员工,2共创用户,3公开,可以多选
CooperationProjectUndertakerType []int32 `cname:"承接对象" json:"cooperationProjectUndertakerType" valid:"Required"`
CooperationProjectUndertakerTypes []int32 `cname:"承接对象" json:"cooperationProjectUndertakerTypes" valid:"Required"`
// 共创项目发起人uid
SponsorUid string `cname:"共创项目发起人UID" json:"sponsorUid" valid:"Required"`
// 共创项目发布人uid
... ...
... ... @@ -237,7 +237,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
} else {
cooperationProjectDao = value
}
//TODO 获取可删除的承接对象类型
// 获取可删除的承接对象类型
undertakerTypesUncheckedAvailable, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
"cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
"cooperationProjectUndertakerTypes": cooperationProject.CooperationProjectUndertakerTypes,
... ... @@ -252,7 +252,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationProject, nil
return cooperationProjectDto, nil
}
}
... ...
... ... @@ -53,17 +53,8 @@ func (cooperationApplication *CooperationApplication) Identify() interface{} {
}
func (cooperationApplication *CooperationApplication) Update(data map[string]interface{}) error {
if userId, ok := data["userId"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserId = userId.(int64)
}
if userBaseId, ok := data["userBaseId"]; ok {
cooperationApplication.CooperationApplicationApplicant.UserBaseId = userBaseId.(int64)
}
if orgs, ok := data["orgs"]; ok {
cooperationApplication.CooperationApplicationApplicant.Orgs = orgs.([]*Org)
}
if status, ok := data["status"]; ok {
cooperationApplication.CooperationApplicationApplicant.Status = status.(int32)
if isCanceled, ok := data["isCanceled"]; ok {
cooperationApplication.IsCanceled = isCanceled.(bool)
}
if cooperationApplicationAttachment, ok := data["cooperationApplicationAttachment"]; ok {
cooperationApplication.CooperationApplicationAttachment = cooperationApplicationAttachment.([]*Attachment)
... ...
... ... @@ -71,90 +71,9 @@ func (cooperationProject *CooperationProject) Update(data map[string]interface{}
if cooperationProjectPublishTime, ok := data["cooperationProjectPublishTime"]; ok {
cooperationProject.CooperationProjectPublishTime = cooperationProjectPublishTime.(time.Time)
}
//if userId, ok := data["userId"]; ok {
// cooperationProject.CooperationProjectPublisher.UserId = userId.(int64)
//}
//if userBaseId, ok := data["userBaseId"]; ok {
// cooperationProject.CooperationProjectPublisher.UserBaseId = userBaseId.(int64)
//}
//if orgId, ok := data["orgId"]; ok {
// cooperationProject.CooperationProjectPublisher.Org.OrgId = orgId.(int64)
//}
//if orgName, ok := data["orgName"]; ok {
// cooperationProject.CooperationProjectPublisher.Org.OrgName = orgName.(string)
//}
//if companyId, ok := data["companyId"]; ok {
// cooperationProject.CooperationProjectPublisher.Org.Company.CompanyId = companyId.(int64)
//}
//if companyLogo, ok := data["companyLogo"]; ok {
// cooperationProject.CooperationProjectPublisher.Org.Company.CompanyLogo = companyLogo.(string)
//}
//if companyName, ok := data["companyName"]; ok {
// cooperationProject.CooperationProjectPublisher.Org.Company.CompanyName = companyName.(string)
//}
//if orgs, ok := data["orgs"]; ok {
// cooperationProject.CooperationProjectPublisher.Orgs = orgs.([]*Org)
//}
//if departmentId, ok := data["departmentId"]; ok {
// cooperationProject.CooperationProjectPublisher.Department.DepartmentId = departmentId.(int64)
//}
//if departmentName, ok := data["departmentName"]; ok {
// cooperationProject.CooperationProjectPublisher.Department.DepartmentName = departmentName.(string)
//}
//if departmentNumber, ok := data["departmentNumber"]; ok {
// cooperationProject.CooperationProjectPublisher.Department.DepartmentNumber = departmentNumber.(string)
//}
//if isOrganization, ok := data["isOrganization"]; ok {
// cooperationProject.CooperationProjectPublisher.Department.IsOrganization = isOrganization.(bool)
//}
//if userAvatar, ok := data["userAvatar"]; ok {
// cooperationProject.CooperationProjectPublisher.UserInfo.UserAvatar = userAvatar.(string)
//}
//if userEmail, ok := data["userEmail"]; ok {
// cooperationProject.CooperationProjectPublisher.UserInfo.UserEmail = userEmail.(string)
//}
//if userName, ok := data["userName"]; ok {
// cooperationProject.CooperationProjectPublisher.UserInfo.UserName = userName.(string)
//}
//if userPhone, ok := data["userPhone"]; ok {
// cooperationProject.CooperationProjectPublisher.UserInfo.UserPhone = userPhone.(string)
//}
//if userAccount, ok := data["userAccount"]; ok {
// cooperationProject.CooperationProjectPublisher.UserInfo.UserAccount = userAccount.(string)
//}
//if userType, ok := data["userType"]; ok {
// cooperationProject.CooperationProjectPublisher.UserType = userType.(int32)
//}
//if status, ok := data["status"]; ok {
// cooperationProject.CooperationProjectPublisher.Status = status.(int32)
//}
//if companyId, ok := data["companyId"]; ok {
// cooperationProject.CooperationProjectPublisher.Company.CompanyId = companyId.(int64)
//}
//if companyLogo, ok := data["companyLogo"]; ok {
// cooperationProject.CooperationProjectPublisher.Company.CompanyLogo = companyLogo.(string)
//}
//if companyName, ok := data["companyName"]; ok {
// cooperationProject.CooperationProjectPublisher.Company.CompanyName = companyName.(string)
//}
//if userId, ok := data["userId"]; ok {
// cooperationProject.CooperationProjectSponsor.UserId = userId.(int64)
//}
//if userBaseId, ok := data["userBaseId"]; ok {
// cooperationProject.CooperationProjectSponsor.UserBaseId = userBaseId.(int64)
//}
//if orgId, ok := data["orgId"]; ok {
// cooperationProject.CooperationProjectSponsor.Org.OrgId = orgId.(int64)
//}
//if orgName, ok := data["orgName"]; ok {
// cooperationProject.CooperationProjectSponsor.Org.OrgName = orgName.(string)
//}
//if companyId, ok := data["companyId"]; ok {
// cooperationProject.CooperationProjectSponsor.Company.CompanyId = companyId.(int64)
//}
//if cooperationProjectUndertakerType, ok := data["cooperationProjectUndertakerType"]; ok {
// cooperationProject.CooperationProjectUndertakerTypes = cooperationProjectUndertakerType.([]int32)
//}
if cooperationProjectUndertakerTypes, ok := data["cooperationProjectUndertakerTypes"]; ok {
cooperationProject.CooperationProjectUndertakerTypes = cooperationProjectUndertakerTypes.([]int32)
}
if operateTime, ok := data["operateTime"]; ok {
cooperationProject.OperateTime = operateTime.(time.Time)
}
... ...
... ... @@ -35,6 +35,12 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
}
}
// CheckUndertakerTypesUncheckedAvailable TODO 校验合约承接对象是否可以删除
func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {
return []int32{}, nil
}
// CheckContractNumberAvailable 检验合约编号唯一性
func (dao *CooperationContractDao) CheckContractNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
... ...
... ... @@ -37,6 +37,7 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
// CheckUndertakerTypesUncheckedAvailable TODO 校验项目承接对象是否可以删除
func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {
return []int32{}, nil
}
... ...
... ... @@ -181,6 +181,21 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string
var cooperationApplicationModels []*models.CooperationApplication
cooperationApplications := make([]*domain.CooperationApplication, 0)
query := sqlbuilder.BuildQuery(tx.Model(&cooperationApplicationModels), queryOptions)
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query.Where("cooperation_project_number like ?", fmt.Sprintf("%%%s%%", cooperationProjectNumber))
}
//TODO 共创项目名称查询
if cooperationProjectName, ok := queryOptions["cooperationProjectName"]; ok && cooperationProjectName != "" {
query.Join("LEFT JOIN cooperation_projects AS a").
JoinOn("a.cooperation_project_number = cooperation_application.cooperation_project_number").
Where("a.cooperation_project_name like ?", fmt.Sprintf("%%%s%%", cooperationProjectName))
}
if applicantName, ok := queryOptions["applicantName"]; ok && applicantName != "" {
query.Where(`(cooperation_application.cooperation_application_applicant->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", applicantName))
}
if cooperationApplicationStatus, ok := queryOptions["cooperationApplicationStatus"]; ok && cooperationApplicationStatus.(int32) != 0 {
}
query.SetOffsetAndLimit(20)
query.SetOrderDirect("cooperation_application_id", "DESC")
if count, err := query.SelectAndCount(); err != nil {
... ...
... ... @@ -166,6 +166,7 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
if _, err := tx.Model(&dividendsIncentivesRulesModel).Insert(); err != nil {
return nil, err
}
// 新增金额激励规则
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
... ... @@ -685,7 +686,6 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
query.Where("cooperation_contract_number like ?", fmt.Sprintf("%%%s%%", cooperationContractNumber))
}
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
//query.Where(`cooperation_contract.cooperation_contract_sponsor->'userName' LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
query.Where(`(cooperation_contract.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
}
query.SetOffsetAndLimit(20)
... ...
... ... @@ -170,6 +170,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
tx := repository.transactionContext.PgTx
cooperationProjectModel := new(models.CooperationProject)
query := sqlbuilder.BuildQuery(tx.Model(cooperationProjectModel), queryOptions)
if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" {
query.Where("cooperation_project_number = ?", cooperationProjectNumber)
}
query.SetWhereByQueryOption("cooperation_project.cooperation_project_id = ?", "cooperationProjectId")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
... ...
... ... @@ -25,14 +25,27 @@ func (controller *CooperationApplicationController) ApplyForCooperation() {
func (controller *CooperationApplicationController) ApprovalCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
agreeCooperationApplicationCommand := &command.ApprovalCooperationApplicationCommand{}
_ = controller.Unmarshal(agreeCooperationApplicationCommand)
approvalCooperationApplicationCommand := &command.ApprovalCooperationApplicationCommand{}
_ = controller.Unmarshal(approvalCooperationApplicationCommand)
header := controller.GetRequestHeader(controller.Ctx)
agreeCooperationApplicationCommand.CompanyId = header.CompanyId
agreeCooperationApplicationCommand.OrgId = header.OrgId
agreeCooperationApplicationCommand.UserId = header.UserId
agreeCooperationApplicationCommand.UserBaseId = header.UserBaseId
data, err := cooperationApplicationService.ApprovalCooperationApplication(agreeCooperationApplicationCommand)
approvalCooperationApplicationCommand.CompanyId = header.CompanyId
approvalCooperationApplicationCommand.OrgId = header.OrgId
approvalCooperationApplicationCommand.UserId = header.UserId
approvalCooperationApplicationCommand.UserBaseId = header.UserBaseId
data, err := cooperationApplicationService.ApprovalCooperationApplication(approvalCooperationApplicationCommand)
controller.Response(data, err)
}
func (controller *CooperationApplicationController) CancelCooperationApplication() {
cooperationApplicationService := service.NewCooperationApplicationService(nil)
cancelCooperationApplicationCommand := &command.CancelCooperationApplicationCommand{}
_ = controller.Unmarshal(cancelCooperationApplicationCommand)
header := controller.GetRequestHeader(controller.Ctx)
cancelCooperationApplicationCommand.CompanyId = header.CompanyId
cancelCooperationApplicationCommand.OrgId = header.OrgId
cancelCooperationApplicationCommand.UserId = header.UserId
cancelCooperationApplicationCommand.UserBaseId = header.UserBaseId
data, err := cooperationApplicationService.CancelCooperationApplication(cancelCooperationApplicationCommand)
controller.Response(data, err)
}
... ...
... ... @@ -6,7 +6,8 @@ import (
)
func init() {
web.Router("/cooperation-applications/apply-for-cooperation", &controllers.CooperationApplicationController{}, "Post:ApplyForCooperation") // 申请共创
web.Router("/cooperation-applications/apply-for-cooperation", &controllers.CooperationApplicationController{}, "Post:ApplyForCooperation") // 申请共创
web.Router("/cooperation-applications/cancel-application", &controllers.CooperationApplicationController{}, "Post:CancelCooperationApplication")
web.Router("/cooperation-applications/agree-cooperation-application", &controllers.CooperationApplicationController{}, "Post:ApprovalCooperationApplication") // 同意共创申请
web.Router("/cooperation-applications/batch-approval", &controllers.CooperationContractController{}, "Post:BatchApprovalCooperationApplication") // 一键审核
web.Router("/cooperation-applications/", &controllers.CooperationApplicationController{}, "Post:CreateCooperationApplication") // 新增共创申请
... ...