Commit 6f1a92e0 authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent ad18cc3c
......@@ -28,10 +28,6 @@ public class FloatingPopulationController {
@PostMapping("/float-population")
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");
floatingPopulation.setCheckTime(sdf.format(new Date()));
FloatingPopulation selectResult = populationServcie.selectOneByReservationId(floatingPopulation);
......
......@@ -157,19 +157,21 @@ public class IdentityInfoController {
public Response selectOneByEncodedId(@RequestBody String json) {
IdentityInformation info;
JSONObject datafterDecryptJson;
try {
JSONObject jsonObject = JSONObject.fromObject(json);
String encodedData = jsonObject.getString("encodedData");
String datafterDecryptStr = DesUtil.decrypt(Const.KEY, encodedData);
datafterDecryptJson = JSONObject.fromObject(datafterDecryptStr);
String authTime = datafterDecryptJson.getString("authTime");
// String lastFourNumOfIdCard = resident.getrIdCard().substring(14);
// resident.setrIdCard(Constant.ID_CARD_14NUM_FLAG + lastFourNumOfIdCard);
if (!identityInformationService.isIdentityInfoValid(authTime)) {
return Response.fail("INVALID-CODE","二维码已过期,请重新生成二维码。");
}
} catch (JSONException e) {
LOGGER.error("解密查询接口Json解析异常", e);
return Response.fail("JSON-PARSE-ERROR","json解析异常");
}
catch (Exception e) {
} catch (Exception e) {
LOGGER.error("解密查询接口异常", e);
return Response.fail("DECRYPT-ERROR","解密异常!");
}
......
......@@ -13,7 +13,5 @@ public interface FloatingPopulationServcie {
boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation);
boolean isIdentityInfoValid(FloatingPopulation floatingPopulation);
FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation);
}
......@@ -39,4 +39,6 @@ public interface IdentityInformationService {
List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info);
boolean isIdentityInfoValid(String authTime);
}
......@@ -28,33 +28,13 @@ public class FloatingPopulationServcieImpl implements FloatingPopulationServcie
@Autowired
private FloatingPopulationMapper populationMapper;
@Value("${QR-code-validTime}")
private long validTime;
@Override
public boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation) {
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
public FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation) {
return populationMapper.selectOneByReservationId(floatingPopulation);
......
......@@ -10,6 +10,7 @@ import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.BufferedReader;
......@@ -18,6 +19,9 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
......@@ -95,4 +99,26 @@ public class IdentityInformationServiceImpl implements IdentityInformationServic
public List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation 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