ceConnection", "rel " + rel); 167
+            rel = mGpService.sendEscCommand(0, str);
125 168
             GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
126 169
             if (r != GpCom.ERROR_CODE.SUCCESS) {
127 170
                 view.showToast( GpCom.getErrorText(r));
128 171
             }
129
-        } catch (Exception e1) {
130
-            e1.printStackTrace();
172
+        } catch (Exception e) {
173
+            view.showToast(App.getAppContext().getString(R.string.go_check_printer));
131 174
         }
132 175
     }
133 176
 

+ 8 - 2
app/src/main/java/ai/pai/lensman/session/SessionActivity.java

@@ -17,6 +17,7 @@ import ai.pai.lensman.bean.PhotoBean;
17 17
 import ai.pai.lensman.bean.SessionBean;
18 18
 import ai.pai.lensman.printer.PrinterSettingActivity;
19 19
 import ai.pai.lensman.qrcode.QRCaptureActivity;
20
+import ai.pai.lensman.utils.UrlContainer;
20 21
 import butterknife.BindView;
21 22
 import butterknife.ButterKnife;
22 23
 import butterknife.OnClick;
@@ -94,7 +95,10 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
94 95
 
95 96
     @OnClick(R.id.iv_qrcode)
96 97
     void showQRCodeForSession(){
97
-        new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow();
98
+//        new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow();
99
+        Intent intent = new Intent(this,PrinterSettingActivity.class);
100
+        intent.putExtra("qrcode", UrlContainer.HOST_URL+sessionBean.sessionId);
101
+        startActivity(intent);
98 102
     }
99 103
 
100 104
     @OnClick(R.id.title_bar_back_layout)
@@ -143,7 +147,9 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
143 147
     @Override
144 148
     public void onClick(View view) {
145 149
         if(view.getId()==R.id.btn_print_qr){
146
-            presenter.printQR();
150
+            Intent intent = new Intent(this,PrinterSettingActivity.class);
151
+            intent.putExtra("qrcode",sessionBean.sessionId);
152
+            startActivity(intent);
147 153
         }else if(view.getId()==R.id.tv_printer_set){
148 154
             startActivity(new Intent(this, PrinterSettingActivity.class));
149 155
         }

+ 0 - 1
app/src/main/java/ai/pai/lensman/session/SessionContract.java

@@ -18,6 +18,5 @@ public class SessionContract {
18 18
 
19 19
     interface Presenter extends BasePresenter{
20 20
         void swipeToDeletePhoto(int index);
21
-        void printQR();
22 21
     }
23 22
 }

+ 1 - 127
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -1,34 +1,13 @@
1 1
 package ai.pai.lensman.session;
2 2
 
3
-import android.content.ComponentName;
4
-import android.content.Context;
5 3
 import android.content.Intent;
6
-import android.content.ServiceConnection;
7
-import android.os.IBinder;
8
-import android.text.TextUtils;
9
-import android.util.Base64;
10
-import android.util.Log;
11
-
12
-import com.android.common.utils.LogHelper;
13
-import com.gprinter.aidl.GpService;
14
-import com.gprinter.command.EscCommand;
15
-import com.gprinter.command.GpCom;
16
-import com.gprinter.io.PortParameters;
17
-import com.gprinter.service.GpPrintService;
18
-
19
-import org.apache.commons.lang.ArrayUtils;
20
-
21
-import java.text.SimpleDateFormat;
4
+
22 5
 import java.util.ArrayList;
23
-import java.util.Date;
24
-import java.util.Vector;
25 6
 
26 7
 import ai.pai.lensman.App;
27
-import ai.pai.lensman.R;
28 8
 import ai.pai.lensman.bean.PhotoBean;
29 9
 import ai.pai.lensman.bean.SessionBean;
30 10
 import ai.pai.lensman.db.DBService;
31
-import ai.pai.lensman.db.Preferences;
32 11
 import ai.pai.lensman.service.UploadService;
33 12
 
34 13
 
@@ -40,9 +19,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
40 19
     private SessionBean sessionBean;
41 20
     private boolean isWorking;
42 21
 
43
-    private GpService mGpService = null;
44
-    private PrinterServiceConnection conn = null;
45
-    private int mPrinterId = 0;
46 22
 
47 23
 
48 24
     public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
@@ -63,16 +39,12 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
63 39
             }
