Добавил новое поле Радиус, осталость еще цвет, и вообще супер

This commit is contained in:
Кашин Максим 2023-12-26 14:01:55 +04:00
parent ec12fd5cbf
commit a985333daf
28 changed files with 73 additions and 12 deletions

View File

@ -54,6 +54,7 @@ class RestBikeRepository(
x.id, x.id,
x.dateTime, x.dateTime,
x.weight, x.weight,
x.radius,
x.maxCount - service.getRents().flatMap { rent -> x.maxCount - service.getRents().flatMap { rent ->
rent.items.filter { item -> item.id == x.id } rent.items.filter { item -> item.id == x.id }
}.sumOf { item -> item.count }, }.sumOf { item -> item.count },

View File

@ -11,6 +11,7 @@ class ItemFromBikeRemote(
@Contextual @Contextual
val dateTime: LocalDateTime = LocalDateTime.MIN, val dateTime: LocalDateTime = LocalDateTime.MIN,
val weight: Double = 0.0, val weight: Double = 0.0,
val radius: Double = 0.0,
val maxCount: Int = 0, val maxCount: Int = 0,
val availableCount: Int = 0, val availableCount: Int = 0,
val bikeId: Int = 0, val bikeId: Int = 0,
@ -20,6 +21,7 @@ fun ItemFromBikeRemote.toItemFromBike(): ItemFromBike = ItemFromBike(
id, id,
dateTime, dateTime,
weight, weight,
radius,
availableCount, availableCount,
bikeId bikeId
) )
@ -28,6 +30,7 @@ fun ItemFromBike.toItemFromBikeRemote(): ItemFromBikeRemote = ItemFromBikeRemote
uid, uid,
dateTime, dateTime,
weight, weight,
radius,
availableCount, availableCount,
bikeId bikeId
) )

View File

@ -13,7 +13,7 @@ class ItemFromCartRemote(
var bikeId: Int = 0, var bikeId: Int = 0,
) )
fun ItemFromCartRemote.toItemFromCart(bike: BikeRemote, dateTime: LocalDateTime, weight: Double, availableCount: Int): ItemFromCart = fun ItemFromCartRemote.toItemFromCart(bike: BikeRemote, dateTime: LocalDateTime, weight: Double, radius: Double, availableCount: Int): ItemFromCart =
ItemFromCart( ItemFromCart(
id, dateTime, weight, availableCount, count, bike.id, bike.toBike() id, dateTime, weight, radius, availableCount, count, bike.id, bike.toBike()
) )

View File

@ -12,11 +12,12 @@ class ItemFromRentRemote(
val id: Int = 0, val id: Int = 0,
@Contextual val dateTime: LocalDateTime = LocalDateTime.MIN, @Contextual val dateTime: LocalDateTime = LocalDateTime.MIN,
val frozenWeight: Double = 0.0, val frozenWeight: Double = 0.0,
val radius: Double = 0.0,
val count: Int = 0, val count: Int = 0,
val bikeId: Int = 0, val bikeId: Int = 0,
) )
fun ItemFromRentRemote.toItemFromRent(bike: BikeRemote): ItemFromRent = fun ItemFromRentRemote.toItemFromRent(bike: BikeRemote): ItemFromRent =
ItemFromRent( ItemFromRent(
id, dateTime, frozenWeight, count, bikeId, bike.toBike() id, dateTime, frozenWeight, radius, count, bikeId, bike.toBike()
) )

View File

@ -11,6 +11,7 @@ data class ItemRemote(
@Contextual @Contextual
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double,
val maxCount: Int, val maxCount: Int,
val bikeId: Int = 0 val bikeId: Int = 0
) )
@ -19,6 +20,7 @@ fun ItemRemote.toItem(): Item = Item(
id, id,
dateTime, dateTime,
weight, weight,
radius,
maxCount, maxCount,
bikeId bikeId
) )
@ -27,6 +29,7 @@ fun Item.toItemRemote(): ItemRemote = ItemRemote(
uid, uid,
dateTime, dateTime,
weight, weight,
radius,
maxCount, maxCount,
bikeId bikeId
) )

View File

