Commit 5c86761f authored by hezhen's avatar hezhen

Merge branch 'base-modify' of http://113.105.137.151:22280/youjj/cloud-platform into base-modify

parents b21d6db3 7c4b3d15
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) {
this.code=code;
this.type=type;
}
public LicensePlateType() {
}
}
......@@ -11,7 +11,7 @@ import javax.persistence.Id;
import java.util.Date;
@Data
public class searchableCity {
public class SearchableCity {
@Id
@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 org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
@Service
public class LicensePlateTypeBiz extends BaseBiz<LicensePlateTypeMapper, LicensePlateType> {
@Transactional
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);
}
}
......@@ -49,7 +49,7 @@ public class TrafficViolationsController {
@GetMapping("/LicensePlateType")
public ObjectRestResponse getLicensePlateType() {
try {
return ObjectRestResponse.succ(JSONObject.parse(tvService.getLicensePlateType()));
return ObjectRestResponse.succ(tvService.getLicensePlateType());
} catch (Exception e) {
e.printStackTrace();
return ObjectRestResponse.createDefaultFail();
......
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;
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.vo.TrafficViolations;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -25,6 +28,9 @@ import java.util.regex.Pattern;
@Service
public class TrafficViolationsService {
@Autowired
private LicensePlateTypeBiz licensePlateTypeBiz;
@Value("${ALIYUN.CODE}")
private String CODE;
@Value("${RETURN.TYPE}")
......@@ -50,29 +56,29 @@ public class TrafficViolationsService {
/**
* 支持城市
*
* 支持查询的城市
* @return
* @throws Exception type 返回参数类型
* @throws Exception
*/
@Scheduled(cron = "0 0 0 * * ?")
// @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);
Map<String, String> querys = new HashMap<String, String>();
querys.put(TYPE_NAME, TYPE);
HttpResponse httpResponse = CertifHttpUtils.doGet(CITY_HOST, CITY_PATH, CITY_METHOD, headers, querys);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
JSONObject.parseObject(result, searchableCity.class);
// String result = EntityUtils.toString(entity);
// ArrayList<SearchableCity> searchableCities = JSONObject.parseObject(result, ArrayList.class);
// searchableCities.forEach(searchableCity ->searchableCity.setCreateDate(new Date()) );
// searchableCityBiz.insertSearchableCities(searchableCities);
return unicodeToString(EntityUtils.toString(entity));
}
/**
/**s
* 违章车辆查询
*
* @param trafficViolations
* @return
*/
......@@ -90,32 +96,28 @@ public class TrafficViolationsService {
}
/**
* 查询车牌类型
*
* @return
* 放入bean中
* @throws Exception
*
*/
public String getLicensePlateType() 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));
public void saveLicensePlateType() throws Exception {
String result = searchaLicensePlateType();
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()));
}
licensePlateTypeBiz.insertLicensePlateType(licensePlateTypes);
}
/**
* Unicode转汉字字符串
* @param str
......@@ -141,7 +143,31 @@ 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));
}
public ArrayList<LicensePlateType> getLicensePlateType() {
List<LicensePlateType> licensePlateTypes = licensePlateTypeBiz.selectListAll();
if (CollectionUtils.isEmpty(licensePlateTypes)) {
}
return null;
}
}
<?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
......@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -31,4 +32,38 @@ public class TimeTest {
DateTime startDay =DateTime.parse("2019-06-04", DEFAULT_DATE_TIME_FORMATTER);
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