64 40
         }
65 41
         interactor.startSession();
66
-        startAndBindPrintService();
67 42
     }
68 43
 
69 44
     @Override
70 45
     public void stop() {
71 46
         interactor.endSession();
72 47
         isWorking = false;
73
-        if (conn != null) {
74
-            App.getAppContext().unbindService(conn);
75
-        }
76 48
     }
77 49
 
78 50
     @Override
@@ -111,102 +83,4 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
111 83
         interactor.deletePhoto(photoBean);
112 84
     }
113 85
 
114
-    @Override
115
-    public void printQR() {
116
-        if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){
117
-            sessionView.showToast(App.getAppContext().getString(R.string.not_set_printer_yet));
118
-            return;
119
-        }
120
-        checkPrinter();
121
-        EscCommand esc = new EscCommand();
122
-        esc.addPrintAndFeedLines((byte) 3);
123
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中
124
-        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽
125
-        esc.addText("拍爱\n");   //  打印文字
126
-        esc.addPrintAndLineFeed();
127
-
128
-		/*打印文字*/
129
-        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽
130
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
131
-        esc.addText("欢迎使用拍爱!\n");   //  打印文字
132
-
133
-		/*QRCode命令打印
134
-			此命令只在支持QRCode命令打印的机型才能使用。
135
-			在不支持二维码指令打印的机型上,则需要发送二维条码图片
136
-		*/
137
-        esc.addText("Print QRCode\n");   //  打印文字
138
-        esc.addPrintAndFeedLines((byte) 3);
139
-        esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级
140
-        esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小
141
-        esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容
142
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐
143
-        esc.addPrintQRCode();//打印QRCode
144
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
145
-        esc.addText("拍摄日期 "+new SimpleDateFormat("yy/MM/dd HH:mm").format(new Date()));
146
-        esc.addPrintAndFeedLines((byte) 3);
147
-
148
-        Vector<Byte> datas = esc.getCommand(); //发送数据
149
-        Byte[] Bytes = datas.toArray(new Byte[datas.size()]);
150
-        byte[] bytes = ArrayUtils.toPrimitive(Bytes);
151
-        String str = Base64.encodeToString(bytes, Base64.DEFAULT);
152
-        int rel;
153
-        try {
154
-            rel = mGpService.sendEscCommand(mPrinterId, str);
155
-            GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
156
-            if (r != GpCom.ERROR_CODE.SUCCESS) {
157
-                sessionView.showToast( GpCom.getErrorText(r));
158
-            }
159
-        } catch (Exception e) {
160
-            sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer));
161
-        }
162
-    }
163
-
164
-    private void checkPrinter(){
165
-        sessionView.showToast(App.getAppContext().getString(R.string.connecting));
166
-        try{
167
-            int status = mGpService.queryPrinterStatus(0, 10000);
168
-            if (status != GpCom.STATE_NO_ERR) {
169
-                connectPrinter();
170
-            }
171
-        }catch (Exception e){
172
-            sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer));
173
-            return;
174
-        }
175
-        printQR();
176
-    }
177
-
178
-    public void connectPrinter() {
179
-        if(mGpService==null){
180
-            sessionView.showToast(App.getAppContext().getString(R.string.printer_service_boot_fail));
181
-            return;
182
-        }
183
-        try {
184
-            int code = mGpService.openPort(0, PortParameters.BLUETOOTH, Preferences.getInstance().getPrinterMac(), 0);
185
-            LogHelper.d("czy111","open port return code ="+code);
186
-        } catch (Exception e) {
187
-            sessionView.showToast(App.getAppContext().getString(R.string.printer_port_open_fail));
188
-        }
189
-
190
-    }
191
-
192
-    private void startAndBindPrintService() {
193
-        Intent intent = new Intent(App.getAppContext(), GpPrintService.class);
194
-        App.getAppContext().startService(intent);
195
-        conn = new PrinterServiceConnection();
196
-        App.getAppContext().bindService(intent, conn, Context.BIND_AUTO_CREATE);
197
-    }
198
-
199
-    class PrinterServiceConnection implements ServiceConnection {
200
-        @Override
201
-        public void onServiceDisconnected(ComponentName name) {
202
-            Log.i("ServiceConnection", "onServiceDisconnected() called");
203
-            mGpService = null;
204
-        }
205
-
206
-        @Override
207
-        public void onServiceConnected(ComponentName name, IBinder service) {
208
-            mGpService = GpService.Stub.asInterface(service);
209
-        }
210
-    }
211
-
212 86
 }

