Фух, ну вроде добавил все перменные, что хотел. Осталось мб сделать "назначение админа", добавить в отчет "текущую дату" и в название может это + дополнить норм данными остаток, а ну еще и придумать с bikeid

This commit is contained in:
Кашин Максим 2023-12-26 15:41:35 +04:00
parent a985333daf
commit 529af56d53
28 changed files with 79 additions and 24 deletions

@ -55,6 +55,7 @@ class RestBikeRepository(
x.dateTime, x.dateTime,
x.weight, x.weight,
x.radius, x.radius,
x.colorbike,
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 },

@ -12,6 +12,7 @@ class ItemFromBikeRemote(
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 radius: Double = 0.0,
val colorbike: String = "",
val maxCount: Int = 0, val maxCount: Int = 0,
val availableCount: Int = 0, val availableCount: Int = 0,
val bikeId: Int = 0, val bikeId: Int = 0,
@ -22,6 +23,7 @@ fun ItemFromBikeRemote.toItemFromBike(): ItemFromBike = ItemFromBike(
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
availableCount, availableCount,
bikeId bikeId
) )
@ -31,6 +33,7 @@ fun ItemFromBike.toItemFromBikeRemote(): ItemFromBikeRemote = ItemFromBikeRemote
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
availableCount, availableCount,
bikeId bikeId
) )

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

@ -13,11 +13,12 @@ class ItemFromRentRemote(
@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 radius: Double = 0.0,
val colorbike: String = "",
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, radius, count, bikeId, bike.toBike() id, dateTime, frozenWeight, radius,colorbike, count, bikeId, bike.toBike()
) )

@ -12,6 +12,7 @@ data class ItemRemote(
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double, val radius: Double,
val colorbike: String,
val maxCount: Int, val maxCount: Int,
val bikeId: Int = 0 val bikeId: Int = 0
) )
@ -21,6 +22,7 @@ fun ItemRemote.toItem(): Item = Item(
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
maxCount, maxCount,
bikeId bikeId
) )
@ -30,6 +32,7 @@ fun Item.toItemRemote(): ItemRemote = ItemRemote(
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
maxCount, maxCount,
bikeId bikeId
) )

@ -13,6 +13,7 @@ data class ItemWithBikeRemote(
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double, val radius: Double,
val colorbike: String,
val maxCount: Int, val maxCount: Int,
val bikeId: Int = 0, val bikeId: Int = 0,
val bike: BikeRemote, val bike: BikeRemote,
@ -23,6 +24,7 @@ fun ItemWithBikeRemote.toItem(): Item = Item(
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
maxCount, maxCount,
bikeId bikeId
) )

@ -114,10 +114,10 @@ class RestItemRepository(
// Отображаем данные в виде таблицы // Отображаем данные в виде таблицы
val tableStartY = yTitle + 80f val tableStartY = yTitle + 80f
val columnWidths = floatArrayOf(0.5f, 1.5f, 1f, 0.5f, 1.5f, 1f) // Увеличиваем ширину столбцов val columnWidths = floatArrayOf(0.5f, 1f, 0.6f, 0.5f, 1f, 1f, 1f) // Увеличиваем ширину столбцов
val rowHeight = 30f // Увеличиваем высоту строки val rowHeight = 30f // Увеличиваем высоту строки
drawTableRow(canvas, arrayOf("ID", "Дата проверки", "Вес", "R", "Количество", "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(
@ -125,6 +125,7 @@ class RestItemRepository(
report.dateTime.toString(), report.dateTime.toString(),
report.weight.toString(), report.weight.toString(),
report.radius.toString(), report.radius.toString(),
report.colorbike.toString(),
report.maxCount.toString(), report.maxCount.toString(),
report.bikeId.toString() report.bikeId.toString()
) )

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

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

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

@ -54,6 +54,7 @@ class RestUserRepository(
item.dateTime, item.dateTime,
item.weight, item.weight,
item.radius, item.radius,
item.colorbike,
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 })

@ -94,6 +94,7 @@ fun Cart(
dateTime = item.dateTime, dateTime = item.dateTime,
weight = item.weight, weight = item.weight,
radius = item.radius, radius = item.radius,
colorbike = item.colorbike,
maxCount = 0, maxCount = 0,
bikeId = item.bikeId bikeId = item.bikeId
), user = it ), user = it
@ -110,6 +111,7 @@ fun Cart(
dateTime = item.dateTime, dateTime = item.dateTime,
weight = item.weight, weight = item.weight,
radius = item.radius, radius = item.radius,
colorbike = item.colorbike,
maxCount = 0, maxCount = 0,
bikeId = item.bikeId bikeId = item.bikeId
), userId = it, count = count, availableCount = item.availableCount ), userId = it, count = count, availableCount = item.availableCount
@ -266,6 +268,7 @@ private fun ItemListItem(
text = "${item.bike.name}\n" + text = "${item.bike.name}\n" +
"Вес: ${item.weight}\n" + "Вес: ${item.weight}\n" +
"R: ${item.radius}\n" + "R: ${item.radius}\n" +
"Цвет: ${item.colorbike}\n" +
"${currentCount}/${item.availableCount}\n" + "${currentCount}/${item.availableCount}\n" +
"Год: ${formattedDate}", "Год: ${formattedDate}",
color = MaterialTheme.colorScheme.onSecondary color = MaterialTheme.colorScheme.onSecondary

@ -41,6 +41,7 @@ class CartViewModel(
item.uid, item.uid,
item.weight, item.weight,
item.radius, item.radius,
item.colorbike,
item.count item.count
) )
) )

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

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

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

