@Entity(tableName = "sale_order") dataclassSaleOrder( //订单号 @PrimaryKey(autoGenerate = true) val orderId:Int=1, //售出产品名称 @ColumnInfo(name = "productName") var productName:String, //售出产品型号 @ColumnInfo(name = "productModel") var productModel:String, //销售数量 @ColumnInfo(name = "count") var count:Int, //销售总价格 @ColumnInfo(name = "price") var price:Float, //客户名称 @ColumnInfo(name = "customer") var customer:String, //销售日期 @ColumnInfo(name = "saleDate") var saleDate: Date, //预计送达日期 @ColumnInfo(name = "deliveryDate") var deliveryDate: Date, //订单状态 @ColumnInfo(name = "state") var state:String, //管理员批注 @ColumnInfo(name = "comment") var comment:String ){ companionobject{ constval STATE_REQUEST:String="申请中" constval STATE_DELIVERY:String="运输中" constval STATE_REFUSED:String="已拒绝" constval STATE_COMPLETE:String="已完成" } }
视图示例
1 2 3 4 5
@DatabaseView("SELECT customer, count(customer) FROM sale_order GROUP BY customer ORDER BY count(customer) DESC") dataclassPurchaseCount( val customer: String, val times:Int )
@Query("SELECT * FROM sale_order ORDER BY" + "( CASE WHEN state = '申请中' THEN 0 WHEN state = '已拒绝' THEN 1 WHEN state = '运输中' THEN 2 ELSE 3 END )") fungetAllSaleOrder(): LiveData<List<SaleOrder>> }