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

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

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