作者 陈志颖

feat:订单列表增加高级搜索

... ... @@ -57,13 +57,13 @@ func (columnSettingService *ColumnSettingService) CreateColumnSetting(createColu
} else {
columnSettingRepository = value
}
if columnSetting, errSaved := columnSettingRepository.Save(newColumnSetting); errSaved != nil {
if columnSettingSaved, errSaved := columnSettingRepository.Save(newColumnSetting); errSaved != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, errSaved.Error())
} else {
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
return columnSetting, nil
return columnSettingSaved, nil
}
}
... ... @@ -106,7 +106,16 @@ func (columnSettingService *ColumnSettingService) GetColumnSetting(getColumnSett
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
return columnSettingFound, nil
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingFound.Value,
"unselected": columnSettingFound.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
... ... @@ -188,7 +197,16 @@ func (columnSettingService *ColumnSettingService) RemoveColumnSetting(removeColu
if errTr := transactionContext.CommitTransaction(); errTr != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errRm.Error())
}
return columnSettingRemoved, nil
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingRemoved.Value,
"unselected": columnSettingRemoved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
... ... @@ -238,7 +256,16 @@ func (columnSettingService *ColumnSettingService) ResetColumn(resetColumnCommand
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
return columnSettingSaved, nil
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingSaved.Value,
"unselected": columnSettingSaved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
... ... @@ -289,7 +316,16 @@ func (columnSettingService *ColumnSettingService) UpdateColumnSetting(updateColu
if errCommit := transactionContext.CommitTransaction(); errCommit != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, errCommit.Error())
}
return columnSettingSaved, nil
// 数据mapper
orderBaseColumns := map[string]interface{}{
"orderBaseColumns": map[string]interface{}{
"selected": columnSettingSaved.Value,
"unselected": columnSettingSaved.InvalidValue,
},
}
return orderBaseColumns, nil
}
}
... ...
... ... @@ -20,6 +20,8 @@ type ListOrderBaseQuery struct {
OrderType int `json:"orderType"`
//合伙人分类
PartnerCategory int `json:"partnerCategory"`
//合伙人类型名称
PartnerCategoryName string `json:"partnerCategoryName"`
//更新时间开始
UpdateTimeBegin string `json:"updateTimeBegin"`
//更新时间截止
... ... @@ -29,7 +31,7 @@ type ListOrderBaseQuery struct {
//创建时间截止
CreateTimeEnd string `json:"createTimeEnd"`
//销售时间开始
SaleDateStart string `json:"saleDateStart"`
SaleDateBegin string `json:"saleDateBegin"`
//销售时间结束
SaleDateEnd string `json:"sateDateEnd"`
}
... ...
... ... @@ -64,8 +64,9 @@ func (service OrderInfoService) PageListOrderBase(listOrderQuery query.ListOrder
listOrderQuery.DeliveryCode, // 发货单号
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd}, // 订单创建时间
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd}, // 订单更新时间
[2]string{listOrderQuery.SaleDateStart, listOrderQuery.SaleDateEnd}, // 销售日期
[2]string{listOrderQuery.SaleDateBegin, listOrderQuery.SaleDateEnd}, // 销售日期
listOrderQuery.PartnerCategory,
listOrderQuery.PartnerCategoryName,
listOrderQuery.Limit, listOrderQuery.Offset,
)
if err != nil {
... ... @@ -927,7 +928,7 @@ func (service OrderInfoService) ListOrderForExcel(listOrderQuery query.ListOrder
listOrderQuery.DeliveryCode, // 发货单号
[2]string{listOrderQuery.UpdateTimeBegin, listOrderQuery.UpdateTimeEnd},
[2]string{listOrderQuery.CreateTimeBegin, listOrderQuery.CreateTimeEnd},
[2]string{listOrderQuery.SaleDateStart, listOrderQuery.SaleDateEnd},
[2]string{listOrderQuery.SaleDateBegin, listOrderQuery.SaleDateEnd},
listOrderQuery.PartnerCategory,
)
if err != nil {
... ...
... ... @@ -330,7 +330,7 @@ type GoodErrInfo struct {
type OrderBaseRepository interface {
Save(order *OrderBase) error
FindOne(qureyOptions OrderBaseFindOneQuery) (*OrderBase, error)
FindOne(queryOptions OrderBaseFindOneQuery) (*OrderBase, error)
Find(queryOptions OrderBaseFindQuery) ([]OrderBase, int, error)
Remove(id int64, companyId int64) error
}
... ...
... ... @@ -191,7 +191,7 @@ func (dao OrderBaseDao) OrderBonusListForExcel(companyId int64, orderType int, p
//@param updateTime 订单更新时间范围"[开始时间,结束时间]",时间格式"2006-01-02 15:04:05+07"
//@param createTime 订单的创建时间范围"[开始时间,结束时间]" 时间格式"2006-01-02 15:04:05+07"
func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, partnerName string, orderCode string, deliveryCode string,
updateTime [2]string, createTime [2]string, saleDate [2]string, partnerCategory int, limit, offset int) ([]models.OrderBase, int, error) {
updateTime [2]string, createTime [2]string, saleDate [2]string, partnerCategory int, partnerCategoryName string, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
... ... @@ -203,6 +203,9 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
if partnerCategory > 0 {
query = query.Where(`order_base.partner_category@>'{"id":?}'`, partnerCategory)
}
if partnerCategoryName != "" {
query = query.Where(`order_base.partner_category->>'name' like ?`, "%"+partnerCategoryName+"%")
}
if len(updateTime[0]) > 0 {
query = query.Where(`order_base.update_time>=?`, updateTime[0])
}
... ... @@ -215,6 +218,12 @@ func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, par
if len(createTime[1]) > 0 {
query = query.Where(`order_base.create_time<=?`, createTime[1])
}
if len(saleDate[0]) > 0 {
query = query.Where(`order_base.sale_date>=?`, saleDate[0])
}
if len(saleDate[1]) > 0 {
query = query.Where(`order_base.sale_date<=?`, saleDate[1])
}
if len(partnerName) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
Where("p.partner_name like ? ", "%"+partnerName+"%")
... ...
... ... @@ -38,7 +38,6 @@ func (repository *ColumnSettingRepository) Save(columnSetting *domain.ColumnSett
if err != nil {
return nil, err
}
return nil, err
//_, err := repository.nextIdentify()
//if err != nil {
// return columnSetting, err
... ...
... ... @@ -23,7 +23,7 @@ func NewOrderBaseRepository(transactionContext *transaction.TransactionContext)
return &OrderBaseRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel *models.OrderBase) (order domain.OrderBase, err error) {
func (repository OrderBaseRepository) transformPgModelToDomainModel(orderModel *models.OrderBase) (order domain.OrderBase, err error) {
order = domain.OrderBase{
Id: orderModel.Id, OrderType: orderModel.OrderType, OrderCode: orderModel.OrderCode,
DeliveryCode: orderModel.DeliveryCode, Buyer: orderModel.Buyer, RegionInfo: orderModel.RegionInfo,
... ... @@ -50,10 +50,10 @@ func (reponsitory OrderBaseRepository) transformPgModelToDomainModel(orderModel
return order, nil
}
func (reponsitory OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
func (repository OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
tx = repository.transactionContext.PgTx
)
m := &models.OrderBase{
Id: orderInfo.Id, OrderType: orderInfo.OrderType, OrderCode: orderInfo.OrderCode,
... ... @@ -90,8 +90,8 @@ func (reponsitory OrderBaseRepository) Save(orderInfo *domain.OrderBase) error {
return err
}
func (reponsitory OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery) ([]domain.OrderBase, int, error) {
db := reponsitory.transactionContext.GetDB()
func (repository OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuery) ([]domain.OrderBase, int, error) {
db := repository.transactionContext.GetDB()
orderModels := []models.OrderBase{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
... ... @@ -127,7 +127,7 @@ func (reponsitory OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuer
return ordersReturn, 0, err
}
for i := range orderModels {
domainOrder, err := reponsitory.transformPgModelToDomainModel(&orderModels[i])
domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i])
if err != nil {
return ordersReturn, 0, err
}
... ... @@ -136,29 +136,29 @@ func (reponsitory OrderBaseRepository) Find(queryOption domain.OrderBaseFindQuer
return ordersReturn, count, nil
}
func (reponsitory OrderBaseRepository) FindOne(qureyOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
func (repository OrderBaseRepository) FindOne(queryOptions domain.OrderBaseFindOneQuery) (*domain.OrderBase, error) {
var (
err error
tx = reponsitory.transactionContext.PgDd
tx = repository.transactionContext.PgDd
)
m := new(models.OrderBase)
query := tx.Model(m).
Where("id=?", qureyOptions.OrderId)
if qureyOptions.CompanyId > 0 {
query = query.Where("company_id=?", qureyOptions.CompanyId)
Where("id=?", queryOptions.OrderId)
if queryOptions.CompanyId > 0 {
query = query.Where("company_id=?", queryOptions.CompanyId)
}
err = query.First()
if err != nil {
return nil, err
}
result, err := reponsitory.transformPgModelToDomainModel(m)
result, err := repository.transformPgModelToDomainModel(m)
return &result, err
}
func (reponsitory OrderBaseRepository) Remove(id int64, companyId int64) error {
func (repository OrderBaseRepository) Remove(id int64, companyId int64) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
tx = repository.transactionContext.PgTx
)
m := &models.OrderBase{
Id: id,
... ...
... ... @@ -160,15 +160,16 @@ func (postData *postOrderPurposeDelivery) Valid() error {
**/
func (c *OrderInfoController) PageListOrderReal() {
type Parameter struct {
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"PartnerCategory"` // 合伙人类型id
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTime []string `json:"updateTime"` // 订单更新时间
CreateTime []string `json:"createTime"` // 订单创建时间
SaleDate []string `json:"saleDate"` // 销售时间
PartnerName string `json:"partnerName"` // 合伙人姓名
OrderCode string `json:"orderCode"` // 订单号
DeliveryCode string `json:"deliveryCode"` // 发货单号
PartnerCategory int `json:"partnerCategory"` // 合伙人类型id
PartnerCategoryName string `json:"partnerCategoryName"` // 合伙人类型名称
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
UpdateTime []string `json:"updateTime"` // 订单更新时间
CreateTime []string `json:"createTime"` // 订单创建时间
SaleDate []string `json:"saleDate"` // 销售时间
}
var (
param Parameter
... ... @@ -269,20 +270,21 @@ func (c *OrderInfoController) PageListOrderReal() {
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderInfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerName: param.PartnerName,
OrderCode: param.OrderCode,
DeliveryCode: param.DeliveryCode,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
SaleDateStart: saleDateBegin,
SaleDateEnd: saleDateEnd,
PartnerName: param.PartnerName,
OrderCode: param.OrderCode,
DeliveryCode: param.DeliveryCode,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
PartnerCategory: param.PartnerCategory,
PartnerCategoryName: param.PartnerCategoryName,
UpdateTimeBegin: updateTimeBegin,
UpdateTimeEnd: updateTimeEnd,
CreateTimeBegin: createTimeBegin,
CreateTimeEnd: createTimeEnd,
SaleDateBegin: saleDateBegin,
SaleDateEnd: saleDateEnd,
})
if err != nil {
c.ResponseError(err)
... ... @@ -361,7 +363,7 @@ func (c *OrderInfoController) GetOrderReal() {
"product": allGoods,
"create_time": orderinfo.CreateTime.Local().Format("2006-01-02 15:04:06"),
"update_time": orderinfo.UpdateTime.Local().Format("2006-01-02 15:04:06"),
"sale_date": orderinfo.SaleDate.Local().Format("2006-01-02 15:04:06"),
"saleDate": orderinfo.SaleDate.Local().Format("2006-01-02 15:04:06"),
"partnerCategoryId": orderinfo.PartnerCategory.Id,
"partnerCategoryName": orderinfo.PartnerCategory.Name,
}
... ...