本文在
https://www.jianshu.com/p/d614ac030e7c: 在pigx-visual之外构建微服务
https://www.jianshu.com/p/353793d668ab: pigx数据库操作示例
https://www.jianshu.com/p/bd81ad89035a:pigx开发示范之旅:项目规划
https://www.jianshu.com/p/c6aa42d402db:pigx开发示范之旅:客户模块开发
基础上开始,本模块主要示范多级对象关联的开发。
一、订单VO
订单VO引用CustomerVO,包含OrderDetailVO的List,
CustomerVO包含Qualification实体的List
OrderDetailVO引用Product实体 及 引用 DeliveryStatusEnum 枚举
package com.mycompany.mydemo.order.vo;
import com.mycompany.mydemo.customer.vo.CustomerVO;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class OrderVO implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
/**
*
*/
private CustomerVO customerVO;
/**
*
*/
private LocalDateTime orderTime;
private List
}
二、订单详情VO
package com.mycompany.mydemo.order.vo;
import com.mycompany.mydemo.base.entity.Product;
import com.mycompany.mydemo.enums.DeliveryStatusEnum;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class OrderDetailVO implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
/**
*
*/
private String orderId;
/**
*
*/
private String productId;
/**
*
*/
private BigDecimal price;
private Boolean isEvaluated;
/**
* 0:未送货
1:已送货
2:已收货
3:已退货
*/
private DeliveryStatusEnum deliveryStatus;
private Product product;
}
三、使用枚举
将 OrderDetail 的 deliveryStatus 属性改为 枚举类型 DeliveryStatusEnum
将 OrderDetailVO 的 deliveryStatus 属性改为 枚举类型 DeliveryStatusEnum
在 nacos 中的 application-dev.yml 的 mybatis-plus: 下 增加
typeEnumsPackage: com.mycompany.mydemo.enums
枚举类型如下:
package com.mycompany.mydemo.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum DeliveryStatusEnum {
/**
* 未送货
*/
UNDELIVERY(0, "未送货"),
/**
* 已送货
*/
DELIVERED(1,"已送货"),
/**
* 已收货
*/
RECEIVED(2,"已收货"),
/**
* 已退货
*/
RETURNED(3,"已退货");
/**
* 状态
*/
@EnumValue
private final Integer status;
/**
* 描述
*/
private final String description;
}
四、Mapper映射VO
注意:getOrderList的查询接收OrderRVO值对象
package com.mycompany.mydemo.order.vo;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
@Data
public class OrderRVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 关键字
*/
private String keyWord;
private LocalDate beginOrderTime;
private LocalDate endOrderTime;
private BigDecimal beginPrice;
private BigDecimal endPrice;
}
以下是OrderMapper.xml的内容,主要定义OrderVO 及 getOrderList
select ord.id, ord.order_time,
cust.id as customer_id, cust.name as customer_name,
qua.id as qualification_id, qua.name as qualification_name,
det.id as order_detail_id, det.price as product_price, det.order_id, det.product_id as order_product_id, det.is_evaluated, det.delivery_status,
prd.id as product_id, prd.name as product_name
from ord_order ord
left join ord_order_detail det on ord.id = det.order_id
left join bas_product prd on det.product_id = prd.id
left join cst_customer cust on ord.customer_id = cust.id
left join cst_customer_qualification cust_qua on cust.id = cust_qua.customer_id
left join bas_qualification qua on cust_qua.qualification_id = qua.id
and (cust.name LIKE CONCAT('%',#{query.keyWord},'%')
or qua.name LIKE CONCAT('%',#{query.keyWord},'%')
or prd.name LIKE CONCAT('%',#{query.keyWord},'%'))
and ord.order_time >= #{query.beginOrderTime}
and ord.order_time <= #{query.endOrderTime}
and det.price >= #{query.beginPrice}
and det.price <= #{query.endPrice}
五、功能实现
为减少Mapper.xml的臃肿,通过Mybatis-plus的lambdaQuery查询数据,如图