fix:宝宝图片

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