use of com.ch999.haha.admin.entity.Imgs in project haha by hahafreeasair666.
the class UserInfoApi method test.
@PostMapping("/test")
public Result<Imgs> test(MultipartFile file, HttpServletResponse httpResponse) {
// 设置ajax跨域可访问
httpResponse.addHeader("Access-Control-Allow-Origin", "*");
if (file == null) {
return Result.error("error", "请选择要上传的图片");
}
Imgs imgs = imgService.uploadImg(file);
if (imgs == null) {
return Result.error("error", "图片上传失败");
}
return Result.success(imgs);
}
use of com.ch999.haha.admin.entity.Imgs in project haha by hahafreeasair666.
the class UserComponent method updateUserAvatar.
public Boolean updateUserAvatar(Integer userId, MultipartFile file) {
Imgs imgs = imgService.uploadImg(file);
if (imgs == null) {
return false;
} else {
UserInfo userInfo = new UserInfo(userId);
userInfo.setPicPath(imgs.getImgUrl());
userInfoService.updateById(userInfo);
UserInfo userInfo1 = userInfoService.selectById(userId);
UserInfoBO one = userInfoBORepository.findOne(userId);
one.setUserInfo(userInfo1);
userInfoBORepository.save(one);
return true;
}
}
use of com.ch999.haha.admin.entity.Imgs in project haha by hahafreeasair666.
the class ImgServiceImpl method uploadImg.
@Override
public Imgs uploadImg(MultipartFile file) {
File file1 = null;
try {
if (file.getSize() >= 1024 * 100) {
// lock.lock();
log.info("图片压缩");
String str = IdWorker.get32UUID();
Thumbnails.of(file.getInputStream()).size(200, 200).toFile(str + ".jpg");
file1 = new File(str + ".jpg");
log.info("压缩完毕");
// lock.unlock();
}
} catch (Exception e) {
log.error("压缩图片异常");
}
Imgs imgs = new Imgs();
String s = HttpClientUtil.uploadFile(IMGSERVER, IMGUPLOAG_URL, file, file1);
file1.delete();
log.info("上传完毕,删除压缩图片");
ImageRes imageRes = JSON.parseObject(s, ImageRes.class);
String fid = imageRes.getFid();
String fileName = imageRes.getFileName();
Integer size = imageRes.getSize();
if (StringUtils.isBlank(fid) || size == null || size == 0) {
return null;
}
imgs.setImgName(fileName);
imgs.setImgUrl("http://" + imageRes.getFileUrl().replace("localhost", "120.79.160.214"));
imgs.setIsdel(0);
imgsService.insert(imgs);
return imgs;
}
use of com.ch999.haha.admin.entity.Imgs in project haha by hahafreeasair666.
the class NewsServiceImpl method getNewsById.
@Override
public NewsDetailVO getNewsById(Integer id, Integer userId) {
NewsDetailVO newsDetailVO = newsMapper.selectNewsDetail(id);
if (newsDetailVO != null) {
// 是否已赞
if (userId != null && newsDetailVO.getZan() > 0) {
CommentZanBO one = commentZanRepository.findOne(id.toString());
if (one != null && one.getZanUserList().stream().anyMatch(userId::equals)) {
newsDetailVO.setIsPraised(true);
} else {
newsDetailVO.setIsPraised(false);
}
} else {
newsDetailVO.setIsPraised(false);
}
// 是否能收藏
Wrapper<NewsCollections> wrapper = new EntityWrapper<>();
wrapper.eq("userid", userId).eq("newid", id);
if (newsCollectionsService.selectCount(wrapper) > 0) {
newsDetailVO.setIsCanCollection(false);
} else {
newsDetailVO.setIsCanCollection(true);
}
if (StringUtils.isNotBlank(newsDetailVO.getPic())) {
String[] split = newsDetailVO.getPic().split(",");
List<String> imgMap = new ArrayList<>();
List<Imgs> imgs = imgsService.selectBatchIds(Arrays.asList(split));
imgs.forEach(li -> imgMap.add(li.getImgUrl()));
newsDetailVO.setPicMap(imgMap);
}
// 是否能收养
Wrapper<Adoption> wrapper1 = new EntityWrapper<>();
wrapper1.eq("adoptionid", newsDetailVO.getId()).eq("isadoption", 0);
if (CollectionUtils.isNotEmpty(adoptionService.selectList(wrapper1))) {
newsDetailVO.setIsCanAdoption(true);
} else {
newsDetailVO.setIsCanAdoption(false);
}
// 组装父公告id
if (newsDetailVO.getParentId() != null) {
News news = this.selectById(newsDetailVO.getParentId());
Map<String, Object> map = new HashMap<>();
map.put("id", news.getId());
map.put("title", news.getTitle());
newsDetailVO.setParentNews(map);
}
// 组装反馈公告id
List<News> news = this.selectList(new EntityWrapper<News>().eq("parentid", id).orderBy("createtime", false));
if (CollectionUtils.isNotEmpty(news)) {
Map<String, Object> map = new HashMap<>();
map.put("id", news.get(0).getId());
map.put("title", news.get(0).getTitle());
newsDetailVO.setFeedBackNews(map);
}
}
return newsDetailVO;
}
Aggregations