Quellcode durchsuchen

Merge branch 'MoneyNote3.0' of http://git.quyaqu.com/xieshengqi/MoneyMoreMoreNote into MoneyNote3.0

e vor 6 Jahren
Ursprung
Commit
d9c34d767d

+ 62 - 48
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/CategoryDBDao.java

@@ -29,14 +29,15 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
29 29
         public final static Property Demo = new Property(2, String.class, "demo", false, "DEMO");
30 30
         public final static Property Name = new Property(3, String.class, "name", false, "NAME");
31 31
         public final static Property Type = new Property(4, int.class, "type", false, "TYPE");
32
-        public final static Property Account = new Property(5, long.class, "account", false, "ACCOUNT");
33
-        public final static Property Category_id = new Property(6, int.class, "category_id", false, "CATEGORY_ID");
34
-        public final static Property Year = new Property(7, int.class, "year", false, "YEAR");
35
-        public final static Property Month = new Property(8, int.class, "month", false, "MONTH");
36
-        public final static Property Day = new Property(9, int.class, "day", false, "DAY");
37
-        public final static Property CreateTime = new Property(10, long.class, "createTime", false, "CREATE_TIME");
38
-        public final static Property UpdateTime = new Property(11, long.class, "updateTime", false, "UPDATE_TIME");
39
-        public final static Property User_id = new Property(12, int.class, "user_id", false, "USER_ID");
32
+        public final static Property Image_path = new Property(5, String.class, "image_path", false, "IMAGE_PATH");
33
+        public final static Property Account = new Property(6, long.class, "account", false, "ACCOUNT");
34
+        public final static Property Category_id = new Property(7, int.class, "category_id", false, "CATEGORY_ID");
35
+        public final static Property Year = new Property(8, int.class, "year", false, "YEAR");
36
+        public final static Property Month = new Property(9, int.class, "month", false, "MONTH");
37
+        public final static Property Day = new Property(10, int.class, "day", false, "DAY");
38
+        public final static Property CreateTime = new Property(11, long.class, "createTime", false, "CREATE_TIME");
39
+        public final static Property UpdateTime = new Property(12, long.class, "updateTime", false, "UPDATE_TIME");
40
+        public final static Property User_id = new Property(13, int.class, "user_id", false, "USER_ID");
40 41
     }
41 42
 
42 43
 
@@ -57,14 +58,15 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
57 58
                 "\"DEMO\" TEXT," + // 2: demo
58 59
                 "\"NAME\" TEXT," + // 3: name
59 60
                 "\"TYPE\" INTEGER NOT NULL ," + // 4: type
60
-                "\"ACCOUNT\" INTEGER NOT NULL ," + // 5: account
61
-                "\"CATEGORY_ID\" INTEGER NOT NULL ," + // 6: category_id
62
-                "\"YEAR\" INTEGER NOT NULL ," + // 7: year
63
-                "\"MONTH\" INTEGER NOT NULL ," + // 8: month
64
-                "\"DAY\" INTEGER NOT NULL ," + // 9: day
65
-                "\"CREATE_TIME\" INTEGER NOT NULL ," + // 10: createTime
66
-                "\"UPDATE_TIME\" INTEGER NOT NULL ," + // 11: updateTime
67
-                "\"USER_ID\" INTEGER NOT NULL );"); // 12: user_id
61
+                "\"IMAGE_PATH\" TEXT," + // 5: image_path
62
+                "\"ACCOUNT\" INTEGER NOT NULL ," + // 6: account
63
+                "\"CATEGORY_ID\" INTEGER NOT NULL ," + // 7: category_id
64
+                "\"YEAR\" INTEGER NOT NULL ," + // 8: year
65
+                "\"MONTH\" INTEGER NOT NULL ," + // 9: month
66
+                "\"DAY\" INTEGER NOT NULL ," + // 10: day
67
+                "\"CREATE_TIME\" INTEGER NOT NULL ," + // 11: createTime
68
+                "\"UPDATE_TIME\" INTEGER NOT NULL ," + // 12: updateTime
69
+                "\"USER_ID\" INTEGER NOT NULL );"); // 13: user_id
68 70
     }
69 71
 
70 72
     /** Drops the underlying database table. */
@@ -97,14 +99,19 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
97 99
             stmt.bindString(4, name);
