parent
3b4b950f4c
commit
3e617d2daa
@ -0,0 +1,44 @@ |
||||
package com.cjy.back.ybsjAppointment.entity; |
||||
|
||||
/** |
||||
* @author liangjiawei |
||||
* @createDate 2023/8/1 |
||||
*/ |
||||
public class AppointmentWriteOffLogEntity { |
||||
private Long id; |
||||
private String time; |
||||
private String idCard; |
||||
private String state; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public void setTime(String time) { |
||||
this.time = time; |
||||
} |
||||
|
||||
public String getIdCard() { |
||||
return idCard; |
||||
} |
||||
|
||||
public void setIdCard(String idCard) { |
||||
this.idCard = idCard; |
||||
} |
||||
|
||||
public String getState() { |
||||
return state; |
||||
} |
||||
|
||||
public void setState(String state) { |
||||
this.state = state; |
||||
} |
||||
} |
||||
@ -0,0 +1,75 @@ |
||||
package com.cjy.back.ybsjAppointment.entity.vo; |
||||
|
||||
/** |
||||
* @author liangjiawei |
||||
* @createDate 2023/8/1 |
||||
*/ |
||||
public class ExtractRecordsDataVO { |
||||
private String sn; |
||||
//是否有小
|
||||
private String effective; |
||||
//进出
|
||||
private String inOut; |
||||
private String idCard; |
||||
private String time; |
||||
//描述
|
||||
private String describe; |
||||
//门号
|
||||
private String doorId; |
||||
|
||||
public String getSn() { |
||||
return sn; |
||||
} |
||||
|
||||
public void setSn(String sn) { |
||||
this.sn = sn; |
||||
} |
||||
|
||||
public String getEffective() { |
||||
return effective; |
||||
} |
||||
|
||||
public void setEffective(String effective) { |
||||
this.effective = effective; |
||||
} |
||||
|
||||
public String getInOut() { |
||||
return inOut; |
||||
} |
||||
|
||||
public void setInOut(String inOut) { |
||||
this.inOut = inOut; |
||||
} |
||||
|
||||
public String getIdCard() { |
||||
return idCard; |
||||
} |
||||
|
||||
public void setIdCard(String idCard) { |
||||
this.idCard = idCard; |
||||
} |
||||
|
||||
public String getTime() { |
||||
return time; |
||||
} |
||||
|
||||
public void setTime(String time) { |
||||
this.time = time; |
||||
} |
||||
|
||||
public String getDescribe() { |
||||
return describe; |
||||
} |
||||
|
||||
public void setDescribe(String describe) { |
||||
this.describe = describe; |
||||
} |
||||
|
||||
public String getDoorId() { |
||||
return doorId; |
||||
} |
||||
|
||||
public void setDoorId(String doorId) { |
||||
this.doorId = doorId; |
||||
} |
||||
} |
||||
@ -0,0 +1,87 @@ |
||||
package com.cjy.back.ybsjAppointment.filter; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.servlet.*; |
||||
import javax.servlet.annotation.WebFilter; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author liangjiawei |
||||
* @createDate 2023/4/24 |
||||
*/ |
||||
|
||||
|
||||
@WebFilter |
||||
@Component |
||||
public class IpRestrictionFilter implements Filter { |
||||
|
||||
|
||||
@Value("${allowed.ip.list}") |
||||
private String allowedIps; |
||||
|
||||
@Value("${allowed.method.methodList}") |
||||
private String methodConfig; |
||||
|
||||
|
||||
@Override |
||||
public void init(FilterConfig filterConfig) throws ServletException { |
||||
if (StringUtils.isBlank(allowedIps)) { |
||||
throw new ServletException("Allowed IPs not found."); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) |
||||
throws IOException, ServletException { |
||||
String method = ((HttpServletRequest)request).getRequestURI(); |
||||
//先判断方法是否在配置中
|
||||
List<String> methodList=Arrays.asList(methodConfig.split(",")); |
||||
methodList.stream().forEach(item ->{ |
||||
if(item.equals(method)){ |
||||
// 获取请求 IP 地址并判断是否允许访问该接口...
|
||||
if (allowedIps.contains(request.getRemoteAddr())) { |
||||
try { |
||||
chain.doFilter(request, response); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} catch (ServletException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} else { |
||||
|
||||
HttpServletResponse httpResponse = (HttpServletResponse) response; |
||||
httpResponse.setStatus(HttpStatus.FORBIDDEN.value()); |
||||
httpResponse.setCharacterEncoding("UTF-8"); // 设置字符编码为UTF-8
|
||||
|
||||
try { |
||||
httpResponse.getWriter().write("访问被禁止"); // 设置返回信息(中文)
|
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return ; |
||||
} |
||||
}else { |
||||
try { |
||||
chain.doFilter(request, response); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} catch (ServletException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@Override |
||||
public void destroy() { |
||||
} |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
package com.cjy.back.ybsjAppointment.task; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.cjy.back.ybsjAppointment.dao.YbsjyAppointmentSettingMapper; |
||||
import com.cjy.back.ybsjAppointment.entity.AppointmentRequestTurnstileLogEntity; |
||||
import com.cjy.back.ybsjAppointment.service.YbsjyAppointmentRecordService; |
||||
import com.cjy.util.HttpUtil; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @author liangjiawei |
||||
* @createDate 2023/8/1 |
||||
*/ |
||||
|
||||
@Component("clearVisitorInformationTask") |
||||
public class ClearVisitorInformationTask { |
||||
@Autowired |
||||
YbsjyAppointmentRecordService ybsjyAppointmentRecordService; |
||||
@Autowired |
||||
YbsjyAppointmentSettingMapper ybsjyAppointmentSettingMapper; |
||||
|
||||
@Value("${turnstile.url}") |
||||
private String turnstileUrl; |
||||
@Value("${turnstile.clearSingleVisitor}") |
||||
private String clearSingleVisitor; |
||||
|
||||
@Scheduled(cron = "0 0/45 * * * ?") |
||||
// @Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void clearVisitorInformationTask() { |
||||
//获取未清理权限的数据
|
||||
List<Map<String, Object>> list = ybsjyAppointmentRecordService.getWrittenOffAppointmentData(); |
||||
List<String> ids = new ArrayList<>(); |
||||
list.stream().forEach(item -> { |
||||
String addVisitorResponseString = HttpUtil.doGet(turnstileUrl+clearSingleVisitor + "?idCard=" + item.get("documentsNumber")); |
||||
JSONObject addVisitorResponseJson = JSONObject.parseObject(addVisitorResponseString); |
||||
//记录访问日志
|
||||
AppointmentRequestTurnstileLogEntity appointmentRequestTurnstileLogEntity = new AppointmentRequestTurnstileLogEntity(); |
||||
appointmentRequestTurnstileLogEntity.setRequestUrl(turnstileUrl+clearSingleVisitor + "?idCard=" + item.get("documentsNumber")); |
||||
appointmentRequestTurnstileLogEntity.setType("get"); |
||||
appointmentRequestTurnstileLogEntity.setResponseBody(addVisitorResponseString); |
||||
appointmentRequestTurnstileLogEntity.setState(addVisitorResponseJson.get("code").toString()); |
||||
ybsjyAppointmentSettingMapper.saveAppointmentRequestTurnstileLog(appointmentRequestTurnstileLogEntity); |
||||
//修改数据清除状态
|
||||
if (ids.size() < 500) { |
||||
ids.add(item.get("id").toString()); |
||||
} else { |
||||
//修改数据状态
|
||||
ybsjyAppointmentRecordService.updateClearVisitorsState(ids); |
||||
ids.clear(); |
||||
ids.add(item.get("id").toString()); |
||||
} |
||||
}); |
||||
if (!ids.isEmpty()) { |
||||
//修改数据状态
|
||||
ybsjyAppointmentRecordService.updateClearVisitorsState(ids); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,110 @@ |
||||
package com.cjy.back.ybsjAppointment.task; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.cjy.back.ybsjAppointment.dao.YbsjyAppointmentRecordMapper; |
||||
import com.cjy.back.ybsjAppointment.entity.AppointmentWriteOffLogEntity; |
||||
import com.cjy.back.ybsjAppointment.entity.vo.ExtractRecordsDataVO; |
||||
import com.cjy.util.HttpUtil; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.scheduling.annotation.Scheduled; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @author liangjiawei |
||||
* @createDate 2023/8/1 |
||||
*/ |
||||
@Component("extractWriteOffRecordsTask") |
||||
public class ExtractWriteOffRecordsTask { |
||||
|
||||
@Value("${turnstile.extractRecords}") |
||||
private String extractRecords; |
||||
@Value("${turnstile.url}") |
||||
private String turnstileUrl; |
||||
@Autowired |
||||
YbsjyAppointmentRecordMapper ybsjyAppointmentRecordMapper; |
||||
|
||||
@Scheduled(cron = "0 0/50 * * * ?") |
||||
// @Scheduled(cron = "0 0/1 * * * ?")
|
||||
public void extractWriteOffRecordsTask() { |
||||
|
||||
Map<String, String> params = new HashMap<>(); |
||||
String extractRecordsString = HttpUtil.sendPost(turnstileUrl + extractRecords, params); |
||||
JSONObject extractRecordsJson = JSONObject.parseObject(extractRecordsString); |
||||
JSONArray extractRecordsDataJson = extractRecordsJson.getJSONArray("data"); |
||||
List<ExtractRecordsDataVO> list = extractRecordsDataJson.toJavaList(ExtractRecordsDataVO.class); |
||||
|
||||
List<AppointmentWriteOffLogEntity> appointmentWriteOffLogEntityList = new ArrayList<>(); |
||||
List<Long> ids = new ArrayList<>(); |
||||
|
||||
//过滤出 描述是 操作员远程开门 的数据
|
||||
List<ExtractRecordsDataVO> newList = list.stream().filter(i -> i.getDescribe().equals("操作员远程开门")).collect(Collectors.toList()); |
||||
newList.stream().forEach(item -> { |
||||
|
||||
|
||||
SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
SimpleDateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
||||
String time = item.getTime(); |
||||
String idCard = item.getIdCard(); |
||||
|
||||
Date date = null; |
||||
try { |
||||
date = inputDateFormat.parse(time); |
||||
} catch (ParseException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
String formattedDate = outputDateFormat.format(date); |
||||
|
||||
AppointmentWriteOffLogEntity appointmentWriteOffLogEntity = new AppointmentWriteOffLogEntity(); |
||||
appointmentWriteOffLogEntity.setTime(time); |
||||
appointmentWriteOffLogEntity.setIdCard(idCard); |
||||
try { |
||||
Map<String, Object> map = ybsjyAppointmentRecordMapper.getAppointmentPeopleInfo(formattedDate, idCard); |
||||
|
||||
if (map != null) { |
||||
ybsjyAppointmentRecordMapper.writeOff(time, map.get("id").toString()); |
||||
if (ybsjyAppointmentRecordMapper.getNotWrittenOffCount((Long) map.get("appointment_documents_id")) == 0) { |
||||
if (ids.size() < 200) { |
||||
ids.add(Long.parseLong(map.get("appointment_documents_id").toString())); |
||||
} else { |
||||
ybsjyAppointmentRecordMapper.updateDocumentsSateList(ids); |
||||
ids.clear(); |
||||
ids.add(Long.parseLong(map.get("appointment_documents_id").toString())); |
||||
} |
||||
|
||||
} |
||||
appointmentWriteOffLogEntity.setState("200"); |
||||
} else { |
||||
appointmentWriteOffLogEntity.setState("500"); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (appointmentWriteOffLogEntityList.size() < 200) { |
||||
appointmentWriteOffLogEntityList.add(appointmentWriteOffLogEntity); |
||||
} else { |
||||
ybsjyAppointmentRecordMapper.saveAppointmentWriteOffLogList(appointmentWriteOffLogEntityList); |
||||
appointmentWriteOffLogEntityList.clear(); |
||||
appointmentWriteOffLogEntityList.add(appointmentWriteOffLogEntity); |
||||
} |
||||
} |
||||
|
||||
}); |
||||
if (!appointmentWriteOffLogEntityList.isEmpty()) { |
||||
ybsjyAppointmentRecordMapper.saveAppointmentWriteOffLogList(appointmentWriteOffLogEntityList); |
||||
} |
||||
|
||||
if (!ids.isEmpty()) { |
||||
ybsjyAppointmentRecordMapper.updateDocumentsSateList(ids); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue