Commit 0cf880f4 authored by hanfeng's avatar hanfeng

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

parent ca1e4608
...@@ -10,6 +10,7 @@ import javax.persistence.Column; ...@@ -10,6 +10,7 @@ import javax.persistence.Column;
import javax.persistence.Id; import javax.persistence.Id;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.Objects;
@Data @Data
public class LicensePlateType implements Serializable { public class LicensePlateType implements Serializable {
...@@ -55,4 +56,18 @@ public class LicensePlateType implements Serializable { ...@@ -55,4 +56,18 @@ public class LicensePlateType implements Serializable {
public LicensePlateType() { public LicensePlateType() {
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LicensePlateType that = (LicensePlateType) o;
return code.equals(that.code) &&
type.equals(that.type);
}
@Override
public int hashCode() {
return Objects.hash(code, type);
}
} }
...@@ -72,6 +72,10 @@ ...@@ -72,6 +72,10 @@
<version>2.0-SNAPSHOT</version> <version>2.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.xxfc.platform.universal.biz; package com.xxfc.platform.universal.biz;
import com.github.wxiaoqi.security.common.biz.BaseBiz; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xxfc.platform.universal.entity.LicensePlateType; import com.xxfc.platform.universal.entity.LicensePlateType;
import com.xxfc.platform.universal.entity.SearchableCity;
import com.xxfc.platform.universal.mapper.LicensePlateTypeMapper; import com.xxfc.platform.universal.mapper.LicensePlateTypeMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;
import java.util.ArrayList; import java.sql.SQLDataException;
import java.sql.SQLException;
import java.util.List;
@Service @Service
public class LicensePlateTypeBiz extends BaseBiz<LicensePlateTypeMapper, LicensePlateType> { public class LicensePlateTypeBiz extends BaseBiz<LicensePlateTypeMapper, LicensePlateType> {
@Transactional @Transactional
public void insertLicensePlateType(ArrayList<LicensePlateType> licensePlateTypes) { public void insertLicensePlateType(List<LicensePlateType> licensePlateTypes) {
mapper.insertLicensePlateType(licensePlateTypes); mapper.insertLicensePlateType(licensePlateTypes);
} }
@Transactional
public void updateLicensePlateType(List<LicensePlateType> licensePlateTypes) throws SQLException {
// List<LicensePlateType> saveLicensePlateTypes = mapper.selectAll();
// HashSet<LicensePlateType> judgeSet = new HashSet<>();
// judgeSet.addAll(saveLicensePlateTypes);
// for (LicensePlateType licensePlateType : licensePlateTypes) {
//
// if (judgeSet.add(licensePlateType)) {
//
// mapper.updateByExample()
// }
// }
for (LicensePlateType licensePlateType : licensePlateTypes) {
Example exa = Example.builder(LicensePlateType.class)
.where(
WeekendSqls.<LicensePlateType>custom()
.andEqualTo(LicensePlateType::getCode,licensePlateType.getCode())
).build();
int flag = mapper.updateByExample(licensePlateType,exa);
if (flag==0) {
insertSelective(licensePlateType);
}
if (flag>1) {
throw new SQLException("修改错误,同时修改多条数据");
}
}
}
} }
...@@ -4,8 +4,9 @@ import com.xxfc.platform.universal.entity.LicensePlateType; ...@@ -4,8 +4,9 @@ import com.xxfc.platform.universal.entity.LicensePlateType;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper; import tk.mybatis.mapper.common.Mapper;
import java.util.ArrayList;
import java.util.List;
public interface LicensePlateTypeMapper extends Mapper<LicensePlateType> { public interface LicensePlateTypeMapper extends Mapper<LicensePlateType> {
void insertLicensePlateType(@Param("licensePlateTypes") ArrayList<LicensePlateType> licensePlateTypes); void insertLicensePlateType(@Param("licensePlateTypes") List<LicensePlateType> licensePlateTypes);
} }
...@@ -3,7 +3,6 @@ package com.xxfc.platform.universal.service; ...@@ -3,7 +3,6 @@ package com.xxfc.platform.universal.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.exception.BaseException; import com.github.wxiaoqi.security.common.exception.BaseException;
import com.xxfc.platform.universal.biz.LicensePlateTypeBiz; 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.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;
...@@ -15,6 +14,7 @@ import org.apache.http.util.EntityUtils; ...@@ -15,6 +14,7 @@ import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
...@@ -31,6 +31,9 @@ public class TrafficViolationsService { ...@@ -31,6 +31,9 @@ public class TrafficViolationsService {
@Autowired @Autowired
private LicensePlateTypeBiz licensePlateTypeBiz; private LicensePlateTypeBiz licensePlateTypeBiz;
@Autowired
private TaskExecutor taskExecutor;
@Value("${ALIYUN.CODE}") @Value("${ALIYUN.CODE}")
private String CODE; private String CODE;
@Value("${RETURN.TYPE}") @Value("${RETURN.TYPE}")
...@@ -60,7 +63,6 @@ public class TrafficViolationsService { ...@@ -60,7 +63,6 @@ public class TrafficViolationsService {
* @return * @return
* @throws Exception * @throws Exception
*/ */
// @Scheduled(cron = "0 0 0 * * ?")
public String getCity() throws Exception { public String getCity() throws Exception {
Map<String, String> headers = new HashMap< Map<String, String> headers = new HashMap<
String, String>(); String, String>();
...@@ -98,8 +100,9 @@ public class TrafficViolationsService { ...@@ -98,8 +100,9 @@ public class TrafficViolationsService {
/** /**
* 放入bean中 * 放入bean中
* @throws Exception * @throws Exception
* @return
*/ */
public void saveLicensePlateType() throws Exception { public ArrayList<LicensePlateType> saveLicensePlateType() throws Exception {
String result = searchaLicensePlateType(); String result = searchaLicensePlateType();
if (StringUtils.isBlank(result)) { if (StringUtils.isBlank(result)) {
throw new BaseException("错误! 查询不到车辆类型"); throw new BaseException("错误! 查询不到车辆类型");
...@@ -114,7 +117,10 @@ public class TrafficViolationsService { ...@@ -114,7 +117,10 @@ public class TrafficViolationsService {
for (Map.Entry<String, String> licensePlateTypeEntry : licensePlateTypeMap.entrySet()) { for (Map.Entry<String, String> licensePlateTypeEntry : licensePlateTypeMap.entrySet()) {
licensePlateTypes.add(new LicensePlateType(licensePlateTypeEntry.getKey(),licensePlateTypeEntry.getValue())); licensePlateTypes.add(new LicensePlateType(licensePlateTypeEntry.getKey(),licensePlateTypeEntry.getValue()));
} }
licensePlateTypeBiz.insertLicensePlateType(licensePlateTypes);
return licensePlateTypes;
} }
...@@ -144,7 +150,7 @@ public class TrafficViolationsService { ...@@ -144,7 +150,7 @@ public class TrafficViolationsService {
/** /**
* 调用接口获取车辆车和代码 * 调用接口获取车辆车和代码
* @return * @return
* @throws Exception * @throws Exception
*/ */
...@@ -163,11 +169,37 @@ public class TrafficViolationsService { ...@@ -163,11 +169,37 @@ public class TrafficViolationsService {
return unicodeToString(EntityUtils.toString(entity)); return unicodeToString(EntityUtils.toString(entity));
} }
public ArrayList<LicensePlateType> getLicensePlateType() { /**
* 查询对应的车牌和车牌代码
* @return
* @throws Exception
*/
public List<LicensePlateType> getLicensePlateType() throws Exception {
List<LicensePlateType> licensePlateTypes = licensePlateTypeBiz.selectListAll(); List<LicensePlateType> licensePlateTypes = licensePlateTypeBiz.selectListAll();
if (CollectionUtils.isEmpty(licensePlateTypes)) { if (CollectionUtils.isEmpty(licensePlateTypes)) {
licensePlateTypes = saveLicensePlateType();
List<LicensePlateType> finalLicensePlateTypes = licensePlateTypes;
taskExecutor.execute(new Runnable() {
@Override
public void run() {
insertLicensePlateType(finalLicensePlateTypes);
}
});
} }
return null; return licensePlateTypes;
} }
@Scheduled(cron = "0 0 0 0/3 * *")
private void updateLicensePlateType(){
List<LicensePlateType> licensePlateTypes = licensePlateTypeBiz.selectListAll();
licensePlateTypeBiz.updateLicensePlateType(licensePlateTypes);
}
private void insertLicensePlateType(List<LicensePlateType> finalLicensePlateTypes){
licensePlateTypeBiz.insertLicensePlateType(finalLicensePlateTypes);
}
} }
...@@ -135,9 +135,10 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> { ...@@ -135,9 +135,10 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> {
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
} }
@Cache(key = "vehical") // @Cache(key = "vehical")
public Vehicle get(String id){ public Vehicle get(String id){
return mapper.selectByPrimaryKey(id); Vehicle vehicle = mapper.selectByPrimaryKey(id);
return vehicle;
} }
/** /**
......
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