Commit d60be694 authored by 廖旭伟's avatar 廖旭伟

事项材料附件自动下载;材料加入公共库,公共库加入材料

parent 0160317c
This diff is collapsed.
......@@ -179,6 +179,20 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aspose.words</groupId>
<artifactId>aspose-words</artifactId>
<version>19.2</version>
<classifier>jdk16</classifier>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.27</version>
</dependency>
</dependencies>
......
......@@ -61,7 +61,7 @@ exec "$JAVACMD" $JAVA_OPTS \
-Dapp.port="$PORT" \
-Dbasedir="$BASEDIR" \
-Djava.io.tmpdir=$TEMP_PATH \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6513 \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6512 \
-jar $MAIN_CLASS \
> /dev/null &
......
package com.mortals.xhx.common.utils;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* 下载网络文件至本地
*
* @Author: haoyalei
* @CreateTime: 2021-06-04 10:10
* @Description: HttpDownload
*/
public class HttpDownloadUtil {
/**
* 从网络Url中下载文件
* @param urlStr
* @param fileName
* @param savePath
* @throws IOException
*/
public static void downLoadFromUrl(String urlStr,String fileName,String savePath) throws IOException{
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(5*1000);
//防止屏蔽程序抓取而返回403错误
// conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
// conn.setRequestProperty("lfwywxqyh_token",toekn);
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);
//文件保存位置
File saveDir = new File(savePath);
if(!saveDir.exists()){
saveDir.mkdir();
}
File file = new File(saveDir+File.separator+fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if(fos!=null){
fos.close();
}
if(inputStream!=null){
inputStream.close();
}
//System.out.println("info:"+url+" download success");
}
/**
* 从输入流中获取字节数组
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
public static void main(String[] args) throws IOException {
String url="http://www.sczwfw.gov.cn//materialibraryui/meterialibraryCatFile/openDownload/4226078996281143296/0";
HttpDownloadUtil.downLoadFromUrl(url,"中国税收居民证明材料.docx","D:\\mortals\\app\\data\\file\\fileupload");
System.out.println("下载完成");
}
}
package com.mortals.xhx.common.utils;
/**
* @author: zxfei
* @date: 2021/10/14 15:44
* @description:
**/
import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.util.DateUtils;
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
public class WordUtil {
private Configuration configure = null;
public Configuration getConfigure() {
return configure;
}
public void setConfigure(Configuration configure) {
this.configure = configure;
}
public WordUtil() {
configure = new Configuration();
configure.setDefaultEncoding("utf-8");
}
/**
* 根据word模板生成word文件
*
* @param dataMap : 数据
* @param outFilePath : 输出word文件地址
* @return
*/
public boolean createWord(Map<String, Object> dataMap, String inputFilePath, String outFilePath) {
boolean flag = false;
try {
// 指定路径方式(根据某个类的相对路径指定)
configure.setClassForTemplateLoading(this.getClass(), "/test");
// 以utf-8的编码读取ftl文件
Template template = configure.getTemplate(inputFilePath, "utf-8");
Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outFilePath)), "utf-8"),
10240);
template.process(dataMap, out);
out.close();
flag = true;
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
public static String convertWordToJPEG(String inputFile, String jpegPath) {
try {
log.info("word to jpg文件转换开始,inputFile:{},jepgPath:{}:{}", inputFile, jpegPath, DateUtils.getCurrStrDateTime());
// 转换开始前时间
long old = System.currentTimeMillis();
// 新建的PDF文件路径
File file = new File(jpegPath);
//FileOutputStream os = new FileOutputStream(file);
// 要转换的word文档的路径
Document doc = new Document(inputFile);
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
//doc.save(os, SaveFormat.JPEG);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
options.setPrettyFormat(true);
options.setUseAntiAliasing(true);
options.setUseHighQualityRendering(true);
int pageCount = doc.getPageCount();
List<BufferedImage> imageList = new ArrayList<BufferedImage>();
for (int i = 0; i < pageCount; i++) {
OutputStream output = new ByteArrayOutputStream();
options.setPageIndex(i);
doc.save(output, options);
ImageInputStream imageInputStream = ImageIO.createImageInputStream(parse(output));
imageList.add(ImageIO.read(imageInputStream));
}
BufferedImage mergeImage = mergeImage(false, imageList);
ImageIO.write(mergeImage, "jpg", file);
// 转换结束后时间
/* doc.save(jpegPath);*/
doc.cleanup();
long now = System.currentTimeMillis();
log.info("文件转换结束,共耗时:" + ((now - old) / 1000.0) + "秒");
return jpegPath;
} catch (Exception e) {
log.error("文件转换异常!", e);
throw new AppException(String.format("文件转换异常! %s", e.getMessage()));
}
}
public static Integer getPageByDoc(String inputFile) {
try {
//FileOutputStream os = new FileOutputStream(file);
// 要转换的word文档的路径
Document doc = new Document(inputFile);
return doc.getPageCount();
} catch (Exception e) {
log.error("获取doc异常!", e);
return 0;
}
}
public static void pdfToImages(String filePath, String jpegPath) {
log.info(String.format("pdf to images文件转换开始:%s", DateUtils.getCurrStrDateTime()));
// 转换开始前时间
long old = System.currentTimeMillis();
File file = new File(jpegPath);
List<BufferedImage> imageInfoList = new ArrayList<>();
try (PDDocument doc = PDDocument.load(new File(filePath))) {
PDFRenderer renderer = new PDFRenderer(doc);
int pageCount = doc.getNumberOfPages();
for (int i = 0; i < pageCount; i++) {
BufferedImage image = renderer.renderImage(i);
imageInfoList.add(image);
}
BufferedImage mergeImage = mergeImage(false, imageInfoList);
ImageIO.write(mergeImage, "png", file);
// 转换结束后时间
long now = System.currentTimeMillis();
//os.close();
log.info("文件转换结束,共耗时:" + ((now - old) / 1000.0) + "秒");
} catch (IOException e) {
log.error("生成预览图片异常:", e);
throw new AppException("生成预览图片异常");
}
}
/**
* 合并任数量的图片成一张图片
*
* @param isHorizontal true代表水平合并,fasle代表垂直合并
* @param imgs 待合并的图片数组
* @return
* @throws IOException
*/
public static BufferedImage mergeImage(boolean isHorizontal, List<BufferedImage> imgs) throws IOException {
// 生成新图片
BufferedImage destImage = null;
// 计算新图片的长和高
int allw = 0, allh = 0, allwMax = 0, allhMax = 0;
// 获取总长、总宽、最长、最宽
for (int i = 0; i < imgs.size(); i++) {
BufferedImage img = imgs.get(i);
allw += img.getWidth();
if (imgs.size() != i + 1) {
allh += img.getHeight() + 5;
} else {
allh += img.getHeight();
}
if (img.getWidth() > allwMax) {
allwMax = img.getWidth();
}
if (img.getHeight() > allhMax) {
allhMax = img.getHeight();
}
}
// 创建新图片
if (isHorizontal) {
destImage = new BufferedImage(allw, allhMax, BufferedImage.TYPE_INT_RGB);
} else {
destImage = new BufferedImage(allwMax, allh, BufferedImage.TYPE_INT_RGB);
}
Graphics2D g2 = (Graphics2D) destImage.getGraphics();
g2.setBackground(Color.LIGHT_GRAY);
g2.clearRect(0, 0, allw, allh);
g2.setPaint(Color.RED);
// 合并所有子图片到新图片
int wx = 0, wy = 0;
for (int i = 0; i < imgs.size(); i++) {
BufferedImage img = imgs.get(i);
int w1 = img.getWidth();
int h1 = img.getHeight();
// 从图片中读取RGB
int[] ImageArrayOne = new int[w1 * h1];
// 逐行扫描图像中各个像素的RGB到数组中
ImageArrayOne = img.getRGB(0, 0, w1, h1, ImageArrayOne, 0, w1);
if (isHorizontal) {
// 水平方向合并
// 设置上半部分或左半部分的RGB
destImage.setRGB(wx, 0, w1, h1, ImageArrayOne, 0, w1);
} else {
// 垂直方向合并
// 设置上半部分或左半部分的RGB
destImage.setRGB(0, wy, w1, h1, ImageArrayOne, 0, w1);
}
wx += w1;
wy += h1 + 5;
}
return destImage;
}
public static ByteArrayInputStream parse(OutputStream out) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos = (ByteArrayOutputStream) out;
ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
return swapStream;
}
public static void main(String[] args) {
String docPath = "E:\\pic\\doc\\2.docx";
String jpgPath = "E:\\pic\\doc\\2.jpg";
WordUtil.convertWordToJPEG(docPath, jpgPath);
/*
String pdfPath = "E:\\pic\\pdf\\1.pdf";
String jpgPath = "E:\\pic\\jpg\\1.jpg";
WordUtil.pdfToImages(pdfPath, jpgPath);
*/
}
}
package com.mortals.xhx.daemon.task;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.common.utils.HttpDownloadUtil;
import com.mortals.xhx.common.utils.WordUtil;
import com.mortals.xhx.module.matter.model.MatterDatumEntity;
import com.mortals.xhx.module.matter.model.MatterDatumFileEntity;
import com.mortals.xhx.module.matter.model.MatterDatumFileQuery;
import com.mortals.xhx.module.matter.model.MatterDatumQuery;
import com.mortals.xhx.module.matter.service.MatterDatumFileService;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
import com.mortals.xhx.module.site.model.SiteMatterQuery;
import com.mortals.xhx.module.site.service.SiteMatterService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
/**
* 事项材料附件本地转换
*/
@Slf4j
@Service("MatterDatumConvertTask")
public class MatterDatumConvertTaskImpl implements ITaskExcuteService {
@Autowired
private SiteMatterService siteMatterService;
@Autowired
private MatterDatumService matterDatumService;
@Autowired
private MatterDatumFileService matterDatumFileService;
@Value("${upload.path}")
private String filePath;
public static String word[] = {"doc", "dot", "wps", "wpt", "docx", "dotx", "docm", "dotm"};
public static String imgs[] = {"jpg", "png", "jpeg", "gif"};
public static String pdf[] = {"pdf"};
@Override
public void excuteTask(ITask task) throws AppException {
log.info("事项材料处理...");
SiteMatterQuery siteMatterQuery = new SiteMatterQuery();
siteMatterQuery.setIsConvert(0);
List<SiteMatterEntity> siteMatterEntities = siteMatterService.find(siteMatterQuery);
if(CollectionUtils.isNotEmpty(siteMatterEntities)){
List<Long> matterIds = new ArrayList<>();
for(SiteMatterEntity siteMatterEntity:siteMatterEntities){
matterIds.add(siteMatterEntity.getMatterId());
}
MatterDatumQuery matterDatumQuery = new MatterDatumQuery();
matterDatumQuery.setMatterIdList(matterIds);
List<MatterDatumEntity> matterDatumEntityList = matterDatumService.find(matterDatumQuery);
List<Long> convertIdList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(matterDatumEntityList)){
for(MatterDatumEntity datumEntity:matterDatumEntityList){
MatterDatumFileQuery fileQuery = new MatterDatumFileQuery();
fileQuery.setDatumId(datumEntity.getId());
List<MatterDatumFileEntity> datumFileEntityList = matterDatumFileService.find(fileQuery);
if(CollectionUtils.isNotEmpty(datumFileEntityList)){
String rootPath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/";
String prePath = "file/preview/";
String savePath = "file/uploadfile/";
for(MatterDatumFileEntity datumFileEntity:datumFileEntityList){
String fileName = datumFileEntity.getFileName();
String fileUrl = datumFileEntity.getFileUrl();
try {
HttpDownloadUtil.downLoadFromUrl(fileUrl,fileName,rootPath + savePath);
}catch (Exception e){
log.error("DatumId:"+datumFileEntity.getDatumId()+",文件下载失败...",e);
continue;
}
MatterDatumFileEntity update = new MatterDatumFileEntity();
update.setId(datumFileEntity.getId());
update.setLocalFileUrl(savePath+fileName);
String newName = genPreviewPath(rootPath, prePath, savePath+fileName);
update.setPreviewUrl(prePath+newName);
matterDatumFileService.update(update);
}
convertIdList.add(datumEntity.getMatterId());
}
}
}
if(convertIdList.size()>0){
SiteMatterQuery matterQuery = new SiteMatterQuery();
matterQuery.setMatterIdList(convertIdList);
List<SiteMatterEntity> matterEntities = siteMatterService.find(matterQuery);
for(SiteMatterEntity matterEntity:matterEntities){
SiteMatterEntity updateEntity = new SiteMatterEntity();
updateEntity.setId(matterEntity.getId());
updateEntity.setIsConvert(1);
siteMatterService.update(updateEntity);
}
}
}
}
@Override
public void stopTask(ITask task) throws AppException {
}
private String genPreviewPath(String rootPath, String prePath, String tempPath) {
//生成样表预览图片
String samplePath = rootPath + tempPath;
String filePath = rootPath + prePath;
File pathDir = new File(filePath);
if (!pathDir.exists()) {
pathDir.mkdirs();
}
String newName = RandomUtil.randomNumbers(12) + ".jpg";
String filePathAll = filePath + newName;
//判断文件类型是否为doc pdf jpg png 等
String extName = FileUtil.getSuffix(samplePath);
if (this.isExsitArry(extName, word)) {
WordUtil.convertWordToJPEG(samplePath, filePathAll);
} else if (this.isExsitArry(extName, pdf)) {
WordUtil.pdfToImages(samplePath, filePathAll);
} else if (this.isExsitArry(extName, imgs)) {
try {
com.mortals.framework.util.FileUtil.copyFile(samplePath, filePathAll);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
return newName;
}
public boolean isExsitArry(String chex, String arry[]) {
for (String ex : arry) {
if (chex.equalsIgnoreCase(ex)) {
return true;
}
}
return false;
}
}
package com.mortals.xhx.module.library.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
import java.util.List;
/**
* 材料公共库Dao
* 材料公共库 DAO接口
*
* @author zxfei
* @date 2023-03-01
*/
public interface PublicLibraryDao extends ICRUDDao<PublicLibraryEntity,Long>{
}
package com.mortals.xhx.module.library.dao.ibatis;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.library.dao.PublicLibraryDao;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import java.util.List;
/**
* 材料公共库DaoImpl DAO接口
*
* @author zxfei
* @date 2023-03-01
*/
@Repository("publicLibraryDao")
public class PublicLibraryDaoImpl extends BaseCRUDDaoMybatis<PublicLibraryEntity,Long> implements PublicLibraryDao {
}
package com.mortals.xhx.module.library.model;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.library.model.vo.PublicLibraryVo;
/**
* 材料公共库实体对象
*
* @author zxfei
* @date 2023-03-01
*/
public class PublicLibraryEntity extends PublicLibraryVo {
private static final long serialVersionUID = 1L;
/**
* 站点id
*/
private Long siteId;
/**
* 材料简称
*/
private String simpleName;
/**
* 材料全称
*/
private String fullName;
/**
* 文件地址
*/
private String fileUrl;
/**
* 文件预览地址
*/
private String previewUrl;
public PublicLibraryEntity(){}
/**
* 获取 站点id
* @return Long
*/
public Long getSiteId(){
return siteId;
}
/**
* 设置 站点id
* @param siteId
*/
public void setSiteId(Long siteId){
this.siteId = siteId;
}
/**
* 获取 材料简称
* @return String
*/
public String getSimpleName(){
return simpleName;
}
/**
* 设置 材料简称
* @param simpleName
*/
public void setSimpleName(String simpleName){
this.simpleName = simpleName;
}
/**
* 获取 材料全称
* @return String
*/
public String getFullName(){
return fullName;
}
/**
* 设置 材料全称
* @param fullName
*/
public void setFullName(String fullName){
this.fullName = fullName;
}
/**
* 获取 文件地址
* @return String
*/
public String getFileUrl(){
return fileUrl;
}
/**
* 设置 文件地址
* @param fileUrl
*/
public void setFileUrl(String fileUrl){
this.fileUrl = fileUrl;
}
/**
* 获取 文件预览地址
* @return String
*/
public String getPreviewUrl(){
return previewUrl;
}
/**
* 设置 文件预览地址
* @param previewUrl
*/
public void setPreviewUrl(String previewUrl){
this.previewUrl = previewUrl;
}
@Override
public int hashCode() {
return this.getId().hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (obj instanceof PublicLibraryEntity) {
PublicLibraryEntity tmp = (PublicLibraryEntity) obj;
if (this.getId() == tmp.getId()) {
return true;
}
}
return false;
}
public String toString(){
StringBuilder sb = new StringBuilder("");
sb.append(",siteId:").append(getSiteId());
sb.append(",simpleName:").append(getSimpleName());
sb.append(",fullName:").append(getFullName());
sb.append(",fileUrl:").append(getFileUrl());
sb.append(",previewUrl:").append(getPreviewUrl());
return sb.toString();
}
public void initAttrValue(){
this.siteId = null;
this.simpleName = "";
this.fullName = "";
this.fileUrl = "";
this.previewUrl = "";
}
}
\ No newline at end of file
package com.mortals.xhx.module.library.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
import java.util.ArrayList;
import java.util.List;
/**
* 材料公共库视图对象
*
* @author zxfei
* @date 2023-03-01
*/
public class PublicLibraryVo extends BaseEntityLong {
}
\ No newline at end of file
package com.mortals.xhx.module.library.service;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
/**
* PublicLibraryService
*
* 材料公共库 service接口
*
* @author zxfei
* @date 2023-03-01
*/
public interface PublicLibraryService extends ICRUDService<PublicLibraryEntity,Long>{
}
\ No newline at end of file
package com.mortals.xhx.module.library.service.impl;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.library.dao.PublicLibraryDao;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
import com.mortals.xhx.module.library.service.PublicLibraryService;
/**
* PublicLibraryService
* 材料公共库 service实现
*
* @author zxfei
* @date 2023-03-01
*/
@Service("publicLibraryService")
public class PublicLibraryServiceImpl extends AbstractCRUDServiceImpl<PublicLibraryDao, PublicLibraryEntity, Long> implements PublicLibraryService {
}
\ No newline at end of file
package com.mortals.xhx.module.library.web;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.library.model.PublicLibraryEntity;
import com.mortals.xhx.module.library.service.PublicLibraryService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 材料公共库
*
* @author zxfei
* @date 2023-03-01
*/
@RestController
@RequestMapping("public/library")
public class PublicLibraryController extends BaseCRUDJsonBodyMappingController<PublicLibraryService,PublicLibraryEntity,Long> {
@Autowired
private ParamService paramService;
public PublicLibraryController(){
super.setModuleDesc( "材料公共库");
}
@Override
protected void init(Map<String, Object> model, Context context) {
super.init(model, context);
}
}
\ No newline at end of file
......@@ -7,10 +7,10 @@ import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.matter.model.vo.MatterDatumFileVo;
/**
* 材料附件实体对象
* 材料附件业务实体对象
*
* @author zxfei
* @date 2022-11-16
* @date 2023-03-11
*/
public class MatterDatumFileEntity extends MatterDatumFileVo {
......@@ -37,17 +37,21 @@ public class MatterDatumFileEntity extends MatterDatumFileVo {
*/
private String fileUrl;
/**
* 附件本地下载地址
* 本地文件地址
*/
private String localFileUrl;
/**
* 附件类型 (示例样表.示例样表,空白表格.空白表格)
* 附件类型 (1.示例样表,2.空白表格)
*/
private String filetype;
/**
* 附件来源 (0.政务网,1.自定义)
*/
private Integer source;
/**
* 预览地址
*/
private String previewUrl;
......@@ -123,28 +127,28 @@ public class MatterDatumFileEntity extends MatterDatumFileVo {
this.fileUrl = fileUrl;
}
/**
* 获取 附件本地下载地址
* 获取 本地文件地址
* @return String
*/
public String getLocalFileUrl(){
return localFileUrl;
}
/**
* 设置 附件本地下载地址
* 设置 本地文件地址
* @param localFileUrl
*/
public void setLocalFileUrl(String localFileUrl){
this.localFileUrl = localFileUrl;
}
/**
* 获取 附件类型 (示例样表.示例样表,空白表格.空白表格)
* 获取 附件类型 (1.示例样表,2.空白表格)
* @return String
*/
public String getFiletype(){
return filetype;
}
/**
* 设置 附件类型 (示例样表.示例样表,空白表格.空白表格)
* 设置 附件类型 (1.示例样表,2.空白表格)
* @param filetype
*/
public void setFiletype(String filetype){
......@@ -164,6 +168,20 @@ public class MatterDatumFileEntity extends MatterDatumFileVo {
public void setSource(Integer source){
this.source = source;
}
/**
* 获取 预览地址
* @return String
*/
public String getPreviewUrl(){
return previewUrl;
}
/**
* 设置 预览地址
* @param previewUrl
*/
public void setPreviewUrl(String previewUrl){
this.previewUrl = previewUrl;
}
......@@ -194,6 +212,7 @@ public class MatterDatumFileEntity extends MatterDatumFileVo {
sb.append(",localFileUrl:").append(getLocalFileUrl());
sb.append(",filetype:").append(getFiletype());
sb.append(",source:").append(getSource());
sb.append(",previewUrl:").append(getPreviewUrl());
return sb.toString();
}
......@@ -211,8 +230,10 @@ public class MatterDatumFileEntity extends MatterDatumFileVo {
this.localFileUrl = "";
this.filetype = "示例样表";
this.filetype = "";
this.source = 0;
this.source = 1;
this.previewUrl = "";
}
}
\ No newline at end of file
package com.mortals.xhx.module.matter.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.matter.model.MatterDatumEntity;
/**
......@@ -11,4 +13,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumEntity;
*/
public interface MatterDatumService extends ICRUDService<MatterDatumEntity,Long>{
/**
* 添加材料到公共库
*
* @param datumIds
* @param siteId
* @param context
*/
Rest<String> addToLibrary(String datumIds, Long siteId, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.matter.service.impl;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.base.system.upload.service.UploadService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.matter.model.*;
import com.mortals.xhx.module.matter.service.MatterDatumFileService;
import com.mortals.xhx.module.matter.service.MatterService;
import com.mortals.xhx.module.site.model.*;
import com.mortals.xhx.module.site.service.SiteDatumLibraryService;
import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
......@@ -13,7 +19,11 @@ import com.mortals.xhx.module.matter.dao.MatterDatumDao;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* MatterDatumService
......@@ -31,6 +41,10 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
private MatterDatumFileService matterDatumFileService;
@Autowired
private UploadService uploadService;
@Autowired
private SiteDatumLibraryService siteDatumLibraryService;
@Autowired
private SiteService siteService;
@Override
......@@ -83,4 +97,63 @@ public class MatterDatumServiceImpl extends AbstractCRUDServiceImpl<MatterDatumD
}
@Override
public Rest<String> addToLibrary(String datumIds, Long siteId, Context context) {
if (ObjectUtils.isEmpty(siteId)) {
throw new AppException("请选择对应站点");
}
List<Long> datumIdList = Arrays.asList(datumIds.split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
MatterDatumQuery datumQuery = new MatterDatumQuery();
datumQuery.setIdList(datumIdList);
List<MatterDatumEntity> entities = this.find(datumQuery);
int success = 0;
int fail = 0;
List<SiteDatumLibraryEntity> addEntities = new ArrayList<>();
for (MatterDatumEntity datum : entities) {
SiteDatumLibraryEntity datumLibrary = updateOrSave(datum, siteId, context);
//SiteMatterEntity siteMatterEntity = updateOrSave(matterEntity, siteId, context);
if (!ObjectUtils.isEmpty(datumLibrary)) {
addEntities.add(datumLibrary);
success++;
} else {
fail++;
}
}
if (!ObjectUtils.isEmpty(addEntities)) {
siteDatumLibraryService.save(addEntities, context);
}
String msg = "当前加入材料已存在!";
if (datumIdList.size() == 1) {
if (success > 0) {
msg = "加入材料成功!";
}
} else if (datumIdList.size() > 1) {
if (success > 0 && fail == 0) {
msg = String.format("加入材料成功%d条!", success);
} else if (success > 0 && fail > 0) {
msg = String.format("加入材料成功%d条,重复加入材料%d条!", success, fail);
} else if (success == 0 && fail > 0) {
msg = String.format("重复加入材料%d条!", fail);
}
}
return Rest.ok(msg);
}
private SiteDatumLibraryEntity updateOrSave(MatterDatumEntity item, Long siteId, Context context) {
SiteDatumLibraryEntity siteDatumLibraryEntity = siteDatumLibraryService.selectOne(new SiteDatumLibraryQuery().siteId(siteId).datumId(item.getId()));
if (ObjectUtils.isEmpty(siteDatumLibraryEntity)) {
SiteEntity siteEntity = siteService.getCache(siteId.toString());
SiteDatumLibraryEntity datumLibraryEntity = BeanUtil.covert(item,SiteDatumLibraryEntity.class);
datumLibraryEntity.setDatumId(item.getId());
datumLibraryEntity.setSiteId(siteId);
datumLibraryEntity.setSiteName(siteEntity==null?"":siteEntity.getSiteName());
datumLibraryEntity.setCreateTime(new Date());
if(context!=null&&context.getUser()!=null) {
datumLibraryEntity.setCreateUserId(context.getUser().getId());
}
return datumLibraryEntity;
}
return null;
}
}
\ No newline at end of file
......@@ -259,9 +259,12 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter
siteMatterEntity.setMatterId(item.getId());
siteMatterEntity.setMatterCode(item.getMatterNo());
siteMatterEntity.setMatterName(item.getMatterName());
siteMatterEntity.setMatterCode(item.getTcode());
siteMatterEntity.setDeptCode(item.getDeptCode());
siteMatterEntity.setSource(item.getSource());
siteMatterEntity.setEventTypeShow(item.getEventTypeShow());
siteMatterEntity.setViewsCount(0l);
siteMatterEntity.setIsConvert(0);
siteMatterEntity.setDeptName(deptEntity == null ? "" : deptEntity.getName());
siteMatterEntity.setDeptId(deptEntity == null ? -1L : deptEntity.getId());
siteMatterEntity.setCreateUserId(context == null ? 1L : context.getUser() == null ? 1L : context.getUser().getId());
......
package com.mortals.xhx.module.matter.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
......@@ -11,9 +14,12 @@ import com.mortals.xhx.module.matter.model.MatterDatumFileQuery;
import com.mortals.xhx.module.matter.service.MatterDatumFileService;
import com.mortals.xhx.module.matter.service.MatterDatumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -59,4 +65,28 @@ public class MatterDatumController extends BaseCRUDJsonBodyMappingController<Mat
entity.setDatumFileList(matterDatumFileEntities);
return super.viewAfter(id, model, entity, context);
}
/**
* 添加事项到站点
*/
@PostMapping(value = "addToLibrary")
public String addToLibrary(@RequestBody Map<String, Object> map) {
JSONObject jsonObject = new JSONObject();
Map<String, Object> model = new HashMap<String, Object>();
String datumIds = (String) map.get("datumIds");
Long siteId = DataUtil.converStr2Long(map.get("siteId").toString(), 0L);
try {
Rest<String> rest = this.service.addToLibrary(datumIds, siteId, getContext());
jsonObject.put(KEY_RESULT_MSG, rest.getMsg());
jsonObject.put(KEY_RESULT_DATA, model);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
this.recordSysLog(this.request, rest.getMsg());
} catch (Exception e) {
log.error("获取异常", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
}
\ No newline at end of file
......@@ -8,8 +8,9 @@ import java.util.List;
* 站点事项 DAO接口
*
* @author zxfei
* @date 2022-01-12
* @date 2023-03-10
*/
public interface SiteMatterDao extends ICRUDDao<SiteMatterEntity,Long>{
......
......@@ -11,7 +11,7 @@ import java.util.List;
* 站点事项DaoImpl DAO接口
*
* @author zxfei
* @date 2022-01-12
* @date 2023-03-10
*/
@Repository("siteMatterDao")
public class SiteMatterDaoImpl extends BaseCRUDDaoMybatis<SiteMatterEntity,Long> implements SiteMatterDao {
......
package com.mortals.xhx.module.site.model;
import com.mortals.xhx.common.code.SourceEnum;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.site.model.vo.SiteMatterVo;
/**
* 站点事项实体对象
*
* @author zxfei
* @date 2022-11-16
* @date 2023-03-11
*/
public class SiteMatterEntity extends SiteMatterVo {
private static final long serialVersionUID = 1L;
/**
* 站点ID
* 站点id
*/
private Long siteId;
/**
......@@ -41,30 +45,38 @@ public class SiteMatterEntity extends SiteMatterVo {
*/
private String deptName;
/**
* 事项类型
* 部门编码
*/
private String eventTypeShow;
private String deptCode;
/**
* 事项来源
*/
private Integer source;
/**
* 部门编号
* 事项类型
*/
private String deptCode;
private String eventTypeShow;
/**
* 浏览次数
*/
private Long viewsCount;
/**
* 是否生成本地附件
*/
private Integer isConvert;
public SiteMatterEntity(){}
/**
* 获取 站点ID
* 获取 站点id
* @return Long
*/
public Long getSiteId(){
return siteId;
}
/**
* 设置 站点ID
* 设置 站点id
* @param siteId
*/
public void setSiteId(Long siteId){
......@@ -155,25 +167,24 @@ public class SiteMatterEntity extends SiteMatterVo {
this.deptName = deptName;
}
/**
* 获取 事项类型
* 获取 部门编码
* @return String
*/
public String getEventTypeShow(){
return eventTypeShow;
public String getDeptCode(){
return deptCode;
}
/**
* 设置 事项类型
* @param eventTypeShow
* 设置 部门编码
* @param deptCode
*/
public void setEventTypeShow(String eventTypeShow){
this.eventTypeShow = eventTypeShow;
public void setDeptCode(String deptCode){
this.deptCode = deptCode;
}
/**
* 获取 事项来源
* @return Integer
*/
public Integer getSource(){
return source;
}
/**
......@@ -184,18 +195,46 @@ public class SiteMatterEntity extends SiteMatterVo {
this.source = source;
}
/**
* 获取 部门编号
* 获取 事项类型
* @return String
*/
public String getDeptCode(){
return deptCode;
public String getEventTypeShow(){
return eventTypeShow;
}
/**
* 设置 部门编号
* @param deptCode
* 设置 事项类型
* @param eventTypeShow
*/
public void setDeptCode(String deptCode){
this.deptCode = deptCode;
public void setEventTypeShow(String eventTypeShow){
this.eventTypeShow = eventTypeShow;
}
/**
* 获取 浏览次数
* @return Long
*/
public Long getViewsCount(){
return viewsCount;
}
/**
* 设置 浏览次数
* @param viewsCount
*/
public void setViewsCount(Long viewsCount){
this.viewsCount = viewsCount;
}
/**
* 获取 是否生成本地附件
* @return Integer
*/
public Integer getIsConvert(){
return isConvert;
}
/**
* 设置 是否生成本地附件
* @param isConvert
*/
public void setIsConvert(Integer isConvert){
this.isConvert = isConvert;
}
......@@ -226,9 +265,11 @@ public class SiteMatterEntity extends SiteMatterVo {
sb.append(",matterCode:").append(getMatterCode());
sb.append(",deptId:").append(getDeptId());
sb.append(",deptName:").append(getDeptName());
sb.append(",eventTypeShow:").append(getEventTypeShow());
sb.append(",source:").append(getSource());
sb.append(",deptCode:").append(getDeptCode());
sb.append(",source:").append(getSource());
sb.append(",eventTypeShow:").append(getEventTypeShow());
sb.append(",viewsCount:").append(getViewsCount());
sb.append(",isConvert:").append(getIsConvert());
return sb.toString();
}
......@@ -248,10 +289,14 @@ public class SiteMatterEntity extends SiteMatterVo {
this.deptName = "";
this.deptCode = "";
this.source = null;
this.eventTypeShow = "";
this.source = 0;
this.viewsCount = 0L;
this.deptCode = "";
this.isConvert = 0;
}
}
\ No newline at end of file
package com.mortals.xhx.module.site.model.vo;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 站点事项视图对象
*
* @author zxfei
* @date 2022-01-12
* @date 2023-03-10
*/
@Data
public class SiteMatterVo extends BaseEntityLong {
/**
* 所属部门
*/
private String belongDept;
/**
* 窗口到现场次数
*/
private Integer windowToTheSceneNum;
/**
* 网办到现场次数
*/
private Integer onlineToTheSceneNum;
/**
* 区域编码
*/
private String areaCode;
/** 事项类型排除列表 */
private List <String> eventTypeShowNotList;
}
\ No newline at end of file
package com.mortals.xhx.module.site.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.site.dao.SiteMatterDao;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
/**
* SiteMatterService
* <p>
* 站点事项 service接口
*
* @author zxfei
* @date 2022-01-12
*/
public interface SiteMatterService extends ICRUDService<SiteMatterEntity, Long> {
SiteMatterDao getDao();
* SiteMatterService
*
* 站点事项 service接口
*
* @author zxfei
* @date 2023-03-10
*/
public interface SiteMatterService extends ICRUDService<SiteMatterEntity,Long>{
void deleteBysiteIdAndSource(Long siteId, Integer source, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.site.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.model.MatterQuery;
import com.mortals.xhx.module.matter.service.MatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.site.dao.SiteMatterDao;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
import com.mortals.xhx.module.site.service.SiteMatterService;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* SiteMatterService
* 站点事项 service实现
*
* @author zxfei
* @date 2022-01-12
*/
* SiteMatterService
* 站点事项 service实现
*
* @author zxfei
* @date 2023-03-10
*/
@Service("siteMatterService")
public class SiteMatterServiceImpl extends AbstractCRUDServiceImpl<SiteMatterDao, SiteMatterEntity, Long> implements SiteMatterService {
@Autowired
private MatterService matterService;
@Override
protected void findAfter(SiteMatterEntity params, PageInfo pageInfo, Context context, List<SiteMatterEntity> list) throws AppException {
// List<Long> matterIdlist = list.parallelStream().map(item -> item.getMatterId()).collect(Collectors.toList());
//Map<Long, MatterEntity> matterEntityMap = matterService.find(new MatterQuery().idList(matterIdlist)).parallelStream().collect(Collectors.toMap(x -> x.getId(), y -> y, (o, n) -> n));
list.forEach(item -> {
if (!ObjectUtils.isEmpty(item.getMatterId())) {
MatterEntity matterEntity = matterService.get(item.getMatterId());
if (!ObjectUtils.isEmpty(matterEntity)) {
item.setBelongDept(matterEntity.getBelongDept());
item.setWindowToTheSceneNum(matterEntity.getWindowToTheSceneNum());
item.setOnlineToTheSceneNum(matterEntity.getOnlineToTheSceneNum());
item.setDeptCode(matterEntity.getDeptCode());
item.setAreaCode(matterEntity.getAreaCode());
}
}
});
super.findAfter(params, pageInfo, context, list);
}
/**
* @param entity
* @param context
* @throws AppException
*/
@Override
protected void updateBefore(SiteMatterEntity entity, Context context) throws AppException {
super.updateBefore(entity, context);
SiteMatterEntity beforeSiteMatterEntity = this.get(entity.getId(), context);
if (!ObjectUtils.isEmpty(beforeSiteMatterEntity.getDeptId()) && !beforeSiteMatterEntity.getDeptId().equals(entity.getDeptId())) {
//更新事项中的部门编号
MatterEntity matterEntity = matterService.get(entity.getMatterId(), context);
if (!ObjectUtils.isEmpty(matterEntity)) {
matterEntity.setDeptCode(entity.getDeptCode());
matterEntity.setDeptName(entity.getDeptName());
matterService.update(matterEntity, context);
}
}
}
@Override
public void deleteBysiteIdAndSource(Long siteId, Integer source, Context context) {
Map<String, Object> condition = new HashMap<>();
condition.put("siteId", siteId);
condition.put("source", source);
this.dao.delete(condition);
}
}
\ No newline at end of file
package com.mortals.xhx.module.site.web;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.site.model.SiteMatterEntity;
import com.mortals.xhx.module.site.service.SiteMatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Map;
/**
* 站点事项
*
* @author zxfei
* @date 2022-01-20
*/
*
* 站点事项
*
* @author zxfei
* @date 2023-03-10
*/
@RestController
@RequestMapping("site/matter")
public class SiteMatterController extends BaseCRUDJsonBodyMappingController<SiteMatterService, SiteMatterEntity, Long> {
public class SiteMatterController extends BaseCRUDJsonBodyMappingController<SiteMatterService,SiteMatterEntity,Long> {
@Autowired
private ParamService paramService;
public SiteMatterController() {
super.setFormClass(SiteMatterForm.class);
super.setModuleDesc("站点事项");
public SiteMatterController(){
super.setModuleDesc( "站点事项");
}
/**
* @param query
* @param model
* @param context
* @throws AppException
*/
@Override
protected void doListBefore(SiteMatterEntity query, Map<String, Object> model, Context context) throws AppException {
super.doListBefore(query, model, context);
if(ObjectUtils.isEmpty(query.getEventTypeShowNotList())){
ArrayList<String> notList = new ArrayList<>();
notList.add("行政处罚");
query.setEventTypeShowNotList(notList);
}
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "source", paramService.getParamBySecondOrganize("SiteMatter","source"));
super.init(model, context);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment