Browse Source

2.0.0 修改轮播图接口

feature/v.2.0.0
peihao 3 years ago
parent
commit
23592eeb28
  1. 29
      air/src/main/java/com/air/cityarea/controller/RotateImageController.java
  2. 4
      air/src/main/java/com/air/cityarea/entity/RotateImage.java
  3. 44
      air/src/main/java/com/air/utils/ExcelUtil.java

29
air/src/main/java/com/air/cityarea/controller/RotateImageController.java

@ -1,7 +1,10 @@
package com.air.cityarea.controller;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.air.cityarea.entity.RotateGroup;
import com.air.cityarea.service.RotateGroupService;
import com.air.cityarea.vo.RotateImageStatusVo;
import com.air.enums.RotateStatusEnum;
import com.air.utils.FileUtil;
@ -17,7 +20,12 @@ import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@ -34,6 +42,8 @@ public class RotateImageController {
private final RotateImageService rotateImageService;
private final RotateGroupService rotateGroupService;
private final FileUtil fileUtil;
/**
@ -50,10 +60,21 @@ public class RotateImageController {
.eq(image.getGroupId() != null,RotateImage::getGroupId,image.getGroupId())
.like(StrUtil.isNotEmpty(image.getImageName()),RotateImage::getImageName,image.getImageName())
.orderByDesc(RotateImage::getCreateDate));
rotateImagePage.getRecords().stream().forEach(e ->{
e.setImagePath(fileUtil.getUrlByInnerPath(e.getImagePath()));
e.setStatusName(RotateStatusEnum.getName(e.getStatusCd()));
});
List<RotateImage> records = rotateImagePage.getRecords();
if (CollectionUtil.isNotEmpty(records)){
List<Long> groupIds = records.stream().map(e -> e.getGroupId()).collect(Collectors.toList());
List<RotateGroup> rotateGroups = rotateGroupService.listByIds(groupIds);
Map<Long, String> map = new HashMap<>();
rotateGroups.stream().forEach(e ->{
map.put(e.getGroupId(),e.getGroupName());
});
records.stream().forEach(e ->{
e.setGroupName(map.get(e.getGroupId()));
e.setImagePath(fileUtil.getUrlByInnerPath(e.getImagePath()));
e.setStatusName(RotateStatusEnum.getName(e.getStatusCd()));
});
}
return R.ok(rotateImagePage);
}

4
air/src/main/java/com/air/cityarea/entity/RotateImage.java

@ -59,4 +59,8 @@ public class RotateImage extends Model<RotateImage> {
@TableField(exist = false)
@ApiModelProperty(value="状态名称(显示用)")
private String statusName;
@TableField(exist = false)
@ApiModelProperty(value="分组名称")
private String groupName;
}

44
air/src/main/java/com/air/utils/ExcelUtil.java

@ -5,6 +5,8 @@ import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.air.cityarea.entity.Dazutuan;
import com.air.cityarea.entity.Xiaozutuan;
import com.air.common.entity.ExcelConfig;
import com.cinderella.framework.common.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
@ -21,6 +23,7 @@ import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* excel表格工具类
@ -160,6 +163,47 @@ public class ExcelUtil {
return mapList.stream().map(e -> BeanUtil.mapToBean(e, clazz, true)).collect(Collectors.toList());
}
public static void main(String[] args) {
List<Dazutuan> dazutuans = new ArrayList<>();
for (int i=1;i<3;i++){
Dazutuan dazutuan = new Dazutuan();
dazutuan.setId(i);
dazutuan.setPos("shezhi"+i);
dazutuans.add(dazutuan);
}
List<Xiaozutuan> xiaozutuans = new ArrayList<>();
for (int i=1;i<3;i++){
Xiaozutuan xiaozutuan = new Xiaozutuan();
xiaozutuan.setId(i);
xiaozutuan.setPos("shezhiwoshuo"+i);
xiaozutuans.add(xiaozutuan);
}
List<Dazutuan> convert = convert(xiaozutuans,dazutuans);
convert.stream().forEach(e->{
System.out.println(e.getId());
System.out.println(e.getPos());
});
}
private static List<Dazutuan> convert(List<Xiaozutuan> xiaozutuans,List<Dazutuan> dazutuans){
List<Dazutuan> collect = xiaozutuans.stream().map(item -> getDazutuan(dazutuans, item)).collect(Collectors.toList());
return collect;
}
private static Dazutuan getDazutuan(List<Dazutuan> dazutuans,Xiaozutuan xiaozutuan){
Dazutuan dazutuan = dazutuans.stream().filter(item -> xiaozutuan.getId().equals(item.getId())).findFirst()
.map(e -> {
Dazutuan dazutuan1 = new Dazutuan();
dazutuan1.setId(e.getId());
dazutuan1.setPos(xiaozutuan.getPos());
return dazutuan1;
}).orElse(new Dazutuan());
return dazutuan;
}
/**
* 读取excel数据列模板配置
*

Loading…
Cancel
Save