Commit 00b54e79 authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent d0eae0dc
package com.yingxin.beijingvehicleflow.constant;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
public interface Const {
/* 人脸照片 单位K*/
long FACE_IMG_SIZE = 30;
}
package com.yingxin.beijingvehicleflow.controller;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.response.Response;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yingxin.beijingvehicleflow.service.ReservationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* description //TODO
......@@ -18,8 +21,24 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/api/v1")
public class ReservationController {
@PostMapping
public Response insertIdentityInfoAndReservation() {
private static Logger LOGGER = LoggerFactory.getLogger(ReservationController.class);
@Autowired
private ReservationService reservationService;
@PostMapping("/identity/reservation")
public Response insertIdentityInfoAndReservation(@RequestBody ReservationInfoDTO info) {
try {
return reservationService.insertIdentityInfoAndReservation(info);
} catch (Exception e) {
LOGGER.error("预约表单提交接口异常:", e);
}
return Response.fail();
}
@PostMapping("/reservations")
public Response selectReservatinsByIdentityId(@RequestBody Reservation reservation) {
return null;
}
}
package com.yingxin.beijingvehicleflow.dto;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import lombok.Data;
/**
* 创建预约单页面表单
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
@Data
public class ReservationInfoDTO {
private Reservation reservation;
private IdentityInformation identityInformation;
}
package com.yingxin.beijingvehicleflow.dto;
import lombok.Data;
/**
* ‘我的预约’展示界面所需信息
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
@Data
public class ReservationsDisplayDTO {
private String name;
}
......@@ -17,8 +17,9 @@ public class IdentityInformation {
private String idCardNumber;
private String phoneNumber;
private String faceImage;
private String toBeijingDate;
private String wechatPhone;
private String wechat_openid;
private String wechatOpenid;
private boolean isWorker;
}
......@@ -22,6 +22,6 @@ public class Reservation {
private String submitTime;
private String authCoordinate;
private String authTime;
private String verifyState;
private int verifyState;
private int identityId;
}
package com.yingxin.beijingvehicleflow.mapper;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;
/**
* 数据库表单对应Mapper
......@@ -11,4 +15,28 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface IdentityInformationMapper {
/**
* 第一次插入身份信息表,注册的时候【只插入wechatPhone,wechatOpenid】
*
* @date 2020/2/23
* @param identityInformation 包含wechatPhone,wechatOpenid
* @return int
*/
@Insert("insert into identity_information(wechat_phone,wechat_openid) " +
"values(#{wechatPhone},#{wechatOpenid})")
@Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
int insertIdentityInfo(IdentityInformation identityInformation);
/**
* 预约表单提交的时候更新身份信息数据
*
* @date 2020/2/23
* @param identityInformation 包含除了wechatPhone,wechatOpenid的所有信息
* @return
*/
@Update("update identity_information set name=#{name},id_card_number=#{idCardNumber}," +
"phone_number=#{phoneNumber},face_image=#{faceImage},toBeijing_date=#{toBeijingDate}," +
"is_worker=#{isWorker} where id =#{id}")
int updateIdentityInfo(IdentityInformation identityInformation);
}
package com.yingxin.beijingvehicleflow.mapper;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
/**
* 数据库表单对应Mapper
......@@ -11,4 +17,28 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ReservationMapper {
/**
* 插入预约表中的所有的内容【在身份信息插入后】,除开认证时的时间还有坐标
*
* @date 2020/2/23
* @param reservation 预约表信息
* @return int
*/
@Insert("insert into reservation(car_number,outset,destination,community_contact_name,community_contact_phone,submit_coordinate,submit_time,verify_state,identity_id) " +
"values(#{carNumber},#{outset},#{destination},#{communityContactName},#{communityContactPhone},#{submitCoordinate},#{submitTime},#{verifyState},#{identityId}) ")
int insertReservation(Reservation reservation);
/**
* 根据预约单的id来更新预约单生成二维码时的认证坐标和认证时间
*
* @date 2020/2/23
* @param reservation 预约表信息【包括id,authCoordinate,authTime】
* @return int
*/
@Update("update reservation set auth_coordinate=#{authCoordinate},auth_time=#{authTime} where id = #{id}")
int updateAuthInfo(Reservation reservation);
@Select("select * ")
List<Reservation> selectReservatinsByIdentityId(Reservation reservation);
}
package com.yingxin.beijingvehicleflow.service;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
public interface IdentityInformationService {
/**
* 注册时插入的记录,此时只有微信绑定手机号码以及openid
*
* @date 2020/2/23
* @param identityInformation 包括微信手机号和微信openid
* @return int 插入后的逻辑主键
*/
int insertIdentityInfo(IdentityInformation identityInformation);
/**
* 预约表单提交关于身份信息的完善
*
* @date 2020/2/23
* @param identityInformation 除开微信手机号和微信openid的所有信息
* @return int 更新数据条数
*/
boolean isUpdateIdentityInfoSucc(IdentityInformation identityInformation);
}
package com.yingxin.beijingvehicleflow.service;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.response.Response;
/**
* description //TODO
* 预约表单相关服务
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
public interface ReservationService {
Response insertIdentityInfoAndReservation(ReservationInfoDTO info) throws Exception;
boolean isInsertReservationSucc(Reservation reservation);
}
package com.yingxin.beijingvehicleflow.service.impl;
import com.yingxin.beijingvehicleflow.constant.Const;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.mapper.IdentityInformationMapper;
import com.yingxin.beijingvehicleflow.service.IdentityInformationService;
import com.yingxin.beijingvehicleflow.util.PicUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/23
*/
@Service
public class IdentityInformationServiceImpl implements IdentityInformationService {
@Autowired
private IdentityInformationMapper identityInformationMapper;
@Override
public int insertIdentityInfo(IdentityInformation identityInformation) {
identityInformationMapper.insertIdentityInfo(identityInformation);
return identityInformation.getId();
}
@Override
public boolean isUpdateIdentityInfoSucc(IdentityInformation identityInformation) {
identityInformation.setFaceImage(
PicUtils.compressImage(identityInformation.getFaceImage(),
Const.FACE_IMG_SIZE));
return identityInformationMapper.updateIdentityInfo(identityInformation) == 1;
}
}
package com.yingxin.beijingvehicleflow.service.impl;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.mapper.ReservationMapper;
import com.yingxin.beijingvehicleflow.response.Response;
import com.yingxin.beijingvehicleflow.service.IdentityInformationService;
import com.yingxin.beijingvehicleflow.service.ReservationService;
import com.yingxin.beijingvehicleflow.util.IdCardUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* description //TODO
......@@ -13,5 +24,36 @@ import org.springframework.stereotype.Service;
@Service
public class ReservationServiceImpl implements ReservationService {
@Autowired
private ReservationMapper reservationMapper;
@Autowired
private IdentityInformationService identityService;
@Override
@Transactional(rollbackFor = Exception.class)
public Response insertIdentityInfoAndReservation(ReservationInfoDTO info) throws Exception{
String idCardNumber = info.getIdentityInformation().getIdCardNumber();
if (!IdCardUtil.isValidatedAllIdcard(idCardNumber)) {
return Response.fail("ERROR-ID-NUMBER", "身份证格式有误,请重新输入。");
}
if (identityService.isUpdateIdentityInfoSucc(info.getIdentityInformation()) &&
isInsertReservationSucc(info.getReservation())) {
return Response.succ();
}
return Response.fail();
}
@Override
public boolean isInsertReservationSucc(Reservation reservation) {
Date date =new Date ();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
reservation.setSubmitTime(sdf.format(date));
return reservationMapper.insertReservation(reservation) == 1;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出-->
<!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数-->
<configuration status="WARN" monitorInterval="30">
<properties>
<property name="projectName">beijing-vehicleflow</property>
<property name="filePath">E:/Biometrics_Recognition_Logs</property>
</properties>
<!--先定义所有的appender-->
<appenders>
<!--这个输出控制台的配置-->
<console name="Console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)-->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<!--输出日志的格式-->
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</console>
<!-- 这个会打印出所有的info及以下级别的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档-->
<RollingFile name="RollingFileError" fileName="${filePath}/${projectName}.log" filePattern="${filePath}/$${date:yyyy-MM}/${projectName}-%d{yyyy-MM-dd}-%i.log">
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>
</appenders>
<!--然后定义logger,只有定义了logger并引入的appender,appender才会生效-->
<loggers>
<!--过滤掉spring和mybatis的一些无用的DEBUG信息-->
<logger name="org.springframework" level="INFO"/>
<logger name="org.mybatis" level="INFO"/>
<root level="all">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFileError"/>
</root>
</loggers>
</configuration>
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