修改岗位发布和修改是上传附件
This commit is contained in:
@@ -54,5 +54,7 @@ public interface IFileService
|
||||
*/
|
||||
public int deleteFileByIds(Long[] ids);
|
||||
|
||||
AjaxResult upload(MultipartFile file, Long bussinessid);
|
||||
|
||||
AjaxResult uploadFile(MultipartFile file, Long bussinessid);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements IF
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult uploadFile(MultipartFile file, Long bussinessid) {
|
||||
public AjaxResult upload(MultipartFile file, Long bussinessid) {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("文件为空,请选择文件上传");
|
||||
}
|
||||
@@ -119,6 +119,45 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, File> implements IF
|
||||
return AjaxResult.error("文件上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加返回bussinessid的接口,新增时使用
|
||||
* @param file
|
||||
* @param bussinessid
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult uploadFile(MultipartFile file, Long bussinessid) {
|
||||
if (file.isEmpty()) {
|
||||
return AjaxResult.error("文件为空,请选择文件上传");
|
||||
}
|
||||
|
||||
try {
|
||||
// 创建上传目录
|
||||
java.io.File dir = new java.io.File(uploadDir);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
// 生成唯一的文件名
|
||||
String fileName = UUID.randomUUID().toString() + "_" + file.getOriginalFilename();
|
||||
Path filePath = Paths.get(uploadDir, fileName);
|
||||
|
||||
// 保存文件到服务器
|
||||
Files.copy(file.getInputStream(), filePath);
|
||||
|
||||
// 保存文件信息到数据库
|
||||
saveFileInfo(fileName, bussinessid);
|
||||
AjaxResult ajaxResult=AjaxResult.success();
|
||||
ajaxResult.put("filePath","http://39.98.44.136/file/"+fileName);
|
||||
ajaxResult.put("bussinessid",bussinessid);
|
||||
return ajaxResult;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error("文件上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
private void saveFileInfo(String fileName, Long bussinessid) {
|
||||
// 这里假设你已经有了一个FileService来处理数据库操作
|
||||
File file = new File();
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
@@ -275,12 +276,20 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
});
|
||||
thread.start();
|
||||
if(insert>0){
|
||||
job.getJobContactList().forEach(x->{
|
||||
//添加联系人
|
||||
List<JobContact> jobContactList = job.getJobContactList() != null ? job.getJobContactList() : Collections.emptyList();
|
||||
jobContactList.forEach(x->{
|
||||
JobContact jobContact=new JobContact();
|
||||
BeanUtils.copyProperties(x,jobContact);
|
||||
jobContact.setJobId(job.getJobId());
|
||||
jobContactMapper.insert(jobContact);
|
||||
});
|
||||
//添加附件
|
||||
List<File> filesList = job.getFilesList() != null ? job.getFilesList() : Collections.emptyList();
|
||||
List<Long> longs = filesList.stream().filter(Objects::nonNull).map(File::getBussinessid).collect(Collectors.toList());
|
||||
if(!longs.isEmpty()){
|
||||
fileMapper.updateBussinessids(longs,job.getJobId());
|
||||
}
|
||||
}
|
||||
return insert;
|
||||
}
|
||||
@@ -323,15 +332,28 @@ public class JobServiceImpl extends ServiceImpl<JobMapper,Job> implements IJobSe
|
||||
int i=jobMapper.updateById(job);
|
||||
//修改岗位联系人列表
|
||||
if(i>0){
|
||||
jobContactMapper.update(null,Wrappers.<JobContact>lambdaUpdate()
|
||||
LambdaUpdateWrapper<JobContact> updateWrapper = Wrappers.<JobContact>lambdaUpdate()
|
||||
.eq(JobContact::getJobId, job.getJobId())
|
||||
.set(JobContact::getDelFlag, Constants.Del_FLAG_DELETE));
|
||||
if(Objects.isNull(job.getJobContactList())){return i;}
|
||||
job.getJobContactList().forEach(x -> {
|
||||
JobContact jobContact = new JobContact();
|
||||
jobContact.setJobId(job.getJobId());
|
||||
jobContactMapper.insert(jobContact);
|
||||
});
|
||||
.set(JobContact::getDelFlag, Constants.Del_FLAG_DELETE);
|
||||
|
||||
JobContact emptyEntity = new JobContact();
|
||||
jobContactMapper.update(emptyEntity, updateWrapper);
|
||||
List<JobContact> jobContactList = job.getJobContactList() != null ? job.getJobContactList() : Collections.emptyList();
|
||||
List<JobContact> insertList = jobContactList.stream()
|
||||
.filter(Objects::nonNull).map(x -> {
|
||||
JobContact jobContact = new JobContact();
|
||||
jobContact.setJobId(job.getJobId());
|
||||
return jobContact;
|
||||
}).collect(Collectors.toList());
|
||||
if (!insertList.isEmpty()) {
|
||||
jobContactMapper.batchInsert(insertList);
|
||||
}
|
||||
//添加附件
|
||||
List<File> filesList = job.getFilesList() != null ? job.getFilesList() : Collections.emptyList();
|
||||
List<Long> longs = filesList.stream().filter(Objects::nonNull).filter(file -> Objects.isNull(file.getId())).map(File::getBussinessid).collect(Collectors.toList());
|
||||
if(!longs.isEmpty()){
|
||||
fileMapper.updateBussinessids(longs,job.getJobId());
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user