package com.ruoyi.web.controller.api;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.common.config.FileUploadConfig;
|
import com.ruoyi.common.core.controller.FileController;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.system.model.*;
|
import com.ruoyi.system.query.StoryListQuery;
|
import com.ruoyi.system.query.WorkPresentationQuery;
|
import com.ruoyi.system.service.*;
|
import com.ruoyi.system.vo.ScreenUserVo;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.UUID;
|
|
/**
|
* 数据统计面板 前端控制器
|
*
|
* @author xiaochen
|
* @since 2025-12-23
|
*/
|
@RestController
|
@RequestMapping("/work-presentation")
|
@Api(tags = "工作展示")
|
@RequiredArgsConstructor(onConstructor_ = @Lazy)
|
public class WorkPresentationController {
|
|
@Autowired
|
private WorkPresentationService workPresentationService;
|
|
|
|
@Autowired
|
private FileUploadConfig fileUploadConfig;
|
|
@ApiOperation(value = "单文件上传", notes = "单文件上传,rename 默认不重命名")
|
@PostMapping(value = "upload", headers = "content-type=multipart/form-data")
|
public R<?> uploadImageMany(@RequestParam(value = "file") MultipartFile mf) throws IOException {
|
if (mf.isEmpty()) {
|
return R.fail("请传入文件!");
|
}
|
String TimeDir =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
// String realPath = fileUploadConfig.getLocation() + TimeDir;
|
String realPath = "F:\\file\\estate\\files";
|
File file = new File(realPath);
|
|
// 没有目录就创建
|
if (!file.exists()) {
|
file.mkdirs();
|
}
|
// 获取文件名称
|
String filename = mf.getOriginalFilename();
|
String originalFilename=filename;
|
// 获取文件后缀
|
String ext = filename.substring(filename.lastIndexOf("."), filename.length());
|
// 检查文件类型
|
if (!fileUploadConfig.getAllowExt().contains(ext)) {
|
return R.fail("上传文件格式不正确,仅支持" + fileUploadConfig.getAllowExt());
|
}
|
filename = UUID.randomUUID()+ ext;
|
File targetFile = new File(realPath, filename);//目标文件
|
|
// 获取文件的大小size
|
long size = mf.getSize();
|
System.out.println(size);
|
//开始从源文件拷贝到目标文件
|
//传图片一步到位
|
mf.transferTo(targetFile);
|
//拼接数据
|
// String imgstr = fileUploadConfig.getAccessPath() + TimeDir +"\\"+ filename;
|
filename = filename.substring(0, filename.lastIndexOf("."));
|
|
UserFile userFile = new UserFile();
|
userFile.setName(filename);
|
userFile.setContentType(mf.getContentType());
|
String s = ext.replaceAll("\\.", "");
|
userFile.setExtension(s);
|
userFile.setSize(size);
|
userFile.setOriginFileName(originalFilename);
|
userFile.setCreateTime(new Date());
|
userFile.setDeleted(false);
|
userFile.setUpdateTime(userFile.getCreateTime());
|
userFile.insert();
|
|
|
return R.ok(filename);
|
}
|
|
|
@ApiOperation(value = "获取工作展示列表",response = WorkPresentation.class)
|
@PostMapping("/getWorkPresentationList")
|
public R<Page<WorkPresentation>> getStoryList(@RequestBody WorkPresentationQuery query) {
|
Page<WorkPresentation> page = new Page<>(query.getPageNum(), query.getPageSize());
|
|
LambdaQueryWrapper<WorkPresentation> wrapper = new LambdaQueryWrapper<>();
|
wrapper.eq(WorkPresentation::getClientId,query.getClientId());
|
if(query.getState()!=null){
|
wrapper.eq(WorkPresentation::getState, query.getState());
|
}
|
if(query.getType()!=null){
|
wrapper.eq(WorkPresentation::getType, query.getType());
|
}
|
if(query.getTime()!=null && !query.getTime().isEmpty()){
|
String sTime = query.getTime().split(" - ")[0]+" 00:00:00";
|
String eTime = query.getTime().split(" - ")[1]+" 23:59:59";
|
wrapper.between(WorkPresentation::getCreateTime,sTime,eTime);
|
}
|
if(query.getContent()!=null && !query.getContent().isEmpty()){
|
wrapper.like(WorkPresentation::getTitle, query.getContent());
|
}
|
wrapper.orderByDesc(WorkPresentation::getCreateTime);
|
Page<WorkPresentation> accidentBriefPage = workPresentationService.page(page, wrapper);
|
return R.ok(accidentBriefPage);
|
}
|
|
|
@ApiOperation(value = "获取工作展示详情",response = WorkPresentation.class)
|
@GetMapping("/getWorkPresentationDetail/{id}")
|
public R<WorkPresentation> getStoryDetail(@PathVariable Integer id) {
|
WorkPresentation workPresentation = workPresentationService.getById(id);
|
return R.ok(workPresentation);
|
}
|
|
|
@ApiOperation(value = "添加工作展示",response = WorkPresentation.class)
|
@PostMapping("/addWorkPresentation")
|
public R<WorkPresentation> addWorkPresentation(@RequestBody WorkPresentation workPresentation) {
|
workPresentationService.save(workPresentation);
|
return R.ok(workPresentation);
|
}
|
|
|
@ApiOperation(value = "修改工作展示",response = WorkPresentation.class)
|
@PostMapping("/updateWorkPresentation")
|
public R<WorkPresentation> updateWorkPresentation(@RequestBody WorkPresentation workPresentation) {
|
workPresentationService.updateById(workPresentation);
|
return R.ok(workPresentation);
|
}
|
|
|
@ApiOperation(value = "删除工作展示",response = WorkPresentation.class)
|
@DeleteMapping("/deleteWorkPresentation/{id}")
|
public R<WorkPresentation> deleteWorkPresentation(@PathVariable Integer id ) {
|
workPresentationService.removeById(id);
|
return R.ok();
|
}
|
|
|
@ApiOperation(value = "操作工作展示",response = WorkPresentation.class)
|
@PostMapping("/operateWorkPresentation")
|
public R<WorkPresentation> operateWorkPresentation(@RequestParam Integer id) {
|
WorkPresentation workPresentation = workPresentationService.getById(id);
|
if(workPresentation.getState()==1){
|
workPresentation.setState(2);
|
}else{
|
workPresentation.setState(1);
|
}
|
workPresentationService.updateById(workPresentation);
|
return R.ok(workPresentation);
|
}
|
|
|
}
|