Commit 51816693c9457c42de6e3d75224cee9b8a47114c

Authored by 陈杰
1 parent 79abf011
Exists in master

返回错误编码

cloud/lapi/src/main/java/com/sincere/lapi/controller/LapiController.java
@@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
16 */ 16 */
17 package com.sincere.lapi.controller; 17 package com.sincere.lapi.controller;
18 18
  19 +import com.alibaba.fastjson.JSONArray;
  20 +import com.alibaba.fastjson.JSONObject;
19 import com.sincere.common.dto.smartCampus.SzVSchoolStudent; 21 import com.sincere.common.dto.smartCampus.SzVSchoolStudent;
20 import com.sincere.common.dto.smartCampus.SzVSchoolTeacher; 22 import com.sincere.common.dto.smartCampus.SzVSchoolTeacher;
21 import com.sincere.common.dto.xiaoan.FaceSendfail; 23 import com.sincere.common.dto.xiaoan.FaceSendfail;
@@ -24,7 +26,6 @@ import com.sincere.lapi.Utils.FileUtils; @@ -24,7 +26,6 @@ import com.sincere.lapi.Utils.FileUtils;
24 import com.sincere.lapi.feign.ScFeign; 26 import com.sincere.lapi.feign.ScFeign;
25 import com.sincere.lapi.feign.XaFeign; 27 import com.sincere.lapi.feign.XaFeign;
26 import com.sincere.lapi.pojo.*; 28 import com.sincere.lapi.pojo.*;
27 -import com.sincere.lapi.server.UrlParam;  
28 import com.sincere.lapi.service.request.TerminalHttpCall; 29 import com.sincere.lapi.service.request.TerminalHttpCall;
29 import io.swagger.annotations.ApiOperation; 30 import io.swagger.annotations.ApiOperation;
30 import org.apache.commons.lang3.StringUtils; 31 import org.apache.commons.lang3.StringUtils;
@@ -35,10 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam; @@ -35,10 +36,7 @@ import org.springframework.web.bind.annotation.RequestParam;
35 import org.springframework.web.bind.annotation.RestController; 36 import org.springframework.web.bind.annotation.RestController;
36 import sun.misc.BASE64Encoder; 37 import sun.misc.BASE64Encoder;
37 38
38 -import java.util.ArrayList;  
39 -import java.util.HashMap;  
40 -import java.util.List;  
41 -import java.util.Map; 39 +import java.util.*;
42 40
43 /** 41 /**
44 * description 42 * description
@@ -57,6 +55,21 @@ public class LapiController { @@ -57,6 +55,21 @@ public class LapiController {
57 @Autowired 55 @Autowired
58 TerminalHttpCall terminalHttpCall = new TerminalHttpCall(); 56 TerminalHttpCall terminalHttpCall = new TerminalHttpCall();
59 57
  58 +
  59 + private static Map<Integer,String> resultCodeMap = new HashMap<>();
  60 +
  61 + static {
  62 + resultCodeMap.put(1,"通用执行失败");
  63 + resultCodeMap.put(2,"初始化检测失败");
  64 + resultCodeMap.put(3,"人脸检测失败");
  65 + resultCodeMap.put(4,"图片未检测到人脸");
  66 + resultCodeMap.put(5,"jpeg 照片解码失败");
  67 + resultCodeMap.put(6,"人脸图片质量分数不满足");
  68 + resultCodeMap.put(7,"图片缩放失败");
  69 + resultCodeMap.put(8,"未启用智能");
  70 + resultCodeMap.put(9,"图片不存在或过大/过小");
  71 + }
  72 +
60 /** 73 /**
61 * 下发整个学校 74 * 下发整个学校
62 * @param deviceIds 多个设备用,隔开 75 * @param deviceIds 多个设备用,隔开
@@ -69,6 +82,7 @@ public class LapiController { @@ -69,6 +82,7 @@ public class LapiController {
69 String[] deviceList = deviceIds.split(","); 82 String[] deviceList = deviceIds.split(",");
70 if(userType.equals("1")){ 83 if(userType.equals("1")){
71 List<SzVSchoolTeacher> list = scFeign.selectTeacherBySchoolId(schoolId) ; 84 List<SzVSchoolTeacher> list = scFeign.selectTeacherBySchoolId(schoolId) ;
  85 + list = removeDuplicateCase(list);
72 for(String deviceId :deviceList){ 86 for(String deviceId :deviceList){
73 sendTeacherBatch(list,deviceId); 87 sendTeacherBatch(list,deviceId);
74 } 88 }
@@ -80,6 +94,17 @@ public class LapiController { @@ -80,6 +94,17 @@ public class LapiController {
80 } 94 }
81 } 95 }
82 96
  97 + private List<SzVSchoolTeacher> removeDuplicateCase(List<SzVSchoolTeacher> cases) {
  98 + Set<SzVSchoolTeacher> set = new TreeSet<>(new Comparator<SzVSchoolTeacher>() {
  99 + @Override
  100 + public int compare(SzVSchoolTeacher o1, SzVSchoolTeacher o2) {
  101 + return o1.getTeacherId().compareTo(o2.getTeacherId());
  102 + }
  103 + });
  104 + set.addAll(cases);
  105 + return new ArrayList<>(set);
  106 + }
  107 +
83 108
84 109
85 //下发单张人脸到设备 110 //下发单张人脸到设备
@@ -107,12 +132,20 @@ public class LapiController { @@ -107,12 +132,20 @@ public class LapiController {
107 private void sendStudent(SzVSchoolStudent student , String deviceId){ 132 private void sendStudent(SzVSchoolStudent student , String deviceId){
108 try{ 133 try{
109 LAPIResponse response = sendImg(Long.valueOf(student.getStudentId()),student.getName(),student.getStudentNum(),student.getPhoto(),deviceId); 134 LAPIResponse response = sendImg(Long.valueOf(student.getStudentId()),student.getName(),student.getStudentNum(),student.getPhoto(),deviceId);
110 - System.out.println("接收到的json-------"+response.toString());  
111 terminalHttpCall.removeKey(deviceId); 135 terminalHttpCall.removeKey(deviceId);
112 if(response.getStatusString().equals("Succeed")){ 136 if(response.getStatusString().equals("Succeed")){
113 - insertSuccess(deviceId,student.getStudentId(),student.getStudentNum(),student.getName(),student.getPhoto(),student.getSchoolId(),2); 137 + JSONObject data = JSONObject.parseObject(response.getData());
  138 + JSONArray personList = (JSONArray)data.get("PersonList") ;
  139 + JSONArray faceList = (JSONArray) ((JSONObject)personList.get(0)).get("FaceList");
  140 + JSONObject face = (JSONObject) faceList.get(0);
  141 + if((Integer) face.get("ResultCode") == 0){
  142 + insertSuccess(deviceId,student.getStudentId(),student.getStudentNum(),student.getName(),student.getPhoto(),student.getSchoolId(),2);
  143 + }else {
  144 + Integer code = (Integer) face.get("ResultCode") ;
  145 + insertFail(deviceId,student.getStudentId(),student.getStudentNum(),student.getName(),student.getPhoto(),student.getSchoolId(),2,code,resultCodeMap.get(code));
  146 + }
114 }else { 147 }else {
115 - insertFail(deviceId,student.getStudentId(),student.getStudentNum(),student.getName(),student.getPhoto(),student.getSchoolId(),2,response.getStatusCode()); 148 + insertFail(deviceId,student.getStudentId(),student.getStudentNum(),student.getName(),student.getPhoto(),student.getSchoolId(),2,response.getStatusCode(),response.getStatusString());
116 } 149 }
117 }catch (Exception e){ 150 }catch (Exception e){
118 e.printStackTrace(); 151 e.printStackTrace();
@@ -133,9 +166,18 @@ public class LapiController { @@ -133,9 +166,18 @@ public class LapiController {
133 LAPIResponse response = sendImg(Long.valueOf(teacher.getTeacherId()),teacher.getName(),teacher.getTeacherNum(),teacher.getFace(),deviceId); 166 LAPIResponse response = sendImg(Long.valueOf(teacher.getTeacherId()),teacher.getName(),teacher.getTeacherNum(),teacher.getFace(),deviceId);
134 terminalHttpCall.removeKey(deviceId); 167 terminalHttpCall.removeKey(deviceId);
135 if(response.getStatusString().equals("Succeed")){ 168 if(response.getStatusString().equals("Succeed")){
136 - insertSuccess(deviceId,teacher.getTeacherId(),teacher.getTeacherNum(),teacher.getName(),teacher.getFace(),teacher.getSchoolId(),1); 169 + JSONObject data = JSONObject.parseObject(response.getData());
  170 + JSONArray personList = (JSONArray)data.get("PersonList") ;
  171 + JSONArray faceList = (JSONArray) ((JSONObject)personList.get(0)).get("FaceList");
  172 + JSONObject face = (JSONObject) faceList.get(0);
  173 + if((Integer) face.get("ResultCode") == 0){
  174 + insertSuccess(deviceId,teacher.getTeacherId(),teacher.getTeacherNum(),teacher.getName(),teacher.getFace(),teacher.getSchoolId(),1);
  175 + }else {
  176 + Integer code = (Integer) face.get("ResultCode") ;
  177 + insertFail(deviceId,teacher.getTeacherId(),teacher.getTeacherNum(),teacher.getName(),teacher.getFace(),teacher.getSchoolId(),1,code,resultCodeMap.get(code));
  178 + }
137 }else { 179 }else {
138 - insertFail(deviceId,teacher.getTeacherId(),teacher.getTeacherNum(),teacher.getName(),teacher.getFace(),teacher.getSchoolId(),1,response.getStatusCode()); 180 + insertFail(deviceId,teacher.getTeacherId(),teacher.getTeacherNum(),teacher.getName(),teacher.getFace(),teacher.getSchoolId(),1,response.getStatusCode(),response.getStatusString());
139 } 181 }
140 }catch (Exception e){ 182 }catch (Exception e){
141 e.printStackTrace(); 183 e.printStackTrace();
@@ -202,18 +244,19 @@ public class LapiController { @@ -202,18 +244,19 @@ public class LapiController {
202 244
203 245
204 private String getCard(String card) { 246 private String getCard(String card) {
205 -  
206 - if (card.length() == 8) {  
207 - int length = card.length();  
208 - String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4)  
209 - + card.substring(length - 8, length - 6);  
210 - return result;  
211 -  
212 - } else {  
213 - System.out.println("卡号位数不对:" + card);  
214 - return ""; 247 + if(StringUtils.isBlank(card)){
  248 + return "0" ;
  249 + }else {
  250 + if (card.length() == 8) {
  251 + int length = card.length();
  252 + String result = card.substring(length - 2, length) + card.substring(length - 4, length - 2) + card.substring(length - 6, length - 4)
  253 + + card.substring(length - 8, length - 6);
  254 + return result;
  255 +
  256 + } else {
  257 + return "0";
  258 + }
215 } 259 }
216 -  
217 } 260 }
218 261
219 private void insertSuccess(String deviceId , int customerId , String num , String name , String imgPath , int schoolId ,int userType){ 262 private void insertSuccess(String deviceId , int customerId , String num , String name , String imgPath , int schoolId ,int userType){
@@ -229,7 +272,7 @@ public class LapiController { @@ -229,7 +272,7 @@ public class LapiController {
229 xaFeign.insertFaceSuccess(send); 272 xaFeign.insertFaceSuccess(send);
230 } 273 }
231 274
232 - private void insertFail(String deviceId , int customerId , String num , String name , String imgPath , int schoolId ,int userType , int failType ){ 275 + private void insertFail(String deviceId , int customerId , String num , String name , String imgPath , int schoolId ,int userType , int failType ,String failContent){
233 FaceSendfail send = new FaceSendfail(); 276 FaceSendfail send = new FaceSendfail();
234 send.setDeviceid(deviceId); 277 send.setDeviceid(deviceId);
235 send.setCustomerid(customerId+""); 278 send.setCustomerid(customerId+"");
@@ -240,35 +283,7 @@ public class LapiController { @@ -240,35 +283,7 @@ public class LapiController {
240 send.setName(name); 283 send.setName(name);
241 send.setNum(num); 284 send.setNum(num);
242 send.setFailtype(failType); 285 send.setFailtype(failType);
243 - send.setFailcontent(failMap.get(failType+"")); 286 + send.setFailcontent(failContent);
244 xaFeign.insertFaceFail(send); 287 xaFeign.insertFaceFail(send);
245 } 288 }
246 -  
247 -  
248 - public static Map<String,String> failMap = new HashMap<>();  
249 -  
250 - static {  
251 - failMap.put("1000","算法初始化失败");  
252 - failMap.put("1001","人脸检测失败");  
253 - failMap.put("1002","图片未检测到人脸");  
254 - failMap.put("1003","jpeg照片解码失败");  
255 - failMap.put("1004","图片质量分数不满足");  
256 - failMap.put("1005","图片缩放失败");  
257 - failMap.put("1006","未启用智能");  
258 - failMap.put("1007","导入图片过小");  
259 - failMap.put("1008","导入图片过大");  
260 - failMap.put("1009","导入图片分辨率超过1920*1080");  
261 - failMap.put("1010","导入图片不存在");  
262 - failMap.put("1011","人脸元素个数已达到上限");  
263 - failMap.put("1012",":智能棒算法模型不匹配");  
264 - failMap.put("1013","人脸导入库成员证件号非法");  
265 - failMap.put("1014","人脸导入库成员图片格式错误");  
266 - failMap.put("1015","通道布控已达设备能力上限");  
267 - failMap.put("1016","其它客户端正在进行操作人脸库");  
268 - failMap.put("1017","人脸库文件正在更新中");  
269 - failMap.put("1018","Json反序列化失败");  
270 - failMap.put("1019","Base64解码失败");  
271 - failMap.put("1020","人脸照片,编码后的大小和实际接收到的长度不一致");  
272 -  
273 - }  
274 } 289 }