98 100
         }
99 101
         stmt.bindLong(5, entity.getType());
100
-        stmt.bindLong(6, entity.getAccount());
101
-        stmt.bindLong(7, entity.getCategory_id());
102
-        stmt.bindLong(8, entity.getYear());
103
-        stmt.bindLong(9, entity.getMonth());
104
-        stmt.bindLong(10, entity.getDay());
105
-        stmt.bindLong(11, entity.getCreateTime());
106
-        stmt.bindLong(12, entity.getUpdateTime());
107
-        stmt.bindLong(13, entity.getUser_id());
102
+ 
103
+        String image_path = entity.getImage_path();
104
+        if (image_path != null) {
105
+            stmt.bindString(6, image_path);
106
+        }
107
+        stmt.bindLong(7, entity.getAccount());
108
+        stmt.bindLong(8, entity.getCategory_id());
109
+        stmt.bindLong(9, entity.getYear());
110
+        stmt.bindLong(10, entity.getMonth());
111
+        stmt.bindLong(11, entity.getDay());
112
+        stmt.bindLong(12, entity.getCreateTime());
113
+        stmt.bindLong(13, entity.getUpdateTime());
114
+        stmt.bindLong(14, entity.getUser_id());
108 115
     }
109 116
 
110 117
     @Override
@@ -131,14 +138,19 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
131 138
             stmt.bindString(4, name);
132 139
         }
133 140
         stmt.bindLong(5, entity.getType());
134
-        stmt.bindLong(6, entity.getAccount());
135
-        stmt.bindLong(7, entity.getCategory_id());
136
-        stmt.bindLong(8, entity.getYear());
137
-        stmt.bindLong(9, entity.getMonth());
138
-        stmt.bindLong(10, entity.getDay());
139
-        stmt.bindLong(11, entity.getCreateTime());
140
-        stmt.bindLong(12, entity.getUpdateTime());
141
-        stmt.bindLong(13, entity.getUser_id());
141
+ 
142
+        String image_path = entity.getImage_path();
143
+        if (image_path != null) {
144
+            stmt.bindString(6, image_path);
145
+        }
146
+        stmt.bindLong(7, entity.getAccount());
147
+        stmt.bindLong(8, entity.getCategory_id());
148
+        stmt.bindLong(9, entity.getYear());
149
+        stmt.bindLong(10, entity.getMonth());
150
+        stmt.bindLong(11, entity.getDay());
151
+        stmt.bindLong(12, entity.getCreateTime());
152
+        stmt.bindLong(13, entity.getUpdateTime());
153
+        stmt.bindLong(14, entity.getUser_id());
142 154
     }
143 155
 
144 156
     @Override
@@ -154,14 +166,15 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
154 166
             cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // demo
155 167
             cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name
156 168
             cursor.getInt(offset + 4), // type
157
-            cursor.getLong(offset + 5), // account
158
-            cursor.getInt(offset + 6), // category_id
159
-            cursor.getInt(offset + 7), // year
160
-            cursor.getInt(offset + 8), // month
161
-            cursor.getInt(offset + 9), // day
162
-            cursor.getLong(offset + 10), // createTime
163
-            cursor.getLong(offset + 11), // updateTime
164
-            cursor.getInt(offset + 12) // user_id
169
+            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // image_path
170
+            cursor.getLong(offset + 6), // account
171
+            cursor.getInt(offset + 7), // category_id
172
+            cursor.getInt(offset + 8), // year
173
+            cursor.getInt(offset + 9), // month
174
+            cursor.getInt(offset + 10), // day
175
+            cursor.getLong(offset + 11), // createTime
176
+            cursor.getLong(offset + 12), // updateTime
177
+            cursor.getInt(offset + 13) // user_id
165 178
         );
166 179
         return entity;
167 180
     }
