1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
| package com.example.firstapp.utils
|
| import com.example.firstapp.core.Core
| import com.example.firstapp.database.entity.Code
| import android.util.Log
|
| object CodeUtils {
| private const val TAG = "CodeUtils"
|
| /**
| * 保存code到数据库,如果已存在则跳过
| * @param code 要保存的code对象
| * @return Boolean 是否成功保存
| */
| fun saveCode(code: Code): Boolean {
| // 检查必要字段是否为空
| if (code.oneLevel.isEmpty() || code.code.isEmpty()) {
| Log.d(TAG, "保存失败:必要字段为空")
| return false
| }
|
| // 检查是否已存在相同记录
| val existingCode = Core.code.queryByTypeAndCodeAndDate(
| code.category,
| code.code,
| code.createTime
| )
|
| return if (existingCode == null) {
| try {
| Core.code.insert(code)
| Log.d(TAG, "成功保存${code.category}记录: ${code.code}")
| true
| } catch (e: Exception) {
| Log.e(TAG, "保存${code.category}记录失败: ${e.message}")
| false
| }
| } else {
| Log.d(TAG, "发现重复${code.category}记录,跳过保存: ${code.code}")
| false
| }
| }
|
| /**
| * 创建快递类型的Code对象
| */
| fun createExpressCode(
| msgId: Long,
| createTime: String,
| post: String?,
| company: String?,
| pickupCode: String?,
| address: String?,
| time: String?
| ): Code {
| // val secondLevel = if (company.isNullOrEmpty()) "未知" else company
| return Code(
| id = 0,
| category = "快递",
| categoryId = 1,
| typeId = 1,
| ruleId = 1,
| msgId = msgId,
| createTime = createTime,
| oneLevel = post ?: "",
| secondLevel = if (company.isNullOrEmpty()) "未知" else company,
| code = pickupCode ?: "",
| pickup = 0,
| pickupTime = "",
| overTime = "",
| address = address ?: "",
| remarks = time ?: ""
| )
| }
|
| /**
| * 创建还款类型的Code对象
| */
| fun createRepaymentCode(
| msgId: Long,
| createTime: String,
| type: String?,
| bank: String?,
| amount: String?,
| date: String?,
| address: String?,
| minAmount: String?,
| number: String?
| ): Code {
| return Code(
| id = 0,
| category = "还款",
| categoryId = 2,
| typeId = 1,
| ruleId = 2,
| msgId = msgId,
| createTime = createTime,
| oneLevel = type ?: "还款",
| secondLevel = if (bank.isNullOrEmpty()) "未知" else bank ,
| code = amount ?: "",
| pickup = 0,
| pickupTime = "",
| overTime = date ?: "",
| address = address ?: "",
| remarks = "最小还款金额${minAmount ?: ""}还款卡号${number ?: ""}"
| )
| }
|
| /**
| * 创建收入类型的Code对象
| */
| fun createIncomeCode(
| msgId: Long,
| createTime: String,
| bank: String?,
| amount: String?,
| datetime: String?,
| address: String?,
| balance: String?
| ): Code {
| return Code(
| id = 0,
| category = "收入",
| categoryId = 3,
| typeId = 1,
| ruleId = 2,
| msgId = msgId,
| createTime = createTime,
| oneLevel = bank ?: "",
| secondLevel = if (bank.isNullOrEmpty()) "未知" else bank,
| code = amount ?: "",
| pickup = 0,
| pickupTime = "",
| overTime = datetime ?: "",
| address = address ?: "",
| remarks = "余额${balance ?: ""}"
| )
| }
|
| /**
| * 创建航班类型的Code对象
| */
| fun createFlightCode(
| msgId: Long,
| createTime: String,
| company: String?,
| start: String?,
| end: String?,
| seat: String?,
| time: String?,
| address: String?
| ): Code {
| return Code(
| id = 0,
| category = "航班",
| categoryId = 4,
| typeId = 1,
| ruleId = 2,
| msgId = msgId,
| createTime = createTime,
| oneLevel = company ?: "",
| secondLevel = "${start ?: ""}${end ?: ""}",
| code = seat ?: "",
| pickup = 0,
| pickupTime = "",
| overTime = time ?: "",
| address = address ?: "",
| remarks = seat ?: ""
| )
| }
|
| /**
| * 创建火车票类型的Code对象
| */
| fun createTrainTicketCode(
| msgId: Long,
| createTime: String,
| company: String?,
| seat: String?,
| time: String?,
| address: String?,
| trips: String?
| ): Code {
| return Code(
| id = 0,
| category = "火车票",
| categoryId = 5,
| typeId = 1,
| ruleId = 2,
| msgId = msgId,
| createTime = createTime,
| oneLevel = company ?: "",
| secondLevel = company ?: "未知",
| code = seat ?: "",
| pickup = 0,
| pickupTime = "",
| overTime = time ?: "",
| address = address ?: "",
| remarks = trips ?: ""
| )
| }
| }
|
|