Commit 9f15cf35 authored by YONG-LIN SU's avatar YONG-LIN SU

修正身障車格判斷邏輯及列印顯示

parent 15fa2c1e
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="QV7218BA3A" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-09-12T03:13:53.292563700Z" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
...@@ -126,6 +126,7 @@ public class Case { ...@@ -126,6 +126,7 @@ public class Case {
} }
/** /**
* 早班 晚班 標記 * 早班 晚班 標記
* @return A 或 B * @return A 或 B
...@@ -187,7 +188,7 @@ public class Case { ...@@ -187,7 +188,7 @@ public class Case {
// 2022/7/29 加入GPS座標功能後,修改該處假資料 // 2022/7/29 加入GPS座標功能後,修改該處假資料
String locationString = String.format("Lat:%f Lon:%f", location.getLatitude(), location.getLongitude()); // Lat:24.1434911 Lon:120.7285887 String locationString = String.format("Lat:%f Lon:%f", location == null ? 0.0 : location.getLatitude(), location == null ? 0.0 : location.getLongitude()); // Lat:24.1434911 Lon:120.7285887
return String.format(Locale.TAIWAN, "%s%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%.1f;%d;%s;%s;%d;\r\n", return String.format(Locale.TAIWAN, "%s%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%.1f;%d;%s;%s;%d;\r\n",
getShift(), user.id, getShift(), user.id,
......
...@@ -26,6 +26,7 @@ import ecom.android.newparkapp.entity.SpaceType; ...@@ -26,6 +26,7 @@ import ecom.android.newparkapp.entity.SpaceType;
*/ */
public class CarPrinter_TPB250 implements IBluetoothPrinter { public class CarPrinter_TPB250 implements IBluetoothPrinter {
// 舊的列印方法
@Override @Override
public ResultCode print(BluetoothSocket socketBT, Case thisCase) throws IOException { public ResultCode print(BluetoothSocket socketBT, Case thisCase) throws IOException {
...@@ -211,13 +212,13 @@ public class CarPrinter_TPB250 implements IBluetoothPrinter { ...@@ -211,13 +212,13 @@ public class CarPrinter_TPB250 implements IBluetoothPrinter {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5d %s", szList = String.format(Locale.TAIWAN, " %02d:%02d %5d %s",
nHour, nHour,
nowCalendar.get(Calendar.MINUTE), nowCalendar.get(Calendar.MINUTE),
carCase.getPricing(), 0,
carCase.user.name); carCase.user.name);
} else if (i == 1) { } else if (i == 1) {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s", szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s",
nHour + (b60Min ? 1 : 0), nHour + (b60Min ? 1 : 0),
b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1), b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1),
carCase.getPricing(), 0,
"________"); "________");
} else { } else {
szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s", szList = String.format(Locale.TAIWAN, " %02d:%02d %5s %s",
...@@ -228,8 +229,8 @@ public class CarPrinter_TPB250 implements IBluetoothPrinter { ...@@ -228,8 +229,8 @@ public class CarPrinter_TPB250 implements IBluetoothPrinter {
} }
} else if (carCase.vehicleType.id == 13) {//身心障礙(社-4) } else if (carCase.vehicleType.id == 13) {//身心障礙(社-4)
szList = (0 == i) ? szList = (0 == i) ?
String.format(Locale.TAIWAN, " %02d:%02d %5d %s", nHour, nowCalendar.get(Calendar.MINUTE), carCase.getPricing(), carCase.user.name) : String.format(Locale.TAIWAN, " %02d:%02d %5d %s", nHour, nowCalendar.get(Calendar.MINUTE), 0, carCase.user.name) :
String.format(Locale.TAIWAN, " %02d:%02d %5s %s", nHour + (b60Min ? 1 : 0), b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1), carCase.getPricing(), "________"); String.format(Locale.TAIWAN, " %02d:%02d %5s %s", nHour + (b60Min ? 1 : 0), b60Min ? 0 : (nowCalendar.get(Calendar.MINUTE) + 1), 0, "________");
} }
} }
......
...@@ -109,6 +109,15 @@ public class MainActivity extends AppCompatActivity { ...@@ -109,6 +109,15 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
@Override
protected void onDestroy() {
if (alertDialogProgress != null){
alertDialogProgress.dismiss();
}
super.onDestroy();
}
/** /**
* 初始化 部分 UI介面 * 初始化 部分 UI介面
*/ */
......
...@@ -19,6 +19,8 @@ import androidx.lifecycle.ViewModelProvider; ...@@ -19,6 +19,8 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import java.io.File; import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import ecom.android.newparkapp.HorizontalLayoutManager; import ecom.android.newparkapp.HorizontalLayoutManager;
...@@ -207,10 +209,12 @@ public class T02PlateAndSpaceConfirmActivity extends AppCompatActivity { ...@@ -207,10 +209,12 @@ public class T02PlateAndSpaceConfirmActivity extends AppCompatActivity {
}else { }else {
// sort by time // sort by time
selectedCases.sort((t1, t2) -> t1.caseTime.compareTo(t2.caseTime)); selectedCases.sort((t1, t2) -> t1.caseTime.compareTo(t2.caseTime));
// 大的在前
Collections.reverse(selectedCases);
Case selectedCase = selectedCases.get(0); Case selectedCase = selectedCases.get(0);
bundle.putString("BillingNumber2", selectedCase.billingNumber2); bundle.putString("BillingNumber2", selectedCase.billingNumber2);
} }
bundle.putParcelable("Location", location);
bundle.putBoolean("IsNewCase", isNewCase); bundle.putBoolean("IsNewCase", isNewCase);
intent.putExtras(bundle); intent.putExtras(bundle);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
......
...@@ -9,6 +9,7 @@ import android.content.DialogInterface; ...@@ -9,6 +9,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.location.Location;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -98,6 +99,9 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -98,6 +99,9 @@ public class T02StartActivity extends AppCompatActivity {
private AlertDialog alertDialogProgress; private AlertDialog alertDialogProgress;
private AlertDialogProgressBarBinding alertDialogProgressBarBinding; private AlertDialogProgressBarBinding alertDialogProgressBarBinding;
private static final int LIMIT_FOR_ADD_COUNT = 4;//限制上次累加時間與現在之間隔,在此數值內才可累加,否則開新單(新單號,新時間,舊資料)
// 自動順序 // 自動順序
final private List<Stage> stageSequence = new ArrayList<Stage>(Arrays.asList(Stage.SPACE, Stage.VEHICLE_TYPE, Stage.PLATE_NUMBER)); final private List<Stage> stageSequence = new ArrayList<Stage>(Arrays.asList(Stage.SPACE, Stage.VEHICLE_TYPE, Stage.PLATE_NUMBER));
...@@ -157,6 +161,11 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -157,6 +161,11 @@ public class T02StartActivity extends AppCompatActivity {
t02StartViewModel.stopTimer(); t02StartViewModel.stopTimer();
} }
// 關閉 Activity 前,須將相關附屬的 windows視窗關閉,避免內存洩漏
if (alertDialogProgress != null){
alertDialogProgress.dismiss();
}
super.onDestroy(); super.onDestroy();
} }
...@@ -346,11 +355,14 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -346,11 +355,14 @@ public class T02StartActivity extends AppCompatActivity {
if (isNewCase){ if (isNewCase){
String plateNumber = bundle.getString("PlateNumber"); String plateNumber = bundle.getString("PlateNumber");
Space space = bundle.getParcelable("Space"); Space space = bundle.getParcelable("Space");
Location location = bundle.getParcelable("Location");
// TODO: 2022/8/25 接續新單流程 // TODO: 2022/8/25 接續新單流程
// 新單 // 新單
t02StartViewModel.initCurrentCase(); t02StartViewModel.initCurrentCase();
// 更新圖片 // 更新圖片
t02StartViewModel.setNewCasePhoto(photoFile); t02StartViewModel.setNewCasePhoto(photoFile);
// 更新GPS座標
t02StartViewModel.setLocation(location);
// 更新路段 // 更新路段
Toast.makeText(this, space.road.name + " " + space.id, Toast.LENGTH_SHORT).show(); Toast.makeText(this, space.road.name + " " + space.id, Toast.LENGTH_SHORT).show();
t02StartViewModel.setSpace(space); t02StartViewModel.setSpace(space);
...@@ -563,7 +575,6 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -563,7 +575,6 @@ public class T02StartActivity extends AppCompatActivity {
private void btnCumulativeTimeOnClicked() { private void btnCumulativeTimeOnClicked() {
Case tempCase = t02StartViewModel.getCurrentCase().getValue(); Case tempCase = t02StartViewModel.getCurrentCase().getValue();
if (tempCase == null) { if (tempCase == null) {
return; return;
} }
...@@ -577,12 +588,17 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -577,12 +588,17 @@ public class T02StartActivity extends AppCompatActivity {
final AlertDialog tempDialog = alertDialog.create(); final AlertDialog tempDialog = alertDialog.create();
// 設置基本參數 // 設置基本參數
// 取得舊的 addCount
int oldAddCount = t02StartViewModel.calcPeriodHourCount(tempCase);
// 取得當前時間 // 取得當前時間
tempCase.finalTime = new Date(); tempCase.finalTime = new Date();
// 累加時間試算 // 累加時間試算
int newAddCount = t02StartViewModel.calcPeriodHourCount(tempCase); int newAddCount = t02StartViewModel.calcPeriodHourCount(tempCase);
// 計算抵免時數
int freeAddCount = t02StartViewModel.calcFreePeriodHourCount(tempCase);
float newPeriodHour = newAddCount * tempCase.space.spaceRate.perHours; float newPeriodHour = newAddCount * tempCase.space.spaceRate.perHours;
int newFinalExpenses = newAddCount * tempCase.space_fee; int newFinalExpenses = (newAddCount - freeAddCount) < 0 ? 0 : (newAddCount - freeAddCount) * tempCase.space_fee;
// 顯示 試算 停車時數 停車費 // 顯示 試算 停車時數 停車費
t03CumulativeTimeDataBinding.diaParkingExpensesTextView.setText(String.valueOf(newFinalExpenses)); t03CumulativeTimeDataBinding.diaParkingExpensesTextView.setText(String.valueOf(newFinalExpenses));
...@@ -636,7 +652,19 @@ public class T02StartActivity extends AppCompatActivity { ...@@ -636,7 +652,19 @@ public class T02StartActivity extends AppCompatActivity {
//takePhoto(cumulativeTimeActivityResultLauncher); //takePhoto(cumulativeTimeActivityResultLauncher);
// 新版,先拍照,選擇完畢直接累加 // 新版,先拍照,選擇完畢直接累加
if (photoFile != null && photoFile.exists()){ if (photoFile != null && photoFile.exists()){
t02StartViewModel.cumulativeTime(photoFile, false); if ((newAddCount - oldAddCount) > LIMIT_FOR_ADD_COUNT) {//檢查開單逾時
new android.app.AlertDialog.Builder(this)
.setTitle("開單逾時")
.setMessage("已超過可進行累加時段,\n將開"新單"並"列印"!")
.setIcon(R.drawable.ic_report_black_24dp)
.setNeutralButton(getString(R.string.label_cancel), null)
.setPositiveButton(getString(R.string.label_ok_and_print), (dI, i) -> {
t02StartViewModel.setNewCase(tempCase, photoFile);//使用"新單號、時間"和"舊路段、格位、車輛資料"進行初始化
btnPrintOnClicked();
}).show();
}else {
t02StartViewModel.cumulativeTime(photoFile, false);
}
}else{ }else{
Toast.makeText(this, "讀取相片失敗,請重新操作",Toast.LENGTH_SHORT).show(); Toast.makeText(this, "讀取相片失敗,請重新操作",Toast.LENGTH_SHORT).show();
} }
......
...@@ -43,6 +43,7 @@ import ecom.android.newparkapp.entity.Road; ...@@ -43,6 +43,7 @@ import ecom.android.newparkapp.entity.Road;
import ecom.android.newparkapp.entity.Shift; import ecom.android.newparkapp.entity.Shift;
import ecom.android.newparkapp.entity.Space; import ecom.android.newparkapp.entity.Space;
import ecom.android.newparkapp.entity.SpaceFee; import ecom.android.newparkapp.entity.SpaceFee;
import ecom.android.newparkapp.entity.SpaceType;
import ecom.android.newparkapp.entity.User; import ecom.android.newparkapp.entity.User;
import ecom.android.newparkapp.entity.VehicleType; import ecom.android.newparkapp.entity.VehicleType;
import ecom.android.newparkapp.repository.InfoRepository; import ecom.android.newparkapp.repository.InfoRepository;
...@@ -152,8 +153,9 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -152,8 +153,9 @@ public class T02StartViewModel extends AndroidViewModel {
SpaceFee spaceFee = infoRepository.spaceFeeDao.findByName(space.spaceRate.id, vehicleType.id); SpaceFee spaceFee = infoRepository.spaceFeeDao.findByName(space.spaceRate.id, vehicleType.id);
tempCase.space_fee = spaceFee==null ? 20: spaceFee.fee; tempCase.space_fee = spaceFee==null ? 20: spaceFee.fee;
int addCount = calcPeriodHourCount(tempCase); int addCount = calcPeriodHourCount(tempCase);
int freeAddCount = calcFreePeriodHourCount(tempCase);
tempCase.periodHour = addCount * space.spaceRate.perHours; tempCase.periodHour = addCount * space.spaceRate.perHours;
tempCase.finalExpenses = addCount * tempCase.space_fee; tempCase.finalExpenses = (addCount - freeAddCount) < 0 ? 0 : (addCount - freeAddCount) * tempCase.space_fee;
} }
} }
...@@ -184,6 +186,19 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -184,6 +186,19 @@ public class T02StartViewModel extends AndroidViewModel {
return new_addCount; return new_addCount;
} }
public int calcFreePeriodHourCount(Case thisCase)
{
int freeAddCont = 0;
Space space = thisCase.space;
VehicleType vehicleType = thisCase.vehicleType;
SpaceFee spaceFee = infoRepository.spaceFeeDao.findByName(space.spaceRate.id, vehicleType.id);
// 符合身障車輛 停放 身障車格 才有免費時數抵免
if (space.spaceType == SpaceType.HANDICAPPED_SPACE && spaceFee != null){
freeAddCont = (int) (spaceFee.freeTime / space.spaceRate.perHours);
}
return freeAddCont;
}
public void updateCaseDate(){ public void updateCaseDate(){
Case tempCase = currentCase.getValue(); Case tempCase = currentCase.getValue();
tempCase.caseTime = Calendar.getInstance().getTime(); tempCase.caseTime = Calendar.getInstance().getTime();
...@@ -254,6 +269,64 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -254,6 +269,64 @@ public class T02StartViewModel extends AndroidViewModel {
currentCase.setValue(newCase()); currentCase.setValue(newCase());
} }
public void setNewCase(Case thisCase, File photoFile){
// 清空佔存
tempCasePhoto.clear();
Case newCase = newCase();
// 更新圖片
// 取得完整路徑
final String path = photoFile.getAbsolutePath();
// TODO: 2022/7/29 加入車牌辨識功能
// 進行車牌辨識
String plateNumber = doLPRByFilePath(path, threshold, nms_threshold);
// 車牌辨識結果 車牌規則 過濾
String newPlateNumber = plateModifyByRule(plateNumber);
String day = new SimpleDateFormat("yyyyMMdd").format(new Date());
String newPath = Environment.getExternalStorageDirectory() + getApplication().getString(R.string.sysDataPhoto_path) + day;
File temp = new File(newPath);
if (!temp.exists()) {
temp.mkdirs();
}
File newFile = new File(newPath, "/" + newCase.billingNumber2 + newCase.photoCount + ".jpg");
String newFilePath = newFile.getAbsolutePath();
// 添加車牌辨識 結果
CasePhoto newCasePhoto = new CasePhoto(0, newCase.billingNumber2, newFilePath, newPlateNumber);
tempCasePhoto.add(newCasePhoto);
// 為圖片壓制浮水印
Thread ModifyPhotoT = new Thread(new ModifyPhoto(path, newFilePath), "ModifyPhoto_Thread");
ModifyPhotoT.start();
// 重新搜尋檔案
MediaScannerConnection.scanFile(getApplication().getApplicationContext(), new String[]{newFilePath}, null, null);
// 更新照片數量
newCase.photoCount+=1;
// 更新GPS座標
newCase.location = thisCase.location;
// 更新車種
newCase.vehicleType = thisCase.vehicleType;
// 更新路段
newCase.space = thisCase.space;
// 更新費用
getSpaceFee(newCase);
// 更新車牌
newCase.plateNumber = thisCase.plateNumber;
// 更新自動扣繳
newCase.autoPay = thisCase.autoPay;
newCase.agency = thisCase.agency;
currentCase.setValue(newCase);
}
private Case newCase(){ private Case newCase(){
Case newCase = new Case(); Case newCase = new Case();
newCase.caseStatus = CaseStatus.NEW; newCase.caseStatus = CaseStatus.NEW;
...@@ -597,6 +670,10 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -597,6 +670,10 @@ public class T02StartViewModel extends AndroidViewModel {
* 案件頁面切換下一頁 * 案件頁面切換下一頁
*/ */
public void pageDown() { public void pageDown() {
// if (currentCase.getValue() != null && currentCase.getValue().photoCount != 0){
// // 透過已經拍照判斷是否再執行開單任務,避免誤觸
// return;
// }
int casesSize = cases.size(); int casesSize = cases.size();
int newCaseCursor = caseCursor.getValue() + 1 ; int newCaseCursor = caseCursor.getValue() + 1 ;
// 判斷是否到底了 // 判斷是否到底了
...@@ -605,13 +682,16 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -605,13 +682,16 @@ public class T02StartViewModel extends AndroidViewModel {
currentCase.setValue(tempCase); currentCase.setValue(tempCase);
caseCursor.setValue(newCaseCursor); caseCursor.setValue(newCaseCursor);
} }
} }
/** /**
* 案件頁面切換上一頁 * 案件頁面切換上一頁
*/ */
public void pageUp() { public void pageUp() {
// if (currentCase.getValue() != null && currentCase.getValue().photoCount != 0){
// // 透過已經拍照判斷是否再執行開單任務,避免誤觸
// return;
// }
int newCaseCursor = caseCursor.getValue() - 1 ; int newCaseCursor = caseCursor.getValue() - 1 ;
// 判斷是否為第一筆 // 判斷是否為第一筆
if (newCaseCursor >= 0){ if (newCaseCursor >= 0){
...@@ -663,8 +743,10 @@ public class T02StartViewModel extends AndroidViewModel { ...@@ -663,8 +743,10 @@ public class T02StartViewModel extends AndroidViewModel {
// 更新累加時間 // 更新累加時間
int addCount = calcPeriodHourCount(tempCase); int addCount = calcPeriodHourCount(tempCase);
// 計算折抵時數
int freeAddCount = calcFreePeriodHourCount(tempCase);
tempCase.periodHour = addCount * tempCase.space.spaceRate.perHours; tempCase.periodHour = addCount * tempCase.space.spaceRate.perHours;
tempCase.finalExpenses = addCount * tempCase.space_fee; tempCase.finalExpenses = (addCount - freeAddCount) < 0 ? 0 : (addCount - freeAddCount) * tempCase.space_fee;
if (!isPhotoProcessed){ if (!isPhotoProcessed){
// 取得完整路徑 // 取得完整路徑
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M15.73,3L8.27,3L3,8.27v7.46L8.27,21h7.46L21,15.73L21,8.27L15.73,3zM12,17.3c-0.72,0 -1.3,-0.58 -1.3,-1.3 0,-0.72 0.58,-1.3 1.3,-1.3 0.72,0 1.3,0.58 1.3,1.3 0,0.72 -0.58,1.3 -1.3,1.3zM13,13h-2L11,7h2v6z" />
</vector>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
9 1 25 0 9 1 25 0
10 1 25 0 10 1 25 0
11 1 25 0 11 1 25 0
12 1 15 4 12 1 15 2
13 1 15 4 13 1 15 4
14 1 25 0 14 1 25 0
1 2 20 0 1 2 20 0
...@@ -23,6 +23,6 @@ ...@@ -23,6 +23,6 @@
9 2 20 0 9 2 20 0
10 2 20 0 10 2 20 0
11 2 20 0 11 2 20 0
12 2 10 4 12 2 10 2
13 2 10 4 13 2 10 4
14 2 20 0 14 2 20 0
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