|
|
|
@ -1,20 +1,31 @@
|
|
|
|
|
package com.bs.ct.controller;
|
|
|
|
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import com.bs.cm.domain.CmAttach;
|
|
|
|
|
import com.bs.cm.service.ICmAttachService;
|
|
|
|
|
import com.bs.common.config.BsConfig;
|
|
|
|
|
import com.bs.common.core.domain.entity.SysDept;
|
|
|
|
|
import com.bs.common.core.domain.model.LoginUser;
|
|
|
|
|
import com.bs.common.utils.file.FileUploadUtils;
|
|
|
|
|
import com.bs.common.utils.file.FileUtils;
|
|
|
|
|
import com.bs.ct.domain.CtTaskFeedback;
|
|
|
|
|
import com.bs.ct.domain.*;
|
|
|
|
|
import com.bs.ct.service.*;
|
|
|
|
|
import com.bs.ct.utils.OperateImageUtils;
|
|
|
|
|
import com.bs.ct.utils.UUIDUtils;
|
|
|
|
|
import com.bs.framework.config.ServerConfig;
|
|
|
|
|
import com.bs.system.service.ISysDeptService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
@ -33,8 +44,6 @@ import com.bs.common.enums.BusinessType;
|
|
|
|
|
import com.bs.common.utils.poi.ExcelUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
|
|
import com.bs.ct.domain.CtGalleryImages;
|
|
|
|
|
import com.bs.ct.service.ICtGalleryImagesService;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
@ -49,12 +58,28 @@ import javax.annotation.Resource;
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/gallery/images")
|
|
|
|
|
public class CtGalleryImagesController extends BaseController {
|
|
|
|
|
@Value("${bs.profile}")
|
|
|
|
|
private String profile;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtGalleryImagesService ctGalleryImagesService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ServerConfig serverConfig;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ICmAttachService cmAttachService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtTaskTagService ctTaskTagService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtGalleryImagesTagService ctGalleryImagesTagService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtTagService ctTagService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDeptService deptService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtTaskBranchService ctTaskBranchService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtTaskInfoService ctTaskInfoService;
|
|
|
|
|
@Resource
|
|
|
|
|
private ICtImagesFeedbackRefService ctImagesFeedbackRefService;
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询图库图片列表
|
|
|
|
|
*/
|
|
|
|
@ -71,6 +96,9 @@ public class CtGalleryImagesController extends BaseController {
|
|
|
|
|
|
|
|
|
|
private void setFile(List<CtGalleryImages> list) {
|
|
|
|
|
for (CtGalleryImages ctGalleryImages : list) {
|
|
|
|
|
List<CtGalleryImagesTag> galleryImagesTags = ctGalleryImagesTagService.list(new LambdaQueryWrapper<CtGalleryImagesTag>()
|
|
|
|
|
.eq(CtGalleryImagesTag::getImageId, ctGalleryImages.getId()));
|
|
|
|
|
ctGalleryImages.setImagesTags(galleryImagesTags);
|
|
|
|
|
List<CmAttach> cmAttachList = cmAttachService.list(new LambdaQueryWrapper<CmAttach>().eq(CmAttach::getFileId,ctGalleryImages.getFileId()));
|
|
|
|
|
ctGalleryImages.setFile(cmAttachList);
|
|
|
|
|
}
|
|
|
|
@ -84,16 +112,104 @@ public class CtGalleryImagesController extends BaseController {
|
|
|
|
|
public AjaxResult list(CtGalleryImages ctGalleryImages) {
|
|
|
|
|
LambdaQueryWrapper<CtGalleryImages> queryWrapper = new LambdaQueryWrapper();
|
|
|
|
|
condition(queryWrapper,ctGalleryImages);
|
|
|
|
|
if (null != ctGalleryImages.getFeedbackId()) {
|
|
|
|
|
List<CtImagesFeedbackRef> ctImagesFeedbackRefs = ctImagesFeedbackRefService.list(new LambdaQueryWrapper<CtImagesFeedbackRef>()
|
|
|
|
|
.eq(CtImagesFeedbackRef::getFeedbackId, ctGalleryImages.getFeedbackId()));
|
|
|
|
|
List<Long> imageIds = ctImagesFeedbackRefs.stream()
|
|
|
|
|
.map(CtImagesFeedbackRef::getImageId)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (null != imageIds && imageIds.size() > 0) {
|
|
|
|
|
List<CtGalleryImages> galleryImages = ctGalleryImagesService.list(new LambdaQueryWrapper<CtGalleryImages>()
|
|
|
|
|
.in(CtGalleryImages::getId, imageIds));
|
|
|
|
|
return success(galleryImages);
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<CtGalleryImages> list = ctGalleryImagesService.list(queryWrapper);
|
|
|
|
|
return success(list);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 生成图片
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("生成图片")
|
|
|
|
|
@Log(title = "生成图片", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/generateImage")
|
|
|
|
|
public AjaxResult generateImage(@RequestBody CtGalleryImages ctGalleryImages) {
|
|
|
|
|
List<Long> imagesIds = ctGalleryImages.getIds();
|
|
|
|
|
String imageType = ctGalleryImages.getImageType(); // 假设 CtGalleryImages 有一个 imageType 字段用于指定生成图片的类型
|
|
|
|
|
List<CtGalleryImages> list = ctGalleryImagesService.list(new LambdaQueryWrapper<CtGalleryImages>()
|
|
|
|
|
.in(CtGalleryImages::getId, imagesIds));
|
|
|
|
|
BufferedImage[] imgs = new BufferedImage[list.size()];
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (CtGalleryImages galleryImages : list) {
|
|
|
|
|
String attachUrl = galleryImages.getImagePath().replace("/profile", "");
|
|
|
|
|
String filePath = profile + attachUrl;
|
|
|
|
|
try {
|
|
|
|
|
imgs[index++] = OperateImageUtils.getBufferedImage(filePath);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return AjaxResult.error("读取图片失败: " + filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BufferedImage destImg = null;
|
|
|
|
|
String outputFileName = null;
|
|
|
|
|
try {
|
|
|
|
|
switch (imageType) {
|
|
|
|
|
case "nineGrid":
|
|
|
|
|
if (imgs.length >= 9) {
|
|
|
|
|
destImg = OperateImageUtils.mergeImageToGrid(3, 3, imgs);
|
|
|
|
|
outputFileName = UUIDUtils.generatorUUID() + "nineGrid.jpg";
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("生成九宫格图片需要至少9张图片");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "fourGrid":
|
|
|
|
|
if (imgs.length >= 4) {
|
|
|
|
|
BufferedImage[] fourImgs = new BufferedImage[4];
|
|
|
|
|
System.arraycopy(imgs, 0, fourImgs, 0, 4);
|
|
|
|
|
destImg = OperateImageUtils.mergeImageToGrid(2, 2, fourImgs);
|
|
|
|
|
outputFileName = UUIDUtils.generatorUUID() + "fourGrid.jpg";
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("生成四宫格图片需要至少4张图片");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "horizontalMerge":
|
|
|
|
|
if (imgs.length >= 2) {
|
|
|
|
|
destImg = OperateImageUtils.mergeImage(true, imgs);
|
|
|
|
|
outputFileName = UUIDUtils.generatorUUID() + "horizontalMerge.jpg";
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("水平合并需要至少2张图片");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "verticalMerge":
|
|
|
|
|
if (imgs.length >= 2) {
|
|
|
|
|
destImg = OperateImageUtils.mergeImage(false, imgs);
|
|
|
|
|
outputFileName = UUIDUtils.generatorUUID() + "verticalMerge.jpg";
|
|
|
|
|
} else {
|
|
|
|
|
return AjaxResult.error("垂直合并需要至少2张图片");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return AjaxResult.error("不支持的图片类型: " + imageType);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (destImg != null) {
|
|
|
|
|
OperateImageUtils.saveImage(destImg, profile , outputFileName, "jpg");
|
|
|
|
|
return AjaxResult.success("图片生成成功");
|
|
|
|
|
}
|
|
|
|
|
return AjaxResult.error("图片生成失败");
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 通用上传请求(单个)
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/upload")
|
|
|
|
|
public AjaxResult uploadFile(MultipartFile file, String fileId, Long cataId, String imageTitle, Date photoTime,Date uploadTime,
|
|
|
|
|
String isOpen,String keyWords,String remarks
|
|
|
|
|
public AjaxResult uploadFile(MultipartFile file, String fileId, Long cataId, String imageTitle, Date photoTime, Date uploadTime,
|
|
|
|
|
String isOpen, String keyWords, String remarks, Long tagId, ArrayList<Long> ctTags, Long feedbackId
|
|
|
|
|
) throws Exception
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -130,11 +246,41 @@ public class CtGalleryImagesController extends BaseController {
|
|
|
|
|
Long id = cmAttach.getId();
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
ajax.put("cmAttach", cmAttach);
|
|
|
|
|
CtTaskTag taskTag = null;
|
|
|
|
|
if (null != tagId) {
|
|
|
|
|
taskTag = ctTaskTagService.getById(tagId);
|
|
|
|
|
ctGalleryImages.setCataId(taskTag.getSaveDir());
|
|
|
|
|
}
|
|
|
|
|
ctGalleryImages.setImageName(originalFilename);
|
|
|
|
|
ctGalleryImages.setImagePath(fileName);
|
|
|
|
|
ctGalleryImages.setImageSize(BigDecimal.valueOf(file.getSize()));
|
|
|
|
|
ctGalleryImages.setFileId(newId);
|
|
|
|
|
boolean saveImage = ctGalleryImagesService.save(ctGalleryImages);
|
|
|
|
|
if (saveImage) {
|
|
|
|
|
ajax.put("imageId",ctGalleryImages.getId());
|
|
|
|
|
if (null != taskTag) {
|
|
|
|
|
CtGalleryImagesTag ctGalleryImagesTag = new CtGalleryImagesTag();
|
|
|
|
|
ctGalleryImagesTag.setImageId(ctGalleryImages.getId());
|
|
|
|
|
ctGalleryImagesTag.setTagType(taskTag.getTagType());
|
|
|
|
|
ctGalleryImagesTag.setTagName(taskTag.getTagName());
|
|
|
|
|
ctGalleryImagesTagService.save(ctGalleryImagesTag);
|
|
|
|
|
}
|
|
|
|
|
if (null != ctTags) {
|
|
|
|
|
for (Long ctTagId : ctTags) {
|
|
|
|
|
CtTag ctTag = ctTagService.getById(ctTagId);
|
|
|
|
|
CtGalleryImagesTag ctGalleryImagesTag = new CtGalleryImagesTag();
|
|
|
|
|
ctGalleryImagesTag.setImageId(ctGalleryImages.getId());
|
|
|
|
|
ctGalleryImagesTag.setTagType(ctTag.getTagType());
|
|
|
|
|
ctGalleryImagesTag.setTagName(ctTag.getTagName());
|
|
|
|
|
ctGalleryImagesTag.setIsPhoto(ctTag.getIsPhoto());
|
|
|
|
|
ctGalleryImagesTag.setTagDesc(ctTag.getTagDesc());
|
|
|
|
|
ctGalleryImagesTag.setPhotoNum(ctTag.getPhotoNum());
|
|
|
|
|
ctGalleryImagesTag.setSaveDir(ctTag.getSaveDir());
|
|
|
|
|
ctGalleryImagesTag.setFileId(ctTag.getFileId());
|
|
|
|
|
ctGalleryImagesTagService.save(ctGalleryImagesTag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
@ -145,6 +291,91 @@ public class CtGalleryImagesController extends BaseController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改图库图片
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("添加图片标签")
|
|
|
|
|
@Log(title = "添加图片标签", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/saveByTag")
|
|
|
|
|
public AjaxResult saveByTag(@RequestBody CtGalleryImages ctGalleryImages) {
|
|
|
|
|
ctGalleryImages.getTaskTagId();
|
|
|
|
|
CtTaskTag ctTaskTag = ctTaskTagService.getById(ctGalleryImages.getTaskTagId());
|
|
|
|
|
List<Long> ids = ctGalleryImages.getIds();
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
CtGalleryImagesTag ctGalleryImagesTag = new CtGalleryImagesTag();
|
|
|
|
|
ctGalleryImagesTag.setImageId(id);
|
|
|
|
|
ctGalleryImagesTag.setTagType(ctTaskTag.getTagType());
|
|
|
|
|
ctGalleryImagesTag.setTagName(ctTaskTag.getTagName());
|
|
|
|
|
List<CtGalleryImagesTag> ctGalleryImagesTags = ctGalleryImagesTagService.list(new LambdaQueryWrapper<CtGalleryImagesTag>()
|
|
|
|
|
.eq(CtGalleryImagesTag::getImageId, id)
|
|
|
|
|
.eq(CtGalleryImagesTag::getTagType, ctTaskTag.getTagType())
|
|
|
|
|
.eq(CtGalleryImagesTag::getTagName, ctTaskTag.getTagName()));
|
|
|
|
|
if (null == ctGalleryImagesTags || ctGalleryImagesTags.size() == 0) {
|
|
|
|
|
ctGalleryImagesTagService.save(ctGalleryImagesTag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return toAjax(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改图库图片
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation("生成任务")
|
|
|
|
|
@Log(title = "生成任务", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/generateTasks")
|
|
|
|
|
public AjaxResult generateTasks(@RequestBody CtGalleryImages ctGalleryImages) {
|
|
|
|
|
List<Long> imagesIds = ctGalleryImages.getIds();
|
|
|
|
|
List<CtGalleryImagesTag> list = ctGalleryImagesTagService.list(new LambdaQueryWrapper<CtGalleryImagesTag>()
|
|
|
|
|
.in(CtGalleryImagesTag::getImageId, imagesIds));
|
|
|
|
|
CtTaskInfo ctTaskInfo = new CtTaskInfo();
|
|
|
|
|
Long newId = System.currentTimeMillis() + new Random().nextInt(1000);
|
|
|
|
|
ctTaskInfo.setId(newId);
|
|
|
|
|
List<CtTaskBranch> branchList = ctTaskInfo.getBranchList();
|
|
|
|
|
for (CtTaskBranch sdTaskOtherBranch : branchList) {
|
|
|
|
|
sdTaskOtherBranch.setTaskId(ctTaskInfo.getId());
|
|
|
|
|
sdTaskOtherBranch.setType("机构");
|
|
|
|
|
ctTaskBranchService.saveOrUpdate(sdTaskOtherBranch);
|
|
|
|
|
}
|
|
|
|
|
//设置发起单位与部门
|
|
|
|
|
LoginUser loginUser = getLoginUser();
|
|
|
|
|
Long deptId = loginUser.getDeptId();
|
|
|
|
|
if (null != deptId) {
|
|
|
|
|
ctTaskInfo.setDeptId(deptId);
|
|
|
|
|
SysDept sysDept = deptService.selectDeptById(deptId);
|
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
|
SysDept parentDept = deptService.selectDeptById(parentId);
|
|
|
|
|
if (null != parentDept) {
|
|
|
|
|
ctTaskInfo.setBranchCode(String.valueOf(parentDept.getDeptId()));
|
|
|
|
|
ctTaskInfo.setBranchName(parentDept.getDeptName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ("1".equals(ctTaskInfo.getStatus())) {
|
|
|
|
|
ctTaskInfo.setTaskDate(new Date());
|
|
|
|
|
}
|
|
|
|
|
boolean save = ctTaskInfoService.save(ctTaskInfo);
|
|
|
|
|
if (save) {
|
|
|
|
|
List<CtTaskTag> tasgs = ctTaskInfo.getTags();
|
|
|
|
|
if (null != tasgs && tasgs.size() > 0) {
|
|
|
|
|
if (null != list && list.size() > 0) {
|
|
|
|
|
for (CtGalleryImagesTag image : list) {
|
|
|
|
|
CtTaskTag taskTag = new CtTaskTag();
|
|
|
|
|
taskTag.setTaskId(ctTaskInfo.getId());
|
|
|
|
|
taskTag.setTagName(image.getTagName());
|
|
|
|
|
taskTag.setTagType(image.getTagType());
|
|
|
|
|
taskTag.setIsPhoto(image.getIsPhoto());
|
|
|
|
|
taskTag.setTagDesc(image.getTagDesc());
|
|
|
|
|
taskTag.setPhotoNum(image.getPhotoNum());
|
|
|
|
|
taskTag.setSaveDir(image.getSaveDir());
|
|
|
|
|
taskTag.setFileId(image.getFileId());
|
|
|
|
|
ctTaskTagService.save(taskTag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return success(ctTaskInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出图库图片列表
|
|
|
|
|