@@ -173,14 +186,15 @@ public class CategoryDBDao extends AbstractDao<CategoryDB, Long> {
173 186
         entity.setDemo(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
174 187
         entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
175 188
         entity.setType(cursor.getInt(offset + 4));
176
-        entity.setAccount(cursor.getLong(offset + 5));
177
-        entity.setCategory_id(cursor.getInt(offset + 6));
178
-        entity.setYear(cursor.getInt(offset + 7));
179
-        entity.setMonth(cursor.getInt(offset + 8));
180
-        entity.setDay(cursor.getInt(offset + 9));
181
-        entity.setCreateTime(cursor.getLong(offset + 10));
182
-        entity.setUpdateTime(cursor.getLong(offset + 11));
183
-        entity.setUser_id(cursor.getInt(offset + 12));
189
+        entity.setImage_path(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
190
+        entity.setAccount(cursor.getLong(offset + 6));
191
+        entity.setCategory_id(cursor.getInt(offset + 7));
192
+        entity.setYear(cursor.getInt(offset + 8));
193
+        entity.setMonth(cursor.getInt(offset + 9));
194
+        entity.setDay(cursor.getInt(offset + 10));
195
+        entity.setCreateTime(cursor.getLong(offset + 11));
196
+        entity.setUpdateTime(cursor.getLong(offset + 12));
197
+        entity.setUser_id(cursor.getInt(offset + 13));
184 198
      }
185 199
     
186 200
     @Override

+ 20 - 3
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/db/CategoryDB.java

@@ -56,6 +56,10 @@ public class CategoryDB {
56 56
     private int type;
57 57
 
58 58
     /**
59
+     * 类别图片
60
+     */
61
+    private String image_path;
62
+    /**
59 63
      * 账单金额
60 64
      */
61 65
     private long account;
@@ -98,15 +102,16 @@ public class CategoryDB {
98 102
 
99 103
 
100 104
 
101
-    @Generated(hash = 1281442951)
105
+    @Generated(hash = 708261383)
102 106
     public CategoryDB(Long id, String bill_id, String demo, String name, int type,
103
-            long account, int category_id, int year, int month, int day,
104
-            long createTime, long updateTime, int user_id) {
107
+            String image_path, long account, int category_id, int year, int month,
108
+            int day, long createTime, long updateTime, int user_id) {
105 109
         this.id = id;
106 110
         this.bill_id = bill_id;
107 111
         this.demo = demo;
108 112
         this.name = name;
109 113
         this.type = type;
114
+        this.image_path = image_path;
110 115
         this.account = account;
111 116
         this.category_id = category_id;
112 117
         this.year = year;
@@ -279,4 +284,16 @@ public class CategoryDB {
279 284
         this.user_id = user_id;
280 285
     }
281 286
 
287
+
288
+
289
+    public String getImage_path() {
290
+        return this.image_path;
291
+    }
292
+
293
+
294
+
295
+    public void setImage_path(String image_path) {
296
+        this.image_path = image_path;
297
+    }
298
+
282 299
 }

+ 13 - 0
app/src/main/java/com/kuxuan/moneynote/db/CategoryDBbean.java

@@ -30,6 +30,11 @@ public class CategoryDBbean implements Serializable{
30 30
      */
31 31
     private int type;
32 32
 
33
+
34
+    /**
35
+     * 类型图片路径
36
+     */
37
+    private String type_imagepath;
33 38
     /**
34 39
      * 账单金额
35 40
      */
@@ -63,6 +68,14 @@ public class CategoryDBbean implements Serializable{
63 68
     private long updateTime;
64 69
 
65 70
 
71
+    public String getType_imagepath() {
72
+        return type_imagepath;
73
+    }
74
+
75
+    public void setType_imagepath(String type_imagepath) {
76
+        this.type_imagepath = type_imagepath;
77
+    }
78
+
66 79
     public long getUpdateTime() {
67 80
         return updateTime;
68 81
     }

+ 18 - 15
app/src/main/java/com/kuxuan/moneynote/db/CategoryDaoOperator.java

@@ -2,6 +2,7 @@ package com.kuxuan.moneynote.db;
2 2
 
3 3
 import com.kuxuan.moneynote.MyApplication;
4 4
 import com.kuxuan.moneynote.common.Constant;
5
+import com.kuxuan.moneynote.json.TimeJson;
5 6
 import com.kuxuan.moneynote.utils.SPUtil;
6 7
 import com.kuxuan.moneynote.utils.TimeUtlis;
7 8
 import com.kuxuan.sqlite.dao.CategoryDBDao;
@@ -57,9 +58,10 @@ public class CategoryDaoOperator {
57 58
      * 插入数据
58 59
      *
59 60
      * @param categoryDBbean
61
+     * @param isSync         是不是网络同步
60 62
      * @return
61 63
      */
62
-    public synchronized boolean insert(CategoryDBbean categoryDBbean) {
64
+    public synchronized boolean insert(CategoryDBbean categoryDBbean, boolean isSync) {
63 65
         start();
64 66
         boolean isSuccess = false;
65 67
         CategoryDBDao categoryDBDao = DbManager.getInstance().getmDaoSession().getCategoryDBDao();
@@ -75,22 +77,23 @@ public class CategoryDaoOperator {
75 77
         }
76 78
         SPUtil.putAndApply(MyApplication.getInstance(), Constant.DbInfo.DB_ID_COUNT, count);
77 79
         String bill_id = null;
78
-        StringBuilder stringBuilder = new StringBuilder();
79
-        long createTime = categoryDBbean.getCreateTime();
80
-        if (String.valueOf(createTime).length() < 13) {
81
-            createTime = createTime * 1000;
80
+        if (isSync) {
81
+            bill_id = categoryDBbean.getBill_id() + "";
82
+        } else {
83
+            StringBuilder stringBuilder = new StringBuilder();
84
+            TimeJson currentTime = TimeUtlis.getCurrentTimeForhhmmss();
85
+            long createTime = currentTime.getCurrentTime();
86
+            if (String.valueOf(createTime).length() < 13) {
87
+                createTime = createTime * 1000;
88
+            }
89
+            String s = String.valueOf(createTime);
90
+            //毫秒4位数
91
+            String ms = s.substring(s.length() - 4, s.length());
92
+            stringBuilder.append(currentTime.getYear() + "" + currentTime.getMonth() + "" + currentTime.getDay() + currentTime.getHh() + "" + currentTime.getMm() + "" + currentTime.getSs() + ms + ((int) ((Math.random() * 9 + 1) * 1000)));
93
+            bill_id = stringBuilder.toString();
82 94
         }
83
-        String hh_mm_dd = TimeUtlis.getHH_mm_dd(createTime + "");
84
-        String[] hh = hh_mm_dd.split(":");
85
-        String s = String.valueOf(createTime);
86
-        //毫秒4位数
87
-        String ms = s.substring(s.length() - 4, s.length());
88
-
89
-        stringBuilder.append(categoryDBbean.getYear() + "" + categoryDBbean.getMonth() + "" + categoryDBbean.getDay() + hh[0] + "" + hh[1] + "" + hh[2] + ms + ((int) ((Math.random() * 9 + 1) * 1000)));
90
-        bill_id =stringBuilder.toString();
91
-
92 95
         try {
93
-            CategoryDB categoryDB = new CategoryDB((long) count, bill_id, categoryDBbean.getDemo(), categoryDBbean.getName(), categoryDBbean.getType(), categoryDBbean.getAccount(), categoryDBbean.getCategory_id(), categoryDBbean.getYear(), categoryDBbean.getMonth(), categoryDBbean.getDay(), categoryDBbean.getCreateTime(), categoryDBbean.getUpdateTime(), categoryDBbean.getUser_id());
96
+            CategoryDB categoryDB = new CategoryDB((long) count, bill_id, categoryDBbean.getDemo(), categoryDBbean.getName(), categoryDBbean.getType(), categoryDBbean.getType_imagepath(), categoryDBbean.getAccount(), categoryDBbean.getCategory_id(), categoryDBbean.getYear(), categoryDBbean.getMonth(), categoryDBbean.getDay(), categoryDBbean.getCreateTime(), categoryDBbean.getUpdateTime(), categoryDBbean.getUser_id());
94 97
             long insert = categoryDBDao.insert(categoryDB);
95 98
             isSuccess = true;
96 99
             onSuccess(insert);

+ 48 - 0
app/src/main/java/com/kuxuan/moneynote/json/TimeJson.java

@@ -12,6 +12,29 @@ public class TimeJson implements Serializable{
12 12
     private int year;
13 13
     private int month;
14 14
     private int day;
15
+    private String hh;
16
+    private String mm;
17
+    private String ss;
18
+    private long currentTime;
19
+
20
+
21
+    public long getCurrentTime() {
22
+        return currentTime;
23
+    }
24
+
25
+    public void setCurrentTime(long currentTime) {
26
+        this.currentTime = currentTime;
27
+    }
28
+
29
+    public TimeJson(int year, int month, int day, String hh, String mm, String ss, long currentTime) {
30
+        this.year = year;
31
+        this.month = month;
32
+        this.day = day;
33
+        this.currentTime = currentTime;
34
+        this.hh = hh;
35
+        this.mm = mm;
36
+        this.ss = ss;
37
+    }
15 38
 
16 39
     public TimeJson(int year, int month, int day) {
17 40
         this.year = year;
@@ -19,6 +42,31 @@ public class TimeJson implements Serializable{
19 42
         this.day = day;
20 43
     }
21 44
 
45
+
46
+    public String getHh() {
47
+        return hh;
48
+    }
49
+
50
+    public void setHh(String hh) {
51
+        this.hh = hh;
52
+    }
53
+
54
+    public String getMm() {
55
+        return mm;
56
+    }
57
+
58
+    public void setMm(String mm) {
59
+        this.mm = mm;
60
+    }
61
+
62
+    public String getSs() {
63
+        return ss;
64
+    }
65
+
66
+    public void setSs(String ss) {
67
+        this.ss = ss;
68
+    }
69
+
22 70
     public int getYear() {
23 71
         return year;
24 72
     }

+ 2 - 2
app/src/main/java/com/kuxuan/moneynote/ui/activitys/LunchActivity.java

@@ -196,7 +196,7 @@ public class LunchActivity extends Activity {
196 196
             categoryDBbean.setCreateTime(System.currentTimeMillis());
197 197
             categoryDBbean.setUpdateTime(System.currentTimeMillis());
198 198
             categoryDBbean.setUser_id(-1);
199
-            categoryDaoOperator.insert(categoryDBbean);
199
+            categoryDaoOperator.insert(categoryDBbean,false);
200 200
         }
201 201
 
202 202
         for (int i = 101; i < 150; i++) {
@@ -216,7 +216,7 @@ public class LunchActivity extends Activity {
216 216
             categoryDBbean.setCreateTime(System.currentTimeMillis());
217 217
             categoryDBbean.setUpdateTime(System.currentTimeMillis());
218 218
             categoryDBbean.setUser_id(-1);
219
-            categoryDaoOperator.insert(categoryDBbean);
219
+            categoryDaoOperator.insert(categoryDBbean,false);
220 220
         }
221 221
 
222 222
     }

+ 1 - 1
app/src/main/java/com/kuxuan/moneynote/ui/activitys/account/AccountModel.java

@@ -118,7 +118,7 @@ public class AccountModel implements AccountContract.AccountModel {
118 118
         Random random = new Random();
119 119
         int randNumber =random.nextInt(10000 - 1 + 1) + 1;
120 120
         categoryDBbean.setBill_id(1 +randNumber);
121
-        boolean insert = CategoryDaoOperator.newInstance().insert(categoryDBbean);
121
+        boolean insert = CategoryDaoOperator.newInstance().insert(categoryDBbean,false);
122 122
         if (insert) {
123 123
             listMVPListener.onSuccess(new Object());
124 124
         } else {

+ 12 - 0
app/src/main/java/com/kuxuan/moneynote/utils/TimeUtlis.java

@@ -125,7 +125,19 @@ public class TimeUtlis {
125 125
     }
126 126
 
127 127
 
128
+    public static TimeJson getCurrentTimeForhhmmss() {
129
+        long currentTimeMillis = System.currentTimeMillis();
130
+        Date date = new Date(currentTimeMillis);
131
+        SimpleDateFormat formatter = new SimpleDateFormat(TIME_FORMAT_FOUR);
132
+        String format = formatter.format(date);
133
+        String[] split = format.split(" ");
134
+        String yearMonthDay = split[0];
135
+        String hhmmss = split[1];
136
+        String[] split1 = yearMonthDay.split("-");
137
+        String[] split2 = hhmmss.split(":");
138
+        return new TimeJson(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]), Integer.parseInt(split1[2]),split2[0],split2[1],split2[2],currentTimeMillis);
128 139
 
140
+    }
129 141
     /**
130 142
      * 时间戳变成日期
131 143
      * @param s