fix:宝宝图片

上级 a130797f
此差异已折叠。
......@@ -40,20 +40,21 @@ public class PicInfoController {
return Result.ok(this.picInfoService.list());
}
/**
* 分页查询图片
*
* @return 所有数据
*/
@GetMapping("/page")
public Result selectAll(@RequestParam Integer page, @RequestParam Integer pageSize) {
public Result selectAll(@RequestParam Integer page, @RequestParam Integer pageSize
, @RequestParam Integer picType) {
Page<PicInfo> pageParm = new Page<>();
pageParm.setCurrent(page);
pageParm.setSize(pageSize);
QueryWrapper<PicInfo> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("id"); // 按照 id 字段降序排列
wrapper.eq("is_delete", 0); // 按照 id 字段降序排列
wrapper.orderByDesc("id");
wrapper.eq("is_delete", 0);
wrapper.eq("type", picType);
return Result.ok(this.picInfoService.page(pageParm, wrapper));
}
......@@ -99,8 +100,8 @@ public class PicInfoController {
* @return
*/
@PostMapping(value = "/insertByPath")
public Result insertByPath(@RequestParam String path) {
return Result.ok(this.picInfoService.insertByPath(path));
public Result insertByPath(@RequestParam String path, @RequestParam Integer type) {
return Result.ok(this.picInfoService.insertByPath(path, type));
}
......@@ -111,8 +112,8 @@ public class PicInfoController {
* @return
*/
@PostMapping(value = "/insertByBaiduUrl")
public Result insertByBaiduUrl(@RequestParam String url) {
return Result.ok(this.picInfoService.insertByBaiduUrl(url));
public Result insertByBaiduUrl(@RequestParam String url, @RequestParam Integer type) {
return Result.ok(this.picInfoService.insertByBaiduUrl(url, type));
}
......
......@@ -15,16 +15,18 @@ public interface PicInfoService extends IService<PicInfo> {
* 根据目录插入图片
*
* @param path
* @param type
* @return
*/
boolean insertByPath(String path);
boolean insertByPath(String path, Integer type);
/**
* 根据百度图片路径获取图片
*
* @param url
* @param type
* @return
*/
boolean insertByBaiduUrl(String url);
boolean insertByBaiduUrl(String url, Integer type);
}
......@@ -41,7 +41,7 @@ public class PicInfoServiceImpl extends ServiceImpl<PicInfoMapper, PicInfo> impl
private static final String PRE_FIX = "https://gitcode.net/qyj19920704/baby-images/-/raw/main/";
@Override
public boolean insertByPath(String path) {
public boolean insertByPath(String path, Integer type) {
Path directoryPath = Paths.get(path);
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directoryPath)) {
for (Path filePath : directoryStream) {
......@@ -49,7 +49,7 @@ public class PicInfoServiceImpl extends ServiceImpl<PicInfoMapper, PicInfo> impl
final String picNameOrigin = filePath.getFileName().toString();
String picPath = PRE_FIX + picNameOrigin;
final String picName = picNameOrigin.split(".")[0];
this.insertPic(picPath, picName);
this.insertPic(type, picPath, picName);
}
}
return true;
......@@ -65,7 +65,7 @@ public class PicInfoServiceImpl extends ServiceImpl<PicInfoMapper, PicInfo> impl
* @param picPath
* @param picName
*/
private void insertPic(String picPath, String picName) {
private void insertPic(Integer type, String picPath, String picName) {
QueryWrapper<PicInfo> wrapper = new QueryWrapper<>();
wrapper.eq("pic_url", picPath);
wrapper.eq("is_delete", 0);
......@@ -76,11 +76,12 @@ public class PicInfoServiceImpl extends ServiceImpl<PicInfoMapper, PicInfo> impl
PicInfo picInfo = new PicInfo();
picInfo.setPicName(picName);
picInfo.setPicUrl(picPath);
picInfo.setType(type);
picInfoMapper.insert(picInfo);
}
@Override
public boolean insertByBaiduUrl(String url) {
public boolean insertByBaiduUrl(String url, Integer type) {
HttpResponse response;
try {
response = HttpUtil.createGet(url).execute();
......@@ -96,7 +97,7 @@ public class PicInfoServiceImpl extends ServiceImpl<PicInfoMapper, PicInfo> impl
if (Objects.isNull(split) || split.length == 0) {
split = fromPageTitle.split(",");
}
this.insertPic(hoverURL, Objects.isNull(split) || split.length == 0 ? fromPageTitle : split[0]);
this.insertPic(type, hoverURL, Objects.isNull(split) || split.length == 0 ? fromPageTitle : split[0]);
}
}
return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册