@ -300,17 +300,18 @@ fun TableScreen(reportData: List<ReportRemote>) {
.fillMaxWidth(), // Занимаем максимальную ширину .fillMaxWidth(), // Занимаем максимальную ширину
verticalAlignment = Alignment.CenterVertically // Выравниваем по центру вертикали verticalAlignment = Alignment.CenterVertically // Выравниваем по центру вертикали
) { ) {
Text("ID", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background) Text("ID", Modifier.weight(0.3f), color = MaterialTheme.colorScheme.background)
Text("Дата", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("Дата", Modifier.weight(0.8f), color = MaterialTheme.colorScheme.background)
Text("Вес", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("Вес", Modifier.weight(0.7f), color = MaterialTheme.colorScheme.background)
Text("R", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background) Text("R", Modifier.weight(0.6f), 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("ID вел.", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background) Text("ID вел", Modifier.weight(0.5f), 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, radius, maxCount, bikeId) = it val (id, dateTime, weight, radius,colorbike, maxCount, bikeId) = it
Card( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -319,12 +320,13 @@ fun TableScreen(reportData: List<ReportRemote>) {
Row(Modifier Row(Modifier
.fillMaxWidth() .fillMaxWidth()
.background(MaterialTheme.colorScheme.background)) { .background(MaterialTheme.colorScheme.background)) {
Text(id.toString(), Modifier.weight(0.5f)) Text(id.toString(), Modifier.weight(0.3f))
Text(dateTime.toString(), Modifier.weight(1.0f)) Text(dateTime.toString(), Modifier.weight(0.8f))
Text(weight.toString(), Modifier.weight(1.0f)) Text(weight.toString(), Modifier.weight(0.7f))
Text(radius.toString(), Modifier.weight(1.0f)) Text(radius.toString(), Modifier.weight(0.6f))
Text(colorbike.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(0.5f))
} }
} }
} }

@ -1,5 +1,6 @@
package com.example.myapplication.database.entities.composeui.edit package com.example.myapplication.database.entities.composeui.edit
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
@ -53,6 +54,7 @@ fun Long.toLocalDate(): org.threeten.bp.LocalDate {
return instant.atZone(ZoneId.systemDefault()).toLocalDate() return instant.atZone(ZoneId.systemDefault()).toLocalDate()
} }
@SuppressLint("SuspiciousIndentation")
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
private fun ItemEdit( private fun ItemEdit(
@ -140,6 +142,19 @@ private fun ItemEdit(
) )
) )
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = itemUiState.itemDetails.colorbike,
label = { Text(text = "Цвет") },
onValueChange = {
onUpdate(itemUiState.itemDetails.copy(colorbike = it))
},
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text),
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(),

