Commit 21d3c2dd authored by UIUANG\Zsc's avatar UIUANG\Zsc

可修改商品份数

parent 1020cb50
......@@ -3,16 +3,23 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/bg_cancel_bg.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/bg_dialog.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/bg_popup_offer_details.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/btn_confirm_bg.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/edit_bg.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/ic_print_receipt.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/drawable/ic_synchronize_products.xml" value="0.3508682328907048" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/activity_login.xml" value="0.16347124117053483" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/activity_main.xml" value="0.16347124117053483" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/activity_register.xml" value="0.16347124117053483" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/item_pos_product.xml" value="0.5" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_cash_pay.xml" value="0.33" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_cash_pay_success.xml" value="0.33" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_change_quantity.xml" value="0.4703703703703704" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_order_pay_amount.xml" value="0.16347124117053483" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_pay_success.xml" value="0.16347124117053483" />
<entry key="..\:/AndroidProject/YPPos/app/src/main/res/layout/popup_settings.xml" value="0.16347124117053483" />
</map>
</option>
</component>
......
......@@ -15,8 +15,8 @@ android {
applicationId "com.ypsx.yppos"
minSdkVersion 21
targetSdkVersion 30
versionCode 100011
versionName "1.00.011"
versionCode 100014
versionName "1.00.014"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
......@@ -124,6 +124,10 @@ dependencies {
implementation 'com.github.jenly1314.AppUpdater:app-updater:1.1.0'
implementation 'com.github.getActivity:ToastUtils:9.5'
implementation 'com.aliyun.dpa:oss-android-sdk:2.1.0'
// 友盟统计SDK
implementation 'com.umeng.umsdk:common:9.4.2'// 必选
implementation 'com.umeng.umsdk:asms:1.4.0'// 必选
implementation 'com.umeng.umsdk:apm:1.5.2'//崩溃
// val work_version = "2.6.0"
// Kotlin + coroutines
......
......@@ -10,9 +10,9 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 100011,
"versionName": "1.00.011",
"outputFile": "yppos_v100011-1.00.011-release-2021-11-29.apk"
"versionCode": 100014,
"versionName": "1.00.014",
"outputFile": "yppos_v100014-1.00.014-release-2021-12-22.apk"
}
]
}
\ No newline at end of file
package com.ypsx.yppos
import android.os.Build
import android.os.Bundle
import com.hjq.toast.ToastUtils
import com.uc.crashsdk.export.CrashApi
import com.umeng.analytics.MobclickAgent
import com.umeng.commonsdk.UMConfigure
import com.ypsx.base.base.BaseApp
import com.ypsx.base.util.dXLog
import com.ypsx.common.app.event.AppViewModel
......@@ -27,7 +31,21 @@ class PosApp : BaseApp() {
eventViewModelInstance = getAppViewModelProvider().get(EventViewModel::class.java)
appViewModelInstance = getAppViewModelProvider().get(AppViewModel::class.java)
initXlog()
UMConfigure.setLogEnabled(false);
//初始化组件化基础库, 所有友盟业务SDK都必须调用此初始化接口。
UMConfigure.init(
this,
"61c283dce0f9bb492ba44479",
"yp_pos",
UMConfigure.DEVICE_TYPE_PHONE,
""
);
// 选用AUTO页面采集模式
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO)
val customInfo = Bundle()
customInfo.putBoolean("mCallNativeDefaultHandler", true)
CrashApi.getInstance().updateCustomInfo(customInfo)
}
......@@ -41,13 +59,9 @@ class PosApp : BaseApp() {
"\nApp VersionName : " + BuildConfig.VERSION_NAME +
"\nApp VersionCode : " + BuildConfig.VERSION_CODE +
"\n<<<<<<<<<<<<<<<< File Header <<<<<<<<<<<<<<<<\n\n";
header.dXLog()
header.dXLog()
}
}
\ No newline at end of file
package com.ypsx.yppos.http.data.bean
class PluRelation(var plu: String, var id: String)
......@@ -14,6 +14,7 @@ import com.ypsx.yppos.http.data.entity.PosStatus
import com.ypsx.yppos.http.data.request.*
import com.ypsx.yppos.room.database.PosDatabase
import com.ypsx.yppos.room.database.name
import com.ypsx.yppos.room.entity.PosProduct
import com.ypsx.yppos.room.repository.PosConfigRepository
import com.ypsx.yppos.room.repository.PosProductRepository
import com.ypsx.yppos.ui.popup.PayAmountPopupWindow
......@@ -314,5 +315,19 @@ class HttpRequestManger {
}
}
suspend fun syncProducts(storeId: String) :ApiResponse<List<PosProduct>>{
val updateTimeBigger = CacheUtil.getUpdateTimeBigger()
val todayDateTime = DateUtil.getTodayDateTime()
val productData = apiService.getProductList(storeId, updateTimeBigger)
if (productData.isSuccess()) {
val data = productData.data
CacheUtil.setUpdateTimeBigger(todayDateTime)
PosProductRepository.getInstance().insertAll(data)
return productData
}
throw AppException(productData.code, productData.message)
}
}
\ No newline at end of file
......@@ -21,6 +21,9 @@ interface PosProductDao {
@Query("SELECT id from POS_Product WHERE barCode=:key OR productNumber=:key OR mnemonicCode=:key LIMIT 0,1")
fun queryKeyWords2(key: String): String?
// @Query("SELECT * from POS_Product WHERE length(name)>20 ORDER BY length(name) DESC")
// fun queryAllByProductId2(productId: ArrayList<String>): List<PosProduct>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(vararg list: PosProduct?)
......
......@@ -62,6 +62,11 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
CacheUtil.getAliYunKey().dXLog()
requestLoginViewModel.upgradeApk(mViewModel.posId.get())
// if (mDatabind.etAccount.text?.length == 11) {
// mDatabind.etPassword.isFocusable = true;
// mDatabind.etPassword.isFocusableInTouchMode = true;
// mDatabind.etPassword.requestFocus() //获取焦点
// }
}
......
......@@ -51,9 +51,9 @@ class OrderProductAdapter(data: ArrayList<InsertOrderProductDTO>) :
holder.setText(R.id.tv_count, "${quantity.toInt()}")
}
PosProductStyle.WEIGHT.name -> {
holder.setGone(R.id.ll_count, true)
holder.setGone(R.id.tv_weight, false)
holder.setText(R.id.tv_weight, "$quantity$unit")
holder.setGone(R.id.ll_count, false)
holder.setGone(R.id.tv_weight, true)
holder.setText(R.id.tv_count, "$quantity")
}
else -> {
......
......@@ -15,7 +15,7 @@ import com.ypsx.yppos.databinding.PopupCashPayBinding
import com.ypsx.yppos.http.data.entity.PosPayMethod
import com.ypsx.yppos.room.entity.PosConfig
import com.ypsx.yppos.room.repository.PosConfigRepository
import com.ypsx.yppos.utils.CashierInputFilter
import com.ypsx.yppos.utils.filter.CashierInputFilter
import com.ypsx.yppos.utils.toastFailed
import com.ypsx.yppos.viewmodel.state.CashPayViewModel
import kotlinx.coroutines.*
......
package com.ypsx.yppos.ui.popup
import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import com.ypsx.base.base.appContext
import com.ypsx.base.ext.util.screenWidth
import com.ypsx.yppos.R
import com.ypsx.yppos.databinding.PopupChangeQuantityBinding
import com.ypsx.yppos.http.data.bean.InsertOrderProductDTO
import com.ypsx.yppos.http.data.entity.PosProductStyle
import com.ypsx.yppos.room.entity.PosProduct
import com.ypsx.yppos.utils.filter.NumberInputFilter
import com.ypsx.yppos.utils.filter.WeighInputFilter
import com.ypsx.yppos.utils.toast
import com.ypsx.yppos.viewmodel.state.ChangeQuantityViewModel
import razerdp.basepopup.BasePopupWindow
import java.math.BigDecimal
class ChangeQuantityPopupWindow(context: Context) : BasePopupWindow(context) {
lateinit var bind: PopupChangeQuantityBinding
private var type: Int = 0
var onChangeClick: OnChangeClick? =null
private var posProduct: PosProduct? = null
private var insertOrderProductDTO: InsertOrderProductDTO?=null
init {
setContentView(R.layout.popup_change_quantity)
width = appContext.screenWidth / 4 * 3
popupGravity = Gravity.CENTER
isOutSideTouchable = false
setOutSideDismiss(false)
}
override fun onViewCreated(contentView: View) {
// 透出应付金额,应付金额四舍五入到分位(记录舍分金额)
bind = PopupChangeQuantityBinding.bind(contentView)
bind.vm = ChangeQuantityViewModel()
bind.click = ProxyClick()
setAutoShowKeyboard(bind.etPurchaseQuantity, true)
setKeyboardAdaptive(true)
setKeyboardAdaptionMode(
bind.textView23,
FLAG_KEYBOARD_ALIGN_TO_ROOT or FLAG_KEYBOARD_ANIMATE_ALIGN
)
bind.etPurchaseQuantity.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
val imm: InputMethodManager =
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(
bind.etPurchaseQuantity.windowToken,
InputMethodManager.HIDE_NOT_ALWAYS
)
return@setOnEditorActionListener true
}
return@setOnEditorActionListener false
}
}
@JvmName("setOnChangeClick1")
fun setOnChangeClick(onChangeClick: OnChangeClick) {
this.onChangeClick = onChangeClick
}
fun setPosProduct(posProduct: PosProduct) {
this.type = 0
this.posProduct = posProduct
bind.vm?.productName?.set(posProduct.name)
var purchaseQuantityName :String
var spec = ""
when (posProduct.style) {
PosProductStyle.WEIGHT.name -> {
purchaseQuantityName = "购买重量"
spec = posProduct.spec
bind.vm?.productBarCode?.set("PLU:" + posProduct.mnemonicCode)
bind.etPurchaseQuantity.filters = arrayOf(WeighInputFilter())
}
PosProductStyle.SINGLE.name -> {
purchaseQuantityName = "购买数量"
spec = posProduct.spec.toInt().toString()
bind.vm?.productBarCode?.set("条码:" + posProduct.barCode)
bind.etPurchaseQuantity.filters = arrayOf(NumberInputFilter())
}
else -> {
purchaseQuantityName = ""
}
}
bind.vm?.purchaseQuantityName?.set(purchaseQuantityName)
bind.vm?.purchaseQuantity?.set(spec)
bind.etPurchaseQuantity.setText(spec)
val length = bind.etPurchaseQuantity.text.toString().length
bind.etPurchaseQuantity.setSelection(length)
bind.etPurchaseQuantity.isFocusable = true;
bind.etPurchaseQuantity.isFocusableInTouchMode = true;
bind.etPurchaseQuantity.requestFocus() //获取焦点
}
fun setOrderProduct(insertOrderProductDTO: InsertOrderProductDTO) {
this.type = 1
this.insertOrderProductDTO = insertOrderProductDTO
bind.vm?.productName?.set(insertOrderProductDTO.name)
var purchaseQuantityName :String
var spec = ""
when (insertOrderProductDTO.style) {
PosProductStyle.WEIGHT.name -> {
purchaseQuantityName = "修改重量"
spec = insertOrderProductDTO.quantity.toString()
bind.vm?.productBarCode?.set("PLU:" + insertOrderProductDTO.mnemonicCode)
bind.etPurchaseQuantity.filters = arrayOf(WeighInputFilter())
}
PosProductStyle.SINGLE.name -> {
purchaseQuantityName = "修改数量"
spec = insertOrderProductDTO.quantity.toInt().toString()
bind.vm?.productBarCode?.set("条码:" + insertOrderProductDTO.barCode)
bind.etPurchaseQuantity.filters = arrayOf(NumberInputFilter())
}
else -> {
purchaseQuantityName = ""
}
}
bind.vm?.purchaseQuantityName?.set(purchaseQuantityName)
bind.vm?.purchaseQuantity?.set(spec)
bind.etPurchaseQuantity.setText(spec)
val length = bind.etPurchaseQuantity.text.toString().length
bind.etPurchaseQuantity.setSelection(length)
bind.etPurchaseQuantity.isFocusable = true;
bind.etPurchaseQuantity.isFocusableInTouchMode = true;
bind.etPurchaseQuantity.requestFocus() //获取焦点
}
inner class ProxyClick {
fun cancel() {
dismiss()
onChangeClick?.cancel()
}
fun confirm() {
val purchaseQuantity: String = bind.etPurchaseQuantity.text.toString()
if (purchaseQuantity.isEmpty()) {
"重量/数据不能为空".toast()
return
}
if (BigDecimal(purchaseQuantity) == BigDecimal.ZERO) {
"重量/数据不能为空".toast()
return
}
dismiss()
if (type == 0) {
posProduct?.spec = purchaseQuantity
onChangeClick?.confirm(posProduct!!,null)
}else{
insertOrderProductDTO?.quantity = purchaseQuantity.toDouble()
onChangeClick?.confirm(null,insertOrderProductDTO!!)
}
}
}
}
interface OnChangeClick{
fun cancel()
fun confirm(posProduct: PosProduct?,insertOrderProductDTO: InsertOrderProductDTO?)
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import com.umeng.analytics.MobclickAgent
import com.ypsx.base.base.appContext
import com.ypsx.base.ext.util.screenWidth
import com.ypsx.base.util.dXLog
......@@ -11,6 +12,9 @@ import com.ypsx.yppos.R
import com.ypsx.common.app.ext.startKtxActivityFinish
import com.ypsx.yppos.databinding.PopupSettingsBinding
import com.ypsx.yppos.http.apiService
import com.ypsx.yppos.http.data.entity.PosPayMethod
import com.ypsx.yppos.http.repository.request.HttpRequestCoroutine
import com.ypsx.yppos.http.repository.request.HttpRequestManger
import com.ypsx.yppos.room.repository.PosBuyRepository
import com.ypsx.yppos.room.repository.PosConfigRepository
import com.ypsx.yppos.ui.activity.LoginActivity
......@@ -24,8 +28,9 @@ import razerdp.util.animation.TranslationConfig
class SettingsPopupWindow(context: Context?) : BasePopupWindow(context) {
private lateinit var bind: PopupSettingsBinding
private val scope = MainScope()
private val scope = MainScope() + CoroutineName("SettingsPopupWindow")
private var settingsAction: () -> Unit =
{ -> }
init {
setContentView(R.layout.popup_settings)
width = appContext.screenWidth / 2
......@@ -104,6 +109,8 @@ class SettingsPopupWindow(context: Context?) : BasePopupWindow(context) {
}.onSuccess {
if (it.isSuccess()) {
messagePopupWindow.dismiss()
//登出
MobclickAgent.onProfileSignOff();
"${CacheUtil.getRealName()}主动退出主界面".dXLog()
val mainActivity =
this@SettingsPopupWindow.context as MainActivity
......@@ -117,7 +124,21 @@ class SettingsPopupWindow(context: Context?) : BasePopupWindow(context) {
}
}
}
}
fun syncProducts() {
dismiss()
settingsAction.invoke()
// scope.launch {
// withContext(Dispatchers.IO) {
// val posConfig = PosConfigRepository.getInstance().loadConfig()
// val storeId = posConfig?.storeId!!
// HttpRequestCoroutine.syncProducts(storeId)
// }
// }
}
}
fun setSyncProductsClick(settingsAction: () -> Unit) {
this.settingsAction = settingsAction
}
}
\ No newline at end of file
......@@ -21,21 +21,21 @@ import com.ypsx.yppos.room.entity.PosConfig
import java.math.BigDecimal
import java.math.RoundingMode
private const val PRNSTS_OK = 0 //OK
private const val PRNSTS_OUT_OF_PAPER = -1 //Out of paper
object PrintUtils {
private const val PRNSTS_OK = 0 //OK
private const val PRNSTS_OVER_HEAT = -2 //Over heat
private const val PRNSTS_OUT_OF_PAPER = -1 //Out of paper
private const val PRNSTS_UNDER_VOLTAGE = -3 //under voltage
private const val PRNSTS_OVER_HEAT = -2 //Over heat
private const val PRNSTS_BUSY = -4 //Device is busy
private const val PRNSTS_UNDER_VOLTAGE = -3 //under voltage
private const val PRNSTS_ERR = -256 //Common error
private const val PRNSTS_BUSY = -4 //Device is busy
private const val PRNSTS_ERR_DRIVER = -257 //Printer Driver error
private const val PRNSTS_ERR = -256 //Common error
object PrintUtils {
private const val PRNSTS_ERR_DRIVER = -257 //Printer Driver error
private lateinit var printerManager: PrinterManager
fun init() {
printerManager = PrinterManager()
......@@ -80,8 +80,14 @@ object PrintUtils {
"机号:${posConfig.code}", 0, height, 384, -1, fontName, fontSize, 0, fontStyle, 0
)
val loginResponse = CacheUtil.getLoginResponse()
var realName = loginResponse!!.loginUser.realName
if (realName!!.length >= 2) {
val first = realName.substring(0, 1)
val end = realName.substring(2)
realName = "$first*$end"
}
height += printerManager.drawTextEx(
"收银员:${loginResponse!!.loginUser.realName}",
"收银员:${realName}",
0,
height,
384,
......@@ -137,7 +143,7 @@ object PrintUtils {
var discountMoney = 0.0
if (product.activitys != null) {
product.activitys!!.forEach { item ->
discountMoney = product.price - item.activityPrice
discountMoney = (product.price - item.activityPrice) * product.quantity
if (item.activityType == ProductActivityType.TIMESHARE_ACTIVITY.name) {
discountTime += discountMoney
} else {
......@@ -163,11 +169,14 @@ object PrintUtils {
buyNum += product.quantity.toInt()
}
val name = if (discountMoney > 0.0 && isPromotion) {
var name = if (discountMoney > 0.0 && isPromotion) {
"${index + 1} *${product.name}*"
} else {
"${index + 1} ${product.name}"
}
if (name.length > 17) {
name = name.substring(0, 15) + "..."
}
height += printerManager.drawTextEx(
name,
0,
......@@ -187,7 +196,7 @@ object PrintUtils {
product.paymentProductQuantity,
product.price,
product.productAmount
), 0, height, 384, -1, fontName, fontSize, 0, fontStyle, 0
), 0, height, 384, -1, fontName, 22, 0, 0, 0
)
}
......@@ -297,14 +306,14 @@ object PrintUtils {
PosPayMethod.CARDPAY.name -> {
"会员余额支付"
}
PosPayMethod.CASHPAY.name->{
PosPayMethod.CASHPAY.name -> {
"现金支付"
}
else -> {
""
}
}
}else{
} else {
payMethod = "现金支付"
}
height += printerManager.drawTextEx(
......@@ -411,22 +420,21 @@ object PrintUtils {
): String {
val builder = StringBuilder()
builder.append(barCode)
for (i in 0 until 15 - length(barCode)) {
for (i in 0 until 14 - length(barCode)) {
builder.append(" ")
}
builder.append(paymentProductQuantity.toString())
for (i in 0 until 5 - length(paymentProductQuantity.toString())) {
for (i in 0 until 6 - length(paymentProductQuantity.toString())) {
builder.append(" ")
}
builder.append(price.toString())
for (i in 0 until 7 - length(price.toString())) {
builder.append(" ")
}
builder.append(productAmount.toString())
for (i in 0 until 5 - length(productAmount.toString())) {
builder.append(price.toString())
for (i in 0 until 7 - length(productAmount.toString())) {
builder.append(" ")
}
builder.append(productAmount.toString())
return builder.toString()
}
......@@ -444,7 +452,7 @@ object PrintUtils {
return builder.toString()
}
fun length(value: String): Int {
private fun length(value: String): Int {
var valueLength = 0
val chinese: String = "[\u0391-\uFFE5]"
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
......@@ -532,8 +540,15 @@ object PrintUtils {
"机号:${posConfig.code}", 0, height, 384, -1, fontName, fontSize, 0, fontStyle, 0
)
val loginResponse = CacheUtil.getLoginResponse()
var realName = loginResponse!!.loginUser.realName
if (realName!!.length >= 2) {
val first = realName.substring(0, 1)
val end = realName.substring(2)
realName = "$first*$end"
}
height += printerManager.drawTextEx(
"收银员:${loginResponse!!.loginUser.realName}",
"收银员:${realName}",
0,
height,
384,
......@@ -620,8 +635,8 @@ object PrintUtils {
object : TypeToken<List<ActivityInfoDTO>>() {}.type
)
activityInfoDTO.forEach { item ->
item.toJson().dXLog()
discountMoney = product.price - item.activityPrice
// item.toJson().dXLog()
discountMoney = (product.price - item.activityPrice) * product.quantity
if (item.activityType == ProductActivityType.TIMESHARE_ACTIVITY.name) {
discountTime += discountMoney
} else {
......@@ -642,7 +657,7 @@ object PrintUtils {
//
val name = if (discountMoney > 0.0 && isPromotion) {
var name = if (discountMoney > 0.0 && isPromotion) {
"${index + 1} *${product.name}*"
} else {
"${index + 1} ${product.name}"
......@@ -652,6 +667,9 @@ object PrintUtils {
} else if (product.style == PosProductStyle.SINGLE.name) {
buyNum += product.quantity.toInt()
}
if (name.length > 17) {
name = name.substring(0, 15) + "..."
}
height += printerManager.drawTextEx(
name,
0,
......@@ -792,7 +810,16 @@ object PrintUtils {
}
}
height += printerManager.drawTextEx(
"付款方式:$payMethod ${posBuy.totalAmount}", 0, height, 384, -1, fontName, fontSize, 0, fontStyle, 0
"付款方式:$payMethod ${posBuy.totalAmount}",
0,
height,
384,
-1,
fontName,
fontSize,
0,
fontStyle,
0
)
val scale = minus.setScale(2).toDouble()
height += printerManager.drawTextEx(
......
package com.ypsx.yppos.utils;
package com.ypsx.yppos.utils.filter;
import android.text.InputFilter;
import android.text.Spanned;
......
package com.ypsx.yppos.utils.filter
import android.text.InputFilter
import android.text.Spanned
import android.text.TextUtils
import java.util.regex.Pattern
class NumberInputFilter:InputFilter {
//输入的最大金额
private val MAX_VALUE = 999
//小数点后的位数
private val POINTER_LENGTH = 0
private val POINTER = "."
private val ZERO = "0"
var mPattern: Pattern? = null
init {
mPattern = Pattern.compile("([0-9]|)*")
}
override fun filter(
source: CharSequence?,
start: Int,
end: Int,
dest: Spanned?,
dstart: Int,
dend: Int
): CharSequence {
val sourceText = source.toString()
val destText = dest.toString()
//验证删除等按键
//验证删除等按键
if (TextUtils.isEmpty(sourceText)) {
return ""
}
val matcher = mPattern!!.matcher(source)
//已经输入小数点的情况下,只能输入数字
if (destText.contains(POINTER)) {
if (!matcher.matches()) {
return ""
} else {
if (POINTER == source.toString()) { //只能输入一个小数点
return ""
}
}
//验证小数点精度,保证小数点后只能输入两位
val index = destText.indexOf(POINTER)
val length = dend - index
if (length > POINTER_LENGTH) {
return dest!!.subSequence(dstart, dend)
}
} else {
/**
* 没有输入小数点的情况下,只能输入小数点和数字
* 1. 首位不能输入小数点
* 2. 如果首位输入0,则接下来只能输入小数点了
*/
if (!matcher.matches()) {
return ""
} else {
if (POINTER == source.toString() && TextUtils.isEmpty(destText)) { //首位不能输入小数点
return ""
} else if (POINTER != source.toString() && ZERO == destText) { //如果首位输入0,接下来只能输入小数点
return ""
}
}
}
//验证输入金额的大小
//验证输入金额的大小
val sumText = (destText + sourceText).toDouble()
return if (sumText > MAX_VALUE) {
dest!!.subSequence(dstart, dend)
} else dest!!.subSequence(dstart, dend).toString() + sourceText
}
}
\ No newline at end of file
package com.ypsx.yppos.utils.filter
import android.text.InputFilter
import android.text.Spanned
import android.text.TextUtils
import java.util.regex.Pattern
class WeighInputFilter: InputFilter {
//输入的最大金额
private val MAX_VALUE = 999.999
//小数点后的位数
private val POINTER_LENGTH = 3
private val POINTER = "."
private val ZERO = "0"
var mPattern: Pattern? = null
init {
mPattern = Pattern.compile("([0-9]|\\.)*")
}
/**
* @param source 新输入的字符串
* @param start 新输入的字符串起始下标,一般为0
* @param end 新输入的字符串终点下标,一般为source长度-1
* @param dest 输入之前文本框内容
* @param dstart 原内容起始坐标,一般为0
* @param dend 原内容终点坐标,一般为dest长度-1
* @return 输入内容
*/
override fun filter(
source: CharSequence?,
start: Int,
end: Int,
dest: Spanned?,
dstart: Int,
dend: Int
): CharSequence {
val sourceText = source.toString()
val destText = dest.toString()
//验证删除等按键
//验证删除等按键
if (TextUtils.isEmpty(sourceText)) {
return ""
}
val matcher = mPattern!!.matcher(source)
//已经输入小数点的情况下,只能输入数字
//已经输入小数点的情况下,只能输入数字
if (destText.contains(POINTER)) {
if (!matcher.matches()) {
return ""
} else {
if (POINTER == source.toString()) { //只能输入一个小数点
return ""
}
}
//验证小数点精度,保证小数点后只能输入两位
val index = destText.indexOf(POINTER)
val length = dend - index
if (length > POINTER_LENGTH) {
return dest!!.subSequence(dstart, dend)
}
} else {
/**
* 没有输入小数点的情况下,只能输入小数点和数字
* 1. 首位不能输入小数点
* 2. 如果首位输入0,则接下来只能输入小数点了
*/
if (!matcher.matches()) {
return ""
} else {
if (POINTER == source.toString() && TextUtils.isEmpty(destText)) { //首位不能输入小数点
return ""
} else if (POINTER != source.toString() && ZERO == destText) { //如果首位输入0,接下来只能输入小数点
return ""
}
}
}
//验证输入金额的大小
//验证输入金额的大小
val sumText = (destText + sourceText).toDouble()
return if (sumText > MAX_VALUE) {
dest!!.subSequence(dstart, dend)
} else dest!!.subSequence(dstart, dend).toString() + sourceText
}
}
\ No newline at end of file
package com.ypsx.yppos.viewmodel.request
import androidx.lifecycle.MutableLiveData
import com.umeng.analytics.MobclickAgent
import com.ypsx.base.base.viewmodel.BaseViewModel
import com.ypsx.base.ext.request
import com.ypsx.base.ext.requestNoCheck
......@@ -28,7 +29,7 @@ class RequestLoginViewModel : BaseViewModel() {
request({ HttpRequestCoroutine.posLogin(posId, storeId, username, password) }, {
val uiState = UpdateUiState(isSuccess = true, data = it)
posDetails.postValue(uiState)
MobclickAgent.onProfileSignIn(username);
}, {
if (it.errCode == 10025) {
......
package com.ypsx.yppos.viewmodel.request
import android.util.ArrayMap
import androidx.lifecycle.MutableLiveData
import com.elvishew.xlog.XLog
import com.ypsx.base.base.viewmodel.BaseViewModel
......@@ -31,7 +32,7 @@ import kotlin.collections.HashMap
*/
class RequestMainViewModel : BaseViewModel() {
// var productPromotionRequest = MutableLiveData<ProductPromotionRequest>()
var posProduct = MutableLiveData<PosProduct>()
var productItemData = MutableLiveData<ProductItem>()
var productPromotionsResponse = MutableLiveData<ProductPromotionsResponse>()
var posBuyPartData = MutableLiveData<List<PosBuyPart>>()
......@@ -46,6 +47,10 @@ class RequestMainViewModel : BaseViewModel() {
val paySuccessStateCash = MutableLiveData<UpdateUiState<CashPaySuccess>>()
val syncProductsState = MutableLiveData<UpdateUiState<String>>()
var pluList = arrayListOf<PluRelation>()
init {
launch({ PosConfigRepository.getInstance().loadConfig() }, {
posConfig = it
......@@ -55,9 +60,20 @@ class RequestMainViewModel : BaseViewModel() {
fun getPlu(barCode: String) {
val plu = barCode.substring(2, 7)
val weight = barCode.substring(7, 12)
val weightCode: Double = weight.toDouble().div(1000)
val mnemonicCode = plu.toInt().toString()
var price: Double = 0.0
var weightCode: Double = 0.0
if (barCode.length > 13) {
val priceCode = barCode.substring(7, 12)
price = priceCode.toDouble().div(100)
val weight = barCode.substring(12, 17)
weightCode = weight.toDouble().div(1000)
} else {
val weight = barCode.substring(7, 12)
weightCode = weight.toDouble().div(1000)
}
"$mnemonicCode $weightCode".dXLog()
launch({ PosProductRepository.getInstance().queryByMnemonicCode(mnemonicCode) }, {
......@@ -65,8 +81,14 @@ class RequestMainViewModel : BaseViewModel() {
"没找到该商品".toastSign()
} else {
it.toJson().dXLog()
map[it.id] = barCode
val productItem = ProductItem(it.merchantItemId!!, it.id, weightCode, it.sellPrice)
pluList.add(PluRelation(barCode, it.id))
// map[barCode] = it.id
val productItem = ProductItem(
it.merchantItemId!!,
it.id,
weightCode,
if (barCode.length > 13) price else it.sellPrice
)
productItem.toJson().dXLog()
productItemData.postValue(productItem)
......@@ -86,10 +108,11 @@ class RequestMainViewModel : BaseViewModel() {
"没找到该商品".toastSign()
} else {
it.toJson().dXLog()
val productItem =
ProductItem(it.merchantItemId!!, it.id, it.spec.toDouble(), it.sellPrice)
productItem.toJson().dXLog()
productItemData.postValue(productItem)
posProduct.postValue(it)
// val productItem =
// ProductItem(it.merchantItemId!!, it.id, it.spec.toDouble(), it.sellPrice)
// productItem.toJson().dXLog()
// productItemData.postValue(productItem)
}
}, {
......@@ -98,6 +121,16 @@ class RequestMainViewModel : BaseViewModel() {
)
}
fun addPluRelation(barcode: String, id: String) {
pluList.add(PluRelation(barcode, id))
}
fun removePluRelation(position: Int) {
if (pluList.size > position) {
pluList.removeAt(position)
}
}
fun request(request: ProductPromotionRequest) {
request({ apiService.getProductPromotions(request) }, {
"操作成功".toastSuccess()
......@@ -122,7 +155,7 @@ class RequestMainViewModel : BaseViewModel() {
var listNum = 0
var amountTotal = 0.0 //总价值
for (product in products) {
for ((index, product) in products.withIndex()) {
for (item in it) {
if (product.productId == item.id) {
posProduct = item
......@@ -137,8 +170,13 @@ class RequestMainViewModel : BaseViewModel() {
}
val amount: Double = product.price.times(product.quantity) ?: 0.0
amountTotal = BigDecimalUtils.forPlus(amountTotal.plus(amount))
var weightCode=""
if (pluList.size > index) {
weightCode =
if (pluList[index].id == posProduct?.id) pluList[index].plu else ""
}
val posBuyPart = InsertOrderProductDTO(
activitys = null,
activityPrice = 0.0,
......@@ -154,7 +192,7 @@ class RequestMainViewModel : BaseViewModel() {
price = product.price ?: 0.0,
quantity = product.quantity ?: 0.0,
tailAmount = 0,
weightCode = map[posProduct.id],
weightCode =weightCode,
name = posProduct.name,
spec = posProduct.spec,
unit = posProduct.unit,
......@@ -217,7 +255,7 @@ class RequestMainViewModel : BaseViewModel() {
var posProduct: PosProduct? = null
var listNum = 0
for (product in productPromotions) {
for ((index,product) in productPromotions.withIndex()) {
for (item in it) {
if (product.productId == item.id) {
posProduct = item
......@@ -246,6 +284,15 @@ class RequestMainViewModel : BaseViewModel() {
activitys.add(activityInfo)
}
var activityPrice = activityInfo?.activityPrice ?: 0.0
var weightCode=""
if (pluList.size > index) {
weightCode =
if (pluList[index].id == posProduct?.id) pluList[index].plu else ""
XLog.d("we$weightCode $index")
}
val posBuyPart = InsertOrderProductDTO(
activitys = activitys,
activityPrice = activityPrice,
......@@ -262,7 +309,7 @@ class RequestMainViewModel : BaseViewModel() {
price = product.price ?: 0.0,
quantity = product.quantity ?: 0.0,
tailAmount = 0,
weightCode = map[posProduct.id],
weightCode = weightCode,
name = posProduct.name,
spec = posProduct.spec,
unit = posProduct.unit,
......@@ -387,6 +434,7 @@ class RequestMainViewModel : BaseViewModel() {
private fun getOrderDetailById(orderId: String, authCode: String) {
request({ apiService.getOrderDetailById(orderId) }, {
"${CacheUtil.getRealName()}付款成功,保存数据库并打印".dXLog()
pluList.clear()
launch({
PrintUtils.print(posConfig!!, it)
PosBuyRepository.getInstance().savePosBuy(it, authCode)
......@@ -417,5 +465,15 @@ class RequestMainViewModel : BaseViewModel() {
})
}
fun syncProducts() {
request({ HttpRequestCoroutine.syncProducts(posConfig?.storeId!!) }, {
val uiState = UpdateUiState(isSuccess = true, data = "", errorMsg = "")
syncProductsState.postValue(uiState)
}, {
val uiState = UpdateUiState(isSuccess = false, data = "", errorMsg = it.errorMsg)
syncProductsState.postValue(uiState)
})
}
}
\ No newline at end of file
package com.ypsx.yppos.viewmodel.state
import com.ypsx.base.base.viewmodel.BaseViewModel
import com.ypsx.base.callback.databind.StringObservableField
class ChangeQuantityViewModel : BaseViewModel() {
var productName = StringObservableField()
var productBarCode = StringObservableField()
var purchaseQuantityName = StringObservableField()
var purchaseQuantity = StringObservableField()
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#E0E0E0" />
<corners android:radius="4dp" />
</shape>
\ No newline at end of file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="200"
android:viewportHeight="200">
<path
android:fillColor="#FF000000"
android:pathData="M179.7,36.3h-48V12.6c0,-4.4 -3.6,-8.2 -8.2,-8.2H75.7c-4.4,0 -8.2,3.6 -8.2,8.2v23.8H19.7l-16,143.9c0,8.8 7.2,16 16,16h159.9c8.8,0 16,-7.2 16,-16L179.7,36.3zM83.7,20.3h32v16h-32V20.3zM165.3,52.3l14.2,127.9H19.7L33.9,52.3"/>
<path
android:fillColor="#FF000000"
android:pathData="M83.5,60.5H67.7v15.8h15.8V60.5zM131.7,60.5h-15.8v15.8h15.8V60.5z"/>
</vector>
......@@ -17,6 +17,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".ui.activity.LoginActivity">
<androidx.constraintlayout.widget.Guideline
......@@ -93,6 +95,8 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatTextView
......@@ -110,8 +114,9 @@
android:id="@+id/et_account"
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:paddingHorizontal="10dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="center_vertical"
android:hint="@string/login_account_tip"
......@@ -168,7 +173,7 @@
android:id="@+id/et_password"
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:paddingHorizontal="10dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="center_vertical"
......@@ -179,7 +184,7 @@
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="20sp"
tools:ignore="NestedWeights" />
/>
<androidx.appcompat.widget.AppCompatImageView
......
......@@ -69,18 +69,10 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view_split_line">
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="2"
android:maxLines="2"
tools:text="商品名称"
android:textColor="#474245"
android:textSize="18sp" />
<LinearLayout
android:id="@+id/ll_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
......@@ -105,27 +97,41 @@
android:textColor="#FF5949"
android:textSize="24sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_toStartOf="@id/ll_price"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="2"
android:maxLines="2"
android:textColor="#474245"
android:textSize="18sp"
tools:text="商品名称" />
<TextView
android:id="@+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="30dp"
android:gravity="bottom"
android:layout_below="@+id/tv_name"
android:layout_marginTop="5dp"
tools:text="价格"
android:textColor="@color/colorAccent"
android:textSize="16sp" />
android:textSize="16sp"
tools:text="价格" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/tv_price"
android:layout_alignTop="@id/tv_price"
android:layout_alignParentEnd="true">
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ll_count"
android:layout_width="110dp"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:minWidth="120dp"
android:background="@drawable/bg_item_count"
android:orientation="horizontal">
......@@ -133,9 +139,14 @@
android:id="@+id/tv_count_reduce"
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="centerInside"
android:layout_gravity="center"
android:layout_marginStart="@dimen/dp_10"
android:layout_marginStart="@dimen/dp_4"
android:layout_marginEnd="@dimen/dp_4"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/tv_count"
app:srcCompat="@drawable/ic_order_reduce" />
<TextView
......@@ -145,11 +156,25 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
tools:text="1"
android:textColor="@color/black_333"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/tv_count_add"
app:layout_constraintStart_toEndOf="@+id/tv_count_reduce"
app:layout_constraintTop_toTopOf="parent"
tools:text="1" />
/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="4dp"
android:background="#909090"
app:layout_constraintEnd_toStartOf="@+id/tv_count_add"
app:layout_constraintStart_toEndOf="@+id/tv_count_reduce"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_count" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/tv_count_add"
......@@ -157,10 +182,15 @@
android:layout_height="20dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:layout_marginEnd="@dimen/dp_10"
android:layout_marginStart="@dimen/dp_4"
android:layout_marginEnd="@dimen/dp_4"
app:layout_constraintStart_toEndOf="@id/tv_count"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_order_add" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="vm"
type="com.ypsx.yppos.viewmodel.state.ChangeQuantityViewModel" />
<variable
name="click"
type="com.ypsx.yppos.ui.popup.ChangeQuantityPopupWindow.ProxyClick" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_dialog">
<TextView
android:id="@+id/tv_product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:paddingHorizontal="@dimen/dp_10"
android:paddingTop="20dp"
android:paddingBottom="@dimen/dp_4"
android:text="@{vm.productName}"
android:gravity="start"
android:textColor="@color/black_333"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_barCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="@dimen/dp_10"
android:text="@{vm.productBarCode}"
android:textColor="@color/colorAccent"
android:textSize="@dimen/sp_14"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_product_name" />
<TextView
android:id="@+id/tvPurchaseQuantityName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingHorizontal="@dimen/dp_10"
android:text="@{vm.purchaseQuantityName}"
android:textColor="@color/black_333"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_barCode" />
<EditText
android:id="@+id/etPurchaseQuantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_10"
android:layout_marginTop="5dp"
android:background="@drawable/edit_bg"
android:digits="0123456789."
android:hint="@{vm.purchaseQuantity}"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:lines="1"
android:paddingVertical="10dp"
android:paddingStart="10dp"
android:text="@{vm.purchaseQuantity}"
android:textColor="#333333"
android:textColorHint="#999999"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvPurchaseQuantityName" />
<TextView
android:id="@+id/textView23"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="15dp"
android:background="@drawable/btn_confirm_bg"
android:gravity="center"
android:onClick="@{()->click.confirm()}"
android:text="确认"
android:textColor="@color/white"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/textView24"
app:layout_constraintTop_toBottomOf="@+id/etPurchaseQuantity" />
<TextView
android:id="@+id/textView24"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="20dp"
android:layout_marginTop="25dp"
android:background="@drawable/btn_cancel_bg"
android:gravity="center"
android:onClick="@{()->click.cancel()}"
android:text="取消"
android:textColor="#505050"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView23"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etPurchaseQuantity" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
......@@ -102,6 +102,31 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center_vertical"
android:onClick="@{()->click.syncProducts()}"
android:orientation="horizontal"
android:padding="15dp">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="centerInside"
app:srcCompat="@drawable/ic_synchronize_products" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="@string/synchronize_products"
android:textColor="@color/black_333"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
......@@ -24,6 +24,7 @@
<string name="pay_success">收款成功</string>
<string name="user_logout">退出登录</string>
<string name="print_receipt">重打上次小票</string>
<string name="synchronize_products">同步商品</string>
<string name="register_account">请先注册账号</string>
<string name="welcome_use_pos_system">欢迎使用谊品POS终端系统</string>
<string name="offer_details">优惠明细</string>
......
package com.ypsx.yppos
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun emailValidator_CorrectEmailSimple_ReturnsTrue() {
// assertThat(EmailValidator.isValidEmail("name@email.com")).isTrue()
}
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
// assertEquals(4, 2 + 2)
val stringBuilder = StringBuilder("24")
val mnemonicCode = "63575"
val weightCode = "23340"
val priceCode = "00400"
stringBuilder.append(mnemonicCode)
stringBuilder.append(priceCode)
stringBuilder.append(weightCode)
print("246357500400233406")
print(checkCode128(stringBuilder.toString(), 18))
}
private fun checkCode128(code: String, codeLength: Int): String {
var code1 = code
return if (code.length == codeLength - 1) {
var c1 = 0
var c2 = 0
run {
var i = 0
while (i < code.length) {
val c = code[i]
//字符串code中第i个位置上的字符
val n = c - '0'
c1 += n //累加奇数位的数字和
i += 2
}
}
var i = 1
while (i < code.length) {
val c = code[i] //字符串code中第i个位置上的字符
val n = c - '0'
c2 += n //累加偶数位的数字和
i += 2
}
val count = c2 + c1 * 3
val check = (10 - count % 10) % 10
code1 += check.toString() + ""
code1
} else {
""
}
}
@Test
fun printPrice() {
print(getPriceSpace("20110593", 12.345, 11.0, 37.04))
}
private fun getPriceSpace(
barCode: String,
paymentProductQuantity: Double,
price: Double,
productAmount: Double
): String {
val builder = StringBuilder()
builder.append(barCode)
for (i in 0 until 14 - length(barCode)) {
builder.append(" ")
}
builder.append(paymentProductQuantity.toString())
for (i in 0 until 6 - length(paymentProductQuantity.toString())) {
builder.append(" ")
}
for (i in 0 until 7 - length(price.toString())) {
builder.append(" ")
}
builder.append(price.toString())
for (i in 0 until 6 - length(productAmount.toString())) {
builder.append(" ")
}
builder.append(productAmount.toString())
return builder.toString()
}
private fun length(value: String): Int {
var valueLength = 0
val chinese: String = "[\u0391-\uFFE5]"
/* 获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1 */
for (i in value.indices) {
/* 获取一个字符 */
val temp = value.substring(i, i + 1)
/* 判断是否为中文字符 */
valueLength += if (temp.matches(Regex(chinese))) {
/* 中文字符长度为2 */
2
} else {
/* 其他字符长度为1 */
1
}
}
return valueLength
}
}
\ 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