fix: 轮播图补丁

This commit is contained in:
筱锋xiao_lfeng 2024-01-19 18:28:45 +08:00
parent e0b4e02acc
commit d505a43122
No known key found for this signature in database
GPG Key ID: F693AA12AABBFA87
4 changed files with 25 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import com.jsl.oa.utils.ResultUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -31,9 +32,9 @@ public class InfoController {
private final InfoService infoService; private final InfoService infoService;
@GetMapping("/info/header-image/get") @GetMapping("/info/header-image/get")
public BaseResponse infoGetHeaderImage() { public BaseResponse infoGetHeaderImage(@RequestParam(required = false) Integer id) {
log.info("请求接口[GET]: /info/header-image/get"); log.info("请求接口[GET]: /info/header-image/get");
return infoService.getHeaderImage(); return infoService.getHeaderImage(id);
} }
@PutMapping("/info/header-image/edit") @PutMapping("/info/header-image/edit")
@ -69,7 +70,7 @@ public class InfoController {
} }
@PutMapping("/info/header-image/edit-setting") @PutMapping("/info/header-image/edit-setting")
public BaseResponse infoEditSettingHeaderImage(@RequestBody @Validated CarouselVO carouselVO, @RequestParam Integer id, HttpServletRequest request, @NotNull BindingResult bindingResult) { public BaseResponse infoEditSettingHeaderImage(@RequestBody @Validated CarouselVO carouselVO, @RequestParam Integer id, HttpServletRequest πrequest, @NotNull BindingResult bindingResult) {
log.info("请求接口[PUT]: /info/header-image/edit-setting"); log.info("请求接口[PUT]: /info/header-image/edit-setting");
return null; return null;
} }

View File

@ -49,6 +49,11 @@ public class InfoDAO {
} }
} }
// 获取排序 // 获取排序
sortCarousel(getCarousel);
return getCarousel;
}
private void sortCarousel(CarouselDO getCarousel) {
for (int i = 0; i < getCarousel.getData().size(); i++) { for (int i = 0; i < getCarousel.getData().size(); i++) {
for (int j = 0; j < getCarousel.getData().size(); j++) { for (int j = 0; j < getCarousel.getData().size(); j++) {
if (getCarousel.getOrder().equals("desc")) { if (getCarousel.getOrder().equals("desc")) {
@ -62,7 +67,6 @@ public class InfoDAO {
} }
} }
} }
return getCarousel;
} }
/** /**
@ -74,6 +78,7 @@ public class InfoDAO {
* @return {@link Boolean} * @return {@link Boolean}
*/ */
public boolean setCarousel(CarouselDO carouselDO) { public boolean setCarousel(CarouselDO carouselDO) {
sortCarousel(carouselDO);
String setCarouselSql = gson.toJson(carouselDO); String setCarouselSql = gson.toJson(carouselDO);
return infoMapper.setCarousel(setCarouselSql); return infoMapper.setCarousel(setCarouselSql);
} }

View File

@ -45,7 +45,7 @@ public interface InfoService {
* *
* @return {@link BaseResponse} * @return {@link BaseResponse}
*/ */
BaseResponse getHeaderImage(); BaseResponse getHeaderImage(Integer id);
/** /**
* <h2>删除轮播图</h2> * <h2>删除轮播图</h2>

View File

@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
@Slf4j @Slf4j
@Service @Service
@ -67,7 +68,10 @@ public class InfoServiceImpl implements InfoService {
// 获取轮播图信息 // 获取轮播图信息
CarouselDO carouselDO = infoDAO.getCarousel(); CarouselDO carouselDO = infoDAO.getCarousel();
// 获取指定轮播图 // 获取指定轮播图
CarouselDO.DataDO carousel = carouselDO.getData().get(id); if (id > carouselDO.getData().size()) {
return ResultUtil.error(ErrorCode.ID_NOT_EXIST);
}
CarouselDO.DataDO carousel = carouselDO.getData().get(id - 1);
carousel.setDisplayOrder(carouselVO.getDisplayOrder()) carousel.setDisplayOrder(carouselVO.getDisplayOrder())
.setImage(carouselVO.getImage()) .setImage(carouselVO.getImage())
.setDescription(carouselVO.getDescription()) .setDescription(carouselVO.getDescription())
@ -84,8 +88,16 @@ public class InfoServiceImpl implements InfoService {
} }
@Override @Override
public BaseResponse getHeaderImage() { public BaseResponse getHeaderImage(Integer id) {
CarouselDO carouselDO = infoDAO.getCarousel(); CarouselDO carouselDO = infoDAO.getCarousel();
if (id != null) {
if (id > carouselDO.getData().size()) {
return ResultUtil.error(ErrorCode.ID_NOT_EXIST);
}
ArrayList<CarouselDO.DataDO> newCarouselDO = new ArrayList<>();
newCarouselDO.add(carouselDO.getData().get(id - 1));
carouselDO.setData(newCarouselDO);
}
return ResultUtil.success(carouselDO); return ResultUtil.success(carouselDO);
} }