作者 陈志颖

feat:增加合约查询

package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
type CooperationContractByUndertakerDto struct {
// 承接人ID
UndertakerId int64 `json:"undertakerId,string"`
// 承接人编号
UndertakerCode string `json:"undertakerCode"`
// 承接人姓名
UndertakerName string `json:"undertakerName"`
// 承接人电话
UndertakerPhone string `json:"undertakerPhone"`
// 项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 项目合约名称
CooperationContractName string `json:"cooperationContractName"`
// 合同附件
Attachment []*domain.Attachment
// 发起人姓名
SponsorName string `json:"sponsorName"`
// 发起部门名称
DepartmentName string `json:"departmentName"`
// 共创模式名称
CooperationModeName string `json:"cooperationModeName"`
// 组织机构名称
OrgName string `json:"orgName"`
}
func (dto *CooperationContractByUndertakerDto) LoadDto(contract *domain.CooperationContract) error {
func (dto *CooperationContractByUndertakerDto) LoadDto(contractByUndertaker *models.CooperationContractByUndertaker) error {
dto.UndertakerId = contractByUndertaker.CooperationContractUndertakerId
dto.UndertakerCode = contractByUndertaker.UndertakerCode
dto.UndertakerName = contractByUndertaker.UndertakerName
dto.UndertakerPhone = contractByUndertaker.UndertakerPhone
dto.CooperationContractNumber = contractByUndertaker.CooperationContractNumber
dto.CooperationContractName = contractByUndertaker.CooperationContractName
dto.Attachment = contractByUndertaker.ContractAttachment
dto.SponsorName = contractByUndertaker.CooperationContractSponsor.UserName
if contractByUndertaker.Department != nil {
dto.DepartmentName = contractByUndertaker.Department.DepartmentName
}
dto.CooperationModeName = contractByUndertaker.CooperationModeName
if contractByUndertaker.Org != nil {
dto.OrgName = contractByUndertaker.Org.OrgName
}
return nil
}
... ...
... ... @@ -9,10 +9,6 @@ import (
)
type SearchCooperationContractByUndertakerQuery struct {
// 页面大小
PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
// 共创合约名称
CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName,omitempty"`
// 项目发起人姓名
... ... @@ -27,6 +23,10 @@ type SearchCooperationContractByUndertakerQuery struct {
UserId int64 `cname:"用户ID" json:"userId"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId"`
// 页面大小
PageNumber int64 `cname:"页码" json:"pageNumber,omitempty"`
// 页面大小
PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
}
func (searchCooperationContractByUndertakerQuery *SearchCooperationContractByUndertakerQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -794,7 +794,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
}
}
// SearchCooperationContractByUndertaker TODO 根据承接人返回共创项目合约
// SearchCooperationContractByUndertaker 根据承接人返回共创项目合约
func (cooperationContractService *CooperationContractService) SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery *query.SearchCooperationContractByUndertakerQuery) (interface{}, error) {
if err := searchCooperationContractByUndertakerQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -809,10 +809,39 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
defer func() {
_ = transactionContext.RollbackTransaction()
}()
if err := transactionContext.CommitTransaction(); err != nil {
// 共创合约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
}
// 查询共创项目合约
if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var cooperationContractByUndertakerDtos []*dto.CooperationContractByUndertakerDto
for _, cooperationContractByUndertaker := range cooperationContractByUndertakers {
cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{}
if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cooperationContractByUndertakerDtos = append(cooperationContractByUndertakerDtos, cooperationContractByUndertakerDto)
}
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": cooperationContractByUndertakerDtos,
},
}, nil
}
return nil, nil
}
// UpdateCooperationContract 更新共创合约服务
... ...
... ... @@ -8,6 +8,34 @@ import (
"time"
)
type (
ImportDividendsReturnedOrderData struct {
//退货客户名称
DividendsReturnedCustomerName string `json:"dividendsReturnedCustomerName"`
//来源单号,源单号,订单号
OriginalOrderNum string `json:"originalOrderNum"`
//订单产品名称
OrderGoodName string `json:"orderGoodName"`
//退货日期
DividendsReturnedDate time.Time `json:"dividendsReturnedDate"`
//退货区域名称
RegionName string `json:"regionName"`
//订单产品单价
OrderGoodPrice float64 `json:"orderGoodPrice"`
//订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity"`
//合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
//订单日期
OrderTime string `json:"orderTime"`
}
// ReqImportDividendsReturnedOrder 请求参数
ReqImportDividendsReturnedOrder struct {
// 分红退货单数据
DividendsReturnedOrderData []ImportDividendsReturnedOrderData `json:"dividendsReturnedOrderData"` //分红退货单数据列表
}
)
// DividendsReturnedOrderData 分红退货单数据
type DividendsReturnedOrderData struct {
// 退货金额
... ...
... ... @@ -77,6 +77,57 @@ func (dao *CooperationContractDao) CheckContractNumberAvailable(queryOptions map
return !ok, err
}
// SearchCooperationContractByUndertaker 查询共创合约并根据承接人返回
func (dao *CooperationContractDao) SearchCooperationContractByUndertaker(queryOptions map[string]interface{}) (int, []*models.CooperationContractByUndertaker, error) {
tx := dao.transactionContext.PgTx
var cooperationContractByUndertakerModels []*models.CooperationContractByUndertaker
var cooperationUndertakerModels []*models.CooperationContractUndertaker
query := tx.Model(&cooperationUndertakerModels)
query.ColumnExpr("cooperation_contract_undertaker.cooperation_contract_undertaker_id")
query.ColumnExpr("cooperation_contract_undertaker.user_info->>'userCode' AS undertaker_code")
query.ColumnExpr("cooperation_contract_undertaker.user_info->>'userName' AS undertaker_name")
query.ColumnExpr("cooperation_contract_undertaker.user_info->>'userPhone' AS undertaker_phone")
query.ColumnExpr("cooperation_contract_undertaker.contract_attachment")
query.ColumnExpr("A.cooperation_contract_sponsor")
query.ColumnExpr("A.cooperation_contract_number")
query.ColumnExpr("A.cooperation_contract_name")
query.ColumnExpr("A.cooperation_contract_description")
query.ColumnExpr("A.department")
query.ColumnExpr("A.org")
query.ColumnExpr("A.status AS contract_status")
query.ColumnExpr("B.cooperation_mode_name")
if cooperationContractName, ok := queryOptions["cooperationContractName"]; ok && cooperationContractName != "" {
query = query.Where("A.cooperation_contract_name ilike ?", fmt.Sprintf("%%%s%%", cooperationContractName))
}
if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
query = query.Where(`A.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
}
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")
if offset, ok := queryOptions["offset"]; ok && offset.(int64) != 0 {
offset := offset.(int64)
if offset > -1 {
query = query.Offset(int(offset))
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok && limit.(int64) != 0 {
limit := limit.(int64)
if limit > -1 {
query = query.Limit(int(limit))
}
} else {
query = query.Limit(20)
}
if count, err := query.SelectAndCount(&cooperationContractByUndertakerModels); err != nil {
return 0, nil, err
} else {
return count, cooperationContractByUndertakerModels, nil
}
}
func NewCooperationContractDao(transactionContext *pgTransaction.TransactionContext) (*CooperationContractDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
package models
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
type CooperationContractByUndertaker struct {
// 共创合约承接人ID
CooperationContractUndertakerId int64 `comment:"共创合约承接人ID"`
// 承接人编号
UndertakerCode string `comment:"承接人编号"`
// 承接人姓名
UndertakerName string `comment:"承接人姓名"`
// 承接人电话
UndertakerPhone string `comment:"承接人电话"`
// 共创合约附件
ContractAttachment []*domain.Attachment `comment:"共创合约附件"`
// 共创合约发起人
CooperationContractSponsor *domain.User `comment:"共创合约发起人"`
// 共创合约编号
CooperationContractNumber string `comment:"共创合约编号"`
// 共创合约名称
CooperationContractName string `comment:"共创合约名称"`
// 共创合约描述
CooperationContractDescription string `comment:"共创合约描述"`
// 共创合约发起部门
Department *domain.Department `comment:"共创合约发起部门"`
// 组织机构
Org *domain.Org `comment:"组织机构"`
// 共创合约状态
ContractStatus int32 `comment:"共创合约状态"`
// 共创模式名称
CooperationModeName string `comment:"共创合约名称"`
}
... ...
... ... @@ -18,37 +18,37 @@ func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId
return map[string]interface{}{}, err
} else {
switch aRoleName {
case "Relevant":
case "Relevant": // 相关人
relevant, err := userTranslator.ToRelevantFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return relevant, nil
case "Referrer":
case "Referrer": // 推荐人
referrer, err := userTranslator.ToReferrerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return referrer, nil
case "Salesman":
case "Salesman": // 业务员
salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return salesman, nil
case "Undertaker":
case "Undertaker": // 承接人
undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return undertaker, nil
case "Operator":
case "Operator": // 操作人
operator, err := userTranslator.ToOperatorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return operator, nil
case "User":
case "User": // 用户
user, err := userTranslator.ToUserFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
... ...
... ... @@ -122,6 +122,7 @@ func (controller *CooperationContractController) SearchCooperationContract() {
func (controller *CooperationContractController) SearchCooperationContractByUndertaker() {
cooperationContractService := service.NewCooperationContractService(nil)
searchCooperationContractByUndertakerQuery := &query.SearchCooperationContractByUndertakerQuery{}
_ = controller.Unmarshal(searchCooperationContractByUndertakerQuery)
data, err := cooperationContractService.SearchCooperationContractByUndertaker(searchCooperationContractByUndertakerQuery)
controller.Response(data, err)
}
... ...