|
|
@@ -0,0 +1,112 @@
|
|
|
+package com.usoftchina.smartschool.device.service.impl;
|
|
|
+
|
|
|
+import com.usoftchina.smartschool.base.Result;
|
|
|
+import com.usoftchina.smartschool.device.api.DeviceApi;
|
|
|
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
|
|
|
+import com.usoftchina.smartschool.device.mapper.DeviceMapper;
|
|
|
+import com.usoftchina.smartschool.device.po.ImageFile;
|
|
|
+import com.usoftchina.smartschool.device.po.Information;
|
|
|
+import com.usoftchina.smartschool.device.po.OutInRecord;
|
|
|
+import com.usoftchina.smartschool.device.service.AccessService;
|
|
|
+import com.usoftchina.smartschool.file.api.FileApi;
|
|
|
+import com.usoftchina.smartschool.file.dto.FileInfoDTO;
|
|
|
+import com.usoftchina.smartschool.utils.DateUtils;
|
|
|
+import com.usoftchina.smartschool.utils.StringUtils;
|
|
|
+import com.usoftchina.smartschool.wechat.api.WechatApi;
|
|
|
+import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: guq
|
|
|
+ * @create: 2019-03-12 09:28
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class AccessServiceImpl implements AccessService{
|
|
|
+
|
|
|
+ /* @Autowired
|
|
|
+ private FileApi fileApi;*/
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceApi deviceApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WechatApi wechatApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceMapper deviceMapper;
|
|
|
+
|
|
|
+ final static String TEMPLATEID = "JcWRReMGC1odqcaAgXDfETv9sWwVbWLXc9KLEn_Nve0";
|
|
|
+
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void accessEvent(AccessControlInfo event) {
|
|
|
+ Long fileId = null;
|
|
|
+ String cardNo = event.getCardNo();
|
|
|
+ if (StringUtils.isEmpty(cardNo)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询人员信息
|
|
|
+ */
|
|
|
+ List<Information> information = deviceMapper.selectInfoByCardNo(cardNo);
|
|
|
+ if (null == information || information.size() == 0) {
|
|
|
+ logger.error("学生信息不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 1、保存图片文件;
|
|
|
+ */
|
|
|
+ /* byte[] imageData = event.getImageData();
|
|
|
+ if (null != imageData && imageData.length > 0) {
|
|
|
+ MultipartFile file = new ImageFile(imageData, information.get(0).getStuName());
|
|
|
+ Result<FileInfoDTO> fileInfo = null;
|
|
|
+ try {
|
|
|
+ fileInfo = fileApi.upload(0l, file);
|
|
|
+ fileId = fileInfo.getData().getId();
|
|
|
+ }catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage());
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ /**
|
|
|
+ * 2、保存门禁出入记录;
|
|
|
+ */
|
|
|
+ int type = event.getEventType();
|
|
|
+ Information info = information.get(0);
|
|
|
+ OutInRecord record = new OutInRecord();
|
|
|
+ record.setClazz_id(info.getClazz_id());
|
|
|
+ record.setSchool_id(info.getSchoolId());
|
|
|
+ record.setClazz_name(info.getStuClass());
|
|
|
+ record.setSchool_id(info.getSchoolId());
|
|
|
+ record.setGrade_clazz(info.getStuClassnickname());
|
|
|
+ record.setGrade_name(info.getStuGrade());
|
|
|
+ record.setRecord_date(new Date());
|
|
|
+ record.setStu_sex(info.getStuSex());
|
|
|
+ record.setRecord_type(type);
|
|
|
+ record.setStu_id(info.getStuId());
|
|
|
+ record.setStu_number(info.getStuNumber());
|
|
|
+ record.setRecord_name(info.getStuName() + (type == 1 ? "进人" : "出去"));
|
|
|
+ deviceMapper.insertRecordSelective(record);
|
|
|
+ /**
|
|
|
+ * 3、推送消息到消息服务器(微信服务监听此消息发送微信消息)
|
|
|
+ */
|
|
|
+ MessageInfoDTO msg = new MessageInfoDTO();
|
|
|
+ msg.setUserType(0);
|
|
|
+ msg.setAppId(info.getAppId());
|
|
|
+ msg.setSecret(info.getSecret());
|
|
|
+ msg.setTouser(info.getOpenId());
|
|
|
+ msg.setTemplateId(TEMPLATEID);
|
|
|
+ msg.setTitle("出入校提醒");
|
|
|
+ msg.setKeyword1(info.getStuName());
|
|
|
+ msg.setKeyword2(DateUtils.format());
|
|
|
+ msg.setRemark("您好! 你的孩子: " + info.getStuName() + (type == 1 ? " 进人" : " 出去") + "学校");
|
|
|
+ wechatApi.sendMsg(msg);
|
|
|
+ }
|
|
|
+}
|