Commit 91ff0818 authored by zhaopengxiang's avatar zhaopengxiang

查询账单处理为按结算时间查询,查询后的单笔查询添加补打功能

parent 92357ce4
......@@ -4,6 +4,7 @@ import android.text.TextUtils
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.miya.fastcashier.dao.DatabaseKeeper
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.utils.isEmpty
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import java.lang.RuntimeException
......@@ -33,6 +34,7 @@ data class ViewPayOrderData(
val oriOrderPrice: String? = null,//订单原价
val refundPrice: String? = null,//退款价格
val payQrCode: String? = null,//支付条码
val userName: String? = null
) {
companion object {
......@@ -58,11 +60,35 @@ data class ViewPayOrderData(
refundOrderNo = payServiceResponse.refundOrderNo,
oriOrderPrice = payServiceResponse.oriOrderPrice,
refundPrice = payServiceResponse.refundPrice,
payQrCode = payServiceResponse.payQrCode
payQrCode = payServiceResponse.payQrCode,
userName = AccountService.getUserName(),
)
}
fun transformPayServiceResponse(orderData: ViewPayOrderData): PayServiceResponse {
var payServiceResponse = PayServiceResponse()
payServiceResponse.shopTradeNo = orderData.orderNo
payServiceResponse.tradStatus = orderData.tradStatus
payServiceResponse.chanelSerialNumber = orderData.tradeNo
payServiceResponse.tradPrice = orderData.tradPrice
payServiceResponse.chanelTag = orderData.chanelTag
payServiceResponse.buyerId = orderData.buyerId
payServiceResponse.couponMessage = orderData.couponMessage
payServiceResponse.chanelOrderTradeTime = orderData.chanelOrderTradeTime
payServiceResponse.miyaResponseTime = orderData.miyaResponseTime
payServiceResponse.miyaOrderDesc = orderData.miyaOrderDesc
payServiceResponse.vipShopTag = orderData.vipShopTag
payServiceResponse.buyerAccount = orderData.buyerAccount
payServiceResponse.memberCardNumber = orderData.memberCardNumber
payServiceResponse.platformName = orderData.platformName
payServiceResponse.refundOrderNo = orderData.refundOrderNo
payServiceResponse.oriOrderPrice = orderData.oriOrderPrice
payServiceResponse.refundPrice = orderData.refundPrice
payServiceResponse.payQrCode = orderData.payQrCode
return payServiceResponse
}
fun insert(payServiceResponse: PayServiceResponse) {
if (TextUtils.isEmpty(payServiceResponse.shopTradeNo)) {
return
......
......@@ -8,7 +8,7 @@ import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
@Dao
interface PayDataDao {
companion object{
companion object {
const val NUM_OF_SINGLE_PAGE = 10
}
......@@ -30,6 +30,12 @@ interface PayDataDao {
beginIndex: Int
): MutableList<ViewPayOrderData>
@Query("SELECT * FROM pay_data WHERE chanelTag =:payType ORDER BY id DESC ")
fun queryAllWithType(payType: String): MutableList<ViewPayOrderData>
@Query("SELECT * FROM pay_data WHERE chanelTag =:payType AND userName=:userName ORDER BY id DESC ")
fun queryAllWithTypeAndName(payType: String,userName:String): MutableList<ViewPayOrderData>
@Query("SELECT COUNT(*) FROM pay_data WHERE chanelTag =:payType")
fun sizeOfType(payType: String): Int
......
......@@ -5,9 +5,12 @@ import androidx.room.RoomDatabase
import com.miya.fastcashier.beans.ViewPayOrderData
import androidx.room.Room
import com.miya.fastcashier.utils.ContextUtils
import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.room.migration.Migration
@Database(entities = [ViewPayOrderData::class],exportSchema=false, version = 1)
@Database(entities = [ViewPayOrderData::class], exportSchema = false, version = 2)
abstract class PayDatabase : RoomDatabase() {
abstract fun payDataDao(): PayDataDao
}
......@@ -16,12 +19,18 @@ abstract class PayDatabase : RoomDatabase() {
class DatabaseKeeper {
companion object {
private val DATABASE_NAME = "pay_data"
val payDatabase: PayDatabase by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
Room.databaseBuilder(
ContextUtils.getContext(),
PayDatabase::class.java, "pay_data"
).build()
Room.databaseBuilder(ContextUtils.getContext(), PayDatabase::class.java, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.build()
}
val MIGRATION_1_2: Migration = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("alter table pay_data add userName Text")
}
}
}
}
......@@ -25,7 +25,6 @@ object PrintService {
private var payServiceResponse: PayServiceResponse? = null;
/**
* 退款
*/
......@@ -39,11 +38,53 @@ object PrintService {
printer.printerStatus
printer.set58mm()
refundPrintCashier(printer, payServiceResponse, selfCashierAccountInfo)
refundPrintCustomer(printer, payServiceResponse, selfCashierAccountInfo)
// refundPrintCustomer(printer, payServiceResponse, selfCashierAccountInfo)
printer.feedPaper()
printer.endPrint()
}
/**
* 查询订单单项打印
*/
fun printSearchOrder(
selfCashierAccountInfo: SelfCashierAccountInfo,
payServiceResponse: PayServiceResponse,
isRefund: Boolean
) {
if (isRefund) {
refundPrint(selfCashierAccountInfo, payServiceResponse)
} else {
val printer = PrinterManager.getInstance().printer
printer.beginPrint()
//检查打印机状态
printer.printerStatus
printer.set58mm()
if (BuildConfig.DEBUG) {
printCashier(
printer,
payServiceResponse,
selfCashierAccountInfo,
OrderRecordManageKit.getSerialNoByOrderNo(payServiceResponse.shopTradeNo))
} else {
printCashier(
printer,
payServiceResponse,
selfCashierAccountInfo,
OrderRecordManageKit.getSerialNoByOrderNo(payServiceResponse.shopTradeNo)
)
printCustomer(
printer,
payServiceResponse,
selfCashierAccountInfo,
OrderRecordManageKit.getSerialNoByOrderNo(payServiceResponse.shopTradeNo)
)
}
printer.feedPaper()
printer.endPrint()
}
}
/**
* 打印上一单
*/
......
......@@ -14,6 +14,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.elvishew.xlog.XLog
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.miya.fastcashier.R
......@@ -22,9 +23,12 @@ import com.miya.fastcashier.dao.PayDataDao
import com.miya.fastcashier.databinding.ActivitySearchOrderBinding
import com.miya.fastcashier.databinding.FragmentSearchOrderBinding
import com.miya.fastcashier.databinding.ItemSearchOrderListBinding
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService
import com.miya.fastcashier.utils.*
import com.miya.fastcashier.viewmodel.SearchOrderViewModel
import com.miya.fastcashier.widget.Divider
import com.tencent.mmkv.MMKV
/**
* 查单列表
......@@ -51,7 +55,6 @@ class SearchOrderActivity : BaseActivity() {
}
}
TabLayoutMediator(
binding.tlIndicator,
binding.vpPage
......@@ -62,9 +65,7 @@ class SearchOrderActivity : BaseActivity() {
else -> tab.text = ""
}
}.attach()
}
}
......@@ -73,8 +74,11 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
private lateinit var adapter: SearchOrderListAdapter
private lateinit var vm: SearchOrderViewModel
private var onLoading = false
// private var onLoading = false
private var isEnd = false
private var balanceDate = 0L
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
......@@ -90,7 +94,8 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
return
}
isEnd = false
onLoading = false
// onLoading = false
balanceDate = MMKV.defaultMMKV().getLong("balanceDate", 0L)
val act = requireActivity()
binding?.run {
adapter = SearchOrderListAdapter(act, arrayListOf())
......@@ -109,43 +114,43 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
}
}
)
rvContent.addOnScrollListener(object : RecyclerView.OnScrollListener() {
//用来标记是否正在向最后一个滑动
var isSlidingToLast = false
override fun onScrollStateChanged(
recyclerView: RecyclerView,
newState: Int
) {
if (isEnd) { //如果已经加载完成,就不处理
return
}
val manager = recyclerView.layoutManager as LinearLayoutManager?
// 当不滚动时
if (manager != null && newState == RecyclerView.SCROLL_STATE_IDLE) {
//获取最后一个完全显示的ItemPosition
val lastVisibleItem = manager.findLastCompletelyVisibleItemPosition()
val totalItemCount = manager.itemCount
// 判断是否滚动到底部,并且是向右滚动
if (!onLoading && totalItemCount > 5 && lastVisibleItem > totalItemCount - 5 && isSlidingToLast) { //滑到最后5条的时候,如果不是列表已经结束,那么就
//加载更多功能的代码
onLoading = true
loadMore(adapter.itemCount)
}
}
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
//dx用来判断横向滑动方向,dy用来判断纵向滑动方向
isSlidingToLast = dy > 0
}
})
// rvContent.addOnScrollListener(object : RecyclerView.OnScrollListener() {
// //用来标记是否正在向最后一个滑动
// var isSlidingToLast = false
//
// override fun onScrollStateChanged(
// recyclerView: RecyclerView,
// newState: Int
// ) {
// if (isEnd) { //如果已经加载完成,就不处理
// return
// }
// val manager = recyclerView.layoutManager as LinearLayoutManager?
// // 当不滚动时
// if (manager != null && newState == RecyclerView.SCROLL_STATE_IDLE) {
// //获取最后一个完全显示的ItemPosition
// val lastVisibleItem = manager.findLastCompletelyVisibleItemPosition()
// val totalItemCount = manager.itemCount
//
// // 判断是否滚动到底部,并且是向右滚动
// if (!onLoading && totalItemCount > 5 && lastVisibleItem > totalItemCount - 5 && isSlidingToLast) { //滑到最后5条的时候,如果不是列表已经结束,那么就
// //加载更多功能的代码
// onLoading = true
// loadMore(adapter.itemCount)
// }
// }
// }
//
// override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
// //dx用来判断横向滑动方向,dy用来判断纵向滑动方向
// isSlidingToLast = dy > 0
// }
// })
}
vm = ViewModelProvider(this).get(SearchOrderViewModel::class.java)
vm.payDataLiveData.observe(act) {
onLoading = false
// onLoading = false
it.onFailure { e ->
CenterToasty.error(act, e.message ?: "", Toast.LENGTH_LONG).show()
}
......@@ -169,7 +174,6 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
}
}
initEmptyView()
loadMore(0)
}
......@@ -181,8 +185,9 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
private fun loadMore(loadIndex: Int) {
//加载更多
vm.getPayData(payType, loadIndex)
onLoading = true
// vm.getPayData(payType, loadIndex)
vm.getPayDataByTimeAndUser(payType,AccountService.getUserName(), balanceDate)
// onLoading = true
}
override fun onDestroyView() {
......@@ -253,6 +258,45 @@ class SearchOrderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
)
)
}
binding.vBg.setOnLongClickListener {
binding.groupPrinter.visibility = View.VISIBLE
true
}
binding.tvPrinter.setOnClickListener(object : View.OnClickListener {
override fun onClick(p0: View?) {
binding.groupPrinter.visibility = View.GONE
printer(data)
}
})
binding.vPrinter.setOnClickListener(object : View.OnClickListener {
override fun onClick(p0: View?) {
binding.groupPrinter.visibility = View.GONE
}
})
}
fun printer(data: ViewPayOrderData) {
var isRefund: Boolean = data.refundOrderNo != null && data.refundPrice != null
//退款打印
try {
XLog.d("开始打印")
AccountService.getAccountInfo()
?.let {
ViewPayOrderData.transformPayServiceResponse(data)?.let { it1 ->
PrintService.printSearchOrder(
it,
it1,
isRefund
)
}
}
} catch (e: Exception) {
e.printStackTrace()
XLog.d("打印异常${e.message}")
}
}
}
\ No newline at end of file
package com.miya.fastcashier.utils.manage
import com.blankj.utilcode.util.LogUtils
import com.miya.fastcashier.utils.DateUtils
import com.tencent.mmkv.MMKV
import java.util.*
......@@ -77,7 +76,6 @@ class OrderRecordManageKit {
*/
private fun isYeaterdayOrderRecordExist(): Boolean {
val actualSize = getYesterdayOrderMMKV().actualSize()
LogUtils.e("Yeaterday actualSize","$actualSize")
return actualSize > 0
}
......
package com.miya.fastcashier.viewmodel
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.beans.ViewPayOrderData
import com.miya.fastcashier.dao.DatabaseKeeper
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import com.miya.fastcashier.utils.isEmpty
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.lang.Exception
import com.miya.fastcashier.beans.ViewPayOrderData as ViewPayOrderData1
class SearchOrderViewModel : ViewModel() {
val payDataLiveData: MutableLiveData<Result<List<ViewPayOrderData>>> = MutableLiveData()
val payDataLiveData: MutableLiveData<Result<List<ViewPayOrderData1>>> = MutableLiveData()
/**
* 获取
* 获取所有订单,分页处理
*/
fun getPayData(payType: MiYaPayPlantformPayWayEnum.MiyaPayType, currentSize: Int) {
viewModelScope.launch(Dispatchers.IO) {
......@@ -32,4 +35,45 @@ class SearchOrderViewModel : ViewModel() {
}
}
/**
* 根据时间、用户获取订单,不分页
*/
fun getPayDataByTimeAndUser(
payType: MiYaPayPlantformPayWayEnum.MiyaPayType,
userName: String,
limitTime: Long
) {
viewModelScope.launch(Dispatchers.IO) {
try {
val list = DatabaseKeeper.payDatabase.payDataDao()
.queryAllWithTypeAndName(payType = payType.code, userName)
if (limitTime == 0L) {
payDataLiveData.postValue(Result.success(list))
return@launch
}
val destList: MutableList<ViewPayOrderData1> = arrayListOf()
if (!isEmpty(list)) {
for (order in list) {
val tradeDate: String = order.chanelOrderTradeTime
if (!TextUtils.isEmpty(tradeDate) &&
DateUtils.stringToLong(
tradeDate,
DateUtils.DF_YYYY_MM_DDHHMMSS
) > limitTime
) {
destList.add(order)
}
}
}
payDataLiveData.postValue(Result.success(destList))
} catch (e: Exception) {
e.printStackTrace()
payDataLiveData.postValue(Result.failure(e))
}
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/transparent_60" />
<corners android:radius="16dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white" />
</shape>
\ No newline at end of file
......@@ -120,4 +120,36 @@
app:layout_goneMarginEnd="24dp"
tools:text="¥200.99" />
<View
android:id="@+id/vPrinter"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/app_bg_search_order_printer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvPrinter"
android:layout_width="120dp"
android:layout_height="120dp"
app:layout_constraintTop_toTopOf="@id/vPrinter"
app:layout_constraintBottom_toBottomOf="@id/vPrinter"
app:layout_constraintStart_toStartOf="@id/vPrinter"
app:layout_constraintEnd_toEndOf="@id/vPrinter"
android:text="打印"
android:textStyle="bold"
android:gravity="center"
android:textColor="@color/colorPrimary"
android:textSize="28sp"
android:background="@drawable/app_bg_search_order_printer_btn" />
<androidx.constraintlayout.widget.Group
android:id="@+id/groupPrinter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="tvPrinter,vPrinter"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -7,6 +7,7 @@
<!--50代表透明度-->
<color name="colorPrimary_50">#80111235</color>
<color name="transparent">#00000000</color>
<color name="transparent_60">#99000000</color>
<color name="green">#06C261</color>
<color name="blue">#2E6CFB</color>
<color name="color_333333">#333333</color>
......
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