|
@@ -2,15 +2,23 @@ package com.usoftchina.smartschool.device.listener;
|
|
|
|
|
|
|
|
import com.usoftchina.smartschool.base.Result;
|
|
import com.usoftchina.smartschool.base.Result;
|
|
|
import com.usoftchina.smartschool.device.api.DeviceApi;
|
|
import com.usoftchina.smartschool.device.api.DeviceApi;
|
|
|
|
|
+import com.usoftchina.smartschool.device.dto.AccessControlInfo;
|
|
|
import com.usoftchina.smartschool.device.dto.DeviceInfo;
|
|
import com.usoftchina.smartschool.device.dto.DeviceInfo;
|
|
|
import com.usoftchina.smartschool.device.event.AccessControlEvent;
|
|
import com.usoftchina.smartschool.device.event.AccessControlEvent;
|
|
|
import com.usoftchina.smartschool.device.mapper.DeviceMapper;
|
|
import com.usoftchina.smartschool.device.mapper.DeviceMapper;
|
|
|
import com.usoftchina.smartschool.device.po.Device;
|
|
import com.usoftchina.smartschool.device.po.Device;
|
|
|
import com.usoftchina.smartschool.device.po.ImageFile;
|
|
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.DeviceService;
|
|
import com.usoftchina.smartschool.device.service.DeviceService;
|
|
|
import com.usoftchina.smartschool.file.api.FileApi;
|
|
import com.usoftchina.smartschool.file.api.FileApi;
|
|
|
import com.usoftchina.smartschool.file.dto.FileInfoDTO;
|
|
import com.usoftchina.smartschool.file.dto.FileInfoDTO;
|
|
|
|
|
+import com.usoftchina.smartschool.school.dto.StudentDTO;
|
|
|
|
|
+import com.usoftchina.smartschool.utils.DateUtils;
|
|
|
import com.usoftchina.smartschool.utils.StringUtils;
|
|
import com.usoftchina.smartschool.utils.StringUtils;
|
|
|
|
|
+import com.usoftchina.smartschool.wechat.api.WechatApi;
|
|
|
|
|
+import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
|
|
|
|
|
+import org.apache.catalina.realm.LockOutRealm;
|
|
|
import org.aspectj.util.FileUtil;
|
|
import org.aspectj.util.FileUtil;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -22,7 +30,9 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,15 +42,20 @@ import java.util.List;
|
|
|
@Component
|
|
@Component
|
|
|
public class AccessControlListener implements InitializingBean{
|
|
public class AccessControlListener implements InitializingBean{
|
|
|
|
|
|
|
|
- /*@Autowired
|
|
|
|
|
- private FileApi fileApi;*/
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private FileApi fileApi;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeviceApi deviceApi;
|
|
private DeviceApi deviceApi;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WechatApi wechatApi;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeviceMapper deviceMapper;
|
|
private DeviceMapper deviceMapper;
|
|
|
|
|
|
|
|
|
|
+ final static String TEMPLATEID = "JcWRReMGC1odqcaAgXDfETv9sWwVbWLXc9KLEn_Nve0";
|
|
|
|
|
+
|
|
|
private Logger logger = LoggerFactory.getLogger(AccessControlListener.class);
|
|
private Logger logger = LoggerFactory.getLogger(AccessControlListener.class);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,26 +66,65 @@ public class AccessControlListener implements InitializingBean{
|
|
|
@Async
|
|
@Async
|
|
|
@EventListener(AccessControlEvent.class)
|
|
@EventListener(AccessControlEvent.class)
|
|
|
public void onAccessControlEvent(AccessControlEvent event) {
|
|
public void onAccessControlEvent(AccessControlEvent event) {
|
|
|
|
|
+ Long fileId = null;
|
|
|
|
|
+ String cardNo = event.getAccessControlInfo().getCardNo();
|
|
|
|
|
+ if (StringUtils.isEmpty(cardNo)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询人员信息
|
|
|
|
|
+ */
|
|
|
|
|
+ List<Information> information = deviceMapper.selectInfoByCardNo(cardNo);
|
|
|
|
|
+ if (null == information || information.size() == 0) {
|
|
|
|
|
+ logger.error("学生信息不存在");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 1、保存图片文件;
|
|
* 1、保存图片文件;
|
|
|
*/
|
|
*/
|
|
|
byte[] imageData = event.getAccessControlInfo().getImageData();
|
|
byte[] imageData = event.getAccessControlInfo().getImageData();
|
|
|
- MultipartFile file = new ImageFile(imageData, "测试");
|
|
|
|
|
- Result<FileInfoDTO> fileInfo = null;
|
|
|
|
|
- try {
|
|
|
|
|
- // fileInfo = fileApi.upload(0l, file);
|
|
|
|
|
- }catch (Exception ex) {
|
|
|
|
|
|
|
+ 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、保存门禁出入记录;
|
|
* 2、保存门禁出入记录;
|
|
|
*/
|
|
*/
|
|
|
- Long fileId = fileInfo.getData().getId();
|
|
|
|
|
-
|
|
|
|
|
- logger.info(event.getAccessControlInfo().getCardNo());
|
|
|
|
|
|
|
+ int type = event.getAccessControlInfo().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、推送消息到消息服务器(微信服务监听此消息发送微信消息)
|
|
* 3、推送消息到消息服务器(微信服务监听此消息发送微信消息)
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
|
|
+ MessageInfoDTO msg = new MessageInfoDTO();
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|