+ 8 - 1
app/src/main/res/layout/activity_printer_setting.xml

@@ -65,6 +65,13 @@
65 65
         android:layout_below="@id/title_bar_with_back_btn"
66 66
         android:orientation="vertical">
67 67
 
68
+        <ImageView
69
+            android:id="@+id/iv_qrcode"
70
+            android:layout_width="240dp"
71
+            android:layout_height="240dp"
72
+            android:layout_gravity="center_horizontal"
73
+            android:layout_margin="8dp"/>
74
+
68 75
         <LinearLayout
69 76
             android:layout_width="match_parent"
70 77
             android:layout_height="38dp"
@@ -111,7 +118,7 @@
111 118
                 android:id="@+id/tv_print_test"
112 119
                 android:layout_width="wrap_content"
113 120
                 android:layout_height="wrap_content"
114
-                android:text="@string/print_test"
121
+                android:text="@string/print_qr"
115 122
                 android:textColor="@color/dark_grey"
116 123
                 android:textSize="16sp" />
117 124
         </LinearLayout>

Return user_info for api tgu_group_user_locations_api · a229908ca3 - Gogs: Go Git Service

Return user_info for api tgu_group_user_locations_api

Brightcells 10 jaren geleden
bovenliggende
commit
a229908ca3
5 gewijzigde bestanden met toevoegingen van 55 en 2 verwijderingen
  1. 3 0
      account/tourguide_views.py
  2. 5 0
      account/views.py
  3. 3 0
      group/lensman_views.py
  4. 10 2
      group/tourguidegroupuser_views.py
  5. 34 0
      utils/redis/rprofile.py

+ 3 - 0
account/tourguide_views.py

@@ -8,6 +8,7 @@ from logit import logit
8 8
 from account.models import TourGuideInfo, UserInfo
9 9
 from utils.error.errno_utils import TourGuideStatusCode
10 10
 from utils.error.response_utils import response
11
+from utils.redis.rprofile import set_profile_info
11 12
 
12 13
 
13 14
 r = settings.REDIS_CACHE
@@ -73,4 +74,6 @@ def tourguide_wx_authorize_api(request):
73 74
     user.city = city
74 75
     user.save()
75 76
 
77
+    set_profile_info(user)
78
+
76 79
     return response(200, 'Tour Guide Login Success', u'导游登录成功', user.data)

+ 5 - 0
account/views.py

@@ -15,6 +15,7 @@ from utils.error.errno_utils import LensmanStatusCode, UserStatusCode
15 15
 from utils.error.response_utils import response
16 16
 from utils.ip_utils import ip_addr
17 17
 from utils.redis.rguest import get_guest_entrance_control
18
+from utils.redis.rprofile import set_profile_info
18 19
 from utils.version_utils import is_version_match
19 20
 
20 21
 
@@ -148,6 +149,8 @@ def user_wx_authorize_api(request):
148 149
         user.city = city
149 150
         user.save()
150 151
 
152
+        set_profile_info(user)
153
+
151 154
         return response(200, 'Login Success', u'登录成功', user.data)
152 155
 
153 156
     # unionid 不存在
@@ -190,6 +193,8 @@ def user_wx_authorize_api(request):
190 193
             signup_at=signup_at,
191 194
         )
192 195
 
196
+        set_profile_info(user)
197
+
193 198
     return response(200, 'Login Success', u'登录成功', user.data)
194 199
 
195 200
 

+ 3 - 0
group/lensman_views.py

@@ -28,6 +28,7 @@ from utils.redis.rgroup import set_group_info
28 28
 from utils.redis.rkeys import GROUP_LAST_PHOTO_PK, TODAY_INCOME, TODAY_UPLOAD_PHOTO_AMOUNT, WEEK_INCOME, WEEK_SOLD
29 29
 from utils.redis.rorder import set_lensman_order_record