@ -12,6 +12,7 @@ data class ItemWithBikeRemote(
@Contextual @Contextual
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double,
val maxCount: Int, val maxCount: Int,
val bikeId: Int = 0, val bikeId: Int = 0,
val bike: BikeRemote, val bike: BikeRemote,
@ -21,6 +22,7 @@ fun ItemWithBikeRemote.toItem(): Item = Item(
id, id,
dateTime, dateTime,
weight, weight,
radius,
maxCount, maxCount,
bikeId bikeId
) )

View File

@ -114,16 +114,17 @@ class RestItemRepository(
// Отображаем данные в виде таблицы // Отображаем данные в виде таблицы
val tableStartY = yTitle + 80f val tableStartY = yTitle + 80f
val columnWidths = floatArrayOf(0.5f, 1.5f, 1f, 1.5f, 1f) // Увеличиваем ширину столбцов val columnWidths = floatArrayOf(0.5f, 1.5f, 1f, 0.5f, 1.5f, 1f) // Увеличиваем ширину столбцов
val rowHeight = 30f // Увеличиваем высоту строки val rowHeight = 30f // Увеличиваем высоту строки
drawTableRow(canvas, arrayOf("ID", "Дата проверки", "Вес", "Количество", "ID велосипеда"), columnWidths, tableStartY, paint) drawTableRow(canvas, arrayOf("ID", "Дата проверки", "Вес", "R", "Количество", "ID велосипеда"), columnWidths, tableStartY, paint)
for ((index, report) in reportData.withIndex()) { for ((index, report) in reportData.withIndex()) {
val row = arrayOf( val row = arrayOf(
report.id.toString(), report.id.toString(),
report.dateTime.toString(), report.dateTime.toString(),
report.weight.toString(), report.weight.toString(),
report.radius.toString(),
report.maxCount.toString(), report.maxCount.toString(),
report.bikeId.toString() report.bikeId.toString()
) )

View File

@ -59,6 +59,7 @@ class RestRentRepository(
uid, uid,
it.id, it.id,
it.frozenWeight, it.frozenWeight,
it.radius,
it.count it.count
) )
) )

View File

@ -19,6 +19,7 @@ class RestRentItemRepository(
item.uid, item.uid,
item.dateTime, item.dateTime,
item.weight, item.weight,
item.radius,
rentItemCrossRef.count, rentItemCrossRef.count,
item.bikeId item.bikeId
) )

View File

@ -7,6 +7,7 @@ data class ReportRemote(
val id: Int = 0, val id: Int = 0,
val dateTime: Int = 0, val dateTime: Int = 0,
val weight: Double = 0.0, val weight: Double = 0.0,
val radius: Double = 0.0,
val maxCount: Int = 0, val maxCount: Int = 0,
val bikeId: Int = 0 val bikeId: Int = 0
) )

View File

@ -53,6 +53,7 @@ class RestUserRepository(
item.bike, item.bike,
item.dateTime, item.dateTime,
item.weight, item.weight,
item.radius,
item.maxCount - service.getRents().flatMap { rent -> item.maxCount - service.getRents().flatMap { rent ->
rent.items.filter { item -> item.id == it.id } rent.items.filter { item -> item.id == it.id }
}.sumOf { item -> item.count }) }.sumOf { item -> item.count })

View File

@ -93,6 +93,7 @@ fun Cart(
uid = item.uid, uid = item.uid,
dateTime = item.dateTime, dateTime = item.dateTime,
weight = item.weight, weight = item.weight,
radius = item.radius,
maxCount = 0, maxCount = 0,
bikeId = item.bikeId bikeId = item.bikeId
), user = it ), user = it
@ -108,6 +109,7 @@ fun Cart(
uid = item.uid, uid = item.uid,
dateTime = item.dateTime, dateTime = item.dateTime,
weight = item.weight, weight = item.weight,
radius = item.radius,
maxCount = 0, maxCount = 0,
bikeId = item.bikeId bikeId = item.bikeId
), userId = it, count = count, availableCount = item.availableCount ), userId = it, count = count, availableCount = item.availableCount
@ -263,6 +265,7 @@ private fun ItemListItem(
Text( Text(
text = "${item.bike.name}\n" + text = "${item.bike.name}\n" +
"Вес: ${item.weight}\n" + "Вес: ${item.weight}\n" +
"R: ${item.radius}\n" +
"${currentCount}/${item.availableCount}\n" + "${currentCount}/${item.availableCount}\n" +
"Год: ${formattedDate}", "Год: ${formattedDate}",
color = MaterialTheme.colorScheme.onSecondary color = MaterialTheme.colorScheme.onSecondary

View File

@ -40,6 +40,7 @@ class CartViewModel(
rentId.toInt(), rentId.toInt(),
item.uid, item.uid,
item.weight, item.weight,
item.radius,
item.count item.count
) )
) )

