|
|
@@ -1,153 +0,0 @@
|
|
|
-/*
|
|
|
-package com.usoftchina.smartschool.device.listener;
|
|
|
-
|
|
|
-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.dto.DeviceInfo;
|
|
|
-import com.usoftchina.smartschool.device.event.AccessControlEvent;
|
|
|
-import com.usoftchina.smartschool.device.mapper.DeviceMapper;
|
|
|
-import com.usoftchina.smartschool.device.po.Device;
|
|
|
-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.file.api.FileApi;
|
|
|
-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.wechat.api.WechatApi;
|
|
|
-import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
|
|
|
-import org.apache.catalina.realm.LockOutRealm;
|
|
|
-import org.aspectj.util.FileUtil;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.InitializingBean;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.event.EventListener;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.text.DateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-*/
|
|
|
-/**
|
|
|
- * @author yingp
|
|
|
- * @date 2019/3/8
|
|
|
- *//*
|
|
|
-
|
|
|
-@Component
|
|
|
-public class AccessControlListener implements InitializingBean{
|
|
|
-
|
|
|
- @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(AccessControlListener.class);
|
|
|
-
|
|
|
- */
|
|
|
-/**
|
|
|
- * 门禁事件
|
|
|
- *
|
|
|
- * @param event
|
|
|
- *//*
|
|
|
-
|
|
|
- @Async
|
|
|
- @EventListener(AccessControlEvent.class)
|
|
|
- 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、保存图片文件;
|
|
|
- *//*
|
|
|
-
|
|
|
- byte[] imageData = event.getAccessControlInfo().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.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、推送消息到消息服务器(微信服务监听此消息发送微信消息)
|
|
|
- *//*
|
|
|
-
|
|
|
- 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
|
|
|
- public void afterPropertiesSet() throws Exception {
|
|
|
- List<DeviceInfo> devices = deviceMapper.findAll();
|
|
|
- devices.forEach(device -> {
|
|
|
- if (!StringUtils.isEmpty(device.getUsername())) {
|
|
|
- deviceApi.add(device);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
-*/
|