|
|
@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.lang.reflect.Array; |
|
|
@ -50,11 +51,15 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public AjaxResult importData(MultipartFile file) throws IOException { |
|
|
|
public AjaxResult importData(String fileName,String fileUrl) throws IOException { |
|
|
|
List<DcSdhsEvent> importData = new ArrayList<>(); |
|
|
|
try { |
|
|
|
//本地路径
|
|
|
|
String newFileUrl = fileUrl.replace("/profile/upload",""); |
|
|
|
String filePath = RuoYiConfig.getUploadPath() + newFileUrl; |
|
|
|
|
|
|
|
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class); |
|
|
|
importData = util.importExcel(file.getInputStream()); |
|
|
|
importData = util.importExcel(new FileInputStream(filePath)); |
|
|
|
} catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
return AjaxResult.error("导入失败,请检查数据是否有误"); |
|
|
@ -126,9 +131,96 @@ public class DcSdhsEventServiceImpl implements IDcSdhsEventService { |
|
|
|
//不入数据库, 放入缓存
|
|
|
|
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT,eventList); |
|
|
|
|
|
|
|
Map<String,Object> fileInfo = new HashMap<>(); |
|
|
|
fileInfo.put("fileName",fileName); |
|
|
|
fileInfo.put("fileUrl",fileUrl); |
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
String updateTime = simpleDateFormat.format(new Date()); |
|
|
|
fileInfo.put("uploadTime",updateTime); |
|
|
|
|
|
|
|
redisCache.setCacheMapValue(RedisKeyConstants.SDHS_EVENT_FILE,updateTime,fileInfo); |
|
|
|
return AjaxResult.success("导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
/*public AjaxResult importData(MultipartFile file) throws IOException { |
|
|
|
List<DcSdhsEvent> importData = new ArrayList<>(); |
|
|
|
try { |
|
|
|
ExcelUtil<DcSdhsEvent> util = new ExcelUtil<DcSdhsEvent>(DcSdhsEvent.class); |
|
|
|
importData = util.importExcel(file.getInputStream()); |
|
|
|
} catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
return AjaxResult.error("导入失败,请检查数据是否有误"); |
|
|
|
} |
|
|
|
|
|
|
|
redisCache.deleteObject(RedisKeyConstants.SDHS_EVENT); |
|
|
|
|
|
|
|
List<DcSdhsEvent> eventList = new ArrayList<>(); |
|
|
|
if (importData != null && importData.size() > 0){ |
|
|
|
int id = 1; |
|
|
|
for (DcSdhsEvent dcSdhsEvent : importData) { |
|
|
|
|
|
|
|
//插入id备用
|
|
|
|
dcSdhsEvent.setId(id); |
|
|
|
|
|
|
|
//是否多车事故
|
|
|
|
String carNum = dcSdhsEvent.getCarNum(); |
|
|
|
if (StringUtils.isNotEmpty(carNum)){ |
|
|
|
List<Integer> numbers = extractNumbers(carNum); |
|
|
|
Integer carNumbers = 0; |
|
|
|
for (Integer number : numbers) { |
|
|
|
carNumbers += number; |
|
|
|
} |
|
|
|
|
|
|
|
if (carNumbers > 0){ |
|
|
|
dcSdhsEvent.setMultiVehicle("是"); |
|
|
|
} else { |
|
|
|
dcSdhsEvent.setMultiVehicle("否"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
dcSdhsEvent.setMultiVehicle("否"); |
|
|
|
} |
|
|
|
|
|
|
|
String stakeMark = dcSdhsEvent.getStakeMark(); |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(stakeMark) && !"无".equals(stakeMark) && !StakeMarkUtils.checkStakeMark(stakeMark)){ |
|
|
|
//尝试桩号补零
|
|
|
|
List<String> numbers = new ArrayList<>(); |
|
|
|
|
|
|
|
// 匹配大小桩号数字
|
|
|
|
Pattern pattern = Pattern.compile("\\d+"); |
|
|
|
Matcher matcher = pattern.matcher(stakeMark); |
|
|
|
while (matcher.find()) { |
|
|
|
numbers.add(matcher.group()); // 将匹配到的数字字符串添加到列表中
|
|
|
|
} |
|
|
|
List<String> formattedNumbers = new ArrayList<>(); |
|
|
|
for (String number : numbers) { |
|
|
|
while (number.length() < 3) { |
|
|
|
number = "0" + number; |
|
|
|
} |
|
|
|
formattedNumbers.add(number); |
|
|
|
} |
|
|
|
stakeMark = "K" + String.join("+",formattedNumbers); |
|
|
|
|
|
|
|
|
|
|
|
//如果还验证不通过 则此条信息作废
|
|
|
|
if (!StakeMarkUtils.checkStakeMark(stakeMark)){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
dcSdhsEvent.setStakeMark(stakeMark); |
|
|
|
} |
|
|
|
|
|
|
|
eventList.add(dcSdhsEvent); |
|
|
|
id++; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//不入数据库, 放入缓存
|
|
|
|
redisCache.setCacheList(RedisKeyConstants.SDHS_EVENT,eventList); |
|
|
|
|
|
|
|
return AjaxResult.success("导入成功"); |
|
|
|
}*/ |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 提取文字中的数字 |
|
|
|
* |
|
|
|