diff --git a/cloud/dahua/pom.xml b/cloud/dahua/pom.xml
index cb424bf..809ccb4 100644
--- a/cloud/dahua/pom.xml
+++ b/cloud/dahua/pom.xml
@@ -127,13 +127,17 @@
commons-codec
1.10
+
org.apache.poi
poi
- 4.1.0
- compile
+ 3.17
+
+
+ org.apache.poi
+ poi-ooxml
+ 3.17
-
com.belerweb
pinyin4j
diff --git a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java
index cde8d75..ef18e61 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/MyTask.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/MyTask.java
@@ -21,6 +21,7 @@ import com.example.dahua.utils.JsonUtils;
import com.example.dahua.xiananDao.SearchMapper;
import com.example.dahua.xiananDao.SendRecordDao;
import com.example.dahua.xstDao.MessageDao;
+import com.google.gson.Gson;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import lombok.extern.slf4j.Slf4j;
@@ -219,10 +220,7 @@ public class MyTask implements ApplicationRunner {
//设备id
String deviceId = "";
try {
- deviceId = new String(buffer1, "GBK").trim();
- log.info("设备GBK心跳:" + deviceId);
deviceId = new String(buffer1, "UTF-8").trim();
- log.info("设备UTF-8心跳:" + deviceId);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
@@ -436,7 +434,6 @@ public class MyTask implements ApplicationRunner {
if(cardBean ==null){
return -1;
}
-
// 缓存抓拍人脸
String fileName = StringUtils.isEmpty(userId)? card + ".png" : userId + ".png";
String snapPicPath = path + "\\" + fileName;
@@ -451,7 +448,7 @@ public class MyTask implements ApplicationRunner {
//关联设备信息
AttendanceBean attendanceBean = myTaskUtil.userDao.getTypeByClint_id(szSn);
if(attendanceBean !=null){
- if(StringUtils.isEmpty(attendanceBean.getSchool_id())){
+ if(!StringUtils.isEmpty(attendanceBean.getSchool_id())){
int schoolId = Integer.parseInt(attendanceBean.getSchool_id());
//门禁进出类型:1进0出
int eventType = 0;
@@ -481,13 +478,16 @@ public class MyTask implements ApplicationRunner {
//刷卡结果,1表示成功, 0表示失败
int status = msg.bStatus;
+ log.info("考勤状态:{},学校:{},设备ID: {},学生信息:{}",status,schoolId,szSn,new Gson().toJson(userInfoBean));
if(szSn.startsWith("ytj")) {
- //保存考勤记录
- kaoQinRecord(status, eventType, card, szSn, eventTime,lAnalyzerHandle);
- // 艺校考勤
- if(schoolId ==12 && status ==1){
+ log.info("考勤进来了,学校:{},设备ID: {},学生信息:{}",schoolId,szSn,new Gson().toJson(userInfoBean));
+ // 艺校考勤OA
+ if(schoolId == 12 && status ==1){
int intOrOut = eventType ==1? 1 : 2;
sendRecordToSXYX(userInfoBean.getName(),userInfoBean.getUser_id(),intOrOut,eventTime);
+ }else{
+ //保存考勤记录
+ kaoQinRecord(status, eventType, card, szSn, eventTime,lAnalyzerHandle);
}
}
}
@@ -727,7 +727,7 @@ public class MyTask implements ApplicationRunner {
log.info("设备id: {},关联placeId: {},未查询到关联看板设备。",deviceId,placeId);
return;
}
- log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds));
+// log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds));
for (String kanbanId : kanbanIds) {
String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
// log.info("====== 开始推送看板======, kanbanId = {}, cardNum = {},content ={}",kanbanId,cardNum,data);
@@ -745,7 +745,7 @@ public class MyTask implements ApplicationRunner {
log.info("学校下未查询到看板信息,学校id: {}",schoolId);
return;
}
- log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds));
+// log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds));
for (int i = 0; i < clintIds.size(); i++) {
String clintId = clintIds.get(i);
String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
@@ -787,7 +787,7 @@ public class MyTask implements ApplicationRunner {
HttpEntity> param = new HttpEntity<>(map, headers);
ResponseEntity response = restTemplate.postForEntity(api, param, String.class);
String body = response.getBody();
- System.out.println(body);
+ log.info("请求艺校OA,返回信息: " + body);
} catch (Exception e) {
sendRecordToSXYX(name,userId,intOrOut,eventTime);
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java b/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
index c458cb0..fec4349 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/async/MyScheduledTask.java
@@ -59,9 +59,6 @@ public class MyScheduledTask {
@Autowired
MyTask myTasks;
-// @Value("${haikangpic}")
-// private String haikangpic;
-
public static boolean isSendHaikang = false;
public static boolean isSendWeigeng = false;
@@ -75,24 +72,9 @@ public class MyScheduledTask {
private String imgFilPath = "C:\\EhomePicServer";//抓拍图片路径
@Scheduled(fixedRate = 5000)
- private void deleteFace() throws InterruptedException {
+ private void deleteFace(){
//删除抓拍人脸
deleteFaceImg();
-
-// /**
-// * 目前分三个时间段(9:00-10:00) (13:00-14:00)(22:00-5:00)进行补发操作
-// */
-// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
-// int hour = Integer.parseInt(simpleDateFormat.format(new Date()));
-//
-// if (hour >= 9 && hour < 11) {
-// dealData();
-// } else if (hour >= 13 && hour < 14) {
-// dealData();
-// } else if (hour >= 20 || hour < 5) {
-// dealData();
-// }
-
}
/**
@@ -109,96 +91,17 @@ public class MyScheduledTask {
}
}
- @Autowired
- private UserOperateService userOperateService;
- @Autowired
- private SearchMapper searchMapper;
-// /**
-// * 订阅任务 20秒执行一次
-// */
-// @Scheduled(cron = "0 51 18 * * ?")
-// protected synchronized void task(){
-// log.info("开始执行----- 晚上到寝");
-// //男
-// Integer schoolId=27;
-// Integer roomId =12226;
-// Integer type = 7;
-// Integer outof = 1;
-// String clintId="253169192";
-// String timeIds = "2021-01-08,2021-01-11,2021-01-12,2021-01-13,2021-01-14,2021-01-15,2021-01-18,2021-01-19,2021-01-20,2021-01-21,2021-01-22";
-// String[] deviceArr = timeIds.split(",");
-// List deviceList= new ArrayList<>(Arrays.asList(deviceArr));
-// //启用多线程执行
-// CountDownLatch begin = new CountDownLatch(1);
-// CountDownLatch end = new CountDownLatch(deviceList.size());
-// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build();
-// ExecutorService exe = new ThreadPoolExecutor(4,8,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue(),namedThreadFactory);
-// for(String s : deviceList){
-// String intime = s + " 20:26:14";
-// String startTime= s + " 00:00:00";
-// String endTime = s+" 23:59:59";
-// exe.execute(new SendFaceBatchTask100(userDao,sendRecordDao,searchMapper,schoolId,roomId,type,outof,intime,clintId,startTime,endTime,begin,end));
-// }
-// begin.countDown();
-// try {
-// end.await();
-// }catch (Exception e){
-// log.error("失败"+e);
-// }
-// exe.shutdown();
-// log.info("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕");
-// }
-//
-// // @Scheduled(cron = "0 50 15 * * ?")
-// @Scheduled(cron = "0 09 21 * * ?")
-// protected synchronized void task2(){
-// log.info("开始执行----- 晚上到寝");
-// //男
-// Integer schoolId=27;
-// Integer roomId =12226;
-// Integer type = 4;
-// Integer outof = 1;
-// String clintId="253169212";
-// String timeIds = "2021-01-08,2021-01-11,2021-01-12,2021-01-13,2021-01-14,2021-01-15,2021-01-18,2021-01-19,2021-01-20,2021-01-21,2021-01-22";
-// String[] deviceArr = timeIds.split(",");
-// List deviceList= new ArrayList<>(Arrays.asList(deviceArr));
-// //启用多线程执行
-// CountDownLatch begin = new CountDownLatch(1);
-// CountDownLatch end = new CountDownLatch(deviceList.size());
-// ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("thread-sendFace-runner-%d").build();
-// ExecutorService exe = new ThreadPoolExecutor(8,16,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue(),namedThreadFactory);
-// for(String s : deviceList){
-//// String intime = s + " 06:03:39";
-//// String startTime= s + " 00:00:00";
-//// String endTime = s+" 23:59:59";
-// String intime = s + " 17:14:39";
-// String startTime= s + " 00:00:00";
-// String endTime = s+" 23:59:59";
-// exe.execute(new SendFaceBatchTask2(userDao,sendRecordDao,searchMapper,schoolId,roomId,type,outof,intime,clintId,startTime,endTime,begin,end));
-// }
-// begin.countDown();
-// try {
-// end.await();
-// }catch (Exception e){
-// log.error("失败"+e);
-// }
-// exe.shutdown();
-// log.info("统计100服务器总共有"+deviceList.size()+"个设备,处理完毕");
-// }
-
/**
* 定期删除人脸抓拍图片
*/
private void deleteFaceImg() {
-
String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
-// System.out.println("deleteDate:" + deleteDate);
if (!deleteDate.equals(date)) {
deleteDate = date;
File file = new File(imgFilPath);
File[] files = file.listFiles();
Date currentDate = new Date();
- if (null != files)
+ if (null != files) {
for (int i = 0; i < files.length; i++) {
File imgFile = files[i];
String name = imgFile.getName().split("\\.")[0];
@@ -220,47 +123,11 @@ public class MyScheduledTask {
} catch (ParseException e) {
imgFile.delete();
-// e.printStackTrace();
+ e.printStackTrace();
}
-
}
-
- }
-
- }
-
- private synchronized void dealData() {
-
- String ip = new Utils().getHostAddress();
- System.out.println("ip:" + ip);
- if (ip.startsWith("192") || ip.contains("172.16.247.64"))
- return;
-
- /**
- * 微耕
- */
-//System.out.println("isSendWeigeng:"+isSendWeigeng+"isSendHaikang:"+isSendHaikang+"isSendDahua:"+isSendDahua);
- if (!isSendWeigeng) {
- isSendWeigeng = true;
- sendUserInfoTask.addWeiGen();
- }
-
- /**
- * 海康
- */
- if (!isSendHaikang) {
- isSendHaikang = true;
- sendUserInfoTask.addHaikangface();
- }
-
- /**
- * 大华人脸
- */
- if (!isSendDahua) {
- isSendDahua = true;
- sendUserInfoTask.addDahuaFace();
+ }
}
-
}
boolean isSendMQ = false;
@@ -344,7 +211,7 @@ public class MyScheduledTask {
//关联的显示看板设备
List kanbanIds = new ArrayList<>();
if(!StringUtils.isEmpty(placeId)) {
- log.info("关联场景ID: {},考勤设备ID:{}",placeId,qiandaoDevId);
+// log.info("关联场景ID: {},考勤设备ID:{}",placeId,qiandaoDevId);
kanbanIds = userDao.getKanBanIdWithPlaceId(placeId);
}else{
List kBIds = userDao.getClintIds(schoolId);
@@ -362,7 +229,7 @@ public class MyScheduledTask {
String clintId = kanbanIds.get(i);
String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
mqttManager.sendMqQD(clintId, data);
- log.info("发送微耕考勤消息:学校ID: {},设备ID: {},关联看板room: {},",schoolId,clintId,placeId);
+// log.info("发送微耕考勤消息:学校ID: {},设备ID: {},关联看板room: {},",schoolId,clintId,placeId);
}
}
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/yx/ImportStudent.java b/cloud/dahua/src/main/java/com/example/dahua/bean/yx/ImportStudent.java
new file mode 100644
index 0000000..8c590ef
--- /dev/null
+++ b/cloud/dahua/src/main/java/com/example/dahua/bean/yx/ImportStudent.java
@@ -0,0 +1,77 @@
+package com.example.dahua.bean.yx;
+
+public class ImportStudent {
+
+ private Integer id;
+ private String name;
+ private String userId;
+ private String cardNum;
+ private String sceneName;
+ private Integer schoolId;
+ private String photo;
+ private String studentCode;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getCardNum() {
+ return cardNum;
+ }
+
+ public void setCardNum(String cardNum) {
+ this.cardNum = cardNum;
+ }
+
+ public String getSceneName() {
+ return sceneName;
+ }
+
+ public void setSceneName(String sceneName) {
+ this.sceneName = sceneName;
+ }
+
+ public Integer getSchoolId() {
+ return schoolId;
+ }
+
+ public void setSchoolId(Integer schoolId) {
+ this.schoolId = schoolId;
+ }
+
+ public String getPhoto() {
+ return photo;
+ }
+
+ public void setPhoto(String photo) {
+ this.photo = photo;
+ }
+
+ public String getStudentCode() {
+ return studentCode;
+ }
+
+ public void setStudentCode(String studentCode) {
+ this.studentCode = studentCode;
+ }
+}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/bean/yx/YxSendFaceDto.java b/cloud/dahua/src/main/java/com/example/dahua/bean/yx/YxSendFaceDto.java
new file mode 100644
index 0000000..7fdb710
--- /dev/null
+++ b/cloud/dahua/src/main/java/com/example/dahua/bean/yx/YxSendFaceDto.java
@@ -0,0 +1,42 @@
+package com.example.dahua.bean.yx;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * 照片下发人脸实体类
+ * @author xuquan
+ * @date 2020/12/16 09:10
+ */
+public class YxSendFaceDto {
+
+ @ApiModelProperty("学校ID")
+ private Integer schoolId ;
+ @ApiModelProperty("设备号,逗号隔开")
+ private String sNos;
+ @ApiModelProperty("区域名称")
+ private String sceneName;
+
+ public Integer getSchoolId() {
+ return schoolId;
+ }
+
+ public void setSchoolId(Integer schoolId) {
+ this.schoolId = schoolId;
+ }
+
+ public String getsNos() {
+ return sNos;
+ }
+
+ public void setsNos(String sNos) {
+ this.sNos = sNos;
+ }
+
+ public String getSceneName() {
+ return sceneName;
+ }
+
+ public void setSceneName(String sceneName) {
+ this.sceneName = sceneName;
+ }
+}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java b/cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
index f1a5b27..8b7f595 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
@@ -1,24 +1,27 @@
package com.example.dahua.control;
import com.example.dahua.async.SendUserInfoTask2;
-import com.example.dahua.bean.StudentBean;
+import com.example.dahua.bean.yx.Result;
+import com.example.dahua.bean.yx.YxSendFaceDto;
import com.example.dahua.dao.UserDao;
import com.example.dahua.service.UserOperateService;
import com.example.dahua.service.imp.BaseService;
-import com.example.dahua.utils.HttpUtil;
+import com.example.dahua.utils.ExcelUtil;
import com.example.dahua.utils.HttpUtils;
-import io.micrometer.core.instrument.util.StringUtils;
+import com.example.dahua.utils.ReadExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -98,4 +101,27 @@ public class UserOperateController {
@RequestParam(value = "deviceIds",required = false) String deviceIds){
userOperateService.deleteFaceByClassId(schoolId,deviceIds);
}
+
+ @ApiOperation(value = "导入学生信息")
+ @RequestMapping(value = "importStudent", method = RequestMethod.POST)
+ public void importExcel(@RequestParam(value="studentFile") MultipartFile file,HttpServletRequest request){
+ List> readExcel = new ArrayList<>();
+ try {
+ readExcel = new ReadExcelUtil().readExcel(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ String originalFileName = file.getOriginalFilename();
+ int beginIndex = originalFileName.lastIndexOf(".");
+ //原名
+ String fileName = originalFileName.substring(0,beginIndex);
+
+ userOperateService.saveStudentInfo(readExcel, fileName);
+ }
+
+ @ApiOperation(value = "艺校照片特定下发")
+ @RequestMapping(value = "sendYxFace", method = RequestMethod.POST)
+ public Result sendFaceByThread(@RequestBody YxSendFaceDto sendFaceDto) {
+ return userOperateService.sendYxUserFace(sendFaceDto);
+ }
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
index bb98e2c..8a7e3e3 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/dao/UserDao.java
@@ -1,6 +1,7 @@
package com.example.dahua.dao;
import com.example.dahua.bean.*;
+import com.example.dahua.bean.yx.ImportStudent;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@@ -100,6 +101,9 @@ public interface UserDao {
@Select(" select * from SZ_V_School_Student where student_num = #{student_num} and name = #{name}")
UserInfoBean getStudent(@Param("student_num") String student_num, @Param("name") String name);
+ @Select(" select Top(1) * from SZ_V_School_Student where school_id = #{schoolId} and name = #{name}")
+ UserInfoBean getStudentByName(@Param("schoolId") Integer schoolId, @Param("name") String name);
+
@Select(" select * from SZ_V_School_Student where school_id = #{school_id} and sex = #{sex} and student_type = #{student_type}")
List getStudentWithSchoolId(@Param("school_id") String school_id, @Param("sex") String sex, @Param("student_type") String student_type);
@@ -281,4 +285,10 @@ public interface UserDao {
List getStudentByClassId(@Param("schoolId") int schoolId,@Param("classIds") List classIds);
List getGroupByClassId(@Param("classId") Integer classId);
+
+ void insertStudent(ImportStudent studentBak);
+
+ List selectYxStudentList(@Param("sceneName") String sceneName,@Param("schoolId") Integer schoolId);
+
+ List selectStudentList();
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java b/cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java
index 536cdf0..e610e7b 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java
@@ -1,6 +1,12 @@
package com.example.dahua.service;
+import com.example.dahua.bean.yx.Result;
+import com.example.dahua.bean.yx.YxSendFaceDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
/**
* 下发用户信息、人脸、卡、权限接口
* @author xuquan
@@ -23,4 +29,13 @@ public interface UserOperateService {
void deleteFaceByClassId(Integer schoolId,String deviceIds);
void test6(Integer schoolId,Integer roomId,Integer type,Integer outof,String intime,String clintId,String startTime,String endTime);
+
+ void saveStudentInfo(List> readExcel, String fileName);
+
+ /**
+ * 多线程照片下发
+ * @param sendFaceDto
+ * @return
+ */
+ Result sendYxUserFace(YxSendFaceDto sendFaceDto);
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/imp/BaseService.java b/cloud/dahua/src/main/java/com/example/dahua/service/imp/BaseService.java
index 5b4b6b8..e6af6ae 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/service/imp/BaseService.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/service/imp/BaseService.java
@@ -3,6 +3,7 @@ package com.example.dahua.service.imp;
import com.example.dahua.bean.SendRecordBean;
import com.example.dahua.bean.StudentBean;
+import com.example.dahua.bean.yx.ImportStudent;
import com.example.dahua.dao.UserDao;
import com.example.dahua.xiananDao.SendRecordDao;
import lombok.extern.slf4j.Slf4j;
@@ -162,4 +163,17 @@ public class BaseService {
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SendRecordBean::getNum))),ArrayList::new));
return studentList;
}
+
+ /**
+ * 获取学校下的老师数据信息
+ * @param schoolId
+ * @return
+ */
+ public List getYxStudentList(Integer schoolId, String sceneName) {
+ List students = userDao.selectYxStudentList(sceneName,schoolId);
+ //去重重复数据
+ List teacherist = students.stream().collect(Collectors.collectingAndThen(
+ Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(ImportStudent::getCardNum))), ArrayList::new));
+ return teacherist;
+ }
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
index 685df08..2922239 100644
--- a/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
+++ b/cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
@@ -4,6 +4,10 @@ import com.example.dahua.MyTask;
import com.example.dahua.bean.SendRecordBean;
import com.example.dahua.bean.StudentBean;
import com.example.dahua.bean.UserInfoBean;
+import com.example.dahua.bean.yx.ImportStudent;
+import com.example.dahua.bean.yx.Result;
+import com.example.dahua.bean.yx.ResultGenerator;
+import com.example.dahua.bean.yx.YxSendFaceDto;
import com.example.dahua.dao.UserDao;
import com.example.dahua.lib.CompressPic;
import com.example.dahua.lib.FilePath;
@@ -16,12 +20,14 @@ import com.example.dahua.utils.HttpUtils;
import com.example.dahua.xiananDao.SearchMapper;
import com.example.dahua.xiananDao.SendRecordDao;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.File;
+import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -59,7 +65,7 @@ public class UserOperateServiceImpl implements UserOperateService {
studentBeanList = baseService.getTeacherList(schoolId);
}
log.info("下发用户总数:"+studentBeanList.size());
- //下發人臉
+ //下发人脸
sendFace(studentBeanList,deviceList,schoolId,userType);
}
@@ -228,4 +234,71 @@ public class UserOperateServiceImpl implements UserOperateService {
}
}
}
+
+ @Override
+ public void saveStudentInfo(List> readExcel, String fileName) {
+ // 读取数据封装实体
+ if(readExcel.size() == 0) {
+ log.error("未解析到数据。");
+ return;
+ }
+ List doList = new ArrayList<>();
+ //将解析的Excel数据集合封装到实体,
+ for(List sList : readExcel) {
+ ImportStudent importStudent = new ImportStudent();
+ int count = 0 ;
+ for (String str : sList){
+ if(0 == count){
+ importStudent.setSceneName(str);
+ }
+ if(3 == count) {
+ UserInfoBean userInfoBean = userDao.getStudentByName(12,str);
+ if(userInfoBean !=null){
+ importStudent.setSchoolId(12);
+ importStudent.setCardNum(userInfoBean.getStudent_num());
+ importStudent.setName(userInfoBean.getName());
+ importStudent.setUserId(userInfoBean.getUser_id());
+ importStudent.setPhoto(userInfoBean.getPhoto());
+ importStudent.setStudentCode(userInfoBean.getStudentcode());
+ }
+ }
+ count ++;
+ }
+ doList.add(importStudent);
+ }
+ if(doList.size() > 0) {
+ for(ImportStudent importStudent : doList) {
+ userDao.insertStudent(importStudent);
+ }
+ }
+ }
+
+ @Override
+ public Result sendYxUserFace(YxSendFaceDto sendFaceDto) {
+ //下发设备集合
+ String[] deviceArr = sendFaceDto.getsNos().split(",");
+ List deviceList= new ArrayList<>(Arrays.asList(deviceArr));
+ if(deviceList.size()<1){
+ return ResultGenerator.genFailResult("未选择下发设备");
+ }
+ Integer schoolId = sendFaceDto.getSchoolId();
+ String sceneName = sendFaceDto.getSceneName();
+ //根据类型获取下发用户信息
+ List studentBeanList = baseService.getYxStudentList(schoolId,sceneName);
+ log.info("统计共有下发用户数量:{}",studentBeanList.size());
+ List dtoList = studentBeanList.stream()
+ .filter(e -> !StringUtils.isEmpty(e.getPhoto()))
+ .map(e -> {
+ StudentBean d = new StudentBean();
+ d.setSchool_id(e.getSchoolId());
+ d.setPhoto(e.getPhoto());
+ d.setName(e.getName());
+ d.setStudentcode(e.getStudentCode());
+ return d;
+ })
+ .collect(Collectors.toList());
+ //下发人脸
+ sendFace(dtoList,deviceList,schoolId,2);
+ return ResultGenerator.genSuccessResult();
+ }
}
diff --git a/cloud/dahua/src/main/java/com/example/dahua/utils/ExcelUtil.java b/cloud/dahua/src/main/java/com/example/dahua/utils/ExcelUtil.java
new file mode 100644
index 0000000..aa9d9c3
--- /dev/null
+++ b/cloud/dahua/src/main/java/com/example/dahua/utils/ExcelUtil.java
@@ -0,0 +1,108 @@
+package com.example.dahua.utils;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * excel工具类
+ */
+@Slf4j
+public class ExcelUtil {
+
+ public static final String OFFICE_EXCEL_2003_POSTFIX = "xls";
+ public static final String OFFICE_EXCEL_2010_POSTFIX = "xlsx";
+ public static final String EMPTY = "";
+ public static final String POINT = ".";
+ public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
+
+ /**
+ * 获得path的后缀名
+ * @param path
+ * @return
+ */
+ public static String getPostfix(String path){
+ if(path==null || EMPTY.equals(path.trim())){
+ return EMPTY;
+ }
+ if(path.contains(POINT)){
+ return path.substring(path.lastIndexOf(POINT)+1,path.length());
+ }
+ return EMPTY;
+ }
+ /**
+ * 单元格格式
+ * @param hssfCell
+ * @return
+ */
+ @SuppressWarnings({ "static-access", "deprecation" })
+ public static String getHValue(HSSFCell hssfCell){
+ if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
+ return String.valueOf(hssfCell.getBooleanCellValue());
+ } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
+ String cellValue = "";
+ if(HSSFDateUtil.isCellDateFormatted(hssfCell)){
+ Date date = HSSFDateUtil.getJavaDate(hssfCell.getNumericCellValue());
+ cellValue = sdf.format(date);
+ }else{
+ DecimalFormat df = new DecimalFormat("#.##");
+ cellValue = df.format(hssfCell.getNumericCellValue());
+ String strArr = cellValue.substring(cellValue.lastIndexOf(POINT)+1,cellValue.length());
+ if(strArr.equals("00")){
+ cellValue = cellValue.substring(0, cellValue.lastIndexOf(POINT));
+ }
+ }
+ return cellValue;
+ } else {
+ return String.valueOf(hssfCell.getStringCellValue());
+ }
+ }
+ /**
+ * 单元格格式
+ * @param xssfCell
+ * @return
+ */
+ public static String getXValue(XSSFCell xssfCell){
+ if (xssfCell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
+ return String.valueOf(xssfCell.getBooleanCellValue());
+ } else if (xssfCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+ String cellValue = "";
+ if(XSSFDateUtil.isCellDateFormatted(xssfCell)){
+ Date date = XSSFDateUtil.getJavaDate(xssfCell.getNumericCellValue());
+ cellValue = sdf.format(date);
+ }else{
+ DecimalFormat df = new DecimalFormat("#.##");
+ cellValue = df.format(xssfCell.getNumericCellValue());
+ String strArr = cellValue.substring(cellValue.lastIndexOf(POINT)+1,cellValue.length());
+ if(strArr.equals("00")){
+ cellValue = cellValue.substring(0, cellValue.lastIndexOf(POINT));
+ }
+ }
+ return cellValue;
+ } else {
+ return String.valueOf(xssfCell.getStringCellValue());
+ }
+ }
+ /**
+ * 自定义xssf日期工具类
+ *
+ */
+ static class XSSFDateUtil extends DateUtil {
+ protected static int absoluteDay(Calendar cal, boolean use1904windowing) {
+ return DateUtil.absoluteDay(cal, use1904windowing);
+ }
+ }
+}
+
diff --git a/cloud/dahua/src/main/java/com/example/dahua/utils/ReadExcelUtil.java b/cloud/dahua/src/main/java/com/example/dahua/utils/ReadExcelUtil.java
new file mode 100644
index 0000000..d49bea0
--- /dev/null
+++ b/cloud/dahua/src/main/java/com/example/dahua/utils/ReadExcelUtil.java
@@ -0,0 +1,161 @@
+package com.example.dahua.utils;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ReadExcelUtil {
+
+ public int totalRows; //sheet中总行数
+
+ public static int totalCells; //每一行总单元格数
+
+ /**
+ * read the Excel .xlsx,.xls
+ * @param file jsp中的上传文件
+ * @return
+ * @throws IOException
+ */
+ public List> readExcel(MultipartFile file) throws IOException {
+ if(file==null||ExcelUtil.EMPTY.equals(file.getOriginalFilename().trim())){
+ return null;
+ }else{
+ String postfix = ExcelUtil.getPostfix(file.getOriginalFilename());
+ if(!ExcelUtil.EMPTY.equals(postfix)){
+ if(ExcelUtil.OFFICE_EXCEL_2003_POSTFIX.equals(postfix)){
+ return readXls(file);
+ }else if(ExcelUtil.OFFICE_EXCEL_2010_POSTFIX.equals(postfix)){
+ return readXlsx(file);
+ }else{
+ return null;
+ }
+ }
+ }
+ return null;
+ }
+ /**
+ * read the Excel 2010 .xlsx
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ @SuppressWarnings("deprecation")
+ public List> readXlsx(MultipartFile file){
+ List> list = new ArrayList>();
+ // IO流读取文件
+ InputStream input = null;
+ XSSFWorkbook wb = null;
+ ArrayList rowList = null;
+ try {
+ input = file.getInputStream();
+ // 创建文档
+ wb = new XSSFWorkbook(input);
+ //读取sheet(页)
+ for(int numSheet=0;numSheet();
+ totalCells = xssfRow.getLastCellNum();
+ //读取列,从第一列开始
+ for(int c=0;c<=totalCells+1;c++){
+ XSSFCell cell = xssfRow.getCell(c);
+ if(cell==null){
+ rowList.add(ExcelUtil.EMPTY);
+ continue;
+ }
+ rowList.add(ExcelUtil.getXValue(cell).trim());
+ }
+ list.add(rowList);
+ }
+ }
+ }
+ return list;
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally{
+ try {
+ input.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+
+ }
+ /**
+ * read the Excel 2003-2007 .xls
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public List> readXls(MultipartFile file){
+ List> list = new ArrayList>();
+ // IO流读取文件
+ InputStream input = null;
+ HSSFWorkbook wb = null;
+ ArrayList rowList = null;
+ try {
+ input = file.getInputStream();
+ // 创建文档
+ wb = new HSSFWorkbook(input);
+ //读取sheet(页)
+ for(int numSheet = 0; numSheet < wb.getNumberOfSheets(); numSheet++){
+ HSSFSheet hssfSheet = wb.getSheetAt(numSheet);
+ String sheetName = hssfSheet.getSheetName();
+ if(hssfSheet == null){
+ continue;
+ }
+ totalRows = hssfSheet.getLastRowNum();
+ //读取Row,从第二行开始
+ for(int rowNum = 1;rowNum <= totalRows;rowNum++){
+ HSSFRow hssfRow = hssfSheet.getRow(rowNum);
+ if(hssfRow!=null){
+ rowList = new ArrayList();
+ totalCells = hssfRow.getLastCellNum();
+ rowList.add(sheetName);
+ //读取列,从第一列开始
+ for(short c=0;c<=totalCells+1;c++){
+ HSSFCell cell = hssfRow.getCell(c);
+ if(cell==null){
+// rowList.add(ExcelUtil.EMPTY);
+ continue;
+ }
+ rowList.add(ExcelUtil.getHValue(cell).trim());
+
+ }
+ list.add(rowList);
+ }
+ }
+ }
+ return list;
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally{
+ try {
+ input.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+}
+
diff --git a/cloud/dahua/src/main/resources/mapper/usermapper.xml b/cloud/dahua/src/main/resources/mapper/usermapper.xml
index ee8ba84..6c6a715 100644
--- a/cloud/dahua/src/main/resources/mapper/usermapper.xml
+++ b/cloud/dahua/src/main/resources/mapper/usermapper.xml
@@ -70,4 +70,26 @@
AND state = 1
+
+
+
+
+
+
+
+
+
+
+
+
+ insert into sz_student_yx values (#{name},#{userId},#{cardNum},#{photo},#{studentCode},#{schoolId},#{sceneName})
+
+
+
+
+
\ No newline at end of file
--
libgit2 0.21.0