Commit dda16cfa authored by hanfeng's avatar hanfeng

修改违章,增加bean

parent 1a3e4ed3
package com.xxfc.platform.universal.api; package com.xxfc.platform.universal.api;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.universal.feign.ThirdFeign;
import com.xxfc.platform.universal.model.JuheResult; import com.xxfc.platform.universal.model.JuheResult;
import com.xxfc.platform.universal.vo.TrafficViolations;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient("xx-third-party") //@FeignClient(name = "xx-universal")
@RequestMapping("3p/tv") @RequestMapping("/3p/tv")
public interface ITrafficViolationsFeign { public interface ITrafficViolationsFeign {
/**
* 获取支持的城市
* @param province
* @return
*/
@RequestMapping(value = "city", method = RequestMethod.GET)
JuheResult getCityInfo(String province);
/**
* 查违章
* @param city 城市代码
* @param hphm 车牌号码
* @param hpzl 车辆类型 01:大车,02:小车
* @param engineno 发动机号
* @param classno 车架号
* @return
*/
@RequestMapping(value = "trafficViolations", method = RequestMethod.GET)
JuheResult queryTrafficViolations(String city, String hphm, String hpzl, String engineno, String classno);
/**
* 获取剩余查询次数
* @return
*/
@RequestMapping(value = "balance", method = RequestMethod.GET)
JuheResult getBalance();
/**
* 根据车牌查归属地
* @param hphm 车牌号码
* @return
*/
@RequestMapping(value = "carPre", method = RequestMethod.GET)
JuheResult carPre(String hphm);
} }
package com.xxfc.platform.universal.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.code.IdentityDialect;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Data
public class searchableCity {
@Id
@KeySql(dialect = IdentityDialect.MYSQL)
private Integer id;
private String code;
@Column(name = "city_name")
private String cityName;
@Column(name = "create_date")
@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss" )
@JsonFormat(timezone = "GMT-8",pattern = "yyyy-MM-dd HH:mm:ss")
private Date createDate;
@Column(name = "update_date")
@DateTimeFormat(pattern ="yyyy-MM-dd HH:mm:ss" )
@JsonFormat(timezone = "GMT-8",pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateDate;
}
...@@ -5,11 +5,9 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; ...@@ -5,11 +5,9 @@ import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.universal.entity.OrderRefund; import com.xxfc.platform.universal.entity.OrderRefund;
import com.xxfc.platform.universal.vo.OrderPayVo; import com.xxfc.platform.universal.vo.OrderPayVo;
import com.xxfc.platform.universal.vo.OrderRefundVo; import com.xxfc.platform.universal.vo.OrderRefundVo;
import com.xxfc.platform.universal.vo.TrafficViolations;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -30,4 +28,25 @@ public interface ThirdFeign { ...@@ -30,4 +28,25 @@ public interface ThirdFeign {
@RequestMapping(value = "/refund/app/wx", method = RequestMethod.POST) @RequestMapping(value = "/refund/app/wx", method = RequestMethod.POST)
public ObjectRestResponse<String> refund(@RequestBody OrderRefundVo orderRefundVo); public ObjectRestResponse<String> refund(@RequestBody OrderRefundVo orderRefundVo);
/**
* 获取支持的城市
* @return
*/
@GetMapping("/city")
ObjectRestResponse getCityInfo();
/**
* 违章车辆查询
* @return
*/
@PostMapping("/trafficViolations")
ObjectRestResponse queryTrafficViolations(@RequestBody TrafficViolations trafficViolations) ;
/**
* 车辆类型查询
* @return
*/
@GetMapping("/LicensePlateType")
ObjectRestResponse getLicensePlateType();
} }
...@@ -19,7 +19,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -19,7 +19,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableAceCache @EnableAceCache
@EnableTransactionManagement @EnableTransactionManagement
@tk.mybatis.spring.annotation.MapperScan(basePackages = "com.xxfc.platform.universal.mapper") @tk.mybatis.spring.annotation.MapperScan(basePackages = "com.xxfc.platform.universal.mapper")
@EnableFeignClients(value = {"com.github.wxiaoqi.security.auth.client.feign", "com.xxfc.platform","com.github.wxiaoqi.security.admin.feign"},defaultConfiguration = HeaderConfig.class) @EnableFeignClients(value = {"com.xxfc.platform","com.github.wxiaoqi.security"},defaultConfiguration = HeaderConfig.class)
public class UniversalApplication { public class UniversalApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
package com.xxfc.platform.universal.controller; package com.xxfc.platform.universal.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.universal.service.TrafficViolationsService; import com.xxfc.platform.universal.service.TrafficViolationsService;
import com.xxfc.platform.universal.vo.TrafficViolations; import com.xxfc.platform.universal.vo.TrafficViolations;
...@@ -15,13 +16,12 @@ public class TrafficViolationsController { ...@@ -15,13 +16,12 @@ public class TrafficViolationsController {
/** /**
* 获取支持的城市 * 获取支持的城市
* @param province
* @return * @return
*/ */
@GetMapping("/city/{province}") @GetMapping("/city")
public ObjectRestResponse getCityInfo(@PathVariable String province) { public ObjectRestResponse getCityInfo() {
try { try {
return ObjectRestResponse.succ(tvService.getCity()); return ObjectRestResponse.succ(JSONObject.parse(tvService.getCity()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ObjectRestResponse.createDefaultFail(); return ObjectRestResponse.createDefaultFail();
...@@ -35,7 +35,7 @@ public class TrafficViolationsController { ...@@ -35,7 +35,7 @@ public class TrafficViolationsController {
@PostMapping("/trafficViolations") @PostMapping("/trafficViolations")
public ObjectRestResponse queryTrafficViolations(@RequestBody TrafficViolations trafficViolations) { public ObjectRestResponse queryTrafficViolations(@RequestBody TrafficViolations trafficViolations) {
try { try {
return ObjectRestResponse.succ(tvService.queryViolations(trafficViolations)); return ObjectRestResponse.succ(JSONObject.parse(tvService.queryViolations(trafficViolations)));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ObjectRestResponse.createDefaultFail(); return ObjectRestResponse.createDefaultFail();
...@@ -49,7 +49,7 @@ public class TrafficViolationsController { ...@@ -49,7 +49,7 @@ public class TrafficViolationsController {
@GetMapping("/LicensePlateType") @GetMapping("/LicensePlateType")
public ObjectRestResponse getLicensePlateType() { public ObjectRestResponse getLicensePlateType() {
try { try {
return ObjectRestResponse.succ(tvService.getLicensePlateType()); return ObjectRestResponse.succ(JSONObject.parse(tvService.getLicensePlateType()));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return ObjectRestResponse.createDefaultFail(); return ObjectRestResponse.createDefaultFail();
......
package com.xxfc.platform.universal.service; package com.xxfc.platform.universal.service;
import com.alibaba.fastjson.JSONObject;
import com.xxfc.platform.universal.entity.searchableCity;
import com.xxfc.platform.universal.utils.CertifHttpUtils; import com.xxfc.platform.universal.utils.CertifHttpUtils;
import com.xxfc.platform.universal.vo.TrafficViolations; import com.xxfc.platform.universal.vo.TrafficViolations;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* 违章查询 * 违章查询
* 注意:调用"北京库斯曼科技有限公司"的接口,返回参是Unicode编码
*/ */
@Service @Service
public class TrafficViolationsService { public class TrafficViolationsService {
...@@ -25,7 +35,7 @@ public class TrafficViolationsService { ...@@ -25,7 +35,7 @@ public class TrafficViolationsService {
private static final String CITY_METHOD = "GET"; private static final String CITY_METHOD = "GET";
private static final String VIOLATIONS_HOST = "https://weizhang.market.alicloudapi.com"; private static final String VIOLATIONS_HOST = "https://weizhang.market.alicloudapi.com";
private static final String VIOLATIONS_PATH = "/wz/type"; private static final String VIOLATIONS_PATH = "/wz/query";
private static final String VIOLATIONS_METHOD = "GET"; private static final String VIOLATIONS_METHOD = "GET";
private static final String GET_LICENSE_PLATE_TYPE_HOST = "https://weizhang.market.alicloudapi.com"; private static final String GET_LICENSE_PLATE_TYPE_HOST = "https://weizhang.market.alicloudapi.com";
...@@ -45,16 +55,18 @@ public class TrafficViolationsService { ...@@ -45,16 +55,18 @@ public class TrafficViolationsService {
* @return * @return
* @throws Exception type 返回参数类型 * @throws Exception type 返回参数类型
*/ */
public String getCity() throws Exception {
@Scheduled(cron = "0 0 0 * * ?")
public String getCity() throws Exception {
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
headers.put(AUTHORIZATION, "APPCODE " + CODE); headers.put(AUTHORIZATION, "APPCODE " + CODE);
Map<String, String> querys = new HashMap<String, String>(); Map<String, String> querys = new HashMap<String, String>();
querys.put(TYPE_NAME, TYPE); querys.put(TYPE_NAME, TYPE);
HttpResponse httpResponse = CertifHttpUtils.doGet(CITY_HOST, CITY_PATH, CITY_METHOD, headers, querys); HttpResponse httpResponse = CertifHttpUtils.doGet(CITY_HOST, CITY_PATH, CITY_METHOD, headers, querys);
String provinceJSON = httpResponse.toString(); HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
return provinceJSON; JSONObject.parseObject(result, searchableCity.class);
return unicodeToString(EntityUtils.toString(entity));
} }
...@@ -65,7 +77,6 @@ public class TrafficViolationsService { ...@@ -65,7 +77,6 @@ public class TrafficViolationsService {
* @return * @return
*/ */
public String queryViolations(TrafficViolations trafficViolations) throws Exception { public String queryViolations(TrafficViolations trafficViolations) throws Exception {
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
headers.put(AUTHORIZATION, "APPCODE " + CODE); headers.put(AUTHORIZATION, "APPCODE " + CODE);
Map<String, String> querys = new HashMap<String, String>(); Map<String, String> querys = new HashMap<String, String>();
...@@ -74,9 +85,8 @@ public class TrafficViolationsService { ...@@ -74,9 +85,8 @@ public class TrafficViolationsService {
querys.put(ENGINENO_NAME, trafficViolations.getEngineno()); querys.put(ENGINENO_NAME, trafficViolations.getEngineno());
querys.put(FRAMENO_NAME, trafficViolations.getFrameno()); querys.put(FRAMENO_NAME, trafficViolations.getFrameno());
HttpResponse httpResponse = CertifHttpUtils.doGet(VIOLATIONS_HOST, VIOLATIONS_PATH, VIOLATIONS_METHOD, headers, querys); HttpResponse httpResponse = CertifHttpUtils.doGet(VIOLATIONS_HOST, VIOLATIONS_PATH, VIOLATIONS_METHOD, headers, querys);
String provinceJSON = httpResponse.toString(); HttpEntity entity = httpResponse.getEntity();
return unicodeToString(EntityUtils.toString(entity));
return provinceJSON;
} }
/** /**
...@@ -84,20 +94,54 @@ public class TrafficViolationsService { ...@@ -84,20 +94,54 @@ public class TrafficViolationsService {
* *
* @return * @return
* @throws Exception * @throws Exception
*
*/ */
public String getLicensePlateType() throws Exception { public String getLicensePlateType() throws Exception {
Map<String, String> headers = new HashMap<String, String>(); Map<String, String> headers = new HashMap<String, String>();
headers.put(AUTHORIZATION, "APPCODE " + CODE); headers.put(AUTHORIZATION, "APPCODE " + CODE);
HashMap<String, String> querys = new HashMap<>();
HttpResponse httpResponse = CertifHttpUtils.doGet(GET_LICENSE_PLATE_TYPE_HOST, HttpResponse httpResponse = CertifHttpUtils.doGet(GET_LICENSE_PLATE_TYPE_HOST,
GET_LICENSE_PLATE_TYPE_PATH, GET_LICENSE_PLATE_TYPE_PATH,
GET_LICENSE_PLATE_TYPE_METHOD, GET_LICENSE_PLATE_TYPE_METHOD,
headers, headers,
new HashMap<String, String>()); querys
String provinceJSON = httpResponse.toString(); );
HttpEntity entity = httpResponse.getEntity();
return unicodeToString(EntityUtils.toString(entity));
}
/**
* Unicode转汉字字符串
* @param str
* @return
*/
private String unicodeToString(String str) {
Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
Matcher matcher = pattern.matcher(str);
char ch;
while (matcher.find()) {
String group = matcher.group(2);
ch = (char) Integer.parseInt(group, 16);
String group1 = matcher.group(1);
str = str.replace(group1, ch + "");
}
return str;
return provinceJSON;
} }
} }
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