Commit 1a5458da authored by gaodapeng's avatar gaodapeng

提测功能

parent 1d4c88d5
......@@ -21,8 +21,8 @@ android {
applicationId "com.miya.fastcashier"
minSdkVersion 19
targetSdkVersion 31
versionCode 2
versionName "2.0"
versionCode 21
versionName "2.1"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
......
......@@ -15,6 +15,7 @@ import com.miya.print.utils.PrintLogger
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import com.tencent.mmkv.MMKV
import java.lang.Exception
import java.lang.RuntimeException
import java.util.*
object PrintService {
......@@ -85,13 +86,14 @@ object PrintService {
fun printStatisticInfo(
viewOrderStatisticsInfo: ViewOrderStatisticsInfo,
selfCashierAccountInfo: SelfCashierAccountInfo,
isBalance: Boolean
) {
val printer = PrinterManager.getInstance().printer
printer.beginPrint()
//检查打印机状态
printer.printerStatus
printer.set58mm()
doPrintStatisticInfo(printer, viewOrderStatisticsInfo, selfCashierAccountInfo)
doPrintStatisticInfo(printer, viewOrderStatisticsInfo, selfCashierAccountInfo, isBalance)
printer.feedPaper()
printer.endPrint()
}
......@@ -100,37 +102,31 @@ object PrintService {
private fun doPrintStatisticInfo(
printer: IPrinter,
orderStatisticsInfo: ViewOrderStatisticsInfo,
accountInfo: SelfCashierAccountInfo
accountInfo: SelfCashierAccountInfo,
isBalance: Boolean
) {
printer.beginPrint()
//[小票内容优化] 去除'欢迎光临'
printer.printText(accountInfo.shopInfo?.storeName ?: "")
if (accountInfo.shopInfo == null) {
throw RuntimeException("无商户配置数据")
}
val shopInfo = accountInfo.shopInfo
printer.printText(IPrinter.ALIGN_CENTER, 3, accountInfo.shopInfo?.storeName ?: "", true)
if (isBalance) {
printer.printText(IPrinter.ALIGN_CENTER, 3, "结算总计单", true)
} else {
printer.printText(IPrinter.ALIGN_CENTER, 3, "交易汇总表", true)
}
printer.setAlign(IPrinter.ALIGN_LEFT)
printer.printText("商户名称:converse")
printer.printText("商户编号:${shopInfo.saasid}")
printer.printText("终端编号:${shopInfo.posId}")
printer.printText("门店编号:${shopInfo.storeId}")
//统计时间
printer.printText(0, 0, "开始时间:" + orderStatisticsInfo.beginDate, true)
printer.printText(0, 0, "结束时间:" + orderStatisticsInfo.endDate, true)
// //打印分割线-居左
printer.printText(0, 0, Page58MmPrintUtils.printDivideLineString(), true)
// //打印门店号、收银机号、收银员号在一行打印显示
if (!TextUtils.isEmpty(
accountInfo.shopInfo?.operatorId
)
) {
printer.printText(
Page58MmPrintUtils.printTwoData(
"门店号:" + accountInfo.shopInfo?.storeId
.toString() + " 收银机号:" + accountInfo.shopInfo?.posId,
"收银员号:" + accountInfo.shopInfo?.operatorId
)
)
} else {
printer.printText(
Page58MmPrintUtils.printTwoData(
"门店号:" + accountInfo.shopInfo?.storeId,
"收银机号:" + accountInfo.shopInfo?.posId
)
)
}
val totalStatistics: ViewOrderStatisticsInfo.StatisticBean? =
orderStatisticsInfo.totalStatistic
if (totalStatistics != null) {
......@@ -148,9 +144,10 @@ object PrintService {
)
)
}
val typedStatisticList: List<ViewOrderStatisticsInfo.StatisticBean> =
orderStatisticsInfo.typeStatistic
if (!isEmpty(typedStatisticList)) {
if (!isEmpty(orderStatisticsInfo.typeStatistic)) {
val typedStatisticList: List<ViewOrderStatisticsInfo.StatisticBean> =
orderStatisticsInfo.typeStatistic
var statisticBean: ViewOrderStatisticsInfo.StatisticBean
for (i in typedStatisticList.indices) {
if (typedStatisticList[i] == null) {
......@@ -176,8 +173,28 @@ object PrintService {
"" + StringPriceFormat.transStringPriceToDecimalString(statisticBean.tradeTotalAmount.toString())
)
)
if (statisticBean.refundCount > 0) {
printer.printText(
Page58MmPrintUtils.printTwoData(
"退款笔数",
"" + statisticBean.refundCount
)
)
}
if (statisticBean.refundTotalAmount > 0) {
printer.printText(
Page58MmPrintUtils.printTwoData(
"退款金额",
"" + StringPriceFormat.transStringPriceToDecimalString(statisticBean.refundTotalAmount.toString())
)
)
}
}
}
printer.printText("\n\n")
}
......@@ -477,7 +494,7 @@ object PrintService {
* //todo 定期删除机制
*/
private fun getSerialNoByOrderNo(orderNo: String): String {
return MMKV.defaultMMKV().getString(orderNo, "00000").toString();
return MMKV.defaultMMKV().getString(orderNo, "00000").toString()
}
private fun setSerialNoByOrderNo(orderNo: String, serialNo: String) {
......
......@@ -74,12 +74,31 @@ class MainActivity : BaseActivity() {
binding.llStatistic.clickWithTrigger {
if (dateSelectHelper == null) {
dateSelectHelper = DateSelectHelper(this@MainActivity) {
viewModel.orderStatistics(it,Date())
viewModel.orderStatistics(it, Date(), false)
}
}
dateSelectHelper!!.showDatePicker()
}
binding.llBalance.clickWithTrigger {
//上次记录的时间,或者当天0点
val timeMillis = MMKV.defaultMMKV().getLong("balanceDate", 0L)
if (timeMillis > 0L && timeMillis <= System.currentTimeMillis()) {
viewModel.orderStatistics(Date(timeMillis), Date(), true)
} else {
val startDate = Calendar.getInstance()
startDate.set(
startDate.get(Calendar.YEAR),
startDate.get(Calendar.MONTH),
startDate.get(Calendar.DAY_OF_MONTH),
0,
0,
0
)
viewModel.orderStatistics(startDate.time, Date(), true)
}
}
initData()
}
......@@ -93,6 +112,15 @@ class MainActivity : BaseActivity() {
CenterToasty.error(this@MainActivity, e.message ?: "").show()
}
})
viewModel.balanceLiveData.observe(this, { result ->
result.onSuccess {
MMKV.defaultMMKV().putLong("balanceDate", it)
}
result.onFailure { e ->
CenterToasty.error(this@MainActivity, e.message ?: "").show()
}
})
}
......
......@@ -208,6 +208,7 @@ class SearchOrderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
binding.tvRefundTag.visibility = View.GONE
binding.tvPrice.text =
"¥" + StringPriceFormat.transStringPriceToDecimalString(data.tradPrice)
binding.tvOrderNo.text = data.orderNo
}
}
......
package com.miya.fastcashier.utils
import android.content.Context
import android.text.TextUtils
fun isEmpty(s: String?): Boolean {
......@@ -7,5 +8,10 @@ fun isEmpty(s: String?): Boolean {
}
fun isEmpty(list: List<Any>?): Boolean {
return list != null && list.isNotEmpty()
return list == null || list.isEmpty()
}
fun sp2px(context: Context, spValue: Float): Int {
val fontScale: Float = context.resources.displayMetrics.scaledDensity
return (spValue * fontScale + 0.5f).toInt()
}
\ No newline at end of file
......@@ -40,6 +40,7 @@ class DateSelectHelper(val context: Context, val callback: (Date) -> Unit) {
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH),
0,
0,
0
)
endDate.set(
......@@ -55,6 +56,9 @@ class DateSelectHelper(val context: Context, val callback: (Date) -> Unit) {
.setTitleText("请选择开始时间")
.setType(booleanArrayOf(false, false, false, true, true, false))
.setDate(startDate)
.setContentTextSize(30)
.setTitleSize(30)
.setSubCalSize(30)
.setRangDate(startDate, endDate)
.build()
}
......
......@@ -11,6 +11,8 @@ import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.net.BaseResult
import com.miya.fastcashier.service.LoginService
import com.miya.fastcashier.beans.LoginFormState
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.lang.RuntimeException
......@@ -21,21 +23,30 @@ class LoginViewModel : ViewModel() {
val loginFormState: LiveData<LoginFormState> = _loginForm
fun login(userName:String,passWord:String) {
viewModelScope.launch {
val result = try {
Result.success(errorHandle(LoginService.getApi().login(LoginRequest(userName,passWord,""))))
fun login(userName: String, passWord: String) {
viewModelScope.launch(Dispatchers.IO) {
try {
val result = Result.success(
errorHandle(LoginService.getApi().login(LoginRequest(userName, passWord, "")))
)
//MMKV记录结算时间
val balanceDate =
MMKV.defaultMMKV().getLong("balanceDate", 0L)
if (balanceDate <= 0L) {
//todo 改成服务器时间
MMKV.defaultMMKV().putLong("balanceDate", System.currentTimeMillis())
}
loginLiveData.postValue(result)
} catch (e: Exception) {
Result.failure(e)
loginLiveData.postValue(Result.failure(e))
}
// 注意这里是主线程,直接用setValue()即可
loginLiveData.value = result
}
}
//TODO 待优化
private fun <T> errorHandle(result: BaseResult<T>): T {
if(result.code != "200"){
if (result.code != "200") {
throw RuntimeException(result.msg)
}
return result.data;
......
......@@ -23,7 +23,8 @@ class MainViewModel : ViewModel() {
val refundLiveData: MutableLiveData<Result<PayRepository>> = MutableLiveData()
val statisticsLiveData: MutableLiveData<Result<Boolean>> = MutableLiveData()
val statisticsLiveData: MutableLiveData<Result<Long>> = MutableLiveData()
val balanceLiveData: MutableLiveData<Result<Long>> = MutableLiveData()
/**
* oriOrderNo 原订单号
......@@ -55,10 +56,12 @@ class MainViewModel : ViewModel() {
/**
* 订单统计
*/
fun orderStatistics(beginDate: Date, endDate: Date) {
fun orderStatistics(beginDate: Date, endDate: Date, isBalance: Boolean) {
val accountInfo = AccountService.getAccountInfo()
val liveData: MutableLiveData<Result<Long>> =
if (isBalance) balanceLiveData else statisticsLiveData
if (accountInfo == null) {
statisticsLiveData.value = Result.failure(RuntimeException("账户数据为空"))
liveData.value = Result.failure(RuntimeException("账户数据为空"))
return
}
val accountInfoFinal = accountInfo!!
......@@ -71,11 +74,11 @@ class MainViewModel : ViewModel() {
DateUtils.format18(beginDate),
DateUtils.format18(endDate)
)
PrintService.printStatisticInfo(info, accountInfoFinal)
statisticsLiveData.postValue(Result.success(true))
PrintService.printStatisticInfo(info, accountInfoFinal,isBalance)
liveData.postValue(Result.success(endDate.time))
} catch (e: Exception) {
e.printStackTrace()
statisticsLiveData.postValue(Result.failure(e))
liveData.postValue(Result.failure(e))
}
}
}
......
......@@ -48,7 +48,7 @@ class PayViewModel : ViewModel() {
refundPayServiceResponse = PayRepository.refundByOrderNo(refundParams)
XLog.d("退款成功:${JSON.toJSONString(refundPayServiceResponse)}")
//保存到数据库
ViewPayOrderData.insert(payServiceResponse)
ViewPayOrderData.insert(refundPayServiceResponse)
refundLiveData.postValue(Result.success(refundPayServiceResponse))
} catch (e: Exception) {
......
......@@ -50,6 +50,7 @@
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@id/tvPrice"
app:layout_constraintTop_toBottomOf="@id/tvPrice"
tools:text="退款金额" />
android:text="退款金额"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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