Commit f2531697b531ae463c335fb87ee5894950801222

Authored by 邱一成
2 parents a4c5d51e b15036d2
Exists in master

Merge remote-tracking branch 'origin/master'

cloud/dahua/src/main/java/com/example/dahua/async/SendUserInfoTask.java
... ... @@ -4,10 +4,7 @@ package com.example.dahua.async;
4 4  
5 5 import com.alibaba.fastjson.JSON;
6 6 import com.example.dahua.MyTask;
7   -import com.example.dahua.bean.AttendanceBean;
8   -import com.example.dahua.bean.SendRecordBean;
9   -import com.example.dahua.bean.TeacherBean;
10   -import com.example.dahua.bean.UserInfoBean;
  7 +import com.example.dahua.bean.*;
11 8 import com.example.dahua.common.Res;
12 9 import com.example.dahua.dao.UserDao;
13 10 import com.example.dahua.enums.*;
... ... @@ -16,10 +13,13 @@ import com.example.dahua.lib.FilePath;
16 13 import com.example.dahua.lib.NetSDKLib;
17 14 import com.example.dahua.lib.ToolKits;
18 15 import com.example.dahua.module.GateModule;
  16 +import com.example.dahua.service.PermissFaceService;
19 17 import com.example.dahua.utils.FileUtils;
20 18 import com.example.dahua.utils.HttpUtils;
  19 +import com.example.dahua.utils.JsonUtils;
21 20 import com.example.dahua.xiananDao.SendRecordDao;
22 21 import com.sun.jna.Memory;
  22 +import io.swagger.models.auth.In;
