SmartVisitorController.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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.ControlConfig;
  14. import com.template.config.ParkConfig;
  15. import com.template.config.SeewoConfig;
  16. import com.template.model.enumModel.*;
  17. import com.template.model.pojo.*;
  18. import com.template.model.request.otherAppointmentRequest;
  19. import com.template.model.request.parentsAppointmentRequest;
  20. import com.template.model.request.turnOnTheDeviceRequest;
  21. import com.template.model.result.CommonResult;
  22. import com.template.model.result.PageUtils;
  23. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidParam;
  24. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidRequest;
  25. import com.template.model.seewo.HomeSchoolServiceSendNoteToKidResult;
  26. import com.template.model.vo.*;
  27. import com.template.services.*;
  28. import org.slf4j.Logger;
  29. import org.slf4j.LoggerFactory;
  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.net.URLEncoder;
  38. import java.util.*;
  39. import java.util.stream.Collectors;
  40. import static com.template.common.utils.AesTestOne.decrypt;
  41. import static com.template.common.utils.StrUtils.getUUIDBits;
  42. /**
  43. * <p>
  44. * 前端控制器
  45. * </p>
  46. *
  47. * @author ceshi
  48. * @since 2023-12-04
  49. */
  50. @RestController
  51. //返回参数加密注解
  52. @DESRespondSecret
  53. public class SmartVisitorController implements SmartVisitorControllerAPI {
  54. private static Logger logger = LoggerFactory.getLogger(SmartVisitorController.class);
  55. @Autowired
  56. private SmartAuthorGroupService smartAuthorGroupService;
  57. @Autowired
  58. private SmartVisitorService smartVisitorService;
  59. @Autowired
  60. private SmartQrcodeService smartQrcodeService;
  61. @Autowired
  62. private SmartDeviceService smartDeviceService;
  63. @Autowired
  64. private SmartUserService smartUserService;
  65. @Resource
  66. private ControlConfig controlConfig;
  67. @Resource
  68. private SeewoConfig seewoConfig;
  69. @Resource
  70. private ParkConfig parkConfig;
  71. /**
  72. * 新增访客预约
  73. *
  74. * @param smartApply 访客预约数据
  75. * @param bindingResult
  76. * @return
  77. */
  78. @Override
  79. @DESRespondSecret(validated = true)
  80. public CommonResult insertSmartVisitor(SmartVisitor smartApply, BindingResult bindingResult) {
  81. if (bindingResult.hasErrors()) {
  82. String st = paramUtils.getParamError(bindingResult);
  83. return CommonResult.fail(st);
  84. }
  85. int result = smartVisitorService.insertSmartVisitor(smartApply);
  86. return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
  87. }
  88. /**
  89. * 更新访客预约
  90. *
  91. * @param sa 访客预约数据
  92. * @param bindingResult
  93. * @return
  94. */
  95. @Override
  96. @DESRespondSecret(validated = true)
  97. public CommonResult updateSmartVisitorById(SmartVisitor sa, BindingResult bindingResult) {
  98. if (bindingResult.hasErrors()) {
  99. String st = paramUtils.getParamError(bindingResult);
  100. return CommonResult.fail(st);
  101. }
  102. int result = smartVisitorService.updateSmartVisitor(sa);
  103. return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
  104. }
  105. /**
  106. * 访客预约分页数据查询
  107. *
  108. * @param currentPage 当前页数
  109. * @param pageCount 一页数据条数
  110. * @param name 查询名称
  111. * @return
  112. */
  113. @Override
  114. @DESRespondSecret(validated = true)
  115. public CommonResult queryPageSmartVisitor(int currentPage, int pageCount, String name) {
  116. PageUtils<SmartVisitor> result = smartVisitorService.queryPageSmartVisitors(currentPage, pageCount, name);
  117. return CommonResult.ok(result);
  118. }
  119. @Override
  120. @DESRespondSecret(validated = true)
  121. public CommonResult deleteSmartVisitorById(int id) {
  122. SmartVisitor data = smartVisitorService.getSmartById(id);
  123. if (data == null) {
  124. return CommonResult.fail("当前数据不存在,删除失败!");
  125. }
  126. //审核通过就不能删除
  127. if (data.getStatu().intValue() == eApproveStatu.Pushed.getValue()) {
  128. return CommonResult.fail("无法删除已审核通过的访客数据");
  129. }
  130. //已审核通过的数据不能删除 那么就不需要进行下面这些操作
  131. //region 推送到希沃班牌,通知访客记录取消
  132. //endregion
  133. //region 删除百胜中的访客数据
  134. //endregion
  135. int result = smartVisitorService.deleteSmartVisitorById(id);
  136. return result > 0 ? CommonResult.ok("删除成功") : CommonResult.fail("删除失败");
  137. }
  138. @Override
  139. @DESRespondSecret(validated = true)
  140. public CommonResult parentsAppointment(parentsAppointmentRequest par, BindingResult bindingResult) {
  141. if (bindingResult.hasErrors()) {
  142. String st = paramUtils.getParamError(bindingResult);
  143. return CommonResult.fail(st);
  144. }
  145. //参数判断 判断受访学生信息是否为空
  146. if (par.getStudents() == null) {
  147. return CommonResult.fail("请选择受访学生");
  148. }
  149. if (par.getStudents().size() <= 0) {
  150. return CommonResult.fail("请选择受访学生");
  151. }
  152. //根据用户ID查询相关信息
  153. SmartUser su = smartUserService.getSmartById(par.getUserId());
  154. if (su == null) {
  155. return CommonResult.fail("当前用户信息不合法,无法进行预约!");
  156. }
  157. String startTime = par.getVisitorTime();
  158. String endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  159. //要进行家长数据重复判断
  160. //那是不是第二次预约的时间不能在那个可访问的时间段内
  161. //例如:比如,第一次约了7:00-10:00;那第二次:6:00-7:30 或 8:11-13:00都不行
  162. Integer count = smartVisitorService.queryVisitorCount(su.getIdCard(), startTime, endTime);
  163. if (count > 0) {
  164. return CommonResult.fail("该时间段已预约,请勿重复预约!");
  165. }
  166. List<SmartVisitor> svs = new ArrayList<>();
  167. for (AffiliateUserVo student : par.getStudents()) {
  168. SmartVisitor sv = new SmartVisitor();
  169. sv.setUserId(par.getUserId());
  170. sv.setUserName(su.getName());
  171. sv.setUserPhone(su.getPhone());
  172. sv.setUserNumber(su.getIdCard());
  173. sv.setPeerNum(par.getPeerNum());
  174. //sv.setCarNum(par.getCarNum());家长预约不能填写车牌号
  175. sv.setVisitReason(par.getVisitReason());
  176. sv.setStatu(eApproveStatu.Audit.getValue());
  177. sv.setVisitorTime(TimeExchange.StringToDate(par.getVisitorTime(), "yyyy-MM-dd HH:mm:ss"));
  178. sv.setVisitorDeadline(TimeExchange.StringToDate(TimeExchange.TimeDesH(sv.getVisitorTime(), 4), "yyyy-MM-dd HH:mm:ss"));
  179. sv.setRespondent(student.getId());
  180. sv.setResponcode(student.getCardNo());
  181. sv.setRespondentName(student.getName());
  182. //将第一个受访学生的部门ID带过去
  183. sv.setDepartmentId(student.getDepartmentId());
  184. sv.setVisitorType(eVisitorType.Parent.getValue());
  185. svs.add(sv);
  186. }
  187. boolean result = smartVisitorService.insertVisitorBatch(svs);
  188. return result ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.fail("预约失败");
  189. }
  190. @Override
  191. @DESRespondSecret(validated = true)
  192. public CommonResult otherAppointment(otherAppointmentRequest oar, BindingResult bindingResult) {
  193. if (bindingResult.hasErrors()) {
  194. String st = paramUtils.getParamError(bindingResult);
  195. return CommonResult.fail(st);
  196. }
  197. //根据用户ID查询相关信息
  198. SmartUser su = smartUserService.getSmartById(oar.getUserId());
  199. if (su == null) {
  200. return CommonResult.fail("当前用户信息不合法,无法进行预约!");
  201. }
  202. String startTime = oar.getVisitorTime();
  203. String endTime = TimeExchange.getEndOfDayStr(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  204. //要进行访客数据重复判断
  205. //那是不是第二次预约的时间不能在那个可访问的时间段内
  206. //例如:比如,第一次约了7:00-10:00;那第二次:6:00-7:30 或 8:11-13:00都不行
  207. Integer count = smartVisitorService.queryVisitorCount(su.getIdCard(), startTime, endTime);
  208. if (count > 0) {
  209. return CommonResult.fail("该时间段已预约,请勿重复预约!");
  210. }
  211. SmartVisitor sv = new SmartVisitor();
  212. sv.setUserId(oar.getUserId());
  213. sv.setUserName(oar.getUserName());
  214. sv.setUserPhone(oar.getUserPhone());
  215. sv.setUserNumber(oar.getUserCard());
  216. sv.setPeerNum(oar.getPeerNum());
  217. sv.setCarNum(oar.getCarNum());
  218. sv.setVisitReason(oar.getVisitReason());
  219. sv.setStatu(eApproveStatu.Audit.getValue());
  220. sv.setVisitorTime(TimeExchange.StringToDate(startTime, "yyyy-MM-dd HH:mm:ss"));
  221. sv.setVisitorDeadline(TimeExchange.StringToDate(endTime, "yyyy-MM-dd HH:mm:ss"));
  222. sv.setRespondentName(oar.getRespondentName());
  223. sv.setRespondentPhone(oar.getRespondentPhone());
  224. sv.setVisitorType(eVisitorType.Other.getValue());
  225. int result = smartVisitorService.insertSmartVisitor(sv);
  226. return result > 0 ? CommonResult.ok("预约成功,等待审批通过") : CommonResult.ok("预约失败");
  227. }
  228. @Override
  229. @DESRespondSecret(validated = true)
  230. public CommonResult appointmentPageRecord(int currentPage, int pageCount, Integer userId, int type, String createStartTime, String createEndTime, String keyWord, String visitorStartTime, String visitorEndTime) {
  231. PageUtils<VisitorPageVo> result = smartVisitorService.smartVisitorPageByUserId(currentPage, pageCount, userId, type, createStartTime, createEndTime, keyWord, visitorStartTime, visitorEndTime);
  232. return CommonResult.ok(result);
  233. }
  234. /**
  235. * 访客记录审核
  236. *
  237. * @param id 数据ID
  238. * @param type 操作类型:
  239. * 同意,并推送:1
  240. * 拒绝:2
  241. * @return
  242. */
  243. @Override
  244. @Transactional(rollbackFor = {Exception.class})
  245. public CommonResult examineRecord(int id, int type) throws Exception {
  246. SmartVisitor visitor = smartVisitorService.getSmartById(id);
  247. if (visitor == null) {
  248. return CommonResult.fail("访客记录已失效,审核失败!");
  249. }
  250. //审核处理后的数据不能再处理判断
  251. if (visitor.getStatu().intValue() != eApproveStatu.Audit.getValue()) {
  252. return CommonResult.fail("该记录已被操作过,请勿重复操作");
  253. }
  254. try {
  255. if (type == eExamineStatu.Agree.getValue()) {
  256. visitor.setStatu(eApproveStatu.Pushed.getValue());
  257. //家长访客预约才需要将消息推送到希沃电子班牌
  258. if (visitor.getVisitorType().intValue() == eVisitorType.Parent.getValue()) {
  259. String content = visitor.getRespondentName() + "你的家长将于" + TimeExchange.chineseDateTime(visitor.getVisitorTime()) + "到校!";
  260. //将预约信息推送到希沃班牌
  261. CommonResult seewo = pushInfo(visitor.getUserPhone(), visitor.getResponcode(), content);
  262. if (!seewo.getCode().equals("200")) {
  263. throw new Exception("审核失败");
  264. }
  265. }
  266. //将数据写入门禁系统逻辑
  267. else {
  268. //家长不能使用车牌系统 其他的可以使用车牌逻辑
  269. if (!ObjectUtils.isEmpty(visitor.getCarNum())) {
  270. String appId = parkConfig.getAppId();
  271. String carNo = visitor.getCarNum();
  272. String parkKey = parkConfig.getParkKey();
  273. String rand = String.valueOf(Math.random());
  274. String reserveTime = TimeExchange.DateToString(visitor.getVisitorTime(), "yyyy-MM-dd HH:mm:ss");
  275. String reserveEndTime = TimeExchange.DateToString(visitor.getVisitorDeadline(), "yyyy-MM-dd HH:mm:ss");
  276. String version = "v1.0";
  277. String appSecret = parkConfig.getAppSecret();
  278. String url = parkConfig.getUrl() + "Inform/Reservation";
  279. JSONObject jsonobject = new JSONObject();
  280. jsonobject.put("appid", appId);
  281. jsonobject.put("carNo", carNo);
  282. jsonobject.put("parkKey", parkKey);
  283. jsonobject.put("rand", rand);
  284. jsonobject.put("reserveEndTime", reserveEndTime);
  285. jsonobject.put("reserveTime", reserveTime);
  286. jsonobject.put("version", "v1.0");
  287. //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
  288. String md5Str = "appid=" + appId + "&carNo=" + carNo + "&parkKey=" + parkKey + "&rand=" + rand + "&reserveEndTime=" + reserveEndTime + "&reserveTime=" + reserveTime + "&version=" + version + "&" + appSecret;
  289. String sign = CommonUtil.MD5(md5Str);
  290. //sign签名
  291. jsonobject.put("sign", sign);
  292. //返回的结果中 code为1表示成功
  293. String result = RequestUtils.httpPost(url, jsonobject.toJSONString());
  294. logger.info(result);
  295. if (!result.contains("预约成功")) {
  296. throw new Exception("审核失败");
  297. }
  298. ObjectMapper objectMapper = new ObjectMapper();
  299. BsReservationVo reservation = objectMapper.readValue(result, BsReservationVo.class);
  300. visitor.setBsOrderNo(reservation.getData().getReOrderNo());
  301. } else {
  302. //查找用户是否存在
  303. SmartUser user = smartUserService.getSmartById(visitor.getUserId());
  304. if (user == null) {
  305. throw new Exception("访客用户ID在系统中不存在,无法将访客信息下发到门禁设备!");
  306. }
  307. List<SmartDevice> devices = smartDeviceService.queryOnLineDevice();
  308. String visitorNo = getUUIDBits(16);
  309. //region 将访客数据下发到设备
  310. for (SmartDevice device : devices) {
  311. CommonResult<String> insertVisitor = bsInsertVisitor(user, TimeExchange.DateToString(visitor.getVisitorTime()), TimeExchange.DateToString(visitor.getVisitorDeadline()), device.getNum(), visitorNo);
  312. if (!insertVisitor.isSuccess()) {
  313. throw new Exception(insertVisitor.getMessage());
  314. }
  315. visitor.setVisitorsync(visitor.getVisitorsync() == null ? insertVisitor.getData() : (visitor.getVisitorsync() + "," + insertVisitor.getData()));
  316. visitor.setDeviceNum(visitor.getDeviceNum() == null ? device.getNum() : (visitor.getDeviceNum() + "," + device.getNum()));
  317. }
  318. //endregion
  319. String code = GetVertifyCode.getRandomNumCode(6);
  320. visitor.setVisitorCode(code);
  321. }
  322. }
  323. } else if (type == eExamineStatu.Refused.getValue()) {
  324. visitor.setStatu(eApproveStatu.Refused.getValue());
  325. }
  326. int result = smartVisitorService.updateSmartVisitor(visitor);
  327. if (result <= 0) {
  328. throw new Exception("审核失败");
  329. }
  330. //发送短信给其他访客用户
  331. if (!ObjectUtils.isEmpty(visitor.getVisitorCode()) && type == eExamineStatu.Agree.getValue()) {
  332. 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());
  333. if (!message.contains("success")) {
  334. throw new Exception("审核失败");
  335. }
  336. }
  337. } catch (Exception e) {
  338. throw new Exception("审核失败");
  339. }
  340. return CommonResult.ok("审核成功");
  341. }
  342. @Override
  343. public CommonResult testVisitorDevice(int id, String deviceNo) throws Exception {
  344. SmartUser user = smartUserService.getSmartById(id);
  345. if (user == null) {
  346. return CommonResult.fail("访客用户ID在系统中不存在,无法将访客信息下发到门禁设备!");
  347. }
  348. List<SmartDevice> devices = smartDeviceService.queryOnLineDevice();
  349. String visitorNo = getUUIDBits(16);
  350. //region 将访客数据下发到设备
  351. for (SmartDevice device : devices) {
  352. CommonResult<String> insertVisitor = bsInsertVisitor(user, "2024-03-28 10:00:00", "2024-03-28 11:00:00", device.getNum(), visitorNo);
  353. if (!insertVisitor.isSuccess()) {
  354. return CommonResult.fail(insertVisitor.getMessage());
  355. }
  356. }
  357. return CommonResult.ok("操作成功");
  358. }
  359. /**
  360. * 1、学生请假:
  361. * 我们这边调用请假接口之后,把请假数据写到了百胜系统的"学生请假登记"页面中,那到时候学生是通过任意设备都能进出吗?
  362. * 即:万载三中有 A、B、C、D四台门禁设备,学生张三 2024-03-01 10:00:00 到 2024-03-01 12:00:00 请假,张三 2024-03-01 10:10:00的时候能否通过A、B、C、D四台门禁设备?
  363. * <p>
  364. * 注:如果要修改请假数据则要先修改系统中的学生编码,再去新增一条请假数据
  365. * 即:修改了这个学生编码之后再下发请假数据的话,原有的该学号的请假数据就会在设备中被清除
  366. * <p>
  367. * 2、访客设备:
  368. * 我们这边调用门禁访客设备接口,是把数据下发到系统还是到门禁设备?
  369. * 如果是写到门禁的话,后续添加访客数据是否会清除之前的所有已写入的访客数据?
  370. * <p>
  371. * <p>
  372. * 答:
  373. * 1、请假数据会自动会同步到设备
  374. * 2、访客数据是下发到门禁设备的,访客数据有效期到了之后会自动被清除掉;如果删除系统中的用户数据会自动把门禁中的用户数据也删掉,如果是已有的则进行更新操作;
  375. *
  376. * @param su
  377. * @param startTime
  378. * @param endTime
  379. * @param deviceNo
  380. * @param visitorNo
  381. * @return
  382. * @throws Exception
  383. */
  384. //region 百胜添加访客数据到设备
  385. public CommonResult<String> bsInsertVisitor(SmartUser su, String startTime, String endTime, String deviceNo, String visitorNo) throws Exception {
  386. //region 百胜添加教师数据
  387. String appId = controlConfig.getAppId();
  388. String schoolno = controlConfig.getSchoolCode();
  389. String timestamp = TimeExchange.DateNowTimeStamo();
  390. String appSecret = controlConfig.getAppSecret();
  391. String url = controlConfig.getUrl() + "visitor/sync";
  392. JSONObject jsonobject = new JSONObject();
  393. jsonobject.put("appid", appId);
  394. String str = "{\"device_no\":\"" + deviceNo + "\",\"visitor_begindate\":\"" + startTime + "\",\"visitor_enddate\":\"" + endTime + "\",\"visitor_idcard\":\"" + su.getIdCard() + "\",\"visitor_name\":\"" + su.getName() + "\",\"visitor_no\":\"" + visitorNo + "\",\"visitor_phone\":\"" + su.getPhone() + "\",\"visitor_photo\":\"" + su.getHeadImage() + "\",\"visitor_sex\":\"" + su.getSexId() + "\"}";
  395. String aesStr = URLEncoder.encode(AesTestOne.encrypt(str, controlConfig.getAppSecret()), "UTF-8");
  396. jsonobject.put("data", aesStr);
  397. jsonobject.put("schoolno", schoolno);
  398. jsonobject.put("timestamp", timestamp);
  399. String md5Str = "appid=" + appId + "&data={\"device_no\":\"" + deviceNo + "\",\"visitor_begindate\":\"" + startTime + "\",\"visitor_enddate\":\"" + endTime + "\",\"visitor_idcard\":\"" + su.getIdCard() + "\",\"visitor_name\":\"" + su.getName() + "\",\"visitor_no\":\"" + visitorNo + "\",\"visitor_phone\":\"" + su.getPhone() + "\",\"visitor_photo\":\"" + su.getHeadImage() + "\",\"visitor_sex\":\"" + su.getSexId() + "\"}" + "&schoolno=" + schoolno + "&timestamp=" + timestamp + "&key=" + appSecret;
  400. String sign = CommonUtil.MD5(md5Str);
  401. //sign签名
  402. jsonobject.put("sign", sign);
  403. //返回的结果中 code为1表示成功
  404. String bsResult = RequestUtils.httpPost(url, jsonobject.toJSONString());
  405. ObjectMapper objectMapper = new ObjectMapper();
  406. BsDeviceVo device = objectMapper.readValue(bsResult, BsDeviceVo.class);
  407. if (!bsResult.contains("添加成功")) {
  408. return CommonResult.fail(device.getMsg());
  409. }
  410. // URL解码
  411. String decodedUrl = URLDecoder.decode(device.getData(), "UTF-8");
  412. BsDeviceNoVo deviceNoData = objectMapper.readValue(decrypt(decodedUrl, controlConfig.getAppSecret()), BsDeviceNoVo.class);
  413. su.setBsStaffCode(deviceNoData.getVisitorsync_no());
  414. return CommonResult.ok("200", "新增成功", deviceNoData.getVisitorsync_no());
  415. //endregion
  416. }
  417. //endregion
  418. /**
  419. * 将预约信息推送到希沃电子班牌
  420. *
  421. * @param parentPhone 预约手机号(家长手机号 在希沃中学生会和家长手机号绑定 可以绑定多个家长)
  422. * @param studentCode 学生编号 希沃中的学生编号和万载系统中的一致
  423. * @param content 消息内容
  424. * @return
  425. */
  426. public CommonResult pushInfo(String parentPhone, String studentCode, String content) {
  427. //初始化客户端
  428. SeewoClient seewoClient = new DefaultSeewoClient(new Account(seewoConfig.getAppId(), seewoConfig.getAppSecret()));
  429. HomeSchoolServiceSendNoteToKidParam param = new HomeSchoolServiceSendNoteToKidParam();
  430. //响应体,MimeType为 application/json
  431. HomeSchoolServiceSendNoteToKidParam.RequestBody requestBody = HomeSchoolServiceSendNoteToKidParam.RequestBody.builder()
  432. .build();
  433. param.setRequestBody(requestBody);
  434. //query
  435. HomeSchoolServiceSendNoteToKidParam.Query query = HomeSchoolServiceSendNoteToKidParam.Query.builder()
  436. .appId(seewoConfig.getAppId())
  437. .schoolUid(seewoConfig.getSchoolId())
  438. .senderPhone(parentPhone)
  439. .studentCode(studentCode)
  440. .type(1)
  441. .content(content)
  442. .autoRegister(0)
  443. .build();
  444. requestBody.setQuery(query);
  445. param.setRequestBody(requestBody);
  446. HomeSchoolServiceSendNoteToKidRequest request = new HomeSchoolServiceSendNoteToKidRequest(param);
  447. logger.info("入参:" + request);
  448. //如果想要调用沙箱环境,请通过设置 request 对象的 serverUrl 属性,如:
  449. //request.setServerUrl("https://openapi.test.seewo.com")
  450. //执行请求,如果想获取到com.seewo.open.sdk.HttpResponse对象,请调用 seewoClient.execute 方法
  451. HomeSchoolServiceSendNoteToKidResult result = seewoClient.invoke(request);
  452. logger.info("出参:" + result);
  453. if (!result.getMessage().equals("success")) {
  454. CommonResult.fail();
  455. }
  456. return CommonResult.ok();
  457. }
  458. /**
  459. * 获取到访代办数据
  460. *
  461. * @param userId
  462. * @return
  463. */
  464. @Override
  465. @DESRespondSecret(validated = false)
  466. public CommonResult visitingAgencys(int currentPage, int pageCount, int userId, int type) {
  467. SmartUser user = smartUserService.getSmartById(userId);
  468. if (user == null) {
  469. return CommonResult.fail("当前用户数据无效,获取到访数据失败");
  470. }
  471. if (user.getIdentityId().intValue() != eIdentityStatu.Teacher.getValue()) {
  472. return CommonResult.fail("非教师身份无法获取到访数据");
  473. }
  474. //是否是管理员
  475. String whereSql = null;
  476. //获取的权限组数据
  477. List<SmartAuthorGroup> authorGroups = smartAuthorGroupService.smartAuthorGroup(user.getId());
  478. for (SmartAuthorGroup authorGroup : authorGroups) {
  479. List<String> applyIds = Arrays.asList(authorGroup.getApplyId().split(","));
  480. //菜单表中7是访客预约
  481. long appointCount = applyIds.stream().filter(e -> e.equals("7")).count();
  482. if (appointCount > 0) {
  483. whereSql = "visitor_type = 2";
  484. break;
  485. }
  486. }
  487. List<Integer> studentIds = null;
  488. //班主任
  489. if (user.getDuties().intValue() == eDuties.ClassTeacher.getValue()) {
  490. //班级ID
  491. Integer schoolClass = user.getSchoolClass();
  492. //获取该班级下的所有学生ID数据
  493. List<SmartUser> students = smartUserService.queryStudentBySchoolClass(user.getSchoolClass());
  494. if (students == null) {
  495. return CommonResult.fail("当前身份下不存在学生信息");
  496. }
  497. studentIds = students.stream().map(SmartUser::getId).collect(Collectors.toList());
  498. }
  499. PageUtils<SmartVisitor> result = new PageUtils<SmartVisitor>(null, 0, pageCount, currentPage);
  500. if (whereSql == null && studentIds == null) {
  501. return CommonResult.ok(result);
  502. }
  503. result = smartVisitorService.queryVisitorPageDatas(currentPage, pageCount, type, studentIds, studentIds != null && whereSql != null ? "or " + whereSql : whereSql);
  504. return CommonResult.ok(result);
  505. }
  506. /**
  507. * 扫码 分为 身份码 和 访客码
  508. * 1、身份码:
  509. * 1.1、如果是老师 任意通行
  510. * 1.2、如果是家长 找有没有访客数据
  511. * 1.3、如果是学生 不让通行
  512. * <p>
  513. * 2、访客码
  514. * 2.1、找下是否存在访客预约记录
  515. * <p>
  516. * 扫码记录增加是否已进 和 是否已出字段
  517. *
  518. * @param data
  519. * @return
  520. * @throws JsonProcessingException
  521. */
  522. @Override
  523. public TurnOnDeviceVo turnOnTheDevice(turnOnTheDeviceRequest data) throws JsonProcessingException {
  524. logger.info("进入扫码解析,参数:" + JSON.toJSON(data));
  525. TurnOnDeviceVo result = new TurnOnDeviceVo();
  526. logger.info("进入扫码解析1");
  527. //region 参数判断
  528. if (data == null) {
  529. result.setResultcode(2);
  530. result.setMessage("扫码参数不能为空");
  531. result.setActionName("qrCodePush");
  532. return result;
  533. }
  534. logger.info("进入扫码解析2");
  535. if (data.getActionName() == null) {
  536. result.setResultcode(2);
  537. result.setMessage("指令不能为空");
  538. result.setActionName("qrCodePush");
  539. return result;
  540. }
  541. logger.info("进入扫码解析3");
  542. if (!data.getActionName().equals("qrCodePush")) {
  543. result.setResultcode(2);
  544. result.setMessage("指令错误");
  545. result.setActionName("qrCodePush");
  546. return result;
  547. }
  548. logger.info("进入扫码解析4");
  549. if (data.getData() == null) {
  550. result.setResultcode(2);
  551. result.setMessage("二维码内容不能为空");
  552. result.setActionName("qrCodePush");
  553. return result;
  554. }
  555. logger.info("进入扫码解析5");
  556. ObjectMapper objectMapper = new ObjectMapper();
  557. qrCodeVo codeVo = objectMapper.readValue(data.getData(), qrCodeVo.class);
  558. if (codeVo == null) {
  559. result.setResultcode(2);
  560. result.setMessage("二维码内容不能为空");
  561. result.setActionName("qrCodePush");
  562. return result;
  563. }
  564. logger.info("进入扫码解析6");
  565. if (codeVo.getQrCode() == null) {
  566. result.setResultcode(2);
  567. result.setMessage("二维码内容不能为空");
  568. result.setActionName("qrCodePush");
  569. return result;
  570. }
  571. logger.info("进入扫码解析7");
  572. if (data.getDeviceno() == null) {
  573. result.setResultcode(2);
  574. result.setMessage("设备编号不能为空");
  575. result.setActionName("qrCodePush");
  576. return result;
  577. }
  578. logger.info("进入扫码解析8");
  579. if (data.getVersion() == null) {
  580. result.setResultcode(2);
  581. result.setMessage("版本不能为空");
  582. result.setActionName("qrCodePush");
  583. return result;
  584. }
  585. //endregion
  586. logger.info("进入扫码解析9");
  587. //解码逻辑
  588. QrcodeImageVo qiv = objectMapper.readValue(codeVo.getQrCode(), QrcodeImageVo.class);
  589. logger.info("进入扫码解析10");
  590. SmartDevice deviceData = smartDeviceService.queryDeviceByNum(data.getDeviceno());
  591. if (deviceData == null) {
  592. logger.info("进入扫码解析11");
  593. result.setResultcode(2);
  594. result.setMessage("设备不存在");
  595. result.setActionName("qrCodePush");
  596. return result;
  597. }
  598. if (qiv.getType().intValue() == eQrcodeType.Identity.getValue()) {//身份码
  599. //身份码中的ID是身份码ID
  600. logger.info("进入身份码扫码解析1");
  601. //目前二维码一分钟内有效
  602. //过期:(时间戳 + 有效期分钟数)<= 当前时间
  603. //时间戳转时间
  604. Date dateNow = TimeExchange.StringToDate(TimeExchange.TimeRangeMinute(qiv.getTimestamp(), 1), "yyyy-MM-dd HH:mm:ss");
  605. logger.info("dateNow参数:" + TimeExchange.DateToString(dateNow));
  606. logger.info("当前时间参数:" + TimeExchange.DateToString(new Date()));
  607. if (new Date().after(dateNow)) {
  608. logger.info("身份码过期");
  609. result.setResultcode(2);
  610. result.setMessage("身份码已过期");
  611. result.setActionName("qrCodePush");
  612. return result;
  613. }
  614. logger.info("进入身份码扫码解析2");
  615. SmartUser user = smartUserService.getSmartById(qiv.getId());
  616. if (user == null) {
  617. result.setResultcode(2);
  618. result.setMessage("用户身份无效,刷码失败");
  619. result.setActionName("qrCodePush");
  620. return result;
  621. }
  622. //成功后将刷码记录存储到数据表中
  623. SmartQrcode sq = new SmartQrcode();
  624. /**
  625. * 1、身份码逻辑
  626. * 1.1、如果是老师 任意通行
  627. * 1.2、如果是家长 找有没有访客数据
  628. * 1.3、如果是学生 不让通行
  629. */
  630. switch (user.getIdentityId().intValue()) {
  631. case 1://家长
  632. //查找是否存在访客记录
  633. SmartVisitor visitor = smartVisitorService.queryParentVisitor(user.getId());
  634. if(visitor == null){
  635. logger.info("无访客数据,家长无法通行");
  636. result.setResultcode(2);
  637. result.setMessage("无访客数据,家长无法通行");
  638. result.setActionName("qrCodePush");
  639. return result;
  640. }
  641. sq.setUserId(qiv.getId());
  642. sq.setQrcodeType(qiv.getType());
  643. sq.setSourceCode(data.getData());
  644. sq.setDataId(visitor.getId());
  645. sq.setIsSuccess(1);
  646. sq.setAccessState(deviceData.getEntrance());
  647. break;
  648. case 2://学生
  649. logger.info("学生无法使用身份码通行");
  650. result.setResultcode(2);
  651. result.setMessage("学生无法使用身份码通行");
  652. result.setActionName("qrCodePush");
  653. return result;
  654. case 3://老师
  655. sq.setUserId(qiv.getId());
  656. sq.setQrcodeType(qiv.getType());
  657. sq.setSourceCode(data.getData());
  658. sq.setDataId(0);
  659. sq.setIsSuccess(1);
  660. sq.setAccessState(deviceData.getEntrance());
  661. break;
  662. default:
  663. break;
  664. }
  665. logger.info("进入身份码扫码解析3");
  666. int insertResult = smartQrcodeService.insertSmartQrcode(sq);
  667. if (insertResult <= 0) {
  668. result.setResultcode(2);
  669. result.setMessage("新增刷码记录失败");
  670. result.setActionName("qrCodePush");
  671. return result;
  672. }
  673. logger.info("进入身份码扫码解析4");
  674. result.setResultcode(1);
  675. result.setMessage("成功");
  676. result.setActionName("qrCodePush");
  677. logger.info("进入身份码扫码解析,结果:" + JSON.toJSON(result));
  678. } else if (qiv.getType().intValue() == eQrcodeType.Visitor.getValue()) {//访客码
  679. //访客码中的ID是访客数据的ID
  680. //查找是否存在访客记录
  681. SmartVisitor visitor = smartVisitorService.getSmartById(qiv.getId());
  682. if(visitor == null){
  683. logger.info("无访客数据,访客无法通行");
  684. result.setResultcode(2);
  685. result.setMessage("无访客数据,访客无法通行");
  686. result.setActionName("qrCodePush");
  687. return result;
  688. }
  689. //成功后将刷码记录存储到数据表中
  690. SmartQrcode sq = new SmartQrcode();
  691. sq.setUserId(visitor.getUserId());
  692. sq.setQrcodeType(qiv.getType());
  693. sq.setSourceCode(data.getData());
  694. sq.setDataId(visitor.getId());
  695. sq.setIsSuccess(1);
  696. sq.setAccessState(deviceData.getEntrance());
  697. logger.info("进入访客码扫码解析3");
  698. int insertResult = smartQrcodeService.insertSmartQrcode(sq);
  699. if (insertResult <= 0) {
  700. result.setResultcode(2);
  701. result.setMessage("新增刷码记录失败");
  702. result.setActionName("qrCodePush");
  703. return result;
  704. }
  705. logger.info("进入访客码扫码解析4");
  706. result.setResultcode(1);
  707. result.setMessage("成功");
  708. result.setActionName("qrCodePush");
  709. logger.info("进入访客码扫码解析,结果:" + JSON.toJSON(result));
  710. }
  711. return result;
  712. }
  713. }