30 30
 from utils.redis.rprice import get_lensman_price_fixed, set_lensman_price_fixed
31
+from utils.redis.rprofile import set_profile_info
31 32
 from utils.thumbnail_utils import make_thumbnail
32 33
 from utils.watermark_utils import watermark_wrap
33 34
 
@@ -116,6 +117,8 @@ def lensman_wx_authorize_api(request):
116 117
     user.city = city
117 118
     user.save()
118 119
 
120
+    set_profile_info(user)
121
+
119 122
     return response(200, 'Lensman Login Success', u'摄影师登录成功', user.data)
120 123
 
121 124
 

+ 10 - 2
group/tourguidegroupuser_views.py

@@ -17,6 +17,7 @@ from utils.redis.rgroup import get_group_info, get_group_users_info, set_group_u
17 17
 from utils.redis.rkeys import (GROUP_LAST_PHOTO_PK, GROUP_USERS_DELETED_SET, GROUP_USERS_PASSED_SET,
18 18
                                GROUP_USERS_QUIT_SET, GROUP_USERS_REFUSED_SET, TOUR_GUIDE_GROUP_CUR_GATHER_INFO,
19 19
                                TOUR_GUIDE_GROUP_CUR_SESSION, TOUR_GUIDE_GROUP_GEO_INFO, TOUR_GUIDE_GROUP_USER_GEO_LIST)
20
+from utils.redis.rprofile import get_profile_by_id
20 21
 from utils.redis.rtourguide import get_tour_guide_own_group
21 22
 
22 23
 
@@ -176,10 +177,17 @@ def tgu_group_user_locations_api(request):
176 177
     # 获取集合经纬度
177 178
     gather_info = json.loads(r.get(TOUR_GUIDE_GROUP_CUR_GATHER_INFO % group_id) or '{}')
178 179
 
180
+    # [['x', 0.33, (2.68220901489e-06, 1.26736058093e-06)], []]
181
+    locations = r.georadius(TOUR_GUIDE_GROUP_GEO_INFO % group_id, gather_info.get('gather_lon', 0), gather_info.get('gather_lat', 0), '+inf', unit='m', withdist=True, withcoord=True, sort='ASC')
182
+    # [{'location_info': ['x', 0.33, (2.68220901489e-06, 1.26736058093e-06)], 'user_info': {}}, {}]
183
+    locations = [{
184
+        'location_info': loc,
185
+        'user_info': get_profile_by_id(loc[0])
186
+    } for loc in locations]
187
+
179 188
     return response(200, 'Get Tour Guide Group All User Location Success', u'获取旅行团用户地理位置信息成功', {
180 189
         'group_id': group_id,
181
-        'locations': r.georadius(TOUR_GUIDE_GROUP_GEO_INFO % group_id, gather_info.get('gather_lon', 0), gather_info.get('gather_lat', 0), '+inf', unit='m', withdist=True, withcoord=True, sort='ASC')
182
-        # 'locations': [['x', 0.33, (2.68220901489e-06, 1.26736058093e-06)]]
190
+        'locations': locations,
183 191
     })
184 192
 
185 193
 

+ 34 - 0
utils/redis/rprofile.py

@@ -0,0 +1,34 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+import json
4
+
5
+from django.conf import settings
6
+
7
+from utils.redis.rkeys import PROFILE_INFO
8
+
9
+
10
+r = settings.REDIS_CACHE
11
+
12
+
13
+# 用户相关
14
+
15
+
16
+def set_profile_info(user):
17
+    """ 设置用户信息 """
18
+    r.set(PROFILE_INFO % user.user_id, json.dumps(user.data))
19
+    return user.data
20
+
21
+
22
+def set_profile_by_uid(user_id):
23
+    """ 获取用户信息 """
24
+    from account.models import UserInfo
25
+    try:
26
+        user = UserInfo.objects.get(user_id=user_id)
27
+    except UserInfo.DoesNotExist:
28
+        return {}
29
+    return set_profile_info(user)
30
+
31
+
32
+def get_profile_by_id(user_id):
33
+    """ 获取用户信息 """
34
+    return json.loads(r.get(PROFILE_INFO % user_id) or '{}') or set_profile_by_uid(user_id)