@ -81,6 +81,7 @@ data class ItemDetails(
val dateTime: LocalDateTime = LocalDateTime.MIN, val dateTime: LocalDateTime = LocalDateTime.MIN,
val weight: String = "0", val weight: String = "0",
val radius: String = "0", val radius: String = "0",
val colorbike: String = "0",
val maxCount: Int = 0, val maxCount: Int = 0,
val bikeId: Int = 0 val bikeId: Int = 0
) )
@ -90,6 +91,7 @@ fun ItemDetails.toItem(uid: Int = 0, bikeUid: Int = 0): Item = Item(
dateTime = dateTime, dateTime = dateTime,
weight = weight.toDoubleOrNull() ?: 0.0, weight = weight.toDoubleOrNull() ?: 0.0,
radius = radius.toDoubleOrNull() ?: 0.0, radius = radius.toDoubleOrNull() ?: 0.0,
colorbike = colorbike,
maxCount = maxCount, maxCount = maxCount,
bikeId = bikeUid bikeId = bikeUid
) )
@ -99,6 +101,7 @@ fun Item.toDetails(): ItemDetails = ItemDetails(
dateTime = dateTime, dateTime = dateTime,
weight = weight.toString(), weight = weight.toString(),
radius = radius.toString(), radius = radius.toString(),
colorbike = colorbike,
maxCount = maxCount, maxCount = maxCount,
bikeId = bikeId bikeId = bikeId
) )

@ -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.radius, 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.colorbike, 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 " +

@ -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, os.radius " + "SELECT o.*, s.*, os.count, os.frozen_weight, os.radius, os.colorbike " +
"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 " +

@ -25,6 +25,7 @@ data class Item(
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double, val radius: Double,
val colorbike: String,
@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)
@ -35,9 +36,10 @@ data class Item(
dateTime: LocalDateTime, dateTime: LocalDateTime,
weight: Double, weight: Double,
radius: Double, radius: Double,
colorbike: String,
maxCount: Int, maxCount: Int,
bike: Bike, bike: Bike,
) : this(0, dateTime, weight,radius, maxCount, bike.uid) ) : this(0, dateTime, weight,radius,colorbike, maxCount, bike.uid)
companion object { companion object {
fun getItem(index: Int = 0): Item { fun getItem(index: Int = 0): Item {
@ -46,6 +48,7 @@ data class Item(
LocalDateTime.MIN, LocalDateTime.MIN,
0.0, 0.0,
0.0, 0.0,
"",
0, 0,
0 0
) )
@ -60,6 +63,7 @@ data class Item(
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 (radius != other.radius) return false
if (colorbike != other.colorbike) 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
@ -70,6 +74,7 @@ data class Item(
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 + radius.hashCode()
result = 31 * result + colorbike.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

@ -11,6 +11,7 @@ data class ItemFromBike(
val dateTime: LocalDateTime, val dateTime: LocalDateTime,
val weight: Double, val weight: Double,
val radius: Double, val radius: Double,
val colorbike: String,
@ColumnInfo(name = "available_count") @ColumnInfo(name = "available_count")
var availableCount: Int, var availableCount: Int,
@ColumnInfo(name = "bike_id") @ColumnInfo(name = "bike_id")
@ -25,6 +26,7 @@ data class ItemFromBike(
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 (radius != other.radius) return false
if (colorbike != other.colorbike) 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
@ -35,6 +37,7 @@ data class ItemFromBike(
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 + radius.hashCode()
result = 31 * result + colorbike.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
@ -46,6 +49,7 @@ fun ItemFromBike.toItem(): Item = Item (
dateTime, dateTime,
weight, weight,
radius, radius,
colorbike,
availableCount, availableCount,
bikeId bikeId
) )

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

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

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

@ -16,10 +16,11 @@
"rents": [], "rents": [],
"items": [ "items": [
{ {
"dateTime": 2020, "dateTime": 2009,
"weight": 23.6, "weight": 36.6,
"radius": 14, "radius": 14.5,
"maxCount": 5, "colorbike": "Красный",
"maxCount": 10,
"bikeId": 3, "bikeId": 3,
"id": 1 "id": 1
} }

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