76 lines
2.9 KiB
Java
76 lines
2.9 KiB
Java
package com.cdzy.activity.service.impl;
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.lang.UUID;
|
|
import com.cdzy.activity.component.ImageConfig;
|
|
import com.cdzy.activity.model.vo.ActivityVo;
|
|
import com.cdzy.activity.model.vo.BulletinVo;
|
|
import com.cdzy.activity.uitls.FileUtils;
|
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
|
import com.cdzy.activity.model.Bulletin;
|
|
import com.cdzy.activity.mapper.BulletinMapper;
|
|
import com.cdzy.activity.service.BulletinService;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* 服务层实现。
|
|
*
|
|
* @author attiya
|
|
* @since 2025-09-18
|
|
*/
|
|
@Service
|
|
public class BulletinServiceImpl extends ServiceImpl<BulletinMapper, Bulletin> implements BulletinService {
|
|
|
|
@Resource
|
|
private BulletinMapper bulletinMapper;
|
|
|
|
@Resource
|
|
private ImageConfig imageConfig;
|
|
|
|
@Override
|
|
public void saveBulletin(BulletinVo bulletin) throws IOException {
|
|
MultipartFile activityCover = bulletin.getBulletinCover();
|
|
String convert = null;
|
|
if (activityCover != null) {
|
|
String uuid = UUID.randomUUID().toString();
|
|
String fileExtension = FileUtils.getFileExtension(activityCover);
|
|
String destPath = imageConfig.getActivityUrl() + "/" + uuid + fileExtension;
|
|
FileUtils.copyMultipartFile(activityCover, destPath, true);
|
|
convert = uuid + fileExtension;
|
|
}
|
|
Bulletin entity = Bulletin.builder()
|
|
.bulletinCover(convert)
|
|
.bulletinTitle(bulletin.getBulletinTitle())
|
|
.bulletinDescription(bulletin.getBulletinDescription())
|
|
.build();
|
|
bulletinMapper.insert(entity);
|
|
}
|
|
|
|
@Override
|
|
public void updateBulletind(BulletinVo bulletin) throws IOException {
|
|
Bulletin entity = bulletinMapper.selectOneById(bulletin.getBulletinId());
|
|
if (entity != null) {
|
|
entity.setBulletinTitle(bulletin.getBulletinTitle());
|
|
MultipartFile activityCover = bulletin.getBulletinCover();
|
|
String convert = entity.getBulletinCover();
|
|
if (activityCover != null) {
|
|
String uuid = UUID.randomUUID().toString();
|
|
String fileExtension = FileUtils.getFileExtension(activityCover);
|
|
String destPath = imageConfig.getActivityUrl() + "/" + uuid + fileExtension;
|
|
FileUtils.copyMultipartFile(activityCover, destPath, true);
|
|
FileUtil.del(imageConfig.getActivityUrl() + "/" + convert);
|
|
convert = uuid + fileExtension;
|
|
}
|
|
entity.setBulletinCover(convert);
|
|
entity.setBulletinDescription(bulletin.getBulletinDescription());
|
|
bulletinMapper.update(entity);
|
|
} else {
|
|
throw new RuntimeException("该公告不存在");
|
|
}
|
|
}
|
|
}
|