Commit 9ab3ed77 authored by hanfeng's avatar hanfeng

修改违章,把查询到的车型代码和类型保存到数据库

parent e62b0829
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.io.Serializable;
import java.util.Date;
@Data
public class LicensePlateType implements Serializable {
/**
* id
*/
@Id
@KeySql(dialect = IdentityDialect.MYSQL)
private Integer id;
/**
* 车型代码
*/
private String code;
/**
* 车型类型
*/
private String type;
/**
* 创建时间
*/
@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;
public LicensePlateType(String code, String type,Date createDate) {
this.code=code;
this.type=type;
this.createDate=createDate;
}
public LicensePlateType() {
}
}
...@@ -11,7 +11,7 @@ import javax.persistence.Id; ...@@ -11,7 +11,7 @@ import javax.persistence.Id;
import java.util.Date; import java.util.Date;
@Data @Data
public class searchableCity { public class SearchableCity {
@Id @Id
@KeySql(dialect = IdentityDialect.MYSQL) @KeySql(dialect = IdentityDialect.MYSQL)
......
package com.xxfc.platform.universal.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.universal.entity.LicensePlateType;
import com.xxfc.platform.universal.entity.SearchableCity;
import com.xxfc.platform.universal.mapper.LicensePlateTypeMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class LicensePlateTypeBiz extends BaseBiz<LicensePlateTypeMapper, LicensePlateType> {
public void insertLicensePlateType(ArrayList<LicensePlateType> licensePlateTypes) {
mapper.insertLicensePlateType(licensePlateTypes);
}
}
package com.xxfc.platform.universal.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.xxfc.platform.universal.entity.SearchableCity;
import com.xxfc.platform.universal.mapper.SearchableCityMapper;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class SearchableCityBiz extends BaseBiz<SearchableCityMapper, SearchableCity> {
public void insertSearchableCities(ArrayList<SearchableCity> searchableCities) {
mapper.insertSearchableCities(searchableCities);
}
}
package com.xxfc.platform.universal.mapper;
import com.xxfc.platform.universal.entity.LicensePlateType;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.ArrayList;
public interface LicensePlateTypeMapper extends Mapper<LicensePlateType> {
void insertLicensePlateType(@Param("licensePlateTypes") ArrayList<LicensePlateType> licensePlateTypes);
}
package com.xxfc.platform.universal.mapper;
import com.xxfc.platform.universal.entity.SearchableCity;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.ArrayList;
public interface SearchableCityMapper extends Mapper<SearchableCity> {
void insertSearchableCities(@Param(value = "searchableCities") ArrayList<SearchableCity> searchableCities);
}
package com.xxfc.platform.universal.service; package com.xxfc.platform.universal.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.xxfc.platform.universal.entity.searchableCity; import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xxfc.platform.universal.biz.LicensePlateTypeBiz;
import com.xxfc.platform.universal.biz.SearchableCityBiz;
import com.xxfc.platform.universal.entity.LicensePlateType;
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.commons.lang3.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -25,6 +26,9 @@ import java.util.regex.Pattern; ...@@ -25,6 +26,9 @@ import java.util.regex.Pattern;
@Service @Service
public class TrafficViolationsService { public class TrafficViolationsService {
@Autowired
private LicensePlateTypeBiz licensePlateTypeBiz;
@Value("${ALIYUN.CODE}") @Value("${ALIYUN.CODE}")
private String CODE; private String CODE;
@Value("${RETURN.TYPE}") @Value("${RETURN.TYPE}")
...@@ -50,29 +54,29 @@ public class TrafficViolationsService { ...@@ -50,29 +54,29 @@ public class TrafficViolationsService {
/** /**
* 支持城市 * 支持查询的城市
*
* @return * @return
* @throws Exception type 返回参数类型 * @throws Exception
*/ */
// @Scheduled(cron = "0 0 0 * * ?")
@Scheduled(cron = "0 0 0 * * ?")
public String getCity() throws Exception { 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);
HttpEntity entity = httpResponse.getEntity(); HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity); // String result = EntityUtils.toString(entity);
JSONObject.parseObject(result, searchableCity.class); // ArrayList<SearchableCity> searchableCities = JSONObject.parseObject(result, ArrayList.class);
// searchableCities.forEach(searchableCity ->searchableCity.setCreateDate(new Date()) );
// searchableCityBiz.insertSearchableCities(searchableCities);
return unicodeToString(EntityUtils.toString(entity)); return unicodeToString(EntityUtils.toString(entity));
} }
/** /**s
* 违章车辆查询 * 违章车辆查询
*
* @param trafficViolations * @param trafficViolations
* @return * @return
*/ */
...@@ -97,25 +101,26 @@ public class TrafficViolationsService { ...@@ -97,25 +101,26 @@ public class TrafficViolationsService {
* *
*/ */
public String getLicensePlateType() throws Exception { public void getLicensePlateType() throws Exception {
String result = searchaLicensePlateType();
Map<String, String> headers = new HashMap<String, String>();
headers.put(AUTHORIZATION, "APPCODE " + CODE);
HashMap<String, String> querys = new HashMap<>();
HttpResponse httpResponse = CertifHttpUtils.doGet(GET_LICENSE_PLATE_TYPE_HOST,
GET_LICENSE_PLATE_TYPE_PATH,
GET_LICENSE_PLATE_TYPE_METHOD,
headers,
querys
);
HttpEntity entity = httpResponse.getEntity();
return unicodeToString(EntityUtils.toString(entity)); if (StringUtils.isBlank(result)) {
throw new BaseException("错误! 查询不到车辆类型");
}
Map<String,Object> resultMap = JSONObject.parseObject(result, Map.class);
Integer status = (Integer) resultMap.get("status");
Map<String,String> licensePlateTypeMap = (Map<String, String>) resultMap.get("result");
if (status!=200||licensePlateTypeMap==null) {
throw new BaseException("错误! 查询不到车辆类型");
}
ArrayList<LicensePlateType> licensePlateTypes=new ArrayList<>();
for (Map.Entry<String, String> licensePlateTypeEntry : licensePlateTypeMap.entrySet()) {
licensePlateTypes.add(new LicensePlateType(licensePlateTypeEntry.getKey(),licensePlateTypeEntry.getValue(),new Date()));
}
licensePlateTypeBiz.insertLicensePlateType(licensePlateTypes);
} }
/** /**
* Unicode转汉字字符串 * Unicode转汉字字符串
* @param str * @param str
...@@ -141,7 +146,23 @@ public class TrafficViolationsService { ...@@ -141,7 +146,23 @@ public class TrafficViolationsService {
} }
/**
* 调用接口获取车辆车型和代码
* @return
* @throws Exception
*/
public String searchaLicensePlateType() throws Exception {
Map<String, String> headers = new HashMap<String, String>();
headers.put(AUTHORIZATION, "APPCODE " + CODE);
HashMap<String, String> querys = new HashMap<>();
HttpResponse httpResponse = CertifHttpUtils.doGet(GET_LICENSE_PLATE_TYPE_HOST,
GET_LICENSE_PLATE_TYPE_PATH,
GET_LICENSE_PLATE_TYPE_METHOD,
headers,
querys
);
HttpEntity entity = httpResponse.getEntity();
return unicodeToString(EntityUtils.toString(entity));
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.universal.mapper.LicensePlateTypeMapper">
<insert id="insertLicensePlateType" parameterType="List" >
insert into license_plate_type (code,type,create_date,update_date) values
<foreach collection="licensePlateTypes" item="lpt" index="index" separator=",">
(#{lpt.code},#{lpt.createDate},#{lpt.updateDate})
</foreach>
</insert>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.universal.mapper.SearchableCityMapper">
<insert id="insertSearchableCities" parameterType="List" >
</insert>
</mapper>
\ No newline at end of file
...@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -31,4 +32,38 @@ public class TimeTest { ...@@ -31,4 +32,38 @@ public class TimeTest {
DateTime startDay =DateTime.parse("2019-06-04", DEFAULT_DATE_TIME_FORMATTER); DateTime startDay =DateTime.parse("2019-06-04", DEFAULT_DATE_TIME_FORMATTER);
System.out.println("test"); System.out.println("test");
} }
@Test
public void testStream() throws Exception {
ArrayList<Student> students = new ArrayList<>();
students.add(new Student("张1","11"));
students.add(new Student("张2","12"));
students.add(new Student("张3","13"));
students.add(new Student("张4","14"));
students.add(new Student("张5","15"));
int i=0;
students.forEach(student -> student.setCode(1));
students.forEach(System.out::println);
}
}
@Data
class Student implements Serializable {
private String name;
private String age;
private int code;
public Student(String name, String age, int code) {
this.name=name;
this.age=age;
this.code=code;
}
public Student(String name, String age) {
this.name=name;
this.age=age;
}
} }
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