View File

@ -109,7 +109,7 @@ fun ItemList(
verticalArrangement = Arrangement.spacedBy(4.dp) verticalArrangement = Arrangement.spacedBy(4.dp)
) { ) {
Text( Text(
text = "Вес: ${item.weight}\n" + "Количество: ${item.availableCount}\n" + "Год: ${formattedDate}", text = "Вес: ${item.weight}\n" + "R: ${item.radius}\n" + "Количество: ${item.availableCount}\n" + "Год: ${formattedDate}",
color = MaterialTheme.colorScheme.onPrimary color = MaterialTheme.colorScheme.onPrimary
) )
} }

View File

@ -17,6 +17,7 @@ class ItemListViewModel(
uid = item.uid, uid = item.uid,
dateTime = item.dateTime, dateTime = item.dateTime,
weight = item.weight, weight = item.weight,
radius = item.radius,
maxCount = 0, maxCount = 0,
bikeId = 0 bikeId = 0
) )

View File

@ -89,6 +89,7 @@ fun RentView(
Text( Text(
text = "${item.bike.name}\n" + text = "${item.bike.name}\n" +
"Вес: ${item.frozenWeight}\n" + "Вес: ${item.frozenWeight}\n" +
"R: ${item.radius}\n" +
"Количество: ${count.value}\n" + "Количество: ${count.value}\n" +
"Дата: ${formattedDate}", "Дата: ${formattedDate}",
color = MaterialTheme.colorScheme.onPrimary color = MaterialTheme.colorScheme.onPrimary

View File

@ -236,7 +236,7 @@ fun ReportPage (navController: NavController?, viewModel: ReportViewModel = view
coroutineScope.launch { coroutineScope.launch {
viewModel.generatePdfFile( viewModel.generatePdfFile(
context = context, context = context,
fileName = "отчет.pdf", fileName = "Отчет по велосипедам.pdf",
reportData = reportResultPageState.resReport reportData = reportResultPageState.resReport
) )
} }
@ -303,13 +303,14 @@ fun TableScreen(reportData: List<ReportRemote>) {
Text("ID", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background) Text("ID", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background)
Text("Дата", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("Дата", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("Вес", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("Вес", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("R", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background)
Text("Кол-во", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("Кол-во", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("ID вел.", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("ID вел.", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
} }
// Here are all the lines of your table. // Here are all the lines of your table.
reportData.forEach { reportData.forEach {
val (id, dateTime, weight, maxCount, bikeId) = it val (id, dateTime, weight, radius, maxCount, bikeId) = it
Card( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -321,6 +322,7 @@ fun TableScreen(reportData: List<ReportRemote>) {
Text(id.toString(), Modifier.weight(0.5f)) Text(id.toString(), Modifier.weight(0.5f))
Text(dateTime.toString(), Modifier.weight(1.0f)) Text(dateTime.toString(), Modifier.weight(1.0f))
Text(weight.toString(), Modifier.weight(1.0f)) Text(weight.toString(), Modifier.weight(1.0f))
Text(radius.toString(), Modifier.weight(1.0f))
Text(maxCount.toString(), Modifier.weight(1.0f)) Text(maxCount.toString(), Modifier.weight(1.0f))
Text(bikeId.toString(), Modifier.weight(1.0f)) Text(bikeId.toString(), Modifier.weight(1.0f))
} }

View File

@ -127,6 +127,19 @@ private fun ItemEdit(
color = MaterialTheme.colorScheme.onSecondary color = MaterialTheme.colorScheme.onSecondary
) )
) )
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = itemUiState.itemDetails.radius,
label = { Text(text = "R") },
onValueChange = {
onUpdate(itemUiState.itemDetails.copy(radius = it))
},
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
textStyle = MaterialTheme.typography.bodyLarge.copy(
color = MaterialTheme.colorScheme.onSecondary
)
)
OutlinedTextField( OutlinedTextField(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
value = itemUiState.itemDetails.maxCount.toString(), value = itemUiState.itemDetails.maxCount.toString(),

View File

@ -80,6 +80,7 @@ data class ItemDetails(
val uid: Int = 0, val uid: Int = 0,
val dateTime: LocalDateTime = LocalDateTime.MIN, val dateTime: LocalDateTime = LocalDateTime.MIN,
val weight: String = "0", val weight: String = "0",
val radius: String = "0",
val maxCount: Int = 0, val maxCount: Int = 0,
val bikeId: Int = 0 val bikeId: Int = 0
) )
@ -88,6 +89,7 @@ fun ItemDetails.toItem(uid: Int = 0, bikeUid: Int = 0): Item = Item(
uid = uid, uid = uid,
dateTime = dateTime, dateTime = dateTime,
weight = weight.toDoubleOrNull() ?: 0.0, weight = weight.toDoubleOrNull() ?: 0.0,
radius = radius.toDoubleOrNull() ?: 0.0,
maxCount = maxCount, maxCount = maxCount,
bikeId = bikeUid bikeId = bikeUid
) )
@ -96,6 +98,7 @@ fun Item.toDetails(): ItemDetails = ItemDetails(
uid = uid, uid = uid,
dateTime = dateTime, dateTime = dateTime,
weight = weight.toString(), weight = weight.toString(),
radius = radius.toString(),
maxCount = maxCount, maxCount = maxCount,
bikeId = bikeId bikeId = bikeId
) )

View File

@ -16,7 +16,7 @@ interface BikeDao {
fun getAll(): PagingSource<Int, Bike> fun getAll(): PagingSource<Int, Bike>
@Query( @Query(
"SELECT c.*, s.uid as item_uid, s.date_time, s.weight, s.max_count-IFNULL(SUM(os.count), 0) as available_count, c.uid as bike_id " + "SELECT c.*, s.uid as item_uid, s.date_time, s.weight, s.radius, s.max_count-IFNULL(SUM(os.count), 0) as available_count, c.uid as bike_id " +
"FROM bikes AS c " + "FROM bikes AS c " +
"LEFT JOIN items AS s ON s.bike_id = c.uid " + "LEFT JOIN items AS s ON s.bike_id = c.uid " +
"LEFT JOIN rents_items AS os ON os.item_id = s.uid " + "LEFT JOIN rents_items AS os ON os.item_id = s.uid " +

View File

@ -15,7 +15,7 @@ interface RentDao {
fun getAll(userId: Int?): PagingSource<Int, Rent> fun getAll(userId: Int?): PagingSource<Int, Rent>
@Query( @Query(
"SELECT o.*, s.*, os.count, os.frozen_weight " + "SELECT o.*, s.*, os.count, os.frozen_weight, os.radius " +
"FROM rents AS o " + "FROM rents AS o " +
"JOIN rents_items AS os ON os.rent_id = o.uid " + "JOIN rents_items AS os ON os.rent_id = o.uid " +
"JOIN items AS s ON s.uid = os.item_id " + "JOIN items AS s ON s.uid = os.item_id " +

View File

@ -24,6 +24,7 @@ data class Item(
@ColumnInfo(name = "date_time") @ColumnInfo(name = "date_time")
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double,
@ColumnInfo(name = "max_count") @ColumnInfo(name = "max_count")
val maxCount: Int, val maxCount: Int,
@ColumnInfo(name = "bike_id", index = true) @ColumnInfo(name = "bike_id", index = true)
@ -33,9 +34,10 @@ data class Item(
constructor( constructor(
dateTime: LocalDateTime, dateTime: LocalDateTime,
weight: Double, weight: Double,
radius: Double,
maxCount: Int, maxCount: Int,
bike: Bike, bike: Bike,
) : this(0, dateTime, weight, maxCount, bike.uid) ) : this(0, dateTime, weight,radius, maxCount, bike.uid)
companion object { companion object {
fun getItem(index: Int = 0): Item { fun getItem(index: Int = 0): Item {
@ -43,6 +45,7 @@ data class Item(
index, index,
LocalDateTime.MIN, LocalDateTime.MIN,
0.0, 0.0,
0.0,
0, 0,
0 0
) )
@ -56,6 +59,7 @@ data class Item(
if (uid != other.uid) return false if (uid != other.uid) return false
if (dateTime != other.dateTime) return false if (dateTime != other.dateTime) return false
if (weight != other.weight) return false if (weight != other.weight) return false
if (radius != other.radius) return false
if (maxCount != other.maxCount) return false if (maxCount != other.maxCount) return false
if (bikeId != other.bikeId) return false if (bikeId != other.bikeId) return false
return true return true
@ -65,6 +69,7 @@ data class Item(
var result = uid var result = uid
result = 31 * result + dateTime.hashCode() result = 31 * result + dateTime.hashCode()
result = 31 * result + weight.hashCode() result = 31 * result + weight.hashCode()
result = 31 * result + radius.hashCode()
result = 31 * result + maxCount.hashCode() result = 31 * result + maxCount.hashCode()
result = 31 * result + bikeId.hashCode() result = 31 * result + bikeId.hashCode()
return result return result

View File

@ -10,6 +10,7 @@ data class ItemFromBike(
@ColumnInfo(name = "date_time") @ColumnInfo(name = "date_time")
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double,
@ColumnInfo(name = "available_count") @ColumnInfo(name = "available_count")
var availableCount: Int, var availableCount: Int,
@ColumnInfo(name = "bike_id") @ColumnInfo(name = "bike_id")
@ -23,6 +24,7 @@ data class ItemFromBike(
val dateFormatter = DateTimeFormatter.ofPattern("yyyy") val dateFormatter = DateTimeFormatter.ofPattern("yyyy")
if (dateFormatter.format(dateTime) != dateFormatter.format(other.dateTime)) return false if (dateFormatter.format(dateTime) != dateFormatter.format(other.dateTime)) return false
if (weight != other.weight) return false if (weight != other.weight) return false
if (radius != other.radius) return false
if (availableCount != other.availableCount) return false if (availableCount != other.availableCount) return false
if (bikeId != other.bikeId) return false if (bikeId != other.bikeId) return false
return true return true
@ -32,6 +34,7 @@ data class ItemFromBike(
var result = uid var result = uid
result = 31 * result + dateTime.hashCode() result = 31 * result + dateTime.hashCode()
result = 31 * result + weight.hashCode() result = 31 * result + weight.hashCode()
result = 31 * result + radius.hashCode()
result = 31 * result + availableCount.hashCode() result = 31 * result + availableCount.hashCode()
result = 31 * result + bikeId.hashCode() result = 31 * result + bikeId.hashCode()
return result return result
@ -42,6 +45,7 @@ fun ItemFromBike.toItem(): Item = Item (
uid, uid,
dateTime, dateTime,
weight, weight,
radius,
availableCount, availableCount,
bikeId bikeId
) )

View File

@ -10,6 +10,7 @@ data class ItemFromCart(
@ColumnInfo(name = "date_time") @ColumnInfo(name = "date_time")
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double,
@ColumnInfo(name = "available_count") @ColumnInfo(name = "available_count")
val availableCount: Int, val availableCount: Int,
val count: Int, val count: Int,

View File

@ -11,6 +11,7 @@ data class ItemFromRent(
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
@ColumnInfo(name = "frozen_weight") @ColumnInfo(name = "frozen_weight")
val frozenWeight: Double, val frozenWeight: Double,
val radius: Double,
val count: Int, val count: Int,
@ColumnInfo(name = "bike_id") @ColumnInfo(name = "bike_id")
val bikeId: Int = 0, val bikeId: Int = 0,

View File

@ -15,6 +15,7 @@ data class RentItemCrossRef(
val itemId: Int, val itemId: Int,
@ColumnInfo(name = "frozen_weight") @ColumnInfo(name = "frozen_weight")
val frozenWeight: Double, val frozenWeight: Double,
val radius: Double,
val count: Int val count: Int
) { ) {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {

View File

@ -14,7 +14,16 @@
} }
], ],
"rents": [], "rents": [],
"items": [], "items": [
{
"dateTime": 2020,
"weight": 23.6,
"radius": 14,
"maxCount": 5,
"bikeId": 3,
"id": 1
}
],
"bikes": [ "bikes": [
{ {
"name": "BMX", "name": "BMX",

View File

@ -39,6 +39,7 @@ function generateReport(items) {
id: item.id, id: item.id,
dateTime: item.dateTime, dateTime: item.dateTime,
weight: item.weight, weight: item.weight,
radius: item.radius,
maxCount: item.maxCount, maxCount: item.maxCount,
bikeId: item.bikeId bikeId: item.bikeId