Commit 635a5a1e authored by zhangzhenbang's avatar zhangzhenbang

试探性写了一两个接口

parent 3d5cba66
package com.yingxin.beijingvehicleflow.controller; package com.yingxin.beijingvehicleflow.controller;
import com.yingxin.beijingvehicleflow.constant.Const;
import com.yingxin.beijingvehicleflow.dto.ReservationInfoDTO;
import com.yingxin.beijingvehicleflow.dto.ReservationsDisplayDTO; import com.yingxin.beijingvehicleflow.dto.ReservationsDisplayDTO;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation; import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.entity.Reservation;
import com.yingxin.beijingvehicleflow.response.Response; import com.yingxin.beijingvehicleflow.response.Response;
import com.yingxin.beijingvehicleflow.service.AuthService;
import com.yingxin.beijingvehicleflow.service.IdentityInformationService; import com.yingxin.beijingvehicleflow.service.IdentityInformationService;
import com.yingxin.beijingvehicleflow.service.ReservationService;
import com.yingxin.beijingvehicleflow.util.AESUtil; import com.yingxin.beijingvehicleflow.util.AESUtil;
import com.yingxin.beijingvehicleflow.util.PicUtils;
import net.sf.json.JSONObject; 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.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -103,4 +111,39 @@ public class IdentityInfoController { ...@@ -103,4 +111,39 @@ public class IdentityInfoController {
return identityInformationService.selectReservatinsByIdentityId(info); return identityInformationService.selectReservatinsByIdentityId(info);
} }
@Autowired
private AuthService authService;
@Autowired
private ReservationService reservationService;
/**
* 认证接口,此处不用再次判断身份证号码
*
* 1.图片压缩
*
* @date 2020/2/24
* @param reservationInfoDTO
* @return com.yingxin.beijingvehicleflow.response.Response
*/
@PostMapping("/identity/auth")
public Response verifyIdentity(@RequestBody ReservationInfoDTO reservationInfoDTO) {
IdentityInformation info = reservationInfoDTO.getIdentityInformation();
/*图片压缩*/
info.setFaceImage(
PicUtils.compressImage(info.getFaceImage(),
Const.FACE_IMG_SIZE));
if (!authService.is0x42AuthSucc(info)) {
return Response.fail("AUTH-FAILED","实名认证失败。");
}
Reservation reservation = reservationInfoDTO.getReservation();
Date date =new Date ();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
reservation.setAuthTime(sdf.format(date));
reservationInfoDTO.setReservation(reservation);
return reservationService.isUpdateAuthInfoSucc(reservation)?Response.succ():Response.fail();
}
} }
package com.yingxin.beijingvehicleflow.dto;
/**
* 发给认证接口的请求数据
*
* @author 226
* @version 1.0
* @date 2020/2/13
*/
public class AuthInfo {
private String cusNbr;
private String appID;
private String authMode;
private String idNbr;
private String idName;
private String idIssueExp;
private String idIssueSt;
private String faceData;
public AuthInfo() {
cusNbr = "YWZD49";
appID = "国投盈信";
idIssueExp = "";
idIssueSt = "";
}
public String getCusNbr() {
return cusNbr;
}
public void setCusNbr(String cusNbr) {
this.cusNbr = cusNbr;
}
public String getAppID() {
return appID;
}
public void setAppID(String appID) {
this.appID = appID;
}
public String getAuthMode() {
return authMode;
}
public void setAuthMode(String authMode) {
this.authMode = authMode;
}
public String getIdNbr() {
return idNbr;
}
public void setIdNbr(String idNbr) {
this.idNbr = idNbr;
}
public String getIdName() {
return idName;
}
public void setIdName(String idName) {
this.idName = idName;
}
public String getIdIssueExp() {
return idIssueExp;
}
public void setIdIssueExp(String idIssueExp) {
this.idIssueExp = idIssueExp;
}
public String getIdIssueSt() {
return idIssueSt;
}
public void setIdIssueSt(String idIssueSt) {
this.idIssueSt = idIssueSt;
}
public String getFaceData() {
return faceData;
}
public void setFaceData(String faceData) {
this.faceData = faceData;
}
}
package com.yingxin.beijingvehicleflow.dto;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/24
*/
public class EncodeData {
private ReservationInfoDTO data;
private String encodedData;
public EncodeData(ReservationInfoDTO data) {
this.data = data;
}
// public EncodeData encodeData() {
//
// encodedData = DesUtil.encrypt(Constant.KEY, String.valueOf(resident.getrId()));
//
// return
// }
}
...@@ -12,9 +12,15 @@ import lombok.Data; ...@@ -12,9 +12,15 @@ import lombok.Data;
@Data @Data
public class ReservationsDisplayDTO { public class ReservationsDisplayDTO {
private int reservationId; /*展示数据*/
private String name; private String name;
private String toBeijingDate; private String toBeijingDate;
private String submitCoordinate; private String submitCoordinate;
/*可能会用到的数据*/
private int identityId; private int identityId;
private int reservationId;
private String idCardNumber;
} }
...@@ -44,7 +44,7 @@ public interface IdentityInformationMapper { ...@@ -44,7 +44,7 @@ public interface IdentityInformationMapper {
@Select("select * from identity_information where wechat_openid = #{openid}") @Select("select * from identity_information where wechat_openid = #{openid}")
IdentityInformation getAllInfoByOpenid(String openid); IdentityInformation getAllInfoByOpenid(String openid);
@Select("select r.id as reservationId,info.name,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 " +
"from identity_information AS info LEFT JOIN reservation AS r ON info.id=r.identity_id WHERE info.id = #{id} ") "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); List<ReservationsDisplayDTO> selectReservatinsByIdentityId(IdentityInformation info);
} }
package com.yingxin.beijingvehicleflow.response;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/13
*/
public class AuthResponse {
private String errorDesc;
private boolean success;
private String authResult;
private String transNbr;
public AuthResponse() {}
public String getErrorDesc() {
return errorDesc;
}
public void setErrorDesc(String errorDesc) {
this.errorDesc = errorDesc;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getAuthResult() {
return authResult;
}
public void setAuthResult(String authResult) {
this.authResult = authResult;
}
public String getTransNbr() {
return transNbr;
}
public void setTransNbr(String transNbr) {
this.transNbr = transNbr;
}
}
package com.yingxin.beijingvehicleflow.service;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/13
*/
public interface AuthService {
/**
* 认证,返回成功或失败
* @param info
* @return
*/
boolean is0x42AuthSucc(IdentityInformation info);
}
...@@ -16,4 +16,6 @@ public interface ReservationService { ...@@ -16,4 +16,6 @@ public interface ReservationService {
Response insertIdentityInfoAndReservation(ReservationInfoDTO info) throws Exception; Response insertIdentityInfoAndReservation(ReservationInfoDTO info) throws Exception;
boolean isInsertReservationSucc(Reservation reservation); boolean isInsertReservationSucc(Reservation reservation);
boolean isUpdateAuthInfoSucc(Reservation reservation);
} }
package com.yingxin.beijingvehicleflow.service.impl;
import com.yingxin.beijingvehicleflow.constant.Const;
import com.yingxin.beijingvehicleflow.dto.AuthInfo;
import com.yingxin.beijingvehicleflow.entity.IdentityInformation;
import com.yingxin.beijingvehicleflow.response.AuthResponse;
import com.yingxin.beijingvehicleflow.service.AuthService;
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 org.springframework.web.client.RestTemplate;
/**
* description //TODO
*
* @author 226
* @version 1.0
* @date 2020/2/13
*/
@Service
public class AuthServiceImpl implements AuthService {
private static Logger LOGGER = LoggerFactory.getLogger(AuthService.class);
@Autowired
private RestTemplate restTemplate;
@Value("${auth-url}")
private String url;
@Override
public boolean is0x42AuthSucc(IdentityInformation info) {
AuthInfo authInfo = new AuthInfo();
authInfo.setAuthMode("0x42");
authInfo.setFaceData(info.getFaceImage());
authInfo.setIdName(info.getName());
authInfo.setIdNbr(info.getIdCardNumber());
AuthResponse authResponse;
try {
authResponse = restTemplate.postForObject(url, authInfo, AuthResponse.class);
} catch (Exception e) {
LOGGER.error("调用认证接口报错:", e);
return false;
}
/* TODO 刪掉 */
System.out.println("0x42");
System.out.println(authResponse.getTransNbr());
System.out.println(authResponse.getErrorDesc());
System.out.println(authResponse.getAuthResult());
System.out.println(authResponse.isSuccess());
return "00XX".equals(authResponse.getAuthResult());
}
}
...@@ -7,6 +7,8 @@ import com.yingxin.beijingvehicleflow.response.Response; ...@@ -7,6 +7,8 @@ import com.yingxin.beijingvehicleflow.response.Response;
import com.yingxin.beijingvehicleflow.service.IdentityInformationService; import com.yingxin.beijingvehicleflow.service.IdentityInformationService;
import com.yingxin.beijingvehicleflow.service.ReservationService; import com.yingxin.beijingvehicleflow.service.ReservationService;
import com.yingxin.beijingvehicleflow.util.IdCardUtil; import com.yingxin.beijingvehicleflow.util.IdCardUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -24,6 +26,9 @@ import java.util.Date; ...@@ -24,6 +26,9 @@ import java.util.Date;
@Service @Service
public class ReservationServiceImpl implements ReservationService { public class ReservationServiceImpl implements ReservationService {
private static Logger LOGGER = LoggerFactory.getLogger(ReservationService.class);
@Autowired @Autowired
private ReservationMapper reservationMapper; private ReservationMapper reservationMapper;
...@@ -54,6 +59,21 @@ public class ReservationServiceImpl implements ReservationService { ...@@ -54,6 +59,21 @@ public class ReservationServiceImpl implements ReservationService {
Date date =new Date (); Date date =new Date ();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
reservation.setSubmitTime(sdf.format(date)); reservation.setSubmitTime(sdf.format(date));
try {
return reservationMapper.insertReservation(reservation) == 1; return reservationMapper.insertReservation(reservation) == 1;
} catch (Exception e) {
LOGGER.error("预约单信息插入异常:", e);
return false;
}
}
@Override
public boolean isUpdateAuthInfoSucc(Reservation reservation) {
try {
return reservationMapper.updateAuthInfo(reservation) == 1;
} catch (Exception e) {
LOGGER.error("更新预约单认证坐标及时间异常:", e);
return false;
}
} }
} }
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