提交 e680437a authored 作者: xc's avatar xc

[设置] 修复了StaticSetting 字段中使用了保留字的BUG

上级 cebe9061
...@@ -70,4 +70,10 @@ public class ExcelController { ...@@ -70,4 +70,10 @@ public class ExcelController {
return excelData.findPath(); return excelData.findPath();
} }
@ApiOperation("查询进度百分比")
@PostMapping("/precent")
public ResponseEntity findPrecent(){
return excelData.findPrecen();
}
} }
...@@ -50,6 +50,7 @@ public class ExcelData { ...@@ -50,6 +50,7 @@ public class ExcelData {
@Autowired @Autowired
private ExcelConfigDao excelConfigDao; private ExcelConfigDao excelConfigDao;
private String path; private String path;
private double percent;
private String successPath = System.getProperty("user.dir") + "/successFile/"; private String successPath = System.getProperty("user.dir") + "/successFile/";
private String errorPath = System.getProperty("user.dir") + "/errorFile/"; private String errorPath = System.getProperty("user.dir") + "/errorFile/";
private String tmpPath = System.getProperty("user.dir") + "/tmp/"; private String tmpPath = System.getProperty("user.dir") + "/tmp/";
...@@ -95,6 +96,7 @@ public class ExcelData { ...@@ -95,6 +96,7 @@ public class ExcelData {
String successFileNameList = ""; String successFileNameList = "";
String errorFileNameList = ""; String errorFileNameList = "";
String errorReason = ""; String errorReason = "";
int total = dataFiles.length;
for (File dataFile : dataFiles){ for (File dataFile : dataFiles){
List<Map<String, Object>> mapList = new ArrayList<>(); List<Map<String, Object>> mapList = new ArrayList<>();
//取模板,如果有模板文件传过来就解析模板文件并保存,否则就读本地模板 //取模板,如果有模板文件传过来就解析模板文件并保存,否则就读本地模板
...@@ -156,16 +158,18 @@ public class ExcelData { ...@@ -156,16 +158,18 @@ public class ExcelData {
} }
} }
int re = modelService.putValueByEntityNameList(mapList); int re = modelService.putValueByEntityNameList(mapList);
if (re == 0){ if (re == 0){
successFileNameList = successFileNameList + "[" + fileName + "]"; successFileNameList = successFileNameList + "[" + fileName + "]";
dataFile.renameTo(new File(successPath + fileName)); dataFile.renameTo(new File(successPath + fileName));
}else { }else {
errorFileNameList = errorFileNameList + "[" + fileName + "]"; errorFileNameList = errorFileNameList + "[" + fileName + "]";
errorReason = "不是excel文件或保存失败"; errorReason = "不是excel文件或保存失败";
dataFile.renameTo(new File(errorPath + fileName)); dataFile.renameTo(new File(errorPath + fileName));
} }
total = total -1;
} }
percent = total/dataFiles.length * 1.0;
if (!"".equals(errorFileNameList)){ if (!"".equals(errorFileNameList)){
excelLogService.save(new ExcelLog("导入失败", errorReason, errorFileNameList)); excelLogService.save(new ExcelLog("导入失败", errorReason, errorFileNameList));
String s = "没有文件"; String s = "没有文件";
...@@ -410,7 +414,13 @@ public class ExcelData { ...@@ -410,7 +414,13 @@ public class ExcelData {
public ResponseEntity savePath(String path){ public ResponseEntity savePath(String path){
try { try {
this.path = path; this.path = path;
excelConfigDao.saveAndFlush(new ExcelConfig(path)); List<ExcelConfig> excelConfigs = excelConfigDao.findAll();
ExcelConfig excelConfig = new ExcelConfig();
if (excelConfigs != null && excelConfigs.size() > 0){
excelConfig = excelConfigs.get(0);
}
excelConfig.setPath(path);
excelConfigDao.saveAndFlush(excelConfig);
return ResultUtil.success("","保存成功"); return ResultUtil.success("","保存成功");
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
...@@ -424,4 +434,9 @@ public class ExcelData { ...@@ -424,4 +434,9 @@ public class ExcelData {
} }
return ""; return "";
} }
public ResponseEntity findPrecen(){
return ResultUtil.success(percent,"保存成功");
}
} }
...@@ -25,10 +25,10 @@ public class StatisticsSetting { ...@@ -25,10 +25,10 @@ public class StatisticsSetting {
private Integer type; private Integer type;
@ApiModelProperty("序号") @ApiModelProperty("序号")
private Integer order; private Integer orderPos;
@ApiModelProperty("参数内容 json格式") @ApiModelProperty("参数内容 json格式")
@Column(columnDefinition = "text") @Lob
private String params; private String params;
} }
...@@ -8,8 +8,8 @@ import java.util.List; ...@@ -8,8 +8,8 @@ import java.util.List;
public interface StatisticsSettingRepository extends JpaRepository<StatisticsSetting,Integer> { public interface StatisticsSettingRepository extends JpaRepository<StatisticsSetting,Integer> {
List<StatisticsSetting> findAllByOrderGreaterThanEqual(Integer index); List<StatisticsSetting> findAllByOrderPosGreaterThanEqual(Integer index);
List<StatisticsSetting> findAllByOrderLessThanEqual(Integer index); List<StatisticsSetting> findAllByOrderPosLessThanEqual(Integer index);
} }
...@@ -43,7 +43,7 @@ public class StatisticsSettingService { ...@@ -43,7 +43,7 @@ public class StatisticsSettingService {
} }
public List<StatisticsSettingVo> findByLimit(Integer limit) { public List<StatisticsSettingVo> findByLimit(Integer limit) {
List<StatisticsSetting> result = statisticsSettingRepository.findAllByOrderLessThanEqual(limit); List<StatisticsSetting> result = statisticsSettingRepository.findAllByOrderPosLessThanEqual(limit);
return result.stream() return result.stream()
.map(this::statisticsSettingVo) .map(this::statisticsSettingVo)
.sorted(Comparator.comparingInt(StatisticsSettingVo::getOrder)) .sorted(Comparator.comparingInt(StatisticsSettingVo::getOrder))
...@@ -64,27 +64,27 @@ public class StatisticsSettingService { ...@@ -64,27 +64,27 @@ public class StatisticsSettingService {
public void deleteById(Integer id) { public void deleteById(Integer id) {
StatisticsSetting statisticsSetting = statisticsSettingRepository.findById(id).orElseThrow(() -> new RuntimeException("未找到该id的数据")); StatisticsSetting statisticsSetting = statisticsSettingRepository.findById(id).orElseThrow(() -> new RuntimeException("未找到该id的数据"));
Integer order = statisticsSetting.getOrder(); Integer order = statisticsSetting.getOrderPos();
statisticsSettingRepository.deleteById(id); statisticsSettingRepository.deleteById(id);
//矫正后排数据的序号 //矫正后排数据的序号
List<StatisticsSetting> otherStatisticsSettingList = statisticsSettingRepository.findAllByOrderGreaterThanEqual(order); List<StatisticsSetting> otherStatisticsSettingList = statisticsSettingRepository.findAllByOrderPosGreaterThanEqual(order);
for (StatisticsSetting setting : otherStatisticsSettingList) { for (StatisticsSetting setting : otherStatisticsSettingList) {
setting.setOrder(setting.getOrder() - 1); setting.setOrderPos(setting.getOrderPos() - 1);
statisticsSettingRepository.save(setting); statisticsSettingRepository.save(setting);
} }
} }
private void handleAndSave(StatisticsSetting statisticsSetting) { private void handleAndSave(StatisticsSetting statisticsSetting) {
Integer order = statisticsSetting.getOrder(); Integer order = statisticsSetting.getOrderPos();
long count = statisticsSettingRepository.count(); long count = statisticsSettingRepository.count();
if (Objects.isNull(order) || order > count + 1 || order < 0) { if (Objects.isNull(order) || order > count + 1 || order < 0) {
//如果检查到序号值非法 则强制将序号赋值为末尾序号 //如果检查到序号值非法 则强制将序号赋值为末尾序号
statisticsSetting.setOrder(Math.toIntExact(count + 1)); statisticsSetting.setOrderPos(Math.toIntExact(count + 1));
} else { } else {
//矫正后排数据的序号 //矫正后排数据的序号
List<StatisticsSetting> otherStatisticsSettingList = statisticsSettingRepository.findAllByOrderGreaterThanEqual(statisticsSetting.getOrder()); List<StatisticsSetting> otherStatisticsSettingList = statisticsSettingRepository.findAllByOrderPosGreaterThanEqual(statisticsSetting.getOrderPos());
for (StatisticsSetting setting : otherStatisticsSettingList) { for (StatisticsSetting setting : otherStatisticsSettingList) {
setting.setOrder(setting.getOrder() + 1); setting.setOrderPos(setting.getOrderPos() + 1);
statisticsSettingRepository.save(setting); statisticsSettingRepository.save(setting);
} }
} }
...@@ -120,7 +120,7 @@ public class StatisticsSettingService { ...@@ -120,7 +120,7 @@ public class StatisticsSettingService {
statisticsSetting.getId(), statisticsSetting.getId(),
statisticsSetting.getName(), statisticsSetting.getName(),
statisticsSetting.getType(), statisticsSetting.getType(),
statisticsSetting.getOrder(), statisticsSetting.getOrderPos(),
params params
); );
} }
......
spring: spring:
datasource: datasource:
username: root username: root
password: root password: Huang123+
url: jdbc:mysql://localhost:3306/data?useSSL=false&serverTimezone=GMT%2b8&characterEncoding=utf-8 url: jdbc:mysql://47.106.142.73:3306/dataTest?useSSL=false&serverTimezone=GMT%2b8&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
jpa: jpa:
show-sql: true show-sql: true
hibernate: hibernate:
ddl-auto: update ddl-auto: update
server: server:
port: 8801 port: 8801
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论