|
|
@@ -0,0 +1,128 @@
|
|
|
+package com.usoftchina.smartschool.device.service.impl;
|
|
|
+
|
|
|
+import com.usoftchina.smartschool.base.Result;
|
|
|
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
|
|
|
+import com.usoftchina.smartschool.device.mapper.AccessControlRecordMapper;
|
|
|
+import com.usoftchina.smartschool.device.mapper.StudentInfoMapper;
|
|
|
+import com.usoftchina.smartschool.device.po.AccessControlRecord;
|
|
|
+import com.usoftchina.smartschool.device.po.ImageFile;
|
|
|
+import com.usoftchina.smartschool.device.po.StudentInfo;
|
|
|
+import com.usoftchina.smartschool.device.service.AccessControlService;
|
|
|
+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.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yingp
|
|
|
+ * @date 2019/3/12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AccessControlServiceImpl implements AccessControlService{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FileApi fileApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WechatApi wechatApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AccessControlRecordMapper accessControlRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentInfoMapper studentInfoMapper;
|
|
|
+
|
|
|
+ private Logger logger = LoggerFactory.getLogger(AccessControlServiceImpl.class);
|
|
|
+
|
|
|
+ @Value("${wechat.template.accesscontrol}")
|
|
|
+ private String accessControlTemplateId;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAccessControlEvent(AccessControlInfo info) {
|
|
|
+ Long fileId = null;
|
|
|
+ String cardNo = info.getCardNo();
|
|
|
+ if (StringUtils.isEmpty(cardNo)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 查询人员信息
|
|
|
+ */
|
|
|
+ List<StudentInfo> information = studentInfoMapper.selectInfoByCardNo(cardNo);
|
|
|
+ if (null == information || information.size() == 0) {
|
|
|
+ logger.error("学生信息不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 1、保存图片文件;
|
|
|
+ */
|
|
|
+ byte[] imageData = info.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 = info.getEventType();
|
|
|
+ StudentInfo studentInfo = information.get(0);
|
|
|
+ AccessControlRecord record = new AccessControlRecord();
|
|
|
+ record.setClazz_id(studentInfo.getClazz_id());
|
|
|
+ record.setSchool_id(studentInfo.getSchoolId());
|
|
|
+ record.setClazz_name(studentInfo.getStuClass());
|
|
|
+ record.setSchool_id(studentInfo.getSchoolId());
|
|
|
+ record.setGrade_clazz(studentInfo.getStuClassnickname());
|
|
|
+ record.setGrade_name(studentInfo.getStuGrade());
|
|
|
+ record.setRecord_date(new Date());
|
|
|
+ record.setStu_sex(studentInfo.getStuSex());
|
|
|
+ record.setRecord_type(type);
|
|
|
+ record.setStu_id(studentInfo.getStuId());
|
|
|
+ record.setStu_number(studentInfo.getStuNumber());
|
|
|
+ record.setRecord_name(studentInfo.getStuName() + (type == 1 ? "进人" : "出去"));
|
|
|
+ accessControlRecordMapper.insertRecordSelective(record);
|
|
|
+ /**
|
|
|
+ * 3、推送消息到消息服务器(微信服务监听此消息发送微信消息)
|
|
|
+ */
|
|
|
+ MessageInfoDTO msg = new MessageInfoDTO();
|
|
|
+ msg.setAppId(studentInfo.getAppId());
|
|
|
+ msg.setSecret(studentInfo.getSecret());
|
|
|
+ msg.setTouser(studentInfo.getOpenId());
|
|
|
+ msg.setTemplateId(accessControlTemplateId);
|
|
|
+ msg.setTitle("出入校提醒");
|
|
|
+ msg.setKeyword1(studentInfo.getStuName());
|
|
|
+ msg.setKeyword2(DateUtils.format());
|
|
|
+ msg.setRemark("您好! 你的孩子: " + studentInfo.getStuName() + (type == 1 ? " 进人" : " 出去") + "学校");
|
|
|
+ wechatApi.sendMsg(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按学号和时间期间查找
|
|
|
+ *
|
|
|
+ * @param stuNumber
|
|
|
+ * @param beginDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AccessControlRecord> findByStuNumberAndDate(String stuNumber, Date beginDate,
|
|
|
+ Date endDate) {
|
|
|
+ return accessControlRecordMapper.selectByStuNumberAndDate(stuNumber, beginDate, endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|