Commit ee60a4c8 authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent f787b905
package com.yingxin.beijingvehicleflow.controller;
import com.yingxin.beijingvehicleflow.entity.FloatingPopulation;
import com.yingxin.beijingvehicleflow.response.Response;
import com.yingxin.beijingvehicleflow.service.FloatingPopulationServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/24
*/
@RestController
@CrossOrigin
@RequestMapping("/api/v1")
public class FloatingPopulationController {
@Autowired
private FloatingPopulationServcie populationServcie;
@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);
floatingPopulation.setAuthCoordinate(selectResult.getAuthCoordinate());
floatingPopulation.setAuthTime(selectResult.getAuthTime());
floatingPopulation.setSubmitCoordinate(selectResult.getSubmitCoordinate());
floatingPopulation.setSubmitTime(selectResult.getSubmitTime());
return populationServcie.isInsertFloatingPopulationSucc(floatingPopulation)?Response.succ():Response.fail();
}
}
......@@ -16,6 +16,8 @@ public class ReservationsDisplayDTO {
private String name;
private String toBeijingDate;
private String submitCoordinate;
private String carNumber;
private int verifyState;
/*可能会用到的数据*/
private int identityId;
......
......@@ -21,4 +21,5 @@ public class FloatingPopulation {
private String authTime;
private int workerId;
private int reservationId;
private boolean isTemperatureOk = true;
}
......@@ -2,6 +2,8 @@ package com.yingxin.beijingvehicleflow.entity;
import lombok.Data;
import java.util.List;
/**
* 数据库reservation表对应实体类
*
......@@ -26,4 +28,12 @@ public class Reservation {
private String authTime;
private int verifyState;
private int identityId;
private List<VerifyMaterial> materials;
@Data
public class VerifyMaterial {
private String material;
}
}
package com.yingxin.beijingvehicleflow.mapper;
import com.yingxin.beijingvehicleflow.entity.FloatingPopulation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/**
* 数据库表单对应Mapper
......@@ -11,4 +14,13 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface FloatingPopulationMapper {
@Insert("insert into floating_population(check_coordinate,check_time,submit_coordinate,submit_time," +
"auth_coordinate,auth_time,worker_id,reservation_id,isTemperatureOk) " +
"values(#{checkCoordinate},#{checkTime},#{submitCoordinate},#{submitTime}," +
"#{authCoordinate},#{authTime},#{workerId},#{reservationId},#{isTemperatureOk})")
int insertFloatingPopulation(FloatingPopulation floatingPopulation);
@Select("select r.submit_time,r.submit_coordinate,r.auth_time,r.auth_coordinate FROM reservation as r WHERE id = #{reservationId}")
FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation);
}
......@@ -44,7 +44,7 @@ public interface IdentityInformationMapper {
@Select("select * from identity_information where wechat_openid = #{openid}")
IdentityInformation getAllInfoByOpenid(String openid);
@Select("select r.id as reservationId,info.name,info.id_card_number,info.toBeijing_date,r.submit_coordinate,r.identity_id " +
@Select("select r.id as reservationId,info.name,info.id_card_number,info.toBeijing_date,r.submit_coordinate,r.identity_id,r.car_number,r.verify_state " +
"from identity_information AS info LEFT JOIN reservation AS r ON info.id=r.identity_id WHERE info.id = #{id} ")
List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info);
}
package com.yingxin.beijingvehicleflow.service;
import com.yingxin.beijingvehicleflow.entity.FloatingPopulation;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/24
*/
public interface FloatingPopulationServcie {
boolean isInsertFloatingPopulationSucc(FloatingPopulation floatingPopulation);
boolean isIdentityInfoValid(FloatingPopulation floatingPopulation);
FloatingPopulation selectOneByReservationId(FloatingPopulation floatingPopulation);
}
package com.yingxin.beijingvehicleflow.service.impl;
import com.yingxin.beijingvehicleflow.entity.FloatingPopulation;
import com.yingxin.beijingvehicleflow.mapper.FloatingPopulationMapper;
import com.yingxin.beijingvehicleflow.service.FloatingPopulationServcie;
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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/24
*/
@Service
public class FloatingPopulationServcieImpl implements FloatingPopulationServcie {
private static Logger LOGGER = LoggerFactory.getLogger(FloatingPopulationServcie.class);
@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);
}
}
......@@ -32,6 +32,8 @@ restTemplate:
defaultMaxPerRoute: 10000
validateAfterInactivity: 30000
QR-code-validTime: 5
async-Config:
MAX-POOL-SIZE: 50
CORE-POOL-SIZE: 20
......
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