|
@@ -2,7 +2,11 @@ package com.huimv.receive.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import cn.hutool.http.Header;
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONException;
|
|
import com.alibaba.fastjson.JSONException;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -28,7 +32,13 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
+import java.net.MalformedURLException;
|
|
|
|
+import java.net.ProtocolException;
|
|
|
|
+import java.net.URL;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -71,6 +81,10 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
|
|
private BillGateMapper gateMapper;
|
|
private BillGateMapper gateMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private BillAccessDoorMapper doorMapper;
|
|
private BillAccessDoorMapper doorMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private DeviceListMapper deviceListMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PeopleListMapper peopleListMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -318,7 +332,7 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public Result handleAdmission(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
|
|
|
|
|
|
+ public Result handleAdmission(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) throws IOException {
|
|
String type = paramsMap.get("type");
|
|
String type = paramsMap.get("type");
|
|
String id = paramsMap.get("id");
|
|
String id = paramsMap.get("id");
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
@@ -405,6 +419,134 @@ public class BillPersonnelAdmissionServiceImpl extends ServiceImpl<BillPersonnel
|
|
// baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() +","+baseLocation.getId());
|
|
// baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() +","+baseLocation.getId());
|
|
//TODO 紧急入场通过先不处理
|
|
//TODO 紧急入场通过先不处理
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //通过生成门禁白名单
|
|
|
|
+ QueryWrapper<DeviceList> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_id", billPersonnelAdmission.getFarmId()).eq("location_id", locationId);
|
|
|
|
+ DeviceList deviceList = deviceListMapper.selectOne(queryWrapper);
|
|
|
|
+ if (ObjectUtil.isNotEmpty(deviceList)) {
|
|
|
|
+ if (deviceList.getDeviceType() == 0) {
|
|
|
|
+ //通过生成门禁白名单
|
|
|
|
+ PeopleList peopleList = new PeopleList();
|
|
|
|
+ peopleList.setFarmId(billPersonnelAdmission.getFarmId().toString());
|
|
|
|
+ peopleList.setDeviceCode(deviceList.getDeviceCode());
|
|
|
|
+ peopleList.setUserId(billPersonnelAdmission.getAdmissionUserId());
|
|
|
|
+ peopleList.setUserName(billPersonnelAdmission.getAdmissionUserName());
|
|
|
|
+ peopleList.setPassword("123456");
|
|
|
|
+ peopleList.setType(0);
|
|
|
|
+ peopleList.setCreateTime(new Date());
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
+ calendar.add(Calendar.HOUR_OF_DAY, 2);
|
|
|
|
+ Date date1 = calendar.getTime();
|
|
|
|
+ peopleList.setOutTime(date1);
|
|
|
|
+ peopleListMapper.insert(peopleList);
|
|
|
|
+
|
|
|
|
+ HashMap<String, Object> jsonObject = new HashMap<>();
|
|
|
|
+ jsonObject.put("seq", deviceList.getDeviceCode());
|
|
|
|
+ String savePath = "D:\\works\\pig_projects\\甜妹.jpg";
|
|
|
|
+ URL url = new URL(billPersonnelAdmission.getUserImgUrl());
|
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
|
+ int resCode = connection.getResponseCode();
|
|
|
|
+ if (resCode == HttpURLConnection.HTTP_OK) {
|
|
|
|
+ InputStream inputStream = connection.getInputStream();
|
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
|
+ int length;
|
|
|
|
+ //读取数据并写入到文件中
|
|
|
|
+ try (FileOutputStream outStream = new FileOutputStream(savePath)) {
|
|
|
|
+ while ((length = inputStream.read(buffer)) != -1) {
|
|
|
|
+ outStream.write(buffer, 0, length);
|
|
|
|
+ }
|
|
|
|
+ outStream.flush();
|
|
|
|
+ } finally {
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println("文件下载错误码为" + resCode);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ jsonObject.put("face", FileUtil.file("D:\\works\\pig_projects\\甜妹.jpg"));
|
|
|
|
+ jsonObject.put("name", billPersonnelAdmission.getAdmissionUserName());
|
|
|
|
+ jsonObject.put("password", "123456");
|
|
|
|
+ jsonObject.put("timestamp", date1.getTime());
|
|
|
|
+ jsonObject.put("uid", billPersonnelAdmission.getAdmissionUserId());
|
|
|
|
+ String post = HttpRequest.post("http://192.168.1.42:8040/addDeviceUser")
|
|
|
|
+ .header(Header.CONTENT_TYPE, "multipart/form-data")
|
|
|
|
+ .form(jsonObject)
|
|
|
|
+ .timeout(30 * 1000).execute().body();
|
|
|
|
+ System.out.println(post);
|
|
|
|
+ } else {
|
|
|
|
+ //车辆闸机
|
|
|
|
+ PeopleList peopleList = new PeopleList();
|
|
|
|
+ peopleList.setFarmId(billPersonnelAdmission.getFarmId().toString());
|
|
|
|
+ peopleList.setDeviceCode(deviceList.getDeviceCode());
|
|
|
|
+ peopleList.setUserId(billPersonnelAdmission.getAdmissionUserId());
|
|
|
|
+ peopleList.setUserName(billPersonnelAdmission.getAdmissionUserName());
|
|
|
|
+ peopleList.setPassword("123456");
|
|
|
|
+ peopleList.setType(1);
|
|
|
|
+ peopleList.setCreateTime(new Date());
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
+ calendar.add(Calendar.HOUR_OF_DAY, 2);
|
|
|
|
+ Date date1 = calendar.getTime();
|
|
|
|
+ peopleList.setOutTime(date1);
|
|
|
|
+ peopleListMapper.insert(peopleList);
|
|
|
|
+
|
|
|
|
+ //需要先验证车辆是否存在白名单内,如果车辆已存在于白名单当中,则需要更新白名单,将车牌从白名单中删除后
|
|
|
|
+ //重新进行添加,如果车辆不存在于白名单当中则直接添加入白名单
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("seq", deviceList.getDeviceCode());
|
|
|
|
+ jsonObject.put("isBlack", false);
|
|
|
|
+ String request = HttpRequest.get("http://192.168.1.42:8040/getCarDeviceWoBList")
|
|
|
|
+ .body(jsonObject.toJSONString())
|
|
|
|
+ .header(Header.CONTENT_TYPE, "application/json")
|
|
|
|
+ .timeout(30 * 1000).execute().body();
|
|
|
|
+ JSONObject object = JSON.parseObject(request);
|
|
|
|
+ System.out.println(object);
|
|
|
|
+ JSONArray data = (JSONArray) object.get("data");
|
|
|
|
+ System.out.println(data);
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
+ JSONObject jsonObject1 = (JSONObject) data.get(i);
|
|
|
|
+ if (jsonObject1.get("plate").equals(billPersonnelAdmission.getCarNum())) {
|
|
|
|
+ JSONObject jsonObject2 = new JSONObject();
|
|
|
|
+ jsonObject2.put("isBlack", false);
|
|
|
|
+ jsonObject2.put("seq", deviceList.getDeviceCode());
|
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
|
+ list.add((Integer) jsonObject1.get("cid"));
|
|
|
|
+ jsonObject2.put("cids", list);
|
|
|
|
+
|
|
|
|
+ String body = HttpRequest.post(" http://192.168.1.42:8040/delCarDeviceWoBList").header(Header.CONTENT_TYPE, "application/json")
|
|
|
|
+ .body(jsonObject2.toJSONString())
|
|
|
|
+ .timeout(30 * 1000).execute().body();
|
|
|
|
+ System.out.println(body);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ JSONObject object1 = new JSONObject();
|
|
|
|
+ jsonObject1.put("seq", deviceList.getDeviceCode());
|
|
|
|
+ jsonObject1.put("isBlack", false);
|
|
|
|
+
|
|
|
|
+ object1.put("timestamp", date1.getTime());
|
|
|
|
+ object1.put("name", billPersonnelAdmission.getAdmissionUserName());
|
|
|
|
+ object1.put("plate", billPersonnelAdmission.getCarNum());
|
|
|
|
+
|
|
|
|
+ jsonArray.add(object1);
|
|
|
|
+ jsonObject1.put("plates", jsonArray);
|
|
|
|
+
|
|
|
|
+ String post = HttpRequest.post(" http://192.168.1.42:8040/addCarDeviceWoBList")
|
|
|
|
+ .header(Header.CONTENT_TYPE, "application/json")
|
|
|
|
+ .body(jsonObject1.toJSONString())
|
|
|
|
+ .timeout(30 * 1000).execute().body();
|
|
|
|
+ System.out.println(post);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
baseProcessMapper.updateById(baseProcess);
|
|
baseProcessMapper.updateById(baseProcess);
|
|
billPersonnelAdmissionMapper.updateById(billPersonnelAdmission);
|
|
billPersonnelAdmissionMapper.updateById(billPersonnelAdmission);
|