SmartVisitorController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. import com.seewo.open.sdk.DefaultSeewoClient;
  8. import com.seewo.open.sdk.SeewoClient;
  9. import com.seewo.open.sdk.auth.Account;
  10. import com.template.annotation.DESRespondSecret;
  11. import com.template.api.SmartVisitorControllerAPI;
  12. import com.template.common.utils.*;
  13. import com.template.config.ParkConfig;
  14. import com.template.config.SeewoConfig;
  15. import com.template.model.enumModel.*;
  16. import com.template.model.pojo.*;
  17. import com.template.model.request.otherAppointmentRequest;
  18. import com.template.model.request.parentsAppointmentRequest;
  19. import com.template.model.request.turnOnTheDeviceRequest;
  20. import com.template.model.result.CommonResult;
  21. import com.template.model.result.PageUtils;
  22. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidParam;
  23. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidRequest;
  24. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidResult;
  25. import com.template.model.vo.*;
  26. import com.template.services.SmartAuthorGroupService;
  27. import com.template.services.SmartQrcodeService;
  28. import com.template.services.SmartUserService;
  29. import com.template.services.SmartVisitorService;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.transaction.annotation.Transactional;
  32. import org.springframework.validation.BindingResult;
  33. import org.springframework.web.bind.annotation.RequestParam;
  34. import org.springframework.web.bind.annotation.RestController;
  35. import javax.annotation.Resource;
  36. import java.net.URLDecoder;
  37. import java.util.*;
  38. import java.util.stream.Collectors;
  39. import static com.template.common.utils.AesTestOne.decrypt;
  40. /**
  41. * <p>
  42. * 前端控制器
  43. * </p>
  44. *
  45. * @author ceshi
  46. * @since 2023-12-04
  47. */
  48. @RestController
  49. //返回参数加密注解
  50. @DESRespondSecret
  51. public class SmartVisitorController implements SmartVisitorControllerAPI {
  52. @Autowired
  53. private SmartAuthorGroupService smartAuthorGroupService;
  54. @Autowired
  55. private SmartVisitorService smartVisitorService;
  56. @Autowired
  57. private SmartQrcodeService smartQrcodeService;
  58. @Autowired
  59. private SmartUserService smartUserService;
  60. @Resource
  61. private SeewoConfig seewoConfig;
  62. @Resource
  63. private ParkConfig parkConfig;
  64. /**
  65. * 新增访客预约
  66. *
  67. * @param smartApply 访客预约数据
  68. * @param bindingResult
  69. * @return
  70. */
  71. @Override
  72. @DESRespondSecret(validated = true)
  73. public CommonResult insertSmartVisitor(SmartVisitor smartApply, BindingResult bindingResult) {
  74. if (bindingResult.hasErrors()) {
  75. String st = paramUtils.getParamError(bindingResult);
  76. return CommonResult.fail(st);
  77. }
  78. int result = smartVisitorService.insertSmartVisitor(smartApply);
  79. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  80. }
  81. /**
  82. * 更新访客预约
  83. *
  84. * @param sa 访客预约数据
  85. * @param bindingResult
  86. * @return
  87. */
  88. @Override
  89. @DESRespondSecret(validated = true)
  90. public CommonResult updateSmartVisitorById(SmartVisitor sa, BindingResult bindingResult) {
  91. if (bindingResult.hasErrors()) {
  92. String st = paramUtils.getParamError(bindingResult);
  93. return CommonResult.fail(st);
  94. }
  95. int result = smartVisitorService.updateSmartVisitor(sa);
  96. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  97. }
  98. /**
  99. * 访客预约分页数据查询
  100. *
  101. * @param currentPage 当前页数
  102. * @param pageCount 一页数据条数
  103. * @param name 查询名称
  104. * @return
  105. */
  106. @Override
  107. @DESRespondSecret(validated = true)
  108. public CommonResult queryPageSmartVisitor(int currentPage, int pageCount, String name) {
  109. PageUtils<SmartVisitor> result = smartVisitorService.queryPageSmartVisitors(currentPage, pageCount, name);
  110. return CommonResult.ok(result);
  111. }
  112. @Override
  113. @DESRespondSecret(validated = true)
  114. public CommonResult deleteSmartVisitorById(int id) {
  115. SmartVisitor data = smartVisitorService.getSmartById(id);
  116. if (data == null) {
  117. return CommonResult.fail("当前数据不存在,删除失败!");
  118. }
  119. //审核通过就不能删除
  120. if (data.getStatu().intValue() == eApproveStatu.Pushed.getValue()) {
  121. return CommonResult.fail("无法删除已审核通过的访客数据");
  122. }
  123. //已审核通过的数据不能删除 那么就不需要进行下面这些操作
  124. //region 推送到希沃班牌,通知访客记录取消
  125. //endregion
  126. //region 删除百胜中的访客数据
  127. //endregion
  128. int result = smartVisitorService.deleteSmartVisitorById(id);
  129. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  130. }
  131. @Override
  132. @DESRespondSecret(validated = true)
  133. public CommonResult parentsAppointment(parentsAppointmentRequest par, BindingResult bindingResult) {
  134. if (bindingResult.hasErrors()) {
  135. String st = paramUtils.getParamError(bindingResult);
  136. return CommonResult.fail(st);
  137. }
  138. //参数判断 判断受访学生信息是否为空
  139. if (par.getStudents() == null) {
  140. return CommonResult.fail("请选择受访学生");
  141. }
  142. if (par.getStudents().size() <= 0) {
  143. return CommonResult.fail("请选择受访学生");
  144. }
  145. //根据用户ID查询相关信息
  146. SmartUser su = smartUserService.getSmartById(par.getUserId());
  147. if (su == null) {
  148. return CommonResult.fail("当前用户信息不合法,无法进行预约!");
  149. }
  150. String startTime = par.getVisitorTime();
  151. String endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  152. //要进行家长数据重复判断
  153. //那是不是第二次预约的时间不能在那个可访问的时间段内
  154. //例如:比如,第一次约了7:00-10:00;那第二次:6:00-7:30 或 8:11-13:00都不行
  155. Integer count = smartVisitorService.queryVisitorCount(su.getIdCard(), startTime, endTime);
  156. if (count > 0) {
  157. return CommonResult.fail("该时间段已预约,请勿重复预约!");
  158. }
  159. List<SmartVisitor> svs = new ArrayList<>();
  160. for (AffiliateUserVo student : par.getStudents()) {
  161. SmartVisitor sv = new SmartVisitor();
  162. sv.setUserId(par.getUserId());
  163. sv.setUserName(su.getName());
  164. sv.setUserPhone(su.getPhone());
  165. sv.setUserNumber(su.getIdCard());
  166. sv.setPeerNum(par.getPeerNum());
  167. //sv.setCarNum(par.getCarNum());家长预约不能填写车牌号
  168. sv.setVisitReason(par.getVisitReason());
  169. sv.setStatu(eApproveStatu.Audit.getValue());
  170. sv.setVisitorTime(TimeExchange.StringToDate(par.getVisitorTime(), "yyyy-MM-dd HH:mm:ss"));
  171. sv.setVisitorDeadline(TimeExchange.StringToDate(TimeExchange.TimeDesH(sv.getVisitorTime(), 4), "yyyy-MM-dd HH:mm:ss"));
  172. sv.setRespondent(student.getId());
  173. sv.setResponcode(student.getCardNo());
  174. sv.setRespondentName(student.getName());
  175. //将第一个受访学生的部门ID带过去
  176. sv.setDepartmentId(student.getDepartmentId());
  177. sv.setVisitorType(eVisitorType.Parent.getValue());
  178. svs.add(sv);
  179. }
  180. boolean result = smartVisitorService.insertVisitorBatch(svs);
  181. return result ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.fail("预约失败");
  182. }
  183. @Override
  184. @DESRespondSecret(validated = true)
  185. public CommonResult otherAppointment(otherAppointmentRequest oar, BindingResult bindingResult) {
  186. if (bindingResult.hasErrors()) {
  187. String st = paramUtils.getParamError(bindingResult);
  188. return CommonResult.fail(st);
  189. }
  190. //根据用户ID查询相关信息
  191. SmartUser su = smartUserService.getSmartById(oar.getUserId());
  192. if (su == null) {
  193. return CommonResult.fail("当前用户信息不合法,无法进行预约!");
  194. }
  195. String startTime = oar.getVisitorTime();
  196. String endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  197. //要进行访客数据重复判断
  198. //那是不是第二次预约的时间不能在那个可访问的时间段内
  199. //例如:比如,第一次约了7:00-10:00;那第二次:6:00-7:30 或 8:11-13:00都不行
  200. Integer count = smartVisitorService.queryVisitorCount(su.getIdCard(), startTime, endTime);
  201. if (count > 0) {
  202. return CommonResult.fail("该时间段已预约,请勿重复预约!");
  203. }
  204. SmartVisitor sv = new SmartVisitor();
  205. sv.setUserId(oar.getUserId());
  206. sv.setUserName(oar.getUserName());
  207. sv.setUserPhone(oar.getUserPhone());
  208. sv.setUserNumber(oar.getUserCard());
  209. sv.setPeerNum(oar.getPeerNum());
  210. sv.setCarNum(oar.getCarNum());
  211. sv.setVisitReason(oar.getVisitReason());
  212. sv.setStatu(eApproveStatu.Audit.getValue());
  213. sv.setVisitorTime(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  214. sv.setVisitorDeadline(TimeExchange.StringToDate(endTime, "yyyy-MM-dd HH:mm:ss"));
  215. sv.setRespondentName(oar.getRespondentName());
  216. sv.setRespondentPhone(oar.getRespondentPhone());
  217. sv.setVisitorType(eVisitorType.Other.getValue());
  218. int result = smartVisitorService.insertSmartVisitor(sv);
  219. return result > 0 ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.ok("预约失败");
  220. }
  221. @Override
  222. @DESRespondSecret(validated = true)
  223. public CommonResult appointmentPageRecord(int currentPage, int pageCount, Integer userId, int type, String createStartTime, String createEndTime, String keyWord, String visitorStartTime, String visitorEndTime) {
  224. PageUtils<VisitorPageVo> result = smartVisitorService.smartVisitorPageByUserId(currentPage, pageCount, userId, type, createStartTime, createEndTime, keyWord, visitorStartTime, visitorEndTime);
  225. return CommonResult.ok(result);
  226. }
  227. /**
  228. * 访客记录审核
  229. *
  230. * @param id 数据ID
  231. * @param type 操作类型:
  232. * 同意,并推送:1
  233. * 拒绝:2
  234. * @return
  235. */
  236. @Override
  237. @Transactional(rollbackFor = {Exception.class})
  238. public CommonResult examineRecord(int id, int type) throws Exception {
  239. SmartVisitor visitor = smartVisitorService.getSmartById(id);
  240. if (visitor == null) {
  241. return CommonResult.fail("访客记录已失效,审核失败!");
  242. }
  243. //审核处理后的数据不能再处理判断
  244. if (visitor.getStatu().intValue() != eApproveStatu.Audit.getValue()) {
  245. return CommonResult.fail("该记录已被操作过,请勿重复操作");
  246. }
  247. try {
  248. if (type == eExamineStatu.Agree.getValue()) {
  249. visitor.setStatu(eApproveStatu.Pushed.getValue());
  250. //家长访客预约才需要将消息推送到希沃电子班牌
  251. if (visitor.getVisitorType().intValue() == eVisitorType.Parent.getValue()) {
  252. String content = visitor.getRespondentName() + "你的家长将于" + TimeExchange.chineseDateTime(visitor.getVisitorTime()) + "到校!";
  253. //将预约信息推送到希沃班牌
  254. CommonResult seewo = pushInfo(visitor.getUserPhone(), visitor.getResponcode(), content);
  255. if (!seewo.getCode().equals("200")) {
  256. throw new Exception("审核失败");
  257. }
  258. }
  259. //将数据写入门禁系统逻辑
  260. else {
  261. //家长不能使用车牌系统 其他的可以使用车牌逻辑
  262. if (!ObjectUtils.isEmpty(visitor.getCarNum())) {
  263. String appId = parkConfig.getAppId();
  264. String carNo = visitor.getCarNum();
  265. String parkKey = parkConfig.getParkKey();
  266. String rand = String.valueOf(Math.random());
  267. String reserveTime = TimeExchange.DateToString(visitor.getVisitorTime(), "yyyy-MM-dd HH:mm:ss");
  268. String reserveEndTime = TimeExchange.DateToString(visitor.getVisitorDeadline(), "yyyy-MM-dd HH:mm:ss");
  269. String version = "v1.0";
  270. String appSecret = parkConfig.getAppSecret();
  271. String url = parkConfig.getUrl() + "Inform/Reservation";
  272. JSONObject jsonobject = new JSONObject();
  273. jsonobject.put("appid", appId);
  274. jsonobject.put("carNo", carNo);
  275. jsonobject.put("parkKey", parkKey);
  276. jsonobject.put("rand", rand);
  277. jsonobject.put("reserveEndTime", reserveEndTime);
  278. jsonobject.put("reserveTime", reserveTime);
  279. jsonobject.put("version", "v1.0");
  280. //appid=ymdd36ed157ac423e2&carNo=赣U123659&parkKey=wdcmq9rc&rand=9.94995525689689966&reserveEndTime=2023-12-22 20:12:10&reserveTime=2023-12-21 18:12:10&version=v1.0&50596cd243dc4547b4c05f01f8ea02a4
  281. String md5Str = "appid=" + appId + "&carNo=" + carNo + "&parkKey=" + parkKey + "&rand=" + rand + "&reserveEndTime=" + reserveEndTime + "&reserveTime=" + reserveTime + "&version=" + version + "&" + appSecret;
  282. String sign = CommonUtil.MD5(md5Str);
  283. //sign签名
  284. jsonobject.put("sign", sign);
  285. //返回的结果中 code为1表示成功
  286. String result = RequestUtils.httpPost(url, jsonobject.toJSONString());
  287. System.out.println(result);
  288. if (!result.contains("预约成功")) {
  289. throw new Exception("审核失败");
  290. }
  291. ObjectMapper objectMapper = new ObjectMapper();
  292. BsReservationVo reservation = objectMapper.readValue(result, BsReservationVo.class);
  293. visitor.setBsOrderNo(reservation.getData().getReOrderNo());
  294. } else {
  295. String code = GetVertifyCode.getRandomNumCode(6);
  296. visitor.setVisitorCode(code);
  297. }
  298. }
  299. } else if (type == eExamineStatu.Refused.getValue()) {
  300. visitor.setStatu(eApproveStatu.Refused.getValue());
  301. }
  302. int result = smartVisitorService.updateSmartVisitor(visitor);
  303. if (result <= 0) {
  304. throw new Exception("审核失败");
  305. }
  306. //发送短信给其他访客用户
  307. if (!ObjectUtils.isEmpty(visitor.getVisitorCode()) && type == eExamineStatu.Agree.getValue()) {
  308. String message = SendSms.sendVisitorSms("+86" + visitor.getUserPhone(), TimeExchange.getYear(visitor.getVisitorTime()), TimeExchange.getMonth(visitor.getVisitorTime()), TimeExchange.getDay(visitor.getVisitorTime()), TimeExchange.getTime(visitor.getVisitorTime()), TimeExchange.getTime(visitor.getVisitorDeadline()), visitor.getVisitorCode());
  309. if (!message.contains("success")) {
  310. throw new Exception("审核失败");
  311. }
  312. }
  313. } catch (Exception e) {
  314. throw new Exception("审核失败");
  315. }
  316. return CommonResult.ok("审核成功");
  317. }
  318. /**
  319. * 将预约信息推送到希沃电子班牌
  320. *
  321. * @param parentPhone 预约手机号(家长手机号 在希沃中学生会和家长手机号绑定 可以绑定多个家长)
  322. * @param studentCode 学生编号 希沃中的学生编号和万载系统中的一致
  323. * @param content 消息内容
  324. * @return
  325. */
  326. public CommonResult pushInfo(String parentPhone, String studentCode, String content) {
  327. //初始化客户端
  328. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  329. HomeSchoolServiceSendNoteToKidParam param = new HomeSchoolServiceSendNoteToKidParam();
  330. //响应体,MimeType为 application/json
  331. HomeSchoolServiceSendNoteToKidParam.RequestBody requestBody = HomeSchoolServiceSendNoteToKidParam.RequestBody.builder()
  332. .build();
  333. param.setRequestBody(requestBody);
  334. //query
  335. HomeSchoolServiceSendNoteToKidParam.Query query = HomeSchoolServiceSendNoteToKidParam.Query.builder()
  336. .appId(seewoConfig.getAppId())
  337. .schoolUid(seewoConfig.getSchoolId())
  338. .senderPhone(parentPhone)
  339. .studentCode(studentCode)
  340. .type(1)
  341. .content(content)
  342. .autoRegister(0)
  343. .build();
  344. requestBody.setQuery(query);
  345. param.setRequestBody(requestBody);
  346. HomeSchoolServiceSendNoteToKidRequest request = new HomeSchoolServiceSendNoteToKidRequest(param);
  347. System.out.println("入参:" + request);
  348. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  349. //request.setServerUrl("https://openapi.test.seewo.com")
  350. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  351. HomeSchoolServiceSendNoteToKidResult result = seewoClient.invoke(request);
  352. System.out.println("出参:" + result);
  353. if (!result.getMessage().equals("success")) {
  354. CommonResult.fail();
  355. }
  356. return CommonResult.ok();
  357. }
  358. /**
  359. * 获取到访代办数据
  360. *
  361. * @param userId
  362. * @return
  363. */
  364. @Override
  365. @DESRespondSecret(validated = true)
  366. public CommonResult visitingAgencys(int currentPage, int pageCount, int userId, int type) {
  367. SmartUser user = smartUserService.getSmartById(userId);
  368. if (user == null) {
  369. return CommonResult.fail("当前用户数据无效,获取到访数据失败");
  370. }
  371. if (user.getIdentityId().intValue() != eIdentityStatu.Teacher.getValue()) {
  372. return CommonResult.fail("非教师身份无法获取到访数据");
  373. }
  374. //是否是管理员
  375. String whereSql = null;
  376. //获取的权限组数据
  377. List<SmartAuthorGroup> authorGroups = smartAuthorGroupService.smartAuthorGroup(user.getId());
  378. for (SmartAuthorGroup authorGroup : authorGroups) {
  379. List<String> applyIds = Arrays.asList(authorGroup.getApplyId().split(","));
  380. //菜单表中7是访客预约
  381. long appointCount = applyIds.stream().filter(e -> e.equals("7")).count();
  382. if (appointCount > 0) {
  383. whereSql = "visitor_type = 2";
  384. break;
  385. }
  386. }
  387. List<Integer> studentIds = null;
  388. //班主任
  389. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  390. //班级ID
  391. Integer schoolClass = user.getSchoolClass();
  392. //获取该班级下的所有学生ID数据
  393. List<SmartUser> students = smartUserService.queryStudentBySchoolClass(user.getSchoolClass());
  394. if (students == null) {
  395. return CommonResult.fail("当前身份下不存在学生信息");
  396. }
  397. studentIds = students.stream().map(SmartUser::getId).collect(Collectors.toList());
  398. }
  399. PageUtils<SmartVisitor> result = new PageUtils<SmartVisitor>(null, 0, pageCount, currentPage);
  400. if (whereSql == null && studentIds == null) {
  401. return CommonResult.ok(result);
  402. }
  403. result = smartVisitorService.queryVisitorPageDatas(currentPage, pageCount, type, studentIds, studentIds != null && whereSql != null ? "or " + whereSql : whereSql);
  404. return CommonResult.ok(result);
  405. }
  406. @Override
  407. public TurnOnDeviceVo turnOnTheDevice(turnOnTheDeviceRequest data) throws JsonProcessingException {
  408. System.out.println("进入扫码解析,参数:" + JSON.toJSON(data));
  409. TurnOnDeviceVo result = new TurnOnDeviceVo();
  410. System.out.println("进入扫码解析1");
  411. //region 参数判断
  412. if (data == null) {
  413. result.setResultcode(2);
  414. result.setMessage("扫码参数不能为空");
  415. result.setActionName("qrCodePush");
  416. return result;
  417. }
  418. System.out.println("进入扫码解析2");
  419. if (data.getActionName() == null) {
  420. result.setResultcode(2);
  421. result.setMessage("指令不能为空");
  422. result.setActionName("qrCodePush");
  423. return result;
  424. }
  425. System.out.println("进入扫码解析3");
  426. if (!data.getActionName().equals("qrCodePush")) {
  427. result.setResultcode(2);
  428. result.setMessage("指令错误");
  429. result.setActionName("qrCodePush");
  430. return result;
  431. }
  432. System.out.println("进入扫码解析4");
  433. if (data.getData() == null) {
  434. result.setResultcode(2);
  435. result.setMessage("二维码内容不能为空");
  436. result.setActionName("qrCodePush");
  437. return result;
  438. }
  439. System.out.println("进入扫码解析5");
  440. ObjectMapper objectMapper = new ObjectMapper();
  441. qrCodeVo codeVo = objectMapper.readValue(data.getData(), qrCodeVo.class);
  442. if (codeVo == null) {
  443. result.setResultcode(2);
  444. result.setMessage("二维码内容不能为空");
  445. result.setActionName("qrCodePush");
  446. return result;
  447. }
  448. System.out.println("进入扫码解析6");
  449. if (codeVo.getQrCode() == null) {
  450. result.setResultcode(2);
  451. result.setMessage("二维码内容不能为空");
  452. result.setActionName("qrCodePush");
  453. return result;
  454. }
  455. System.out.println("进入扫码解析7");
  456. if (data.getDeviceno() == null) {
  457. result.setResultcode(2);
  458. result.setMessage("设备编号不能为空");
  459. result.setActionName("qrCodePush");
  460. return result;
  461. }
  462. System.out.println("进入扫码解析8");
  463. if (data.getVersion() == null) {
  464. result.setResultcode(2);
  465. result.setMessage("版本不能为空");
  466. result.setActionName("qrCodePush");
  467. return result;
  468. }
  469. //endregion
  470. System.out.println("进入扫码解析9");
  471. //解码逻辑
  472. QrcodeImageVo qiv = objectMapper.readValue(codeVo.getQrCode(), QrcodeImageVo.class);
  473. System.out.println("进入扫码解析10");
  474. SmartUser user = smartUserService.getSmartById(qiv.getId());
  475. if (user == null) {
  476. result.setResultcode(2);
  477. result.setMessage("用户身份无效,刷码失败");
  478. result.setActionName("qrCodePush");
  479. return result;
  480. }
  481. System.out.println("进入扫码解析11");
  482. //目前二维码一分钟内有效
  483. //过期:(时间戳 + 有效期分钟数)<= 当前时间
  484. //时间戳转时间
  485. Date dateNow = TimeExchange.StringToDate(TimeExchange.TimeRangeMinute(qiv.getTimestamp(), 1), "yyyy-MM-dd HH:mm:ss");
  486. System.out.println("dateNow参数:" + TimeExchange.DateToString(dateNow));
  487. System.out.println("当前时间参数:" + TimeExchange.DateToString(new Date()));
  488. if (new Date().after(dateNow)) {
  489. System.out.println("身份码过期");
  490. result.setResultcode(2);
  491. result.setMessage("身份码已过期");
  492. result.setActionName("qrCodePush");
  493. return result;
  494. }
  495. System.out.println("进入扫码解析12");
  496. //成功后将刷码记录存储到数据表中
  497. SmartQrcode sq = new SmartQrcode();
  498. sq.setUserId(0);
  499. sq.setSourceCode(data.getData());
  500. sq.setIsSuccess(1);
  501. System.out.println("进入扫码解析13");
  502. int insertResult = smartQrcodeService.insertSmartQrcode(sq);
  503. if (insertResult <= 0) {
  504. result.setResultcode(2);
  505. result.setMessage("新增刷码记录失败");
  506. result.setActionName("qrCodePush");
  507. return result;
  508. }
  509. System.out.println("进入扫码解析14");
  510. result.setResultcode(1);
  511. result.setMessage("成功");
  512. result.setActionName("qrCodePush");
  513. System.out.println("进入扫码解析,结果:" + JSON.toJSON(result));
  514. return result;
  515. }
  516. }