Commit bf04b134 authored by fengruiyu's avatar fengruiyu

数据库数据添加

parent e8975bec
......@@ -10,7 +10,7 @@ import me.goldze.mvvmhabit.utils.Utils
*/
@Database(entities = [ScenicSpotBean::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): ScenicSpotDao
abstract fun scenicSpotDao(): ScenicSpotDao
companion object {
private var _instance: AppDatabase? = null
......
package com.mints.street.db
import androidx.room.Dao
import androidx.room.Query
import androidx.room.*
/**
* Created by 冯瑞雨 on 2021/7/20.
*/
@Dao
interface ScenicSpotDao {
@Query("SELECT * FROM scenic_spot")
fun getAll(): List<ScenicSpotBean>
/**
* 添加 VR 免费专区
* OnConflictStrategy.REPLACE表如已有数据,就覆盖掉。
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addVRFreeZoneAll(list:List<ScenicSpotBean>)
/**
* 获取 VR 免费专区
*/
@Query("SELECT * FROM vr_scenic_spot")
fun getVRFreeZoneAll(): List<ScenicSpotBean>
/**
* 删除 VR 免费专区
*/
@Delete
fun deleteVRFreeZoneAll(list:List<ScenicSpotBean>)
/**
* 获取 国外的 免费专区
*/
@Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 1")
fun getForeignFreeAll(list:List<ForeignScenicSpots>)
/**
* 获取 国外的 收费(精选体验)
*/
@Query("SELECT * FROM foreign_scenic_spots WHERE is_free = 2")
fun getForeignTollAll(list:List<ForeignScenicSpots>)
/**
* 添加 VR 国外
*/
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun addForeignAll(list:List<ForeignScenicSpots>)
/**
* 删除 VR 国外免费
*/
@Query("DELETE FROM foreign_scenic_spots WHERE is_free =1")
fun deleteForeignFreeAll()
/**
* 删除 VR 国外收费
*/
@Query("DELETE FROM foreign_scenic_spots WHERE is_free =2")
fun deleteForeignTollAll()
}
\ No newline at end of file
......@@ -21,21 +21,31 @@ class ScenicSpotBean(
var name :String? = null,
//景区 图片
var images : String? = null,
//景区 url地址
var url : String? = null,
//景区 星级 默认0-5
@ColumnInfo(name="star_rating")
var starRating : Int? = null
var starRating : String? = null
)
@Entity(tableName = "foreign_scenic_spots")
class ForeignScenicSpots(
//主键 自增
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
//景区 免费还是收费的 1=免费 2=收费
@ColumnInfo(name="is_free")
var isFree:Int,
//景区 经度
var longitude :Double?=null,
//景区 纬度
var latitude :Double?=null,
//景区 目的地的ID
var did :Int?=null,
//景区 名称
var name :String? = null,
//景区 人数
@ColumnInfo(name = "number_people")
var numberPeople :Int? = null,
//景区 图片
var images : List<String>? = null
......
......@@ -28,8 +28,9 @@
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:paddingStart="10dp"
android:text="测试"
android:paddingTop="5dp"
android:textColor="@color/black"
android:textSize="12sp" />
......@@ -40,12 +41,23 @@
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
>
<com.mints.street.widget.RatingStar
android:layout_width="60dp"
android:layout_height="10dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="10dp"
android:layout_weight="1"
app:starNormal="@mipmap/star_icon"
app:starNumber="5"
/>
app:starNumber="5" />
</LinearLayout>
</LinearLayout>
</layout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment