Commit bf04b134 authored by fengruiyu's avatar fengruiyu

数据库数据添加

parent e8975bec
...@@ -10,7 +10,7 @@ import me.goldze.mvvmhabit.utils.Utils ...@@ -10,7 +10,7 @@ import me.goldze.mvvmhabit.utils.Utils
*/ */
@Database(entities = [ScenicSpotBean::class], version = 1) @Database(entities = [ScenicSpotBean::class], version = 1)
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
abstract fun userDao(): ScenicSpotDao abstract fun scenicSpotDao(): ScenicSpotDao
companion object { companion object {
private var _instance: AppDatabase? = null private var _instance: AppDatabase? = null
......
package com.mints.street.db package com.mints.street.db
import androidx.room.Dao import androidx.room.*
import androidx.room.Query
/** /**
* Created by 冯瑞雨 on 2021/7/20. * Created by 冯瑞雨 on 2021/7/20.
*/ */
@Dao @Dao
interface ScenicSpotDao { 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( ...@@ -21,21 +21,31 @@ class ScenicSpotBean(
var name :String? = null, var name :String? = null,
//景区 图片 //景区 图片
var images : String? = null, var images : String? = null,
//景区 url地址
var url : String? = null,
//景区 星级 默认0-5 //景区 星级 默认0-5
@ColumnInfo(name="star_rating") @ColumnInfo(name="star_rating")
var starRating : Int? = null var starRating : String? = null
) )
@Entity(tableName = "foreign_scenic_spots") @Entity(tableName = "foreign_scenic_spots")
class ForeignScenicSpots( class ForeignScenicSpots(
//主键 自增 //主键 自增
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
var id: Int = 0, var id: Int = 0,
//景区 免费还是收费的 1=免费 2=收费
@ColumnInfo(name="is_free")
var isFree:Int,
//景区 经度 //景区 经度
var longitude :Double?=null, var longitude :Double?=null,
//景区 纬度 //景区 纬度
var latitude :Double?=null, var latitude :Double?=null,
//景区 目的地的ID
var did :Int?=null,
//景区 名称 //景区 名称
var name :String? = null, var name :String? = null,
//景区 人数
@ColumnInfo(name = "number_people")
var numberPeople :Int? = null,
//景区 图片 //景区 图片
var images : List<String>? = null var images : List<String>? = null
......
...@@ -28,8 +28,9 @@ ...@@ -28,8 +28,9 @@
android:id="@+id/tv_name" android:id="@+id/tv_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dp" android:paddingStart="10dp"
android:text="测试" android:text="测试"
android:paddingTop="5dp"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="12sp" /> android:textSize="12sp" />
...@@ -40,12 +41,23 @@ ...@@ -40,12 +41,23 @@
android:orientation="horizontal"> android:orientation="horizontal">
</LinearLayout> </LinearLayout>
<com.mints.street.widget.RatingStar <LinearLayout
android:layout_width="60dp" android:layout_width="wrap_content"
android:layout_height="10dp" android:layout_height="match_parent"
app:starNormal="@mipmap/star_icon" android:gravity="center"
app:starNumber="5" >
/> <com.mints.street.widget.RatingStar
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" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</layout> </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