23 23 import lombok.extern.slf4j.Slf4j;
24 24 import org.springframework.beans.factory.annotation.Autowired;
25 25 import org.springframework.http.ResponseEntity;
... ... @@ -44,6 +44,8 @@ public class SendUserInfoTask {
44 44  
45 45 @Autowired
46 46 SendRecordDao sendRecordDao;
  47 + @Autowired
  48 + PermissFaceService permissFaceService;
47 49  
48 50 /**
49 51 * 下发单个用户人脸任务
... ... @@ -301,6 +303,7 @@ public class SendUserInfoTask {
301 303 }
302 304 }
303 305  
  306 +
304 307 /**
305 308 * 下发人脸/卡信息
306 309 * @param attendanceBean
... ... @@ -323,6 +326,10 @@ public class SendUserInfoTask {
323 326 calendar.add(Calendar.YEAR, 4);
324 327 String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
325 328  
  329 + String studentType = userDao.getStudentType(attendanceBean.getSchool_id(),sendRecordBean.getCustomerid());
  330 + //通道号
  331 + int channel = analysisPermission(Integer.parseInt(attendanceBean.getSchool_id()),studentType);
  332 +
326 333 /**
327 334 * 注:用户下发逻辑
328 335 * 下发时,先从下发记录表:SZ_Student_RecoderNo 获取当前用户下发记录集编号,存在于设备的,新增卡号时返回,
... ... @@ -371,7 +378,7 @@ public class SendUserInfoTask {
371 378 if (bCardFlags) {
372 379 //修改设备卡信息
373 380 boolean isEditCard = GateModule.modifyCard(Integer.parseInt(recordNo),cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1),
374   - Res.string().getCardTypeInt(1), 0, 0, 1, startTime, endTime, loginHandleLong, userType,cardErrNum);
  381 + Res.string().getCardTypeInt(1), 0, 0, 1, startTime, endTime, loginHandleLong, userType,cardErrNum,channel);
375 382  
376 383 if (isEditCard) {
377 384 //修改卡成功, 更新下发记录集编号表
... ... @@ -387,7 +394,7 @@ public class SendUserInfoTask {
387 394 userDao.deleteRecordNo(user_id, Integer.parseInt(recordNo));
388 395 //重新下发卡号至设备
389 396 newRecordNo = GateModule.insertCard(cardNum, user_id, name, "123456", Res.string().getCardStatusInt(1),
390   - Res.string().getCardTypeInt(1), 0, 1, 1, startTime, endTime, loginHandleLong,userType,cardErrNum);
  397 + Res.string().getCardTypeInt(1), 0, 1, 1, startTime, endTime, loginHandleLong,userType,cardErrNum,channel);
391 398  
392 399 //下发卡至设备,返回值不为-1为下发成功,保存下发记录集编号表
393 400 if (newRecordNo != -1) {
... ... @@ -401,7 +408,7 @@ public class SendUserInfoTask {
401 408 //新增卡信息, 新增人脸信息至设备
402 409 newRecordNo = GateModule.insertCard(cardNum, user_id, name, "123456"
403 410 , Res.string().getCardStatusInt(1), Res.string().getCardTypeInt(1), 0, 1
404   - , 1, startTime, endTime, loginHandleLong,userType,cardErrNum);
  411 + , 1, startTime, endTime, loginHandleLong,userType,cardErrNum,channel);
405 412  
406 413 //下发卡至设备,返回值不为-1为下发成功,保存下发记录集编号表
407 414 if (newRecordNo != -1) {
... ... @@ -475,6 +482,41 @@ public class SendUserInfoTask {
475 482 }
476 483 }
477 484  
  485 + private static JsonUtils objectMapper = JsonUtils.nonEmptyMapper();
  486 +
  487 + /**
  488 + * 解析权限模板、获取下发通道号
  489 + * @param schoolId
  490 + * @param studentType
  491 + * @return
  492 + */
  493 + private int analysisPermission(int schoolId, String studentType){
  494 + List<PermissionFaceBean> permissionFaceBeans = permissFaceService.getPermissionList(schoolId);
  495 + String channel ="";
  496 + if(permissionFaceBeans.size()>0){
  497 + for(PermissionFaceBean permissionFaceBean : permissionFaceBeans){
  498 + String json = permissionFaceBean.getPermissionJson();
  499 + PermissionBean permissionBean = objectMapper.fromJson(json,PermissionBean.class);
  500 + //学生考勤类型 1:通校生,2:住校生,3:全部
  501 + String studentTypeStr = permissionBean.getStudentType();
  502 + if(studentTypeStr.indexOf(studentType)!=-1){
  503 + channel= permissionFaceBean.getChannel();
  504 + }
  505 + }
  506 + }
  507 + return Integer.parseInt(channel);
  508 + }
  509 +
  510 +
  511 + public static void main(String[] args) {
  512 + String json ="{\"studentType\":\"1,2\",\"deviceIds\":[\"aaa\"],\"weekDays\":[{\"weekTimes\":[{\"startTime\":\"12:00\",\"endTime\":\"06:00\"}],\"sex\":\"1,2\",\"weekDay\":\"0,1,2\"}]}";
  513 + PermissionBean permissionBean = objectMapper.fromJson(json,PermissionBean.class);
  514 + String studentType = permissionBean.getStudentType();
  515 + if(studentType.indexOf("1")!=-1){
  516 + System.out.println(true);
  517 + }
  518 + }
  519 +
478 520 /**
479 521 * 解析下发异常信息
480 522 * @param cardErrNum
... ... @@ -506,9 +548,6 @@ public class SendUserInfoTask {
506 548 return sb.toString();
507 549 }
508 550  
509   - public static void main(String[] args) {
510   - System.out.println(new SendUserInfoTask().analysisErrorMsg("",""));
511   - }
512 551  
513 552 /**
514 553 * 添加人脸下发失败记录
... ...
cloud/dahua/src/main/java/com/example/dahua/bean/PermissionBean.java
... ... @@ -15,6 +15,12 @@ public class PermissionBean implements Serializable {
15 15 @ApiModelProperty("用逗号隔开,1:通校生,2:住校生,3:全部")
16 16 private String studentType;
17 17  
  18 + @ApiModelProperty("权限通道号")
  19 + private String channel;
  20 +
  21 + @ApiModelProperty("权限自定义名成")
  22 + private String customName;
  23 +
18 24 public String getStudentType() {
19 25 return studentType;
20 26 }
... ... @@ -38,4 +44,20 @@ public class PermissionBean implements Serializable {
38 44 public void setWeekDays(List<WeekDay> weekDays) {
39 45 this.weekDays = weekDays;
40 46 }
  47 +
  48 + public String getChannel() {
  49 + return channel;
  50 + }
  51 +
  52 + public void setChannel(String channel) {
  53 + this.channel = channel;
  54 + }
  55 +
  56 + public String getCustomName() {
  57 + return customName;
  58 + }
  59 +
  60 + public void setCustomName(String customName) {
  61 + this.customName = customName;
  62 + }
41 63 }
... ...
cloud/dahua/src/main/java/com/example/dahua/bean/PermissionFaceBean.java
... ... @@ -42,6 +42,11 @@ public class PermissionFaceBean implements Serializable {
42 42 @ApiModelProperty(value = "0-新增;1-编辑;2-删除",required = true)
43 43 private int type;
44 44  
  45 + @ApiModelProperty("权限通道号")
  46 + private String channel;
  47 + @ApiModelProperty("权限自定义名成")
  48 + private String customName;
  49 +
45 50 public int getType() {
46 51 return type;
47 52 }
... ... @@ -105,4 +110,20 @@ public class PermissionFaceBean implements Serializable {
105 110 public void setPermissionJson(String permissionJson) {
106 111 this.permissionJson = permissionJson;
107 112 }
  113 +
  114 + public String getChannel() {
  115 + return channel;
  116 + }
  117 +
  118 + public void setChannel(String channel) {
  119 + this.channel = channel;
  120 + }
  121 +
  122 + public String getCustomName() {
  123 + return customName;
  124 + }
  125 +
  126 + public void setCustomName(String customName) {
  127 + this.customName = customName;
  128 + }
108 129 }
... ...
cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
... ... @@ -44,6 +44,15 @@ public interface UserDao {
44 44 @Select("select top 1 recordNo from SZ_Student_RecoderNo where user_id = #{user_id} and deviceId = #{deviceId}")
45 45 String getRecordNo(@Param("user_id") String user_id, @Param("deviceId") String deviceId);
46 46  
  47 + /**
  48 + * 获取学生考勤类型
  49 + * @param school_id
  50 + * @param customerid
  51 + * @return
  52 + */
  53 + @Select(" select Top(1)* student_type from SZ_V_School_Student where school_id = #{school_id} and student_id = #{customerid}")
  54 + String getStudentType(@Param("school_id") String school_id, @Param("customerid") String customerid);
  55 +
47 56 @Insert("insert into SZ_Student_RecoderNo values(#{user_id},#{recordNo},#{student_name},#{deviceId})")
48 57 int saveRecordNo(@Param("user_id") String user_id, @Param("recordNo") int recordNo, @Param("student_name") String student_name, @Param("deviceId") String deviceId);
49 58  
... ... @@ -104,7 +113,7 @@ public interface UserDao {
104 113 @Select("select StudentId from SS_RoomNumber where Pid in (select id from SS_Room where SchoolId = 479)")
105 114 List<String> getStudentIds();
106 115  
107   - @Select("select * from SZ_V_Card where num=#{num}")
  116 + @Select("select Top(1) * from SZ_V_Card where num=#{num}")
108 117 CardBean getCards(@Param("num") String num);
109 118  
110 119 @Select("select clint_id from SZ_Attendance where school_id = #{schoolId} and (clint_type = 8 or clint_type = 9 or clint_type = 10)")
... ...
cloud/dahua/src/main/java/com/example/dahua/enums/EnumSzBusinessType.java
... ... @@ -29,21 +29,22 @@ public interface EnumSzBusinessType {
29 29 }
30 30 }
31 31  
32   -// public enum EnumCardType {
33   -//
34   -// STUDENT(1, "student","学生"),
35   -// TEACHER(2, "teacher","老师");
36   -//// PARENT(3, "parent","家长");
37   -//
38   -// public final int code;
39   -// public final String enName;
40   -// public final String cnName;
41   -//
42   -// EnumUserType(int code, String enName,String cnName) {
43   -// this.code = code;
44   -// this.enName = enName;
45   -// this.cnName = cnName;
46   -// }
47   -// }
  32 + /**
  33 + * 学生出入类型
  34 + */
  35 + public enum EnumStudentType {
  36 +
  37 + GO_OUT(1, "通校"),
  38 + LIVING(2, "住校"),
  39 + ALL(3, "全部");
  40 +
  41 + public final int code;
  42 + public final String name;
  43 +
  44 + EnumStudentType(int code, String name) {
  45 + this.code = code;
  46 + this.name = name;
  47 + }
  48 + }
48 49  
49 50 }
... ...
cloud/dahua/src/main/java/com/example/dahua/module/GateModule.java
... ... @@ -5,6 +5,7 @@ import com.example.dahua.bean.WeekDay;
5 5 import com.example.dahua.bean.WeekTime;
6 6 import com.example.dahua.enums.EnumSendCardErrorType;
7 7 import com.example.dahua.enums.EnumSendFaceErrorType;
  8 +import com.example.dahua.enums.EnumSzBusinessType;
