Commit 6f1a92e0 authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent ad18cc3c
...@@ -28,10 +28,6 @@ public class FloatingPopulationController { ...@@ -28,10 +28,6 @@ public class FloatingPopulationController {
@PostMapping("/float-population") @PostMapping("/float-population")
public Response checkFloatingPopulation(@RequestBody FloatingPopulation floatingPopulation) { public Response checkFloatingPopulation(@RequestBody FloatingPopulation floatingPopulation) {
if (!populationServcie.isIdentityInfoValid(floatingPopulation)) {
return Response.fail("INVALID-CODE","二维码已过期,请重新生成二维码。");
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
floatingPopulation.setCheckTime(sdf.format(new Date())); floatingPopulation.setCheckTime(sdf.format(new Date()));
FloatingPopulation selectResult = populationServcie.selectOneByReservationId(floatingPopulation); FloatingPopulation selectResult = populationServcie.selectOneByReservationId(floatingPopulation);
......
...@@ -157,19 +157,21 @@ public class IdentityInfoController { ...@@ -157,19 +157,21 @@ public class IdentityInfoController {
public Response selectOneByEncodedId(@RequestBody String json) { public Response selectOneByEncodedId(@RequestBody String json) {
IdentityInformation info; IdentityInformation info;
JSONObject datafterDecryptJson; JSONObject datafterDecryptJson;
try { try {
JSONObject jsonObject = JSONObject.fromObject(json); JSONObject jsonObject = JSONObject.fromObject(json);
String encodedData = jsonObject.getString("encodedData"); String encodedData = jsonObject.getString("encodedData");
String datafterDecryptStr = DesUtil.decrypt(Const.KEY, encodedData); String datafterDecryptStr = DesUtil.decrypt(Const.KEY, encodedData);
datafterDecryptJson = JSONObject.fromObject(datafterDecryptStr); datafterDecryptJson = JSONObject.fromObject(datafterDecryptStr);
String authTime = datafterDecryptJson.getString("authTime");
// String lastFourNumOfIdCard = resident.getrIdCard().substring(14); if (!identityInformationService.isIdentityInfoValid(authTime)) {
// resident.setrIdCard(Constant.ID_CARD_14NUM_FLAG + lastFourNumOfIdCard); return Response.fail("INVALID-CODE","二维码已过期,请重新生成二维码。");
}
} catch (JSONException e) { } catch (JSONException e) {
LOGGER.error("解密查询接口Json解析异常", e); LOGGER.error("解密查询接口Json解析异常", e);
return Response.fail("JSON-PARSE-ERROR","json解析异常"); return Response.fail("JSON-PARSE-ERROR","json解析异常");
} } catch (Exception e) {
catch (Exception e) {
LOGGER.error("解密查询接口异常", e); LOGGER.error("解密查询接口异常", e);
return Response.fail("DECRYPT-ERROR","解密异常!"); return Response.fail("DECRYPT-ERROR","解密异常!");
} }
......
...@@ -13,7 +13,5 @@ public interface FloatingPopulationServcie { ...@@ -13,7 +13,5 @@ public interface FloatingPopulationServcie {
boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation); boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation);
boolean isIdentityInfoValid(FloatingPopulation floatingPopulation);
FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation); FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation);
} }
...@@ -39,4 +39,6 @@ public interface IdentityInformationService { ...@@ -39,4 +39,6 @@ public interface IdentityInformationService {
List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info); List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info);
boolean isIdentityInfoValid(String authTime);
} }
...@@ -28,33 +28,13 @@ public class FloatingPopulationServcieImpl implements FloatingPopulationServcie ...@@ -28,33 +28,13 @@ public class FloatingPopulationServcieImpl implements FloatingPopulationServcie
@Autowired @Autowired
private FloatingPopulationMapper populationMapper; private FloatingPopulationMapper populationMapper;
@Value("${QR-code-validTime}")
private long validTime;
@Override @Override
public boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation) { public boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation) {
return populationMapper.insertFloatingPopulation(floatingPopulation) == 1; return populationMapper.insertFloatingPopulation(floatingPopulation) == 1;
} }
@Override
public boolean isIdentityInfoValid(FloatingPopulation floatingPopulation) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String authTime = floatingPopulation.getAuthTime();
String checkTime = sdf.format(new Date());
long milliSeconds;
try {
Date authDate = sdf.parse(authTime);
Date checkDate = sdf.parse(checkTime);
milliSeconds = checkDate.getTime() - authDate.getTime();
} catch (ParseException e) {
LOGGER.error("检验二维码是否过期日期解析异常", e);
return false;
}
return (milliSeconds/60.0/1000.0) < validTime;
}
@Override @Override
public FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation) { public FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation) {
return populationMapper.selectOneByReservationId(floatingPopulation); return populationMapper.selectOneByReservationId(floatingPopulation);
......
...@@ -10,6 +10,7 @@ import net.sf.json.JSONObject; ...@@ -10,6 +10,7 @@ import net.sf.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -18,6 +19,9 @@ import java.io.InputStreamReader; ...@@ -18,6 +19,9 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -95,4 +99,26 @@ public class IdentityInformationServiceImpl implements IdentityInformationServic ...@@ -95,4 +99,26 @@ public class IdentityInformationServiceImpl implements IdentityInformationServic
public List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info) { public List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info) {
return identityInformationMapper.selectReservatinsByIdentityId(info); return identityInformationMapper.selectReservatinsByIdentityId(info);
} }
@Value("${QR-code-validTime}")
private long validTime;
@Override
public boolean isIdentityInfoValid(String authTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String checkTime = sdf.format(new Date());
long milliSeconds;
try {
Date authDate = sdf.parse(authTime);
Date checkDate = sdf.parse(checkTime);
milliSeconds = checkDate.getTime() - authDate.getTime();
} catch (ParseException e) {
LOGGER.error("检验二维码是否过期日期解析异常", e);
return false;
}
return (milliSeconds/60.0/1000.0) < validTime;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment