json字符串按值排序

dongdingding
杜函宇 1 year ago
parent aca60186e0
commit 5942c54cb5

@ -86,13 +86,13 @@ public class JMemorandumController extends BaseController {
/**
*
*
* @param idList
* @param id
* @return
*/
@ApiOperation(value = "删除数据")
@DeleteMapping
public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
return success(this.jMemorandumService.removeByIds(idList));
public AjaxResult delete(@RequestParam("id") Long id) {
return success(this.jMemorandumService.removeById(id));
}
}

@ -87,13 +87,13 @@ public class JProjectController extends BaseController {
/**
*
*
* @param idList
* @param id
* @return
*/
@ApiOperation(value = "删除项目")
@DeleteMapping
public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
return success(this.jProjectService.removeByIds(idList));
public AjaxResult delete(@RequestParam("id") Long id) {
return success(this.jProjectService.removeById(id));
}
/**
@ -114,12 +114,8 @@ public class JProjectController extends BaseController {
if(proList == null && proList.isEmpty()){
throw new ServiceException("项目导入数据不能为空");
}else {
if (!proList.isEmpty()) {
jProjectService.saveBatch(proList);
successMsg.append("导入成功");
} else {
successMsg.append("导入失败,文件为空");
}
jProjectService.saveBatch(proList);
successMsg.append("导入成功");
}
return AjaxResult.success(successMsg);
}

@ -310,7 +310,7 @@ public class ProjectExcelUtil<T> {
fieldsMap.put(column, objects);
}
}
if(fieldsMap.size() != 4){
if (fieldsMap.size() != 4) {
throw new ServiceException("请导入正确的项目数据");
}
for (int i = titleNum + 1; i <= rows; i++) {
@ -387,20 +387,34 @@ public class ProjectExcelUtil<T> {
}
cellMap.entrySet().removeIf(entry -> hasStr.contains(entry.getKey()));
StringBuilder str = new StringBuilder();
Map<String,String> sortHash = new HashMap<>();
str.append("{");
for (Map.Entry<String, Integer> entry : cellMap.entrySet()) {
String key1 = entry.getKey();
Object val1 = this.getCellValue(row, entry.getValue());
if (val1 == "" || val1 == null) {
val1 = null;
str.append('"').append(key1).append('"').append(":").append(val1).append(",");
}else {
str.append('"').append(key1).append('"').append(":").append('"').append(val1).append('"').append(",");
sortHash.put(key1, String.valueOf(val1));
}
// 自定义比较器按值排序
Comparator<Map.Entry<String, String>> customComparator = Comparator.comparingInt(entry -> entry.getValue().length());
Map<String, String> sortedMap = sortHash.entrySet().stream()
.sorted(customComparator)
.collect(Collectors.toMap(
Map.Entry::getKey,
Map.Entry::getValue,
(oldVal, newVal) -> oldVal,
LinkedHashMap::new
));
for (Map.Entry<String, String> entry : sortedMap.entrySet()) {
if (Objects.equals(entry.getValue(), "") || entry.getValue() == null) {
String nulls = null;
str.append('"').append(entry.getKey()).append('"').append(":").append(nulls).append(",");
} else {
str.append('"').append(entry.getKey()).append('"').append(":").append('"').append(entry.getValue()).append('"').append(",");
}
}
str.append("}");
String res = String.valueOf(str).replaceAll("\\s*|\r|\n|\t", "");
ReflectUtils.invokeSetter(entity, "otherJson", res.replaceAll(",(?!.*,)",""));
ReflectUtils.invokeSetter(entity, "otherJson", res.replaceAll(",(?!.*,)", ""));
list.add(entity);
}
}

Loading…
Cancel
Save