8 9 import com.example.dahua.lib.NetSDKLib;
9 10 import com.example.dahua.lib.NetSDKLib.*;
10 11 import com.example.dahua.lib.ToolKits;
... ... @@ -203,7 +204,7 @@ public class GateModule {
203 204 public static synchronized int insertCard(String cardNo, String userId, String cardName, String cardPwd,
204 205 int cardStatus, int cardType, int useTimes, int isFirstEnter,
205 206 int isValid, String startValidTime, String endValidTime, LLong lLong,
206   - String userType,String cardErrNum) {
  207 + String userType,String cardErrNum,int channel) {
207 208 /**
208 209 * 门禁卡记录集信息
209 210 */
... ... @@ -230,13 +231,13 @@ public class GateModule {
230 231 accessCardInfo.sznDoors[0] = 0;
231 232 accessCardInfo.sznDoors[1] = 1;
232 233 accessCardInfo.nTimeSectionNum = 2; // 与门数对应
233   -// if (userType.equals("1")){
  234 + if (userType.equals("1")){
234 235 accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效
235 236 accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效
236   -// }else {
237   -// accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
238   -// accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
239   -// }
  237 + }else {
  238 + accessCardInfo.sznTimeSectionNo[0] = channel; // 表示第一个门全天有效
  239 + accessCardInfo.sznTimeSectionNo[1] = channel; // 表示第二个门全天有效
  240 + }
240 241  
241 242 // 卡状态
242 243 accessCardInfo.emStatus = cardStatus;
... ... @@ -291,14 +292,13 @@ public class GateModule {
291 292 log.info("添加卡信息失败,错误信息:{} ,错误码:{} ",ret,number);
292 293 cardErrNum = number;
293 294 //146用户已存在,21对返回数据的校验出错,1162未知错误
294   - if(number.equals(EnumSendCardErrorType.CHECK_DATA_ERR_21.code)|| number.equals(EnumSendCardErrorType.EXIST_USER_146.code)||
295   - number.equals(EnumSendCardErrorType.UNKNOWN_1162.code)) {
  295 + if(number.equals(EnumSendCardErrorType.CHECK_DATA_ERR_21.code)||number.equals(EnumSendCardErrorType.EXIST_USER_146.code)) {
296 296 //用户已存在/返回数据校验出错时,执行删除用户
297 297 deleteUser( userId, lLong);
298 298 //重新下发卡至设备
299 299 cardErrNum = "";
300 300 return insertCard(cardNo, userId, cardName, cardPwd, cardStatus, cardType, useTimes, isFirstEnter,
301   - isValid, startValidTime, endValidTime, lLong, userType,cardErrNum);
  301 + isValid, startValidTime, endValidTime, lLong, userType,cardErrNum,channel);
302 302 }
303 303 //新增卡失败,错误码,返回-1
304 304 return -1;
... ... @@ -414,10 +414,12 @@ public class GateModule {
414 414 CFG_ACCESS_TIMESCHEDULE_INFO msg = new CFG_ACCESS_TIMESCHEDULE_INFO();
415 415 String strCmd = NetSDKLib.CFG_CMD_ACCESSTIMESCHEDULE;
416 416 // 通道号
417   - int nChannel = 120;
  417 + int nChannel = Integer.parseInt(permissionBean.getChannel());
418 418 // msg.stuTimeWeekDay[0].stuTimeSection[0].dwRecordMask
419   - String name = "3";
  419 + //自定义名称
  420 + String name = permissionBean.getCustomName();
420 421 System.arraycopy(name.getBytes(), 0, msg.szName, 0, name.getBytes().length);
  422 + //时间段使能开关, 1-true; 0-false
421 423 msg.bEnable = 1;
422 424  
423 425 List<WeekDay> weekDays = permissionBean.getWeekDays();
... ... @@ -525,10 +527,11 @@ public class GateModule {
525 527  
526 528 }
527 529  
528   - public static void getAccessTimeSchedule1(LLong lLong) {
  530 + public static void getAccessTimeSchedule1(LLong lLong,String channel) {
529 531 CFG_ACCESS_TIMESCHEDULE_INFO msg = new CFG_ACCESS_TIMESCHEDULE_INFO();
530 532 String strCmd = NetSDKLib.CFG_CMD_ACCESSTIMESCHEDULE;
531   - int nChannel = 120; // 通道号
  533 + // 通道号
  534 + int nChannel = Integer.parseInt(channel);
532 535  
533 536 // 获取
534 537 if (ToolKits.GetDevConfig(lLong, nChannel, strCmd, msg)) {
... ... @@ -687,7 +690,7 @@ public class GateModule {
687 690 public static boolean modifyCard(int recordNo, String cardNo, String userId, String cardName, String cardPwd,
688 691 int cardStatus, int cardType, int useTimes, int isFirstEnter,
689 692 int isValid, String startValidTime, String endValidTime, LLong lLong,
690   - String userType,String cardErrNum) {
  693 + String userType,String cardErrNum,int channel) {
691 694 /**
692 695 * 门禁卡记录集信息
693 696 */
... ... @@ -715,13 +718,14 @@ public class GateModule {
715 718 accessCardInfo.nDoorNum = 2;
716 719 accessCardInfo.sznDoors[0] = 0;
717 720 accessCardInfo.sznDoors[1] = 1;
718   - accessCardInfo.nTimeSectionNum = 2; // 与门数对应
719   - if (userType.equals("1")){
  721 + // 有效的的开门时间段数目 ,与设备门数保持一至
  722 + accessCardInfo.nTimeSectionNum = 2;
  723 + if (userType.equals(EnumSzBusinessType.EnumUserType.TEACHER.code)){
720 724 accessCardInfo.sznTimeSectionNo[0] = 255; // 表示第一个门全天有效
721 725 accessCardInfo.sznTimeSectionNo[1] = 255; // 表示第二个门全天有效
722 726 }else {
723   - accessCardInfo.sznTimeSectionNo[0] = 120; // 表示第一个门全天有效
724   - accessCardInfo.sznTimeSectionNo[1] = 120; // 表示第二个门全天有效
  727 + accessCardInfo.sznTimeSectionNo[0] = channel; // 表示第一个门全天有效
  728 + accessCardInfo.sznTimeSectionNo[1] = channel; // 表示第二个门全天有效
725 729 }
726 730  
727 731 // 卡状态
... ...
cloud/dahua/src/main/java/com/example/dahua/service/PermissFaceService.java
... ... @@ -17,4 +17,6 @@ public interface PermissFaceService {
17 17  
18 18  
19 19 ResponseBean<String> addFace(String imgUrl, String userId);
  20 +
  21 + public List<PermissionFaceBean> getPermissionList(int schoolId);
20 22 }
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/PermissFaceServiceImp.java
... ... @@ -41,7 +41,14 @@ public class PermissFaceServiceImp implements PermissFaceService {
41 41  
42 42 int schoolId = permissionFaceBean.getSchoolId();
43 43  
  44 + //编辑设置
44 45 PermissionBean permissionBean = permissionFaceBean.getPermissionBean();
  46 + if(!StringUtils.isEmpty(permissionFaceBean.getChannel())){
  47 + permissionBean.setChannel(permissionFaceBean.getChannel());
  48 + }
  49 + if(!StringUtils.isEmpty(permissionFaceBean.getCustomName())){
  50 + permissionBean.setChannel(permissionFaceBean.getCustomName());
  51 + }
45 52  
46 53 int type = permissionFaceBean.getType();
47 54 if (null != permissionBean)
... ... @@ -56,9 +63,19 @@ public class PermissFaceServiceImp implements PermissFaceService {
56 63 }
57 64 switch (type) {
58 65 case 0://新增
  66 + /**通道号**/
  67 + String channel = Rand();
  68 + /**通道自定义名称**/
  69 + String customName = Rand();
  70 + permissionBean.setChannel(channel);
  71 + permissionBean.setCustomName(customName);
  72 + permissionFaceBean.setChannel(channel);
  73 + permissionFaceBean.setCustomName(customName);
  74 +
59 75 permissionFaceDao.addPermissionFace(permissionFaceBean);
60 76 responseBean.setMessage("添加权限模板成功");
61 77 responseBean.setData(null);
  78 + //下发权限
62 79 sendPermiss2Dev(permissionFaceBean);
63 80 responseBean.setStatus(1);
64 81 break;
... ... @@ -94,6 +111,16 @@ public class PermissFaceServiceImp implements PermissFaceService {
94 111 }
95 112  
96 113 /**
  114 + * 取100以内随机数
  115 + * @return
  116 + */
  117 + public static String Rand() {
  118 + int rand = (int) (Math.random() * 100000) % 100;
  119 + return String.valueOf(rand);
  120 + }
  121 +
  122 +
  123 + /**
97 124 * 下发权限到设备
98 125 *
99 126 * @param permissionFaceBean
... ... @@ -140,6 +167,12 @@ public class PermissFaceServiceImp implements PermissFaceService {
140 167 }
141 168  
142 169 @Override
  170 + public List<PermissionFaceBean> getPermissionList(int schoolId) {
  171 + List<PermissionFaceBean> permissionFaceBeans = permissionFaceDao.getPermissFaces(schoolId);
  172 + return permissionFaceBeans;
  173 + }
  174 +
  175 + @Override
143 176 public ResponseBeanList<PermissionFaceBean> getPermissionDetail(int permissionId) {
144 177 ResponseBeanList responseBeanList = new ResponseBeanList();
145 178 try {
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java
... ... @@ -129,7 +129,7 @@ public class UserServiceImp implements UserService {
129 129 NetSDKLib.LLong loginHandleLong = MyTask.lLongMap.get(deviceId);
130 130 //下发权限
131 131 GateModule.setAccessTimeSchedule(loginHandleLong, permissionBean);
132   - GateModule.getAccessTimeSchedule1(loginHandleLong);
  132 + GateModule.getAccessTimeSchedule1(loginHandleLong,permissionBean.getChannel());
133 133 }
134 134  
135 135  
... ...
cloud/dahua/src/main/java/com/example/dahua/utils/JsonUtils.java 0 → 100644
... ... @@ -0,0 +1,133 @@
  1 +package com.example.dahua.utils;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonInclude.Include;
  4 +import com.fasterxml.jackson.core.type.TypeReference;
  5 +import com.fasterxml.jackson.databind.DeserializationFeature;
  6 +import com.fasterxml.jackson.databind.JavaType;
  7 +import com.fasterxml.jackson.databind.ObjectMapper;
  8 +import org.apache.commons.lang.StringUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +
  12 +import java.io.IOException;
  13 +import java.util.Map;
  14 +
  15 +/**
  16 + * 类JsonMapper.java的实现描述:简单封装Jackson,实现JSON String<->Java Object的Mapper.
  17 + *
  18 + * <p> 封装不同的输出风格, 使用不同的builder函数创建实例. </p>
  19 + *
  20 + * @author xuquan
  21 + */
  22 +public class JsonUtils {
  23 +
  24 + private static final Logger LOG = LoggerFactory.getLogger(JsonUtils.class);
  25 +
  26 + private ObjectMapper mapper;
  27 +
  28 + public JsonUtils(){
  29 + this(null);
  30 + }
  31 +
  32 + public JsonUtils(Include include) {
  33 + mapper = new ObjectMapper();
  34 + // 设置输出时包含属性的风格
  35 + if (include != null) {
  36 + mapper.setSerializationInclusion(include);
  37 + }
  38 + // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
  39 + mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
  40 + }
  41 +
  42 + /**
  43 + * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
  44 + */
  45 + public static JsonUtils nonEmptyMapper() {
  46 + return new JsonUtils(Include.NON_EMPTY);
  47 + }
  48 +
  49 + /**
  50 + * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
  51 + */
  52 + public static JsonUtils nonDefaultMapper() {
  53 + return new JsonUtils(Include.NON_DEFAULT);
  54 + }
  55 +
  56 + /**
  57 + * Object可以是POJO,也可以是Collection或数组。
  58 + * 如果对象为Null, 返回"null".
  59 + * 如果集合为空集合, 返回"[]".
  60 + */
  61 + public String toJson(Object object) {
  62 +
  63 + try {
  64 + return mapper.writeValueAsString(object);
  65 + } catch (IOException e) {
  66 + LOG.warn(String.format("序列化成 JSON 字符串发生错误:%s", object), e);
  67 + return null;
  68 + }
  69 + }
  70 +
  71 + /**
  72 + * 反序列化POJO或简单Collection如List<String>.
  73 + *
  74 + * 如果JSON字符串为Null或"null"字符串, 返回Null.
  75 + * 如果JSON字符串为"[]", 返回空集合.
  76 + *
  77 + * 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String, JavaType)
  78 + *
  79 + * @see #fromJson(String, JavaType)
  80 + */
  81 + public <T> T fromJson(String jsonString, Class<T> clazz) {
  82 + if (StringUtils.isEmpty(jsonString)) {
  83 + return null;
  84 + }
  85 +
  86 + try {
  87 + return mapper.readValue(jsonString, clazz);
  88 + } catch (IOException e) {
  89 + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e);
  90 + return null;
  91 + }
  92 + }
  93 +
  94 + /**
  95 + * 反序列化泛型对象
  96 + * @param <T>
  97 + * @param jsonString
  98 + * @param typeReference
  99 + * @return
  100 + */
  101 + public <T> T fromJson(String jsonString, TypeReference<T> typeReference) {
  102 + if (StringUtils.isEmpty(jsonString)) {
  103 + return null;
  104 + }
  105 +
  106 + try {
  107 + return mapper.readValue(jsonString, typeReference);
  108 + } catch (IOException e) {
  109 + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e);
  110 + return null;
  111 + }
  112 + }
  113 +
  114 + /**
  115 + * 反序列化复杂Collection如List<Bean>, 先使用createCollectionType()或contructMapType()构造类型, 然后调用本函数.
  116 + *
  117 + * @see #(Class, Class...)
  118 + */
  119 + public <T> T fromJson(String jsonString, JavaType javaType) {
  120 + if (StringUtils.isEmpty(jsonString)) {
  121 + return null;
  122 + }
  123 +
  124 + try {
  125 + return mapper.readValue(jsonString, javaType);
  126 + } catch (IOException e) {
  127 + LOG.error(String.format("解析 JSON 字符串发生错误:%s", jsonString), e);
  128 + return null;
  129 + }
  130 + }
  131 +
  132 +
  133 +}
... ...
cloud/dahua/src/main/resources/mapper/PermissionFaceMapper.xml
... ... @@ -23,7 +23,7 @@
23 23  
24 24 <insert id="addPermissionFace" parameterType="com.example.dahua.bean.PermissionFaceBean">
25 25  
26   - insert into PermissionFace values (#{permissionJson},#{schoolId},#{perrmissName},#{createTime},#{updateTime})
  26 + insert into PermissionFace values (#{permissionJson},#{schoolId},#{perrmissName},#{createTime},#{updateTime},#{channel},#{customName})
27 27  
28 28 </insert>
29 29  
... ...
cloud/dahua/src/test/java/com/example/dahua/mapper/SearchMapperTest.java
... ... @@ -5,6 +5,7 @@ import com.example.dahua.Tester;
5 5 import com.example.dahua.bean.CheckIn;
6 6 import com.example.dahua.bean.ShortMsg;
7 7 import com.example.dahua.dao.UserDao;
  8 +import com.example.dahua.service.UserService;
8 9 import com.example.dahua.utils.DateUtils;
9 10 import com.example.dahua.xiananDao.SearchMapper;
10 11 import org.junit.Test;
... ... @@ -27,6 +28,9 @@ public class SearchMapperTest extends Tester {
27 28 @Autowired
28 29 private UserDao userDao;
29 30  
  31 + @Autowired
  32 + private UserService userService;
  33 +
30 34 @Test
31 35 public void test(){
32 36 //有效刷卡调考勤存储过程
... ... @@ -61,4 +65,6 @@ public class SearchMapperTest extends Tester {
61 65 // System.out.println(JSON.toJSON(userDao.checkLeave("234232")));
62 66  
63 67 }
  68 +
  69 +// boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid);
64 70 }
... ...